From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 CF6A03B637F for ; Thu, 23 Jul 2026 21:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784840903; cv=none; b=isHrUOT5IG3yJ2QA6FHZLvmt7jvtG1VfLGDDETTpHKTV0n0c6B1B8eR4wNhJkKBtDvwLP2ngHMwZoDIpdWqAzLOoEx/Bv+ap9tu2NXU3qtUBJPwEP5Ik++qxNuemACR9c9vGDzy/Dqe7TEgqZa1jsA/VJalRsXU3+IhudAVL+sM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784840903; c=relaxed/simple; bh=1/gvq+OLekmRwsEGzr3vC5u0db5zRvtFjM+5W0IssTw=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=SC/QtvSilJ0oCPReeJHX9Ji9aRw1QlVzh4y4Ctcuk9AXvSDKMT4NhLlrO2b++B0bq2wMCp9s6oMc9s9dUkjXjSCX4ko0WvI9XurId5N5HPi0xK0PfIw72pD4g4IJF16vLl3uTIs73OtbJ5piDK7BDzHit4QfiXrWZXEPDVea96o= 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=t20ZRoWW; arc=none smtp.client-ip=209.85.216.71 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="t20ZRoWW" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38e4758ab46so1196844a91.0 for ; Thu, 23 Jul 2026 14:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784840892; x=1785445692; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date :reply-to:from:to:cc:subject:date:message-id:reply-to:content-type; bh=vGZcB8o0pRvIKvfmoxU3/u8bc4tgPgdDY2N6HG7Pmws=; b=t20ZRoWWHwU1dYP4XaBjj4ANvk/dqx02zru+LHFQx+8KJSdUIaj2M7EmeU0NPXs+BQ t4sJlCzaQXv5N+o1Xqc/yhsGORI0++GgEVQHU8gVCkNL+QTPR711OTBP5B1kmryIYhei 3e/+H9eTXSNKabjbPrT9KGlCeu1wHYc0oUAIRcT03x/I+i353nSQ+octjETjQ0Ogc98u mpcMtHsExpTAp4ago5R2q/LbIWhdfOqBW5Ddjcd4n1zep4qh4miDFeBJuORNeOqyLuXU LN817jDbZEeW2QbZHUDRfABy+vFyKDVahIgXycb/MBlWDBrsqkbu6j9X2BgBhFsVLzTw wuqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784840892; x=1785445692; h=content-type:cc:to:from:subject:message-id:mime-version:date :reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=vGZcB8o0pRvIKvfmoxU3/u8bc4tgPgdDY2N6HG7Pmws=; b=YXC7Vq4TxZumbHIz6S51CXvd/XxKaVmdGciXtefUasTZ3ylNb+woF1p7S1nwGrdyo4 GW2bVbIf75BiygQl36RP7oXGoGs99VPU5O0hlcQjnefv9sLzBxNhBbuUsvlUPrSY9sGM d3MYj/nvDxGQBBsEL3rFq8YUaECrZPXf5DlMsqopQBAjlTWzCsW8DzhhP7NPhHYbg9Uq 4u0QfEG/JRRGTgRBFLsSK3tx8tgCN8XoZBByznmB3h3I4dWzCN9imxm1FduGvQ5yERww oVb/ZO/wUev+w+IuUMPxupyvqTHrIYYjwM5cYYAWaJEM0RP9B50QrGcjMskFMuGJQCRn pJgg== X-Forwarded-Encrypted: i=1; AHgh+RrqToUFk9bsc98FtrGfZAu3ZWW/HCLLmr8BvvQhrftsMHH1sO6Cd/7VtjlIRq5wPFI0q2cLP0Cuoyc/+1s=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9lL4BCMVt9hRmSX39Fnl9ya7mSsNX7WU/SE5SPQ1c5mwNJVnq K8UG7VpjDzvJFB3TAA88s2J711l65itTTWM76pN9aDkOylA8GqUBywQV00vKq3Zca7LmEE/Amu0 ElnSARw== X-Received: from pjqv24.prod.google.com ([2002:a17:90a:af18:b0:38e:bbd1:f3c8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:582e:b0:37f:9ce1:735e with SMTP id 98e67ed59e1d1-38ec65d29b4mr4727148a91.31.1784840892296; Thu, 23 Jul 2026 14:08:12 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 23 Jul 2026 14:08:02 -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.229.g6434b31f56-goog Message-ID: <20260723210811.72720-1-seanjc@google.com> Subject: [PATCH v6 0/9] KVM: guest_memfd: RECLAIM+CONVERT cleanups From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Fuad Tabba , Ackerley Tng , Xiaoyao Li , Michael Roth , Fuad Tabba Content-Type: text/plain; charset="UTF-8" These are the cleanups from the SNP VMSA series. Well, that's how they started out, now it's full into prep work for in-place conversion. Oh well. Rework prepare()+invalidate() into make_private()+reclaim(), with direct line of sight to adding make_shared() for in-place conversion. Have the x86 backend use make_{private,shared} (no reclaim()) for SNP, as reclaim in SNP-land just means "make shared". The goals are to eliminate the misleading use of the term "invalidate", drop the "prepare" terminology (which gets especially confusing with in-place conversion), and in general to prepare for the future. E.g. so that KVM ends up with something like: if (!to_private) kvm_gmem_make_shared(inode, start, end); instead of a funky: if (!to_private) kvm_gmem_invalidate(inode, start, end); and #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT if (kvm_gmem_is_private_mem(file_inode(file), index)) r = kvm_arch_gmem_make_private(kvm, gfn, *pfn, (kvm_pfn_t)1 << *max_order); #endif instead of the current bare: r = kvm_gmem_prepare_folio(kvm, slot, gfn, folio); We'll still need changes for things like TDX hugepage support, and obviously to add kvm_arch_gmem_make_shared() for in-place conversion, but I think/hope this sets the stage for SNP, TDX, and pKVM to build on the arch hooks without needing to make non-trivial changes to the core semantics. v6: - Provide separate make_{private,shared}() hooks instead of a single convert(), because forcing a single API just meant multiplexing on the front-end, and de-multiplexing on the back-end, along with weird sanity checks to enforce different requires for private vs. shared. [Ackerley] - Kill off per-folio preparation entirely. [Sashiko, because Sashiko kept finding bugs in my attemps to refactor the code, so I went scorched earth]. - Pull in "Only "prepare" folios for private pages" from the in-place series to make it easier to kill of per-folio preparation. - Collect some reviews (dropped many since things got reworked, at lot). v5 - https://lore.kernel.org/all/20260714231015.3337831-1-seanjc@google.com - Drop the VMSA fixes (already applied). - Keep a dedicated reclaim() flow. [Fuad, Ackerley] - Pass a gfn, not a gpa, to convert() / reclaim(). [Ackerley] - Collect reviews. [Ackerley] - Align the gfn when folding __kvm_gmem_prepare_folio() into its caller. [Sashiko] v4: - https://lore.kernel.org/all/20260709204948.1988414-1-seanjc@google.com - Collect reviews. [Mike, Ackerley] - Rework prepare()+invalidate() into a common convert() instead of simply renaming invalidate() to reclaim_memory(). [Ackerley] - Fix several (mostly benign) issues in the "prepare" flow. v3: - https://lore.kernel.org/all/20260630222607.497895-1-seanjc@google.com - Ensure disabling quirks while the VM is live won't result in KVM skipping the back-half of "zap all fast". [Sashiko] - s/gmem_free_folio/gmem_reclaim_memory. [Ackerley] - Use {READ,WRITE}_ONCE() when accessing the guest's VMSA GPA outside of the per-vCPU mutex, and comment. [Sashiko] v2: - https://lore.kernel.org/all/20260626231416.3943216-1-seanjc@google.com - 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 Ackerley Tng (1): KVM: guest_memfd: Only "prepare" folios for private pages Sean Christopherson (8): KVM: guest_memfd: Pass the number of pages instead of the end pfn into .invalidate() KVM: guest_memfd: Rename invalidate() arch hook to reclaim() and isolate it KVM: x86: Rename kvm_x86_ops' gmem_invalidate() to gmem_make_shared() KVM: guest_memfd: Drop the redundant printk on arch gmem_prepare() failure KVM: guest_memfd: Add helpers to query SHARED vs. PRIVATE for a given page KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private() / CONVERT KVM: guest_memfd: Explicitly pass number of pages to make_private() hook KVM: guest_memfd: Make private exactly what can be mapped on page fault arch/x86/include/asm/kvm-x86-ops.h | 8 ++-- arch/x86/include/asm/kvm_host.h | 9 ++-- arch/x86/kvm/Kconfig | 3 +- arch/x86/kvm/svm/sev.c | 35 +++++++-------- arch/x86/kvm/svm/svm.c | 4 +- arch/x86/kvm/svm/svm.h | 4 +- arch/x86/kvm/x86.c | 18 +++++--- include/linux/kvm_host.h | 10 +++-- virt/kvm/Kconfig | 6 ++- virt/kvm/guest_memfd.c | 68 +++++++----------------------- 10 files changed, 71 insertions(+), 94 deletions(-) base-commit: 6bc96b971766fbbbbdd9fb2642cedacaf02da957 -- 2.55.0.229.g6434b31f56-goog