Add support for mapping grant references into HVM guests (+ some cleanup)
PATCH 1/1 Add support for mapping grant references into HVM guests (+ some cleanup)
Add support for mapping grant references into HVM domains, by modifying the P2M table.
The first couple of patches just tidy up the current grant table implementation a bit, fixing a couple of bugs in the process, and should be fairly uncontroversial. The fourth patch in the series adds a new HVM op to Xen which allows a HVM guest to map a remote domain's grant reference into its P2M table, which can then be mapped by the pagetables in the usual way. The final patch adds matching support to the Linux unmodified drivers tree, allowing the new operation to actually be used, and also adds a couple of very simple test modules.
This isn't actually terribly useful as it stands, because there are no realistic consumers of this interface. I wrote it mostly for the benefit of our closed-source Windows drivers, but that obviously doesn't help people on the list very much. I'm not quite sure what the best way of handling this is; it's clearly better for us for this stuff to go into xen-unstable, rather than being maintained as an out-of-tree patch forever, and it'd be a bit of a waste to force anyone else who wanted this functionality to reinvent it, but it seems odd to add an interface which has no publicly available consumers.
PATCH 1/1 The map_count field of struct grant_table is only written to and never read
# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1242731493 -3600
# Node ID 1954d5a3a1f5977b6d22c545cdc352bad27af528
# Parent 20b69e03fbd099226652fb9ba1540d5e93f35438
The map_count field of struct grant_table is only written to and never read. That makes it a bit useless. Kill it.
xen/common/grant_table.c +0 -2
@@ -119,7 +119,6 @@if (unlikely ((h = t->maptrack_head) == (t->maptrack_limit -1 )) )return -1 ; t->maptrack_head =maptrack_entry (t, h).ref; - t->map_count++;return h; }
@@ -129,7 +128,6 @@ {maptrack_entry (t, handle).ref = t->maptrack_head; t->maptrack_head = handle; - t->map_count--; } static inline int
xen/include/xen/grant_table.h +0 -1
@@ -91,7 +91,6 @@struct grant_mapping **maptrack;unsigned int maptrack_head;unsigned int maptrack_limit; -unsigned int map_count;/* Lock protecting updates to active and shared grant tables. */ spinlock_t lock; };
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 Fix up the synchronisation around grant table map track handles
In reply to [email protected]# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1242731493 -3600
# Node ID 5c6214b1f6003bfb0db95ad8f02a1665a98a21ba
# Parent 1954d5a3a1f5977b6d22c545cdc352bad27af528
Fix up the synchronisation around grant table map track handles. At present, we're not doing any at all, so if a domain e.g. tries to do two map operations at the same time from different vcpus then you could end up with both operations getting back the same maptrack handle.
Fix this problem by just shoving an enormous lock around grant table operations. This is unlikely to be heavily contended, because netback and blkback both restrict themselves to mapping on a single vcpu at a time (globally for netback, and per-device for blkback), and most of the interesting bits are already protected by the remote domain's grant table lock anyway.
The unconteded acquisition cost might be significant for some workloads. If that were the case, it might be worth only acquiring the lock only for multi-vcpu domains, since we only manipulate the maptrack table in the context of one of the domain's vcpus. I've not done that optimisation here, because I didn't want to think about what would happen if e.g. a cpu got hot-unplugged from a domain while it was performing a map operation.
xen/common/grant_table.c +48 -33
@@ -111,6 +111,26 @@#define active_entry (t, e) \ ((t)->active[(e)/ACGNT_PER_PAGE][(e)%ACGNT_PER_PAGE]) +/* Technically, we only really need to acquire the lock for SMP +guests, because you only ever touch the maptrack tables from the +context of the guest which owns them, so if it's uniproc then the +lock can't be contended, and is therefore pointless. Don't bother +with that optimisation for now, though, because it's scary and +confusing. */ +/* The maptrack lock is top-level: you're not allowed to be holding +any other locks when you acquire it. */ +static void +maptrack_lock (struct grant_table *lgt) +{ +spin_lock (&lgt->maptrack_lock); +} + +static void +maptrack_unlock (struct grant_table *lgt) +{ +spin_unlock (&lgt->maptrack_lock); +} +static inline int __get_maptrack_handle (struct grant_table *t)
@@ -141,43 +161,30 @@if (unlikely ((handle =__get_maptrack_handle (lgt)) ==-1 ) ) { -spin_lock (&lgt->lock); + nr_frames =nr_maptrack_frames (lgt); +if ( nr_frames >=max_nr_maptrack_frames () ) +return -1 ; -if (unlikely ((handle =__get_maptrack_handle (lgt)) ==-1 ) ) + new_mt =alloc_xenheap_page (); +if ( new_mt ==NULL ) +return -1 ; + +clear_page (new_mt); + + new_mt_limit = lgt->maptrack_limit +MAPTRACK_PER_PAGE ; + +for ( i = lgt->maptrack_limit; i < new_mt_limit; i++ ) { - nr_frames =nr_maptrack_frames (lgt); -if ( nr_frames >=max_nr_maptrack_frames () ) - { -spin_unlock (&lgt->lock); -return -1 ; - } - - new_mt =alloc_xenheap_page (); -if ( new_mt ==NULL ) - { -spin_unlock (&lgt->lock); -return -1 ; - } - -clear_page (new_mt); - - new_mt_limit = lgt->maptrack_limit +MAPTRACK_PER_PAGE ; - -for ( i = lgt->maptrack_limit; i < new_mt_limit; i++ ) - { - new_mt[i %MAPTRACK_PER_PAGE ].ref = i+1 ; - new_mt[i %MAPTRACK_PER_PAGE ].flags =0 ; - } - - lgt->maptrack[nr_frames] = new_mt; - lgt->maptrack_limit = new_mt_limit; - -gdprintk (XENLOG_INFO , -"Increased maptrack size to %u frames.\n" , nr_frames +1 ); - handle =__get_maptrack_handle (lgt); + new_mt[i %MAPTRACK_PER_PAGE ].ref = i+1 ; + new_mt[i %MAPTRACK_PER_PAGE ].flags =0 ; } -spin_unlock (&lgt->lock); + lgt->maptrack[nr_frames] = new_mt; + lgt->maptrack_limit = new_mt_limit; + +gdprintk (XENLOG_INFO , +"Increased maptrack size to %u frames.\n" , nr_frames +1 ); + handle =__get_maptrack_handle (lgt); }return handle; }
@@ -1506,7 +1513,9 @@guest_handle_cast (uop, gnttab_map_grant_ref_t);if (unlikely (!guest_handle_okay (map, count)) ) goto out; +maptrack_lock (current->domain->grant_table); rc =gnttab_map_grant_ref (map, count); +maptrack_unlock (current->domain->grant_table);break ; }case GNTTABOP_unmap_grant_ref:
@@ -1515,7 +1524,9 @@guest_handle_cast (uop, gnttab_unmap_grant_ref_t);if (unlikely (!guest_handle_okay (unmap, count)) ) goto out; +maptrack_lock (current->domain->grant_table); rc =gnttab_unmap_grant_ref (unmap, count); +maptrack_unlock (current->domain->grant_table);break ; }case GNTTABOP_unmap_and_replace:
@@ -1527,7 +1538,9 @@ rc = -ENOSYS ;if (unlikely (!replace_grant_supported ()) ) goto out; +maptrack_lock (current->domain->grant_table); rc =gnttab_unmap_and_replace (unmap, count); +maptrack_unlock (current->domain->grant_table);break ; }case GNTTABOP_setup_table:
@@ -1598,6 +1611,7 @@/* Simple stuff. */ memset (t,0 ,sizeof (*t));spin_lock_init (&t->lock); +spin_lock_init (&t->maptrack_lock); t->nr_grant_frames =INITIAL_NR_GRANT_FRAMES ;/* Active grant table. */
@@ -1678,6 +1692,7 @@for ( handle =0 ; handle < gt->maptrack_limit; handle++ ) { +/* Domain is dying, so don't need maptrack lock */ map = &maptrack_entry (gt, handle);if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) )continue ;
xen/include/xen/grant_table.h +2 -0
@@ -91,6 +91,8 @@struct grant_mapping **maptrack;unsigned int maptrack_head;unsigned int maptrack_limit; +/* Lock protecting maptrack-related fields. */ +spinlock_t maptrack_lock;/* Lock protecting updates to active and shared grant tables. */ spinlock_t lock; };
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 Try not to use the active grant table structure when we don't hold the lock
In reply to [email protected]# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1242731493 -3600
# Node ID 6cba03677059ca31345cb588fb294d915b8639a8
# Parent 5c6214b1f6003bfb0db95ad8f02a1665a98a21ba
Try not to use the active grant table structure when we don't hold the lock.
xen/common/grant_table.c +3 -1
@@ -206,6 +206,7 @@unsigned long frame =0 , nr_gets =0 ;int rc = GNTST_okay;u32 old_pin; +u32 act_pin;unsigned int cache_flags;struct active_grant_entry *act;struct grant_mapping *mt;
@@ -336,6 +337,7 @@ GNTPIN_hstr_inc : GNTPIN_hstw_inc; frame = act->frame; + act_pin = act->pin; cache_flags = (sha->flags & (GTF_PAT |GTF_PWT |GTF_PCD ) );
@@ -398,7 +400,7 @@if (need_iommu (ld) && !(old_pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) && - (act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) ) + (act_pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) ) {if (iommu_map_page (ld,mfn_to_gmfn (ld, frame), frame) ) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 Add support for mapping grant references into HVM guests by modifying the P2M
In reply to [email protected]# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1242731493 -3600
# Node ID c6126a51b5094529933790ba166778bfb8c3d9de
# Parent 6cba03677059ca31345cb588fb294d915b8639a8
Add support for mapping grant references into HVM guests by modifying the P2M. This is moderately involved, because it means that you can now have several pfns mapping on to a single mfn, which wasn't previously allowed. Fortunately, pretty much everything which does a P2M lookup immediately follows it with a get_page(), which will fail because the page is owned by the wrong domain, which should be fairly safe. This means that guests are likely to crash if e.g. they try to put their page tables in memory which was grant-mapped in from another domain, but I don't consider that to be a particular problem.
There's a minor change to get_page_from_l1e(), which I believe is a bug fix, because it makes put_page_from_l1e() be an inverse of get_page_from_l1e(), but I don't really understand that stuff well enough to be entirely confident of it.
One slight oddity is that we allow a guest's page tables to be mapped writably from another domain (this is also true of ordinary PV grant mappings). I believe this to be okay, because the worst that can happen is that an update to the guest page tables isn't reflected into the shadows, and the worst that can happen as a result of that is that the guest becomes unhappy, with no damage to Xen or to other domains.
This will only work for 64-bit hypervisors, because we've run out of P2M types in 32 bit mode.
xen/arch/x86/hvm/emulate.c +2 -2
@@ -636,12 +636,12 @@return rc; (void )gfn_to_mfn_current (sgpa >>PAGE_SHIFT , &p2mt); -if ( !p2m_is_ram (p2mt) ) +if ( !p2m_is_ram (p2mt) && !p2m_is_grant (p2mt) )return hvmemul_do_mmio ( sgpa, reps, bytes_per_rep, dgpa,IOREQ_READ , df,NULL ); (void )gfn_to_mfn_current (dgpa >>PAGE_SHIFT , &p2mt); -if ( !p2m_is_ram (p2mt) ) +if ( !p2m_is_ram (p2mt) && !p2m_is_grant (p2mt) )return hvmemul_do_mmio ( dgpa, reps, bytes_per_rep, sgpa,IOREQ_WRITE , df,NULL );
xen/arch/x86/hvm/hvm.c +63 -7
111 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +21 -2
@@ -909,8 +909,27 @@ }/* Log-dirty: mark the page dirty and let the guest write it again */ -paging_mark_dirty (current->domain,mfn_x (mfn)); -p2m_change_type (current->domain, gfn, p2m_ram_logdirty, p2m_ram_rw); +if ( p2mt == p2m_ram_logdirty ) + { +paging_mark_dirty (current->domain,mfn_x (mfn)); +p2m_change_type (current->domain, gfn, p2m_ram_logdirty, p2m_ram_rw); +return ; + } + +/* Okay, this shouldn't happen. Maybe the guest was writing to a +read-only grant mapping? */ +if ( p2mt == p2m_grant_map_ro ) + { +/* Naughty... */ +gdprintk (XENLOG_WARNING , +"trying to write to read-only grant mapping\n" ); +hvm_inject_exception (TRAP_gp_fault,0 ,0 ); +return ; + } + +/* Something bad has happened; either Xen or the hardware have +screwed up. */ +gdprintk (XENLOG_WARNING ,"unexpected SVM nested page fault\n" ); }static void svm_fpu_dirty_intercept (void )
xen/arch/x86/mm.c +1 -1
@@ -761,7 +761,7 @@* qemu-dm helper process in dom0 to map the domain's memory without * messing up the count of "real" writable mappings.) */ if ( (l1f & _PAGE_RW) && - !(paging_mode_external (d) && (d != curr->domain)) && + !(paging_mode_external (owner) && (owner != curr->domain)) && !get_page_type (page, PGT_writable_page) ) goto could_not_pin;
xen/arch/x86/mm/hap/p2m-ept.c +2 -0
@@ -39,10 +39,12 @@return ;case p2m_ram_rw:case p2m_mmio_direct: +case p2m_grant_map_rw: entry->r = entry->w = entry->x =1 ;return ;case p2m_ram_logdirty:case p2m_ram_ro: +case p2m_grant_map_ro: entry->r = entry->x =1 ; entry->w =0 ;return ;
xen/arch/x86/mm/p2m.c +50 -8
135 lines not on this page · raw message
xen/arch/x86/mm/shadow/multi.c +65 -26
220 lines not on this page · raw message
xen/common/grant_table.c +353 -91
572 lines not on this page · raw message
xen/include/asm-x86/grant_table.h +2 -2
@@ -39,8 +39,8 @@ }/* Foreign mappings of HHVM-guest pages do not modify the type count. */ -#define gnttab_host_mapping_get_page_type (op, ld, rd) \ - (!((op)->flags & GNTMAP_readonly) && \ +#define gnttab_host_mapping_get_page_type (flags, ld, rd) \ + (!((flags) & GNTMAP_readonly) && \ (((ld) == (rd)) || !paging_mode_external(rd)))/* Done implicitly when page tables are destroyed. */
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -31,6 +31,7 @@#include <asm/hvm/viridian.h> #include <asm/hvm/vmx/vmcs.h> #include <asm/hvm/svm/vmcb.h> +#include <public/grant_table.h> #include <public/hvm/params.h> #include <public/hvm/save.h>
xen/include/asm-x86/p2m.h +24 -14
@@ -45,6 +45,10 @@*/ #define phys_to_machine_mapping ((l1_pgentry_t *)RO_MPT_VIRT_START) +#ifdef __x86_64__ +#define HAVE_GRANT_MAP_P2M +#endif +/* * The upper levels of the p2m pagetable always contain full rights; all * variation in the access control bits is made in the level-1 PTEs.
@@ -65,6 +69,12 @@ p2m_mmio_dm =4 ,/* Reads and write go to the device model */ p2m_mmio_direct =5 ,/* Read/write mapping of genuine MMIO area */ p2m_populate_on_demand =6 ,/* Place-holder for empty memory */ + +/* Note that these can only be used if HAVE_GRANT_MAP_P2M is +defined. They get defined anyway so as to avoid lots of +#ifdef's everywhere else. */ + p2m_grant_map_rw =7 ,/* Read/write grant mapping */ + p2m_grant_map_ro =8 ,/* Read-only grant mapping */ } p2m_type_t; typedef enum {
@@ -81,13 +91,19 @@ | p2m_to_mask(p2m_ram_logdirty) \ | p2m_to_mask(p2m_ram_ro)) +/* Grant mapping types, which map to a real machine frame in another +* VM */ +#define P2M_GRANT_TYPES (p2m_to_mask(p2m_grant_map_rw) \ + | p2m_to_mask(p2m_grant_map_ro) ) +/* MMIO types, which don't have to map to anything in the frametable */ #define P2M_MMIO_TYPES (p2m_to_mask(p2m_mmio_dm) \ | p2m_to_mask(p2m_mmio_direct))/* Read-only types, which must have the _PAGE_RW bit clear in their PTEs */ #define P2M_RO_TYPES (p2m_to_mask(p2m_ram_logdirty) \ - | p2m_to_mask(p2m_ram_ro)) + | p2m_to_mask(p2m_ram_ro) \ + | p2m_to_mask(p2m_grant_map_ro) )#define P2M_MAGIC_TYPES (p2m_to_mask(p2m_populate_on_demand))
@@ -96,7 +112,8 @@#define p2m_is_mmio (_t) (p2m_to_mask(_t) & P2M_MMIO_TYPES)#define p2m_is_readonly (_t) (p2m_to_mask(_t) & P2M_RO_TYPES)#define p2m_is_magic (_t) (p2m_to_mask(_t) & P2M_MAGIC_TYPES) -#define p2m_is_valid (_t) (p2m_to_mask(_t) & (P2M_RAM_TYPES | P2M_MMIO_TYPES)) +#define p2m_is_grant (_t) (p2m_to_mask(_t) & P2M_GRANT_TYPES) +#define p2m_is_valid (_t) (p2m_to_mask(_t) & (P2M_RAM_TYPES | P2M_MMIO_TYPES | P2M_GRANT_TYPES))/* Populate-on-demand */ #define POPULATE_ON_DEMAND_MFN (1<<9)
@@ -161,8 +178,12 @@/* Extract the type from the PTE flags that store it */ static inline p2m_type_t p2m_flags_to_type (unsigned long flags) { -/* Type is stored in the "available" bits, 9, 10 and 11 */ +/* Type is stored in the "available" bits */ +#ifdef __x86_64__ +return (flags >>9 ) &0x3fff ; +#else return (flags >>9 ) &0x7 ; +#endif }/* Read the current domain's p2m table. Do not populate PoD pages. */
@@ -225,17 +246,6 @@else return mfn_x (mfn); } - -/* Translate the frame number held in an l1e from guest to machine */ -static inline l1_pgentry_t -gl1e_to_ml1e (struct domain *d,l1_pgentry_t l1e) -{ -if (unlikely (paging_mode_translate (d)) ) - l1e =l1e_from_pfn (gmfn_to_mfn (d,l1e_get_pfn (l1e)), -l1e_get_flags (l1e)); -return l1e; -} -/* Init the datastructures for later use by the p2m code */ int p2m_init (struct domain *d);
xen/include/public/hvm/hvm_op.h +26 -0
@@ -128,4 +128,30 @@#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ +/* Map a grant reference exposed by a given remote domain into a given +slot in the local P2M table. */ +#define HVMOP_map_grant_ref 9 +struct xen_hvm_map_grant_ref { +/* IN */ +domid_t domid; +uint16_t pad0; +grant_ref_t gref; +uint64_t pfn; +uint32_t flags; +/* OUT */ +grant_handle_t handle; +uint32_t pad1; +}; +typedef struct xen_hvm_map_grant_ref xen_hvm_map_grant_ref_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_map_grant_ref_t); + +/* Unmap a grant reference previously mapped by HVMOP_map_grant_ref */ +#define HVMOP_unmap_grant_ref 10 +struct xen_hvm_unmap_grant_ref { +/* IN */ +grant_handle_t handle; +}; +typedef struct xen_hvm_unmap_grant_ref xen_hvm_unmap_grant_ref_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_unmap_grant_ref_t); +#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
xen/include/xen/grant_table.h +10 -3
@@ -71,10 +71,13 @@* table of these, indexes into which are returned as a 'mapping handle'. */ struct grant_mapping { -u32 ref;/* grant ref */ -u16 flags;/* 0-4: GNTMAP_* ; 5-15: unused */ -domid_t domid;/* granting domain */ +u32 ref;/* grant ref */ +u16 flags;/* 0-4: GNTMAP_* ; 5: MAPTRACK_P2M; 6-15: unused */ +domid_t domid;/* granting domain */ +xen_pfn_t pfn;/* Only for P2M mappings */ }; + +#define MAPTRACK_P2M 0x20/* Fairly arbitrary. [POLICY] */ #define MAPTRACK_MAX_ENTRIES 16384
@@ -148,4 +151,8 @@ return num_act_frames_from_sha_frames(nr_grant_frames(gt)); } +int gnttab_map_grant_ref_p2m (domid_t domid,grant_ref_t gref,xen_pfn_t pfn, +unsigned flags,grant_handle_t *handle); +int gnttab_unmap_grant_ref_p2m (grant_handle_t handle); +#endif /* __XEN_GRANT_TABLE_H__ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 Add support for mapping grant references in HVM domains to unmodified_drivers/linux-2.6
In reply to [email protected]# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1242731493 -3600
# Node ID db464ab112d4b6095a966c09c7065c91f2d6930e
# Parent c6126a51b5094529933790ba166778bfb8c3d9de
Add support for mapping grant references in HVM domains to unmodified_drivers/linux-2.6. I've not tried to give it the same API as the PV grant map interface, because the underlying mechanism is too different for that to be very comfortable.
Also add a couple of very simple modules to unmodified_drivers/linux-2.6 which can be used to test mapping grants into HVM domains. These are about as brain-dead as it's possible to be, but they do demonstrate the basic functionality.
unmodified_drivers/linux-2.6/Makefile +2 -0
@@ -5,3 +5,5 @@ obj-m += blkfront/ obj-m += netfront/ obj-m += scsifront/ + +obj-m += test-gntmap.o test-gntoffer.o
unmodified_drivers/linux-2.6/platform-pci/Kbuild +1 -1
@@ -7,7 +7,7 @@ xen-platform-pci-objs := evtchn.o platform-pci.o gnttab.o xen_support.o xen-platform-pci-objs += features.o platform-compat.o xen-platform-pci-objs += reboot.o machine_reboot.o -xen-platform-pci-objs += panic-handler.o +xen-platform-pci-objs += panic-handler.o gntmap.o xen-platform-pci-objs += ../xenbus/xenbus_comms.o xen-platform-pci-objs += ../xenbus/xenbus_xs.o
unmodified_drivers/linux-2.6/platform-pci/gntmap.c new file +56 -0
56 lines not on this page · raw message
unmodified_drivers/linux-2.6/platform-pci/gntmap.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef GNTMAP_H__ +#define GNTMAP_H__ + +#include <xen/interface/xen.h> +#include <xen/interface/grant_table.h> + +struct gntmap_detail { +unsigned long phys_addr; +void *va; +grant_handle_t handle; +}; + +int gntmap_map_grant (struct gntmap_detail *res, +domid_t domid, +grant_ref_t gref, +int readonly); + +void gntmap_unmap_grant (struct gntmap_detail *detail); + +#endif /* !GNTMAP_H__ */
unmodified_drivers/linux-2.6/platform-pci/platform-pci.c +2 -0
@@ -36,7 +36,9 @@#include <asm/uaccess.h> #include <asm/hypervisor.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <xen/interface/memory.h> +#include <xen/interface/grant_table.h> #include <xen/interface/hvm/params.h> #include <xen/features.h> #include <xen/evtchn.h>
unmodified_drivers/linux-2.6/test-gntmap.c new file +59 -0
59 lines not on this page · raw message
unmodified_drivers/linux-2.6/test-gntoffer.c new file +36 -0
@@ -0,0 +1,36 @@ +#include <linux/kernel.h> +#include <linux/module.h> + +#include <xen/interface/xen.h> +#include <xen/interface/grant_table.h> +#include <xen/gnttab.h> + +static int remote_domid; +module_param (remote_domid, int,S_IRUGO ); + +static int gref; +static void *buf; + +int main (void ) +{ + buf = (void *)get_zeroed_page (GFP_KERNEL ); +if (!buf) { +printk (KERN_ERR "can't get a free page\n" ); +return -ENOMEM ; + } +memset (buf,0x92 ,PAGE_SIZE ); + gref =gnttab_grant_foreign_access (remote_domid,virt_to_mfn (buf),0 ); +printk (KERN_INFO "gref is %d\n" , gref); +return 0 ; +} + +void finish (void ) +{ +gnttab_end_foreign_access (gref,0 ); +free_page ((unsigned long )buf); +} + +module_init (main); +module_exit (finish); + +MODULE_LICENSE ("GPL" );
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi. Some comments.
- Patch 4 adds a new grant hypercall, but the current GNTTABOP_map_grant_ref can be used, I suppose. Why not to use gnttab_map_grant_ref::host_addr?
- It seems that the patch 4 touches common code unnecessary. it would suffice to touch create_grant_host_mapping() and replace_grant_host_mapping() inserting something like "if (hvm_domain) return hvm_domain_case()".
Then, your modification will be well separated so that the possibility for inclusion would increase.
thanks,
Quoted 28 lines · On Tue, May 19, 2009 at 12:27:02PM +0100, [email protected] wrote:
Add support for mapping grant references into HVM domains, by modifying the P2M table.
The first couple of patches just tidy up the current grant table implementation a bit, fixing a couple of bugs in the process, and should be fairly uncontroversial. The fourth patch in the series adds a new HVM op to Xen which allows a HVM guest to map a remote domain's grant reference into its P2M table, which can then be mapped by the pagetables in the usual way. The final patch adds matching support to the Linux unmodified drivers tree, allowing the new operation to actually be used, and also adds a couple of very simple test modules.
This isn't actually terribly useful as it stands, because there are no realistic consumers of this interface. I wrote it mostly for the benefit of our closed-source Windows drivers, but that obviously doesn't help people on the list very much. I'm not quite sure what the best way of handling this is; it's clearly better for us for this stuff to go into xen-unstable, rather than being maintained as an out-of-tree patch forever, and it'd be a bit of a waste to force anyone else who wanted this functionality to reinvent it, but it seems odd to add an interface which has no publicly available consumers.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Signature · 1 line
yamahata
Re: [PATCH 4 of 5] Add support for mapping grant references into HVM guests by modifying the P2M
In reply to [email protected]Hi Steven,
I understand that we are going to drop Xen 32bit, and support only Xen 64bit on this feature??
I believe that Xen 32bit is still important and desired by many people. So please considere supporting that with your patch.
Thanks,
N
Quoted 5 lines · On Tue, May 19, 2009 at 8:27 PM, <[email protected]> wrote:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 5] Add support for mapping grant references into HVM guests by modifying the P2M
Quoted 2 lines
I understand that we are going to drop Xen 32bit, and support only Xen 64bit on this feature??
That's the plan, yes.
Quoted 2 lines
I believe that Xen 32bit is still important and desired by many people. So please considere supporting that with your patch.
The problem is that we only have a limited number of bits available in the P2M entries, which limits the number of distinct types of P2M entry which we can encode. On 32-bit Xen, that limit is eight, of which seven are already used, and the grant mapping patch needs another two (one for read-write maps, and one for read-only). There just isn't enough room everything we want to do.
It'd be easy enough to make grant mapping work on 32-bit Xen if we were willing to drop some other feature (populate-on-demand, say), but I don't think that would be an acceptable solution. Finding somewhere else to stash the required bits would significantly complicate things, and, since there aren't any particularly convincing use-cases yet for even the 64-bit variant, I didn't think that would be worthwhile.
Steven.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 6 lines
Hi. Some comments.
- Patch 4 adds a new grant hypercall, but the current
GNTTABOP_map_grant_refcan be used, I suppose. Why not to usegnttab_map_grant_ref::host_addr?
Quoted 7 lines
- It seems that the patch 4 touches common code unnecessary. it would suffice to touch
create_grant_host_mapping()andreplace_grant_host_mapping()inserting something like "if (hvm_domain) returnhvm_domain_case()".Then, your modification will be well separated so that the possibility for inclusion would increase.
Yes, it could be done like that. I decided against going that way, though, because we'd end up with the same call having significantly different semantics in PV and HVM guests, which sounds like a bad idea.
In PV guests, the grant map hypercalls map a grant reference into the virtual address space, by going and rewriting guest PTEs. In an HVM guest, the guest PTEs are all owned by the guest OS kernel, and so it's not a good idea for Xen to go and modify them directly (even ignoring the nasty interactions with shadow mode). The patch therefore works by modifying the P2M PTEs instead, since they're owned by Xen and it can modify them as it wills. Since the two operations are different, from a guest perspective, and have different semantics, it seemed best not to try to mosh them together.
It would have been possible to instead allocate another GNTMAP_* flag, and use that to indicate that the guest wants the different semantics. That would have worked fine, but it seemed a bit less clean to me than keeping the two interfaces separate.
Steven.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 5] Add support for mapping grant references into HVM guests by modifying the P2M
In reply to Steven SmithQuoted 13 lines · Steven Smith
Quoted 2 lines
I understand that we are going to drop Xen 32bit, and support only Xen 64bit on this feature??
That's the plan, yes.
Quoted 2 lines
I believe that Xen 32bit is still important and desired by many people. So please considere supporting that with your patch.
The problem is that we only have a limited number of bits available in the P2M entries, which limits the number of distinct types of P2M entry which we can encode. On 32-bit Xen, that limit is eight, of which seven are already used, and the grant mapping patch needs another two (one for read-write maps, and one for read-only). There just isn't enough room everything we want to do.
Quoted 6 lines
It'd be easy enough to make grant mapping work on 32-bit Xen if we were willing to drop some other feature (populate-on-demand, say), but I don't think that would be an acceptable solution. Finding somewhere else to stash the required bits would significantly complicate things, and, since there aren't any particularly convincing use-cases yet for even the 64-bit variant, I didn't think that would be worthwhile.
OK, I see.
I want to try your patch. However, my Dom0 is 32bit, so Xen is 32 bit, too (I compiled Xen from source code). How can I compile Xen in 64bit for your patch now?
If it is not possible (or easy) to do that now, could you please provide the patch to cross compile Xen in 64bit, too?
That would be useful to try your patch, and also for other things.
Thanks,
N
Quoted 28 lines · Steven Smith
Quoted 6 lines
Hi. Some comments.
- Patch 4 adds a new grant hypercall, but the current
GNTTABOP_map_grant_refcan be used, I suppose. Why not to usegnttab_map_grant_ref::host_addr?Quoted 7 lines
- It seems that the patch 4 touches common code unnecessary. it would suffice to touch
create_grant_host_mapping()andreplace_grant_host_mapping()inserting something like "if (hvm_domain) returnhvm_domain_case()".Then, your modification will be well separated so that the possibility for inclusion would increase.
Yes, it could be done like that. I decided against going that way, though, because we'd end up with the same call having significantly different semantics in PV and HVM guests, which sounds like a bad idea.
In PV guests, the grant map hypercalls map a grant reference into the virtual address space, by going and rewriting guest PTEs. In an HVM guest, the guest PTEs are all owned by the guest OS kernel, and so it's not a good idea for Xen to go and modify them directly (even ignoring the nasty interactions with shadow mode). The patch therefore works by modifying the P2M PTEs instead, since they're owned by Xen and it can modify them as it wills. Since the two operations are different, from a guest perspective, and have different semantics, it seemed best not to try to mosh them together.
Quoted 4 lines
It would have been possible to instead allocate another GNTMAP_* flag, and use that to indicate that the guest wants the different semantics. That would have worked fine, but it seemed a bit less clean to me than keeping the two interfaces separate.
ia64 grant table works with guest physical address as updating ia64 p2m table. (the ia64 p2m table isn't exactly same to x86, though. and please note note that ia64 guest works with always auto_translated_physmap mode enabled.)
And by using "if (xen_feature(XENFEAT_auto_translated_physmap))", almost all pv backend/frontend works for ia64 pv guest.
So if grant table for x86 HVM domain is implemented with existing gnttabop, x86 HVM guest can use pv backend/frontend as is.
Your concern is windows pv driver, so this doesn't make sense to you, though.
thanks,
Signature · 1 line
yamahata
Re: [PATCH 4 of 5] Add support for mapping grant references into HVM guests by modifying the P2M
In reply to NAHieuQuoted 17 lines
Quoted 9 lines
Quoted 2 lines
I believe that Xen 32bit is still important and desired by many people. So please considere supporting that with your patch.
The problem is that we only have a limited number of bits available in the P2M entries, which limits the number of distinct types of P2M entry which we can encode. On 32-bit Xen, that limit is eight, of which seven are already used, and the grant mapping patch needs another two (one for read-write maps, and one for read-only). There just isn't enough room everything we want to do.
Quoted 6 lines
It'd be easy enough to make grant mapping work on 32-bit Xen if we were willing to drop some other feature (populate-on-demand, say), but I don't think that would be an acceptable solution. Finding somewhere else to stash the required bits would significantly complicate things, and, since there aren't any particularly convincing use-cases yet for even the 64-bit variant, I didn't think that would be worthwhile.
OK, I see.
Quoted 7 lines
I want to try your patch. However, my Dom0 is 32bit, so Xen is 32 bit, too (I compiled Xen from source code). How can I compile Xen in 64bit for your patch now?
If it is not possible (or easy) to do that now, could you please provide the patch to cross compile Xen in 64bit, too?
That would be useful to try your patch, and also for other things.
Err... The easy way of building a 64-bit Xen is just to install a 64-bit Linux and do a native compile from there. It's possible, in principle, to cross-compile it, but it's not something I've ever done, and it requires a fair bit of fiddling to get right. I'd recommend that you install a 64-bit version of Linux somewhere and do the compilation from there, rather than trying to set up cross toolchains, unless you have absolutely no choice in the matter.
Steven.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 14 lines
Quoted 10 lines
In PV guests, the grant map hypercalls map a grant reference into the virtual address space, by going and rewriting guest PTEs. In an HVM guest, the guest PTEs are all owned by the guest OS kernel, and so it's not a good idea for Xen to go and modify them directly (even ignoring the nasty interactions with shadow mode). The patch therefore works by modifying the P2M PTEs instead, since they're owned by Xen and it can modify them as it wills. Since the two operations are different, from a guest perspective, and have different semantics, it seemed best not to try to mosh them together.
Quoted 4 lines
It would have been possible to instead allocate another GNTMAP_* flag, and use that to indicate that the guest wants the different semantics. That would have worked fine, but it seemed a bit less clean to me than keeping the two interfaces separate.
Quoted 6 lines
ia64 grant table works with guest physical address as updating ia64 p2m table. (the ia64 p2m table isn't exactly same to x86, though. and please note note that ia64 guest works with always
auto_translated_physmapmode enabled.) And by using "if (xen_feature(XENFEAT_auto_translated_physmap))", almost all pv backend/frontend works for ia64 pv guest.
Okay, so the suggestion is that we should use map-to-VA if auto_translated_physmap is clear, and map-via-P2M if it's set? Tying together largely unrelated features like that sounds to me like encoding implementation limitations into the interface, which doesn't sound like a good idea.
Quoted 5 lines
So if grant table for x86 HVM domain is implemented with existing gnttabop, x86 HVM guest can use pv backend/frontend as is.
Your concern is windows pv driver, so this doesn't make sense to you, though.
Well, no, it's not directly relevant to me, but at the same time being able to move backends between PV and HVM guests easily would be pretty useful. Any API we can come up with will necessarily require some changes to the backends, though, so it's mostly a matter of balancing the amount of porting needed now against the long-term maintenance cost of having yet more weird special cases in our APIs. I think that keying off of auto_translated_physmap probably puts too much emphasis on the short-term cost, but using an explicit GNTMAP_p2m_map flag might be better.
Steven.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 14 lines · Steven Smith
Quoted 14 lines
Quoted 14 lines
In PV guests, the grant map hypercalls map a grant reference into the virtual address space, by going and rewriting guest PTEs. In an HVM guest, the guest PTEs are all owned by the guest OS kernel, and so it's not a good idea for Xen to go and modify them directly (even ignoring the nasty interactions with shadow mode). The patch therefore works by modifying the P2M PTEs instead, since they're owned by Xen and it can modify them as it wills. Since the two operations are different, from a guest perspective, and have different semantics, it seemed best not to try to mosh them together.
It would have been possible to instead allocate another GNTMAP_* flag, and use that to indicate that the guest wants the different semantics. That would have worked fine, but it seemed a bit less clean to me than keeping the two interfaces separate.
Quoted 8 lines
Quoted 6 lines
ia64 grant table works with guest physical address as updating ia64 p2m table. (the ia64 p2m table isn't exactly same to x86, though. and please note note that ia64 guest works with always
auto_translated_physmapmode enabled.) And by using "if (xen_feature(XENFEAT_auto_translated_physmap))", almost all pv backend/frontend works for ia64 pv guest.Okay, so the suggestion is that we should use map-to-VA if
auto_translated_physmapis clear, and map-via-P2M if it's set?
Yes. That is exactly what ia64 xen is doing. (ia64 xen supports only auto translated mode enabled mode.)
Quoted 10 lines
Tying
together largely unrelated features like that sounds to me like encoding implementation limitations into the interface, which doesn't sound like a good idea.Quoted 5 lines
So if grant table for x86 HVM domain is implemented with existing gnttabop, x86 HVM guest can use pv backend/frontend as is.
Your concern is windows pv driver, so this doesn't make sense to you, though.
Quoted 9 lines
Well, no, it's not directly relevant to me, but at the same time being able to move backends between PV and HVM guests easily would be pretty useful. Any API we can come up with will necessarily require some changes to the backends, though, so it's mostly a matter of balancing the amount of porting needed now against the long-term maintenance cost of having yet more weird special cases in our APIs. I think that keying off of
auto_translated_physmapprobably puts too much emphasis on the short-term cost, but using an explicitGNTMAP_p2m_mapflag might be better.
Yeah. I agree with the point. It's a trade off. auto_translated_physmap mode support was included long time before and uite stable. At least for linux pv drivers in linux-2.6.18-xen.hg. In fact it was introduced before switching to linux-2.6.18-xen.hg tree. I.e. before June 2007.
Please note that I'm not trying to prevent your new hypercall. I'm quite fine as long as it doesn't break existing ones. I was curious why you came up with a new hypercall instead of reusing existing hypercall.
thanks,
Signature · 1 line
yamahata