From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754634AbdK2Lor (ORCPT ); Wed, 29 Nov 2017 06:44:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60872 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582AbdK2Lop (ORCPT ); Wed, 29 Nov 2017 06:44:45 -0500 Subject: Re: [PATCH] KVM: x86: inject exceptions produced by x86_decode_insn To: Eduardo Habkost Cc: Wanpeng Li , "linux-kernel@vger.kernel.org" , kvm , yfu@redhat.com References: <1510307378-97452-1-git-send-email-pbonzini@redhat.com> <4ff4d2f3-439b-2a8f-ef89-b2a1984e809d@redhat.com> <20171129114411.GA16634@localhost.localdomain> From: Paolo Bonzini Message-ID: <4a61fa0a-a4ca-4c06-63c9-2b940eac2601@redhat.com> Date: Wed, 29 Nov 2017 12:44:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171129114411.GA16634@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 29 Nov 2017 11:44:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/11/2017 12:44, Eduardo Habkost wrote: > On Mon, Nov 13, 2017 at 09:32:09AM +0100, Paolo Bonzini wrote: >> On 13/11/2017 08:15, Wanpeng Li wrote: >>> 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. >> >> Hmm, you're right. Looks like Yanan has been (un)lucky when trying out >> this patch! :( >> >> Yanan, can you double check that you can reproduce the issue with an >> unpatched kernel? I will work on a kvm-unit-tests testcsae > > We don't have a kvm-unit-tests reproducer for this yet, right? > > I'm considering trying to write one, but I don't want to > duplicate work. No, I haven't written one yet. Paolo