From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
LKML <linux-kernel@vger.kernel.org>, KVM <kvm@vger.kernel.org>
Subject: [PATCH v2 02/12] KVM: x86: tag the instructions which are used to write page table
Date: Tue, 02 Aug 2011 19:07:31 +0800 [thread overview]
Message-ID: <4E37DA73.7010908@cn.fujitsu.com> (raw)
In-Reply-To: <4E37DA49.1040000@cn.fujitsu.com>
The idea is from Avi:
| tag instructions that are typically used to modify the page tables, and drop
| shadow if any other instruction is used
| The list would include, I'd guess, and, or, bts, btc, mov, xchg, cmpxchg, and
| cmpxchg8b
This patch is used to tag the instructions and in the later path, shadow page
is dropped if it is written by other instructions
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
arch/x86/include/asm/kvm_emulate.h | 1 +
arch/x86/kvm/emulate.c | 8 ++++++++
arch/x86/kvm/x86.c | 1 +
arch/x86/kvm/x86.h | 5 +++++
4 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index 6040d11..049a6f5 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -244,6 +244,7 @@ struct x86_emulate_ctxt {
bool guest_mode; /* guest running a nested guest */
bool perm_ok; /* do not check permissions if true */
bool only_vendor_specific_insn;
+ bool page_table_written_insn;
bool have_exception;
struct x86_exception exception;
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 0453c07..3c027ac 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2516,6 +2516,7 @@ static int em_add(struct x86_emulate_ctxt *ctxt)
static int em_or(struct x86_emulate_ctxt *ctxt)
{
emulate_2op_SrcV("or", ctxt->src, ctxt->dst, ctxt->eflags);
+ tag_page_table_written_insn(ctxt);
return X86EMUL_CONTINUE;
}
@@ -2534,6 +2535,7 @@ static int em_sbb(struct x86_emulate_ctxt *ctxt)
static int em_and(struct x86_emulate_ctxt *ctxt)
{
emulate_2op_SrcV("and", ctxt->src, ctxt->dst, ctxt->eflags);
+ tag_page_table_written_insn(ctxt);
return X86EMUL_CONTINUE;
}
@@ -2572,6 +2574,7 @@ static int em_xchg(struct x86_emulate_ctxt *ctxt)
/* Write back the memory destination with implicit LOCK prefix. */
ctxt->dst.val = ctxt->src.orig_val;
ctxt->lock_prefix = 1;
+ tag_page_table_written_insn(ctxt);
return X86EMUL_CONTINUE;
}
@@ -2610,6 +2613,7 @@ static int em_rdtsc(struct x86_emulate_ctxt *ctxt)
static int em_mov(struct x86_emulate_ctxt *ctxt)
{
ctxt->dst.val = ctxt->src.val;
+ tag_page_table_written_insn(ctxt);
return X86EMUL_CONTINUE;
}
@@ -4135,6 +4139,7 @@ twobyte_insn:
break;
case 0xab:
bts: /* bts */
+ tag_page_table_written_insn(ctxt);
emulate_2op_SrcV_nobyte("bts", ctxt->src, ctxt->dst, ctxt->eflags);
break;
case 0xac: /* shrd imm8, r, r/m */
@@ -4148,6 +4153,7 @@ twobyte_insn:
* Save real source value, then compare EAX against
* destination.
*/
+ tag_page_table_written_insn(ctxt);
ctxt->src.orig_val = ctxt->src.val;
ctxt->src.val = ctxt->regs[VCPU_REGS_RAX];
emulate_2op_SrcV("cmp", ctxt->src, ctxt->dst, ctxt->eflags);
@@ -4192,6 +4198,7 @@ twobyte_insn:
break;
case 0xbb:
btc: /* btc */
+ tag_page_table_written_insn(ctxt);
emulate_2op_SrcV_nobyte("btc", ctxt->src, ctxt->dst, ctxt->eflags);
break;
case 0xbc: { /* bsf */
@@ -4235,6 +4242,7 @@ twobyte_insn:
(u64) ctxt->src.val;
break;
case 0xc7: /* Grp9 (cmpxchg8b) */
+ tag_page_table_written_insn(ctxt);
rc = em_grp9(ctxt);
break;
default:
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ea8f9f0..cf6fb29 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4831,6 +4831,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
ctxt->interruptibility = 0;
ctxt->have_exception = false;
ctxt->perm_ok = false;
+ ctxt->page_table_written_insn = false;
ctxt->only_vendor_specific_insn
= emulation_type & EMULTYPE_TRAP_UD;
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index d36fe23..b6e868f 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -111,6 +111,11 @@ static inline bool vcpu_match_mmio_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)
return false;
}
+static inline void tag_page_table_written_insn(struct x86_emulate_ctxt *ctxt)
+{
+ ctxt->page_table_written_insn = true;
+}
+
void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
--
1.7.5.4
next prev parent reply other threads:[~2011-08-02 11:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 11:06 [PATCH v2 01/12] KVM: MMU: avoid pte_list_desc run out in kvm_mmu_pte_write Xiao Guangrong
2011-08-02 11:07 ` Xiao Guangrong [this message]
2011-08-02 12:20 ` [PATCH v2 02/12] KVM: x86: tag the instructions which are used to write page table Avi Kivity
2011-08-03 6:02 ` Xiao Guangrong
2011-08-03 8:09 ` Avi Kivity
2011-08-03 9:24 ` Xiao Guangrong
2011-08-03 9:25 ` Avi Kivity
2011-08-03 9:41 ` Xiao Guangrong
2011-08-03 9:40 ` Avi Kivity
2011-08-02 11:08 ` [PATCH v2 03/12] zap sp if it is written by unaware instructions Xiao Guangrong
2011-08-02 11:08 ` [PATCH v2 04/12] KVM: x86: cleanup port-in/port-out emulated Xiao Guangrong
2011-08-02 11:09 ` [PATCH v2 05/12] KVM: x86: fast emulate repeat string write instructions Xiao Guangrong
2011-08-03 8:10 ` Avi Kivity
2011-08-03 9:31 ` Xiao Guangrong
2011-08-02 11:09 ` [PATCH v2 06/12] KVM: MMU: do not mark access bit on pte write path Xiao Guangrong
2011-08-02 11:10 ` [PATCH v2 07/12] KVM: MMU: cleanup FNAME(invlpg) Xiao Guangrong
2011-08-02 11:10 ` [PATCH v2 08/12] KVM: MMU: fast prefetch spte on invlpg path Xiao Guangrong
2011-08-02 18:36 ` Marcelo Tosatti
2011-08-03 6:03 ` Xiao Guangrong
2011-08-02 11:11 ` [PATCH v2 09/12] KVM: MMU: remove unnecessary kvm_mmu_free_some_pages Xiao Guangrong
2011-08-02 11:11 ` [PATCH v2 10/12] KVM: MMU: split kvm_mmu_pte_write function Xiao Guangrong
2011-08-02 11:12 ` [PATCH v2 11/12] KVM: MMU: fix detecting misaligned accessed Xiao Guangrong
2011-08-02 11:13 ` [PATCH v2 12/12] KVM: MMU: improve write flooding detected Xiao Guangrong
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=4E37DA73.7010908@cn.fujitsu.com \
--to=xiaoguangrong@cn.fujitsu.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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