From patchwork Fri Dec 13 16:47:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13907458 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 82F62E77180 for ; Fri, 13 Dec 2024 16:48:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CAD76B0093; Fri, 13 Dec 2024 11:48:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17A746B0095; Fri, 13 Dec 2024 11:48:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0427C6B0098; Fri, 13 Dec 2024 11:48:16 -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 D5DB46B0093 for ; Fri, 13 Dec 2024 11:48:16 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8D1CD80F80 for ; Fri, 13 Dec 2024 16:48:16 +0000 (UTC) X-FDA: 82890518046.18.F404BC3 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf07.hostedemail.com (Postfix) with ESMTP id DBDCF4000A for ; Fri, 13 Dec 2024 16:47:42 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cvZ6DldM; spf=pass (imf07.hostedemail.com: domain of 3TWVcZwUKCMo9qrrqw44w1u.s421y3AD-220Bqs0.47w@flex--tabba.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3TWVcZwUKCMo9qrrqw44w1u.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=1734108467; 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: references:dkim-signature; bh=l49nZBQWbj/tqR0pfbsQBWP6JXQh3gfv222a0VGKOo8=; b=FH2yyKZXbDA2RZOr3Wi4cJ4ZDQspu812sblLPuzSB3UbhNu52GBSVvsDE2jgrgWbdnq5dc T5yvR7wWOIxJeVia2e11C7RP4Cf4Z5vBKTtqKRbq1nb0cPIyUJhU6rxxrvUGxsRxwfCtej FsmeXx0Bn8X/VUY20M7Bji5t8CSkNeg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cvZ6DldM; spf=pass (imf07.hostedemail.com: domain of 3TWVcZwUKCMo9qrrqw44w1u.s421y3AD-220Bqs0.47w@flex--tabba.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3TWVcZwUKCMo9qrrqw44w1u.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=1734108467; a=rsa-sha256; cv=none; b=tZsLQz8VPIUdxt7IJ8jDg/L2YwdJf0RjtJfcZCy3sh7XTG6jtRR/HvSm2UiZY8rCLWmAiS al73BHjs2DVX0K0HkHdlz3fnwE/ixWf+4H1W1eLwOxLMZqIGg70sQTKdSpmClqW/Q0wflh lpqUS679TgUeU9tn2ElrkItbz2RuYGk= Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3862e986d17so865814f8f.3 for ; Fri, 13 Dec 2024 08:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734108493; x=1734713293; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=l49nZBQWbj/tqR0pfbsQBWP6JXQh3gfv222a0VGKOo8=; b=cvZ6DldMXhqev2ZrOGeSasayyD27bUCB12jr9ctAr29V/bTh6b9J8L/koB0AOg/tl8 mXRzv2rRCm1PwGadxfIbB+79JflFbmmMU/FTodTMmnpmNsSqUdBwboyyfu9XPjbyE+3p lUWVPUq3FdcX2bFCHR8kmlF5KWdmcRBJCAkKFXgl5ILk9NzXbEQMJfnWivdMPft1WO6e urZZbcon2eFF2zus+tWFkn+b0Nl3204I05XYy4wjfhy1xuRRFD9nlYnYuo1AGWXH2LAF Dr4p+RyliTzSNVRzd//kLVRH2hv7sYV5Um05B2HnR+Mwc0//p2LWtUYGadlX7qd3fR6V mrJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734108493; x=1734713293; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=l49nZBQWbj/tqR0pfbsQBWP6JXQh3gfv222a0VGKOo8=; b=MrC93cvkcH7opDBvW2gBAX7mzftM65abuX4be8RfyaKfiXsPTMxvudDnFBxN8cp9iR fmrhINPHlv7D3elINZf0ZZ5gtF6EmIUt9PEOXxyevinT8AhyHXDwhN6jWlq34PWQzWQu gcsAOj7IH1dTWJ/CMW71Qz7kNX+WAhTb4CYAAfYPOl8jra0FMvgGYR+kfkXTHDoS6Wpj w5oP7lXVKMfcC41uRmQJ6Ipn4LVGGWMYVheEm+4osFeLYnuaJRHLRsRtQkXjmCUm5Cve Qp33GDv7oFL47xjAG+FxfstFRIZmtIYvXuMsR1acCbmnvSTOjJnV/avHYErezi5/4u1s b5yg== X-Forwarded-Encrypted: i=1; AJvYcCWiKLSE4QXPAjP74FnkgG/6CojgBy4ymmngDcfXEo9V5nbiI+b0LAVr6i/rNsZZq3p2QypPP70BpA==@kvack.org X-Gm-Message-State: AOJu0Ywob7hgvcKtBLfn4aGSsu0sl5ydcIYiWArBKu+16PjUJQE1Uua1 ZGjhuc/YPRNVV0tnK54wKIxu3+OYW6AovpYtBZmrWhPYndroMkBXXlY1F+k99ERhbgxhS5uYiw= = X-Google-Smtp-Source: AGHT+IHeXWv9UlvNwtt49TJOJkvo4Sw+243biArECpj/wEQYlB+Xl6ffPPZWh7+IujbdTMPrByuwczoUyA== X-Received: from wmph6.prod.google.com ([2002:a05:600c:4986:b0:434:e96f:86b0]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5986:0:b0:385:dea3:6059 with SMTP id ffacd0b85a97d-3889ad32e66mr2769505f8f.49.1734108493083; Fri, 13 Dec 2024 08:48:13 -0800 (PST) Date: Fri, 13 Dec 2024 16:47:56 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241213164811.2006197-1-tabba@google.com> Subject: [RFC PATCH v4 00/14] KVM: Restricted mapping of guest_memfd at the host and arm64 support 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: rspam06 X-Rspamd-Queue-Id: DBDCF4000A X-Rspam-User: X-Stat-Signature: uy3kr6gxmya1peyiuc5dm5a57p3jwhum X-HE-Tag: 1734108462-607311 X-HE-Meta: U2FsdGVkX18u9RqGM9jjgz93FLxmMYT+e/MbbBQi28KnyBiRr1LnccxYBaE+FSTmwOPfSDrc3twboh1ppVsrK6wUOUasIPjhar7MQu0JMMhU5CP7ca8CgPbLAIbeUo1gAQURGwY0yfjuDVQ5+ZHC0IJuT2p0XnTKDhXMaJxHvpkN0LuSz1UkJQqoC8OJYGQaAi9AQzbo6y4Q2LSv/2fGUE3fAxjd12hYudiHNat/lzpQX8lrfwKapShYHc7OIaCka41el7miNdIuytXRbEjtXCcDYgaDhWu3tfHDSpCep9wjdvssDqjWlbGAkYFB7IwW6osUC2ArMQl34AlvCBuNDZEj0LvjWT1RpKO+F3MyqXCF1d7kxrdo/LE0cOBXCvWgLnqtp7mCBtnr0ujxQTwtFQz7AH/psCJjA0KJ3QbRl8u/Cp62uMph+5d/g3DGDeH/ohQ6CSA+q1ORuQAqU2BBIvSIfl/IJREKvNYG3VJe+Is0MWe12/GVB7RhioVlZpNxbUMwk8zSMG3mTyWXyUJj502dsGKDjUxK+aZkfjU5na56zHKi9HK1URGyaRoZXAHjht/18pRDDucd4TsIcNz9EUT39ws/YurTtlX7Ui97qZ2R7dlovWWhCrRgXyDs1NXeSU7k+1gYd+t6pHg3o5FAkVuOYod8VCq+8dU99MYjqZc9deHIAPUVxxSYxhropMSL75e80PF4ps8yQ/bJjGtH2yfpkDEIe7D5HQXE8D8BHOgY/q5RbHukm79GhXbnmMkq3oqCIjACf4APdZllw7SElcY0QIuhvRqyF9KMmI6k7PrPkh0SRt22HtOWwh7pwC9aB7uqfvMDhNyXOw2j/Bjalawl0S2gbIcv4V5DmDFQlZIcoZrKlxNgI+JnKU3+5FavHdkBK6BCBdJqaW6Oym/HtrFir2mcNYn6ZLrtMuu8t0BUL/2ZMAeTwaMBjPIp+zyrvc1VZJUEbPqI5Q4bbVR E2EaZClR 3Kdf8EN4Syi1/ZfBOWqaQPHUt4PgyGMJrB3rEqYq08Rj0xBWGU6hv1mwDgdQTc5A5ANuUwYBXg6j8+lzAkR1W4k+u9NFsVSmmP7FK0k4r/Ei2iquz/4bFZ64bZNTTHXanyf3eOmuymb8Lzu6/EUnYnh3yejTj9/4Coqps3htzEEWBl9tp/1vpXEkENrxXtVoS5QGvkmoISGsC0MWtEcYOjTrTm29GyqpPfzFunp/jeRymvrIf7YRVw+Z1/fRPWN7DA2N5Ey8zUin/OeMOC1Y0pJw+8F0SSDxPp1CqnnEgek70IQr+V5LsN3uBCuEg+YVnpowLBXmYMd8Js4aU++HO0pZNSHawnasWacNvaOhgX0mg2BMELBehFxl+QaB8Aw96XCb3b1arB1uaOYkF+4v1LZrUEOyA6PYWaRR8IQM9ao1t0kVMLvp3bdHFAZkstye4ypGXK7EVazf3WCvfOAq4edXvnTPy4RkPSGjaxTuXbWlMdKs0UI8uiqAVGifm4xb5oYvLhaodQ9C9sCDzaiLougACe5rvVXAFoZVIBRvgtClrPo7zNLGcVy8S9RNNDXovENl/Ya2G7I74V+hO56SDqHUeytzOcOIXnWU6asSD+5AvUVltrDsRjQH6ChpFKDZz3yP6RGhbDrDvX4rOtJk2QxnEzRFn55yBxn3CpYUatZdsmaQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.018833, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This series adds restricted mmap() support to guest_memfd, as well as support for guest_memfd on arm64. It is based on Linux 6.13-rc2. Please refer to v3 for the context [1]. Main changes since v3: - Added a new folio type for guestmem, used to register a callback when a folio's reference count reaches 0 (Matthew Wilcox, DavidH) [2] - Introduce new mappability states for folios, where a folio can be mappable by the host and the guest, only the guest, or by no one (transient state) - Rebased on Linux 6.13-rc2 - Refactoring and tidying up Cheers, /fuad [1] https://lore.kernel.org/all/20241010085930.1546800-1-tabba@google.com/ [2] https://lore.kernel.org/all/20241108162040.159038-1-tabba@google.com/ Ackerley Tng (2): KVM: guest_memfd: Make guest mem use guest mem inodes instead of anonymous inodes KVM: guest_memfd: Track mappability within a struct kvm_gmem_private Fuad Tabba (12): mm: Consolidate freeing of typed folios on final folio_put() KVM: guest_memfd: Introduce kvm_gmem_get_pfn_locked(), which retains the folio lock KVM: guest_memfd: Folio mappability states and functions that manage their transition KVM: guest_memfd: Handle final folio_put() of guestmem pages KVM: guest_memfd: Allow host to mmap guest_memfd() pages when shared KVM: guest_memfd: Add guest_memfd support to kvm_(read|/write)_guest_page() KVM: guest_memfd: Add KVM capability to check if guest_memfd is host mappable KVM: guest_memfd: Add a guest_memfd() flag to initialize it as mappable KVM: guest_memfd: selftests: guest_memfd mmap() test when mapping is allowed KVM: arm64: Skip VMA checks for slots without userspace address KVM: arm64: Handle guest_memfd()-backed guest page faults KVM: arm64: Enable guest_memfd private memory when pKVM is enabled Documentation/virt/kvm/api.rst | 4 + arch/arm64/include/asm/kvm_host.h | 3 + arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/mmu.c | 119 +++- include/linux/kvm_host.h | 75 +++ include/linux/page-flags.h | 22 + include/uapi/linux/kvm.h | 2 + include/uapi/linux/magic.h | 1 + mm/debug.c | 1 + mm/swap.c | 28 +- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/guest_memfd_test.c | 64 +- virt/kvm/Kconfig | 4 + virt/kvm/guest_memfd.c | 579 +++++++++++++++++- virt/kvm/kvm_main.c | 229 ++++++- 15 files changed, 1074 insertions(+), 59 deletions(-) base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4