From patchwork Fri Sep 1 14:35:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9934387 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 D1BBE60216 for ; Fri, 1 Sep 2017 14:37:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4A982860E for ; Fri, 1 Sep 2017 14:37:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B962D28687; Fri, 1 Sep 2017 14:37:53 +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 07E392860E for ; Fri, 1 Sep 2017 14:37:50 +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 1dnn2z-0000os-C6; Fri, 01 Sep 2017 14:35:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dnn2y-0000oQ-0G for xen-devel@lists.xenproject.org; Fri, 01 Sep 2017 14:35:48 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id DF/94-03642-34079A95; Fri, 01 Sep 2017 14:35:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXtepYGW kQctEPYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWP38rvMBf9UK65t3MDUwDhFpouRk0NCwF/i 6MuNjCA2m4CyxM/OXjYQW0RAT6LpwHOwOLNAnsTZ1YtYQWxhgQCJjweXsoDYLAIqEqde/ASze QUsJH4sus0GMVNeYlfbRbB6TgFLifl7F7OD2EJANTPu3IWyFSQ6ph9jgugVlDg58wkLxC4JiY MvXjBPYOSdhSQ1C0lqASPTKkaN4tSistQiXWNDvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKR iveT83E2MwOBhAIIdjE2LAg8xSnIwKYnyVvuviBTiS8pPqcxILM6ILyrNSS0+xCjDwaEkwSue vzJSSLAoNT21Ii0zBxjGMGkJDh4lEd6OPKA0b3FBYm5xZjpE6hSjopQ470GQhABIIqM0D64NF juXGGWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJMw7C2QKT2ZeCdz0V0CLmYAW//u8AmRxSSJCSq qBkaOpzSL7a+j/j9MiZpa2Lmc+YXTzQdndJ87fTQv3zGP9efvmjNsV1ifqeVI/uvWV1DA96tz RvuTs1J8O/6c3GzlU/+Kce2iW24UXNj9Wh/KF7J3zpsK2bM+ZueHTnsae2qe5VeXub5aGyKV3 m2+XuL+S7ctfYjvtQ/uP9JlPuBRPNbLtntvJ0ajEUpyRaKjFXFScCACvZEMjmAIAAA== X-Env-Sender: prvs=410f0257c=wei.liu2@citrix.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1504276544!109999093!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55491 invoked from network); 1 Sep 2017 14:35:46 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 1 Sep 2017 14:35:46 -0000 X-IronPort-AV: E=Sophos;i="5.41,458,1498521600"; d="scan'208";a="446218613" From: Wei Liu To: Xen-devel Date: Fri, 1 Sep 2017 15:35:38 +0100 Message-ID: <20170901143539.13276-2-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170901143539.13276-1-wei.liu2@citrix.com> References: <20170901143539.13276-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v3 1/2] 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. x86_emulate_ctxt now 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 Reviewed-by: Andrew Cooper --- v3: drop unnecessary hunk, but kept Andrew's Rb because the patch is not essentially changed. v2: do away with pointer in ptwr_emulate_ctxt --- xen/arch/x86/mm.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index f4b9747aba..8831f06605 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4964,7 +4964,6 @@ 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; }; @@ -4995,7 +4994,7 @@ static int ptwr_emulated_update( paddr_t val, unsigned int bytes, unsigned int do_cmpxchg, - struct ptwr_emulate_ctxt *ptwr_ctxt) + struct x86_emulate_ctxt *ctxt) { unsigned long mfn; unsigned long unaligned_addr = addr; @@ -5003,6 +5002,7 @@ static int ptwr_emulated_update( l1_pgentry_t pte, ol1e, nl1e, *pl1e; struct vcpu *v = current; struct domain *d = v->domain; + struct ptwr_emulate_ctxt *ptwr_ctxt = ctxt->data; int ret; /* Only allow naturally-aligned stores within the original %cr2 page. */ @@ -5026,7 +5026,7 @@ static int ptwr_emulated_update( { x86_emul_pagefault(0, /* Read fault. */ addr + sizeof(paddr_t) - rc, - &ptwr_ctxt->ctxt); + ctxt); return X86EMUL_EXCEPTION; } /* Mask out bits provided by caller. */ @@ -5141,9 +5141,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); } static int ptwr_emulated_cmpxchg( @@ -5166,9 +5164,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); } static const struct x86_emulate_ops ptwr_emulate_ops = { @@ -5187,14 +5183,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; @@ -5224,7 +5220,7 @@ int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, ptwr_ctxt.cr2 = addr; ptwr_ctxt.pte = pte; - rc = x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops); + rc = x86_emulate(&ctxt, &ptwr_emulate_ops); page_unlock(page); put_page(page); @@ -5239,18 +5235,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 */