From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: Re: [RFC][PATCH 02/13] introduce XENMEM_reserved_device_memory_map Date: Fri, 24 Apr 2015 08:21:34 +0100 Message-ID: <553A0B1E0200007800075742@mail.emea.novell.com> References: <1428657724-3498-1-git-send-email-tiejun.chen@intel.com> <1428657724-3498-3-git-send-email-tiejun.chen@intel.com> <20150416145916.GF13441@deinos.phlegethon.org> <552FED140200007800072D70@mail.emea.novell.com> <5538E640.10008@intel.com> <553908D5020000780007524E@mail.emea.novell.com> <553999AD.7070405@intel.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part043065EE.3__=" Return-path: In-Reply-To: <553999AD.7070405@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Tiejun Chen Cc: Tim Deegan , kevin.tian@intel.com, wei.liu2@citrix.com, ian.campbell@citrix.com, andrew.cooper3@citrix.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org, stefano.stabellini@citrix.com, yang.z.zhang@intel.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part043065EE.3__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 24.04.15 at 03:17, wrote: > On 2015/4/23 20:59, Jan Beulich wrote: >>>>> On 23.04.15 at 14:32, wrote: >>> But if you already have one just please ignore this and tell me >> >> Here's what I currently have: >=20 > Could you resend me this as an attached file? Then I can apply that=20 > properly without any miss? Here you go. Jan --=__Part043065EE.3__= Content-Type: text/plain; name="get-reserved-device-memory.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="get-reserved-device-memory.patch" introduce XENMEM_reserved_device_memory_map=0A=0AThis is a prerequisite = for punching holes into HVM and PVH guests' P2M=0Ato allow passing through = devices that are associated with (on VT-d)=0ARMRRs.=0A=0ASigned-off-by: = Jan Beulich =0AAcked-by: Kevin Tian =0A---=0Av??: Comment iommu_grdm_t typedef. Comment on the purpose of = the new=0A hypercall in the public header. (Both requested by = Tim.)=0A=0A--- unstable.orig/xen/common/compat/memory.c=0A+++ unstable/xen/= common/compat/memory.c=0A@@ -17,6 +17,37 @@ CHECK_TYPE(domid);=0A = CHECK_mem_access_op;=0A CHECK_vmemrange;=0A =0A+#ifdef HAS_PASSTHROUGH=0A+s= truct get_reserved_device_memory {=0A+ struct compat_reserved_device_mem= ory_map map;=0A+ unsigned int used_entries;=0A+};=0A+=0A+static int = get_reserved_device_memory(xen_pfn_t start,=0A+ = xen_ulong_t nr, void *ctxt)=0A+{=0A+ struct get_reserved_devic= e_memory *grdm =3D ctxt;=0A+=0A+ if ( grdm->used_entries < grdm->map.nr_= entries )=0A+ {=0A+ struct compat_reserved_device_memory rdm =3D = {=0A+ .start_pfn =3D start, .nr_pages =3D nr=0A+ = };=0A+=0A+ if ( rdm.start_pfn !=3D start || rdm.nr_pages !=3D nr = )=0A+ return -ERANGE;=0A+=0A+ if ( __copy_to_compat_offse= t(grdm->map.buffer, grdm->used_entries,=0A+ = &rdm, 1) )=0A+ return -EFAULT;=0A+ }=0A+=0A+ = ++grdm->used_entries;=0A+=0A+ return 0;=0A+}=0A+#endif=0A+=0A int = compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)=0A = {=0A int split, op =3D cmd & MEMOP_CMD_MASK;=0A@@ -303,6 +334,29 @@ = int compat_memory_op(unsigned int cmd, X=0A break;=0A = }=0A =0A+#ifdef HAS_PASSTHROUGH=0A+ case XENMEM_reserved_device_memo= ry_map:=0A+ {=0A+ struct get_reserved_device_memory = grdm;=0A+=0A+ if ( copy_from_guest(&grdm.map, compat, 1) ||=0A+ = !compat_handle_okay(grdm.map.buffer, grdm.map.nr_entries) = )=0A+ return -EFAULT;=0A+=0A+ grdm.used_entries = =3D 0;=0A+ rc =3D iommu_get_reserved_device_memory(get_reserved_= device_memory,=0A+ = &grdm);=0A+=0A+ if ( !rc && grdm.map.nr_entries < grdm.used_entr= ies )=0A+ rc =3D -ENOBUFS;=0A+ grdm.map.nr_entrie= s =3D grdm.used_entries;=0A+ if ( __copy_to_guest(compat, = &grdm.map, 1) )=0A+ rc =3D -EFAULT;=0A+=0A+ = return rc;=0A+ }=0A+#endif=0A+=0A default:=0A = return compat_arch_memory_op(cmd, compat);=0A }=0A--- unstable.orig= /xen/common/memory.c=0A+++ unstable/xen/common/memory.c=0A@@ -748,6 = +748,34 @@ static int construct_memop_from_reservat=0A return 0;=0A = }=0A =0A+#ifdef HAS_PASSTHROUGH=0A+struct get_reserved_device_memory {=0A+ = struct xen_reserved_device_memory_map map;=0A+ unsigned int = used_entries;=0A+};=0A+=0A+static int get_reserved_device_memory(xen_pfn_t = start,=0A+ xen_ulong_t nr, void = *ctxt)=0A+{=0A+ struct get_reserved_device_memory *grdm =3D ctxt;=0A+=0A= + if ( grdm->used_entries < grdm->map.nr_entries )=0A+ {=0A+ = struct xen_reserved_device_memory rdm =3D {=0A+ .start_pfn =3D = start, .nr_pages =3D nr=0A+ };=0A+=0A+ if ( __copy_to_guest_o= ffset(grdm->map.buffer, grdm->used_entries,=0A+ = &rdm, 1) )=0A+ return -EFAULT;=0A+ }=0A+=0A+ = ++grdm->used_entries;=0A+=0A+ return 0;=0A+}=0A+#endif=0A+=0A long = do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)=0A {=0A = struct domain *d;=0A@@ -1162,6 +1190,32 @@ long do_memory_op(unsigned = long cmd, XEN=0A break;=0A }=0A =0A+#ifdef HAS_PASSTHROUGH=0A+ = case XENMEM_reserved_device_memory_map:=0A+ {=0A+ struct = get_reserved_device_memory grdm;=0A+=0A+ if ( unlikely(start_extent)= )=0A+ return -ENOSYS;=0A+=0A+ if ( copy_from_guest(&grdm= .map, arg, 1) ||=0A+ !guest_handle_okay(grdm.map.buffer, = grdm.map.nr_entries) )=0A+ return -EFAULT;=0A+=0A+ = grdm.used_entries =3D 0;=0A+ rc =3D iommu_get_reserved_device_memory= (get_reserved_device_memory,=0A+ = &grdm);=0A+=0A+ if ( !rc && grdm.map.nr_entries < grdm.used_entri= es )=0A+ rc =3D -ENOBUFS;=0A+ grdm.map.nr_entries =3D = grdm.used_entries;=0A+ if ( __copy_to_guest(arg, &grdm.map, 1) = )=0A+ rc =3D -EFAULT;=0A+=0A+ break;=0A+ }=0A+#endif= =0A+=0A default:=0A rc =3D arch_memory_op(cmd, arg);=0A = break;=0A--- unstable.orig/xen/drivers/passthrough/iommu.c=0A+++ = unstable/xen/drivers/passthrough/iommu.c=0A@@ -344,6 +344,16 @@ void = iommu_crash_shutdown(void)=0A iommu_enabled =3D iommu_intremap =3D = 0;=0A }=0A =0A+int iommu_get_reserved_device_memory(iommu_grdm_t *func, = void *ctxt)=0A+{=0A+ const struct iommu_ops *ops =3D iommu_get_ops();=0A= +=0A+ if ( !iommu_enabled || !ops->get_reserved_device_memory )=0A+ = return 0;=0A+=0A+ return ops->get_reserved_device_memory(func, = ctxt);=0A+}=0A+=0A bool_t iommu_has_feature(struct domain *d, enum = iommu_feature feature)=0A {=0A const struct hvm_iommu *hd =3D = domain_hvm_iommu(d);=0A--- unstable.orig/xen/drivers/passthrough/vtd/dmar.c= =0A+++ unstable/xen/drivers/passthrough/vtd/dmar.c=0A@@ -893,3 +893,20 @@ = int platform_supports_x2apic(void)=0A unsigned int mask =3D ACPI_DMAR_I= NTR_REMAP | ACPI_DMAR_X2APIC_OPT_OUT;=0A return cpu_has_x2apic && = ((dmar_flags & mask) =3D=3D ACPI_DMAR_INTR_REMAP);=0A }=0A+=0A+int = intel_iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt)=0A+{= =0A+ struct acpi_rmrr_unit *rmrr;=0A+ int rc =3D 0;=0A+=0A+ = list_for_each_entry(rmrr, &acpi_rmrr_units, list)=0A+ {=0A+ rc = =3D func(PFN_DOWN(rmrr->base_address),=0A+ PFN_UP(rmrr->en= d_address) - PFN_DOWN(rmrr->base_address),=0A+ ctxt);=0A+ = if ( rc )=0A+ break;=0A+ }=0A+=0A+ return = rc;=0A+}=0A--- unstable.orig/xen/drivers/passthrough/vtd/extern.h=0A+++ = unstable/xen/drivers/passthrough/vtd/extern.h=0A@@ -75,6 +75,7 @@ int = domain_context_mapping_one(struct do=0A u8 = bus, u8 devfn, const struct pci_dev *);=0A int domain_context_unmap_one(str= uct domain *domain, struct iommu *iommu,=0A = u8 bus, u8 devfn);=0A+int intel_iommu_get_reserved_device_memory(iommu_grdm= _t *func, void *ctxt);=0A =0A unsigned int io_apic_read_remap_rte(unsigned = int apic, unsigned int reg);=0A void io_apic_write_remap_rte(unsigned int = apic,=0A--- unstable.orig/xen/drivers/passthrough/vtd/iommu.c=0A+++ = unstable/xen/drivers/passthrough/vtd/iommu.c=0A@@ -2491,6 +2491,7 @@ const = struct iommu_ops intel_iommu_ops =3D=0A .crash_shutdown =3D vtd_crash_s= hutdown,=0A .iotlb_flush =3D intel_iommu_iotlb_flush,=0A .iotlb_flu= sh_all =3D intel_iommu_iotlb_flush_all,=0A+ .get_reserved_device_memory = =3D intel_iommu_get_reserved_device_memory,=0A .dump_p2m_table =3D = vtd_dump_p2m_table,=0A };=0A =0A--- unstable.orig/xen/include/public/memory= .h=0A+++ unstable/xen/include/public/memory.h=0A@@ -573,7 +573,29 @@ = struct xen_vnuma_topology_info {=0A typedef struct xen_vnuma_topology_info = xen_vnuma_topology_info_t;=0A DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_in= fo_t);=0A =0A-/* Next available subop number is 27 */=0A+/*=0A+ * With = some legacy devices, certain guest-physical addresses cannot safely=0A+ * = be used for other purposes, e.g. to map guest RAM. This hypercall=0A+ * = enumerates those regions so the toolstack can avoid using them.=0A+ = */=0A+#define XENMEM_reserved_device_memory_map 27=0A+struct xen_reserved= _device_memory {=0A+ xen_pfn_t start_pfn;=0A+ xen_ulong_t = nr_pages;=0A+};=0A+typedef struct xen_reserved_device_memory xen_reserved_d= evice_memory_t;=0A+DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_t);= =0A+=0A+struct xen_reserved_device_memory_map {=0A+ /* IN/OUT */=0A+ = unsigned int nr_entries;=0A+ /* OUT */=0A+ XEN_GUEST_HANDLE(xen_reser= ved_device_memory_t) buffer;=0A+};=0A+typedef struct xen_reserved_device_me= mory_map xen_reserved_device_memory_map_t;=0A+DEFINE_XEN_GUEST_HANDLE(xen_r= eserved_device_memory_map_t);=0A+=0A+/* Next available subop number is 28 = */=0A =0A #endif /* __XEN_PUBLIC_MEMORY_H__ */=0A =0A--- unstable.orig/xen/= include/xen/iommu.h=0A+++ unstable/xen/include/xen/iommu.h=0A@@ -121,6 = +121,14 @@ void iommu_dt_domain_destroy(struct doma=0A =0A struct = page_info;=0A =0A+/*=0A+ * Any non-zero value returned from callbacks of = this type will cause the=0A+ * function the callback was handed to = terminate its iteration. Assigning=0A+ * meaning of these non-zero values = is left to the top level caller /=0A+ * callback pair.=0A+ */=0A+typedef = int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, void *ctxt);=0A+=0A = struct iommu_ops {=0A int (*init)(struct domain *d);=0A void = (*hwdom_init)(struct domain *d);=0A@@ -152,12 +160,14 @@ struct iommu_ops = {=0A void (*crash_shutdown)(void);=0A void (*iotlb_flush)(struct = domain *d, unsigned long gfn, unsigned int page_count);=0A void = (*iotlb_flush_all)(struct domain *d);=0A+ int (*get_reserved_device_memo= ry)(iommu_grdm_t *, void *);=0A void (*dump_p2m_table)(struct domain = *d);=0A };=0A =0A void iommu_suspend(void);=0A void iommu_resume(void);=0A = void iommu_crash_shutdown(void);=0A+int iommu_get_reserved_device_memory(io= mmu_grdm_t *, void *);=0A =0A void iommu_share_p2m_table(struct domain = *d);=0A =0A--- unstable.orig/xen/include/xlat.lst=0A+++ unstable/xen/includ= e/xlat.lst=0A@@ -61,9 +61,10 @@=0A ! memory_exchange = memory.h=0A ! memory_map memory.h=0A ! memory_rese= rvation memory.h=0A-? mem_access_op memory.h=0A+? = mem_access_op memory.h=0A ! pod_target = memory.h=0A ! remove_from_physmap memory.h=0A+! reserved_de= vice_memory_map memory.h=0A ? vmemrange memory.h=0A= ! vnuma_topology_info memory.h=0A ? physdev_eoi = physdev.h=0A --=__Part043065EE.3__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part043065EE.3__=--