From patchwork Fri Apr 4 15:43:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kalyazin X-Patchwork-Id: 14038634 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 D1556C36010 for ; Fri, 4 Apr 2025 15:44:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EBF46B0025; Fri, 4 Apr 2025 11:44:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1746B6B0026; Fri, 4 Apr 2025 11:44:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2E986B0027; Fri, 4 Apr 2025 11:44:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D0BD16B0025 for ; Fri, 4 Apr 2025 11:44:06 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 920CE1204B7 for ; Fri, 4 Apr 2025 15:44:07 +0000 (UTC) X-FDA: 83296782534.04.CC6C753 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf16.hostedemail.com (Postfix) with ESMTP id A033D180003 for ; Fri, 4 Apr 2025 15:44:05 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=En4mpUCo; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf16.hostedemail.com: domain of "prvs=182d669d3=kalyazin@amazon.co.uk" designates 52.95.49.90 as permitted sender) smtp.mailfrom="prvs=182d669d3=kalyazin@amazon.co.uk" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743781445; a=rsa-sha256; cv=none; b=LszqJ73soSM+dhMjGJBHx0/op9XnlN+jZyqSnCZOAcDvo5r8IC48R2ryixucGpEkb6ScJb 7/EUeFXSgu3DIhJbrvINepUbrA2wuOx6Wdes/fuYneho2uHfbje440cQmhW/FNPbNVRcIe KUdt2KYios4iw+OcCoU/UvqMw+PX1+4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=En4mpUCo; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf16.hostedemail.com: domain of "prvs=182d669d3=kalyazin@amazon.co.uk" designates 52.95.49.90 as permitted sender) smtp.mailfrom="prvs=182d669d3=kalyazin@amazon.co.uk" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743781445; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=wclIRAQFfE2pzVzzCPlSKXfar9IWu+zIoU0sBLVtp38=; b=y3M2A+VK2LewSt8yhYSP56uQ14ot66jNv96LG8kkZBCE0FyRHPy7/dA3UnVUBnaK4TgSnK Wsi/V9pvuwe7qAGSPK0aKT4nToqwPm9rHVg3lct0+Y5RSKtUQ+bPf8TSmoUZDcoGbha1Tz TPq5j4dtInk+IYmjMDpa9n+alv9Bm10= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1743781446; x=1775317446; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wclIRAQFfE2pzVzzCPlSKXfar9IWu+zIoU0sBLVtp38=; b=En4mpUCo0sRNCVTx32Eq803PDdF9kKWPFWB8cBS6/4qHaWcILAROed7I vKAdgimouFxghEHK6oMJO4gCGEqSieurVwJ4TMUBRmhJVU6F9Islci43s mR4kF0BjLgwINZ8bzRzLQok/LPUPTGJ/BTjW/dGWM1j0RNLN9yi/qlyA3 M=; X-IronPort-AV: E=Sophos;i="6.15,188,1739836800"; d="scan'208";a="486684103" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2025 15:44:01 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:38790] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.25.120:2525] with esmtp (Farcaster) id 19e4150d-3051-47dc-b5ab-c8164781f6fc; Fri, 4 Apr 2025 15:44:00 +0000 (UTC) X-Farcaster-Flow-ID: 19e4150d-3051-47dc-b5ab-c8164781f6fc Received: from EX19D003UWB001.ant.amazon.com (10.13.138.92) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Fri, 4 Apr 2025 15:43:55 +0000 Received: from EX19MTAUWC001.ant.amazon.com (10.250.64.145) by EX19D003UWB001.ant.amazon.com (10.13.138.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Fri, 4 Apr 2025 15:43:55 +0000 Received: from email-imr-corp-prod-iad-1box-1a-6851662a.us-east-1.amazon.com (10.25.36.210) by mail-relay.amazon.com (10.250.64.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14 via Frontend Transport; Fri, 4 Apr 2025 15:43:55 +0000 Received: from dev-dsk-kalyazin-1a-a12e27e2.eu-west-1.amazon.com (dev-dsk-kalyazin-1a-a12e27e2.eu-west-1.amazon.com [172.19.103.116]) by email-imr-corp-prod-iad-1box-1a-6851662a.us-east-1.amazon.com (Postfix) with ESMTPS id DE9684032D; Fri, 4 Apr 2025 15:43:52 +0000 (UTC) From: Nikita Kalyazin To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 0/6] KVM: guest_memfd: support for uffd minor Date: Fri, 4 Apr 2025 15:43:46 +0000 Message-ID: <20250404154352.23078-1-kalyazin@amazon.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A033D180003 X-Stat-Signature: c3ukaeysgw1ft9dh5jhc5x9yon83redm X-HE-Tag: 1743781445-101741 X-HE-Meta: U2FsdGVkX188w+CF/jw2sIIgs2cjMB3Ft9qPKDY6Zhd8YGq27Qrv/G2Rs9xrKsT+e35GKX+iuSn3MYZHHjT8dYhB5UX4sIDmT+lOzZ/OYcHMjZTBvxBkDTq6LEu2iWwCHNE0EYhKt9dE3z5g9fxTt/tX2eSl6cDT8SelJHdbYTOFmTOK/Y10IovkvgpoQX34QGInr5zw/z33q1o9EPlxlQx+ciVfIJaH71xESP1raP4aEypTm/7nsOmWTXVjI1nGm5vPbvfGZptMnYSt2rRLm/IBJIY3xfLxIQONLTsrRPxxZAuifGt1CM//YSgjAA4Al03CjNW/aOsylYK3ie+5AZk9vcBQFf7M0sP1TG4p3vHlgYwvH8DcUjWSgBQasUHtXGuod9gL2IrORsMwYHkN9ULWNhHa0nevVKPb7ZvSuKfW6Fc06BiSZJsSDkVI6bXRri6iKOy1/NGWojWdbrkeGR6xF4LfjldMYcMzOqNMC5tFziKOWuG07cRLmIUHItj9y5sAVmtk0LmQ4O3uCwZMsFcMWXpgRXHhFZGid1jwLrpk/UYxSAMAUnBPsfoHnmPsI2fb2ebCnmLt5BXVQw4LqW8LO+a9z8mgiy+las5tc2o7y0H5w4WJEqkcmq/x1GLcT5TyuGBRYbEfS38su8SAV9qEAs70k5WJJgqtx7Fzj3XPWKdwL1Djv07EEojENGur4ClZm0TkfGVRY1ROepI69vnPpy235SWMQKoQpYWBu0JdS36n3DH8jl2V8ptQ0YZ6IjAzaRueDX5yP3mNoIlmvwCqKS8HuxrsVw8BTd4hWHYm1gxZGmywW8W9Cmto1ACjff+RN/sehzlqfX9B612zSWa4VFufkHgtVZqIFeFLWqOvcRr5l5liOsfAFQZE+LkbJJnEggqGWUvy/Uk7cX9G6FmlywqmzApXTLzkrMRSxThhZ/tz+/brPRM0BxPvp5/JTcw70oS+BgeH04VrcB9 T48Gv2i1 3zsg6XfESwsrWccpZYzfnkAHzK2LrbyC2cjZgjUgTiXgAtUQ74NT8fVQh+LTEwxBVfqStKU/+42X1NkWcCC//Pq5yiAdgIyIPN8sTijB2GvddjC96ezLshOYdj0SLqf+DQh4wkK/cP7ZufX1cdsZNXWG2pzYJ7A+c1Pa800zXVT5O7T+yn60Z/anxx8gw/VYUT1U0kl+UmNFPyqviwdCzvWhlkQaHgeLHZRd0T9706xIxCuH/+NFEeGdfFhmzOltj70pHoiZSS2ePVmXfw8H3c6/DRH18XYSCJ0JnITezdlqOj8hdaSnT+3qnqfo854nfhK50Z7h+p4cv5SE7vnWLOkZUt3Vxo9r3qbJg2L28hHolZRxVRXYKBysmJUY01RRhiiN1YXPzJqeZ41EdIXZbi+M5gu1rMA7Cfn2fzLo5PUCYkrMWtsoUo97BpXUsgbCnm/7iP1fAMyF60d/gf6AJc8s9laebAWWzcNNkpG+iU4n+AVoqQZvqiBOxSVoigjSmUH06tNOzoMge+U28bHItJDH/mI63wONbkFskxebYbninbPOAkB3rkg4M3Y0x3/w84ag8lw26UbvqIFuoBu0wUd0OJX3T95h2pW4cb7b7KAN9UgM= 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: This series is built on top of the Fuad's v7 "mapping guest_memfd backed memory at the host" [1]. With James's KVM userfault [2], it is possible to handle stage-2 faults in guest_memfd in userspace. However, KVM itself also triggers faults in guest_memfd in some cases, for example: PV interfaces like kvmclock, PV EOI and page table walking code when fetching the MMIO instruction on x86. It was agreed in the guest_memfd upstream call on 23 Jan 2025 [3] that KVM would be accessing those pages via userspace page tables. In order for such faults to be handled in userspace, guest_memfd needs to support userfaultfd. Changes since v2 [4]: - James: Fix sgp type when calling shmem_get_folio_gfp - James: Improved vm_ops->fault() error handling - James: Add and make use of the can_userfault() VMA operation - James: Add UFFD_FEATURE_MINOR_GUEST_MEMFD feature flag - James: Fix typos and add more checks in the test Nikita [1] https://lore.kernel.org/kvm/20250318161823.4005529-1-tabba@google.com/T/ [2] https://lore.kernel.org/kvm/20250109204929.1106563-1-jthoughton@google.com/T/ [3] https://docs.google.com/document/d/1M6766BzdY1Lhk7LiR5IqVR8B8mG3cr-cxTxOrAosPOk/edit?tab=t.0#heading=h.w1126rgli5e3 [4] https://lore.kernel.org/kvm/20250402160721.97596-1-kalyazin@amazon.com/T/ Nikita Kalyazin (6): mm: userfaultfd: generic continue for non hugetlbfs mm: provide can_userfault vma operation mm: userfaultfd: use can_userfault vma operation KVM: guest_memfd: add support for userfaultfd minor mm: userfaultfd: add UFFD_FEATURE_MINOR_GUEST_MEMFD KVM: selftests: test userfaultfd minor for guest_memfd fs/userfaultfd.c | 3 +- include/linux/mm.h | 5 + include/linux/mm_types.h | 4 + include/linux/userfaultfd_k.h | 10 +- include/uapi/linux/userfaultfd.h | 8 +- mm/hugetlb.c | 9 +- mm/shmem.c | 17 +++- mm/userfaultfd.c | 47 ++++++--- .../testing/selftests/kvm/guest_memfd_test.c | 99 +++++++++++++++++++ virt/kvm/guest_memfd.c | 10 ++ 10 files changed, 188 insertions(+), 24 deletions(-) base-commit: 3cc51efc17a2c41a480eed36b31c1773936717e0