Received: by 10.223.164.202 with SMTP id h10csp419926wrb; Thu, 30 Nov 2017 01:21:15 -0800 (PST) X-Google-Smtp-Source: AGs4zMYRvPiS/Q3PkXtxluUcao65EvSvYQtX/P4D2qBCCU1t0a9LeBCNo+YSYQPm2Ff/y5qvELqX X-Received: by 10.98.9.209 with SMTP id 78mr5958510pfj.59.1512033675425; Thu, 30 Nov 2017 01:21:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512033675; cv=none; d=google.com; s=arc-20160816; b=g7y51GSbsv26dvqZaRjvm5fUb2IVpuK6U95cWRdp6/LmL35FIXs3PbbBfUvg0EvXoa gStu94DNh9o3YdRp1CeBGA9fLXt4x4km25L8ZBRRjImG8N4IdJMpIABNekq3GhDCSZ3/ mS4EoduAU0IUhHqSXidBtS0u5MjqLgS0rQ2XZ2tJ+n3EEZWtRLwx6SCkKL6NGXCf6rS9 vWlnCjwmVDND3rr9D/4URiGPWC0jFjX7JBTRVR/fIiXsFnywg3dqu/J4jHuq4ZOueCCM yisme//ZrpE5dCjY7jcESh/rFEZDGe/ApeIGtKJSlYHAeT8BDoYkCsU16po0k5eae7Xa En1g== 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=4djTIfaUL/RWVFRXLDSa6vQtmkrOxYtlYf2hQykZU58=; b=ZtTkdMJByRE1gTE5W6CLN7EAoH+k8VmEismk6OdKn92s9KhHKzO/hUkg9mIqoU3WuD Kucs6sS2RH2CjtzZ2+fAZprYlsMLIDBRil2oVqZgPkWQczM6hZlQh+MyRcub85VHshkb Y+adsayQNf17VDXGX/kMH/9+AY9DDNjM3Va3slrqesUitKuetMM6Lq8h3dC1CHu+Q01q VOGTP+VYIoFw05yk2oaCR6xk36RsGnTza1AmMbisLQnnrrlVXDOTOf/Re+Bbx7YAG2NW 4v9n1DknIt3e9lp4036/dQ0wDmeNrvPLwYWN4L9UFuNKo66hnT4UUhRuKETYPtnF5B+h +TSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BguA0qJ2; 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 v196si1946812pgb.825.2017.11.30.01.21.02; Thu, 30 Nov 2017 01:21:15 -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=BguA0qJ2; 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 S1752077AbdK3JUP (ORCPT + 99 others); Thu, 30 Nov 2017 04:20:15 -0500 Received: from mail-ot0-f169.google.com ([74.125.82.169]:35055 "EHLO mail-ot0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdK3JUN (ORCPT ); Thu, 30 Nov 2017 04:20:13 -0500 Received: by mail-ot0-f169.google.com with SMTP id q3so5552226oth.2; Thu, 30 Nov 2017 01:20:13 -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=4djTIfaUL/RWVFRXLDSa6vQtmkrOxYtlYf2hQykZU58=; b=BguA0qJ2uqhunjk0mLMp1DwGxOrCL9gaJ0wS0fbAE/G46zjs5Q4MMONQzMzRiTEfWt EEQJX1NCc7fQhkRM5ADdUYd7JVw3tX8fZH51kf5tTC4d/Y4xVePHzNERn53Tpmt5YZpi avM5ZXF07H17OW/5V005Y+bQLYBewE7L4+TBFQ2+tsHzsPrl3dVggK6V6TuzUINbOvdl 3qKY9IBkTUy0Xj4Uck7gGom4UtUbGGs30vrFeYz7o/z7BV4p6Kq/yOt/JzfSXZIj9KeP qEg+0JPVYTnaoQgAZGh6GaUDN6vQ/gGfdePSflBo4Ju3kxxO2Elc0SIKnheDKzGBXFBY MdUg== 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=4djTIfaUL/RWVFRXLDSa6vQtmkrOxYtlYf2hQykZU58=; b=myHgkh5h5q5llxSE3H3hd+Cx5wsSxD8E+cqpBtj3ZCEMttcPikiP8wwAyVXCUT6vHM cyhoTFTFUf2j4Oam2UxaNx9G2OicxwlfJsUoIfG6iLxJg5IVBIZKzvXJjN3DxaplsOQr EkOS7xqxbfpfAiMma7AFnyFFDfUaHGIm1BDElpDeFNyP/JXCiY30YurgRSmy3oGhlfWA F6955W8qS9sht2gWDssD/pEWgNgGAl8oF6fr2NvgEV7/oahSWFM8UroqMpaG/uOj4Qiv pFygy4z6ljmErK5MfhqSPR5dXPkOVpIGQyAdV1uSnS5RfdV1B+SQhCbLG0vDJ8MwHspJ NSyQ== X-Gm-Message-State: AJaThX4zgvpWlklsaxL0tr+lkN/GltGR1LHs9zyLMBtEgX1VEPhQM9E1 InGAgtRWx6Y24z4Gcf1zLT8b3RsXfdoSbeVa5K0= X-Received: by 10.157.54.37 with SMTP id w34mr4339311otb.201.1512033612743; Thu, 30 Nov 2017 01:20:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.209.8 with HTTP; Thu, 30 Nov 2017 01:20:12 -0800 (PST) In-Reply-To: <20171129184216.GC3037@localhost.localdomain> References: <1510307378-97452-1-git-send-email-pbonzini@redhat.com> <4ff4d2f3-439b-2a8f-ef89-b2a1984e809d@redhat.com> <20171129114411.GA16634@localhost.localdomain> <4a61fa0a-a4ca-4c06-63c9-2b940eac2601@redhat.com> <20171129184216.GC3037@localhost.localdomain> From: Wanpeng Li Date: Thu, 30 Nov 2017 17:20:12 +0800 Message-ID: Subject: Re: [PATCH] KVM: x86: inject exceptions produced by x86_decode_insn To: Eduardo Habkost Cc: Paolo Bonzini , "linux-kernel@vger.kernel.org" , kvm , yfu@redhat.com 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-30 2:42 GMT+08:00 Eduardo Habkost : > On Wed, Nov 29, 2017 at 12:44:42PM +0100, Paolo Bonzini wrote: >> 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. > > The reproducer (not a full test case) is quite simple, see patch below. I can also have a look if there is a formal test case. :) Regards, Wanpeng Li From 1585443902659860332@xxx Wed Nov 29 23:12:10 +0000 2017 X-GM-THRID: 1583672192246103487 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread