[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC][PATCH 02/13] introduce XENMEM_reserved_device_memory_map
On 2015/4/23 20:59, Jan Beulich wrote: On 23.04.15 at 14:32, <tiejun.chen@xxxxxxxxx> wrote:But if you already have one just please ignore this and tell meHere's what I currently have: Could you resend me this as an attached file? Then I can apply that properly without any miss? Thanks Tiejun introduce XENMEM_reserved_device_memory_map This is a prerequisite for punching holes into HVM and PVH guests' P2M to allow passing through devices that are associated with (on VT-d) RMRRs. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> Acked-by: Kevin Tian <kevin.tian@xxxxxxxxx> --- v??: Comment iommu_grdm_t typedef. Comment on the purpose of the new hypercall in the public header. (Both requested by Tim.) --- unstable.orig/xen/common/compat/memory.c +++ unstable/xen/common/compat/memory.c @@ -17,6 +17,37 @@ CHECK_TYPE(domid); CHECK_mem_access_op; CHECK_vmemrange; +#ifdef HAS_PASSTHROUGH +struct get_reserved_device_memory { + struct compat_reserved_device_memory_map map; + unsigned int used_entries; +}; + +static int get_reserved_device_memory(xen_pfn_t start, + xen_ulong_t nr, void *ctxt) +{ + struct get_reserved_device_memory *grdm = ctxt; + + if ( grdm->used_entries < grdm->map.nr_entries ) + { + struct compat_reserved_device_memory rdm = { + .start_pfn = start, .nr_pages = nr + }; + + if ( rdm.start_pfn != start || rdm.nr_pages != nr ) + return -ERANGE; + + if ( __copy_to_compat_offset(grdm->map.buffer, grdm->used_entries, + &rdm, 1) ) + return -EFAULT; + } + + ++grdm->used_entries; + + return 0; +} +#endif + int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) { int split, op = cmd & MEMOP_CMD_MASK; @@ -303,6 +334,29 @@ int compat_memory_op(unsigned int cmd, X break; } +#ifdef HAS_PASSTHROUGH + case XENMEM_reserved_device_memory_map: + { + struct get_reserved_device_memory grdm; + + if ( copy_from_guest(&grdm.map, compat, 1) || + !compat_handle_okay(grdm.map.buffer, grdm.map.nr_entries) ) + return -EFAULT; + + grdm.used_entries = 0; + rc = iommu_get_reserved_device_memory(get_reserved_device_memory, + &grdm); + + if ( !rc && grdm.map.nr_entries < grdm.used_entries ) + rc = -ENOBUFS; + grdm.map.nr_entries = grdm.used_entries; + if ( __copy_to_guest(compat, &grdm.map, 1) ) + rc = -EFAULT; + + return rc; + } +#endif + default: return compat_arch_memory_op(cmd, compat); } --- unstable.orig/xen/common/memory.c +++ unstable/xen/common/memory.c @@ -748,6 +748,34 @@ static int construct_memop_from_reservat return 0; } +#ifdef HAS_PASSTHROUGH +struct get_reserved_device_memory { + struct xen_reserved_device_memory_map map; + unsigned int used_entries; +}; + +static int get_reserved_device_memory(xen_pfn_t start, + xen_ulong_t nr, void *ctxt) +{ + struct get_reserved_device_memory *grdm = ctxt; + + if ( grdm->used_entries < grdm->map.nr_entries ) + { + struct xen_reserved_device_memory rdm = { + .start_pfn = start, .nr_pages = nr + }; + + if ( __copy_to_guest_offset(grdm->map.buffer, grdm->used_entries, + &rdm, 1) ) + return -EFAULT; + } + + ++grdm->used_entries; + + return 0; +} +#endif + long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { struct domain *d; @@ -1162,6 +1190,32 @@ long do_memory_op(unsigned long cmd, XEN break; } +#ifdef HAS_PASSTHROUGH + case XENMEM_reserved_device_memory_map: + { + struct get_reserved_device_memory grdm; + + if ( unlikely(start_extent) ) + return -ENOSYS; + + if ( copy_from_guest(&grdm.map, arg, 1) || + !guest_handle_okay(grdm.map.buffer, grdm.map.nr_entries) ) + return -EFAULT; + + grdm.used_entries = 0; + rc = iommu_get_reserved_device_memory(get_reserved_device_memory, + &grdm); + + if ( !rc && grdm.map.nr_entries < grdm.used_entries ) + rc = -ENOBUFS; + grdm.map.nr_entries = grdm.used_entries; + if ( __copy_to_guest(arg, &grdm.map, 1) ) + rc = -EFAULT; + + break; + } +#endif + default: rc = arch_memory_op(cmd, arg); break; --- unstable.orig/xen/drivers/passthrough/iommu.c +++ unstable/xen/drivers/passthrough/iommu.c @@ -344,6 +344,16 @@ void iommu_crash_shutdown(void) iommu_enabled = iommu_intremap = 0; } +int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt) +{ + const struct iommu_ops *ops = iommu_get_ops(); + + if ( !iommu_enabled || !ops->get_reserved_device_memory ) + return 0; + + return ops->get_reserved_device_memory(func, ctxt); +} + bool_t iommu_has_feature(struct domain *d, enum iommu_feature feature) { const struct hvm_iommu *hd = domain_hvm_iommu(d); --- unstable.orig/xen/drivers/passthrough/vtd/dmar.c +++ unstable/xen/drivers/passthrough/vtd/dmar.c @@ -893,3 +893,20 @@ int platform_supports_x2apic(void) unsigned int mask = ACPI_DMAR_INTR_REMAP | ACPI_DMAR_X2APIC_OPT_OUT; return cpu_has_x2apic && ((dmar_flags & mask) == ACPI_DMAR_INTR_REMAP); } + +int intel_iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt) +{ + struct acpi_rmrr_unit *rmrr; + int rc = 0; + + list_for_each_entry(rmrr, &acpi_rmrr_units, list) + { + rc = func(PFN_DOWN(rmrr->base_address), + PFN_UP(rmrr->end_address) - PFN_DOWN(rmrr->base_address), + ctxt); + if ( rc ) + break; + } + + return rc; +} --- unstable.orig/xen/drivers/passthrough/vtd/extern.h +++ unstable/xen/drivers/passthrough/vtd/extern.h @@ -75,6 +75,7 @@ int domain_context_mapping_one(struct do u8 bus, u8 devfn, const struct pci_dev *); int domain_context_unmap_one(struct domain *domain, struct iommu *iommu, u8 bus, u8 devfn); +int intel_iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt); unsigned int io_apic_read_remap_rte(unsigned int apic, unsigned int reg); void io_apic_write_remap_rte(unsigned int apic, --- unstable.orig/xen/drivers/passthrough/vtd/iommu.c +++ unstable/xen/drivers/passthrough/vtd/iommu.c @@ -2491,6 +2491,7 @@ const struct iommu_ops intel_iommu_ops = .crash_shutdown = vtd_crash_shutdown, .iotlb_flush = intel_iommu_iotlb_flush, .iotlb_flush_all = intel_iommu_iotlb_flush_all, + .get_reserved_device_memory = intel_iommu_get_reserved_device_memory, .dump_p2m_table = vtd_dump_p2m_table, }; --- unstable.orig/xen/include/public/memory.h +++ unstable/xen/include/public/memory.h @@ -573,7 +573,29 @@ struct xen_vnuma_topology_info { typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t; DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t); -/* Next available subop number is 27 */ +/* + * With some legacy devices, certain guest-physical addresses cannot safely + * be used for other purposes, e.g. to map guest RAM. This hypercall + * enumerates those regions so the toolstack can avoid using them. + */ +#define XENMEM_reserved_device_memory_map 27 +struct xen_reserved_device_memory { + xen_pfn_t start_pfn; + xen_ulong_t nr_pages; +}; +typedef struct xen_reserved_device_memory xen_reserved_device_memory_t; +DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_t); + +struct xen_reserved_device_memory_map { + /* IN/OUT */ + unsigned int nr_entries; + /* OUT */ + XEN_GUEST_HANDLE(xen_reserved_device_memory_t) buffer; +}; +typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t; +DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_map_t); + +/* Next available subop number is 28 */ #endif /* __XEN_PUBLIC_MEMORY_H__ */ --- unstable.orig/xen/include/xen/iommu.h +++ unstable/xen/include/xen/iommu.h @@ -121,6 +121,14 @@ void iommu_dt_domain_destroy(struct doma struct page_info; +/* + * Any non-zero value returned from callbacks of this type will cause the + * function the callback was handed to terminate its iteration. Assigning + * meaning of these non-zero values is left to the top level caller / + * callback pair. + */ +typedef int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, void *ctxt); + struct iommu_ops { int (*init)(struct domain *d); void (*hwdom_init)(struct domain *d); @@ -152,12 +160,14 @@ struct iommu_ops { void (*crash_shutdown)(void); void (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count); void (*iotlb_flush_all)(struct domain *d); + int (*get_reserved_device_memory)(iommu_grdm_t *, void *); void (*dump_p2m_table)(struct domain *d); }; void iommu_suspend(void); void iommu_resume(void); void iommu_crash_shutdown(void); +int iommu_get_reserved_device_memory(iommu_grdm_t *, void *); void iommu_share_p2m_table(struct domain *d); --- unstable.orig/xen/include/xlat.lst +++ unstable/xen/include/xlat.lst @@ -61,9 +61,10 @@ ! memory_exchange memory.h ! memory_map memory.h ! memory_reservation memory.h -? mem_access_op memory.h +? mem_access_op memory.h ! pod_target memory.h ! remove_from_physmap memory.h +! reserved_device_memory_map memory.h ? vmemrange memory.h ! vnuma_topology_info memory.h ? physdev_eoi physdev.h _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |