From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 568DC25B095 for ; Fri, 26 Jun 2026 23:14:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782515661; cv=none; b=swgwoX2JhT/uf3j0OPtTDp1quoX/5qL7OEJWrv9vkXke73mElC/Uzz39OL/Y5mZf0NJdiHbGA4tKp+WOYUTz9S2iO2k8mNX3bQrG1Vu+Y7DSkMILbXfdHwBRGHUbnrOS6jK56RhiKvR5qQrexUREZJpVZWFAYvTzcuoJKHja7n4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782515661; c=relaxed/simple; bh=WI6EEV7DkYcS4010cYThLDi+CUB1ZZRYSLAEfPYAzSM=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=f/2elpoB+MKwfk19oXWbs47wxDNBrwhexx02hbKjo+IC5nmL/ztr2RLGHm5RHkwcuMP9pWTMOxKni3u+5yskNWSZxz/EGM6aEt4mEDrEY1hl6wyU+mS5ZTudl94RyHwzqejAzmAYN/+vQjETC9ejCUSeVrm8cRbcDqTP3iyAnzU= 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=e7KTgoaQ; arc=none smtp.client-ip=209.85.210.201 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="e7KTgoaQ" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-845d3bef1e2so331569b3a.0 for ; Fri, 26 Jun 2026 16:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782515659; x=1783120459; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=M6oeuLIgIp8Ap/tdPEY25lL0kvoDgAnckkPY4D/+jCk=; b=e7KTgoaQydtBLTbux9BJfKejUA7gqaPsLaMGh+ySnZbPVvko8wcNxlEPX77b6pJ0Vv KutAP1VG+iwVTmhnrKsPNj5/AlefYFWMlXcoDmfu6Q3++AatdPmGVtTeWDmEh6yOqR2T lw0uJwt8rjitQXdeEXtTZmLpIX2DlY/hf8KhLHx0+aXs6hHVCWl0TbmOSs2FVCgQPN0V tWKr2/TVWJ9nZl1XbbdaGa1JjCe3drVFH3ZcYARgSBmvfJY1wmzOEsvT+YyRr5xVlk1r 3Baxu4FAPdhk04tI5ANs4Z5Rjzo4s7B2URDKwfK8wCY2Uf/zA0DrqrEZOC1HX/WYHigU 2ALg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782515660; x=1783120460; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=M6oeuLIgIp8Ap/tdPEY25lL0kvoDgAnckkPY4D/+jCk=; b=BMKP3OctUmPBkypJux0ygRUQrCzWQnHEnKOYhlv/EozAVhthkSnWZ7aj03HfCQVkXM P4LS3w1ikWy7HIARcMmnuSaUjR4za5sC5BGtnCUjv+8+/IAN0qtY1iB43Jf2ucbYbjjD rz+IRt6JjsxGst0YOHmzlDR4bYjcEgh9l6wrg9i+9NVWd1vrxqyNdczMHmHYQkKBxX5H OsE6x8oz56RslmNr4cTnIMw7BtKdx2w4SYSDlzl8k4igxR78prGdkcn/UPw/uDtKKL/s s9cCEk9xj2RA6e15odXdqlEH/RUKHX3t5AZD+9VXw7VI0rfgjBaWV23c7QKZZ7NVy4WK 7GNg== X-Forwarded-Encrypted: i=1; AHgh+Rqs6Er9myXMCcxJnsVX4A2w5Ddm2Ce+VRyhnQe4yVEOMKavjPdyYo9hjV8xgonbYVin6FLuQwv0IFK1OHc=@vger.kernel.org X-Gm-Message-State: AOJu0YyBakLaIwPBDYBJdcFyp4M6dptmTB2px4InebMcQTc+xZVOesq6 9w+Wto/n+zLnUp4PWF9ASa/2Qdl6hiVy2pVRNh5qP1SZjTZnbW9Vucu8XoenQKt0vZ9ER4ndTqe gNFrsVQ== X-Received: from pfbgx4.prod.google.com ([2002:a05:6a00:1e04:b0:842:3bd7:f2bf]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:8c11:b0:842:672e:7b5d with SMTP id d2e1a72fcca58-845b39f9acdmr8960486b3a.17.1782515659388; Fri, 26 Jun 2026 16:14:19 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 26 Jun 2026 16:14:07 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260626231416.3943216-1-seanjc@google.com> Subject: [PATCH v2 0/9] KVM: SEV: Fix RMP #PF due freeing in-use VMSA From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Hyunwoo Kim , Tom Lendacky , Michael Roth , "=?UTF-8?q?J=C3=B6rg=20R=C3=B6del?=" , Fuad Tabba , Ackerley Tng Content-Type: text/plain; charset="UTF-8" Rework KVM's handling of guest-provided (and always guest_memfd-backed) VMSAs to forcefully reclaim VMSA pages when the pages are being freed from their backing gmem instance, e.g. in response to PUNCH_HOLE. In the worst case scenario, marking the page SHARED in the RMP will fail due to the page being IN_USE, ultimately leading to RMP #PF violations due to guest_memfd freeing the memory back to the kernel while it's still assigned to a VM. Note, the implementation nearly identical to that used by KVM for VMX's APIC access page (which isn't guest controlled, but is migratable and whose PA is shoved directly into a vCPU control structure). v2: - Invalidate VMSAs if the memslot is DELETED or MOVED. [Sashiko] - Limit stable@ patches without a Fixes to 6.12+. v1: https://lore.kernel.org/all/20260625222229.3367197-2-seanjc@google.com Sean Christopherson (9): KVM: SEV: Track the GPA of the guest-controlled VMSA used for SNP guests KVM: SEV: Extract loading of guest-provided VMSA to a separate helper KVM: SEV: Mark vCPU RUNNABLE after AP_CREATE, even if VMSA is unusable KVM: Rework .gmem_invalidate() into .gmem_free_folio() KVM: x86/mmu: Fold kvm_mmu_zap_memslot() into kvm_arch_flush_shadow_memslot() KVM: x86/mmu: Split kvm_mmu_zap_all_fast() into "front" and "back" halves KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped KVM: x86: Guard .gmem_prepare() declarations with HAVE_KVM_GMEM_PREPARE=y KVM: SEV: Mark vCPU has having guest-provided VMSA even if its invalid arch/x86/include/asm/kvm-x86-ops.h | 8 +- arch/x86/include/asm/kvm_host.h | 10 +- arch/x86/kvm/mmu/mmu.c | 76 +++++++++------ arch/x86/kvm/svm/sev.c | 152 +++++++++++++++++++++-------- arch/x86/kvm/svm/svm.c | 6 +- arch/x86/kvm/svm/svm.h | 8 +- arch/x86/kvm/x86.c | 10 +- include/linux/kvm_host.h | 3 +- virt/kvm/guest_memfd.c | 17 +--- 9 files changed, 197 insertions(+), 93 deletions(-) base-commit: a204badd8432f93b7e862e7dac6db0fe3d65f370 -- 2.55.0.rc0.799.gd6f94ed593-goog