From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 244D633D6D5 for ; Tue, 30 Jun 2026 22:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782858384; cv=none; b=kGMQZ1QfQVEepRp09FvSr82UqmytqJh9AI2OEBW8Os9pZG9nA+c/5vGol1ptRKM219mkHItr1g3JcziLVprvF7vV0cJD4kxk9gbEK7V3faOWJtfQwmDOAbj6+ZCyycdXfIDww5RJ1/xHbzfP6vhiJimurWufvCOnyFLuoQjB+qI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782858384; c=relaxed/simple; bh=9YT7FEIhPznIpjAcilWDorcILgSVRqZbQ5JERmigS5c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lItZEg0grB58ubCdLvvrX6MqXIgxxZa98oYJs/NUbA/yDJ83YuZ8GQI9wzMzF0X6pqW8kfuaGg72cpvb20TcjUedlRQrl4QFtmjJnrhmemmcBxZVC6DeoFBzkT5LA+jEaOTrByp9ezmz4x6SqWILJEnJPM2ko3vc1mjUu8baKlA= 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=PLYpDq5Z; arc=none smtp.client-ip=209.85.215.202 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="PLYpDq5Z" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c889d1eedcdso2631989a12.1 for ; Tue, 30 Jun 2026 15:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782858382; x=1783463182; 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=hTiRO5hN4RQ/IM936Hq23oSsoj372U9jOsT+tm322qo=; b=PLYpDq5ZNcimVBkmA7WFndJxRYiGQa3MdXpTd3ji0OPuYSoAhUjUj7KI9zxN0vT6nJ rhJTJ4+aVvXXf/fPluBuc+xxbLrZ7CY7QhJYmRgs8eX2FkpSahFuW6rEuET/eWVMpYHy jbH9vAUIFwb8L/SqnunToQzNbfSg5XQsbTaSZ+bHmG5/Y8Zb0pp7t5kfqXQcVpiGW56l P16pvwHllZWuM50Y/GqyF0sIfveiaN/92mpIl7aSKqlHVM9/6hvXDrySxFUItstOeXgA DSxvAWVidP2KPhfWqxNMAab/qyOzUH9RiuYoZnAvu4V+knR8ElbrHr5uoGI769AwE0nm /BRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782858382; x=1783463182; 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=hTiRO5hN4RQ/IM936Hq23oSsoj372U9jOsT+tm322qo=; b=OuWZNGNmCtbzb+3Sd4DNn8kzu5V/wUs1CvMxbblArHrU2CVbICGOVaFrYDmDUJeKx+ NrxZr8A+Ehh31lMvk3gtk/KKschiKY7F5T1ZrWn/A5HYMQaemNj5PDgy/R7gKsHdtile eCyu/EJR0d5dxSlzaMCVG7NR2SRhrkkjcQ0FpVRhjvVxMbvQ/qNqnaW09GGCqUUU3J2O /Dd9RPWKDDKd+pbGlxBNmVed8oT/2hmuAToOpIF/n2LZtbT2s7mgErYtNfgly9m+zoqB dY2sQZ3Ud4Yb2owG22y0Tu+dhCYmptSFdadFlpVK0TfFI0tGgzdaXSFi/0ZqVYxzbB+y w2Ow== X-Forwarded-Encrypted: i=1; AFNElJ+QiYSl/6OI2XGez+yymyT8lgUT5IGTCr6ErG5xKwA0O2/qw0UwDRpOhdhSUcSzm0j2j4Kb2qX378DFfSA=@vger.kernel.org X-Gm-Message-State: AOJu0Yydd8L5qylKJuEFoVquzniVSSf13j9gd+BIJZBoCl8S0SRLZC3u 2dP/y5O8RpWBT7Rc27EaeQOeGUHSXRh3dUiDV/mrrmq96qSAcEQWdp7H+7It6RJcfvrnoZ1RDG7 Mtts9ag== X-Received: from pgbdq2.prod.google.com ([2002:a05:6a02:f82:b0:c96:4c5b:dcb8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6f0d:b0:3a2:f7bd:a9a5 with SMTP id adf61e73a8af0-3bfc52b250dmr4831962637.38.1782858382228; Tue, 30 Jun 2026 15:26:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Jun 2026 15:26:07 -0700 In-Reply-To: <20260630222607.497895-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: <20260630222607.497895-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260630222607.497895-13-seanjc@google.com> Subject: [PATCH v3 12/12] KVM: SEV: Mark vCPU has having guest-provided VMSA even if its invalid From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ackerley Tng , Hyunwoo Kim , Tom Lendacky , Michael Roth , "=?UTF-8?q?J=C3=B6rg=20R=C3=B6del?=" , Fuad Tabba Content-Type: text/plain; charset="UTF-8" Track the guest as having a guest-provided VMSA as soon as control.vmsa_pa is invalidated, instead of waiting to see if the guest-provided VMSA is usable, so that KVM doesn't switch back to the original VMSA instead of exiting to userspace (due to an invalid VMSA). By the time a vCPU tries to load a guest-provided VMSA, KVM has already communicated "success" for AP creation, i.e. KVM has committed to using the guest-provided VMSA. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 2d2c159f20c2..ec426a5582aa 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -4005,23 +4005,6 @@ static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa) */ vmcb_mark_all_dirty(svm->vmcb); - if (!VALID_PAGE(gpa)) - return; - - slot = gfn_to_memslot(vcpu->kvm, gfn); - if (!slot) - return; - - mmu_seq = kvm->mmu_invalidate_seq; - smp_rmb(); - - /* - * The new VMSA will be private memory guest memory, so retrieve the - * PFN from the gmem backend. - */ - if (kvm_gmem_get_pfn(vcpu->kvm, slot, gfn, &pfn, &page, NULL)) - return; - /* * From this point forward, the VMSA will always be a guest-mapped page * rather than the initial one allocated by KVM in svm->sev_es.vmsa. In @@ -4033,6 +4016,23 @@ static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa) */ svm->sev_es.snp_has_guest_vmsa = true; + if (!VALID_PAGE(gpa)) + return; + + slot = gfn_to_memslot(vcpu->kvm, gfn); + if (!slot) + return; + + mmu_seq = kvm->mmu_invalidate_seq; + smp_rmb(); + + /* + * The new VMSA will be private memory guest memory, so retrieve the + * PFN from the gmem backend. + */ + if (kvm_gmem_get_pfn(vcpu->kvm, slot, gfn, &pfn, &page, NULL)) + return; + read_lock(&kvm->mmu_lock); /* * Save the guest-provided GPA. If retry is needed, then KVM will try -- 2.55.0.rc0.799.gd6f94ed593-goog