From patchwork Wed Apr 2 16:07:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kalyazin X-Patchwork-Id: 14036200 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 EDB6DC36017 for ; Wed, 2 Apr 2025 16:07:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 291B5280007; Wed, 2 Apr 2025 12:07:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 241FD280001; Wed, 2 Apr 2025 12:07:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 093BF280007; Wed, 2 Apr 2025 12:07:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D969E280001 for ; Wed, 2 Apr 2025 12:07:41 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CE7B05A33A for ; Wed, 2 Apr 2025 16:07:43 +0000 (UTC) X-FDA: 83289584406.30.FE78D16 Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) by imf04.hostedemail.com (Postfix) with ESMTP id 738A54000E for ; Wed, 2 Apr 2025 16:07:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=s+m1DQYw; spf=pass (imf04.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 52.119.213.150 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743610061; 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:in-reply-to:references:references:dkim-signature; bh=5WJu5FXIQjlvFzc2S3oagYQCTjwqOt8Vj/HqIU2A0PE=; b=B3pCCXAFZscWA+/BKQypS5Ab360E5Nn0RgaZ/LklRO9rZCTrYVSL+yhS0cUX5sgD9Huj9i hv3SHAd9Tfy9DnBRRueYOGbQmblpS6NOagFLFBF/0UqkRqyZWBrXG5sbjplEepkjdvwlGI Nb+93LFavzzZrehx7wV524ZtaXmjkos= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=s+m1DQYw; spf=pass (imf04.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 52.119.213.150 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743610061; a=rsa-sha256; cv=none; b=ec+3IldhjoMoWevqMQlsLHQdtUC8LeN5U0KvMlpUAnKzZIGdIZdKEwqpnFWdP/zUF4Rlw2 Ed6pPZbaiAQEBEiIhJpk3GG+jHHxkxlZT28GHWBAVYdDhX623uwH0D+LVcYLHt9KS92yH4 Jsl9VAiMyxdy6MTQ5mQM4jg6G2dTZfE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1743610062; x=1775146062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5WJu5FXIQjlvFzc2S3oagYQCTjwqOt8Vj/HqIU2A0PE=; b=s+m1DQYwf144iN/Fs/vO78aud7B4lwY4ofU/ZwmjlV5+XHyQjKaH1Fzh 1Ixk1+xjNeV8AT7iATHeYBJXmTSrcbxDb2h+lTVer7Eeekq/SmLkLA4wk k7xKsK/d8bln9/qRJO6+QB0HEyWMwsob6f2TXZI5ptIhDnThSRcivEdVI s=; X-IronPort-AV: E=Sophos;i="6.15,182,1739836800"; d="scan'208";a="710490762" 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-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 16:07:38 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.10.100:19931] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.36.151:2525] with esmtp (Farcaster) id 5d4c3ca3-5bf6-48b9-9c8f-8b474d7042db; Wed, 2 Apr 2025 16:07:37 +0000 (UTC) X-Farcaster-Flow-ID: 5d4c3ca3-5bf6-48b9-9c8f-8b474d7042db Received: from EX19D022EUA001.ant.amazon.com (10.252.50.125) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:07:36 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D022EUA001.ant.amazon.com (10.252.50.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:07:36 +0000 Received: from email-imr-corp-prod-iad-all-1b-8410187a.us-east-1.amazon.com (10.43.8.6) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14 via Frontend Transport; Wed, 2 Apr 2025 16:07:36 +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-all-1b-8410187a.us-east-1.amazon.com (Postfix) with ESMTPS id 706BE40536; Wed, 2 Apr 2025 16:07:34 +0000 (UTC) From: Nikita Kalyazin To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v2 1/5] mm: userfaultfd: generic continue for non hugetlbfs Date: Wed, 2 Apr 2025 16:07:17 +0000 Message-ID: <20250402160721.97596-2-kalyazin@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250402160721.97596-1-kalyazin@amazon.com> References: <20250402160721.97596-1-kalyazin@amazon.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 738A54000E X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: nprs6dn4pruusiuwgmmf6qxighwhkpik X-HE-Tag: 1743610061-835026 X-HE-Meta: U2FsdGVkX1/DOgDgv2J4FZErEHQYFXdqqKA8N/VFmue3UKX7HL5mIOkWzOccyD7oFbLy/e3PFBnL9KW56curCZ/hlV5HecbhOMOkljmVlGIMeGfol7jTTJM4PuPybfZ/6UbfOUoapMu0MCIw/3ok648LZyyWcjQ42YRiLU5zpauWT/b1qz4tYM79jmG5UsWG0w6DYW5adMUXei5DtEKgXHm+/jwjQT9A5kTSTzhS0VPjWKFBXwpDvEf71TTCuoSCabna75bR9XhA8JepY4CMW9u8CGrgV6JJkRiW9Xgr41idW5qlCR1yOwOj+XcxlVI42rJx9qCFmrspAr/ltPSmubPywE+I7C4S8ZbXFKPf32heJOPfjp/VJeKEFT8UsqjhenTM1wdb83d9OBKm6HA3Hqkj11cBTM7nKW7gfJ6n0wD2woSPyEtvjemvDUFkNqOi1oMR+8/pYuyJddA1MA3bl5QVwtuci/ULJUblj5IpAKc4YEkckw5ApLZ0dpQ/XD/hcfNbSnkBIi7Vk785vaPb9WNfdUV+l1gjaejNLg/4SWMv+WoWCqajpYWmwR6VnTVz46O9rbi9G98G/NOpPcQEyBrdneO79GFt7e4LrTjdCCYPDSsnJmjpDyJAXhHhEp2hDEiM82XqPO8SF3grrcGxrCcLYFS/rc+E117H1fiDfpWGRpYgeIRLeG8Q71y3WCVuBLZlui9siB6yhdiGWngPEOXa79aZRht7O2JucBAo1cPrjC2xcGzgIzjRfTdqz/xTQTiwGVbiQXYkNZ6a6ZVx+jPO08IcYGui3YfJh9YQkC9uHHKNyLd7YS7bMvKUge5z0LBcObeY0kb5MLVc4UqzjxA/rRLU676GtKZ+r+ZpxAh5Y6d6/uuhM+zW5I8N30c8WhES/rtr4Lth90I3Pgr0tp/uF4XyUaWrwpSxkAIknb9masSSViYFoG/kRrfPes7fzh5g3vZI9tEA9F+/Rx3 AWukShuJ n6zTxudtFvfcU1VW0FzgxywnpWcKgOFhpk5fGeQ8AIiz5zjB3olhvUCA4rTT7jPBjcnH5gEPlyEGEDcQ33YlhiDToD/youByAL5EXP2i3e9ILGJDrOzDNP4NlNCwp0trdyScsK+k4DbRJV6qtwLxjS9uupshMKm92rFtxXUlA5K6EBA7Jxfizqn07cafYnPOIKowyei410ZIbHwHf6xXvfXONH+T3dd6ysCuvwLoM8Xtsi0Jt4ZaAUFaBRXGxlvx4x3YDPTdqTdvz/40upbIdcPEzOeclXfAB5zx0339DPMyjgdRyYw4mJxB4TdCqx2NnlH0uYv1hr6DdNRIZWsgBqw/DRywq77uVpTAFzni8WlnZwf9OwJdd0x1ue8LaYKQSwZj98PgkbSn6ZyGh6ryxKRE9Yb46lzQKLx6iahWZEzwqEETd2ja6tuq7GOE3n8DxxZ4cV8QW8PajIKZ2Jorjn2iDtIqE1tx3+sjgVe1hhA3FQlwov6AVBhbxA7tlSCwsDl4L 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: Remove shmem-specific code from UFFDIO_CONTINUE implementation for non-huge pages by calling vm_ops->fault(). A new VMF flag, FAULT_FLAG_NO_USERFAULT_MINOR, is introduced to avoid recursive call to handle_userfault(). Signed-off-by: Nikita Kalyazin --- include/linux/mm_types.h | 3 +++ mm/hugetlb.c | 2 +- mm/shmem.c | 3 ++- mm/userfaultfd.c | 25 ++++++++++++++++++------- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 0234f14f2aa6..91a00f2cd565 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1429,6 +1429,8 @@ enum tlb_flush_reason { * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached. * We should only access orig_pte if this flag set. * @FAULT_FLAG_VMA_LOCK: The fault is handled under VMA lock. + * @FAULT_FLAG_NO_USERFAULT_MINOR: The fault handler must not call userfaultfd + * minor handler. * * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify * whether we would allow page faults to retry by specifying these two @@ -1467,6 +1469,7 @@ enum fault_flag { FAULT_FLAG_UNSHARE = 1 << 10, FAULT_FLAG_ORIG_PTE_VALID = 1 << 11, FAULT_FLAG_VMA_LOCK = 1 << 12, + FAULT_FLAG_NO_USERFAULT_MINOR = 1 << 13, }; typedef unsigned int __bitwise zap_flags_t; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 97930d44d460..ba90d48144fc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6228,7 +6228,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, } /* Check for page in userfault range. */ - if (userfaultfd_minor(vma)) { + if (userfaultfd_minor(vma) && !(vmf->flags & FAULT_FLAG_NO_USERFAULT_MINOR)) { folio_unlock(folio); folio_put(folio); /* See comment in userfaultfd_missing() block above */ diff --git a/mm/shmem.c b/mm/shmem.c index 1ede0800e846..5e1911e39dec 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2467,7 +2467,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, fault_mm = vma ? vma->vm_mm : NULL; folio = filemap_get_entry(inode->i_mapping, index); - if (folio && vma && userfaultfd_minor(vma)) { + if (folio && vma && userfaultfd_minor(vma) && + !(vmf->flags & FAULT_FLAG_NO_USERFAULT_MINOR)) { if (!xa_is_value(folio)) folio_put(folio); *fault_type = handle_userfault(vmf, VM_UFFD_MINOR); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index d06453fa8aba..68a995216789 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -386,24 +386,35 @@ static int mfill_atomic_pte_continue(pmd_t *dst_pmd, unsigned long dst_addr, uffd_flags_t flags) { - struct inode *inode = file_inode(dst_vma->vm_file); - pgoff_t pgoff = linear_page_index(dst_vma, dst_addr); struct folio *folio; struct page *page; int ret; + struct vm_fault vmf = { + .vma = dst_vma, + .address = dst_addr, + .flags = FAULT_FLAG_WRITE | FAULT_FLAG_REMOTE | + FAULT_FLAG_NO_USERFAULT_MINOR, + .pte = NULL, + .page = NULL, + .pgoff = linear_page_index(dst_vma, dst_addr), + }; + + if (!dst_vma->vm_ops || !dst_vma->vm_ops->fault) + return -EINVAL; - ret = shmem_get_folio(inode, pgoff, 0, &folio, SGP_NOALLOC); - /* Our caller expects us to return -EFAULT if we failed to find folio */ - if (ret == -ENOENT) + ret = dst_vma->vm_ops->fault(&vmf); + if (ret & VM_FAULT_ERROR) { ret = -EFAULT; - if (ret) goto out; + } + + page = vmf.page; + folio = page_folio(page); if (!folio) { ret = -EFAULT; goto out; } - page = folio_file_page(folio, pgoff); if (PageHWPoison(page)) { ret = -EIO; goto out_release; From patchwork Wed Apr 2 16:07:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kalyazin X-Patchwork-Id: 14036201 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 0DD79C28B20 for ; Wed, 2 Apr 2025 16:08:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83A9D280008; Wed, 2 Apr 2025 12:08:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E892280001; Wed, 2 Apr 2025 12:08:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B148280008; Wed, 2 Apr 2025 12:08:00 -0400 (EDT) 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 453F9280001 for ; Wed, 2 Apr 2025 12:08:00 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0C8AD161CEA for ; Wed, 2 Apr 2025 16:08:00 +0000 (UTC) X-FDA: 83289585120.01.F575DED Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) by imf17.hostedemail.com (Postfix) with ESMTP id EBA5E40002 for ; Wed, 2 Apr 2025 16:07:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=vu2lPLqX; spf=pass (imf17.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 207.171.188.206 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743610078; 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:in-reply-to:references:references:dkim-signature; bh=UqLHY0tozEGhyxnF+okEAbfVCr65ECLQO5uKTF2y+bU=; b=0tX2mEsgvK3HgpnHvQd37n+3BqO27Imegv87j63UOEsh8G0488njAaGawPzFCOH8TWB+c/ SycWQqGmucQKQftiOp9RsQm2XFxIaKIdfM9nniwXDgZGW0mLSeo3SUUkE347acF325CCjC BXWzgGTsqtLzsFqgWku3mou8oCTXxPs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743610078; a=rsa-sha256; cv=none; b=Flgm973hj2pZAvqbsFN12LCRyBN0MzJAr7Ka8XdH1x+JHfzgv4OGx9aVcfhT6L6ihnEHFY G79k96QBSDGodBsc4ZJ7jwjgH41meFem9vbzfykiLL6NU0k0MDUvCNF9i5X2+6UGB1r6on BPMkaJg9o/z2shpD7BrHKnYtMlKeVwA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=vu2lPLqX; spf=pass (imf17.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 207.171.188.206 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1743610078; x=1775146078; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UqLHY0tozEGhyxnF+okEAbfVCr65ECLQO5uKTF2y+bU=; b=vu2lPLqXSHchnY773LyR96szF5ESI0NLAAmhw22BIfjcBi+WvhX1o/u4 TnAUdUmfXKpGb9lKSuAVekTYKx97BRz5V5+UeCiAMQDxqMql7psnR2Et5 W1IzvDpbnLdP8ztiNIUXiiVrH5K1Ow1VnkDBsj6SKxv+yLp0X0Af/Zhdx Q=; X-IronPort-AV: E=Sophos;i="6.15,182,1739836800"; d="scan'208";a="812710781" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 16:07:51 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.38.20:29109] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.27.18:2525] with esmtp (Farcaster) id 0dbab0ac-a3ac-4e29-911c-8594f554e27d; Wed, 2 Apr 2025 16:07:50 +0000 (UTC) X-Farcaster-Flow-ID: 0dbab0ac-a3ac-4e29-911c-8594f554e27d Received: from EX19D020UWC001.ant.amazon.com (10.13.138.157) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:07:50 +0000 Received: from EX19MTAUWA002.ant.amazon.com (10.250.64.202) by EX19D020UWC001.ant.amazon.com (10.13.138.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:07:49 +0000 Received: from email-imr-corp-prod-pdx-all-2b-f5cd2367.us-west-2.amazon.com (10.25.36.210) by mail-relay.amazon.com (10.250.64.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14 via Frontend Transport; Wed, 2 Apr 2025 16:07:49 +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-pdx-all-2b-f5cd2367.us-west-2.amazon.com (Postfix) with ESMTPS id 1F660C061B; Wed, 2 Apr 2025 16:07:47 +0000 (UTC) From: Nikita Kalyazin To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v2 2/5] KVM: guest_memfd: add kvm_gmem_vma_is_gmem Date: Wed, 2 Apr 2025 16:07:18 +0000 Message-ID: <20250402160721.97596-3-kalyazin@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250402160721.97596-1-kalyazin@amazon.com> References: <20250402160721.97596-1-kalyazin@amazon.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EBA5E40002 X-Stat-Signature: uokoonhj4tr4isnjg9raqaepdrdmium5 X-HE-Tag: 1743610077-257792 X-HE-Meta: U2FsdGVkX1/6R7jetHY/X4YsRn/TMcWHOg4ZGw9bm2paODoQauqNgKPC24CFBCVMUX3NWfpQrX0nuh6WbJBXapYbPUZ1OqcqQparq6UCiuIiJl9r8+U+y9aEPjQ2I552naqm9M5RBCHV42OM14d7VICVnRdDWPP+CeQY/HXMBnVgAAZDoCAoBN9kcG0Bdl1IULgIaHQM7kODpU0wuOzBHv3p/VBf1Gi5joTYMg0sPRlgNoyOgJ3grqlNopG8z+GXyd1swRLU/qAZiUCdzrXC0zDrwdgqEcAbo6wWpQJXLo2r/IYQVoGhPVjaZJwkJ+91uCLklqk+TKGppOhGRAE7xoPyLqt+xjrOkDErW4OuvbLoTT3A5CKRi3BjUShHOa1ZiMI7YUX5qqEoaTVCLS+VO6SOeWHDGZnRRq/JQuMOLpygtrtFjQeH79eWd9evzJ86QloS46C+aDC+y8s4YWL+oc+RfRr0NZdWx+VfLQm0V3DiIj2SV2eW+f6zRUCOcW9uq/QsELtb1jQyedKkZBMxeSMurcHkwfttGmVB7cSCM4bkiXfxzuGnUtWaqX6d6gKVZon1w+szs2m30KocmH/Kht4jMhkvi3E9n9itPn6glbJ+NKbSGLTY1oKKwwyHZdIXLXGN6b17qUo61Umenr5+eJAh/UDdbWa080mX03SKbEbSM2aMtiVNgWE9NMBNcLCPjBemNqSlRLy9Fg3FXEqkTKAQnc4ZF6eYRySz19I1QWU3XPlsKe0g6ppuYoy78SnUzj5N8KY2yxmmpdWPPspjiMRg6uLS6Nww22g5+y4f0BambgiCkOEYcfw+E3nR799kwunxQL9eYppOSnZYmoR1J8/6FW3bAzjgSoy+310zXNI0foGPJLWyAl80pAHlRMaAB5lcDYFD0FbKErIoZ/B3lr08na1EfGrdflTy+JFqtxnH33OSAahZ2i1xrjs00eGb8m6Y6sPCBKpngQt35E7 OXOu5Kdc iMQIZnb4TS2O3Bi0DTpyl5hV8IkK4un5tCCeBVp4NqDqF/nx0bYuUVzeQ9USqP+g4OEVOKx6xOwSVZhMIoAwqkJgXogDfdU4I7wH2HOuRC/HLxDVd2qdUk1FUF3qBCYHgrEYJzXMYvvOBQnkQ60CH2RwYXID8XbiVLMHA2E2kmic+I8lGLtUckCWHAX0eqM4W0UinDpleF0hYSNPneexeTra0EVpF6zNZI5G3qorKRBq2XBjl+rH/M7o5ywqQYhutWHqPqQpKg6GG24BkruimyHTKCvFQaJAFeDzR5b23nyu0/ECAiI+GaTzInSYYOoL0F32//vR1CsiIYQ0CF8FcFPQ5Ex2ZqtkETGcAxdooc2IAKd4g6BgpD2imqH3vwK6nH2411aKRws1/0iJU+GvVXqCxTN5vTgzhT5nWrhFsklTqXWxoVnejixCO2fkDOlAy/sVtf3lEIDuGD8lkeZmRlVVZ69w6o8Yzff0+F3Mjj29HefZ9U99IC1q6WrxJMumxS+a11+uBJPSxZgoBFxLztWURbO4mOe1WAlbrtYQhnFrJKtw= 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: It will be used to distinguish the vma type in userfaultfd code. Signed-off-by: Nikita Kalyazin --- virt/kvm/guest_memfd.c | 5 +++++ virt/kvm/kvm_mm.h | 1 + 2 files changed, 6 insertions(+) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index fbf89e643add..26b1734b9623 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -416,6 +416,11 @@ static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma) return 0; } + +bool kvm_gmem_vma_is_gmem(struct vm_area_struct *vma) +{ + return vma->vm_ops == &kvm_gmem_vm_ops; +} #else #define kvm_gmem_mmap NULL #endif /* CONFIG_KVM_GMEM_SHARED_MEM */ diff --git a/virt/kvm/kvm_mm.h b/virt/kvm/kvm_mm.h index acef3f5c582a..09fcdf18a072 100644 --- a/virt/kvm/kvm_mm.h +++ b/virt/kvm/kvm_mm.h @@ -73,6 +73,7 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args); int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot, unsigned int fd, loff_t offset); void kvm_gmem_unbind(struct kvm_memory_slot *slot); +bool kvm_gmem_vma_is_gmem(struct vm_area_struct *vma); #else static inline void kvm_gmem_init(struct module *module) { From patchwork Wed Apr 2 16:07:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kalyazin X-Patchwork-Id: 14036210 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 8DB6DC28B20 for ; Wed, 2 Apr 2025 16:08:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE76E280009; Wed, 2 Apr 2025 12:08:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6F1E280001; Wed, 2 Apr 2025 12:08:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE974280009; Wed, 2 Apr 2025 12:08:27 -0400 (EDT) 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 AC084280001 for ; Wed, 2 Apr 2025 12:08:27 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 550B11CE1AF for ; Wed, 2 Apr 2025 16:08:27 +0000 (UTC) X-FDA: 83289586254.04.4232FD0 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by imf13.hostedemail.com (Postfix) with ESMTP id 4F7BD20010 for ; Wed, 2 Apr 2025 16:08:25 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=ekdSKJib; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf13.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 99.78.197.218 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743610105; a=rsa-sha256; cv=none; b=IZXvVu0DGJGaPTzBayfad2tS5Ykd6vGVtLKacGnRmTWFuB+00aFclp+m9RcKt6dsCi3GDj avKR9pI4sze1mtnrabSetkItKba03MGhfL6dqnkYSEWy35PSC9H+O+ie+9Qpf6D5kU+PVd IeVqVPoGjYUimlkC9OeBlueKH3eIETM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=ekdSKJib; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf13.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 99.78.197.218 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743610105; 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:in-reply-to:references:references:dkim-signature; bh=c1vC5PQObwSRnrwFndUeVO1NivEsO2o9+Qe0hvf7HYM=; b=FywtBG8+5k/AqIPUbNf+UsBdWNTJuxIa07kqhxj7V8utl0f7vumMxhDz4ajZm4kSiKkB/L E1h/YZ7b6yAGZJSnHpbM4S5+Hb4A0rouxZDBdELOvLaI8++rFuSzMK4DeIrJGO+6WZSxfh TB/FXz6ELyJUEiiFTHp+VcsYZ4vrgnw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1743610106; x=1775146106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c1vC5PQObwSRnrwFndUeVO1NivEsO2o9+Qe0hvf7HYM=; b=ekdSKJibnez/UBSo4+daWWuc74TiBfeszhGB87sX651g7OpkjiYB8CI0 VFCr+Rnspcb111X4H2UjEJTd3qLFCKNv9isbAJAGYhyxWE36QZ8K7Ynx/ c/kbHd5mWwnkGewTno1MNXvwF8GHd3KasWNokv5j2oz5tvNDkeyR5jZTp k=; X-IronPort-AV: E=Sophos;i="6.15,182,1739836800"; d="scan'208";a="392250945" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 16:08:20 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.38.20:33674] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.46:2525] with esmtp (Farcaster) id 8b5e1693-98e0-4752-bfa2-b66a2ae4dca2; Wed, 2 Apr 2025 16:08:19 +0000 (UTC) X-Farcaster-Flow-ID: 8b5e1693-98e0-4752-bfa2-b66a2ae4dca2 Received: from EX19D003UWB004.ant.amazon.com (10.13.138.24) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:08:03 +0000 Received: from EX19MTAUWA001.ant.amazon.com (10.250.64.204) by EX19D003UWB004.ant.amazon.com (10.13.138.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:08:02 +0000 Received: from email-imr-corp-prod-iad-1box-1a-9bbde7a3.us-east-1.amazon.com (10.25.36.214) by mail-relay.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14 via Frontend Transport; Wed, 2 Apr 2025 16:08:02 +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-9bbde7a3.us-east-1.amazon.com (Postfix) with ESMTPS id 84EFE42240; Wed, 2 Apr 2025 16:08:00 +0000 (UTC) From: Nikita Kalyazin To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v2 3/5] mm: userfaultfd: allow to register continue for guest_memfd Date: Wed, 2 Apr 2025 16:07:19 +0000 Message-ID: <20250402160721.97596-4-kalyazin@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250402160721.97596-1-kalyazin@amazon.com> References: <20250402160721.97596-1-kalyazin@amazon.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4F7BD20010 X-Stat-Signature: 91516x7tf69uyypzctomzmzdwznjxzks X-Rspam-User: X-HE-Tag: 1743610105-703405 X-HE-Meta: U2FsdGVkX1+Lt7y9VW+hc4CGu2Qpb9pfMu5gnYd6M+3KQmJRButQ9VnqfyAkBzxiwbhA/uftqY7TGsZtgKY0KXeK7ZFyNbAWkAjeyB+k9OKRuCie6580fXi4GSR24D9X4peRZA78LImsFF4xw3yWBpy7/7Viz/Di+E2ixDl76JDlUKpULsXNA0jboQgv1bxGRcxu+UM1QM2Np9AyU58KeLyr5+VldOnW9VizoQJ9sWfhnkfSmwBNFEywA0F2P7DjpEpZWjbSssEnf6uTwbxcqB0oew+YqBExV43MvYGSNEKiYrjMd5hPHtX3EPSbGrtmm5kde7zVqfngE2UZYpQkDZUb4RqjfXgiNQHdMu14X8kCRy3pzS0N/U4fXDU0GpuW/cqJNMtvCuuNHVGxo0eV7vvz6Sw05Vbo2XkQSq9k3u3ZS38VSLbR6wflGWVVcu68ON1ctEvQ7azc9GKTs/b7OTkMX+BX4PPZ2ug9vyB0oYy4pfPDvB5U8xDX9TW3dBOX/XLL+M8gFj0bx3kMObRcZtHQ1Qh6kdrqv1y7CW/Qoa2ddZl264c758tSLwqqIgy02NySeICGV+9nx5GmWDDQmyW2h3PZsFjjeMiGfm5P/8/9/qdQgtvSriw+poc5UIwSQfxhsC9WWXbKm6YGv5u5xwLh4AubYNrHWgEUYOxbUur0PI8h3HqHSoks1SU78tR3UVA1M12kVD5oUgf5Bih4eRRb0i6tBT2vT2XUJ+9C/yDNuhdbHlvOmy091rNFazEh0BxOKAUqNWlW25Moj8qfNu+waO/vAo8vWZBkKpMyjNWxVqvYaF3X4FHQF7LAhBswcd2wo9Rq0GI1oy7RzWXq7+d4STt3FHAM8PrLUViRfwC4ygi0SLD8c0A38fukYLA9MX5FLgbpQ8cpVRAGuI5U+mGrIO9ZXThS4ARyU50pjZ+pm3OJurfX0WtDte0BSGP+6Rha6XNs1Y327DnaT1m G1tMSGrq 5lvRyCDZgDKY5mVOMYn38DkQLowpE16JTETWLnmEz9KTle8kPdfASOyNU5FABXFnbV1GnZEwJxXksMFbQPSnp2T0V1+C/M5VgtyQcO07kiwYkRi2IljLBJCmQV/u9d9JL9/aDsHzniMu8O3/rr2A3bZXo7otRE3aBJ8KmdOXv0OckQr2Yr7QuL1v8C4HPVlUF0Lo5tz9TH8YJCOEDmCkq0+kQm8/1xN0wB8usy0EtvdVIFgqAT1discge+ZRE3TROsYlHNFvs5pxv73d9vByB4S159XOVrLeJBH6LCaHirN8rzuaRcrquyDqmGnu2j+aISvddQUYLg1ArqQAiK/3JwEaLo0xJlUaywkKFyrorgRSQwiC01T9F21WSaCqc7QwVKqFK+ViE1KWsUm4Pkp5tgjmB5zSnrlzxylxFqj8B8VZCtNzEaGbug/AkpRhyPmlc4+hEdvl4mM+FCL0X+8KmsiUjhzVd0FzBMY5Gy65R4MSuSVDR9c5Zr4zZ+9GqMcQof42+AKmPzu19Rs70aJcyxHD19Jzbh2Npb4NZK+wlYlspSac= 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: Signed-off-by: Nikita Kalyazin --- include/linux/userfaultfd_k.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 75342022d144..bc184edfbb85 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -212,6 +212,10 @@ static inline bool userfaultfd_armed(struct vm_area_struct *vma) return vma->vm_flags & __VM_UFFD_FLAGS; } +#ifdef CONFIG_KVM_PRIVATE_MEM +bool kvm_gmem_vma_is_gmem(struct vm_area_struct *vma); +#endif + static inline bool vma_can_userfault(struct vm_area_struct *vma, unsigned long vm_flags, bool wp_async) @@ -222,7 +226,11 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma, return false; if ((vm_flags & VM_UFFD_MINOR) && - (!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma))) + (!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma)) +#ifdef CONFIG_KVM_PRIVATE_MEM + && !kvm_gmem_vma_is_gmem(vma) +#endif + ) return false; /* @@ -244,6 +252,9 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma, /* By default, allow any of anon|shmem|hugetlb */ return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) || +#ifdef CONFIG_KVM_PRIVATE_MEM + kvm_gmem_vma_is_gmem(vma) || +#endif vma_is_shmem(vma); } From patchwork Wed Apr 2 16:07:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kalyazin X-Patchwork-Id: 14036211 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 19767C3601A for ; Wed, 2 Apr 2025 16:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5757528000A; Wed, 2 Apr 2025 12:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54B69280001; Wed, 2 Apr 2025 12:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39F2E28000A; Wed, 2 Apr 2025 12:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 12844280001 for ; Wed, 2 Apr 2025 12:08:29 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D5696161CEA for ; Wed, 2 Apr 2025 16:08:28 +0000 (UTC) X-FDA: 83289586296.15.3486E59 Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) by imf13.hostedemail.com (Postfix) with ESMTP id CE4A020011 for ; Wed, 2 Apr 2025 16:08:26 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=pecYHAsE; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf13.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 99.78.197.219 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743610107; a=rsa-sha256; cv=none; b=yS0buum41A65hm9zvGzhq7ScFofSFGfaRZCC/HqdfPJmZFFIrG+BzmvNZS7hQmpxjF0KtS oaBSFEtKzEsyas0GNBRhxEShLhTBLIRYhrM1tukqSpIR0kj85eKMEOEHvD8TSZSaks/J6I KMhpRy1jcmauY0jVDpi6DoFo3RwyFRg= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=pecYHAsE; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf13.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 99.78.197.219 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743610107; 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:in-reply-to:references:references:dkim-signature; bh=uKvQStBu+rMX8UPjQS1EH5XeuJ9x01oElWsxsBsndIY=; b=LQUpfuAgFJZVu2YqMQTYZf4nRUEH+HIwmhqP1EIcmz2z29uZi4h4mUKJVVXiGs+82r6qTz zANA4KbzkCMfZ3Nh6X1jT5GkYmT263UD5T4S/0qVrI/6jBamK8YgH9BWIpicdtllXzzaTm yvpHhf6JwCS1SaBxI9PSPNXPFWjVxJs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1743610106; x=1775146106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uKvQStBu+rMX8UPjQS1EH5XeuJ9x01oElWsxsBsndIY=; b=pecYHAsEOZ3NB3UU0jDunX59FlbH7Eu2bQswo1PsWOPOkl2E05oHGJzx adsL3HYzp2R0Rz4exBpXK1awwzFzspkGOt/WXgv/jEPOONuXM3l+oyAcG iA8xSrlKsivIk/TnyYiaQmqoENbuhOosYXqrfRYAW0WyOgkKNEdF/ca3o k=; X-IronPort-AV: E=Sophos;i="6.15,182,1739836800"; d="scan'208";a="184231774" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 16:08:23 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.38.20:23064] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.91:2525] with esmtp (Farcaster) id 9fca53eb-8c49-414d-98bb-13cf3c17e564; Wed, 2 Apr 2025 16:08:23 +0000 (UTC) X-Farcaster-Flow-ID: 9fca53eb-8c49-414d-98bb-13cf3c17e564 Received: from EX19D020UWC002.ant.amazon.com (10.13.138.147) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:08:16 +0000 Received: from EX19MTAUWA001.ant.amazon.com (10.250.64.204) by EX19D020UWC002.ant.amazon.com (10.13.138.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:08:15 +0000 Received: from email-imr-corp-prod-pdx-all-2b-5ec155c2.us-west-2.amazon.com (10.25.36.214) by mail-relay.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14 via Frontend Transport; Wed, 2 Apr 2025 16:08:15 +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-pdx-all-2b-5ec155c2.us-west-2.amazon.com (Postfix) with ESMTPS id 3A4DA40BE5; Wed, 2 Apr 2025 16:08:13 +0000 (UTC) From: Nikita Kalyazin To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v2 4/5] KVM: guest_memfd: add support for userfaultfd minor Date: Wed, 2 Apr 2025 16:07:20 +0000 Message-ID: <20250402160721.97596-5-kalyazin@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250402160721.97596-1-kalyazin@amazon.com> References: <20250402160721.97596-1-kalyazin@amazon.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CE4A020011 X-Stat-Signature: 78364aawb9sehhcw9gbptarz8uakb4bu X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1743610106-960172 X-HE-Meta: U2FsdGVkX1/O3eAdSo2b9TvERYCVjGCrO/WeTeUMBIvDP/noPTiDlQa8myYQz68a4G0Sv5PJxyngITaAlEvM0oETH1g0vvEbSmrW5ANzUdyON+VoVe424W37KaOuf1Ro8ydLrbMPaWn3/CANo995K3DdpPM16uuatKjiu+JmgUxvzsV2vwmiXVYVqa6rpEcOhnWDpky0Or3G0N1kYNxjGil/8W6pQ1R/2RB+8vksyNtKwfc7fpy7JfvCEMr46i1F7r4LS/RnibNNWl8TQyHh5oB/rTjbsJ5DKR+rjveJvShDV7O3n5z5b8ZWkTzCmn4ICdDvCw/ICpSG0u1mT2KH5k2Zn5gM+UpORow5gk8LsXcE/aVeOuxIYbnbkMNexaWeIJo0NxFjmTFcGSOqBFsh7sCWfJU0x3VAXEcSPAjkOPnBXYHOkFXM/dMTU9KCGdgdCUZ/h7pHUcnWYCDUOWUa0tI2ayRGBVEuXdFbdsA5K/INR/mYOEzBh5Oghe+Vf14TKlNRNyGj/ndDQ5U0ZCgvl5oC4/wYY1Xh49O/mbdJXkve4wl4kKPQBBhxM68/2V1maLPHnrgZX/6xMH0Jvtj8ORC3O7tuZeWvgasaX6zzJXTMeDyopaj9G9cRH7txBifYwFYBsSthW7Ox6BDFy8C1QqEFvmIcOUI/9QWuw6PDwxkhcZAxPtwkY1ozg8/puaHs3vGpOzBATfYAKE4Ig6jmf00j2M2GaxFExZwggAHCEQXmFgHa51425+TjqhWYF3iEeeniQWby55RoJqXGebJIWqKnuDN/ZwhawgGGvA3dO4UGvTUghlZDQTOxvtnYA/oolwWXHiymH182tQzW1h3ZBbTWiCPOeHGdF49YkT/otfnb37G/kOP5yDmFTpCMk7Ih5Yv2qQOzUILyV03jE9WMMyJ3EjV07pz2PBPX1QZaaCO9yUIQ67ISGtAIV6qwBnkviw7ptqL+B/j7CUYEXDl dsFVrqgI R7MGfYVq19Dg20nov/RH61zm4WpOtD+qun65E/WQql2JSqvs/q80ti+BIW8YTMzVlZ/PqSKWYOAI3EXjASD0QjrkfJmhLZuUXd85CGFqHflSja4p1ezyKnPRrofyYFOYeCl9IdHAqtQHxI/9nzMDv3NCDy/AcyEsVwtZkZjiFxk0hcoiqnS2uemdtfOZ/bhOSYDkuYcYcsRyzO3R8ZZQvp2q2qsgO1Dzr7/rH6ggOil7mI6LtvGXMOgdPx4lX5DQAyr2XTAmdA/QXWoIhsQJHuJVDTSyJjKWRu5t1kKusPc5DnBa5lkPyf7sa8qOMeLtRK0KSIWKDHSA1Uezwwoec0ciqCCchgucQ44R6Zu/Pmue20wEz0ADw9FwchrueLG1XMRrtGFrSi2v0mhsOV0Ylk397cuS2Zna+kMHvOoQd8oXt76aqOJ4Si/Kp2S/zZ3nxlCkCf6SHSzYLIPamsKPh4a6a095kf6jcWjePW/50ZRM2X4dqtZ7wTzioPiqfQHWUHCIlhWQ7odLHvtu0ZGTu0BQphw4F5oS0tLmeH1qRlLYvT5ybC9fUI66n00d+iPXDVmSu9vEyn3XDVW0= 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 sending a pagefault event if userfaultfd is registered. Only page minor event is currently supported. Signed-off-by: Nikita Kalyazin --- virt/kvm/guest_memfd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 26b1734b9623..92d3e6b51dc2 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -4,6 +4,9 @@ #include #include #include +#ifdef CONFIG_KVM_PRIVATE_MEM +#include +#endif /* CONFIG_KVM_PRIVATE_MEM */ #include "kvm_mm.h" @@ -380,6 +383,13 @@ static vm_fault_t kvm_gmem_fault(struct vm_fault *vmf) kvm_gmem_mark_prepared(folio); } + if (userfaultfd_minor(vmf->vma) && + !(vmf->flags & FAULT_FLAG_NO_USERFAULT_MINOR)) { + folio_unlock(folio); + filemap_invalidate_unlock_shared(inode->i_mapping); + return handle_userfault(vmf, VM_UFFD_MINOR); + } + vmf->page = folio_file_page(folio, vmf->pgoff); out_folio: From patchwork Wed Apr 2 16:07:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kalyazin X-Patchwork-Id: 14036212 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 63306C28B20 for ; Wed, 2 Apr 2025 16:08:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB55528000B; Wed, 2 Apr 2025 12:08:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3E34280001; Wed, 2 Apr 2025 12:08:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A93CF28000B; Wed, 2 Apr 2025 12:08:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 85ACA280001 for ; Wed, 2 Apr 2025 12:08:36 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5EAD6121C6A for ; Wed, 2 Apr 2025 16:08:36 +0000 (UTC) X-FDA: 83289586632.02.919C79E Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 2FEC61C000B for ; Wed, 2 Apr 2025 16:08:33 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=YEbD3va5; spf=pass (imf20.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 99.78.197.217 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743610114; 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:in-reply-to:references:references:dkim-signature; bh=wTofU1xt/dJK2QsInBbhwR8+NZ3Sv3EgYY1jxlgxsY4=; b=b3by0VvqHbekaIwKXclggBCmdrE5kc6ggyolv+VbsV7olHXm1lR6yhlOGjmEFTQzgmt4bu 4l9b3oMO6sO20EyzAcJEcgtPr3ixDJ0BiZCBzWOlOBHnFuaGcMnNZZMM7gKVuH9amqLNce cGJyIF9OB+IY+w4ixqtQqmvNC/poTxg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=YEbD3va5; spf=pass (imf20.hostedemail.com: domain of "prvs=1800b2f01=kalyazin@amazon.co.uk" designates 99.78.197.217 as permitted sender) smtp.mailfrom="prvs=1800b2f01=kalyazin@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743610114; a=rsa-sha256; cv=none; b=G0sbeeHPgNcAjXcs9kdTYJLEeiVN6bimjIC6x1qkTTgllVVL1fSOK+JsExKOpC7pwf00Rt 3eMgFmp2cz8qB4Gq+Ni4DKb/CzvhAM8N/cvm4//oxu5quSCmQC8A6fBuD4Lop79tawr/7q b8r7Iy5EjJTtZfKyn5eppEilbsUb6dQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1743610114; x=1775146114; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wTofU1xt/dJK2QsInBbhwR8+NZ3Sv3EgYY1jxlgxsY4=; b=YEbD3va5c0UREH7Zvs1YjpdApdZ/S3adVmfdUgmHFNTX4CoKS7/Zu2+V JGvUSxfUtxo2/ecwPg7xs3ykfQbkha+5X9uP0FgUePst8stEJ64DsN02C LmZokj33bBOUHIvYByAE/mhJWSbV8kjsfP4k+hmszwro2QNEKpRakfR9K A=; X-IronPort-AV: E=Sophos;i="6.15,182,1739836800"; d="scan'208";a="37468501" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 16:08:30 +0000 Received: from EX19MTAUWA001.ant.amazon.com [10.0.21.151:61509] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.46:2525] with esmtp (Farcaster) id bacfcabb-94e1-4d19-a36d-27c598e119db; Wed, 2 Apr 2025 16:08:30 +0000 (UTC) X-Farcaster-Flow-ID: bacfcabb-94e1-4d19-a36d-27c598e119db Received: from EX19D020UWA003.ant.amazon.com (10.13.138.254) by EX19MTAUWA001.ant.amazon.com (10.250.64.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:08:29 +0000 Received: from EX19MTAUWC002.ant.amazon.com (10.250.64.143) by EX19D020UWA003.ant.amazon.com (10.13.138.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 2 Apr 2025 16:08:29 +0000 Received: from email-imr-corp-prod-pdx-all-2b-f5cd2367.us-west-2.amazon.com (10.25.36.210) by mail-relay.amazon.com (10.250.64.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14 via Frontend Transport; Wed, 2 Apr 2025 16:08:29 +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-pdx-all-2b-f5cd2367.us-west-2.amazon.com (Postfix) with ESMTPS id 06432C061B; Wed, 2 Apr 2025 16:08:26 +0000 (UTC) From: Nikita Kalyazin To: , , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v2 5/5] KVM: selftests: test userfaultfd minor for guest_memfd Date: Wed, 2 Apr 2025 16:07:21 +0000 Message-ID: <20250402160721.97596-6-kalyazin@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250402160721.97596-1-kalyazin@amazon.com> References: <20250402160721.97596-1-kalyazin@amazon.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2FEC61C000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: eqmoriocubt1r5tdapqfzi337ez4dnua X-HE-Tag: 1743610113-621461 X-HE-Meta: U2FsdGVkX18BTJs8otfd2Af9DIkK/2Dsq4ieViljPzNXGI4j1QOv8J3BNnaQwh+7HlOdp9vp9YL7OyH9d3pwp6xSzIizKreKbTHpSQVc88qcJmLI2I1dE9aBKAdimjonf+59QGc483PZ3YKqWWMnwkQfSXhaV/ahB99HQF3rvQy48zGzuipLjVTBCniJkan3hZHDqyJhT3NUT/Rpc4zBhr8rWPCURFiaWXO6/aX4Kd0maeAnk9xBV4Imp0CaVhcWskusjRKNQcgbw9LO5laLji+HoyTf4Ohi+qp73ZH01qeNRe7VCLoiCVZaUCXwRMm23+JdSqlzyNQtlKrz6Ql7UAxqEppsROuAmMILyWJ+gT/dfssiCs0S34wgNrKyB9Lpfyf5DwYc0m2F5IEHsQxdtIF/HULx7o/DNXz/gZsdxPGsSaDZkek2Dz8S+KNM0F5FBvQdWIoyjn24SFcD8nC04JXUi2VNtVGvUT3A52+XrjZZaPPN9ApjXwQdVArh5+Q/eqWUJulWqg3E6IIDou0kW0VKF/JY4Lhpb74U1rHM28R4bls2SRbpgh8VQE4+qEXdWrNyZCfr9fvjH4FczcrnE3atEBT7cN6l5kzjtV4thEIZeTLGIFMpVgxUdvd5CUb/Qi3EUXdsmpZKn6VCLzZLHaBBw/l+as7KOOobNY6noCSeLHZWGF3LCLwv10zwN7ffFMThV+JC8dXssYmpO+lv9QD9tEOnOpm4Ya7emMr1EcCqTc9tmXA1h9W8lXQUJubejqIvrhOlvucoYt0ezff3qvfqQOGbmnd/lrAJQRngQNE6IyvVucYPCwPZ8bhzRrPXtRv2Fo6ZsPciAuox+NGu7vp3Jvk6PiyqMmVwoPLOYK/CB4I8bb6CVFDQkGTSMjZ7FMQjmTMPgsUG8irw89vh6a6tPUIS2zBmAGuMGXTRhTz/yc9BLdtWIfyhqx1lb+mpra6EeAfgIdfLzvpia5g QrX0oVtu VzZSHzXAKqsrhnxWl1lnwA8F1o7jORRe6SUcpsfQ9dTvjckpwSh+3q7PFZeLWb4N6Dk2tEyrhUJoZbZWBG/FLafWx4Dt0de97nB5yPDY1jNDCuN9g/t1IKrGJw4pYndaV5mnJSeRmwYLPRkXZjjjDGj88Qom4x6lD7gYmh0HBztngpU5/OxleiEQoGYD8i+VY3k9vblefWfAu+C+TWim3Xv9Pn17NJWkSkIB2T8XJRYNgJI4xW0I6vIeD0JXezc1AetV18mn/sMEZ1kAcwF+Byg+zEwcJjYJqCE4N5FBDiwQ3Lf/WJiwQssU9edzXTOq8ebVWFG1PRYgPNMGXUHuGeWBR1VLjqUgi4Bqs8Wt+dV8Y0s58EjFN5AWfED+LSxzjC5OYsJgHPrTQLYqFE5KMBXrXCcXdC7JR71CtLeBxP0ygrrH7Gc3B+IfpFtF3Rpi5od9rYZ2oGAJdW3N3NIkn0RQSwMT52zdpSLxOo/1xIr1pXkYuTxmQ7qaUe/Yesgu1bwcDHYBdIXQaKXQ8LelhETGxlRRb0CnvhWYuIKeG3DAX1dU= 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 test demonstrates that a minor userfaultfd event in guest_memfd can be resolved via a memcpy followed by a UFFDIO_CONTINUE ioctl. Signed-off-by: Nikita Kalyazin --- .../testing/selftests/kvm/guest_memfd_test.c | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index 38c501e49e0e..9b47b796f3aa 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -10,12 +10,16 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "kvm_util.h" #include "test_util.h" @@ -206,6 +210,93 @@ static void test_create_guest_memfd_multiple(struct kvm_vm *vm) close(fd1); } +struct fault_args { + char *addr; + volatile char value; +}; + +static void *fault_thread_fn(void *arg) +{ + struct fault_args *args = arg; + + /* Trigger page fault */ + args->value = *args->addr; + return NULL; +} + +static void test_uffd_missing(int fd, size_t page_size, size_t total_size) +{ + struct uffdio_register uffd_reg; + struct uffdio_continue uffd_cont; + struct uffd_msg msg; + struct fault_args args; + pthread_t fault_thread; + void *mem, *mem_nofault, *buf = NULL; + int uffd, ret; + off_t offset = page_size; + void *fault_addr; + + ret = posix_memalign(&buf, page_size, total_size); + TEST_ASSERT_EQ(ret, 0); + + uffd = syscall(__NR_userfaultfd, O_CLOEXEC); + TEST_ASSERT(uffd != -1, "userfaultfd creation should succeed"); + + struct uffdio_api uffdio_api = { + .api = UFFD_API, + .features = UFFD_FEATURE_MISSING_SHMEM, + }; + ret = ioctl(uffd, UFFDIO_API, &uffdio_api); + TEST_ASSERT(ret != -1, "ioctl(UFFDIO_API) should succeed"); + + mem = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + TEST_ASSERT(mem != MAP_FAILED, "mmap should succeed"); + + mem_nofault = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + TEST_ASSERT(mem_nofault != MAP_FAILED, "mmap should succeed"); + + uffd_reg.range.start = (unsigned long)mem; + uffd_reg.range.len = total_size; + uffd_reg.mode = UFFDIO_REGISTER_MODE_MINOR; + ret = ioctl(uffd, UFFDIO_REGISTER, &uffd_reg); + TEST_ASSERT(ret != -1, "ioctl(UFFDIO_REGISTER) should succeed"); + + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, + offset, page_size); + TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) should succeed"); + + fault_addr = mem + offset; + args.addr = fault_addr; + + ret = pthread_create(&fault_thread, NULL, fault_thread_fn, &args); + TEST_ASSERT(ret == 0, "pthread_create should succeed"); + + ret = read(uffd, &msg, sizeof(msg)); + TEST_ASSERT(ret != -1, "read from userfaultfd should succeed"); + TEST_ASSERT(msg.event == UFFD_EVENT_PAGEFAULT, "event type should be pagefault"); + TEST_ASSERT((void *)(msg.arg.pagefault.address & ~(page_size - 1)) == fault_addr, + "pagefault should occur at expected address"); + + memcpy(mem_nofault + offset, buf + offset, page_size); + + uffd_cont.range.start = (unsigned long)fault_addr; + uffd_cont.range.len = page_size; + uffd_cont.mode = 0; + ret = ioctl(uffd, UFFDIO_CONTINUE, &uffd_cont); + TEST_ASSERT(ret != -1, "ioctl(UFFDIO_CONTINUE) should succeed"); + + ret = pthread_join(fault_thread, NULL); + TEST_ASSERT(ret == 0, "pthread_join should succeed"); + + ret = munmap(mem_nofault, total_size); + TEST_ASSERT(!ret, "munmap should succeed"); + + ret = munmap(mem, total_size); + TEST_ASSERT(!ret, "munmap should succeed"); + free(buf); + close(uffd); +} + unsigned long get_shared_type(void) { #ifdef __x86_64__ @@ -244,6 +335,9 @@ void test_vm_type(unsigned long type, bool is_shared) test_fallocate(fd, page_size, total_size); test_invalid_punch_hole(fd, page_size, total_size); + if (is_shared) + test_uffd_missing(fd, page_size, total_size); + close(fd); kvm_vm_release(vm); }