From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v2 1/2] x86/mm: don't wrap x86_emulate_ctxt in ptwr_emulate_ctxt
Date: Thu, 31 Aug 2017 12:22:22 +0100 [thread overview]
Message-ID: <20170831112223.24761-2-wei.liu2@citrix.com> (raw)
In-Reply-To: <20170831112223.24761-1-wei.liu2@citrix.com>
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 <wei.liu2@citrix.com>
---
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 */
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-08-31 11:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 11:22 [PATCH v2 0/2] x86/mm: merge ptwr and mmio_ro page fault handlers Wei Liu
2017-08-31 11:22 ` Wei Liu [this message]
2017-08-31 12:37 ` [PATCH v2 1/2] x86/mm: don't wrap x86_emulate_ctxt in ptwr_emulate_ctxt Andrew Cooper
2017-09-01 9:16 ` Jan Beulich
2017-08-31 11:22 ` [PATCH v2 2/2] x86/mm: merge ptwr and mmio_ro page fault handlers Wei Liu
2017-09-01 9:38 ` Jan Beulich
2017-09-01 13:46 ` Wei Liu
2017-09-01 13:50 ` Wei Liu
2017-09-01 15:29 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170831112223.24761-2-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).