Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2529947rdb; Fri, 8 Dec 2023 10:39:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOzdGtFC68d7oCWAGAvRgmKy9YGgTXmlWg7Tf0ffvSxtIgNiFnYa/LvRh5ut6jTI4TnuAg X-Received: by 2002:a05:6a21:604:b0:18f:ea5b:6825 with SMTP id ll4-20020a056a21060400b0018fea5b6825mr397222pzb.117.1702060785802; Fri, 08 Dec 2023 10:39:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702060785; cv=none; d=google.com; s=arc-20160816; b=We9pKi9mlgSI9p8AmLgYYBYRxtUE0Vj0+eCqF8cPyNyqSVeDLIpwXBXw2Bs3xasexc YBFquO622SQKfTNOQpNz2YlbVnGptItW53xjERQIjugWeDjRZWFed5yyI6GllVfGRsxJ cB2fTHw4fRBtXEGJ2hp7I7YM8mEuWUT83x+wQ9EhRjNEc7aRhknpKyLP+3aVJS9FkWjI Fvn1SStqR3uOro6MK0znbjppypSFf3T4YddRikgbrtvftfG0210z6FLjALBlM+pvpn30 qd2A7DnzCl5dBCp2t0lZWIZa67nxt/DTE7CcxPKIInBKPglEBc+Tx3ZB74dluYhY/LEb L0MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5xpi6oKeZnMTqEA1GU/S46QdXQaCqr8RrHilbjEq4XU=; fh=NNdsCKOsulwoG3HY0psAwG/QeAEi1ObKoMEhMLcod3E=; b=hNVq+MVq1mwBwNam18+f4x6pXrQzX5PRvLpJlRXGcibnLHb/bqKKUZmPflDFI5eByX dHfIWXZvs/1daIUzpiu/bxWqEQxAjvsEfXUV7mOcA20BqEch+477XiJDtHkJXoZTyEOq 8IzIv518ydyQ9x8oOfaEKEsk4TOvNjTOmstSqwKi+NmaTwPGY/1NpvENFJ7CSzlBYpPO WgJsPrp7LPY2aiwblywBLWKcv1Zrcy5/htZMH8sQ09WLAeufYOQs1p1c1xq5sdagAyxj 6znwU513gQNpr6JAj4YizpbG+txX0RRQOA10mf8R1H98GjpfkZCEwKSyz3FPwuGSWTZE 7QTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YR7wyDa9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id j20-20020a635954000000b005b9a149e61esi1869825pgm.649.2023.12.08.10.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 10:39:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YR7wyDa9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2CB6281C0CA0; Fri, 8 Dec 2023 10:39:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574610AbjLHSj0 (ORCPT + 99 others); Fri, 8 Dec 2023 13:39:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233834AbjLHSjZ (ORCPT ); Fri, 8 Dec 2023 13:39:25 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9946C6 for ; Fri, 8 Dec 2023 10:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702060770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5xpi6oKeZnMTqEA1GU/S46QdXQaCqr8RrHilbjEq4XU=; b=YR7wyDa9riYA9msFbkr7TvyqH/HyMjM2oTp5HM8JHFU94cUhjXRTYVLSi8hqq05LSMsPuN BrDW9AfSo0L9Gn3l0jKubRyamanMLsdPSvtaNPLAmE4hEaD0bhwgm//myywsgPuiRO4VUU xDtyZWZW2545Cu8uygLnIkWfusFexb8= Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-NidrHa2oOa-jFs-wNpBhbg-1; Fri, 08 Dec 2023 13:39:29 -0500 X-MC-Unique: NidrHa2oOa-jFs-wNpBhbg-1 Received: by mail-ua1-f71.google.com with SMTP id a1e0cc1a2514c-7c410725a6cso397694241.0 for ; Fri, 08 Dec 2023 10:39:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702060769; x=1702665569; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5xpi6oKeZnMTqEA1GU/S46QdXQaCqr8RrHilbjEq4XU=; b=dqqebttdNMgUHklDsJeQw25AN5cHRuB04VusMhcZ+i1ygFhJddGv2tgac73ibKPRVL GhY21FznSx5ZO8GJpolaambGIS+FJEAVsKCMlgSWlzvRPLgDwb9eZYpdRFwbzPok2bSK WDgleVn6GZIRql7U98sIIqwCicXNelPBu1ptslPncS24Sc40tNzXZic7PgSGE2jCJyNV MNdU9RDXkRjwbmt2mCQkzilCSuSVwdIwSEe+Rei/WiuLeOKhngMdnu1kiqCjMAirYmeu wR6sdr4MG0u2nTNFf81dgWluGYMCrmpsHo/STNDNmRqHFl0RSm2LU2O8QJ4cBvEdkiVy B+aw== X-Gm-Message-State: AOJu0YxS862xU/ExVn1nreC1iaJFzuiDT63e+aYTZE+GP5stATXZSpkd 7aWJzycrtp4/qdkD4ycQynyZykSu10eY9FFVhMhQjwHnCLo/Q0NeENKw+c5o8nQibGx2GueKhYu sz1+3eS/xwd7jquznySHUzDbgyHOJxDDB9rIUhdbO X-Received: by 2002:a05:6122:3109:b0:4b2:f6a2:7736 with SMTP id cg9-20020a056122310900b004b2f6a27736mr649956vkb.28.1702060768853; Fri, 08 Dec 2023 10:39:28 -0800 (PST) X-Received: by 2002:a05:6122:3109:b0:4b2:f6a2:7736 with SMTP id cg9-20020a056122310900b004b2f6a27736mr649953vkb.28.1702060768633; Fri, 08 Dec 2023 10:39:28 -0800 (PST) MIME-Version: 1.0 References: <20231205234956.1156210-1-michael.roth@amd.com> In-Reply-To: From: Paolo Bonzini Date: Fri, 8 Dec 2023 19:39:16 +0100 Message-ID: Subject: Re: [PATCH] KVM: SEV: Fix handling of EFER_LMA bit when SEV-ES is enabled To: Sean Christopherson Cc: Michael Roth , kvm@vger.kernel.org, Tom Lendacky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 08 Dec 2023 10:39:43 -0800 (PST) On Wed, Dec 6, 2023 at 4:28=E2=80=AFPM Sean Christopherson wrote: > Blech. This is a hack to fix even worse hacks. KVM ignores CR0/CR4/EFER= values > that are set via KVM_SET_SREGS, i.e. KVM is rejecting an EFER value that = it will > never consume, which is ridiculous. And the fact that you're not trying = to have > KVM actually set state further strengthens my assertion that tracking CR0= /CR4/EFER > in KVM is pointless necessary for SEV-ES+ guests[1]. I agree that KVM is not going to consume CR0/CR4/EFER. I disagree that it's a good idea to have a value of vcpu->arch.efer that is architecturally impossible (so much so that it would fail vmentry in a non-SEV-ES guest). I also agree that changing the source is not particularly useful, but then changing the destination can be easily done in userspace. In other words, bugfix or not this can and should be merged as a code cleanup (though your older "[PATCH 1/2] KVM: SVM: Update EFER software model on CR0 trap for SEV-ES" is nicer in that it clarifies that svm->vmcb->save.efer is not used, and that's what I would like to apply). > So my very strong preference is to first skip the kvm_is_valid_sregs() ch= eck No, please don't. If you want to add a quirk that, when disabled, causes all guest state get/set ioctls to fail, go ahead. But invalid processor state remains invalid, and should be rejected, even when KVM won't consume it. > My understanding is that SVM_VMGEXIT_AP_CREATION is going to force KVM to= assume > maximal state anyways since KVM will have no way of verifying what state = is actually > shoved into the VMSA, i.e. emulating INIT is wildly broken[2]. Yes, or alternatively a way to pass CR0/CR4/EFER from the guest should be included in the VMGEXIT spec. > Side topic, Peter suspected that KVM _does_ need to let userspace set CR8= since > that's not captured in the VMSA[3]. Makes sense, and then we would have to apply the 2/2 patch from 2021 as well. But for now I'll leave that aside. Paolo > [1] https://lore.kernel.org/all/YJla8vpwqCxqgS8C@google.com > [2] https://lore.kernel.org/all/20231016132819.1002933-38-michael.roth@am= d.com > [3] https://lore.kernel.org/all/CAMkAt6oL9tfF5rvP0htbQNDPr50Zk41Q4KP-dM0N= +SJ7xmsWvw@mail.gmail.com > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 2c924075f6f1..6fb2b913009e 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -11620,7 +11620,8 @@ static int __set_sregs_common(struct kvm_vcpu *vc= pu, struct kvm_sregs *sregs, > int idx; > struct desc_ptr dt; > > - if (!kvm_is_valid_sregs(vcpu, sregs)) > + if (!vcpu->arch.guest_state_protected && > + !kvm_is_valid_sregs(vcpu, sregs)) > return -EINVAL; > > apic_base_msr.data =3D sregs->apic_base; >