From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BB33C433FE for ; Mon, 6 Dec 2021 17:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239460AbhLFR0U (ORCPT ); Mon, 6 Dec 2021 12:26:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239283AbhLFR0T (ORCPT ); Mon, 6 Dec 2021 12:26:19 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29931C061746 for ; Mon, 6 Dec 2021 09:22:50 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id i12so10783487pfd.6 for ; Mon, 06 Dec 2021 09:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=e4v6IKiW/2WlbASsvrvF2UTULHy1m6fHcEIgOmsmgnI=; b=NgWpG1PfIksDugSwjn0vSFOwpf7eoIHnHW1dTEJlxDOr14pHVHjuU3ZWJYo8nhSREw wORI/+Jr6dN58hMsmwYXSwCT+fVa2fb4EbGQBOx6nexwBFGboAhvZOXjOIMrUWIp+NsF 1kzczu/D31wau2OYK0MQwWwKJ7f+2YdCTz0blWWLLLQeCtIzYS5rAlYyE6UhlABTVNnV RF+aOThFdVI3o+blg8LW6IBCb0XJvcpVvipZqW9rD6zu0ODObFjm2aylUKCvkXTgq/n5 EsKSJeImQWl2Mox7vHpVbDfl3rPTcZW4p6V7TpublXSaaiG0RP8XrANvLZlGKVLL/Qpn DVrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=e4v6IKiW/2WlbASsvrvF2UTULHy1m6fHcEIgOmsmgnI=; b=B1+DEtJtm4G5kYyxe+dQZ3Q5gWmyWFXE/6kiVI3XsZ2OifNcUpndBcYvaNY9YUe6LC W2WPZC1J2l0eE1KZVkmbuNh2sjWyF7XAcnYHUT5z1jSUUcB05wF+BcnOTa5TuRe29hMz KDRSuw5j5KA451GlxL/igqjxOuYt12ZkJ3L1ClYDbcVTtVi61pKFUvgcsy+IfuX1FBMN yoOT1NIbWsx62+pU5X29+m8VyR7RSzQ/X9MggSZtQqEPSZPeJhpKAKh0bphepogdY8Xp Xjo1s0Ah8Rz7saNGoh6sHiO49E2LWV3QOY8Ca9cmszOb6Scl08C4HkASob9i9BPDSbdo nfHQ== X-Gm-Message-State: AOAM532FB+kJNgXqZKBfq/zlT8+eKER2diFb/syKlcb8UmmBYCTnGIk6 YcIi4o9sixIjYNl605b2SVlhMQ== X-Google-Smtp-Source: ABdhPJy9GZqYqYpevufXjYQIZ/YpPacZwnffWH1X44rpkphLcq/o2EAlO3xFyWmJ//FGEG/zaZVs5w== X-Received: by 2002:a63:1b1c:: with SMTP id b28mr19749416pgb.288.1638811369405; Mon, 06 Dec 2021 09:22:49 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id j6sm12586661pfu.205.2021.12.06.09.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 09:22:48 -0800 (PST) Date: Mon, 6 Dec 2021 17:22:45 +0000 From: Sean Christopherson To: Vitaly Kuznetsov Cc: Maxim Levitsky , kvm@vger.kernel.org, jmattson@google.com, syzbot , bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, joro@8bytes.org, linux-kernel@vger.kernel.org, mingo@redhat.com, pbonzini@redhat.com, syzkaller-bugs@googlegroups.com, tglx@linutronix.de, wanpengli@tencent.com, x86@kernel.org Subject: Re: [syzbot] WARNING in nested_vmx_vmexit Message-ID: References: <00000000000051f90e05d2664f1d@google.com> <87bl1u6qku.fsf@redhat.com> <87k0gh675j.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 06, 2021, Sean Christopherson wrote: > On Mon, Dec 06, 2021, Vitaly Kuznetsov wrote: > > Sean Christopherson writes: > > > I objected to the patch[*], but looking back at the dates, it appears that I did > > > so after the patch was queued and my comments were never addressed. > > > I'll see if I can reproduce this with a selftest. The fix is likely just: > > > > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > > > index dc4909b67c5c..927a7c43b73b 100644 > > > --- a/arch/x86/kvm/vmx/vmx.c > > > +++ b/arch/x86/kvm/vmx/vmx.c > > > @@ -6665,10 +6665,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) > > > * consistency check VM-Exit due to invalid guest state and bail. > > > */ > > > if (unlikely(vmx->emulation_required)) { > > > - > > > - /* We don't emulate invalid state of a nested guest */ > > > - vmx->fail = is_guest_mode(vcpu); > > > - > > > vmx->exit_reason.full = EXIT_REASON_INVALID_STATE; > > > vmx->exit_reason.failed_vmentry = 1; > > > kvm_register_mark_available(vcpu, VCPU_EXREG_EXIT_INFO_1); > > > > > > [*] https://lore.kernel.org/all/YWDWPbgJik5spT1D@google.com/ > > > > Let's also summon Max to the discussion to get his thoughts. > > Thinking more on this, we should do three things: Doh, hit send too soon. s/three/five, I'm not _that_ bad at math... > 1. Revert this part back to "vmx->fail = 0". > > 2. Override SS.RPL and CS.RPL on RSM for VMX. Not sure this is strictly > necessary, I'm struggling to remember how SS.RPL and SS.DPL can get out of > sync. > > IF RFLAGS.VM = 0 AND (in VMX root operation OR the “unrestricted guest” > VM-execution control is 0) > THEN > CS.RPL := SS.DPL; > SS.RPL := SS.DPL; > FI; > > 3. Modify RSM to go into TRIPLE_FAULT if vmx->emulation_required is true after > loading state for RSM. On AMD, whose SMRAM KVM emulates, all segment state > is read-only, i.e. if it's modified to be invalid then KVM essentially do > whatever it wants. > > 4. Reject KVM_RUN if is_guest_mode() and vmx->emulation_required are true. By > handling the RSM case explicitly, this means userspace has attempted to run > L2 with garbage, which KVM most definitely doesn't want to support. > > 5. Add KVM_BUG_ON(is_guest_mode(vcpu), ...) in the emulation_required path in > vmx_vcpu_run(), as reaching that point means KVM botched VM-Enter, RSM or > the #4 above.