From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 91B1E3DE446 for ; Tue, 30 Jun 2026 17:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782840130; cv=none; b=pn3DCvZxquUmlmeD0GaLrK8RMPZlaHmDPdbXpqf5FWuz0a0OKd98HyMuoYn3Qvi8mF+/NS1YZjMvgF5Q1zwEvYNYzFD/sHWZ6v09tIIp9ADQwYWGG3KLQcKA6HgNsu1YemeTGfHFDywYfIY51HxRdtUti5u6SElYhWI6U0w+Nl4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782840130; c=relaxed/simple; bh=GJiY0G+v1cHtWDhoF6H7oSsoQa/Y8R9a0sPu01Qf5Rg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cEp6KQrzQg0SMx2f90Li3UfPgv+JSPP6W+gOjWvz2CfgU1VsA5IWQ7uaueTD4wjNTPeOqZEs9hseW78dBwUi7qby2d7xVWzlKQ5u6iseof+i2J83AMwvHXJuetHxI34MtTgLzH/AQuYZYNRgRxDk7KfqpKs6L+xnRJxSHmaLSvg= 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=eil2Qigu; arc=none smtp.client-ip=209.85.210.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="eil2Qigu" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-845ea8fd3easo4191611b3a.0 for ; Tue, 30 Jun 2026 10:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782840129; x=1783444929; 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=plT5/1MQYoLBw0hf7vwLUa68BnMiEY/lHOfm/Z/BEKM=; b=eil2Qigu+nVxG+043Br3hYg3wzon+eM9FJBcif8V9IdXTLj/uIi/pwo11d9eM5HvtZ IMHCq//NjdrNphsq31lX31Zyf/KIRUjrFowQtO4mPlQc4SdYMKMd+jxANcgcnl/23kTu u8q3qm1wd4256aIobOp9rEiQhwAFqjMK/b8jNDI6PIw7j4aPI3DwpPs8VCEvp8WwHbR4 ha3U2T33ehIqppTdNvWMa17/zXkrus5xjnrokuTOjl8r0lY1foUTOlfrA83vtmR+TNo9 sMWd5aROQwm0N6rpLdSUxd+cBhF0NyDLgsY0fqBBfxK/dVQ5r2uyeCkuFJacJs5lcfR5 9Drg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782840129; x=1783444929; 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=plT5/1MQYoLBw0hf7vwLUa68BnMiEY/lHOfm/Z/BEKM=; b=DA9HvOHsR6xjfTgSW8mIBM0tEP/UbBIDJ20MAp4+IW4L3PtfpRW53WYp0H2ZbnB24X QlDThrICDGcoYSkxo8c4k5CShGgV03mRWw9OtTfNOzJS50L7U8AbQb91YiVRBdPFZHOz if6xF4gMzIGd7CDms5l56wcq0ahrsyDtsjSfMkVSnhBH0BcsGf/QhtZnQsdoWUFPeA5e SI4mZ0MaxJI+LuxktXxssspcWCoY5D2UNQJjRJLoDIZV9hZx6236J6dKJvBlY4fKrdDi QBv3Yzp0re4H/QTjUoPiNs5L9wV9UDGZQqH7Hb9xUNX4Yfo+yLkYGE91DipRbm7B2uCk rTWA== X-Forwarded-Encrypted: i=1; AFNElJ93G73abZ7KnJevBA1iYulBcqYH2p/vm48dCcXxJ03E6qfkKc0YzjtloG8YCASy18Y0k3UT1j3+KMCNhWE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1jj8G+9feqpFJyFddUVV6DdaGC39M2JDn8fJy0tF7UJtjGiIf EhhTNWZuj635+kaqqTf3v+hkQ+th0o2P+vgOamKkrtB7W/Zta3FBjPVa0CmKcsG5GHOZ5LCOTwW bNlJjvw== X-Received: from pfoo8.prod.google.com ([2002:a05:6a00:1a08:b0:845:c4b8:9730]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2ea8:b0:847:7f38:27c2 with SMTP id d2e1a72fcca58-8479f293658mr3669670b3a.50.1782840128582; Tue, 30 Jun 2026 10:22:08 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Jun 2026 10:22:03 -0700 In-Reply-To: <20260630172204.279784-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: <20260630172204.279784-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260630172204.279784-2-seanjc@google.com> Subject: [PATCH 6.12.y 1/2] KVM: SEV: Move sev_free_vcpu() down below sev_es_unmap_ghcb() From: Sean Christopherson To: stable@vger.kernel.org, Greg Kroah-Hartman , Sasha Levin Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky , Michael Roth , Sean Christopherson , Paolo Bonzini Content-Type: text/plain; charset="UTF-8" [ Upstream commit 08385c5e1814edee829ffe475d559ed730354335 ] Relocate sev_free_vcpu() down in sev.c so that it's definition comes after sev_es_unmap_ghcb(). This will allow sharing unmap functionality between the two functions without needing a forward declaration (or weird placement of the common code). No functional change intended. Cc: stable@vger.kernel.org Reviewed-by: Tom Lendacky Reviewed-by: Michael Roth Signed-off-by: Sean Christopherson Message-ID: <20260501202250.2115252-16-seanjc@google.com> Signed-off-by: Paolo Bonzini Message-ID: <20260529183549.1104619-16-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini [sean: Preserve use of sev_es_guest() as is_sev_es_guest() doesn't exist in 6.12, resolve superficial conflict due to pre_sev_run() prototype mismatch.] Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 62 +++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 115c59c86f44..0f79e052ac42 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3168,37 +3168,6 @@ void sev_guest_memory_reclaimed(struct kvm *kvm) wbinvd_on_all_cpus(); } -void sev_free_vcpu(struct kvm_vcpu *vcpu) -{ - struct vcpu_svm *svm; - - if (!sev_es_guest(vcpu->kvm)) - return; - - svm = to_svm(vcpu); - - /* - * If it's an SNP guest, then the VMSA was marked in the RMP table as - * a guest-owned page. Transition the page to hypervisor state before - * releasing it back to the system. - */ - if (sev_snp_guest(vcpu->kvm)) { - u64 pfn = __pa(svm->sev_es.vmsa) >> PAGE_SHIFT; - - if (kvm_rmp_make_shared(vcpu->kvm, pfn, PG_LEVEL_4K)) - goto skip_vmsa_free; - } - - if (vcpu->arch.guest_state_protected) - sev_flush_encrypted_page(vcpu, svm->sev_es.vmsa); - - __free_page(virt_to_page(svm->sev_es.vmsa)); - -skip_vmsa_free: - if (svm->sev_es.ghcb_sa_free) - kvfree(svm->sev_es.ghcb_sa); -} - static void dump_ghcb(struct vcpu_svm *svm) { struct ghcb *ghcb = svm->sev_es.ghcb; @@ -3475,6 +3444,37 @@ void sev_es_unmap_ghcb(struct vcpu_svm *svm) svm->sev_es.ghcb = NULL; } +void sev_free_vcpu(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm; + + if (!sev_es_guest(vcpu->kvm)) + return; + + svm = to_svm(vcpu); + + /* + * If it's an SNP guest, then the VMSA was marked in the RMP table as + * a guest-owned page. Transition the page to hypervisor state before + * releasing it back to the system. + */ + if (sev_snp_guest(vcpu->kvm)) { + u64 pfn = __pa(svm->sev_es.vmsa) >> PAGE_SHIFT; + + if (kvm_rmp_make_shared(vcpu->kvm, pfn, PG_LEVEL_4K)) + goto skip_vmsa_free; + } + + if (vcpu->arch.guest_state_protected) + sev_flush_encrypted_page(vcpu, svm->sev_es.vmsa); + + __free_page(virt_to_page(svm->sev_es.vmsa)); + +skip_vmsa_free: + if (svm->sev_es.ghcb_sa_free) + kvfree(svm->sev_es.ghcb_sa); +} + void pre_sev_run(struct vcpu_svm *svm, int cpu) { struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu); -- 2.55.0.rc0.799.gd6f94ed593-goog