From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793069806; b=EFXwhMDVSXp8K0xY0FZSLlDvM5KrRJ8B89fJHucRxlD7ItXbfiZtM82pvxudEloN3Cm8 cq2Hg2nWexckFB3dOVCGKYqlXHlRWtLHp9SbqRLwodlFBeCn2s1P708y6T/UsETg8Heho bYW0NsXL9/ilOPXAvxaO2+IxoER3iepm3kq0l2vf70FCIXU3sXR/ZakQ66nkl3HcTmOhP O39Oe5WXdMkNrxbp3Cgw9sJ0YkH5U7jjRxW0NoZrwwhZd+MwVk03SNpztolcDBmXjKYZx C87/vvTuKes1CBBdlfOeaVAn2srWDPBwizRVFHin3YYVkzTjyAgVtoKm91YhEStsN9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793069806; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=nTmoe18Cl/4sVBSCzKT2MKtNZE6Kiks6IBw/3aH90Qo=; b=fi8+v1Tk+s2dhBTWxqWDa+4ZIdit2OiY/lKJceBnCF1hfYw8dIwypO3umC6pPcp4oONZ zjK4rKppfEpJQ0smsuYI6PFTYkFHYXMCDwaVNudRpF4MbSfAmsyeEpeHdqe443xgPE/8w sJwu4s5IqTPLLufXMXBXaP4vLYhnFkbe7j5cAIlO3WdpPqhzGNglZSAOqjjRDt2MjmEhg w+EC1HU6U1PmHUckpS+AZfLznE25KGkJAPvWJC1ot/X9aODWvtgds82Irz+li1jh3wmZE HNxzaEP4UpZ94AlP4iByuc/fSfqfT6KHch4nYpSeYruVhqejNkQBDraXYRTelttRQRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kevinloughlin.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=Z62pXTP9; arc=none smtp.remote-ip=209.85.210.71 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4286A606A328 for ; Tue, 27 Oct 2026 02:56:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4286A606A328 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--kevinloughlin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=Z62pXTP9 Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-847e2926d94so7191487a34.0 for ; Mon, 26 Oct 2026 19:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1793069805; x=1793674605; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nTmoe18Cl/4sVBSCzKT2MKtNZE6Kiks6IBw/3aH90Qo=; b=Z62pXTP9xfa3gTQxIGNoVXsy7duoq/uH7iqChJqgs30TMgADpDXAmA9S82vLp2oRE3 5wt/Ko8E3RdUqvtjnwFDsI7l+rVT1Et/15PCRyAsE4mH91ws0QxpiE7p6SpFgARwTHgW SxSA/cQeNsBA5wr/7Al7NECagdmqb3FLzwI0ZuBQZXS/7tddFUKzIRZaOJJxMac81ZX5 krShLH65S4N1/6bXrK6ZUftZkp+xO4gySYOailHgxJ+hCf1HmCxds1P0qvowL3WW4rMi bDEJM1dDoSzx/2W0w9+7OIPHu1uSWatpe4AD/8CHqO2f1Y6fZH3PCDKURD/Gebd1T6qM POkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793069805; x=1793674605; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nTmoe18Cl/4sVBSCzKT2MKtNZE6Kiks6IBw/3aH90Qo=; b=s5jWkSEwYqs2zcGufrnuh9mkEUSb6YdS2HLzD+cLDGIvNsoy8tcYSIpfZPIffk6FSX tpnAdI8ZwqYFdhG0O7U6txAiKFqTwgFYC/JFkqmAV+2Ra/NsZ4xnFJ8m+KwmE763PeQQ Qaa3ZRqxfS6pNzb1tF3jd8slRIr9ws1S0rES/3bD9VhLBnaKcaX5Uq7gmDV003iKmugC 4uVlzUXoDZV+IJ9P2n/oAs8g/RCeJzIzOVUzvnIZRhdw6duTx2v8y3GWWivn9WucWTTI RoSgPHSEkIBuTyC/kMagCRM/A083vFW6/IAmR+SJp0qPb96UhWTWi36qMIxSQZEQuYXq Ry4Q== X-Forwarded-Encrypted: i=1; AKwUvBwmIRh998EPZeuO0JkkVOyn7z1CN3toqTnRRvrBT5/bQ81nX6u4HP8yl3oeRQU6W8DBsCFb61BbyVdu0UQ=@vger.kernel.org X-Gm-Message-State: AFq9FYL5C/oHMfPK0ImS7VFhJqIEKP7Kl0Lr7GaDbZ4OAdhisVf/W7xD 3OWht5tBhN9tvMI9qPVM2CZen1T8jRqen+PvaAPgx0lajcz6HYR+aV/R3F44UODG0nKB8ucuj3g J+mPxR/IyzIwBnd7r2A2qCuOZiprny+170Q== X-Received: from ila5-n1.prod.google.com ([2002:a05:6e02:5205:10b0:50d:41bd:b30]) (user=kevinloughlin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:c0cc:10b0:6dc:6e90:f650 with SMTP id 006d021491bc7-70ba0e0f19cmr3730965eaf.15.1793069804982; Mon, 26 Oct 2026 19:56:44 -0700 (PDT) Date: Tue, 27 Oct 2026 02:56:06 +0000 In-Reply-To: <20261027025616.1632690-1-kevinloughlin@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261027025616.1632690-1-kevinloughlin@google.com> X-Mailer: git-send-email 2.56.0.307.g5fe7bd680c-goog Message-ID: <20261027025616.1632690-4-kevinloughlin@google.com> Subject: [PATCH 03/13] x86/coco/sev: add snp_unaccept_memory() From: Kevin Loughlin To: "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , "=?UTF-8?q?Eugenio=20P=C3=A9rez?=" , Xuan Zhuo , Ard Biesheuvel , Kiryl Shutsemau , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , Ashish Kalra , Michael Roth , Rick Edgecombe , Andrew Morton , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Alexander Duyck Cc: virtualization@lists.linux.dev, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sidharth Telang , Punit Salian , Peter Gonda , Ackerley Tng , Jacky Li , Steve Rutherford , David Skidmore , Kevin Loughlin Content-Type: text/plain; charset="UTF-8" Add snp_unaccept_memory() and wire it up to arch_unaccept_memory() and arch_has_unaccept_memory() on AMD SEV-SNP guests. When memory ranges are dynamically unaccepted (such as during virtio-balloon inflation or free page reporting), snp_unaccept_memory() invokes set_pages_state(..., SNP_PAGE_STATE_SHARED). This call rescinds guest RMP validation via PVALIDATE(..., validate=false), handling 2MB PMD pages with automatic fallback to 4KB pages on RMP size mismatch. snp_unaccept_memory() -> set_pages_state() also issues a GHCB Page State Change request so the hypervisor transitions the range from private to shared symmetrically with snp_accept_memory(). Signed-off-by: Kevin Loughlin --- arch/x86/coco/sev/core.c | 13 +++++++++++++ arch/x86/include/asm/sev.h | 2 ++ arch/x86/include/asm/unaccepted_memory.h | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index eb2e853e950a..3f8809bae14a 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -432,6 +432,19 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t end) set_pages_state(vaddr, npages, SNP_PAGE_STATE_PRIVATE); } +void snp_unaccept_memory(phys_addr_t start, phys_addr_t end) +{ + unsigned long vaddr, npages; + + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return; + + vaddr = (unsigned long)__va(start); + npages = (end - start) >> PAGE_SHIFT; + + set_pages_state(vaddr, npages, SNP_PAGE_STATE_SHARED); +} + static int vmgexit_ap_control(u64 event, struct sev_es_save_area *vmsa, u32 apic_id) { bool create = event != SVM_VMGEXIT_AP_DESTROY; diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index c7ea9845351e..464a721f8889 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -514,6 +514,7 @@ bool snp_init(struct boot_params *bp); void snp_dmi_setup(void); int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, struct svsm_attest_call *input); void snp_accept_memory(phys_addr_t start, phys_addr_t end); +void snp_unaccept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void sev_show_status(void); @@ -624,6 +625,7 @@ static inline int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, return -ENOTTY; } static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { } +static inline void snp_unaccept_memory(phys_addr_t start, phys_addr_t end) { } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void sev_show_status(void) { } diff --git a/arch/x86/include/asm/unaccepted_memory.h b/arch/x86/include/asm/unaccepted_memory.h index f5937e9866ac..931d1388973e 100644 --- a/arch/x86/include/asm/unaccepted_memory.h +++ b/arch/x86/include/asm/unaccepted_memory.h @@ -18,6 +18,20 @@ static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) } } +static inline bool arch_has_unaccept_memory(void) +{ + return cc_platform_has(CC_ATTR_GUEST_SEV_SNP); +} + +static inline void arch_unaccept_memory(phys_addr_t start, phys_addr_t end) +{ + /* Platform-specific memory-unacceptance call goes here */ + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + snp_unaccept_memory(start, end); + else + WARN_ONCE(1, "Cannot unaccept memory: unsupported platform\n"); +} + static inline struct efi_unaccepted_memory *efi_get_unaccepted_table(void) { if (efi.unaccepted == EFI_INVALID_TABLE_ADDR) -- 2.56.0.307.g5fe7bd680c-goog