aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Gross <jgross@suse.com>2017-11-02 05:19:21 -0400
committerBoris Ostrovsky <boris.ostrovsky@oracle.com>2017-11-06 15:50:17 -0500
commit8dca4d96c7d8058e7c97daad9ae0a76569ea31e6 (patch)
tree171e808f1a9c34a655325193addb4206e8f5d1ff
parent223c8f3349f9ce52847dfa266b32761ac223b9ac (diff)
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: Juergen Gross <jgross@suse.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
-rw-r--r--drivers/xen/grant-table.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 573e7fe9b147..fa152832e0e6 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -33,6 +33,7 @@
33 33
34#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt 34#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
35 35
36#include <linux/bootmem.h>
36#include <linux/sched.h> 37#include <linux/sched.h>
37#include <linux/mm.h> 38#include <linux/mm.h>
38#include <linux/slab.h> 39#include <linux/slab.h>
@@ -43,6 +44,7 @@
43#include <linux/hardirq.h> 44#include <linux/hardirq.h>
44#include <linux/workqueue.h> 45#include <linux/workqueue.h>
45#include <linux/ratelimit.h> 46#include <linux/ratelimit.h>
47#include <linux/moduleparam.h>
46 48
47#include <xen/xen.h> 49#include <xen/xen.h>
48#include <xen/interface/xen.h> 50#include <xen/interface/xen.h>
@@ -52,6 +54,9 @@
52#include <xen/hvc-console.h> 54#include <xen/hvc-console.h>
53#include <xen/swiotlb-xen.h> 55#include <xen/swiotlb-xen.h>
54#include <xen/balloon.h> 56#include <xen/balloon.h>
57#ifdef CONFIG_X86
58#include <asm/xen/cpuid.h>
59#endif
55#include <asm/xen/hypercall.h> 60#include <asm/xen/hypercall.h>
56#include <asm/xen/interface.h> 61#include <asm/xen/interface.h>
57 62
@@ -68,6 +73,8 @@ static int gnttab_free_count;
68static grant_ref_t gnttab_free_head; 73static grant_ref_t gnttab_free_head;
69static DEFINE_SPINLOCK(gnttab_list_lock); 74static DEFINE_SPINLOCK(gnttab_list_lock);
70struct grant_frames xen_auto_xlat_grant_frames; 75struct grant_frames xen_auto_xlat_grant_frames;
76static unsigned int xen_gnttab_version;
77module_param_named(version, xen_gnttab_version, uint, 0);
71 78
72static union { 79static union {
73 struct grant_entry_v1 *v1; 80 struct grant_entry_v1 *v1;
@@ -1177,12 +1184,36 @@ static const struct gnttab_ops gnttab_v2_ops = {
1177 .query_foreign_access = gnttab_query_foreign_access_v2, 1184 .query_foreign_access = gnttab_query_foreign_access_v2,
1178}; 1185};
1179 1186
1187static bool gnttab_need_v2(void)
1188{
1189#ifdef CONFIG_X86
1190 uint32_t base, width;
1191
1192 if (xen_pv_domain()) {
1193 base = xen_cpuid_base();
1194 if (cpuid_eax(base) < 5)
1195 return false; /* Information not available, use V1. */
1196 width = cpuid_ebx(base + 5) &
1197 XEN_CPUID_MACHINE_ADDRESS_WIDTH_MASK;
1198 return width > 32 + PAGE_SHIFT;
1199 }
1200#endif
1201 return !!(max_possible_pfn >> 32);
1202}
1203
1180static void gnttab_request_version(void) 1204static void gnttab_request_version(void)
1181{ 1205{
1182 int rc; 1206 long rc;
1183 struct gnttab_set_version gsv; 1207 struct gnttab_set_version gsv;
1184 1208
1185 gsv.version = 1; 1209 if (gnttab_need_v2())
1210 gsv.version = 2;
1211 else
1212 gsv.version = 1;
1213
1214 /* Boot parameter overrides automatic selection. */
1215 if (xen_gnttab_version >= 1 && xen_gnttab_version <= 2)
1216 gsv.version = xen_gnttab_version;
1186 1217
1187 rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gsv, 1); 1218 rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gsv, 1);
1188 if (rc == 0 && gsv.version == 2) 1219 if (rc == 0 && gsv.version == 2)