Received: by 10.223.164.202 with SMTP id h10csp2961040wrb; Sun, 12 Nov 2017 23:16:38 -0800 (PST) X-Google-Smtp-Source: AGs4zMah5eVJ5p3JvNMqGNdcb08nD4lpqimc3j0pCjhQqpKPcOLmNU+QQp2ucqJei5uO36jkXZoG X-Received: by 10.84.135.3 with SMTP id 3mr8003849pli.147.1510557398642; Sun, 12 Nov 2017 23:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510557398; cv=none; d=google.com; s=arc-20160816; b=yRbbTCuO4PD4tqBObnoMgGMXI+Jq90D6KA7mXXsby0wPoTvdsAg08iVYcEUMOs1/3y Tv1qwLS+RLW0DW+bnUJtwJuZ4ag/YEKsyfAzPX1expS88unw4XE2OfWgGh4TdCvtXHcK g0Td8JtFeFc0FMu48RbWYJ+YPdtLwDwrUIsE+QuAAzfFLKMEaPed+UB3n3f6axBRgXCv 6+x5PMlykynhBhSRXimenAMCOzVAlm/634yPtWS+ck5bhUFH7hDsn9l+nk7OvIh4aXiB Wr1fv7PbHHsGU2vADaWZzOoQX2g+dQIwVvMKvSPkYWcUuMppmVbF/ZDaVkKla1QjnLeK FBgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=T13HTqIlJv5xfeQEwHl1gLvPa27P9nKehejUx5gf8NY=; b=H70PrervNF61VMHRkN6Kd3hquu5Ya76epqbkClwxee/f/iALQSkSo6OGmgocuVHD2+ +3ilGOaMREh3hMGftZlH1+psxJazJ4ZTKEVC6HklW+SczNmL84PVnBdpwzHw9AQz19VL vA1UrQOlzQ/Bn2fhU5ZP4k6RjNsFG0pt6g0/YpXygUf9dyuHCqXld2TphmkVlXWYurc1 gNT36xAHZBgiBIkDzq/DXh+rUD2IHsthEnpKwQz+44jJ8wrw7Cuz+4ZqTa43KWZ9UppS 0AaI7LAMRxjN1VWCyl7YVVquu3Ogt7NLqVoLaS/TWKq3/Ky4lGPZONJSmtbMcUPrk1PW qnVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tEqe6Q4C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si13754942plz.564.2017.11.12.23.16.26; Sun, 12 Nov 2017 23:16:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tEqe6Q4C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751910AbdKMHPq (ORCPT + 89 others); Mon, 13 Nov 2017 02:15:46 -0500 Received: from mail-oi0-f68.google.com ([209.85.218.68]:55993 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751553AbdKMHPo (ORCPT ); Mon, 13 Nov 2017 02:15:44 -0500 Received: by mail-oi0-f68.google.com with SMTP id v123so488450oif.12; Sun, 12 Nov 2017 23:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=T13HTqIlJv5xfeQEwHl1gLvPa27P9nKehejUx5gf8NY=; b=tEqe6Q4C0NCntI4RqhEuECf696E0RobfOarL/m3ioTRSnt+ou0qMw58INbJk1G+Amc i8QbfmIRFnzYzCwyMkioAqHiw4/0ZJz98LoYo69Y7Nu0oDv2GPCzgnEYVr9SOGpXocuk eHkIk/xsJk5It0VbA9I8ME+EME8KKNXUzhlsXq0Z9yeFWHYPZ1dS3megIOYYZN4suSZx es+7n+bb6ntLH9WR5wPGSp7jDCMiB8z+scjYghCL53Rm1/JwylKAfnN282JYn4piZtcY LTcs23oQUtKgisnIGSjZIaFVBtLO2Euc85OtqamtJdLKHh8iceZ2Y5kzMAF2KAlNsLu0 YY2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=T13HTqIlJv5xfeQEwHl1gLvPa27P9nKehejUx5gf8NY=; b=YhvddKtgS40NnpgvTLjLeAhmjbRNfTVXRShoILrK09fPQF4AB5EdzHOXh0Vkb1swsf HKuH8GClL/rMhYTnNOAqHn0VvJCDh2r4embcmGVXpLw6i5Yg4XNk0cr6fLKArkq/a0+O aGP+usstBpmWAfosZ+eBtcnfrofGZKxViLGnSOUuewxxW9PpHNBFZw2dnEmnHjprH2Jq gW7JJErFNyxNYMAzTcA1Hrg3mbAE/kQX0RHc/wDnp8aJK196PthavCVgwM97BZl+Fi2g YXH3c1dJKXfvjV0Z6DQ7l8ZscQ/dqNP2IutqNyu2JztN37KILXHt5ZTgF9CHv+gwyiT6 t5mQ== X-Gm-Message-State: AJaThX5NxiLU+/cRecfoUnfTkEqKQSdRfG4pLMjWmdq22lE6mOgvVxIK UWeN4inkIsQYBodEHanC8uCji0VFnGZHqqyjZjY= X-Received: by 10.202.205.193 with SMTP id d184mr4771406oig.333.1510557344216; Sun, 12 Nov 2017 23:15:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.53.27 with HTTP; Sun, 12 Nov 2017 23:15:43 -0800 (PST) In-Reply-To: <1510307378-97452-1-git-send-email-pbonzini@redhat.com> References: <1510307378-97452-1-git-send-email-pbonzini@redhat.com> From: Wanpeng Li Date: Mon, 13 Nov 2017 15:15:43 +0800 Message-ID: Subject: Re: [PATCH] KVM: x86: inject exceptions produced by x86_decode_insn To: Paolo Bonzini Cc: "linux-kernel@vger.kernel.org" , kvm , yfu@redhat.com, Eduardo Habkost , "# v3 . 10+" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-10 17:49 GMT+08:00 Paolo Bonzini : > Sometimes, a processor might execute an instruction while another > processor is updating the page tables for that instruction's code page, > but before the TLB shootdown completes. The interesting case happens > if the page is in the TLB. > > In general, the processor will succeed in executing the instruction and > nothing bad happens. However, what if the instruction is an MMIO access? > If *that* happens, KVM invokes the emulator, and the emulator gets the > updated page tables. If the update side had marked the code page as non > present, the page table walk then will fail and so will x86_decode_insn. > > Unfortunately, even though kvm_fetch_guest_virt is correctly returning > X86EMUL_PROPAGATE_FAULT, x86_decode_insn's caller treats the failure as > a fatal error if the instruction cannot simply be reexecuted (as is the > case for MMIO). And this in fact happened sometimes when rebooting > Windows 2012r2 guests. Just checking ctxt->have_exception and injecting > the exception if true is enough to fix the case. I found the only place which can set ctxt->have_exception is in the function x86_emulate_insn(), and x86_decode_insn() will not set ctxt->have_exception even if kvm_fetch_guest_virt() returns X86_EMUL_PROPAGATE_FAULT. Regards, Wanpeng Li > > Thanks to Eduardo Habkost for helping in the debugging of this issue. > > Reported-by: Yanan Fu > Cc: Eduardo Habkost > Cc: stable@vger.kernel.org > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 34c85aa2e2d1..6dbed9022797 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -5722,6 +5722,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, > if (reexecute_instruction(vcpu, cr2, write_fault_to_spt, > emulation_type)) > return EMULATE_DONE; > + if (ctxt->have_exception && inject_emulated_exception(vcpu)) > + return EMULATE_DONE; > if (emulation_type & EMULTYPE_SKIP) > return EMULATE_FAIL; > return handle_emulation_failure(vcpu); > -- > 1.8.3.1 > From 1583716958069911059@xxx Fri Nov 10 21:43:07 +0000 2017 X-GM-THRID: 1583672192246103487 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread