From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Rzeszutek Wilk Subject: Re: [v8][PATCH 13/17] xen/mem_access: don't allow accessing reserved device memory Date: Tue, 2 Dec 2014 15:27:22 -0500 Message-ID: <20141202202722.GK357@laptop.dumpdata.com> References: <1417425875-9634-1-git-send-email-tiejun.chen@intel.com> <1417425875-9634-14-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1417425875-9634-14-git-send-email-tiejun.chen@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: kevin.tian@intel.com, wei.liu2@citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, tim@xen.org, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, jbeulich@suse.com, yang.z.zhang@intel.com List-Id: xen-devel@lists.xenproject.org On Mon, Dec 01, 2014 at 05:24:31PM +0800, Tiejun Chen wrote: > We can't expost those reserved device memory in case of mem_access s/expost/expose/ > since any access may corrupt device usage. Could you explain this in more details please? > > Signed-off-by: Tiejun Chen > --- > xen/common/mem_access.c | 41 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/xen/common/mem_access.c b/xen/common/mem_access.c > index 6c2724b..72a807a 100644 > --- a/xen/common/mem_access.c > +++ b/xen/common/mem_access.c > @@ -55,6 +55,43 @@ void mem_access_resume(struct domain *d) > } > } > > +/* We can't expose reserved device memory. */ > +static int mem_access_check_rdm(struct domain *d, uint64_aligned_t start, > + uint32_t nr) > +{ > + uint32_t i; > + struct p2m_get_reserved_device_memory pgrdm; > + int rc = 0; > + > + if ( !is_hardware_domain(d) && iommu_use_hap_pt(d) ) > + { > + for ( i = 0; i < nr; i++ ) > + { > + pgrdm.gfn = start + i; > + pgrdm.domain = d; > + rc = iommu_get_reserved_device_memory(p2m_check_reserved_device_memory, > + &pgrdm); > + if ( rc < 0 ) > + { > + printk(XENLOG_WARNING > + "Domain %d can't check reserved device memory.\n", > + d->domain_id); > + return rc; > + } > + > + if ( rc == 1 ) > + { > + printk(XENLOG_WARNING > + "Domain %d: we shouldn't mem_access reserved device memory.\n", > + d->domain_id); > + return rc; > + } > + } > + } > + > + return rc; > +} > + > int mem_access_memop(unsigned long cmd, > XEN_GUEST_HANDLE_PARAM(xen_mem_access_op_t) arg) > { > @@ -99,6 +136,10 @@ int mem_access_memop(unsigned long cmd, > ((mao.pfn + mao.nr - 1) > domain_get_maximum_gpfn(d))) ) > break; > > + rc = mem_access_check_rdm(d, mao.pfn, mao.nr); > + if ( rc == 1 ) > + break; > + > rc = p2m_set_mem_access(d, mao.pfn, mao.nr, start_iter, > MEMOP_CMD_MASK, mao.access); > if ( rc > 0 ) > -- > 1.9.1 >