Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp935034ybl; Wed, 28 Aug 2019 07:24:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpKZd2sEWG6B0oE3vkqmo/LirRmMq5dkALw3aoXBhVaEZAOwF8PtDuUdNxOyGH7LO1d6gj X-Received: by 2002:a63:de4f:: with SMTP id y15mr3813684pgi.239.1567002296094; Wed, 28 Aug 2019 07:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567002296; cv=none; d=google.com; s=arc-20160816; b=0Dx1snw8VYpcXHuwAdMjmbI5nIoBfe3g0IxheuAVED2e4DiPTxvGFCB0k1QpOrvZsK fH5k6QKwUVlwMcCHEMkVFkZzZlIUNO7OXnXiTOvGS66Krpq5KZlZeII8D6uornuMj9f4 GeBEQGoK4AZjcAEHuNq2lVp5l5zzV8vTUvizkdrFIu3GvOnaZC+8Q2e2+sCna9Kqmt8B UIwU9JQPWrbojdcEKTR7lwaj0COqDvsokAUtEni3RmdMyIN443cET0uX2InWZocCNKLu xC7BQSTZU4byDS9hq0XEUgg+doElR5TMW2c30g1flrjXhMtfZjSSyYbM94J2EFaqW6PF nP4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/DJhoMT4VOPi3UV+iTzV52nYiyQ6WCA+x4xm1bdYzdc=; b=DGpcFGhnrE6RjjWo5rZ96SbJO8y5szgdfYXB0Y3jxpCWz3JWzN7DxE4Jev+YDWtoHn zahRoAmHvbdsJpW9rAVsyxg7iVX4dZoCutEEx1Fj0vGDgIr1WglLF9hdudREb8s8/dy9 64xxE/BtK4UYCcsKoP2LP8HQcdmg8s3qb9EZ9cnXjLTRaYpJPksNLdHDNOXPz0Sx0wd7 KOnTqImdlsEXwezeqkpt/74Lh705TsoEPZ83Jd/gU9EtlEw3B34RLla+uVyXpahqAK0H 66n3LDqU24yrcdAbty0IHFD9Mh1jOMNEp7jgh9MWQY3a4jK1lTKVrA9rE/LBGqvS1OGb lbKA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 185si2219609pgc.522.2019.08.28.07.24.37; Wed, 28 Aug 2019 07:24:56 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726555AbfH1OXn (ORCPT + 99 others); Wed, 28 Aug 2019 10:23:43 -0400 Received: from mga12.intel.com ([192.55.52.136]:63432 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfH1OXn (ORCPT ); Wed, 28 Aug 2019 10:23:43 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2019 07:23:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,441,1559545200"; d="scan'208";a="210181730" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga002.fm.intel.com with ESMTP; 28 Aug 2019 07:23:40 -0700 Date: Wed, 28 Aug 2019 07:23:40 -0700 From: Sean Christopherson To: Jan Dakinevich Cc: "linux-kernel@vger.kernel.org" , Denis Lunev , Roman Kagan , Denis Plotnikov , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "kvm@vger.kernel.org" , Yi Wang , Peng Hao Subject: Re: [PATCH 3/3] KVM: x86: always stop emulation on page fault Message-ID: <20190828142340.GA21651@linux.intel.com> References: <1566911210-30059-1-git-send-email-jan.dakinevich@virtuozzo.com> <1566911210-30059-4-git-send-email-jan.dakinevich@virtuozzo.com> <20190827145030.GC27459@linux.intel.com> <20190828131948.cb67f97cab502b9f5f63b1b8@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828131948.cb67f97cab502b9f5f63b1b8@virtuozzo.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 28, 2019 at 10:19:51AM +0000, Jan Dakinevich wrote: > On Tue, 27 Aug 2019 07:50:30 -0700 > Sean Christopherson wrote: > > Yikes, this patch and the previous have quite the sordid history. > > > > > > The non-void return from inject_emulated_exception() was added by commit > > > > ef54bcfeea6c ("KVM: x86: skip writeback on injection of nested exception") > > > > for the purpose of skipping writeback. At the time, the above blob in the > > decode flow didn't exist. > > > > > > Decode exception handling was added by commit > > > > 6ea6e84309ca ("KVM: x86: inject exceptions produced by x86_decode_insn") > > > > but it was dead code even then. The patch discussion[1] even point out that > > it was dead code, i.e. the change probably should have been reverted. > > > > > > Peng Hao and Yi Wang later ran into what appears to be the same bug you're > > hitting[2][3], and even had patches temporarily queued[4][5], but the > > patches never made it to mainline as they broke kvm-unit-tests. Fun side > > note, Radim even pointed out[4] the bug fixed by patch 1/3. > > > > So, the patches look correct, but there's the open question of why the > > hypercall test was failing for Paolo. > > Sorry, I'm little confused. Could you please, point me which test or tests > were broken? I've just run kvm-unit-test and I see same results with and > without my changes. > > > I've tried to reproduce the #DF to > > no avail. Aha! The #DF occurs if patch 2/3, but not patch 3/3, is applied, and the VMware backdoor is enabled. The backdoor is off by default, which is why only Paolo was seeing the #DF. To handle the VMware backdoor, KVM intercepts #GP faults, which includes the non-canonical #GP from the hypercall unit test. With only patch 2/3 applied, x86_emulate_instruction() injects a #GP for the non-canonical RIP but returns EMULATE_FAIL instead of EMULATE_DONE. EMULATE_FAIL causes handle_exception_nmi() (or gp_interception() for SVM) to re-inject the original #GP because it thinks emulation failed due to a non-VMware opcode. Applying patch 3/3 resolves the issue as x86_emulate_instruction() returns EMULATE_DONE after injecting the #GP. TL;DR: Swap the order of patches and everything should be hunky dory. Please rebase to the latest kvm/queue, which has an equivalent to patch 1/3.