From nobody Mon Feb 9 16:08:24 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23AB716A959 for ; Wed, 19 Feb 2025 01:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739928438; cv=none; b=ESk1CNu1/VArutJ30BFurRubHvh0qzs/XBDGa8Lt78WaGHa29CD+3g1psonhuahNbWhqmJrXG3rmV4wwljvPAWdLFG0dwJwbGuUZcw9XlRRFECHzuNbknC31CF2hIi7RtzUyGPH/0e3H7it2cuBa5wFesxRGtB1DPSNVZxwaI6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739928438; c=relaxed/simple; bh=HS/OGyPieAUMN+o3iI2SoK4HV3gkuOhVEedxfxsJjPQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Lt1Pd0uPFeABS7NjhArS4ZxgaPGOwlQIHMC8fhvt17LUJhO6jwqL/gGXUyHQUz5/DrE4/7m0FUKenRJjDSsS1RLFevTOL0v+VtG/Zl3bZ3ENbivG1JNL1XmMiuUU/vvEAIgOFaI2F/r6YvoFzBhgr0n8AXYpSrirhk8wKovmGOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=u9jl//jl; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u9jl//jl" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fc45101191so6714213a91.1 for ; Tue, 18 Feb 2025 17:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739928436; x=1740533236; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=NOqNLm8zpj7r5p6cWzA7ewxdPggAPFsC3tCvVJWmq4Y=; b=u9jl//jlRAahR95FDOsHeizXwb1pgeMDafOZHlQQesOI1vN2zy6zUpZJT3fg48xV6f 6X9kAVv/1h51opTnnjfrP1HfAxMcv/qWRhkMZKym3qbOXdwKQdLFNELQiD9q9K7buEkc C1i0tf/pduKH0Zm61BbHU5vKHd3BkR9s3+NSkM9kdIxmZiJbFwFreV/B2lnYjpq8Jzts OTn8aUZ+FkHqo03b6PRfK7o2z4qcWaAvTj7uj/qYWc0r84TJ6GgDHD0YSa45Gei6ESUj 4v1Kg8QirG7L0bgyuidv3U6q0gi5jUa8Nb+O1yQamcMhQ2odZ6A4+fFeQR3oEIPaKPX3 i5YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739928436; x=1740533236; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NOqNLm8zpj7r5p6cWzA7ewxdPggAPFsC3tCvVJWmq4Y=; b=Vt6YyrC/kNcnSnWBe2JzuUyMzu0alJHQaN3RS8pDuqkkAuroLf4Y09OvGv8b9/thu0 TzU6wUSqSHmpCMt7WHUTgudZk84UcZ7UeaDrKO0+9H0iqXTzirD5gILsfTHTBGJqBpo/ H4m1Bx/5NK6HbR/ysnx3GK9MUjDOIFmgasBYMSkLo8psvE41FIVvTShqITVq0DN0Ca8o 0NupLk0Cewi3F1wdzhbyzBu86ahKRv8tYgRvLKHWCZVp5HnYr1Qzpo/XZIWJICKuPg4B 1AI3gTbJNkDO1BxRfRGscw7pVidXgipMruBO5hcsHGsl8stjRmwCBsfjbOrUnuEhtkrR q1aA== X-Forwarded-Encrypted: i=1; AJvYcCUEETKz+m38sKEugJcagRKJhdXkEgZkXnDWBcNmPxoO3ao2JW3vkysOxngSJNG4/pbQTXSRC2901bilpmw=@vger.kernel.org X-Gm-Message-State: AOJu0YxN4vJpACkSvdh7trpqBFJu0uFk9xTdMvf9Wt8ZZfhJ/V9EXoir i0e0rXWHGpbVWjft9GFU8NTOm6LbXSHwoK9uErBuVKf8zS09In/MjOJKOevn+NpifGSI3WBi+wd 9Lw== X-Google-Smtp-Source: AGHT+IGbOdETGV4/8dazx0YgIjrgRH1peDdIwCZwKiJ8gyxb6gn3o4TseTvRc52oNdBvm8Q95Zspls7KQ0E= X-Received: from pjbli12.prod.google.com ([2002:a17:90b:48cc:b0:2fc:c98:ea47]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3f06:b0:2fc:3264:3667 with SMTP id 98e67ed59e1d1-2fc40d131bemr23974637a91.1.1739928436566; Tue, 18 Feb 2025 17:27:16 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 18 Feb 2025 17:27:00 -0800 In-Reply-To: <20250219012705.1495231-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250219012705.1495231-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250219012705.1495231-6-seanjc@google.com> Subject: [PATCH 05/10] KVM: SVM: Require AP's "requested" SEV_FEATURES to match KVM's view From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Naveen N Rao , Kim Phillips , Tom Lendacky , Alexey Kardashevskiy Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When handling an "AP Create" event, return an error if the "requested" SEV features for the vCPU don't exactly match KVM's view of the VM-scoped features. There is no known use case for heterogeneous SEV features across vCPUs, and while KVM can't actually enforce an exact match since the value in RAX isn't guaranteed to match what the guest shoved into the VMSA, KVM can at least avoid knowingly letting the guest run in an unsupported state. E.g. if a VM is created with DebugSwap disabled, KVM will intercept #DBs and DRs for all vCPUs, even if an AP is "created" with DebugSwap enabled in its VMSA. Note, the GHCB spec only "requires" that "AP use the same interrupt injection mechanism as the BSP", but given the disaster that is DebugSwap and SEV_FEATURES in general, it's safe to say that AMD didn't consider all possible complications with mismatching features between the BSP and APs. Oppurtunistically fold the check into the relevant request flavors; the "request < AP_DESTROY" check is just a bizarre way of implementing the AP_CREATE_ON_INIT =3D> AP_CREATE fallthrough. Fixes: e366f92ea99e ("KVM: SEV: Support SEV-SNP AP Creation NAE event") Signed-off-by: Sean Christopherson Reviewed-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 07125b2cf0a6..8425198c5204 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3934,6 +3934,7 @@ void sev_snp_init_protected_guest_state(struct kvm_vc= pu *vcpu) =20 static int sev_snp_ap_creation(struct vcpu_svm *svm) { + struct kvm_sev_info *sev =3D to_kvm_sev_info(svm->vcpu.kvm); struct kvm_vcpu *vcpu =3D &svm->vcpu; struct kvm_vcpu *target_vcpu; struct vcpu_svm *target_svm; @@ -3965,26 +3966,18 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm) =20 mutex_lock(&target_svm->sev_es.snp_vmsa_mutex); =20 - /* Interrupt injection mode shouldn't change for AP creation */ - if (request < SVM_VMGEXIT_AP_DESTROY) { - u64 sev_features; - - sev_features =3D vcpu->arch.regs[VCPU_REGS_RAX]; - sev_features ^=3D to_kvm_sev_info(svm->vcpu.kvm)->vmsa_features; - - if (sev_features & SVM_SEV_FEAT_INT_INJ_MODES) { - vcpu_unimpl(vcpu, "vmgexit: invalid AP injection mode [%#lx] from guest= \n", - vcpu->arch.regs[VCPU_REGS_RAX]); - ret =3D -EINVAL; - goto out; - } - } - switch (request) { case SVM_VMGEXIT_AP_CREATE_ON_INIT: kick =3D false; fallthrough; case SVM_VMGEXIT_AP_CREATE: + if (vcpu->arch.regs[VCPU_REGS_RAX] !=3D sev->vmsa_features) { + vcpu_unimpl(vcpu, "vmgexit: mismatched AP sev_features [%#lx] !=3D [%#l= lx] from guest\n", + vcpu->arch.regs[VCPU_REGS_RAX], sev->vmsa_features); + ret =3D -EINVAL; + goto out; + } + if (!page_address_valid(vcpu, svm->vmcb->control.exit_info_2)) { vcpu_unimpl(vcpu, "vmgexit: invalid AP VMSA address [%#llx] from guest\= n", svm->vmcb->control.exit_info_2); --=20 2.48.1.601.g30ceb7b040-goog