From patchwork Wed Jan 29 17:23:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953966 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 E2709C02193 for ; Wed, 29 Jan 2025 17:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F057328007F; Wed, 29 Jan 2025 12:23:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8B5C280067; 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 C9215280080; Wed, 29 Jan 2025 12:23:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A04A9280067 for ; Wed, 29 Jan 2025 12:23:30 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B77F4A0FD1 for ; Wed, 29 Jan 2025 17:23:27 +0000 (UTC) X-FDA: 83061160854.14.5ED393B Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf01.hostedemail.com (Postfix) with ESMTP id E1DE640015 for ; Wed, 29 Jan 2025 17:23:25 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dPoqhIZT; spf=pass (imf01.hostedemail.com: domain of 3DGSaZwUKCIEyfggflttlqj.htrqnsz2-rrp0fhp.twl@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3DGSaZwUKCIEyfggflttlqj.htrqnsz2-rrp0fhp.twl@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=1738171406; 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=iDaVGDLi8mgRhdRmBEo1g3AHoA0NuWvKpi8mcLq23xA=; b=MKMpHBGKJteFHvIM6N2AwoPxRYMZyfEh9KCT+Z8oVOszC46EL4C6okq8/vit2DRvBGjR4u JQTJfvn0R4tLrOi8dgpCgftEdjO5U7XHmdCQ10EWN5yrOzVAaB26A6lzy1Ep4zjWi0bqQd u+FuvPaXjnLn9zzuTdwmKp6Xd4FvUEU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dPoqhIZT; spf=pass (imf01.hostedemail.com: domain of 3DGSaZwUKCIEyfggflttlqj.htrqnsz2-rrp0fhp.twl@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3DGSaZwUKCIEyfggflttlqj.htrqnsz2-rrp0fhp.twl@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171406; a=rsa-sha256; cv=none; b=ucSJhOqvl5sqmeesAtA/QXjWIsletfsa44QpZq9KGrf8ak2cnbTCAxjI5bIx7MKnb59MDQ UQ4kXVo3B5x7yGpecvvRlZ6GjZligk4LgbPXJ0yznwG/TZKVl7iU6O1N5AV10Bw+V4meYv 75U0cjMC+m3gLucpLSKLMuGVC3fVE2o= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-438da39bb69so12012775e9.0 for ; Wed, 29 Jan 2025 09:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171404; x=1738776204; 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=iDaVGDLi8mgRhdRmBEo1g3AHoA0NuWvKpi8mcLq23xA=; b=dPoqhIZT9SCp0D1B9W6eVW7Eh1cswWwGM43eLz/oMys7KBgXuruAWJZk4sEXvD4Gww W72nCnx7hsrhECWDdUO/VTXg1IFxgGCM3BFfiZH3syWnhZnIgG2rUkTJo9Of6LG6rE+P CfA4iGPDmQKFle7tGk4wUBS66RP6MrA7wyt3vi9qznf6MywB+U7ehPr33/qSIx+MJd5y r1IXA6nIBsVKWMITWRGdN9Y/9YUxgYD3ydFhXsVoPWvDpFtVolLdUCBw4H+eXHS1HnrH lUFxnimsBmTIRBH7pR/bqcVH+2KOZiAJne+FR/mrcYwWsWmhkxbPCBujMy7wOtuNNyMw BLtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171404; x=1738776204; 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=iDaVGDLi8mgRhdRmBEo1g3AHoA0NuWvKpi8mcLq23xA=; b=BFBkP1pPyfCcwHiyJo89FFcJosFI2MGzGiNjfOYwifeIHQXLGYHZnpJdxvQ/8Z1PxV e9V0nBkr8qlfg6giRlGyTv14qCQOGzsFoh5emWR3udIyKCwq8WBOaDjOOMv/9PjAq9d2 aLBg0f9e8hGesii/62CvYXoHYYU6++1LE6prqFhIRzQ6w1JpO/rURXZ1ZBAgF2PgyLS0 nLA54LmLTxxDrAHXkoCBYXF16FR9pWk2Ge88/tV86NZ9+WuI8hthH26fm8cGINP2BGIf tr3Hc9tkgphiU/Vc2PK58DBIuLnGOuGfI29A0vaDginCZ8LrUUWNTEVO06+rla8lcBzf 6ObA== X-Forwarded-Encrypted: i=1; AJvYcCUSL87Nv6+cY3qwjXxFdl0danpS4MVp7+PiulwKmnWgV1DR3OjhVoNU44MOlDmtTe3N9/PWMDe1Fw==@kvack.org X-Gm-Message-State: AOJu0YzukoicTRUSFpD8uI5H3h31RsoXWrKyidKwv3iX9ZOY44rSJ5IQ x7UqHeZwC7dMYLREtOOrZaaaVed7DWuOpMk/EYfdYbbu6xWkMV2iEI2ncglIi5x634t1oF9fkQ= = X-Google-Smtp-Source: AGHT+IG7AAxXO9uUL/TV8lWRjQ0ckYe36dATBMk94k2BjGqrWcfbwhKyc4W7DSJHTwQDQb5yqHpv0ii9Sw== X-Received: from wmbbh25.prod.google.com ([2002:a05:600c:3d19:b0:434:f173:a51]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d26:b0:42c:b9c8:2bb0 with SMTP id 5b1f17b1804b1-438dc3aa595mr34124635e9.4.1738171404499; Wed, 29 Jan 2025 09:23:24 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:10 +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-2-tabba@google.com> Subject: [RFC PATCH v2 01/11] mm: Consolidate freeing of typed folios on final folio_put() 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-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E1DE640015 X-Stat-Signature: j5bamm15zcy5ag8ujhzf7eqaquwe8ikb X-Rspam-User: X-HE-Tag: 1738171405-660170 X-HE-Meta: U2FsdGVkX1+F/BCbJOgUUMGnaty2EoFtWI3m8m87QOw/+n2TDRTCKtnTgUjllR5G2Af5WNYqvUiD33RhS533aETsJHYflOO/RV0G6IIX4SEtSf41ulLqIz//K4/r3zReonN/6kixxBrItkbJhAhAC4q+bfjQLGTK79TmJK9AaXqB6leJqmmBSp/qqw5Qhxth/OHr9fPWNMS85wuYMDnvrC/6fL8BN0l9IcDYypLJ7AndHVuqXgZYfPlK94fL/ntpFjzwu98Uydlxu29Z66r5dKcS65YIQAub0YfSPNGBfBCbj+4QTXqQ0NLqBu4Lzv0XmLk8eosHGseDDk65zjaJk2Uv5rmBfIylHms67ip7nlmj/d1fZHnNBk69XH3RZ+SMjAfBuQYGYwbsS46war9tZNbsJkTwCcjeVD3FaBK/qmWry7Eo/4bRrVJjH4PtX5W5b+/NugKIXnWdjkhb1GjUFDdpS/I42cZ1hJeF/y6LI2cKXDF4/j+O2SVIHRZlU4doTGioLXlaU/NPlHEQXM5iL/HEwjlh7ohMqVYkh17N3kPWsGV+oTOshhUlXgu/xR4mMGND/iXOT3SexmWVG2W0HRmpLe8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ests=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: Some folio types, such as hugetlb, handle freeing their own folios. Moreover, guest_memfd will require being notified once a folio's reference count reaches 0 to facilitate shared to private folio conversion, without the folio actually being freed at that point. As a first step towards that, this patch consolidates freeing folios that have a type. The first user is hugetlb folios. Later in this patch series, guest_memfd will become the second user of this. Suggested-by: David Hildenbrand Signed-off-by: Fuad Tabba --- include/linux/page-flags.h | 15 +++++++++++++++ mm/swap.c | 22 +++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 691506bdf2c5..6615f2f59144 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -962,6 +962,21 @@ static inline bool page_has_type(const struct page *page) return page_mapcount_is_type(data_race(page->page_type)); } +static inline int page_get_type(const struct page *page) +{ + return page->page_type >> 24; +} + +static inline bool folio_has_type(const struct folio *folio) +{ + return page_has_type(&folio->page); +} + +static inline int folio_get_type(const struct folio *folio) +{ + return page_get_type(&folio->page); +} + #define FOLIO_TYPE_OPS(lname, fname) \ static __always_inline bool folio_test_##fname(const struct folio *folio) \ { \ diff --git a/mm/swap.c b/mm/swap.c index 10decd9dffa1..8a66cd9cb9da 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -94,6 +94,18 @@ static void page_cache_release(struct folio *folio) unlock_page_lruvec_irqrestore(lruvec, flags); } +static void free_typed_folio(struct folio *folio) +{ + switch (folio_get_type(folio)) { + case PGTY_hugetlb: + if (IS_ENABLED(CONFIG_HUGETLBFS)) + free_huge_folio(folio); + return; + default: + WARN_ON_ONCE(1); + } +} + void __folio_put(struct folio *folio) { if (unlikely(folio_is_zone_device(folio))) { @@ -101,8 +113,8 @@ void __folio_put(struct folio *folio) return; } - if (folio_test_hugetlb(folio)) { - free_huge_folio(folio); + if (unlikely(folio_has_type(folio))) { + free_typed_folio(folio); return; } @@ -934,13 +946,13 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs) if (!folio_ref_sub_and_test(folio, nr_refs)) continue; - /* hugetlb has its own memcg */ - if (folio_test_hugetlb(folio)) { + if (unlikely(folio_has_type(folio))) { + /* typed folios have their own memcg, if any */ if (lruvec) { unlock_page_lruvec_irqrestore(lruvec, flags); lruvec = NULL; } - free_huge_folio(folio); + free_typed_folio(folio); continue; } folio_unqueue_deferred_split(folio); 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/v9U9MBYWvEM0LkAqtQXGDUE3gOy6APq73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9t/jHXCvr58KD2ARRfJeHrRWtmFu4z6XpeJQG7iFEO/c8/fQxIPnCTbF7xkCdrQv6dr4Lcf3lnFWwyKgVmeRilyGzlUzo2Db/2KXQ9c603S6KKEvh2yilD/bCSknKejRHYK2r9XwBULR1PXrHlv+2IEi2fiAkcUz5RUm3DZfe1zVa8nhTXCsEa978C/VphlInq7iZjJ5wfhx+ym6tvPXA0wsL58h+yh13FbTxmFbZ5po909SarS/HI86Ih3QJnSCTlVt7Jcy9FucQQ== 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); } From patchwork Wed Jan 29 17:23:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953967 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 6A50EC02192 for ; Wed, 29 Jan 2025 17:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AD9C280080; Wed, 29 Jan 2025 12:23:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E795280067; Wed, 29 Jan 2025 12:23:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6519C280080; Wed, 29 Jan 2025 12:23:32 -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 45769280067 for ; Wed, 29 Jan 2025 12:23:32 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 113D8A0A99 for ; Wed, 29 Jan 2025 17:23:32 +0000 (UTC) X-FDA: 83061161064.29.19DCD7B Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf16.hostedemail.com (Postfix) with ESMTP id 279DE18001D for ; Wed, 29 Jan 2025 17:23:29 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eSkmBjev; spf=pass (imf16.hostedemail.com: domain of 3EGSaZwUKCIU2jkkjpxxpun.lxvurw36-vvt4jlt.x0p@flex--tabba.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3EGSaZwUKCIU2jkkjpxxpun.lxvurw36-vvt4jlt.x0p@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=1738171410; 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=RoVkPwaMvkLCkrMEK45Vw1CTJ2upgTYFUQnx7UT1Wys=; b=j2vUXd53wJPQgvH9WtEDrISWKGEl2umcZ8BH+4KDQ/g7ROpwcIG/A3H2DdbxXsiiADymRt MniXw04EQwsFZl1BEkQztQBPZcFMi5zpoWfbA0+rjxfpVSTgyOga/LR0yiaWbJvKisPVP0 YRvCZuSqVWD9CSPEhIpOgvDj5O257fA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eSkmBjev; spf=pass (imf16.hostedemail.com: domain of 3EGSaZwUKCIU2jkkjpxxpun.lxvurw36-vvt4jlt.x0p@flex--tabba.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3EGSaZwUKCIU2jkkjpxxpun.lxvurw36-vvt4jlt.x0p@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171410; a=rsa-sha256; cv=none; b=SfM24yjW6z+VKp2oW68D6/Mp3mUzfcDB8gmpPjk40CiWkZEDBP5uDbKk0SvyYpneOENghf vjoYsyVJt81B+4rU5AgmejunxFHqN0AvONZ4UHqox8dMBVwaO7sHp0wB8pj3lxcCbTy1Vt ox2nNg/iWz+7HXCkjOeeYGjaOv7kbh0= Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-385fdff9db5so2511814f8f.0 for ; Wed, 29 Jan 2025 09:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171408; x=1738776208; 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=RoVkPwaMvkLCkrMEK45Vw1CTJ2upgTYFUQnx7UT1Wys=; b=eSkmBjevPyp1nO7v1j6X7JJwwCbdh7ufwQaU4rmXxNFh6tMLz2S+UovdIAshXRTZdX d3FvLEQ8YDPBiA9BU8Yf2yaCrQs5VTMqALUn71AIc7M+wQcRKVSMPpaQmjaIQcaHt8sT iUas1nqXxPQ4VCl86zeW0DpjzTUjw8vhf5xAsmS5uLJmk/Sj72J7vXhDPCMsNUChR8H5 teUb4vHX1lxtzVqBovlwLKgu1OIBwILqAV2+tQj6attFuLYjH/nHJ6Jk13nKWf8+iCz2 91QuVSXzeWJfLuxWljRO5TxBJUnNERgzgT7eaoxLMdtykJK7LRkSeCuHEAHzv8sqZPoO Sk3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171408; x=1738776208; 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=RoVkPwaMvkLCkrMEK45Vw1CTJ2upgTYFUQnx7UT1Wys=; b=dzhzGWTxQCZ40MniHvTLEUjx9UVf9S2bfSStI9+Z9HzJCg3nVbBaomtD0SOOxX2ZhL KuiguTle35IG2XXFg8y5QOvS+z2zBbCw0h6pW3j+CTNmsKce7S0dMx77fcCdCUI39v3V Ok+eLXlNTs92MupvaTz5kUen0Mog4GCyxgPPI6wA4HzpgAy0BeCRNLZuzb+bQ8UlNcSv JFmYJN/LNKM4eOuuhDsbRR8/HQQuZAorKokeL87pQdHdTOhvbJgy84kq19wNFq+9IZ0c EvT70xKAxlgRtRixYcVT5Mu/gZ13LhZgJhs9JsGGrPCV6coAJyUMmOx9KEEPBEKex1K/ 2ing== X-Forwarded-Encrypted: i=1; AJvYcCVxLO+TZfnzHFTRoatb/H83BKbdnJFGL788PJxwIT74CJX/Oq+svr2jUYrWARWFAIsEBk4v3n7oCw==@kvack.org X-Gm-Message-State: AOJu0YzORwFWXl4MXObfB0PfR0hrY11SdRLzixo0Z9Z0ZviowgGdca3H vLwqeRVHvclbkaAK/oWto/H/1NTjALF91HqSMv1knKlKZ/+ro+S/qyNKg7vUuXXou5P2v6VdCw= = X-Google-Smtp-Source: AGHT+IFhvEin4XE4wsGkRNdDKMzEHI3B5ItG8XmtbU1PM70tgZsQHYBr2xJu8rB4jweNCcCb7JB0XXISUQ== X-Received: from wmbez5.prod.google.com ([2002:a05:600c:83c5:b0:434:f9da:44af]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:154c:b0:38a:39ad:3e2f with SMTP id ffacd0b85a97d-38c5194c9femr3444938f8f.2.1738171408672; Wed, 29 Jan 2025 09:23:28 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:12 +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-4-tabba@google.com> Subject: [RFC PATCH v2 03/11] KVM: guest_memfd: Allow host to map 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-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 279DE18001D X-Stat-Signature: djped8wfutktrnh76h7nha4bkdafasks X-HE-Tag: 1738171409-539586 X-HE-Meta: U2FsdGVkX18Jr47xpqIZgaVx73XzMu59ahMuothCdpCP8QzZLkA85m0L+yjUe7z7sFFO1CbHZVedwgsvEmUQJquhLI9YeRO2iC1gsnE4B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/Oi2lUsFtUvGsOGrjrdnG3+MejaZNM/G1lOp0zMfu9oRjt1PonHJP9d0tjN7GqoBcIKsBImsmpU8k+IfiFakRKXBHa1szv+7kCJ+NkoRWWatBdHc5bHP4Kgz7YoTVJeJ3MXbWR/eR4dSfzycnzA72HziIhV3Y7+SgCQRtgCpskQHmbE04eWcdG+uiaK7Xq7Rgm/7d+0CSSuCQ2voUBg8KzTCXtXEFnQIYm36/VtUvdYS2DabL/4uvy13OP/zgIov9ZPIvRUlyS/ktbrTtv/uFsDIr5XnQbeviovEv43lGl9d4kY1pHgu602UnTIRB3l7p9bTJzLDGrm2HdqsVXPFlF+CGSzDMCoUvFkmFrZUxL3OzKT3gaygktSrZAXKkHzZ8Lbgb0OzXMa6E5ADkmrLMhEQ8qsYcRPVWNaWt36vabLTwclJtnWgKgjRZTL/e4GyeXIcbxUEvaA+lBl1e1ZeDP9jekmQ== 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: Add support for mmap() and fault() for guest_memfd backed memory in the host for VMs that support in-place conversion between shared and private (shared memory). To that end, this patch adds the ability to check whether the VM type has that support, and only allows mapping its memory if that's the case. Additionally, this behavior is gated with a new configuration option, CONFIG_KVM_GMEM_SHARED_MEM. Signed-off-by: Fuad Tabba --- This patch series will allow shared memory support for software VMs in x86. It will also introduce a similar VM type for arm64 and allow shared memory support for that. In the future, pKVM will also support shared memory. --- include/linux/kvm_host.h | 11 ++++++ virt/kvm/Kconfig | 4 +++ virt/kvm/guest_memfd.c | 77 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 401439bb21e3..408429f13bf4 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -717,6 +717,17 @@ static inline bool kvm_arch_has_private_mem(struct kvm *kvm) } #endif +/* + * Arch code must define kvm_arch_gmem_supports_shared_mem if support for + * private memory is enabled and it supports in-place shared/private conversion. + */ +#if !defined(kvm_arch_gmem_supports_shared_mem) && !IS_ENABLED(CONFIG_KVM_PRIVATE_MEM) +static inline bool kvm_arch_gmem_supports_shared_mem(struct kvm *kvm) +{ + return false; +} +#endif + #ifndef kvm_arch_has_readonly_mem static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm) { diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 54e959e7d68f..4e759e8020c5 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -124,3 +124,7 @@ config HAVE_KVM_ARCH_GMEM_PREPARE config HAVE_KVM_ARCH_GMEM_INVALIDATE bool depends on KVM_PRIVATE_MEM + +config KVM_GMEM_SHARED_MEM + select KVM_PRIVATE_MEM + bool diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 47a9f68f7b24..86441581c9ae 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -307,7 +307,84 @@ static pgoff_t kvm_gmem_get_index(struct kvm_memory_slot *slot, gfn_t gfn) return gfn - slot->base_gfn + slot->gmem.pgoff; } +#ifdef CONFIG_KVM_GMEM_SHARED_MEM +static vm_fault_t kvm_gmem_fault(struct vm_fault *vmf) +{ + struct inode *inode = file_inode(vmf->vma->vm_file); + struct folio *folio; + vm_fault_t ret = VM_FAULT_LOCKED; + + filemap_invalidate_lock_shared(inode->i_mapping); + + folio = kvm_gmem_get_folio(inode, vmf->pgoff); + if (IS_ERR(folio)) { + ret = VM_FAULT_SIGBUS; + goto out_filemap; + } + + if (folio_test_hwpoison(folio)) { + ret = VM_FAULT_HWPOISON; + goto out_folio; + } + + if (WARN_ON_ONCE(folio_test_guestmem(folio))) { + ret = VM_FAULT_SIGBUS; + goto out_folio; + } + + /* No support for huge pages. */ + if (WARN_ON_ONCE(folio_nr_pages(folio) > 1)) { + ret = VM_FAULT_SIGBUS; + goto out_folio; + } + + if (!folio_test_uptodate(folio)) { + clear_highpage(folio_page(folio, 0)); + folio_mark_uptodate(folio); + } + + vmf->page = folio_file_page(folio, vmf->pgoff); + +out_folio: + if (ret != VM_FAULT_LOCKED) { + folio_unlock(folio); + folio_put(folio); + } + +out_filemap: + filemap_invalidate_unlock_shared(inode->i_mapping); + + return ret; +} + +static const struct vm_operations_struct kvm_gmem_vm_ops = { + .fault = kvm_gmem_fault, +}; + +static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct kvm_gmem *gmem = file->private_data; + + if (!kvm_arch_gmem_supports_shared_mem(gmem->kvm)) + return -ENODEV; + + if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) != + (VM_SHARED | VM_MAYSHARE)) { + return -EINVAL; + } + + file_accessed(file); + vm_flags_set(vma, VM_DONTDUMP); + vma->vm_ops = &kvm_gmem_vm_ops; + + return 0; +} +#else +#define kvm_gmem_mmap NULL +#endif /* CONFIG_KVM_GMEM_SHARED_MEM */ + static struct file_operations kvm_gmem_fops = { + .mmap = kvm_gmem_mmap, .open = generic_file_open, .release = kvm_gmem_release, .fallocate = kvm_gmem_fallocate, From patchwork Wed Jan 29 17:23:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953968 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 06768C02193 for ; Wed, 29 Jan 2025 17:23:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C7C22801D5; Wed, 29 Jan 2025 12:23:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6501B280067; Wed, 29 Jan 2025 12:23:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B7AE2801D5; Wed, 29 Jan 2025 12:23:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 13D51280067 for ; Wed, 29 Jan 2025 12:23:35 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 37E66160F6C for ; Wed, 29 Jan 2025 17:23:34 +0000 (UTC) X-FDA: 83061161148.19.F594BE6 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf01.hostedemail.com (Postfix) with ESMTP id 47C0F4000B for ; Wed, 29 Jan 2025 17:23:32 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=vNWDnH92; spf=pass (imf01.hostedemail.com: domain of 3EmSaZwUKCIc4lmmlrzzrwp.nzxwty58-xxv6lnv.z2r@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3EmSaZwUKCIc4lmmlrzzrwp.nzxwty58-xxv6lnv.z2r@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=1738171412; 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=1nv4yVODl7ioMW6jJkbW1mbC87Wz7QQ6PPy9XEa8BJQ=; b=tTE2cmQTrXHaObhgsbv6hlUA9vrM5tCOSHpb2UQNz1qlzUVU5JCupMLDDir/ukBTeKekkZ bD75B7MZyxc48XP10kT03WX9TbmpPfBe0Aeg1KVNaH/31NqCaNTXKv9cslSeLIlHi4iwSn dULN8UrQGD+UGlPqGm9OBBGWgEps0so= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=vNWDnH92; spf=pass (imf01.hostedemail.com: domain of 3EmSaZwUKCIc4lmmlrzzrwp.nzxwty58-xxv6lnv.z2r@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3EmSaZwUKCIc4lmmlrzzrwp.nzxwty58-xxv6lnv.z2r@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171412; a=rsa-sha256; cv=none; b=iGy2YS0Vqc9kpyNZr+Dlt9YQ2kQl0b4gd++7NAX7+zmr42hY7fN9bZ4lk1wV1D1+1zEs3Y Sr517BgtpL9FCj/m5x7Asaygx7ZYlVA77Zl6sZD8t3vyNF/ez68uc9YZzUNb3ChdjKCWrg iLGy4JFVj4NyiOMGWojwM1L//fyVm+c= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-438d9f1faa0so10642395e9.1 for ; Wed, 29 Jan 2025 09:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171411; x=1738776211; 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=1nv4yVODl7ioMW6jJkbW1mbC87Wz7QQ6PPy9XEa8BJQ=; b=vNWDnH92DLaXVpDlF7UDa4mEbDP+3Q1b1zTswZvUb3kBinHim28xcoGnAo1MYaAy/+ 84Wng2XfgrPbuubXENicVxtEUpHPJb6JOK9OxATUPl5172p25TVDOB63qW1yZeojw73K 878J7bdI9i/zdhX2WUvNsl2aCIF0e+qSWZh4DOGn+1zmtf81lLUtEMfq8Rdhc9/1V3Q3 KBvud5j9ZpIQ0hZN2rFLYK14Sl0jwEpqC/AQ3mjKEMrPar1/pALxI8maewdn4+3J5Sjk gN9WmEapcjWKb3HirwHkYFX0zuTO0s1aCLD27Eoj1OieEdshnWdSDY3VwCxxzUfxxbL+ hadw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171411; x=1738776211; 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=1nv4yVODl7ioMW6jJkbW1mbC87Wz7QQ6PPy9XEa8BJQ=; b=C/pZoV+0pxwEfsmQkOHJUTBEPzFsGKB0tSyyL2YOPCA1mKbzMIeYmgQvtmakBvrTl9 qkB0tFXGREv688fqlrf9FeaBcTgXQ+szbOFi0iKEQq8k56pnBi6stkWup+WFnRCGOurQ H4/h7WDMFJecUroEQ8wIYADsUGJ7vSk9M9HYD5EuZFt+cokzAkq/p4cbP5eIzyo1YMxd +P3IwkA1zOEaUpD6HMPDVPryyqHWtP7Imcx2syZX83Vn1hhCcUtgeb2Y6cK2T5nDqh8+ 5tx7X4LefxHjK3EHhOJYGtwSjiyULj2fxOK1Esldo8FXzDqi2JN/5j9KNk8DRZvOY9Bk knLw== X-Forwarded-Encrypted: i=1; AJvYcCVa0/hjz0w2TH6NRwQMmNE2T/O2NZpCeVnpWyYEO9SiltvzTxdaKzMFheD/45uon2UsVlByI+Cuag==@kvack.org X-Gm-Message-State: AOJu0Yw6p5+WfMOkq3DXY6m0T0BDCBLGuhd2fs5UmjvPp3Ms4pInIZuZ K0L+mf2bSA/jCSp3/2NNJ8WLb5dqgATzV5e7w3Hy7odcbULp4b+BHumLi8cGJs3FVNFkqrH2Ig= = X-Google-Smtp-Source: AGHT+IFIuIn6HWlnbbn3OX1lNHWQpyl+hx+IsFXmYLoKnyKlPSNVYQFkHXDzngFkRTaSpQvhKnRXZbiDkQ== X-Received: from wmbjm10.prod.google.com ([2002:a05:600c:6aca:b0:435:21e:7bec]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a04:b0:436:e3ea:4447 with SMTP id 5b1f17b1804b1-438dc436a08mr37793435e9.30.1738171410842; Wed, 29 Jan 2025 09:23:30 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:13 +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-5-tabba@google.com> Subject: [RFC PATCH v2 04/11] KVM: guest_memfd: Add KVM capability to check if guest_memfd is shared 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-Rspamd-Queue-Id: 47C0F4000B X-Stat-Signature: ajtzsrm7hka69o4m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Y9/0hctmlGIdi4aCR+vkYgcqVchRSZVfZm4qdLbR74XqM+CsZJZVYMKn0kIOZEkXSzzfI2F8wDzYb/I+TARbL6kYBg6zYutlyj9dMBUjOFJfGRjM+GToaIA/dbjVcgQB7iEmR6IUW2+XHtKln1gwQBV0aodPV5NQlZMhzzgSTaAuqr2orSywW652SegdVT6935oeUJT0ddgQbTHkqew2ugD7+c47E/B7rzmhNzl05K9cd71UWWuXZefWUGM737a0DEA3gEr/5kiKyh4vF1Ds+0PFdjx5Gdz5Czq5OFqJQK+2V7M534iVQA14jCn1OEEM7z4JvJcBrsiXMTrx/ea6T2ut1oyKFM8ek9QcnsZy7w8vLsR9sDdmFvv9NYSvVXAkkZEJsIYSWo1U9OIaTORwv+KuH+hlyU/mBu4jdFOre8EHtGhU9IFARE7OSzDaDM497Z38NlBukz6lLUHmeCMIV8wi+I6V39dB8dtdtjeYX0pmNNMtf/psnf1EBVeHgpQUnFsTafC9P5tdNj1Dvz6dPm4zGGWVfqkyoOLqfFpBvIP7/gqBihBmyNZnfpWy87pE6w/TB57a/t+nSOa4OodTwYP7TQMhlDs+Xz6KZC3xGEUnwV7Swxd+LlchAlZZXd46PaWnJM3jF4Ahg== 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: Add the KVM capability KVM_CAP_GMEM_SHARED_MEM, which indicates that the VM supports shared memory in guest_memfd, or that the host can create VMs that support shared memory. Supporting shared memory implies that memory can be mapped when shared with the host. For now, this checks only whether the VM type supports sharing guest_memfd backed memory. In the future, it will be expanded to check whether the specific memory address is shared with the host. Signed-off-by: Fuad Tabba --- include/uapi/linux/kvm.h | 1 + virt/kvm/guest_memfd.c | 13 +++++++++++++ virt/kvm/kvm_main.c | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 502ea63b5d2e..3ac805c5abf1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -933,6 +933,7 @@ struct kvm_enable_cap { #define KVM_CAP_PRE_FAULT_MEMORY 236 #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237 #define KVM_CAP_X86_GUEST_MODE 238 +#define KVM_CAP_GMEM_SHARED_MEM 239 struct kvm_irq_routing_irqchip { __u32 irqchip; diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 86441581c9ae..4e1144ed3446 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -308,6 +308,13 @@ static pgoff_t kvm_gmem_get_index(struct kvm_memory_slot *slot, gfn_t gfn) } #ifdef CONFIG_KVM_GMEM_SHARED_MEM +static bool kvm_gmem_is_shared(struct file *file, pgoff_t pgoff) +{ + struct kvm_gmem *gmem = file->private_data; + + return kvm_arch_gmem_supports_shared_mem(gmem->kvm); +} + static vm_fault_t kvm_gmem_fault(struct vm_fault *vmf) { struct inode *inode = file_inode(vmf->vma->vm_file); @@ -327,6 +334,12 @@ static vm_fault_t kvm_gmem_fault(struct vm_fault *vmf) goto out_folio; } + /* Must be called with folio lock held, i.e., after kvm_gmem_get_folio() */ + if (!kvm_gmem_is_shared(vmf->vma->vm_file, vmf->pgoff)) { + ret = VM_FAULT_SIGBUS; + goto out_folio; + } + if (WARN_ON_ONCE(folio_test_guestmem(folio))) { ret = VM_FAULT_SIGBUS; goto out_folio; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index de2c11dae231..40e4ed512923 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4792,6 +4792,10 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) #ifdef CONFIG_KVM_PRIVATE_MEM case KVM_CAP_GUEST_MEMFD: return !kvm || kvm_arch_has_private_mem(kvm); +#endif +#ifdef CONFIG_KVM_GMEM_SHARED_MEM + case KVM_CAP_GMEM_SHARED_MEM: + return !kvm || kvm_arch_gmem_supports_shared_mem(kvm); #endif default: break; From patchwork Wed Jan 29 17:23:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953969 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 9EA4AC0218D for ; Wed, 29 Jan 2025 17:23:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 565F2280258; Wed, 29 Jan 2025 12:23:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53D52280067; Wed, 29 Jan 2025 12:23:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B8EE280258; Wed, 29 Jan 2025 12:23:37 -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 1B8ED280067 for ; Wed, 29 Jan 2025 12:23:37 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BEE3F120FD6 for ; Wed, 29 Jan 2025 17:23:36 +0000 (UTC) X-FDA: 83061161232.21.DE7E065 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf05.hostedemail.com (Postfix) with ESMTP id 592FC100010 for ; Wed, 29 Jan 2025 17:23:34 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=r769NHYk; spf=pass (imf05.hostedemail.com: domain of 3FWSaZwUKCIo7oppou22uzs.q20zw18B-00y9oqy.25u@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3FWSaZwUKCIo7oppou22uzs.q20zw18B-00y9oqy.25u@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=1738171415; 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=LUYJLmVCJmslu0EZ70wF3BbY2jfY7y/4QOInoyL0YSs=; b=NZuBpPPo/OFAiRKsqTUbz0R9InQrjTKxUqqBx75ZdCmMxNC/hdlWVpkP1e8ZfDNp6ePeye oXdoYKabcYy33TkiqJREv/4BXM8MvGwXYJRykzRxCgw4AbXo9IRqdwJEEWbKTOnLkSWdiD 4vN8YfbUyHvhHC1nYv16XQEkLBRB+PE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171415; a=rsa-sha256; cv=none; b=vPYCilSB72Mf29l1j9nwPZTJuAuV9diCf1AtaXawEH4AOWuh52vmiorqhhAr9W7W8nWyQh 6tNJVDQx7nnDO1BS3ozGzKy7CjDXRNZCOwVpxFJm2m5eyLWXpg3u0VyD8IQ6dPzqt8vI7u 4faa3THOkozcEnI71zf4H1XyaimBVRU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=r769NHYk; spf=pass (imf05.hostedemail.com: domain of 3FWSaZwUKCIo7oppou22uzs.q20zw18B-00y9oqy.25u@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3FWSaZwUKCIo7oppou22uzs.q20zw18B-00y9oqy.25u@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4359eb032c9so50903835e9.2 for ; Wed, 29 Jan 2025 09:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171413; x=1738776213; 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=LUYJLmVCJmslu0EZ70wF3BbY2jfY7y/4QOInoyL0YSs=; b=r769NHYkV0HtrTFK7OTJpalGLX8fnQCVQcqV7tKmwHoatfVJMPQZpl3e3ff+UodOMM 166PKPLi1EZHWuoZzKpRzu4Q8EduAxLNVmXU57PcBj+mDL3Fei7nCGldUqiUKakFGcXi DJHgt2xSP9Jj47P47/5QGSZZ5UgGgSwjABhWzH8bkajhgvyOZ9HzX/in6My9SOG5oMlr +kf6G39KPFhDUvKnSnqei6Dp7itmFYxK2yryBjTy9Bh0gxMAljoj0R2Bllzr1HaiWSed bWTBc0lXy/kjuyw1aCOGuTYkwyx5Imy60EGhIjAZ8wbOnCb+OlCcGlLZyPdWhytjLgML cpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171413; x=1738776213; 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=LUYJLmVCJmslu0EZ70wF3BbY2jfY7y/4QOInoyL0YSs=; b=Ueh9bzOFwfsNxgkXTdwCrgtCBWwosCH4DyCYxSsM50b7tRVaqwMrihjSex1UKVYuX/ S+E9cXFSFWpQdm11wOb4yE5xJUtKYS1B6+jdkFGXp20GcYVWyHc3hWhhyq2KeYnh6Eaq AwiOaPOL5fHWqcdBLIDuu3C0SNo1AWLPoBdcQSHo2Ifw6NRW3FKQfCfag8HYk8cZwUcZ mGr0MltoGCrn76rmgwdIOy1hRQatcdvK1eizbHcXc/tJ/0B+DdjxFKiojYWJY7jKMon1 fYwjFV9HC67fnW5XZP1gzmUim7dYHnV/h3EdoepNwPDR/wIo0MFNZ5bNr4iwPIN60Lvl gpUg== X-Forwarded-Encrypted: i=1; AJvYcCVlxQAAeCarUR9PIsgaDe7/wA7Z9U4TM2P8ZJSiZngJQhF6ccaoozq2sUzLtyexh9TwAj9Xmmjy/A==@kvack.org X-Gm-Message-State: AOJu0YyKvRGECxnoeLEctnHmAGWDTOfV7+Cbcv6AYCYbWGCHq7orhKx+ PoIdr9PZxK5C173uFpS/IoeD3b1IVWf94VX3CtsoWC0mUy7BpeGjIiQAHEwJLwKaAH862A0u2A= = X-Google-Smtp-Source: AGHT+IEzz5y+mMN5wvE2N/WLUB8ZD0NYIc/aKjbCfNBDRcZwxKLOkunY2FkpKk8kIiLC8nBZsvQDYPVFww== X-Received: from wmrn34.prod.google.com ([2002:a05:600c:5022:b0:436:3ea:c491]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1863:b0:386:37af:dd9a with SMTP id ffacd0b85a97d-38c5209037cmr4744111f8f.35.1738171413076; Wed, 29 Jan 2025 09:23:33 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:14 +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-6-tabba@google.com> Subject: [RFC PATCH v2 05/11] KVM: guest_memfd: Handle in-place shared memory as guest_memfd backed memory 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: qguz6ei93j8gqy5hezbwtennqstgaukm X-Rspam-User: X-Rspamd-Queue-Id: 592FC100010 X-Rspamd-Server: rspam03 X-HE-Tag: 1738171414-421783 X-HE-Meta: U2FsdGVkX18S02wiEwWAVa7JABRZSL2NN9tdMllQHnFR87FMnho6RvUkT9KMWIifr0VIPQF13bVl4kOTogg65Qeqy1KwpjGjYcxnk34bQ6ftP44PDGqhffLK80GqyfcqURKEnNiD/cX/Kh41w+mDqtOSScM6Ks84tvDkRRo4aIFLE6fQkaMKyHBFXN8V4TiWfQ5C6qqcjXAXLin4uGJ2+z9XVd+XN+42Im2fsnWV6FoMO22bmtloX57S36jLuFDd1+MipdSCl020tqSVACpV9M93HCig3PbZqiLI3o82PTTz2c9i0VZ6+tZPYZejWeHYSY3c6eDTg1lp2YiaMq3HfEjr9iXin0l7OkdG8WkdMYoeYrw2IOBMViaDDXbPgMi09uGMv776ciiG1SjnA3mBg4oqEJI3hfob0l28J+cs9JdqvCrCYNpp1am87aCi3UGVUjXoBikIAkmD766p5y1zqSNGlnjj7Rrki6PQQLIa6m81qhDQxtq1FT754awkz1/t4q3umaV+SPF5/Y7oHrVXtrWAI3ywEEzuTJ9pV6OnwydMk91z7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zWTNCKk0W+g== 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: For VMs that allow sharing guest_memfd backed memory in-place, handle that memory the same as "private" guest_memfd memory. This means that faulting that memory in the host or in the guest will go through the guest_memfd subsystem. Note that the word "private" in the name of the function kvm_mem_is_private() doesn't necessarily indicate that the memory isn't shared, but is due to the history and evolution of guest_memfd and the various names it has received. In effect, this function is used to multiplex between the path of a normal page fault and the path of a guest_memfd backed page fault. Signed-off-by: Fuad Tabba --- include/linux/kvm_host.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 408429f13bf4..e57cdf4e3f3f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2503,7 +2503,8 @@ static inline bool kvm_mem_is_private(struct kvm *kvm, gfn_t gfn) #else static inline bool kvm_mem_is_private(struct kvm *kvm, gfn_t gfn) { - return false; + return kvm_arch_gmem_supports_shared_mem(kvm) && + kvm_slot_can_be_private(gfn_to_memslot(kvm, gfn)); } #endif /* CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES */ From patchwork Wed Jan 29 17:23:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953970 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 55733C0218D for ; Wed, 29 Jan 2025 17:23:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF93128025A; Wed, 29 Jan 2025 12:23:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B7F2D280067; Wed, 29 Jan 2025 12:23:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AD0628025A; Wed, 29 Jan 2025 12:23:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 73173280067 for ; Wed, 29 Jan 2025 12:23:39 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D6619C0FDD for ; Wed, 29 Jan 2025 17:23:38 +0000 (UTC) X-FDA: 83061161316.06.F3711AA Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf22.hostedemail.com (Postfix) with ESMTP id E1343C0014 for ; Wed, 29 Jan 2025 17:23:36 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=DTyCUiPw; spf=pass (imf22.hostedemail.com: domain of 3F2SaZwUKCIw9qrrqw44w1u.s421y3AD-220Bqs0.47w@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3F2SaZwUKCIw9qrrqw44w1u.s421y3AD-220Bqs0.47w@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=1738171417; 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=yt94aUdAvXZMqsG3cEe+u7ei8ysAwqoWnN4dmeRVKOk=; b=nzUnyAelYrX04nMDhBZSxwPOmpzRe+9dwJPBn+Ve2Ntkgp3sHVPgICwlyUEDwl6B/VccQH oK3glDsdf00mogjdodDFFfr+7sl4RJuvN29+gCNcWISg4p5cfZel5J5MFepo/KrYGUIJTh yK/GMtVlw7bGVPOKSGu14z5MKXt58U0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=DTyCUiPw; spf=pass (imf22.hostedemail.com: domain of 3F2SaZwUKCIw9qrrqw44w1u.s421y3AD-220Bqs0.47w@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3F2SaZwUKCIw9qrrqw44w1u.s421y3AD-220Bqs0.47w@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171417; a=rsa-sha256; cv=none; b=nb5IgCfqZiOhknXkEmjDusLZpYkYAAQ7j6bWzeH2Yc4/cnNiXXp3TwMCzV4ad8td+G9PGU 6Y6rwZ23OuRUe3rFt+rxhIPRDpcfgI8XpAUDjT1dqKkHtwu5zl60u02xz5rPnwaPqJqccO 3+6D+yqfhzs9H8gr9m3jWHlDPjNjmhM= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-436723bf7ffso56536385e9.3 for ; Wed, 29 Jan 2025 09:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171415; x=1738776215; 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=yt94aUdAvXZMqsG3cEe+u7ei8ysAwqoWnN4dmeRVKOk=; b=DTyCUiPw5ypjhO4RV0eev9stu3rsfLE9Hw0tJ4H85390jiOj/akw2+gt4KK1eMtU9d nNE11GTZ9XjOhCr0xX4nkPaupykFR2o+u+UiRxDrnB6Pmt0zgQjvBq7N+cDULNgQDwKW y/6t/lxiVdQex42jP+bHQKUGvhxEzJHObk3iB7rXZ7fNzpCsPzXqT2tuG7MNkTaY5BOV 86IZDAuMvIJGVL90nH58NsL4nhA9DiAuewm05Zn+1p86XgtrM0aRXXvzSBqfrHD45QkZ Hg5r/XWxbBZKPp8JbMxVJ3WYL+Bx+aL/ma2C3WFGZE4mwzSZbxWDp2XGK0CBl4js+ZNq pHZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171415; x=1738776215; 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=yt94aUdAvXZMqsG3cEe+u7ei8ysAwqoWnN4dmeRVKOk=; b=S/ftoHZKEXhUMU599sibTnFw60A/+TN6qa7KfPPENnSQITWpcCtOgf8hASKe4FqMN0 lJW6vKWoTrS/Yzvg3rARxQB1PRlebGSin44JE+YgiuznradWBFm4A8b/eYdzE+w5I+gb y7Jy25dZCJzyDt4rDs6OYFgrhdQBdfUbtUFJMhs34/nfpHrnoSu6u1FCjpM4mXf8O+Mz uFhXFnqmsnbSZgAsUa78+BnbgIkxwXn6Nz1DAHLJjgMDWflM8saQi8UxaThJjJomUxmy 6QBTIWAbUxYPFoHCnPPPIrlSVoqBwI+XQtxlAgq4tndr7WSPVfxV4RtFZ0XKEucNRWTy vxtw== X-Forwarded-Encrypted: i=1; AJvYcCU4mIZLyAgT8lGHo2kCS9SRuVDe4bdkT8rTZkkbyRRQKtNt/mbJr2DOtVBn5FY6lOD6rHlzzd+0hw==@kvack.org X-Gm-Message-State: AOJu0YyPzh/SJNWwYZUUaDwB/THnuZTtGhcsjEn2AKTmTDEKRMiQg3lq 5pVSo7oOpmQbIJLVpCCigiP1PUzLxIfhReYdTsOw28a1De5CLygEM/6sfQ+He+cFaeXNHbTT1Q= = X-Google-Smtp-Source: AGHT+IEVZD0fIeUKq/vmlbjgjG2X+DT3UCWZpcJ4Ann1EaDXdRvf6zyGqzjMjCufoNNThN4KeHC2zb1K+A== X-Received: from wmbfk10.prod.google.com ([2002:a05:600c:cca:b0:434:feb1:add1]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d26:b0:436:916b:aaf4 with SMTP id 5b1f17b1804b1-438dc3c31a3mr45515505e9.10.1738171415500; Wed, 29 Jan 2025 09:23:35 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:15 +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-7-tabba@google.com> Subject: [RFC PATCH v2 06/11] KVM: x86: Mark KVM_X86_SW_PROTECTED_VM as supporting guest_memfd shared memory 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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AvF43qEYI6WtYGU5M71b h9fGOR+T UYIPG8ydWPSYUYGI1D1aXnQmUPoXaJgNZz70GitEN044av5eVMOOxrxb3SqHIGQyZdCzDc8McLCIqC8GpXM+L70Lae+jK+B9CnKPh2zE1JF7LQ5fajJ2/drRHiGUs+mTXanzUF8ALwRELUCBjEzPEM6mU+XPJqlDPt/nDYub6ppj0/25rXtspfm14fi24O5BFLTCwlwBDJnQtltOqSAfZ8eYmrPNF6S/rIOHH1PCpDVpy64nMN/L1mPp6DoVnnh36ABGkPEgujkExtlEzUZU9F0wryg7ViVbv2UM5nM1NeSvCyA1z53HfADWHpsZJWJ32efVY07q0kTy5yOnXPRWFop5uxMctKHtafqd9iyOawc7QFVWz+nsIvsdbEfINKPlTi38HaHSo9qZaOJvg+zKmXUhj6M4G9/RcPnzQL0uXysaDwTq32Ow4UdJDjDM5ifeo7IURXWuPI2rVGq8S1fDxy9ecq7fHyPaA02oYICq8F+DMYMlufFzO94BxOLSDuAIU6ebeAPqoRp7BxsbjAFzoGyvBuNdSfG2cTQ9OeyM3EK3B45FMYsro8izMEQx8mRM/GgiF8YZTyIjkGzQxSYWYbD/2Y1aWpjmI7lBxqpk0d11A0UGiZc/pF14UEa0bc3ejw5H0QVquXcCVZqCCpVLi3JOgKQ== 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: The KVM_X86_SW_PROTECTED_VM type is meant for experimentation and does not have any underlying support for protected guests. This makes it a good candidate to use for testing this patch series. Therefore, when the kconfig option is enabled, mark KVM_X86_SW_PROTECTED_VM as supporting shared memory. This means that this memory is considered by guest_memfd to be shared with the host, with in-place conversion. This allows the host to map and fault in guest_memfd memory belonging to this VM type. Signed-off-by: Fuad Tabba --- arch/x86/include/asm/kvm_host.h | 5 +++++ arch/x86/kvm/Kconfig | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index e159e44a6a1b..35d5995350da 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2202,8 +2202,13 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level, #ifdef CONFIG_KVM_PRIVATE_MEM #define kvm_arch_has_private_mem(kvm) ((kvm)->arch.has_private_mem) + +#define kvm_arch_gmem_supports_shared_mem(kvm) \ + (IS_ENABLED(CONFIG_KVM_GMEM_SHARED_MEM) && \ + ((kvm)->arch.vm_type == KVM_X86_SW_PROTECTED_VM)) #else #define kvm_arch_has_private_mem(kvm) false +#define kvm_arch_gmem_supports_shared_mem(kvm) false #endif #define kvm_arch_has_readonly_mem(kvm) (!(kvm)->arch.has_protected_state) diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index ea2c4f21c1ca..22d1bcdaad58 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -45,7 +45,8 @@ config KVM_X86 select HAVE_KVM_PM_NOTIFIER if PM select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_PRE_FAULT_MEMORY - select KVM_GENERIC_PRIVATE_MEM if KVM_SW_PROTECTED_VM + select KVM_PRIVATE_MEM if KVM_SW_PROTECTED_VM + select KVM_GMEM_SHARED_MEM if KVM_SW_PROTECTED_VM select KVM_WERROR if WERROR config KVM From patchwork Wed Jan 29 17:23:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953971 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 B20FDC0218D for ; Wed, 29 Jan 2025 17:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5664A28025C; Wed, 29 Jan 2025 12:23:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51635280067; Wed, 29 Jan 2025 12:23:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 342C828025C; Wed, 29 Jan 2025 12:23:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0FE33280067 for ; Wed, 29 Jan 2025 12:23:41 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C8891160F84 for ; Wed, 29 Jan 2025 17:23:40 +0000 (UTC) X-FDA: 83061161400.13.E0FE7AA Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf20.hostedemail.com (Postfix) with ESMTP id F05C11C0019 for ; Wed, 29 Jan 2025 17:23:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=hG7xCVG5; spf=pass (imf20.hostedemail.com: domain of 3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@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=1738171419; 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=clAA2pQ0aAsHHtJcPdsprveMf7sd3Qr2fHuajtMaEDo=; b=wsB4KrWNLX0HkirYgcvzO2RPJZ0Jx2QuYbpjWGyyAHdbgQL4iHBRvjf5TUqL9HsF2HqXcJ 7zJ9/RwocVQoSni8dSqbUdWBO3BnFxp2Z1HE9Kb+AxgtUVEY6rJyHJvC92Vk6HTGC54lKT weg4c31oxNeXuhdUOd+5b8K7PwVfLQY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=hG7xCVG5; spf=pass (imf20.hostedemail.com: domain of 3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171419; a=rsa-sha256; cv=none; b=7lRn5eoWCtHGafXtDb3V7aYVwRPsoWib9V1geVVl/SVXjvHigDyGItquoxzR2QDv7KS6Yt EWQ75Ar3JqsLK1CeEyBgkb/B0xeoj0pz//NYImmmk32rvFfiKq93TP9phCHrjkYq4QRzTX rRa3PKwrsf6C+o5LsSwdkEjYkKIDy8Y= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4388eee7073so4788955e9.0 for ; Wed, 29 Jan 2025 09:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171417; x=1738776217; 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=clAA2pQ0aAsHHtJcPdsprveMf7sd3Qr2fHuajtMaEDo=; b=hG7xCVG5KzbGS1+zuDxth/vlvPjeWOAy3khVm1AvsHg+9JDRa4wtRUvM+qjPIXi38u 88wpmECFETtzuk6I0Owaz6OSToQNwWWItE+g8v5MUkzpLQlRBfX39rNFmc39RYzNVLUI 6PElgV9HxAvY33pnfsdw3OwbC9QoM/awCgF9Lu0FZ1T5vNtXreKjb2O6DPf9vMoAyQ/C uA8pbp45mW54KgR+mN2Bo7V6QvHRJlWgdjEBNiR++IIrLmuYjfruAvjGL0xooD3BB+Nl d4uaWBvdcL/zwibaWQjXKG1QW+mtGP03P9mDYinzOySmdxMvLUj2c4QuiAyUGfMn8DPT aYpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171417; x=1738776217; 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=clAA2pQ0aAsHHtJcPdsprveMf7sd3Qr2fHuajtMaEDo=; b=mNLxrde7KWRYS3y64tsAuj08fqi1cvBM+yfaVY2k9X6GmqbI0dF+k1Jx4Te0IzD7ER wxnfRmshZqEisA4OskoE2/AJRtavkfx6BrClKlDEjQJXqtW/VOJLtdwv5TgG7wH7d9rB 7gXumagMjHvUBxYVsTbRbis8fhrfxrkhKov9l+jhvBp+bPKipcHNu3gnGKW3dGNOk7yF tK0u45kODf7NVNa36icQRBkLvdPY8No8hEksen1iXaWqILusyw2OH1YbqujdkD0IjNWi dLqX14IdXqsqlaUOLSwTrARqmn+5dvP5/4AuPtkYKw/fY5y96g0YJk4nlhVDY3lHwNRx ZGPw== X-Forwarded-Encrypted: i=1; AJvYcCWMuD4eDFVHg6jMM/HX18FXTSHWh+RftuUaH6X4aR4VJqJnnprd4y1LlFL5/EdxwXemvRLAKvkxGA==@kvack.org X-Gm-Message-State: AOJu0YyHTwHayKIPe+V+e6fIPF/tSXavHTGox8NKkO6ZbtQUE3gAGdUu d24GVQVl+uaBjJGUsyyhKmw9eGO/3h/VN073zvBwlzGzgfWy1uVdoJQNCwk7zuH5PM2EJGMqqg= = X-Google-Smtp-Source: AGHT+IH4Z/w8m7ect4Xjx7d6nFW4rotWrjkyMgHYG1tUIFYfo/owBhkDUsni5QfNbmeYmc7O93FGA8qkJQ== X-Received: from wmd22.prod.google.com ([2002:a05:600c:6056:b0:435:dde5:2c3b]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:b8d:b0:436:1b77:b5aa with SMTP id 5b1f17b1804b1-438e15e8307mr1177165e9.8.1738171417631; Wed, 29 Jan 2025 09:23:37 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:16 +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-8-tabba@google.com> Subject: [RFC PATCH v2 07/11] KVM: arm64: Refactor user_mem_abort() calculation of force_pte 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-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: F05C11C0019 X-Stat-Signature: 54ugbzask7itwztm9s6iju3ha64t75qe X-HE-Tag: 1738171418-258726 X-HE-Meta: U2FsdGVkX1/qUv6BA7XAyR0tjr8h2jkTIoERBKUJgYLQcRRVJNB1yUmKsZHKSOwEKOFF7/6QDxX+rBhqYoEZAt3vXFHiPQK7gEGQtSPooOCa6zLAo1tVVDe24D1vwLzByccYq85XdO+TD0F+rEjEPpfMJXbzdjB5bhHhBqUz0wym7VieIjVo8CzkrJfMSStJeZBm1e0Lpkk+fm+8FfNcgabTAdXg1VlAlrYo2AX2xYJkGMCOGG1hOseE2g2Xm7Mn6glhDFH3T2X2RzTFZ9fHY/GdDXhSJxvx0PZH4xmjJUq9x9ecZVmJIhHyPi0kVvrr8RmYNGQ+QwdhCL7V4QOqMxaD3QGjyc+Okx0/6KzP55r60FEH1w/MWdILhiJXRTWLc6Wf7CV2k1ysCcQLdGiVn5n+AyAhfCxnYZI5omGSMLvJ5lFi/awPzqDOnqvDURoqrc4OgIn49otz9AC5dDpBoEcp/UwOUBWRyAq2iTTttjqNhlmDffsXy1M7LUtgbX2k9tNP1Qjno3vYqLZwsvtQzcmAqLm1vWO1UVT8+48TXBzOVgBSuaVvy/puMfia82tkcZOsFygosbkbyLAHg4W9xoRQAU5kT8q2Bln2+Sr3pcQ2ZFy4N7ZPuqUiem9SBuBC48ibN2S0kup424WjstERqcRgU0eLGOzlzcdvrKSMJeyGkz+RRzQURJ0A5t4uLwXIb94F3k1ka+/5szHoiagH+Jd9Gr6f4gkLFzsxOeCnqTwMM3z7bdQnVZL3fBJpB432FtGYnBOgKvQWdAZBfPh9vf8SzhrFHjvWg5vhpMgjal79oKexH+Tnx8LRdiieGj/tSuX51OM7bvu+vDWVHf0fDw4WC5Xydz96aRGTObrkrGSC4h7A2AaeaDwInrN0LQ1I6wm2mrmKBanGUIBsfx76muNArYrCrGAxfO82DI/go98yp1Kor5BgYaIQFEO2XXQflHnYPh7++fPMBcoXUB8 JfRPAkJv R/6Fo++GYzvwClLkLQaCM6HiwBl9Ocn60jA+E9Jt8VgAiFtMNRBf26ZeHwtIjDy4AgBlXz+RwSwkYAUSVrrhij1T0A2Z8xM92nOea+qYwztR7Z0v3aUt/EWSyTpkMHxahuOKTRTuaPE+OP5s+0HryqcnV/ixkkYSLlKzCc6jfRaXIOHYdN3Mz1HyfV0z7Oc8r1Wlj+qJ8hAjxntjmOlQ4kDjF7c3k7Q9eL+ubjm1CVv40mUBfiaTng0qq/8zTKdbB8z4zIKWZh1oOGjb5vUc2loXBY+K0A4Tlexa4lSYEYLyAnwPinKFsgZb5QKUgnvhg63aC5MHbiXgRfWRzk+TIdlFKu75Lw16/l9YPt79K8sMnhxm2woTLuF9J6r/Ybtwmp6nin0sOrnjDharOv9LOOge4YDQOrTGr+3OjYsi3Swqn/YGeQyFA+wA8A9jGWjaJIHk/0IQoJJGxV+hL+gJ0ruHFtHfHZ9WKKXNSRYTFQ2cBen5HQ/fiBc4KBpg24vdOI+dOQTQDFSIqnJuniSDD++vEygQm9tVtmfP2ok4CgwXogagbxs5q+xQeLZaZvT9IJ8ZJkhDpKAm3zEiY58kU+tWcyTgIf75eXfissWh8aVP2P2bXlm7LvbhW8izKChJC3LgYB4QcisJfGkXkTuOSDCMnWw== 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: To simplify the code and to make the assumptions clearer, refactor user_mem_abort() by immediately setting force_pte to true if logging_active is true. Also, add a check to ensure that the assumption that logging_active is guaranteed to never be true for VM_PFNMAP memslot is true. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index c9d46ad57e52..1ec362d0d093 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1436,7 +1436,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, bool fault_is_perm) { int ret = 0; - bool write_fault, writable, force_pte = false; + bool write_fault, writable; bool exec_fault, mte_allowed; bool device = false, vfio_allow_any_uc = false; unsigned long mmu_seq; @@ -1448,6 +1448,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, gfn_t gfn; kvm_pfn_t pfn; bool logging_active = memslot_is_logging(memslot); + bool force_pte = logging_active; long vma_pagesize, fault_granule; enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; @@ -1493,12 +1494,13 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, * logging_active is guaranteed to never be true for VM_PFNMAP * memslots. */ - if (logging_active) { - force_pte = true; + if (WARN_ON_ONCE(logging_active && (vma->vm_flags & VM_PFNMAP))) + return -EFAULT; + + if (force_pte) vma_shift = PAGE_SHIFT; - } else { + else vma_shift = get_vma_page_shift(vma, hva); - } switch (vma_shift) { #ifndef __PAGETABLE_PMD_FOLDED From patchwork Wed Jan 29 17:23:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953972 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 7CC01C0218D for ; Wed, 29 Jan 2025 17:23:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B71A28025F; Wed, 29 Jan 2025 12:23:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 73DDC280067; Wed, 29 Jan 2025 12:23:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 540B828025F; Wed, 29 Jan 2025 12:23:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 341E4280067 for ; Wed, 29 Jan 2025 12:23:43 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E53EE1A0F81 for ; Wed, 29 Jan 2025 17:23:42 +0000 (UTC) X-FDA: 83061161484.16.A5CC362 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf12.hostedemail.com (Postfix) with ESMTP id 16ABA4000C for ; Wed, 29 Jan 2025 17:23:40 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2CSQTa8V; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3G2SaZwUKCJADuvvu08805y.w86527EH-664Fuw4.8B0@flex--tabba.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3G2SaZwUKCJADuvvu08805y.w86527EH-664Fuw4.8B0@flex--tabba.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171421; a=rsa-sha256; cv=none; b=C+etThlz2LndaGfG0V+P4ExyWVJ87GqJDQ5QE8bGhAP4ajvJoDGXXlEBZWiPCQ/T6A6Gyn 7ywnF5UFiecClQ/mcX04XZ80D/xCaXBZmpbHMX1Y8hBIV95u9ArHOfMqkVRVNZOK+8XdIc gj6oN9ckUfp6wyR7F2izQm9wUoJJM6U= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2CSQTa8V; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3G2SaZwUKCJADuvvu08805y.w86527EH-664Fuw4.8B0@flex--tabba.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3G2SaZwUKCJADuvvu08805y.w86527EH-664Fuw4.8B0@flex--tabba.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738171421; 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=gJUlshLqVqxF/x1Q6yciZ2xZ0kPW08W616puHCRAMyA=; b=4oovlwiyZhl2N3opObJ5HaynN0FjHD0uEGu4j7WAgTThZE3yZaGljOuvaFm2aML9o/dycW jHFv/7GVPqPq9z2Ju4+2X6HiL9M3sUE9BUQDZezn/0vXDFKS+sUrL5ldPoGnLpsrckc0My YekMgUFaNzeXdgzS6vyiD3xP2z+M7RE= Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38a684a096eso3189044f8f.2 for ; Wed, 29 Jan 2025 09:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171420; x=1738776220; 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=gJUlshLqVqxF/x1Q6yciZ2xZ0kPW08W616puHCRAMyA=; b=2CSQTa8V6vRzTP3ZluCAk42ujoMRiIV84Ua7JTQQwhBJZyp4PqO0kN+PHlZeTbNtrp aIPaZm5oMdvzczk8ezsWQjLdYyMBgjusHtYdHcIX/QWNn2mVz6KsBJV78D5tZ7kw5jvM e2jIED1Himkj/vuYwuDS2ZUoOlTYNxQG8f4HCK7GiOscI4aRG138KU8P5Cc2RGCWp04n v+BHJgK+J5RxiuHPv/k7EtfINKLW1hdLZdei8TxsKCKb07jhZ/x/vrvOikFTKbRshVQK 7fB2Gza3HpEzYWYFPems+Y4D1OTB/F0DLg3mzh9U69+uO3PktuGNyBVI68gFXxDuqWAg BztQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171420; x=1738776220; 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=gJUlshLqVqxF/x1Q6yciZ2xZ0kPW08W616puHCRAMyA=; b=EFY/sCZbzul1TPb9dNQt/EMV/zXbVeBZCpNa+U8oUeQ6RUc3ha5oANxWNGk0+Crq1n YZBRDwgZpgrDoNzOYhwXYskhYxaP8J36q/ThYzncHaM9qf/lE3MSGjwZ3mSp8zc8Eo95 lLRvZtDDZWMBmPv7H8RGhvUgB+Im7j2HEp5J8z3lWt7e+UNw5MMLR02byqnRt42yl58O xWhvWc+YKulS/MkTDHVH7QttZyBpzBycnWysO0peWemKVCsoZdybl7ntqTnC76OPrpjU HdfsX2nBsW9GIiQvAddsiBOoVN45cPXimny8N7B9yDReWVkYMT+2Yp0op86T0R5Cqgu9 RPXQ== X-Forwarded-Encrypted: i=1; AJvYcCUoWPHIBBSrSE8Fn0BP56GjZzIOvUomNYettmO1KEFj/mxm9jjNZ9qTZVPVhdf9UNiBeuN46na0oQ==@kvack.org X-Gm-Message-State: AOJu0YxvVxgm2a2EXc/PcRGbfLGQRRiFGKw0i+BqIBrLU2a8AReaOPn9 wRfz1D6TDmX+zkwZ26a+q2mECjn/U0Qi7w2VYKjN8aezX5aXQ7ssdTGC7ak/s8t7iVPUQgoBiQ= = X-Google-Smtp-Source: AGHT+IFusRcrVc4/78hZx6Io2rOdbnPNNEy+1FtewyjP5IWPByZvcuY2dAJE2DcSV4SFz55Z5sZ6LOwVmQ== X-Received: from wmgg8.prod.google.com ([2002:a05:600d:8:b0:436:e67f:5b4c]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:adf:fa11:0:b0:385:e8aa:2a4e with SMTP id ffacd0b85a97d-38c51b87e3fmr2896212f8f.31.1738171419742; Wed, 29 Jan 2025 09:23:39 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:17 +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-9-tabba@google.com> Subject: [RFC PATCH v2 08/11] KVM: arm64: Handle guest_memfd()-backed guest page faults 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-Rspam-User: X-Rspamd-Queue-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o8r W7i3pHXy V2ikv0BOlBK2g0a0alxZsl5PKK2OAOX+2M9/0ET+gu7eyQNYqyqzcZx+861BsfNeKPLy4BEgjbMxHlU4xjvWsKPqnOGUca5cAwztVz36DrU6FQQDObw71KHtVE2D43AL3VDLSUVigYJ9ChOZ6FBo5xiIPTiTXMAyCOa+CsU6OtknyVYMVdStgP4vFfwaSJFhJQ5tP7cld9EtCQDFAo62hZRO2X+wVJQ2/A6+a7BKOLisJ+IIQQhC2/SnHW/BKCLDHLer/lRFmkfFU9pBVSUIrZiIB1++mO3934eVxH0leYz25aHqjQM/AUjSSqvOH+tW4w/oHhOHtilytDB/xCd+dB4UGt+76485wmqKyC3/cLffwb+ZStO9AsHdC6cOQ4WcHLGQkmYUY5OaVDLh7Vr8sEuuao8LtJJn0T/84TuSLTAEDdMrlPd2kYHiwNEkwvmP3Ucbw5wx5LVeH7lAV3w6HH/xJHOyX8ZyaiwLD/Y2JGC17KyM21dc68d8/LYicdtQ8lCHkcoFG6qQewIv2Volu29LperPZmAy53b9GiQdwBqmNlGU0rZQuC5H7N5xLJ5H7PRuBNzo3d6v//R9nB0nMRvenu5cTfk1/g79jhjtVSn222Z90i2hIvN8k7DEb6FViVrsXsry2QigbqL/4I5qqrSTe/A== 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: Add arm64 support for handling guest page faults on guest_memfd backed memslots. For now, the fault granule is restricted to PAGE_SIZE. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 84 ++++++++++++++++++++++++++-------------- include/linux/kvm_host.h | 5 +++ virt/kvm/kvm_main.c | 5 --- 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1ec362d0d093..c1f3ddb88cb9 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1430,6 +1430,33 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma) return vma->vm_flags & VM_MTE_ALLOWED; } +static kvm_pfn_t faultin_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, bool write_fault, bool *writable, + struct page **page, bool is_private) +{ + kvm_pfn_t pfn; + int ret; + + if (!is_private) + return __kvm_faultin_pfn(slot, gfn, write_fault ? FOLL_WRITE : 0, writable, page); + + *writable = false; + + if (WARN_ON_ONCE(write_fault && memslot_is_readonly(slot))) + return KVM_PFN_ERR_NOSLOT_MASK; + + ret = kvm_gmem_get_pfn(kvm, slot, gfn, &pfn, page, NULL); + if (!ret) { + *writable = write_fault; + return pfn; + } + + if (ret == -EHWPOISON) + return KVM_PFN_ERR_HWPOISON; + + return KVM_PFN_ERR_NOSLOT_MASK; +} + static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, struct kvm_s2_trans *nested, struct kvm_memory_slot *memslot, unsigned long hva, @@ -1437,24 +1464,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, { int ret = 0; bool write_fault, writable; - bool exec_fault, mte_allowed; + bool exec_fault, mte_allowed = false; bool device = false, vfio_allow_any_uc = false; unsigned long mmu_seq; phys_addr_t ipa = fault_ipa; struct kvm *kvm = vcpu->kvm; struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; - struct vm_area_struct *vma; + struct vm_area_struct *vma = NULL; short vma_shift; - gfn_t gfn; + gfn_t gfn = ipa >> PAGE_SHIFT; kvm_pfn_t pfn; bool logging_active = memslot_is_logging(memslot); - bool force_pte = logging_active; - long vma_pagesize, fault_granule; + bool is_private = kvm_mem_is_private(kvm, gfn); + bool force_pte = logging_active || is_private; + long vma_pagesize, fault_granule = PAGE_SIZE; enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; struct page *page; - if (fault_is_perm) + if (fault_is_perm && !is_private) fault_granule = kvm_vcpu_trap_get_perm_fault_granule(vcpu); write_fault = kvm_is_write_fault(vcpu); exec_fault = kvm_vcpu_trap_is_exec_fault(vcpu); @@ -1478,24 +1506,30 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, return ret; } + mmap_read_lock(current->mm); + /* * Let's check if we will get back a huge page backed by hugetlbfs, or * get block mapping for device MMIO region. */ - mmap_read_lock(current->mm); - vma = vma_lookup(current->mm, hva); - if (unlikely(!vma)) { - kvm_err("Failed to find VMA for hva 0x%lx\n", hva); - mmap_read_unlock(current->mm); - return -EFAULT; - } + if (!is_private) { + vma = vma_lookup(current->mm, hva); + if (unlikely(!vma)) { + kvm_err("Failed to find VMA for hva 0x%lx\n", hva); + mmap_read_unlock(current->mm); + return -EFAULT; + } - /* - * logging_active is guaranteed to never be true for VM_PFNMAP - * memslots. - */ - if (WARN_ON_ONCE(logging_active && (vma->vm_flags & VM_PFNMAP))) - return -EFAULT; + /* + * logging_active is guaranteed to never be true for VM_PFNMAP + * memslots. + */ + if (WARN_ON_ONCE(logging_active && (vma->vm_flags & VM_PFNMAP))) + return -EFAULT; + + vfio_allow_any_uc = vma->vm_flags & VM_ALLOW_ANY_UNCACHED; + mte_allowed = kvm_vma_mte_allowed(vma); + } if (force_pte) vma_shift = PAGE_SHIFT; @@ -1565,18 +1599,13 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, ipa &= ~(vma_pagesize - 1); } - gfn = ipa >> PAGE_SHIFT; - mte_allowed = kvm_vma_mte_allowed(vma); - - vfio_allow_any_uc = vma->vm_flags & VM_ALLOW_ANY_UNCACHED; - /* Don't use the VMA after the unlock -- it may have vanished */ vma = NULL; /* * Read mmu_invalidate_seq so that KVM can detect if the results of - * vma_lookup() or __kvm_faultin_pfn() become stale prior to - * acquiring kvm->mmu_lock. + * vma_lookup() or faultin_pfn() become stale prior to acquiring + * kvm->mmu_lock. * * Rely on mmap_read_unlock() for an implicit smp_rmb(), which pairs * with the smp_wmb() in kvm_mmu_invalidate_end(). @@ -1584,8 +1613,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, mmu_seq = vcpu->kvm->mmu_invalidate_seq; mmap_read_unlock(current->mm); - pfn = __kvm_faultin_pfn(memslot, gfn, write_fault ? FOLL_WRITE : 0, - &writable, &page); + pfn = faultin_pfn(kvm, memslot, gfn, write_fault, &writable, &page, is_private); if (pfn == KVM_PFN_ERR_HWPOISON) { kvm_send_hwpoison_signal(hva, vma_shift); return 0; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index e57cdf4e3f3f..42397fc4a1fb 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1864,6 +1864,11 @@ static inline int memslot_id(struct kvm *kvm, gfn_t gfn) return gfn_to_memslot(kvm, gfn)->id; } +static inline bool memslot_is_readonly(const struct kvm_memory_slot *slot) +{ + return slot->flags & KVM_MEM_READONLY; +} + static inline gfn_t hva_to_gfn_memslot(unsigned long hva, struct kvm_memory_slot *slot) { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 40e4ed512923..9f913a7fc44b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2622,11 +2622,6 @@ unsigned long kvm_host_page_size(struct kvm_vcpu *vcpu, gfn_t gfn) return size; } -static bool memslot_is_readonly(const struct kvm_memory_slot *slot) -{ - return slot->flags & KVM_MEM_READONLY; -} - static unsigned long __gfn_to_hva_many(const struct kvm_memory_slot *slot, gfn_t gfn, gfn_t *nr_pages, bool write) { From patchwork Wed Jan 29 17:23:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953973 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 51EFFC02192 for ; Wed, 29 Jan 2025 17:23:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 085C0280260; Wed, 29 Jan 2025 12:23:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05D8C280067; Wed, 29 Jan 2025 12:23:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E19F8280260; Wed, 29 Jan 2025 12:23:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B2199280067 for ; Wed, 29 Jan 2025 12:23:45 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 41D63A0FF1 for ; Wed, 29 Jan 2025 17:23:45 +0000 (UTC) X-FDA: 83061161610.23.71FBBAF Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf16.hostedemail.com (Postfix) with ESMTP id 6B361180003 for ; Wed, 29 Jan 2025 17:23:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AEQ5jMJJ; spf=pass (imf16.hostedemail.com: domain of 3HWSaZwUKCJIFwxxw2AA270.yA8749GJ-886Hwy6.AD2@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3HWSaZwUKCJIFwxxw2AA270.yA8749GJ-886Hwy6.AD2@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=1738171423; 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=LJ160MXGhYFmROJLbL7eYj3t8ftygUUVZySLs0qAKPY=; b=ycoHeXWjlUCGDnrjgr2C+CeNR9wZcJsy3RzB0XJIHikJIRLw18vTxuoaMnPylW2yXDYdmS oKiQLHGiBsgd8VPdHiqiA9/4LcFXEzbgbCCbMoaYMippoR0BKOI+coyu/lxjWcGpOfnvQc WRucKnlN65GDw13Wl0G2zkiW5JJ7bQg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AEQ5jMJJ; spf=pass (imf16.hostedemail.com: domain of 3HWSaZwUKCJIFwxxw2AA270.yA8749GJ-886Hwy6.AD2@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3HWSaZwUKCJIFwxxw2AA270.yA8749GJ-886Hwy6.AD2@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171423; a=rsa-sha256; cv=none; b=qmOwmLoq/OA8xmtU20J8JGSjm7v8ec5RMXPGap83XviEu3mu06R8x2EUpKOblQ4QygISKT c5GLj1BP8TvdUhNO/TKrJpd740wY/C/Nrgtp7HYaNKVNFh6j1WROphIe8bb5d0CrBEHqpd JiUPu3drIhUN5B1KTYX4Pr2WhGyAhkw= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-436328fcfeeso54865715e9.1 for ; Wed, 29 Jan 2025 09:23:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171422; x=1738776222; 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=LJ160MXGhYFmROJLbL7eYj3t8ftygUUVZySLs0qAKPY=; b=AEQ5jMJJ+wkf1Vkz+aaV/PNSL1Vr//Ba0nvMc96h2ZT/k2QKyYu5nTyGt2QMKNHnOQ aii3/l5EHexhFlEOuR4pr51IZ5oXR4GBckgXYXBTiWaddMwysUroSox4f6c29vA8w34A STOKme96+NqZCcVGejE37/CG7UvmzJK8T3+4tsZcHO0LHQzX/z8M03Ekg3MLWVbtZLa4 IVU6JV/yw/6l9/AIjGwV73AeOHfSjgeSPJ3qjJ7G+bPCYqUPJg/vq8u/LjrzRRc+4VeA ro7uydSLW94XWVpj+dimpOpriM8F9PjJm9A1FsAObHsBbBS7iyJjuxb39i88qgVc+aiz ueYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171422; x=1738776222; 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=LJ160MXGhYFmROJLbL7eYj3t8ftygUUVZySLs0qAKPY=; b=KSMBmz9r/spR5Z349JBuGrHvJtEh407twTUX1qvApsK+LEg7taC9zdWWaSjOgCEiF3 btI5XYqAn8OJwN6EqhrooL9Vq/Isu2Jh/sWFbnk9z7ld9FQyXl+rRRLcUBabOVhU1FmT Z+Uvq8Tm/cptRqBkE5/PPvqcP/8E1Q68rQv3KTfGUHXsgLW/YpmI2ECkiX9/M4vHGvRF YO5Xzc6hwZr6nG7zv6EE7fdmUPyqUqFQVMV2gA4LPVO6FDGFFz04/V39vOAiE7B5zE9T 4LeiwnKvL8JJ3QyFGARIcJ0W2cRCOCL0i9e6MYqhXZSOkc3hIn3ibzSAw36/GqY/+OIG w1vQ== X-Forwarded-Encrypted: i=1; AJvYcCXRSnUsDk9acDLYL4kD9mv6t0BOp+ysvONnLvv2Es4m1A4MwURW4HFgR4c4ij56mokSGuIxD7K1EQ==@kvack.org X-Gm-Message-State: AOJu0YzxhCRox6+GsFXNqafqgd9hFTuFAp0E9QKNMCBXl8XnYkTjgDpR rL3diz1fO0s361fvlGPax0bMPh8YC7OyHwXCeLALX2VW1dKjgi/kYTxHUatOGZ9TzxLEmaGE7w= = X-Google-Smtp-Source: AGHT+IHzze1fd9XcgYyloPMAtmGdSptsFbtkXMC3i4as+lZ1qQjtORL3JE2QGX7gEDdKOF6yr1lLOcmjHw== X-Received: from wmbg5.prod.google.com ([2002:a05:600c:a405:b0:434:fb78:6216]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3b23:b0:436:f960:3428 with SMTP id 5b1f17b1804b1-438dc42ff3cmr36674135e9.29.1738171421994; Wed, 29 Jan 2025 09:23:41 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:18 +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-10-tabba@google.com> Subject: [RFC PATCH v2 09/11] KVM: arm64: Introduce KVM_VM_TYPE_ARM_SW_PROTECTED machine type 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-Rspamd-Queue-Id: 6B361180003 X-Stat-Signature: 3ao83wupzdrf59e8e81aen7z1uxz7tha X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1738171423-347474 X-HE-Meta: U2FsdGVkX1883qd+L0QBjOjzDLgRLZyteiPKmJ8ggalAcSYBAuqrZhTenCzgjn7eT9RkpQQt/aEDaGqZHcFqq+3uzH0pK4SbfOf2vEM12osHj0WQ5rljO9+DGgKDMAUoLmLqZZno/FML2o2ggD4xyuwpzALvRxTJJmT6eGVq5/rs0ytX3S4OKy0MuKQVB8lkYniOX6bKheWjTM+OXahCObgyRs4KPQDO73RpMZzhT5aa1gQUFO0DMnkl4hqxzx7wIs8ueMmC2NyiVN9wyP/0n9QICINURX5KZrBUnYAFn6DlUR7pKR5e0dUrNDGT1et0aCa6d3Ke+Va26AC2UEUStEcFlxQRjkLX/U41xZDEB1tie/9bxYLXyrmU8BXKo9nGA+uTkzVQQl2csIL3z2HlPs7T2gJpLZoPdN6cTUtaczdTiLWBm64pCSM6f42vls9rPzCJR6+MDv3cJeMDFPnbI0g6PZkQuOYTs8Ac9plqnLUzrP8/9YhJXQlGooDxz7afaR+LNq8OIGdRPUen46G0v5JqopeZfacTkZagp+WDn7tBPj1lfIE76VEYcr8F9YJenBlukBetPwaAPKFQ6SDrI0xTkgDeIqrcaTZIlfKtnjHUB1dCpoLLKkGK4zaCZEeehRrZ/VKoaN+/4l7MUr6lHF9zXHrrhTHPAYAfQb3rNP7jeRQxtgFVwG5Q2nSIdXH7robFMzkjnrFLWs5TxjYhqihdkzEkPC8Lyx6hBTARnXSQcqXXIObgNBs0197juaobCI+VTN6+hNJInI9oiZOItDehmb+d5gxrXKKFR9DR6a9CmwOiF9RXhHNRPWNVwMnlyOt52mfXuIIJIRaZrB69Xp6IT/8jcV30553XHp/TvYDTsTGZL7P68Wx4jfKF3+9Wmv59X1GSpv9abEBSQypN2ToSZmfPDNKb7r94IQIEHG7dp4uO0MFUz4KxE/ksm1qlss4m6t5SdEJ+5AljrEE hSxxmNiD w3vKLf6KAv+6LVN8JRAoTx6NBEVxkUn755p9rjkiXcJYmCDMUxK9WLqxm4Y89rNvSqBVwq8KWN/vCgA9tJqHyXTTUnEy09GUmgAVGYowdym42zM0B2RgdfsiZi6Omo9gFLNP/wZK9CEMewUP3wwRABL64154Odr96hCbZEl9mBn81V7CTyZ/+LW7fOoq85BPUq54+FOdikIwPT2cwsMAI1X/NFl2W3/rVTr5oxO1qVteMZOo1T1swmzcQsfdBBlGE61LciMz0+ansU8kYrbyhOhnJNxSb9pz9R2W/ih1leccID35T4exNDqCiimiE1OwtJ8R4yBdNyNfE4L4aszueijgJQqZJLKC05xVQAocCHMfii6PhPJqRM3ME+KwbEihEFkcinJyJ0CowI8E8X7u0obMPFu1+Mxe2gWJSsH+Rk5RIjH1trHfRBAMyK7jYzpDjtZY/esNLWh7r7h4Lmy4BsBapOczYujsPsJjQdovhwQKI3JcZvaeKMr2bEtjbLSjyAylm4MMG04I4lVIM10Wsof6y4Ax/TayYSRDedzyh6DnRS+m0s/qU0Dq7d/jUZ+FtHrv7dWrvFhkWpgXmmNcRsODyC0XriEBovuiw9XYewD8ZHXqY96O0swiMOIe58moZGUKZsGWS+sAHvHOL2WxvMhhMtg== 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: Introduce a new virtual machine type, KVM_VM_TYPE_ARM_SW_PROTECTED, to serve as a development and testing vehicle for Confidential (CoCo) VMs, similar to the x86 KVM_X86_SW_PROTECTED_VM type. Initially, this is used to test guest_memfd without needing any underlying protection. Similar to the x86 type, this is currently only for development and testing. Do not use KVM_VM_TYPE_ARM_SW_PROTECTED for "real" VMs, and especially not in production. The behavior and effective ABI for software-protected VMs is unstable. Signed-off-by: Fuad Tabba --- Documentation/virt/kvm/api.rst | 5 +++++ arch/arm64/include/asm/kvm_host.h | 10 ++++++++++ arch/arm64/kvm/arm.c | 5 +++++ arch/arm64/kvm/mmu.c | 3 --- include/uapi/linux/kvm.h | 6 ++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index f15b61317aad..7953b07c8c2b 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -214,6 +214,11 @@ exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects size of the address translated by the stage2 level (guest physical to host physical address translations). +KVM_VM_TYPE_ARM_SW_PROTECTED is currently only for development and testing of +confidential VMs without having underlying support. Do not use +KVM_VM_TYPE_ARM_SW_PROTECTED for "real" VMs, and especially not in production. +The behavior and effective ABI for software-protected VMs is unstable. + 4.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST ---------------------------------------------------------- diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index e18e9244d17a..e8a0db2ac4fa 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -380,6 +380,8 @@ struct kvm_arch { * the associated pKVM instance in the hypervisor. */ struct kvm_protected_vm pkvm; + + unsigned long vm_type; }; struct kvm_vcpu_fault_info { @@ -1529,4 +1531,12 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val); #define kvm_has_s1poe(k) \ (kvm_has_feat((k), ID_AA64MMFR3_EL1, S1POE, IMP)) +#define kvm_arch_has_private_mem(kvm) \ + (IS_ENABLED(CONFIG_KVM_PRIVATE_MEM) && \ + ((kvm)->arch.vm_type & KVM_VM_TYPE_ARM_SW_PROTECTED)) + +#define kvm_arch_gmem_supports_shared_mem(kvm) \ + (IS_ENABLED(CONFIG_KVM_GMEM_SHARED_MEM) && \ + ((kvm)->arch.vm_type & KVM_VM_TYPE_ARM_SW_PROTECTED)) + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a102c3aebdbc..ecdb8db619d8 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -171,6 +171,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { int ret; + if (type & ~KVM_VM_TYPE_MASK) + return -EINVAL; + mutex_init(&kvm->arch.config_lock); #ifdef CONFIG_LOCKDEP @@ -212,6 +215,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES); + kvm->arch.vm_type = type; + return 0; err_free_cpumask: diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index c1f3ddb88cb9..8e19248533f1 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -869,9 +869,6 @@ static int kvm_init_ipa_range(struct kvm_s2_mmu *mmu, unsigned long type) u64 mmfr0, mmfr1; u32 phys_shift; - if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK) - return -EINVAL; - phys_shift = KVM_VM_TYPE_ARM_IPA_SIZE(type); if (is_protected_kvm_enabled()) { phys_shift = kvm_ipa_limit; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 3ac805c5abf1..a3973d2b1a69 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -656,6 +656,12 @@ struct kvm_enable_cap { #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL #define KVM_VM_TYPE_ARM_IPA_SIZE(x) \ ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) + +#define KVM_VM_TYPE_ARM_SW_PROTECTED (1UL << 9) + +#define KVM_VM_TYPE_MASK (KVM_VM_TYPE_ARM_IPA_SIZE_MASK | \ + KVM_VM_TYPE_ARM_SW_PROTECTED) + /* * ioctls for /dev/kvm fds: */ From patchwork Wed Jan 29 17:23:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953974 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 621E4C0218D for ; Wed, 29 Jan 2025 17:23:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20B74280261; Wed, 29 Jan 2025 12:23:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BAFE280067; Wed, 29 Jan 2025 12:23:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F01B3280261; Wed, 29 Jan 2025 12:23:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D01B8280067 for ; Wed, 29 Jan 2025 12:23:47 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 52BDD140FAB for ; Wed, 29 Jan 2025 17:23:47 +0000 (UTC) X-FDA: 83061161694.07.6F0EB4C Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf07.hostedemail.com (Postfix) with ESMTP id 721FC40006 for ; Wed, 29 Jan 2025 17:23:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=s1Ax7uD9; spf=pass (imf07.hostedemail.com: domain of 3IGSaZwUKCJUIz00z5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3IGSaZwUKCJUIz00z5DD5A3.1DBA7CJM-BB9Kz19.DG5@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=1738171425; 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=OG1tDMqftBd8Me3OBv+qFo5btVz20E1wK5N2Nsjw9qk=; b=KlGk1WqYBOpNVF/plDNatngkyAsAC4MHJbDC0SfgZN6W2Uk1TDyljQS+JAp3ohFe5Y5ckt u2xg3iSHc0dyA3KEmSriz6ejXsX+JQXNSVxHse//OPDXtV5Qw6E0z6y9D7DPm2KIzRRuEZ R2/tYZ7wvKdUKzwU449SPPRO7f+FD9U= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=s1Ax7uD9; spf=pass (imf07.hostedemail.com: domain of 3IGSaZwUKCJUIz00z5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3IGSaZwUKCJUIz00z5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171425; a=rsa-sha256; cv=none; b=oA2d33Bw3hrBwoFkC5J7bq4Vd9TqbVYDqfQ88hUYAfqpkhVKnqPxToqyPL/s48sQ7nT/SW taMMsXD1ZxRTVbe+0Zn8jwRPFZNHnFb6xRyUwSh/q+wAVwGaWIMlute5fNi7bOQLGHzBQY DwV1icX72+k9asRmuDmtFV6yannq97M= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-436379713baso33678285e9.2 for ; Wed, 29 Jan 2025 09:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171424; x=1738776224; 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=OG1tDMqftBd8Me3OBv+qFo5btVz20E1wK5N2Nsjw9qk=; b=s1Ax7uD9bNuH5giqsmhFxSLqiSuoiMGjEpXQBoC8yExb7zasZBNAn2lgVwnI7Skjvx Khfgs0NBKx342sbWGSGMjMjKVQgJLdnzWPsSuXKqLb4HOFrG7W+vz+3nCAX5I6BN5Q37 01WXTd8QuD/9CyoNhn1BhTk99uQdY4EXKzyjTCpT1rAgrBbzqDDDQg9ZKPBH+Ui7iwRn YkhfhWvSKFpIn6DywA/clNAgre0aBAjyhBJCDbCS7/G6+FgtmTVaZo+a+yaOs2rFU6TK Nda4PDnOlWauMdv3mcAd68rNMCGmE+wGMDmJ7CyrE3bGODGCQwPHwuCLHgO8VrCKSjU2 AgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171424; x=1738776224; 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=OG1tDMqftBd8Me3OBv+qFo5btVz20E1wK5N2Nsjw9qk=; b=F5cBsBSsPLRHSGHHTRBvEJf6X0iw4Oj9QoEsPdQEk4NxzpkWBWljAXvfDeftJPitAT guyU1vA95FRiXnfkaQ0tr3+yeBkKkX0cVLwyVw4sQYT1D+xndl8YLvghbNqUL8tQ54GL eTBoG8D0ltPcKUxim86FW/xOMFvEhOdnPM2nZgTArCF5pMLaeyqx7Ionm12p5WcT+hNL BGO576xyBgBrBLP/RLVwrI39zxxYrxr9JrNIWRlGW/qTKpuOVJNThdSLBIJSeOaD45cd 6Z63koJbz6WCD8pEYGEz4dYIHrpejJ92HJmdnTD/+J4b0hIaOuFiMu6ETjrHnawc82Oe TrMw== X-Forwarded-Encrypted: i=1; AJvYcCXTXaWX8a2F+XkgJWyE3QwYaU2Nu6NXnr9s/j1SBDRWbv+oQgiJDwrnXEHypWesqvtAjmj850rGow==@kvack.org X-Gm-Message-State: AOJu0YwqP46Sqq5RUm4ymP1nr879WR9MbaFj+SPe8svREc+hMrdAPIZ6 +uzuIeddePrm2KFuLAcVRS+gr/ymKvkHpKdEA75n2WSaZiNpVMuQGfAErI2lc5Aoge47eiy4/w= = X-Google-Smtp-Source: AGHT+IGvVHP8k2OISYlCvdzbSWOg8/1s8TB8QwJ8K/TIlHOXAaW3sCB6BDzqqteDbn13Mj2Ujoo4vShVnA== X-Received: from wmqe15.prod.google.com ([2002:a05:600c:4e4f:b0:434:f996:b54]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c97:b0:434:9c1b:b36a with SMTP id 5b1f17b1804b1-438dc3caac1mr34886695e9.13.1738171424101; Wed, 29 Jan 2025 09:23:44 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:19 +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-11-tabba@google.com> Subject: [RFC PATCH v2 10/11] KVM: arm64: Enable mapping guest_memfd in arm64 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-Rspamd-Queue-Id: 721FC40006 X-Stat-Signature: yfuj5w756fq8crwye476mthszc3hte4b X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1738171425-512776 X-HE-Meta: U2FsdGVkX1/n3BC9EqnLu17IKEO5Tf8+bFQHF/l9chz1j3uPOVzFk8WQszoIt7LRCmNx87oFLaV1LvZvDhETBe2tHtJNsceha2gLG3MjYPW1TT1a856qoU9+Hd4GXizOmN5dwGjaW4p7wAqK1QYVV/YaL1+kP/KzkGnIXkyp/6agfaLWEvpM51AlRApxP15NSccGBznJi7Yr362v4/l4Fpla2RjVZNWCJxG+gJLoOA4RU7nAzZ54lqI+M1B1fNH1f265gtJbeDoLbj4jFnSyFpVJ24OGX2zNzWC08pfDnXWua2wZ/dfG1GcqsucylKH9MGq6fDK03QqMY+N5/YDInvdAIh3Cz4QKBwcA7VFeTfs+BVitBWjHmbSFigS/W4uEvC2GnDJ6ZdB351USCBWAFgjkhGecjud+k4kSnm4DWGe5jdbyTj1FooiQSrsAPRLMyAgGr4XMj7j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wrc/g6nIMbr4hUuo1Is0lL8Ro0B58ONShCNy0t0rfaXuc2b692ggvgS9Uex4f28mmnIwouyQwKawkoFtohuCYikH6lLA6AWp2F0tQf3zL60RiKq+KBJD0Kmqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000018, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable mapping guest_memfd in arm64, which would only apply to VMs with the type KVM_VM_TYPE_ARM_SW_PROTECTED. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index ead632ad01b4..4830d8805bed 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -38,6 +38,7 @@ menuconfig KVM select HAVE_KVM_VCPU_RUN_PID_CHANGE select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS + select KVM_GMEM_SHARED_MEM help Support hosting virtualized guest machines. From patchwork Wed Jan 29 17:23:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13953975 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 45424C02192 for ; Wed, 29 Jan 2025 17:23:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF637280262; Wed, 29 Jan 2025 12:23:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DA2EF280067; Wed, 29 Jan 2025 12:23:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF49F280262; Wed, 29 Jan 2025 12:23:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9C787280067 for ; Wed, 29 Jan 2025 12:23:49 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 44F8580F65 for ; Wed, 29 Jan 2025 17:23:49 +0000 (UTC) X-FDA: 83061161778.21.4AA7D51 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf21.hostedemail.com (Postfix) with ESMTP id 75B8B1C0004 for ; Wed, 29 Jan 2025 17:23:47 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1jxitcoW; spf=pass (imf21.hostedemail.com: domain of 3ImSaZwUKCJcK12217FF7C5.3FDC9ELO-DDBM13B.FI7@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3ImSaZwUKCJcK12217FF7C5.3FDC9ELO-DDBM13B.FI7@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=1738171427; 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=3zrvzGaN8zaP+D06MaP8yPSKdvx6oMhYyqVOrUtzvXY=; b=dETHmCWQeijfINY2wGTM7YxmLtvfKmW1R/SY4ZWPznLt5+xOQTkxCQOtY9gf7rGMSG/T21 na94rDolhc5zjQaFmriOe5iwip2mepqkVMPL+wXF3GiO+Xh95u8DmI30FYsQdzoJYMlm69 YvjsEPIZJRiSgZAgPFh9r721fI10NJI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171427; a=rsa-sha256; cv=none; b=ivP23Prx28xQNjnIG5E4P1ke6T3JjNcHtls9umy+jwZXk7ypcX7/WBOfsC6uUl8FVamqkA xT5lo5eiqFJ//15GKkhahk0RdrMWYQPkNGsB2Wn7jgtZbbOiLG7bqMBfFdaLq7FiW8ZwJx fjAaYCfLZvNq3sAb2sOdh4jldjypq3A= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1jxitcoW; spf=pass (imf21.hostedemail.com: domain of 3ImSaZwUKCJcK12217FF7C5.3FDC9ELO-DDBM13B.FI7@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3ImSaZwUKCJcK12217FF7C5.3FDC9ELO-DDBM13B.FI7@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4361b090d23so36495285e9.0 for ; Wed, 29 Jan 2025 09:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171426; x=1738776226; 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=3zrvzGaN8zaP+D06MaP8yPSKdvx6oMhYyqVOrUtzvXY=; b=1jxitcoW9Kndkqu3NgWbrW7ufy92IFDvekLuxGMk7qNewLUgUw+hjqlEET/y+mSqQK rlCwMiep3hMmdwetVsrCIq1A/9SFnYq3j90mtvFzZG3duB3XIZCKZCKY5/ZbxG+qm+Mr ugneRmq6RC+yKopm2bDB/68YkwmrVIs9PBHFQLcf2w4GTQRCcnIzrRzV2ajL0eZyrOc6 CMdKupZEYuJ4z94YkPIfBgB6YMjnfOKbxdHFYVkFIrPYdirO5pjy5OGgK2ksKcarZtoQ z40c3wbWApA9aenUb4/DPVXmY00fcagi5y3s9TwReW8RnXTxamSPJEt6kc+IGeLdtZ3h xsTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171426; x=1738776226; 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=3zrvzGaN8zaP+D06MaP8yPSKdvx6oMhYyqVOrUtzvXY=; b=bdRaeyvysxOn8C4FrMrc9OP3T6qUZoiw2aXUrYF0w3k5P+sXSdhnF0811gGFg5vTh5 Ol2iMIeMAhcp4K+laAwqITpSXvjVT1NPfJcyPyGbz1kTYW54qiUA3fZc4SDZg3JZG8vB C89kAhM/wT3P86l2ITyHA3lAFNeoL4CA/PD0mYKg6gJ9BtW80szn2LunB1B0w+Yrgwih u7j5sUcX8bJUKz4q9cs6QS3plvWb1uwzn9MmVfw+ujnx6RtmbFEeerHw58fVR+zecW8t 8HzavDItOvteS1UbfRvAkwIuOpzRZVo+bZmVPLXNab70FXIJclegNQvyTPOCCAB+hOHW IFwg== X-Forwarded-Encrypted: i=1; AJvYcCXuaTavVh/HkIT17ll8XSk7R6M1PJ5blYRElKM3SNuHJd7RNhx+EoqtXp53ty767HChrcu92+t5ew==@kvack.org X-Gm-Message-State: AOJu0YyNomWuUyDmTfmQXIgmKAcDGFp30gWtcgj0Qh57hlJqMJy+g7w7 1nxazMpNhgC3HCHdvGbGkccu51tu4nnssJar/JW5ohIErIuklgQF7KBsjOLBm+3rK3n7wqUChQ= = X-Google-Smtp-Source: AGHT+IFR5xFOkTLqeb6QODDX2zzdjcB9oqFqKPN0nLKNTAI4B+FSdQD2EzgL2GfPKUeAFSCR2jBuoM5BRA== X-Received: from wmqe7.prod.google.com ([2002:a05:600c:4e47:b0:434:fbcf:594e]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e45:b0:436:6160:5b81 with SMTP id 5b1f17b1804b1-438dc3c7c5cmr38793015e9.14.1738171426208; Wed, 29 Jan 2025 09:23:46 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:20 +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-12-tabba@google.com> Subject: [RFC PATCH v2 11/11] KVM: guest_memfd: selftests: guest_memfd mmap() test when mapping is allowed 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: 1j64nmjxf87gp5i7i31msztsurnyhqya X-Rspamd-Queue-Id: 75B8B1C0004 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738171427-875717 X-HE-Meta: U2FsdGVkX1+PRjsT3pQDJ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wzrL3IanF81uFjSBRSM2oJxYbhmk66Wnma9UYJg/zjTwLO2Jn6fVUsReuLALUC1h7lJ/1za42EitO8xidMcDiSFu+u2eK+scUkuKSpbOlRlQaDWsfcvHZiioDdw2vvggrCO1j9LHjFaZeVDt0QtONlsDMdOrFUypbj274nbAueOPn1MJfgvXTbUmYdAkyc1Y3sda4Tv48sKBjt8uSY8aiwH7SbzhsKde/sYlYAb9QdO7zMymaqqXKm8v/M6FCP7LG9YDILIFEI90A4hU0xsjTofSTwu894O1dbrXKzhZEs04COQP9R4XhdnG/8fKg7KX8yB+TuYBV8+zYf5tKFX3mW3/8Uew8ZtcX+z5L4SdoeS3qXSmeKpOKbC3yYV9GJbNRzLcbzWe/i4OHwXI2qur+gWoQB3Ki3w6V56xeQ6j46G330gT7GxEbCOJCBjYstem6yiwkGkmo5GFgkjZ76axPiS4yb5PPQnoK/mRV1k7T6sT/0YiD1w5H6UZpS07ulvmiXTx+JJPXG5jK2elg+PAHWYOPtpunQ00BARDr2j3SG7uaV5h6pA== 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: Expand the guest_memfd selftests to include testing mapping guest memory for VM types that support it. Also, build the guest_memfd selftest for aarch64. Signed-off-by: Fuad Tabba --- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/guest_memfd_test.c | 75 +++++++++++++++++-- tools/testing/selftests/kvm/lib/kvm_util.c | 3 +- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 41593d2e7de9..c998eb3c3b77 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -174,6 +174,7 @@ TEST_GEN_PROGS_aarch64 += coalesced_io_test TEST_GEN_PROGS_aarch64 += demand_paging_test TEST_GEN_PROGS_aarch64 += dirty_log_test TEST_GEN_PROGS_aarch64 += dirty_log_perf_test +TEST_GEN_PROGS_aarch64 += guest_memfd_test TEST_GEN_PROGS_aarch64 += guest_print_test TEST_GEN_PROGS_aarch64 += get-reg-list TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index ce687f8d248f..f1e89f72b89f 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -34,12 +34,48 @@ static void test_file_read_write(int fd) "pwrite on a guest_mem fd should fail"); } -static void test_mmap(int fd, size_t page_size) +static void test_mmap_allowed(int fd, size_t total_size) { + size_t page_size = getpagesize(); + const char val = 0xaa; + char *mem; + int ret; + int i; + + mem = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + TEST_ASSERT(mem != MAP_FAILED, "mmaping() guest memory should pass."); + + memset(mem, val, total_size); + for (i = 0; i < total_size; i++) + TEST_ASSERT_EQ(mem[i], val); + + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 0, + page_size); + TEST_ASSERT(!ret, "fallocate the first page should succeed"); + + for (i = 0; i < page_size; i++) + TEST_ASSERT_EQ(mem[i], 0x00); + for (; i < total_size; i++) + TEST_ASSERT_EQ(mem[i], val); + + memset(mem, val, total_size); + for (i = 0; i < total_size; i++) + TEST_ASSERT_EQ(mem[i], val); + + ret = munmap(mem, total_size); + TEST_ASSERT(!ret, "munmap should succeed"); +} + +static void test_mmap_denied(int fd, size_t total_size) +{ + size_t page_size = getpagesize(); char *mem; mem = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); TEST_ASSERT_EQ(mem, MAP_FAILED); + + mem = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + TEST_ASSERT_EQ(mem, MAP_FAILED); } static void test_file_size(int fd, size_t page_size, size_t total_size) @@ -170,19 +206,30 @@ static void test_create_guest_memfd_multiple(struct kvm_vm *vm) close(fd1); } -int main(int argc, char *argv[]) +unsigned long get_shared_type(void) { - size_t page_size; +#ifdef __x86_64__ + return KVM_X86_SW_PROTECTED_VM; +#endif +#ifdef __aarch64__ + return KVM_VM_TYPE_ARM_SW_PROTECTED; +#endif + return 0; +} + +void test_vm_type(unsigned long type, bool is_shared) +{ + struct kvm_vm *vm; size_t total_size; + size_t page_size; int fd; - struct kvm_vm *vm; TEST_REQUIRE(kvm_has_cap(KVM_CAP_GUEST_MEMFD)); page_size = getpagesize(); total_size = page_size * 4; - vm = vm_create_barebones(); + vm = vm_create_barebones_type(type); test_create_guest_memfd_invalid(vm); test_create_guest_memfd_multiple(vm); @@ -190,10 +237,26 @@ int main(int argc, char *argv[]) fd = vm_create_guest_memfd(vm, total_size, 0); test_file_read_write(fd); - test_mmap(fd, page_size); + + if (is_shared) + test_mmap_allowed(fd, total_size); + else + test_mmap_denied(fd, total_size); + test_file_size(fd, page_size, total_size); test_fallocate(fd, page_size, total_size); test_invalid_punch_hole(fd, page_size, total_size); close(fd); + kvm_vm_release(vm); +} + +int main(int argc, char *argv[]) +{ + test_vm_type(VM_TYPE_DEFAULT, false); + + if (kvm_has_cap(KVM_CAP_GMEM_SHARED_MEM)) + test_vm_type(get_shared_type(), true); + + return 0; } diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 480e3a40d197..098ea04ec099 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -347,9 +347,8 @@ struct kvm_vm *____vm_create(struct vm_shape shape) } #ifdef __aarch64__ - TEST_ASSERT(!vm->type, "ARM doesn't support test-provided types"); if (vm->pa_bits != 40) - vm->type = KVM_VM_TYPE_ARM_IPA_SIZE(vm->pa_bits); + vm->type |= KVM_VM_TYPE_ARM_IPA_SIZE(vm->pa_bits); #endif vm_open(vm);