From patchwork Thu Aug 31 11:22:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9931923 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 9ABAC602F0 for ; Thu, 31 Aug 2017 11:24:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EADE288D7 for ; Thu, 31 Aug 2017 11:24:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FBF6288DF; Thu, 31 Aug 2017 11:24:55 +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 1408D28897 for ; Thu, 31 Aug 2017 11:24:54 +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 1dnNYM-0002TA-5h; Thu, 31 Aug 2017 11:22:30 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dnNYK-0002Sy-LZ for xen-devel@lists.xenproject.org; Thu, 31 Aug 2017 11:22:28 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 1A/E0-03414-471F7A95; Thu, 31 Aug 2017 11:22:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUrf44/J Ig/edChbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b5s5uZCl6pVtyfsY+1gfGxdBcjJ4eEgL/E k66ZrCA2m4CyxM/OXjYQW0RAT6LpwHNGEJtZIE/i7OpFYDXCAgESN54vBathEVCV+NHzCKyGV 8BCYvrfGWwQM+UldrVdBKvnFLCUuNU/iQnEFgKqef3nBiuErSDRMf0YE0SvoMTJmU9YIHZJSB x88YJ5AiPvLCSpWUhSCxiZVjFqFKcWlaUW6Rob6SUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCY V6yXn525iBAYPAxDsYDy9LvAQoyQHk5Io78PbyyOF+JLyUyozEosz4otKc1KLDzHKcHAoSfDu fg+UEyxKTU+tSMvMAYYxTFqCg0dJhFflA1Cat7ggMbc4Mx0idYpRUUqcVwMkIQCSyCjNg2uDx c4lRlkpYV5GoEOEeApSi3IzS1DlXzGKczAqCfOqg0zhycwrgZv+CmgxE9DiWK+lIItLEhFSUg 2MimfOlc1cPvN3csHT+DMm8ktCllmxqu7bfGMqo+pR+/+fgwqSA7lS33X8bSvYLVfta+RaFdG 6ML7U4jS3brbYe+Fn7J8PH9dmiS3dk+4Z3HPovqP+lzfbXraq/zttZa6bvIZ76joDVvbu4rkr mtleveVY0r/Y8NX3tkf/l9cvOXxUyODJtVtnlViKMxINtZiLihMBrl+iMJgCAAA= X-Env-Sender: prvs=4097f923a=wei.liu2@citrix.com X-Msg-Ref: server-16.tower-21.messagelabs.com!1504178545!68501308!1 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 43569 invoked from network); 31 Aug 2017 11:22:27 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-16.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 31 Aug 2017 11:22:27 -0000 X-IronPort-AV: E=Sophos;i="5.41,453,1498521600"; d="scan'208";a="437815619" From: Wei Liu To: Xen-devel Date: Thu, 31 Aug 2017 12:22:22 +0100 Message-ID: <20170831112223.24761-2-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170831112223.24761-1-wei.liu2@citrix.com> References: <20170831112223.24761-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v2 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 --- v2: do away with pointer in ptwr_emulate_ctxt --- xen/arch/x86/mm.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index f4b9747aba..3306088255 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; @@ -5221,10 +5217,12 @@ 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, + }; - rc = x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops); + rc = x86_emulate(&ctxt, &ptwr_emulate_ops); page_unlock(page); put_page(page); @@ -5239,18 +5237,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 */