From patchwork Fri Jan 11 14:12:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 1966351 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CDCA8DF2A2 for ; Fri, 11 Jan 2013 14:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753542Ab3AKONJ (ORCPT ); Fri, 11 Jan 2013 09:13:09 -0500 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:47383 "EHLO e28smtp03.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752103Ab3AKONH (ORCPT ); Fri, 11 Jan 2013 09:13:07 -0500 Received: from /spool/local by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 Jan 2013 19:41:49 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp03.in.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 11 Jan 2013 19:41:47 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id D0C65394004D; Fri, 11 Jan 2013 19:43:00 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0BECxKG41222344; Fri, 11 Jan 2013 19:42:59 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0BECxel030294; Sat, 12 Jan 2013 01:13:00 +1100 Received: from localhost.localdomain ([9.123.236.83]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0BECwYe030188; Sat, 12 Jan 2013 01:12:58 +1100 Message-ID: <50F01DEA.6000005@linux.vnet.ibm.com> Date: Fri, 11 Jan 2013 22:12:58 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 MIME-Version: 1.0 To: Marcelo Tosatti CC: Gleb Natapov , LKML , KVM Subject: [PATCH v5 6/5] KVM: x86: clear write_fault_to_shadow_pgtable explicitly References: <50EBBE54.1040007@linux.vnet.ibm.com> <50EBBEEC.2060100@linux.vnet.ibm.com> <20130110173036.GB24703@amt.cnet> <50EF056B.4040803@linux.vnet.ibm.com> <20130111131511.GA18558@amt.cnet> In-Reply-To: <20130111131511.GA18558@amt.cnet> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13011114-3864-0000-0000-0000065D48DF Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 01/11/2013 09:15 PM, Marcelo Tosatti wrote: > > This is cryptic. Its not obvious at all for someone modifying the code, > for example. > > Can you please clear it explicitly? Sure, this is the patch to apply your idea, is it good to you? :) ============================================ Subject: [PATCH 6/6] KVM: x86: clear write_fault_to_shadow_pgtable explicitly Clear it explicitly when exiting x86_emulate_instruction to clarify the code, it is suggested by Marcelo Signed-off-by: Xiao Guangrong --- arch/x86/kvm/x86.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2957012..89d01a8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4753,7 +4753,8 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu) return r; } -static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t cr2) +static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t cr2, + bool write_fault_to_shadow_pgtable) { gpa_t gpa = cr2; pfn_t pfn; @@ -4816,7 +4817,7 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t cr2) * be fixed by unprotecting shadow page and it should * be reported to userspace. */ - return !vcpu->arch.write_fault_to_shadow_pgtable; + return !write_fault_to_shadow_pgtable; } static bool retry_instruction(struct x86_emulate_ctxt *ctxt, @@ -4875,7 +4876,13 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, int r; struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; bool writeback = true; + bool write_fault_to_spt = vcpu->arch.write_fault_to_shadow_pgtable; + /* + * Clear write_fault_to_shadow_pgtable here to ensure it is + * never reused. + */ + vcpu->arch.write_fault_to_shadow_pgtable = false; kvm_clear_exception_queue(vcpu); if (!(emulation_type & EMULTYPE_NO_DECODE)) { @@ -4894,7 +4901,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, if (r != EMULATION_OK) { if (emulation_type & EMULTYPE_TRAP_UD) return EMULATE_FAIL; - if (reexecute_instruction(vcpu, cr2)) + if (reexecute_instruction(vcpu, cr2, + write_fault_to_spt)) return EMULATE_DONE; if (emulation_type & EMULTYPE_SKIP) return EMULATE_FAIL; @@ -4924,7 +4932,7 @@ restart: return EMULATE_DONE; if (r == EMULATION_FAILED) { - if (reexecute_instruction(vcpu, cr2)) + if (reexecute_instruction(vcpu, cr2, write_fault_to_spt)) return EMULATE_DONE; return handle_emulation_failure(vcpu);