Commit 8dca4d96 authored by Juergen Gross's avatar Juergen Gross Committed by Boris Ostrovsky

xen: select grant interface version

Grant v2 will be needed in cases where a frame number in the grant
table can exceed 32 bits. For PV guests this is a host feature, while
for HVM guests this is a guest feature.

So select grant v2 in case frame numbers can be larger than 32 bits
and grant v1 else.

For testing purposes add a way to specify the grant interface version
via a boot parameter.
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent 223c8f33
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
#include <linux/bootmem.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
#include <linux/hardirq.h> #include <linux/hardirq.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/ratelimit.h> #include <linux/ratelimit.h>
#include <linux/moduleparam.h>
#include <xen/xen.h> #include <xen/xen.h>
#include <xen/interface/xen.h> #include <xen/interface/xen.h>
...@@ -52,6 +54,9 @@ ...@@ -52,6 +54,9 @@
#include <xen/hvc-console.h> #include <xen/hvc-console.h>
#include <xen/swiotlb-xen.h> #include <xen/swiotlb-xen.h>
#include <xen/balloon.h> #include <xen/balloon.h>
#ifdef CONFIG_X86
#include <asm/xen/cpuid.h>
#endif
#include <asm/xen/hypercall.h> #include <asm/xen/hypercall.h>
#include <asm/xen/interface.h> #include <asm/xen/interface.h>
...@@ -68,6 +73,8 @@ static int gnttab_free_count; ...@@ -68,6 +73,8 @@ static int gnttab_free_count;
static grant_ref_t gnttab_free_head; static grant_ref_t gnttab_free_head;
static DEFINE_SPINLOCK(gnttab_list_lock); static DEFINE_SPINLOCK(gnttab_list_lock);
struct grant_frames xen_auto_xlat_grant_frames; struct grant_frames xen_auto_xlat_grant_frames;
static unsigned int xen_gnttab_version;
module_param_named(version, xen_gnttab_version, uint, 0);
static union { static union {
struct grant_entry_v1 *v1; struct grant_entry_v1 *v1;
...@@ -1177,12 +1184,36 @@ static const struct gnttab_ops gnttab_v2_ops = { ...@@ -1177,12 +1184,36 @@ static const struct gnttab_ops gnttab_v2_ops = {
.query_foreign_access = gnttab_query_foreign_access_v2, .query_foreign_access = gnttab_query_foreign_access_v2,
}; };
static bool gnttab_need_v2(void)
{
#ifdef CONFIG_X86
uint32_t base, width;
if (xen_pv_domain()) {
base = xen_cpuid_base();
if (cpuid_eax(base) < 5)
return false; /* Information not available, use V1. */
width = cpuid_ebx(base + 5) &
XEN_CPUID_MACHINE_ADDRESS_WIDTH_MASK;
return width > 32 + PAGE_SHIFT;
}
#endif
return !!(max_possible_pfn >> 32);
}
static void gnttab_request_version(void) static void gnttab_request_version(void)
{ {
int rc; long rc;
struct gnttab_set_version gsv; struct gnttab_set_version gsv;
gsv.version = 1; if (gnttab_need_v2())
gsv.version = 2;
else
gsv.version = 1;
/* Boot parameter overrides automatic selection. */
if (xen_gnttab_version >= 1 && xen_gnttab_version <= 2)
gsv.version = xen_gnttab_version;
rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gsv, 1); rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gsv, 1);
if (rc == 0 && gsv.version == 2) if (rc == 0 && gsv.version == 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment