From patchwork Wed Jan 29 17:23:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44CFFC0218D for ; Wed, 29 Jan 2025 17:23:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC07628007E; Wed, 29 Jan 2025 12:23:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A516B28007F; Wed, 29 Jan 2025 12:23:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8979A28007E; Wed, 29 Jan 2025 12:23:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6BE86280067 for ; Wed, 29 Jan 2025 12:23:30 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DDB0B1A0F45 for ; Wed, 29 Jan 2025 17:23:29 +0000 (UTC) X-FDA: 83061160938.20.A67411F Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf14.hostedemail.com (Postfix) with ESMTP id E1026100013 for ; Wed, 29 Jan 2025 17:23:27 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lZFi3nRf; spf=pass (imf14.hostedemail.com: domain of 3DmSaZwUKCIM0hiihnvvnsl.jvtspu14-ttr2hjr.vyn@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3DmSaZwUKCIM0hiihnvvnsl.jvtspu14-ttr2hjr.vyn@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738171408; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RoF+4xfgxTm/p575y9XCqcSYW8AHz4umMJsaklpwUz0=; b=PfSEhahpmXDSPCt0lJtAKSNHp2zog6TWrZsGq2T6rglTykTd4csSD7WhesBeJ/e7k85zT0 7vSDqeIuZVJc/MuB8Khut/kmqSLNT5JfCA37U7gFtYKNUw3+PqKl5DfXRR+A23NBLoOVTi DqGpRiUeENGf5X5A7spGqlWcgvnNlv8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171408; a=rsa-sha256; cv=none; b=KQwPwqf6cKmOpdwmNNgnteX95dCe2L9k4OUng9RYFpUV5cmygapExlLaIwxNCJ+jqfC9tr 9RkoILkzj/yzkz3mCfLTGwyIBq2cX+xpafiRU6+hjvv9SpaYgxn6AqfTVGjb4pBDmg+jQU HXhP6UE2+FzaRmL2ZZk2eWtwU7t2HaY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lZFi3nRf; spf=pass (imf14.hostedemail.com: domain of 3DmSaZwUKCIM0hiihnvvnsl.jvtspu14-ttr2hjr.vyn@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3DmSaZwUKCIM0hiihnvvnsl.jvtspu14-ttr2hjr.vyn@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4361efc9dc6so38426625e9.3 for ; Wed, 29 Jan 2025 09:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171406; x=1738776206; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RoF+4xfgxTm/p575y9XCqcSYW8AHz4umMJsaklpwUz0=; b=lZFi3nRfTI5Zh5P+DrUVlMjoy12fI09b3obPHypPwum8aibh/jrcvabFu+H0fXp9AJ AXHeeBqfXJ/i/I18kFqQGvMyYQ116Ae9nSs7zkndYE/87tHuoILGNVY4PMo2tLGblj86 WnBX7qEklxSrdKds7rLedVgRQMrCIE15Eti6FtSt1RVRMuVy+IQ/gpZQ9gxFxY+UJvG4 GIiuLVT0TdDbiwDRLb8+L3Iv2+798UUM8fTiIIyqepSNvSfoTy90H1jn5NgeFDHYQjPn sGK2r9cDknEhNsx7fzzFLkl8+Y3dSXDtYRX5alP5oGiQN786CzezHiJNJm0ts/2W+AQ3 Fg5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171406; x=1738776206; h=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; bh=RoF+4xfgxTm/p575y9XCqcSYW8AHz4umMJsaklpwUz0=; b=JHgCdGLWEaYWafkD09O0gKPaifHO+tL7bphj3hFmFs4XDax58c04yc43tP13brhQ0U 7y7HlTRe7+cZwi7LpVX1PHllTIroXupQN6a/7STFQI9oZy/gCZsfe8m1pUUYI8RyLgCW CAcuhHbiRFdzpLE0R/nC8W8SooPeJ/dIukVoPaZu3mcM/W6LSNPPuZijqHKzbk07FUln /q3I6BYX2RyUw3xMyLMcnFRp/mTl762j7Vvf6+B+WGT1JS7RBF9FRqI6/kO1kqHMQGIW 80a0xYp5eu1lOuXnkCc29/anZ/YM5bFj8k3slE/nBsbnikwMbeeSKWu6hmKETdAl9AzP S5bQ== X-Forwarded-Encrypted: i=1; AJvYcCXNL+2bxXacsMWPrXjR4gdqYG98xyVbR/yMerY3RvkyBUxx95rZ+8+GrHfx74WcOjefHGs0vYevhg==@kvack.org X-Gm-Message-State: AOJu0Yw8XBEJf2fWXbPAoKuZkZ6KvD7IzPNhEAfwjCGC6Nuo4gEwCs1n xRPqePiy8HtujDw+uz4eXIa3v9+yS6RQvCQtwWN61RZ7L7yUJG5dIkV+5wfZlLCRVXTlbh1PzQ= = X-Google-Smtp-Source: AGHT+IGJ+0GvDv1cmo5xMm/8jI+35SnN2WajY5bhLqVpw0IOvEaGfT+KLFYF/7jjtxYb3vLecx8RvCq3Tg== X-Received: from wmaq26.prod.google.com ([2002:a05:600c:6c9a:b0:435:51:727b]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e52:b0:434:9dfe:20e6 with SMTP id 5b1f17b1804b1-438dc3fc2b0mr35391245e9.23.1738171406534; Wed, 29 Jan 2025 09:23:26 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:11 +0000 In-Reply-To: <20250129172320.950523-1-tabba@google.com> Mime-Version: 1.0 References: <20250129172320.950523-1-tabba@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250129172320.950523-3-tabba@google.com> Subject: [RFC PATCH v2 02/11] KVM: guest_memfd: Handle final folio_put() of guest_memfd pages From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com, tabba@google.com X-Stat-Signature: i9sczw794zukmqsud9fm16599m864ezr X-Rspamd-Queue-Id: E1026100013 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738171407-705160 X-HE-Meta: U2FsdGVkX189lzY4C+qjX0CXFpRx+Lc5XhM3s16vl8xwjMytrtyCRgwAxWiP/hnLCsd06xf27vA4+CZzFooi1N0U5xt1H/Tfi3zST/o+My4cuuf2XFDW4mQEF+Zp7bFLCQPv7RDDFDErKrEV9r7gi1Jkxuxu+Ec+rV5JKMehvkZKlviZB75Y68Rnc/EUPJUdw4bwAMCAo22tQ/2Ea0zxvgkG6xAODgQGdBDd0wFZgYntJfdPPYzafz5lBze1sNFfQYXH814ceFeStJrEX2uNrcYHkOSKmfWobh7AqKBBm7XeY/v9U9MBYWvEM0LkAqtQXGDUE3gOy6APq73D7/OqfhF5atqiHvRthoB6s/aMPnD2fiEnYDRPNlx0t0Rs71MQz4l8CJgdrU9h7rZxFJStTb1IidV9KbOEONPT8ixvD9NVhb5IQlqwJaEO+MYV0+qms+rwlVAlmK46UAgrEIpr9TLTK8bqLqIM6CyjR1eWwUdEYICpsEy87qsI93UlSfDUZLBSx4ZatjhZMq7ur7EuyLdw4VIwjYfhVLbuIgmhR6B3ZpUeq4lfUzyM3TJUQP/U142TpUovfqf2w6oF8p95S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y9FucQQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Before transitioning a guest_memfd folio to unshared, thereby disallowing access by the host and allowing the hypervisor to transition its view of the guest page as private, we need to be sure that the host doesn't have any references to the folio. This patch introduces a new type for guest_memfd folios, which isn't activated in this series but is here as a placeholder and to facilitate the code in the next patch. This will be used in the future to register a callback that informs the guest_memfd subsystem when the last reference is dropped, therefore knowing that the host doesn't have any remaining references. Signed-off-by: Fuad Tabba --- include/linux/page-flags.h | 7 +++++++ mm/debug.c | 1 + mm/swap.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 6615f2f59144..bab3cac1f93b 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -942,6 +942,7 @@ enum pagetype { PGTY_slab = 0xf5, PGTY_zsmalloc = 0xf6, PGTY_unaccepted = 0xf7, + PGTY_guestmem = 0xf8, PGTY_mapcount_underflow = 0xff }; @@ -1091,6 +1092,12 @@ FOLIO_TYPE_OPS(hugetlb, hugetlb) FOLIO_TEST_FLAG_FALSE(hugetlb) #endif +#ifdef CONFIG_KVM_GMEM_MAPPABLE +FOLIO_TYPE_OPS(guestmem, guestmem) +#else +FOLIO_TEST_FLAG_FALSE(guestmem) +#endif + PAGE_TYPE_OPS(Zsmalloc, zsmalloc, zsmalloc) /* diff --git a/mm/debug.c b/mm/debug.c index 95b6ab809c0e..db93be385ed9 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -56,6 +56,7 @@ static const char *page_type_names[] = { DEF_PAGETYPE_NAME(table), DEF_PAGETYPE_NAME(buddy), DEF_PAGETYPE_NAME(unaccepted), + DEF_PAGETYPE_NAME(guestmem), }; static const char *page_type_name(unsigned int page_type) diff --git a/mm/swap.c b/mm/swap.c index 8a66cd9cb9da..73d61c7f8edd 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "internal.h" @@ -101,6 +102,10 @@ static void free_typed_folio(struct folio *folio) if (IS_ENABLED(CONFIG_HUGETLBFS)) free_huge_folio(folio); return; + case PGTY_guestmem: + if (IS_ENABLED(CONFIG_KVM_GMEM_SHARED_MEM)) + WARN_ONCE(1, "A placeholder that shouldn't trigger."); + return; default: WARN_ON_ONCE(1); }