From: Tiejun Chen Subject: [v7][RFC][PATCH 08/13] xen/x86/p2m: set p2m_access_n for reserved device memory mapping Date: Fri, 24 Oct 2014 15:34:32 +0800 Message-ID: <1414136077-18599-9-git-send-email-tiejun.chen@intel.com> References: <1414136077-18599-1-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1414136077-18599-1-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: JBeulich@suse.com, tim@xen.org, konrad.wilk@oracle.com, kevin.tian@intel.com, yang.z.zhang@intel.com Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org In case of shared-ept or non-shared-ept but 1:1 mapping, we need to set p2m_access_n to make sure all reserved device memory can't be accessed by any !iommu approach. Signed-off-by: Tiejun Chen --- xen/arch/x86/mm/p2m.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index efa49dd..97eb6fd 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -686,6 +686,30 @@ guest_physmap_add_entry(struct domain *d, unsigned long gfn, /* Now, actually do the two-way mapping */ if ( mfn_valid(_mfn(mfn)) ) { + + if ( !is_hardware_domain(d) ) + { + rc = iommu_get_reserved_device_memory(p2m_check_reserved_device_memory, + &gfn); + if ( rc ) + { + /* + * Just set p2m_access_n in case of shared-ept + * or non-shared ept but 1:1 mapping. + */ + if ( iommu_use_hap_pt(d) || + (!iommu_use_hap_pt(d) && mfn == gfn) ) + { + rc = p2m_set_entry(p2m, gfn, _mfn(mfn), page_order, t, + p2m_access_n); + if ( rc ) + gdprintk(XENLOG_WARNING, "set rdm p2m failed: (%#lx)\n", + gfn); + goto out; /* Failed to update rdm p2m. */ + } + } + } + rc = p2m_set_entry(p2m, gfn, _mfn(mfn), page_order, t, p2m->default_access); if ( rc ) -- 1.9.1