From patchwork Wed Aug 30 17:11:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9930275 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 457A460383 for ; Wed, 30 Aug 2017 17:14:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A31F28538 for ; Wed, 30 Aug 2017 17:14:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EFE6285AD; Wed, 30 Aug 2017 17:14:19 +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=-4.2 required=2.0 tests=BAYES_00, 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 B8B8628538 for ; Wed, 30 Aug 2017 17:14:18 +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 1dn6Wq-0002GW-2S; Wed, 30 Aug 2017 17:11:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dn6Wo-0002GE-F9 for xen-devel@lists.xenproject.org; Wed, 30 Aug 2017 17:11:46 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 03/82-03093-1D1F6A95; Wed, 30 Aug 2017 17:11:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUvfix2W RBie6OC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1owJnxoZCw4pVRycvoW5gXGJZBcjJ4eEgL/E 1Tv9TCA2m4CyxM/OXjYQW0RAT6LpwHNGEJtZIE/i7OpFrCC2sICvxKsdi8DqWQRUJZb9eMECY vMKmEv0L5/JCDFTXmJX20Wwek4BC4l3E5vBaoSAanoP3WGEsBUkOqYfY4LoFZQ4OfMJC8QuCY mDL14wT2DknYUkNQtJagEj0ypGjeLUorLUIl1DY72kosz0jJLcxMwcXUMDM73c1OLixPTUnMS kYr3k/NxNjMDgYQCCHYxflgUcYpTkYFIS5ZV9syxSiC8pP6UyI7E4I76oNCe1+BCjDAeHkgTv 23dAOcGi1PTUirTMHGAYw6QlOHiURHhngaR5iwsSc4sz0yFSpxgVpcR5pd8DJQRAEhmleXBts Ni5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHeBSDjeTLzSuCmvwJazAS0ONZrKcjikkSElF QD45Y1B10M9nCp3U1u3HFn8yUfTg9LpWkL3832+9H0ur83oGJlxLwS1h0rLtb9ktPUZZIRuKu kInhB5g3PFsa7vVMv1p/d3h7fnzgz9Nz7af/9v1gJ1XhozjmZxB/NN/HomyMxUn75C3YuSqlM kV7YVNst5yu8bk4Ff8uuP2ktlUuLfb0s+Z2llFiKMxINtZiLihMB/D706JgCAAA= X-Env-Sender: prvs=408b96340=wei.liu2@citrix.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1504113102!104705165!2 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 5823 invoked from network); 30 Aug 2017 17:11:44 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 30 Aug 2017 17:11:44 -0000 X-IronPort-AV: E=Sophos;i="5.41,449,1498521600"; d="scan'208";a="437496771" From: Wei Liu To: Xen-devel Date: Wed, 30 Aug 2017 18:11:11 +0100 Message-ID: <20170830171112.3634-3-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170830171112.3634-1-wei.liu2@citrix.com> References: <20170830171112.3634-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH 2/3] x86/mm: don't wrap x86_emulate_ctxt in ptwr_emulate_ctxt 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 Rewrite the code so that it has the same structure as mmio_ro_emualte_ctxt. The new code doesn't contain x86_emulate_ctxt anymore but a pointer to the x86_emulate_ctxt; x86_emulate_ctxt now also points to ptwr_emulate_ctxt via its data pointer. This patch will help unify mmio_ro and ptwr code paths later. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index ed80df02fa..5b840cc603 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4956,9 +4956,9 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) */ struct ptwr_emulate_ctxt { - struct x86_emulate_ctxt ctxt; unsigned long cr2; l1_pgentry_t pte; + struct x86_emulate_ctxt *ctxt; }; static int ptwr_emulated_read( @@ -5018,7 +5018,7 @@ static int ptwr_emulated_update( { x86_emul_pagefault(0, /* Read fault. */ addr + sizeof(paddr_t) - rc, - &ptwr_ctxt->ctxt); + ptwr_ctxt->ctxt); return X86EMUL_EXCEPTION; } /* Mask out bits provided by caller. */ @@ -5133,9 +5133,7 @@ static int ptwr_emulated_write( memcpy(&val, p_data, bytes); - return ptwr_emulated_update( - offset, 0, val, bytes, 0, - container_of(ctxt, struct ptwr_emulate_ctxt, ctxt)); + return ptwr_emulated_update(offset, 0, val, bytes, 0, ctxt->data); } static int ptwr_emulated_cmpxchg( @@ -5158,9 +5156,7 @@ static int ptwr_emulated_cmpxchg( memcpy(&old, p_old, bytes); memcpy(&new, p_new, bytes); - return ptwr_emulated_update( - offset, old, new, bytes, 1, - container_of(ctxt, struct ptwr_emulate_ctxt, ctxt)); + return ptwr_emulated_update(offset, old, new, bytes, 1, ctxt->data); } static const struct x86_emulate_ops ptwr_emulate_ops = { @@ -5179,14 +5175,14 @@ int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, struct domain *d = v->domain; struct page_info *page; l1_pgentry_t pte; - struct ptwr_emulate_ctxt ptwr_ctxt = { - .ctxt = { - .regs = regs, - .vendor = d->arch.cpuid->x86_vendor, - .addr_size = is_pv_32bit_domain(d) ? 32 : BITS_PER_LONG, - .sp_size = is_pv_32bit_domain(d) ? 32 : BITS_PER_LONG, - .lma = !is_pv_32bit_domain(d), - }, + struct ptwr_emulate_ctxt ptwr_ctxt; + struct x86_emulate_ctxt ctxt = { + .regs = regs, + .vendor = d->arch.cpuid->x86_vendor, + .addr_size = is_pv_32bit_domain(d) ? 32 : BITS_PER_LONG, + .sp_size = is_pv_32bit_domain(d) ? 32 : BITS_PER_LONG, + .lma = !is_pv_32bit_domain(d), + .data = &ptwr_ctxt, }; int rc; @@ -5213,10 +5209,13 @@ int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, goto bail; } - ptwr_ctxt.cr2 = addr; - ptwr_ctxt.pte = pte; + ptwr_ctxt = (struct ptwr_emulate_ctxt) { + .cr2 = addr, + .pte = pte, + .ctxt = &ctxt + }; - rc = x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops); + rc = x86_emulate(&ctxt, &ptwr_emulate_ops); page_unlock(page); put_page(page); @@ -5231,18 +5230,18 @@ int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, * emulation bug, or a guest playing with the instruction stream under * Xen's feet. */ - if ( ptwr_ctxt.ctxt.event.type == X86_EVENTTYPE_HW_EXCEPTION && - ptwr_ctxt.ctxt.event.vector == TRAP_page_fault ) - pv_inject_event(&ptwr_ctxt.ctxt.event); + if ( ctxt.event.type == X86_EVENTTYPE_HW_EXCEPTION && + ctxt.event.vector == TRAP_page_fault ) + pv_inject_event(&ctxt.event); else gdprintk(XENLOG_WARNING, "Unexpected event (type %u, vector %#x) from emulation\n", - ptwr_ctxt.ctxt.event.type, ptwr_ctxt.ctxt.event.vector); + ctxt.event.type, ctxt.event.vector); /* Fallthrough */ case X86EMUL_OKAY: - if ( ptwr_ctxt.ctxt.retire.singlestep ) + if ( ctxt.retire.singlestep ) pv_inject_hw_exception(TRAP_debug, X86_EVENT_NO_EC); /* Fallthrough */