> -----Original Message----- > From: Jan Beulich [mailto:jbeul...@suse.com] > Sent: 19 March 2018 15:14 > To: Paul Durrant <paul.durr...@citrix.com> > Cc: Andrew Cooper <andrew.coop...@citrix.com>; Wei Liu > <wei.l...@citrix.com>; George Dunlap <george.dun...@citrix.com>; Ian > Jackson <ian.jack...@citrix.com>; Stefano Stabellini > <sstabell...@kernel.org>; xen-devel@lists.xenproject.org; Konrad Rzeszutek > Wilk <konrad.w...@oracle.com>; Tim (Xen.org) <t...@xen.org> > Subject: Re: [PATCH 6/7] x86: add iommu_op to query reserved ranges > > >>> On 12.02.18 at 11:47, <paul.durr...@citrix.com> wrote: > > --- a/xen/arch/x86/iommu_op.c > > +++ b/xen/arch/x86/iommu_op.c > > @@ -22,6 +22,58 @@ > > #include <xen/event.h> > > #include <xen/guest_access.h> > > #include <xen/hypercall.h> > > +#include <xen/iommu.h> > > + > > +struct get_rdm_ctxt { > > + unsigned int max_entries; > > + unsigned int nr_entries; > > + XEN_GUEST_HANDLE(xen_iommu_reserved_region_t) regions; > > +}; > > + > > +static int get_rdm(xen_pfn_t start, xen_ulong_t nr, u32 id, void *arg) > > +{ > > + struct get_rdm_ctxt *ctxt = arg; > > + > > + if ( ctxt->nr_entries < ctxt->max_entries ) > > + { > > + xen_iommu_reserved_region_t region = { > > + .start_bfn = start, > > + .nr_frames = nr, > > + }; > > + > > + if ( copy_to_guest_offset(ctxt->regions, ctxt->nr_entries, ®ion, > > + 1) ) > > + return -EFAULT; > > + } > > + > > + ctxt->nr_entries++; > > + > > + return 1; > > +} > > + > > +static int iommuop_query_reserved(struct > xen_iommu_op_query_reserved *op) > > +{ > > + struct get_rdm_ctxt ctxt = { > > + .max_entries = op->nr_entries, > > + .regions = op->regions, > > + }; > > + int rc; > > + > > + if (op->pad != 0) > > + return -EINVAL; > > + > > + rc = iommu_get_reserved_device_memory(get_rdm, &ctxt); > > + if ( rc ) > > + return rc; > > + > > + /* Pass back the actual number of reserved regions */ > > + op->nr_entries = ctxt.nr_entries; > > + > > + if ( ctxt.nr_entries > ctxt.max_entries ) > > + return -ENOBUFS; > > + > > + return 0; > > +} > > One more note here: As it looks we can only hope there won't be > too many RMRRs, as the number of entries that can be requested > here is basically unbounded. >
The caller has to be able to allocate a buffer large enough but, yes there is no explicit limit. I'll add pre-empt checks. Paul > Jan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel