From patchwork Tue Oct 10 16:31:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9998107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A9D6A603B5 for ; Tue, 10 Oct 2017 22:55:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9634828801 for ; Tue, 10 Oct 2017 22:55:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B15528806; Tue, 10 Oct 2017 22:55:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6F5D287F3 for ; Tue, 10 Oct 2017 22:55:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e23O8-00024V-A5; Tue, 10 Oct 2017 22:52:36 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e23O7-00023t-9p for xen-devel@lists.xenproject.org; Tue, 10 Oct 2017 22:52:35 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id FC/57-30115-23F4DD95; Tue, 10 Oct 2017 22:52:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrohUtfI/26 kwadN7Bbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8banjmsBT+1Kz7suMTUwNiq0MXIySEh4C9x 4cYDFhCbTUBHYurTS6xdjBwcIgIqErf3GnQxcnEwCxxlkjg6+xkbSFxYIFii71oMSDmLgKpE+ 96nLCBhXgFriQmfPCEmykvsarvICmJzCthIPFzSwghiCwGVrHvdyARhq0isnzqLDcTmFRCUOD nzCdgFzAISEgdfvGCewMg7C0lqFpLUAkamVYwaxalFZalFuoYGeklFmekZJbmJmTlAnplebmp xcWJ6ak5iUrFecn7uJkZg4DAAwQ7G4+/jDjFKcjApifK+Vr8bKcSXlJ9SmZFYnBFfVJqTWnyI UYaDQ0mC18kPKCdYlJqeWpGWmQMMYZi0BAePkghvri9Qmre4IDG3ODMdInWKUZej4+bdP0xCL Hn5ealS4rxXQYoEQIoySvPgRsDi6RKjrJQwLyPQUUI8BalFuZklqPKvGMU5GJWEefVALuHJzC uB2/QK6AgmoCNE0+6AHFGSiJCSamCcZqojK7wyOGPT6++JMw7nJ/t//dkuNJVfTf6f2NPoKRv /fX7kz7N+VqWzhsql/Ms9f6a8Pv/G4u/3TKcDTasPtl/m5ortPdLH/WfvltX2m/bH529sPu9h PFP8ff3dyHm+4ncOsOy5yFFm/0xYSm7WplmrzS9x98pkxlZe3t7EcoS7aNOrR/YMSizFGYmGW sxFxYkANMTJ6qICAAA= X-Env-Sender: prvs=4497f262f=Paul.Durrant@citrix.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1507675950!109598780!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3437 invoked from network); 10 Oct 2017 22:52:33 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 10 Oct 2017 22:52:33 -0000 X-IronPort-AV: E=Sophos;i="5.43,359,1503360000"; d="scan'208";a="445201185" From: Paul Durrant To: Date: Tue, 10 Oct 2017 17:31:22 +0100 Message-ID: <20171010163126.2558-8-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171010163126.2558-1-paul.durrant@citrix.com> References: <20171010163126.2558-1-paul.durrant@citrix.com> MIME-Version: 1.0 Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Paul Durrant Subject: [Xen-devel] [PATCH v10 07/11] x86/mm: add an extra command to HYPERVISOR_mmu_update... X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ...to allow the calling domain to prevent translation of specified l1e value. Despite what the comment in public/xen.h might imply, specifying a command value of MMU_NORMAL_PT_UPDATE will not simply update an l1e with the specified value. Instead, mod_l1_entry() tests whether foreign_dom has PG_translate set in its paging mode and, if it does, assumes that the the pfn value in the l1e is a gfn rather than an mfn. To allow PV tools domain to map mfn values from a previously issued HYPERVISOR_memory_op:XENMEM_acquire_resource, there needs to be a way to tell HYPERVISOR_mmu_update that the specific l1e value does not require translation regardless of the paging mode of foreign_dom. This patch therefore defines a new command value, MMU_PT_UPDATE_NO_TRANSLATE, which has the same semantics as MMU_NORMAL_PT_UPDATE except that the paging mode of foreign_dom is ignored and the l1e value is used verbatim. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu v8: - New in this version, replacing "allow a privileged PV domain to map guest mfns". --- xen/arch/x86/mm.c | 17 ++++++++++------- xen/include/public/xen.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index c9bc4a4e92..3dd5b2c00f 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1619,9 +1619,10 @@ void page_unlock(struct page_info *page) /* Update the L1 entry at pl1e to new value nl1e. */ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, - unsigned long gl1mfn, int preserve_ad, + unsigned long gl1mfn, unsigned int cmd, struct vcpu *pt_vcpu, struct domain *pg_dom) { + bool preserve_ad = (cmd == MMU_PT_UPDATE_PRESERVE_AD); l1_pgentry_t ol1e; struct domain *pt_dom = pt_vcpu->domain; int rc = 0; @@ -1643,7 +1644,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, return -EINVAL; } - if ( paging_mode_translate(pg_dom) ) + if ( cmd != MMU_PT_UPDATE_NO_TRANSLATE && + paging_mode_translate(pg_dom) ) { page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), NULL, P2M_ALLOC); if ( !page ) @@ -3258,6 +3260,7 @@ long do_mmu_update( */ case MMU_NORMAL_PT_UPDATE: case MMU_PT_UPDATE_PRESERVE_AD: + case MMU_PT_UPDATE_NO_TRANSLATE: { p2m_type_t p2mt; @@ -3323,7 +3326,8 @@ long do_mmu_update( p2m_query_t q = (l1e_get_flags(l1e) & _PAGE_RW) ? P2M_UNSHARE : P2M_ALLOC; - if ( paging_mode_translate(pg_owner) ) + if ( cmd != MMU_PT_UPDATE_NO_TRANSLATE && + paging_mode_translate(pg_owner) ) target = get_page_from_gfn(pg_owner, l1e_get_pfn(l1e), &l1e_p2mt, q); @@ -3350,9 +3354,7 @@ long do_mmu_update( break; } - rc = mod_l1_entry(va, l1e, mfn, - cmd == MMU_PT_UPDATE_PRESERVE_AD, v, - pg_owner); + rc = mod_l1_entry(va, l1e, mfn, cmd, v, pg_owner); if ( target ) put_page(target); } @@ -3630,7 +3632,8 @@ static int __do_update_va_mapping( goto out; } - rc = mod_l1_entry(pl1e, val, mfn_x(gl1mfn), 0, v, pg_owner); + rc = mod_l1_entry(pl1e, val, mfn_x(gl1mfn), MMU_NORMAL_PT_UPDATE, v, + pg_owner); page_unlock(gl1pg); put_page(gl1pg); diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index 2ac6b1e24d..d2014a39eb 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -268,6 +268,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed * with those in @val. * + * ptr[1:0] == MMU_PT_UPDATE_NO_TRANSLATE: + * As MMU_NORMAL_PT_UPDATE above, but @val is not translated though FD + * page tables. + * * @val is usually the machine frame number along with some attributes. * The attributes by default follow the architecture defined bits. Meaning that * if this is a X86_64 machine and four page table layout is used, the layout @@ -334,9 +338,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); * * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7. */ -#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ -#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ -#define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */ +#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ +#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ +#define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */ +#define MMU_PT_UPDATE_NO_TRANSLATE 3 /* checked '*ptr = val'. prt is MA. */ + /* val never translated. */ /* * MMU EXTENDED OPERATIONS