|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC v1 56/74] xen/pvshim: add grant table operations
From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
xen/arch/x86/pv/shim.c | 174 ++++++++++++++++++++++++++++++++++
xen/common/compat/grant_table.c | 5 +
xen/common/grant_table.c | 10 ++
xen/include/asm-x86/guest/hypercall.h | 6 ++
xen/include/asm-x86/pv/shim.h | 9 ++
5 files changed, 204 insertions(+)
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 69482993f9..98c1e31e8f 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -22,6 +22,7 @@
#include <xen/guest_access.h>
#include <xen/hypercall.h>
#include <xen/init.h>
+#include <xen/iocap.h>
#include <xen/shutdown.h>
#include <xen/types.h>
@@ -30,11 +31,17 @@
#include <asm/guest.h>
#include <asm/pv/mm.h>
+#include <compat/grant_table.h>
+
#ifndef CONFIG_PV_SHIM_EXCLUSIVE
bool pv_shim;
boolean_param("pv-shim", pv_shim);
#endif
+static unsigned int nr_grant_list;
+static unsigned long *grant_frames;
+static DEFINE_SPINLOCK(grant_lock);
+
#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER| \
_PAGE_GUEST_KERNEL)
#define COMPAT_L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
@@ -360,6 +367,173 @@ void pv_shim_inject_evtchn(unsigned int port)
}
}
+long pv_shim_grant_table_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop,
+ unsigned int count, bool compat)
+{
+ struct domain *d = current->domain;
+ long rc = 0;
+
+ if ( count != 1 )
+ return -EINVAL;
+
+ switch ( cmd )
+ {
+ case GNTTABOP_setup_table:
+ {
+ struct gnttab_setup_table nat;
+ struct compat_gnttab_setup_table cmp;
+ unsigned int i;
+
+ if ( unlikely(compat ? copy_from_guest(&cmp, uop, 1)
+ : copy_from_guest(&nat, uop, 1)) ||
+ unlikely(compat ? !compat_handle_okay(cmp.frame_list,
+ cmp.nr_frames)
+ : !guest_handle_okay(nat.frame_list,
+ nat.nr_frames)) )
+ {
+ rc = -EFAULT;
+ break;
+ }
+ if ( compat )
+#define XLAT_gnttab_setup_table_HNDL_frame_list(d, s)
+ XLAT_gnttab_setup_table(&nat, &cmp);
+#undef XLAT_gnttab_setup_table_HNDL_frame_list
+
+ nat.status = GNTST_okay;
+
+ spin_lock(&grant_lock);
+ if ( !nr_grant_list )
+ {
+ struct gnttab_query_size query_size = {
+ .dom = DOMID_SELF,
+ };
+
+ rc = xen_hypercall_grant_table_op(GNTTABOP_query_size,
+ &query_size, 1);
+ if ( rc )
+ {
+ spin_unlock(&grant_lock);
+ break;
+ }
+
+ ASSERT(!grant_frames);
+ grant_frames = xzalloc_array(unsigned long,
+ query_size.max_nr_frames);
+ if ( !grant_frames )
+ {
+ spin_unlock(&grant_lock);
+ rc = -ENOMEM;
+ break;
+ }
+
+ nr_grant_list = query_size.max_nr_frames;
+ }
+
+ if ( nat.nr_frames > nr_grant_list )
+ {
+ spin_unlock(&grant_lock);
+ rc = -EINVAL;
+ break;
+ }
+
+ for ( i = 0; i < nat.nr_frames; i++ )
+ {
+ if ( !grant_frames[i] )
+ {
+ struct xen_add_to_physmap xatp = {
+ .domid = DOMID_SELF,
+ .idx = i,
+ .space = XENMAPSPACE_grant_table,
+ };
+ mfn_t mfn;
+
+ rc = hypervisor_alloc_unused_page(&mfn);
+ if ( rc )
+ {
+ gprintk(XENLOG_ERR,
+ "unable to get memory for grant table\n");
+ break;
+ }
+
+ xatp.gpfn = mfn_x(mfn);
+ rc = xen_hypercall_memory_op(XENMEM_add_to_physmap, &xatp);
+ if ( rc )
+ {
+ hypervisor_free_unused_page(mfn);
+ break;
+ }
+
+ BUG_ON(iomem_permit_access(d, mfn_x(mfn), mfn_x(mfn)));
+ grant_frames[i] = mfn_x(mfn);
+ }
+
+ ASSERT(grant_frames[i]);
+ if ( compat )
+ {
+ compat_pfn_t pfn = grant_frames[i];
+
+ if ( __copy_to_compat_offset(cmp.frame_list, i, &pfn, 1) )
+ {
+ nat.status = GNTST_bad_virt_addr;
+ rc = -EFAULT;
+ break;
+ }
+ }
+ else if ( __copy_to_guest_offset(nat.frame_list, i,
+ &grant_frames[i], 1) )
+ {
+ nat.status = GNTST_bad_virt_addr;
+ rc = -EFAULT;
+ break;
+ }
+ }
+ spin_unlock(&grant_lock);
+
+ if ( compat )
+#define XLAT_gnttab_setup_table_HNDL_frame_list(d, s)
+ XLAT_gnttab_setup_table(&cmp, &nat);
+#undef XLAT_gnttab_setup_table_HNDL_frame_list
+
+ if ( unlikely(compat ? copy_to_guest(uop, &cmp, 1)
+ : copy_to_guest(uop, &nat, 1)) )
+ {
+ rc = -EFAULT;
+ break;
+ }
+
+ break;
+ }
+ case GNTTABOP_query_size:
+ {
+ struct gnttab_query_size op;
+ int rc;
+
+ if ( unlikely(copy_from_guest(&op, uop, 1)) )
+ {
+ rc = -EFAULT;
+ break;
+ }
+
+ rc = xen_hypercall_grant_table_op(GNTTABOP_query_size, &op, count);
+ if ( rc )
+ break;
+
+ if ( copy_to_guest(uop, &op, 1) )
+ {
+ rc = -EFAULT;
+ break;
+ }
+
+ break;
+ }
+ default:
+ rc = -ENOSYS;
+ break;
+ }
+
+ return rc;
+}
+
domid_t get_dom0_domid(void)
{
uint32_t eax, ebx, ecx, edx;
diff --git a/xen/common/compat/grant_table.c b/xen/common/compat/grant_table.c
index ff1d678f01..88c608b62b 100644
--- a/xen/common/compat/grant_table.c
+++ b/xen/common/compat/grant_table.c
@@ -122,6 +122,11 @@ int compat_grant_table_op(unsigned int cmd,
return do_grant_table_op(cmd, cmp_uop, count);
}
+#ifdef CONFIG_X86
+ if ( pv_shim )
+ return pv_shim_grant_table_op(cmd, cmp_uop, count, true);
+#endif
+
if ( (int)count < 0 )
rc = -EINVAL;
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 250450bdda..caf9d2cfae 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -40,6 +40,10 @@
#include <xsm/xsm.h>
#include <asm/flushtlb.h>
+#ifdef CONFIG_X86
+#include <asm/pv/shim.h>
+#endif
+
/* Per-domain grant information. */
struct grant_table {
/*
@@ -3324,6 +3328,12 @@ do_grant_table_op(
if ( (cmd &= GNTTABOP_CMD_MASK) != GNTTABOP_cache_flush && opaque_in )
return -EINVAL;
+#ifdef CONFIG_X86
+ if ( pv_shim )
+ /* NB: no continuation support for pv-shim ops. */
+ return pv_shim_grant_table_op(cmd, uop, count, false);
+#endif
+
rc = -EFAULT;
switch ( cmd )
{
diff --git a/xen/include/asm-x86/guest/hypercall.h
b/xen/include/asm-x86/guest/hypercall.h
index 7d11df29fa..85985a7d98 100644
--- a/xen/include/asm-x86/guest/hypercall.h
+++ b/xen/include/asm-x86/guest/hypercall.h
@@ -103,6 +103,12 @@ static inline long xen_hypercall_event_channel_op(unsigned
int cmd, void *arg)
return _hypercall64_2(long, __HYPERVISOR_event_channel_op, cmd, arg);
}
+static inline long xen_hypercall_grant_table_op(unsigned int cmd, void *arg,
+ unsigned int count)
+{
+ return _hypercall64_3(long, __HYPERVISOR_grant_table_op, cmd, arg, count);
+}
+
static inline long xen_hypercall_hvm_op(unsigned int op, void *arg)
{
return _hypercall64_2(long, __HYPERVISOR_hvm_op, op, arg);
diff --git a/xen/include/asm-x86/pv/shim.h b/xen/include/asm-x86/pv/shim.h
index 6f7b39c3e0..47bc4267af 100644
--- a/xen/include/asm-x86/pv/shim.h
+++ b/xen/include/asm-x86/pv/shim.h
@@ -38,6 +38,8 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t
*l4start,
void pv_shim_shutdown(uint8_t reason);
long pv_shim_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
void pv_shim_inject_evtchn(unsigned int port);
+long pv_shim_grant_table_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop,
+ unsigned int count, bool compat);
domid_t get_dom0_domid(void);
#else
@@ -65,6 +67,13 @@ static inline void pv_shim_inject_evtchn(unsigned int port)
{
ASSERT_UNREACHABLE();
}
+static inline long pv_shim_grant_table_op(unsigned int cmd,
+ XEN_GUEST_HANDLE_PARAM(void) uop,
+ unsigned int count, bool compat)
+{
+ ASSERT_UNREACHABLE();
+ return 0;
+}
static inline domid_t get_dom0_domid(void)
{
return 0;
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |