From patchwork Thu Apr 13 23:11:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210718 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 1AB46C77B6E for ; Thu, 13 Apr 2023 23:11:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD8C96B0075; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C86EE900004; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B00156B007B; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) 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 A1F5A6B0075 for ; Thu, 13 Apr 2023 19:11:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4C90B80492 for ; Thu, 13 Apr 2023 23:11:29 +0000 (UTC) X-FDA: 80677916298.25.B12DD19 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id CEBEA160003 for ; Thu, 13 Apr 2023 23:11:26 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bCwt7HAh; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681427487; a=rsa-sha256; cv=none; b=iZ67PTWYzwg1Bel+88FpIDTMbhVLoUblslDn4n/QfPkFd28HqgedFhma/1duEI13HOfM5a vv3chWjXe6AUbYgDH+0L+guWYeIGTD86CK3YRge/v411JvVTcKeMOpUZ9Uniiezt4eKsS0 H862AAgPySsfEvcDyq+HS0VdaeBDifY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bCwt7HAh; spf=pass (imf08.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681427487; 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=yQk3ShNsJBmwBAeq1XAgk+wt78LOM0H1LyrpvOkMJhI=; b=v6nnu475SjLnImhlYaoQZVJmhZ+Ue7naTG3sajVfF0thikDn3pojaXoa3Wg+OyQ1I1woM7 anv5PbPeHNcwlBzK15MDTm1/klP2dripqvFHCF+ur6hhuIFg6JFbmxqziBJeCG7ViXXbhQ e1QVuFfDYO/AwqKS74A8r3h8wEFQbb4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427486; h=from:from: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; bh=yQk3ShNsJBmwBAeq1XAgk+wt78LOM0H1LyrpvOkMJhI=; b=bCwt7HAhsgdXxOZXgvT5oI1qo1zYjKg+4Q30CAS6Q8L7f1RCrQpNcUn0/alWqJztZKjgLQ ph4Jm9lYbtyw9sWw+uQwnuX83Psn+9a+5kzvKd7evcfNyZ4y2P1VLn3dEeb3vEgC+/HdZ5 fmSdFdAhINOGrE6ZqntSO3gqDX92cTw= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-3-Mey82hocNwi9AmpvwO4GVw-1; Thu, 13 Apr 2023 19:11:25 -0400 X-MC-Unique: Mey82hocNwi9AmpvwO4GVw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3e947d81d7dso3391291cf.1 for ; Thu, 13 Apr 2023 16:11:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427484; x=1684019484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yQk3ShNsJBmwBAeq1XAgk+wt78LOM0H1LyrpvOkMJhI=; b=ft2rtEhmkhxKR9uQpgsLDfM1v7GKzfHtODT9ic44VaYWZ7lJn2agS3ZF02l/mnCUiX 29/gmApaigOr2Fb5z6BP46p7Gmt9gU87YnBJm0d39r8zjwtFLhSfvvLgTLh1QKdjyMqg fIGB7m5tJ+g6czgl5DtrabCa8ZmgqpQgPkTj+EU2ISwpCipAhFCyV9k4I5H4qCJ9XlsZ cKF/rytJePQvsR3dNzOQ/fiJO8F8hLkEX7GxAgg6/gADLV6AwXq1peJjq/zDprsr7+Zn xlj4sABspKMxOmslv56jHEzspoGHZUSF7wV1Xkb/lgPKkZWOTZFsOpVhrG9N8YOtZ8tK Uksg== X-Gm-Message-State: AAQBX9f2ybymKWbLnNrTVkYvkiXfbo0xL5gPgdwgiAecO90dogSJlZHZ ZmcHu2tJaveaYoK1yH4FAOmsaOYAAyt7T5CdLlRmzdTppZsAMFROuKgTImg9AYRpQpvdmtwo4z3 6Z4U8kBB+JFM= X-Received: by 2002:a05:622a:19a1:b0:3e3:98cf:68ae with SMTP id u33-20020a05622a19a100b003e398cf68aemr1101140qtc.2.1681427484546; Thu, 13 Apr 2023 16:11:24 -0700 (PDT) X-Google-Smtp-Source: AKy350bljVojz9f9gM3R2vNG1p3GyeG+24EcdnppJPHidpEMFzohOSepYYLSiIIjIIlL/AyTNhMu9Q== X-Received: by 2002:a05:622a:19a1:b0:3e3:98cf:68ae with SMTP id u33-20020a05622a19a100b003e398cf68aemr1101122qtc.2.1681427484321; Thu, 13 Apr 2023 16:11:24 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g3-20020ac81243000000b003ea1b97acfasm612446qtj.49.2023.04.13.16.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:11:23 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , Andrew Morton , David Hildenbrand , peterx@redhat.com, Mike Kravetz , Nadav Amit , Andrea Arcangeli , linux-stable Subject: [PATCH 1/6] mm/hugetlb: Fix uffd-wp during fork() Date: Thu, 13 Apr 2023 19:11:15 -0400 Message-Id: <20230413231120.544685-2-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413231120.544685-1-peterx@redhat.com> References: <20230413231120.544685-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: CEBEA160003 X-Rspamd-Server: rspam01 X-Stat-Signature: 79qoakygjofe691nmkwxdu7jgnngfnrz X-HE-Tag: 1681427486-773595 X-HE-Meta: U2FsdGVkX1+447wIMil3bLOrCr8SbxzLQEoZPUIAPCZ+4ECczvwoSgBXzVF5+IKvIJUuvIHYvlp7700wX+3fkT4u9nZDghhlgIrHi0wE3eW3iqfbTU7dUyo6t6GYNRL+bzoM6F5/3Lh++gzN/vxm2ZfrCMqMZWn0XIvpTGFSX09bfv5EwKsB0xcmGwcC6SPMbAwTu9YKuW9wH2s3i+2dh0l07eT8qxP0lKsz4f2Ay56AnituAeQ21ICZRDd6tUcjsGv9HMHzPsIBMLe3nuWrt80ggfn/gRGXzQQf4hi7smQxpt74HwIzLDPyWkR23xJXuFMV3edXqgGy8+Lsthxz3CbzbO5QluLmN/A4cwkGlDWTvNIZwmvZe+plGoXULre5MIllKEhX6In3152Cb1eqpEuzZJ6XwjmFTOZQNjWvuePbdx04D9oDr+HuoSScYU+qwGjEhOS+/3O/e3QMEjXsmbo8knWmn/J8GN62ywREaRW+JMmZOqVWhz96UDx7IYBKtkK+MNDTkEZ9WQeJn39InhLeo9nV05v7zQn7A0WSBRO2oPdTo0SLMGWWCnRd9jjtocnpukFy7R/SefZN7YkzJ0TOLIhj8XsOpVaih2y1VZAVc+7ByHNcepiZm8PCkUHlTthYQQfAatJiXmCTdAPFxdvI9L7df10jZXXvUsNkRRcnUCukqv95H7Za+VaG24BJtwgUstQ2WDVmXHK2iNKR5IID/0nJZk56vL1oSnrut/5PLTScWRDm/3ad/UefKfE2KgfJsIJBDVdnzR9NplleRpMTb/wvdjGD5r73z9b2YMA5VVWgYLYNv4neWTSexAZSq10xnrtYJ6qF96pFtY+3uLgPgbRTKuVfnFSCzjRZYX8Gksp0+ICLmnDu1lYZ3QjPoVB8npIags6y7NlCWq8Oil/JE8QX1ZYejUKYg9aRZE6pYvO6VINv1Gd+LelJwSXAZOQut+64a9Fi5OQ1X+O Q6lKfy1O Abj5EGG3uUtECTxQ5eYlH6oHHHKm+B2IWd2vkqqYCtr9pXmNL3XnxMBYNvxbBRUOuVOO9LyA3S5GmoQJ2Hyo/FoH9OCXLCSw4uLzm70HphhHWofkbmHHCXP59PEe5evYbIMxFSFwwkR1ApE99LOfE+uqUAx7ynftNoU/WdWocpl2IhqTfrYgF3WYIYLZPZvNyi8aUKXqRn4uNeHVXtXF0JZTupDT9iySvHfBBF6Q5cQOViDqAHoZTbReCwGEj1JYuQYssfAnYblEdNKi/wS+xs0VG4HBcm+kJpFadWHaR/9DQYrCwZp7bEgqOsDuQyJKz1DMGAmI8emq0xWSV+TgSPntc62tsZvltuoRcXWKB/o0J7fzcCWz33O3cQejiOuB5dwUmZF+8cCXPKUa+/nEa7HpxsqPyrg35NCkHHVj6vQjXZ66bIKeXsRyi/FwN9MXgxihl2jtybhxpWI5Z3bvMhbikfbBAaG976PNWh2y+Ru6qP4ttJJ2FATMJjIX274//t/fHkOW63xTfc8VpR7SC6hyOvA== 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: There're a bunch of things that were wrong: - Reading uffd-wp bit from a swap entry should use pte_swp_uffd_wp() rather than huge_pte_uffd_wp(). - When copying over a pte, we should drop uffd-wp bit when !EVENT_FORK (aka, when !userfaultfd_wp(dst_vma)). - When doing early CoW for private hugetlb (e.g. when the parent page was pinned), uffd-wp bit should be properly carried over if necessary. No bug reported probably because most people do not even care about these corner cases, but they are still bugs and can be exposed by the recent unit tests introduced, so fix all of them in one shot. Cc: linux-stable Fixes: bc70fbf269fd ("mm/hugetlb: handle uffd-wp during fork()") Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- mm/hugetlb.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f16b25b1a6b9..7320e64aacc6 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4953,11 +4953,15 @@ static bool is_hugetlb_entry_hwpoisoned(pte_t pte) static void hugetlb_install_folio(struct vm_area_struct *vma, pte_t *ptep, unsigned long addr, - struct folio *new_folio) + struct folio *new_folio, pte_t old) { + pte_t newpte = make_huge_pte(vma, &new_folio->page, 1); + __folio_mark_uptodate(new_folio); hugepage_add_new_anon_rmap(new_folio, vma, addr); - set_huge_pte_at(vma->vm_mm, addr, ptep, make_huge_pte(vma, &new_folio->page, 1)); + if (userfaultfd_wp(vma) && huge_pte_uffd_wp(old)) + newpte = huge_pte_mkuffd_wp(newpte); + set_huge_pte_at(vma->vm_mm, addr, ptep, newpte); hugetlb_count_add(pages_per_huge_page(hstate_vma(vma)), vma->vm_mm); folio_set_hugetlb_migratable(new_folio); } @@ -5032,14 +5036,11 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, */ ; } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) { - bool uffd_wp = huge_pte_uffd_wp(entry); - - if (!userfaultfd_wp(dst_vma) && uffd_wp) + if (!userfaultfd_wp(dst_vma)) entry = huge_pte_clear_uffd_wp(entry); set_huge_pte_at(dst, addr, dst_pte, entry); } else if (unlikely(is_hugetlb_entry_migration(entry))) { swp_entry_t swp_entry = pte_to_swp_entry(entry); - bool uffd_wp = huge_pte_uffd_wp(entry); if (!is_readable_migration_entry(swp_entry) && cow) { /* @@ -5049,11 +5050,12 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, swp_entry = make_readable_migration_entry( swp_offset(swp_entry)); entry = swp_entry_to_pte(swp_entry); - if (userfaultfd_wp(src_vma) && uffd_wp) - entry = huge_pte_mkuffd_wp(entry); + if (userfaultfd_wp(src_vma) && + pte_swp_uffd_wp(entry)) + entry = pte_swp_mkuffd_wp(entry); set_huge_pte_at(src, addr, src_pte, entry); } - if (!userfaultfd_wp(dst_vma) && uffd_wp) + if (!userfaultfd_wp(dst_vma)) entry = huge_pte_clear_uffd_wp(entry); set_huge_pte_at(dst, addr, dst_pte, entry); } else if (unlikely(is_pte_marker(entry))) { @@ -5114,7 +5116,8 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, /* huge_ptep of dst_pte won't change as in child */ goto again; } - hugetlb_install_folio(dst_vma, dst_pte, addr, new_folio); + hugetlb_install_folio(dst_vma, dst_pte, addr, + new_folio, src_pte_old); spin_unlock(src_ptl); spin_unlock(dst_ptl); continue; @@ -5132,6 +5135,9 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, entry = huge_pte_wrprotect(entry); } + if (!userfaultfd_wp(dst_vma)) + entry = huge_pte_clear_uffd_wp(entry); + set_huge_pte_at(dst, addr, dst_pte, entry); hugetlb_count_add(npages, dst); } From patchwork Thu Apr 13 23:11:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210719 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 A5D99C77B6F for ; Thu, 13 Apr 2023 23:11:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E12B900005; Thu, 13 Apr 2023 19:11:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 869BF900004; Thu, 13 Apr 2023 19:11:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E2AD900005; Thu, 13 Apr 2023 19:11:31 -0400 (EDT) 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 5F988900004 for ; Thu, 13 Apr 2023 19:11:31 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3F2151A0476 for ; Thu, 13 Apr 2023 23:11:31 +0000 (UTC) X-FDA: 80677916382.08.A7297FF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 31B5D140011 for ; Thu, 13 Apr 2023 23:11:29 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QHbL/w4d"; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681427489; 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=sPrSeNO5Sj4btD4u1XV4AOohfTbtE2i2MNiZ002Yg6Y=; b=KK7+cNEJXaO0+l6kCRw2DO1j6bCYGSlKj3vDSaARNGZbNLpiU5RuhJ4xh/8/GEb8TPXQk3 PWA7IKgyuMIOs1hEW0NSA7G8cVfcz0H9G4qZGXLkL/pzsZun5ZR2SCZ1XKrItzt2M+b6ic 1efVhyaPzhGXAKqZU7J/GZ0v/KN1b/Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QHbL/w4d"; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681427489; a=rsa-sha256; cv=none; b=pmkrk4dbP/bDNwFkKHzl4X0ijf/V4/3sZ8YSlURGczSQt0MV3BRZY97uwn84e+oEnmJhvO 6QilWLorygY7giz4ZzfjwWpttMRm7q2M2cGOPXR+Ao7+VkuTRsp0+q9Fsd+glM1cIVtctF 2//x2S0pgYnxMdjUxpKDCPJr0HIp/Mk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427488; h=from:from: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; bh=sPrSeNO5Sj4btD4u1XV4AOohfTbtE2i2MNiZ002Yg6Y=; b=QHbL/w4dmvGxFeQLBb7JjktmB6rwN+AfJXZpHrDwAnrHLEnM7JPNTka5XJxEivFpaIniBJ 2hCrYpAB+3msNZEeX9o6sWPRmBlsYy1MlLzSGaE5Gm8sV6UTp+gV5/GyjcKFlU/Jdfm8Ts l9jS0wG33ssKUjVTvNZ43JAxojkM1lY= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-C3imq5NMNXCosO6WE6BdlA-1; Thu, 13 Apr 2023 19:11:27 -0400 X-MC-Unique: C3imq5NMNXCosO6WE6BdlA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74acff8cfaeso17907385a.0 for ; Thu, 13 Apr 2023 16:11:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427487; x=1684019487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sPrSeNO5Sj4btD4u1XV4AOohfTbtE2i2MNiZ002Yg6Y=; b=SpzgmfBaBB4fuWslNT9lM03LbOIraeFTez95nA1ONUKpgGx9XdoU1mA7UOnOj+94R/ pjmaJmB80iUUyJVvvlfY+R2eUrzHAgjIsxWE346QHMjlMzNfLp5beePDMAnBN5oZjZsK g9nubWqKsNMIiWXYEyltfizIMYmrOXrFXXKVO1RQCSYWv4nCiVFLL0XhtHx6PH52aOuj subFikkAVOwywW75H7BQ/j6hRqmx4My2UIeEr65Uq5Yf/dcWzPXQ53ntsiboIwoDaqad a4PIzWx60iLkJbmYR5IpH1eBMcfr/xJ0gVJ5gR891Zea189ncb+ezHf+9ofrCPZppbgK g0nA== X-Gm-Message-State: AAQBX9dVPP9btSasv7h7C+dgvrlpLSD5UkdZ7AqhMMNd8kdWQI4iSJ1L I+X5troNZNz41GAh0eSTX0XKAvl772NV5fSBlS1cKSJxi82t3XHfIIb8GhL17b3P45ikACr8RI2 SjV4XbfZbUkw= X-Received: by 2002:a05:622a:1aa6:b0:3e2:be32:cb74 with SMTP id s38-20020a05622a1aa600b003e2be32cb74mr1006397qtc.3.1681427486994; Thu, 13 Apr 2023 16:11:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ay1srzjNEubUa8Bu2M4QrSigXg05em6AqIPROuVf3uz6yCOvlGUBFyb0XrOhaExs1Nao5lxA== X-Received: by 2002:a05:622a:1aa6:b0:3e2:be32:cb74 with SMTP id s38-20020a05622a1aa600b003e2be32cb74mr1006377qtc.3.1681427486764; Thu, 13 Apr 2023 16:11:26 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g3-20020ac81243000000b003ea1b97acfasm612446qtj.49.2023.04.13.16.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:11:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , Andrew Morton , David Hildenbrand , peterx@redhat.com, Mike Kravetz , Nadav Amit , Andrea Arcangeli , linux-stable Subject: [PATCH 2/6] mm/hugetlb: Fix uffd-wp bit lost when unsharing happens Date: Thu, 13 Apr 2023 19:11:16 -0400 Message-Id: <20230413231120.544685-3-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413231120.544685-1-peterx@redhat.com> References: <20230413231120.544685-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 31B5D140011 X-Stat-Signature: y19q5nk7mwpjfyoyzg6hwho4jrcp4oo3 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681427489-777748 X-HE-Meta: U2FsdGVkX1+0OaGC+6YN+dgwJYALlQQWNkzKXwx9tZxRaBpcjTy2gXEyLxk+/C6al25kavnGMuQqwodGU2EtFTvlSScfZCt/CC2KdW9gt14QYbAKS+EMS6Uptb+Txb6F85kQNMSaAU4gOBwRi1aKqeMxc1HRcn4Hzq7mPDIYnhJ3c7HlsCcFCqY9vr5S0Lga7W2C4n+RxuaOb4NvCitQdSVcv1wCzLWJpUYWwz+mII1Ib+YrWIs2j5MfUdgV2ZDm4kTde/62H2vXZlK8V/a5EjEReGtb2ZMmA5JhOSwTcxnfemqYGq0SGZg6mWuq+ndL6+fn1GK/F22OS8E3V81QbwUZZd6eZkVAsO+DMpp55o4AnuAbdBIw/kGPrDKsv/i7ZW0Pw1bkg2XsME9j5b5R6u0WjaAfvynpfN+bGEXVTFreCoRdHGFBgUYrKNCAHyDeaDmR1yAay7+jznaTTnwFznTXmKre6faN/PDq8QkCNcgaMEoTMVQdKCoPhthsMUw7BTlDZoyGn0jn7XmEgpslaohCHuzCgUwiOqQlQrbOU8jnbAYhrdVtcHtiYhUyD0z6SFfDHPBaPyrkCeD5cNFFnwt+Lwygn5YRTmSBjijaFqevLinEk1Cn0Bqs2xID0hh4IzV/ck+fH7aBh9fjUudyYE0j7p2o9+0JoPf2oR0qlCEd1ytpyo3+qv/qJFVfm9t8qJL4JBHfaErbQUqJVE0SQmxO5mvLl7bjOH9dtkAKrC9DyNe2sOwSZnTsLh6T0T5XrOKvc5mkgbLp+ion6OkjFzAVkjOlS6LwXoWfmtrneX9PPDhAClV2/m6SLFaqhVNnRLuLl113XMkqAxg05mmbpOj9UVPXfQAKey12+9guyDeVufMlMslWw/wvu7DbuXnWqxTtqxGY70fPW8oz6j8drbt1gahHnB3ADOB1WjObHv9sGzE8DMh5TU5/+OFHsGUS8tRfiGG/26V7ic5lVaD 6L536Hwv zO0WggBUkTU4t68vM0QVjiZIBGQJThKr1ve0LgUnzKfTtSRkN5S87xrSUhwlRRJWdpHKgcoKs2Kx5b7iH1TdljVJTuvlNgyEiNQevIQdkzBjU+UEfb5XW0rdXB1ar+NXk9HeOgdCjvgpBhwMhFHI7e3sLtu8/ehoUfws9sO/Y/3UZ9cthlg9j9bWtsFj/60ZwV05pzTf2oZyCPYOer3cW620Pkri7+VtXdcg6I99+Jkf4K7kziIPbpqe73g9G8LSxAuh2hpN7oC9RuMaWOv4LfBsqH7eb6f+p/LUS5etIz1DX1Q58JMnFDsKMd8yRGk++azdHAZfScZnnTrnhqppV+My+f6yi6dk07VN59c0jqbCqGaSkWGnHvC9mKBRHaOt2NV2rF3f4Kj218wTkRw1D3o2c4QDAoTKDWKa9nHZUlPHeSl2K5rIPnTtw5C0FyYfDBy7XWddHiW+Ifv7OzK5q7NwXQ40AtAsyjoJ0WF34YH7+eHk075wALGIleqIqFbhSAPOIb2JzDihRiFsCT7xtfPZkvNaZDc1xEJcXQYVUGGxFqeHs825iijS2zoSft98O91mhu4MScrmUFNI= 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: When we try to unshare a pinned page for a private hugetlb, uffd-wp bit can get lost during unsharing. Fix it by carrying it over. This should be very rare, only if an unsharing happened on a private hugetlb page with uffd-wp protected (e.g. in a child which shares the same page with parent with UFFD_FEATURE_EVENT_FORK enabled). Cc: linux-stable Fixes: 166f3ecc0daf ("mm/hugetlb: hook page faults for uffd write protection") Reported-by: Mike Kravetz Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7320e64aacc6..083aae35bff8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5637,13 +5637,16 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, spin_lock(ptl); ptep = hugetlb_walk(vma, haddr, huge_page_size(h)); if (likely(ptep && pte_same(huge_ptep_get(ptep), pte))) { + pte_t newpte = make_huge_pte(vma, &new_folio->page, !unshare); + /* Break COW or unshare */ huge_ptep_clear_flush(vma, haddr, ptep); mmu_notifier_invalidate_range(mm, range.start, range.end); page_remove_rmap(old_page, vma, true); hugepage_add_new_anon_rmap(new_folio, vma, haddr); - set_huge_pte_at(mm, haddr, ptep, - make_huge_pte(vma, &new_folio->page, !unshare)); + if (huge_pte_uffd_wp(pte)) + newpte = huge_pte_mkuffd_wp(newpte); + set_huge_pte_at(mm, haddr, ptep, newpte); folio_set_hugetlb_migratable(new_folio); /* Make the old page be freed below */ new_folio = page_folio(old_page); From patchwork Thu Apr 13 23:11:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210720 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 1B092C77B6E for ; Thu, 13 Apr 2023 23:11:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB48D900004; Thu, 13 Apr 2023 19:11:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3D73280001; Thu, 13 Apr 2023 19:11:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B757900006; Thu, 13 Apr 2023 19:11:34 -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 7D167900004 for ; Thu, 13 Apr 2023 19:11:34 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4CEEF1C6100 for ; Thu, 13 Apr 2023 23:11:34 +0000 (UTC) X-FDA: 80677916508.11.D696AB5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id EB97A4001E for ; Thu, 13 Apr 2023 23:11:31 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Bs3bSm5s; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681427492; 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=VlJAJroC0qfUjlayNMIBwxZydfuRD55bTGjabDZPAD4=; b=LZcaRILHsoWqYdOiDLVR3K5OP7MBRTaiXrXyRvzVObyBfrVp2i3n1E95LozeuMtg/3eqR2 Dk3mtMF4ElVqhEJELcJuTrp10bUvnrgxNJeLrNSXbQxIBrFgCEPOyLiLhK0HBjPHkD4FsK MK8rTHsBBbZXFEePPLAQqF3oY5W/mcA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Bs3bSm5s; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681427492; a=rsa-sha256; cv=none; b=QUCUsj9fanrh+fc8FbpgerF6aU+EAGxhvpmGg+4Myk5ALVERyjKNjrGiugGER7BWjmLNZQ MajdiUYlqtzAnA6JflB7Gj1gPIaoe5nt5phcGAKT9FpF2rOkIfYiN4SYD/bzQOiGbHLrKy Zb9KVT1LK3VIlLMNlu5VDjZCdd0aTP8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427491; h=from:from: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; bh=VlJAJroC0qfUjlayNMIBwxZydfuRD55bTGjabDZPAD4=; b=Bs3bSm5sgWADy+7brHUZo3b7Ue5nyWpm1wQP/ExIT4Gm/dj0y22eMQlnThhXR+WXylsdzw yIYwj/3iw8psFx/b9YYbvXmBpQHP2uMlH7VCDa/X2FApHDJnL4YdgsywLHxOVVBuK0mw3+ OCxu9GHrQE1mGie3uWQqeaa0HoE7RYE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-287-QbDtX7TNPzyj--sHkPD5Cg-1; Thu, 13 Apr 2023 19:11:29 -0400 X-MC-Unique: QbDtX7TNPzyj--sHkPD5Cg-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3eab4df3ef0so822571cf.0 for ; Thu, 13 Apr 2023 16:11:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427489; x=1684019489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VlJAJroC0qfUjlayNMIBwxZydfuRD55bTGjabDZPAD4=; b=hsgnpNTe6Yx1fPVurV8ui0qSzMoWf02flZtHgs5yxZGOOeQSGyuBQ0jY/+Y/4xlqBZ KkaUdBSjjPqT5f0OF5idFMylgIRgEI5Njs/AquIbbHK9gTm8lt8QTkNN14VfTn74heVX 3nKjOFSJKGMzb31MmPwa6Pudo5kLwUJdBYsxkzjmxMf/WQTX+BWAH3GfWXFXDGXbrksu hnGM8GFuOgpn7jE4N7XRsBxUIdyT14EQsJNH+oq67djJ7Z4kB3a4opqM+eDMvrZGOvVA bKyjFmY/m7O2u7A9lGR+LTkhwdvwqGX10U4588NTnsfq6Ov0p9TfuXq2RLfaP+dSBojL o2pA== X-Gm-Message-State: AAQBX9fJmpLnkHqm4OmV2jj0rBwac5S3DCRb6urypUaoIh8x8Wbcghxm PsCXOVhR7XzNFJZ0GlUHoQMWbsZ2+GfOTb6WvcTZAGjr5DykLKq5wRda6W2sUODpkR/iEjRuDA/ ZcaJZ9Cyohyc= X-Received: by 2002:a05:622a:1a0b:b0:3e6:3af1:de7a with SMTP id f11-20020a05622a1a0b00b003e63af1de7amr979927qtb.4.1681427489497; Thu, 13 Apr 2023 16:11:29 -0700 (PDT) X-Google-Smtp-Source: AKy350an97YBpu5VR+5rQ8BpvcSWa0qXKTYAqU3oGcgNxCkPHbBxgc6lQQadGX+kjho8InyBO8r1YA== X-Received: by 2002:a05:622a:1a0b:b0:3e6:3af1:de7a with SMTP id f11-20020a05622a1a0b00b003e63af1de7amr979903qtb.4.1681427489278; Thu, 13 Apr 2023 16:11:29 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g3-20020ac81243000000b003ea1b97acfasm612446qtj.49.2023.04.13.16.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:11:28 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , Andrew Morton , David Hildenbrand , peterx@redhat.com, Mike Kravetz , Nadav Amit , Andrea Arcangeli Subject: [PATCH 3/6] selftests/mm: Add a few options for uffd-unit-test Date: Thu, 13 Apr 2023 19:11:17 -0400 Message-Id: <20230413231120.544685-4-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413231120.544685-1-peterx@redhat.com> References: <20230413231120.544685-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: kkwk19eox46u9afsyfd9p936e934qou4 X-Rspamd-Queue-Id: EB97A4001E X-HE-Tag: 1681427491-798209 X-HE-Meta: U2FsdGVkX1+swXFkBaAWW0rJEfwunpseRj1+JDhXr1Q1Hmz4YbozB1j+WJ/aptQ4V45+leOhI+RISZOG2yuhRGW2XkaJkbkYUXZYvDBvut/q6f1AVrdMkSJQ7gxknjdYqbOt/sLfvK0TNUGj4TJBts3OHm3T0OdTpdkVUHEHyyOMwZjtQJ9ilS3m02VtGrN/awauYKNzvkOByrNsXZbgcYLxxdcJf9O1mH9ieNbu4SaRKhDVLFIsSy69+MpMuhBVH76HtsdsTyEkGktfPO5feodsDlSxhgf0U4Q5C8aR0wwd1+rJP43QSvCjYDGvU0RGp97eA0DcVicAJr2wNMH88nrxKgCP+6csaAoK3sG5DsDq1BD4gy/Mn62vQX7GxUlcEnHV4JRdBGkV/oKiVsqEvv1bLce5nQl77iEe28wTrAwCl64UgOHBHdAPQE45kJsfPwDXFaQgy/Wbwi0RtkcLCCSgwH2DvcZXo1/In3mekPzcA4/V3MAhLFLr4vTf+ubjnsSTEf/ufj/6AVYbPiwa7XVm5bSwXJ1EY6THmwBl6071b2CwOWIaIBQPYECJzhkoGIPGnKoqXO9Gx+Cuk/SBz9K1HXypxRYpCStyJPxMMvSiKrz4CirzrhE2fk1x8bSEUJI63cC6C8lozaSaZzrdSrEVvtYHPo8oZIAQZX1+mWVOPrVfyK7CHVXSfn+HrfuVc4htI2pcKeFwgfCzSxAWkU1RurygZ+Ao39fAZdWAAGoiPu1i5EicoNWHW7VQGNq0WXxBWNZuycSZfZHIpmcb3BJ9hQN+aCzBpv3dmtUqd4GyIelTs//a0CWHUz9gljUe5QI5f0m1LUjZUyuwk2qKJ8GSJSG2jiIG29+RJ0yNsnlLQ7vlN5MdvFdeoqXR1sVmaBAogjg9pokjp8oLLxwzyA6yvssS8Ja51mm27TxM9ivn44TU+itRKhstUpDXEM2hn3r0UErOpuS2i7+WXQP X22BPilv tM7f6Ebd1yM+3dSNfDVETug4EWfQBm621Y+WF+HVjxmqhm+LVZ/D4KQL9TO9uerMBl3C00+OdGOW739Sofk1Bq2HVHwTok8sFwZ3j9QRKVsvb+r2prj77cOzPsf/++FeRvAWCdP1++lK0ZUXPffSKYDiGV3QN7FSrVIBFsYiSCIt2UxWLxF0WxdK70m1r4t3ulncbtra7vSjj4L5/yhJDHv3wovJmYg+1pdCWxYcq7nlo3MJNRbNbRjHCGmdd8/IuySgM+MayJmIeby9VBqr4bcxh7AFzSKhCEvnXbDdDlV3WFfTtKTJv1kZXPu2RUTHRjrIjuAe+y0hrYscYpTk/KFcEM/WiVsv/U+bc9CCVgYfKDc/8Mo384umyunHmsmLwObnSj2I9Z3sit/cxl6ViiT/PXWc2SJMYjlJMQwJnPgxhYWVyDy2YMr/kvZplW/ckdki2vWyK3+XfsiCBvSGZ4FnixwnhjO8ti/1kT+Q+v2qVmvQvnT5JLbKF5lHaoLQABHWW 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: Namely: "-f": add a wildcard filter for tests to run "-l": list tests rather than running any "-h": help msg Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 52 +++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index d871bf732e62..452ca05a829d 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -909,28 +909,65 @@ uffd_test_case_t uffd_tests[] = { }, }; +static void usage(const char *prog) +{ + printf("usage: %s [-f TESTNAME]\n", prog); + puts(""); + puts(" -f: test name to filter (e.g., event)"); + puts(" -h: show the help msg"); + puts(" -l: list tests only"); + puts(""); + exit(KSFT_FAIL); +} + int main(int argc, char *argv[]) { int n_tests = sizeof(uffd_tests) / sizeof(uffd_test_case_t); int n_mems = sizeof(mem_types) / sizeof(mem_type_t); + const char *test_filter = NULL; + bool list_only = false; uffd_test_case_t *test; mem_type_t *mem_type; uffd_test_args_t args; char test_name[128]; const char *errmsg; - int has_uffd; + int has_uffd, opt; int i, j; - has_uffd = test_uffd_api(false); - has_uffd |= test_uffd_api(true); + while ((opt = getopt(argc, argv, "f:hl")) != -1) { + switch (opt) { + case 'f': + test_filter = optarg; + break; + case 'l': + list_only = true; + break; + case 'h': + default: + /* Unknown */ + usage(argv[0]); + break; + } + } + + if (!test_filter && !list_only) { + has_uffd = test_uffd_api(false); + has_uffd |= test_uffd_api(true); - if (!has_uffd) { - printf("Userfaultfd not supported or unprivileged, skip all tests\n"); - exit(KSFT_SKIP); + if (!has_uffd) { + printf("Userfaultfd not supported or unprivileged, skip all tests\n"); + exit(KSFT_SKIP); + } } for (i = 0; i < n_tests; i++) { test = &uffd_tests[i]; + if (test_filter && !strstr(test->name, test_filter)) + continue; + if (list_only) { + printf("%s\n", test->name); + continue; + } for (j = 0; j < n_mems; j++) { mem_type = &mem_types[j]; if (!(test->mem_targets & mem_type->mem_flag)) @@ -952,7 +989,8 @@ int main(int argc, char *argv[]) } } - uffd_test_report(); + if (!list_only) + uffd_test_report(); return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS; } From patchwork Thu Apr 13 23:11:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210721 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 B0E8BC77B61 for ; Thu, 13 Apr 2023 23:11:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49B1D280002; Thu, 13 Apr 2023 19:11:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 424D6280001; Thu, 13 Apr 2023 19:11:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29ECB280002; Thu, 13 Apr 2023 19:11:36 -0400 (EDT) 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 1C424280001 for ; Thu, 13 Apr 2023 19:11:36 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DA919140497 for ; Thu, 13 Apr 2023 23:11:35 +0000 (UTC) X-FDA: 80677916550.30.10ABF76 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id B5CE218000E for ; Thu, 13 Apr 2023 23:11:33 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JuIvPqfd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681427493; 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=PiB4O8c7FzfgLpxlGuxco4WipLi6p7uHP+fG5udokS8=; b=Cj8IkuyftFS4nNtJVxOzgDd0ZAbstFz3mPgyDW94Wyq6X/JHYcNmAge6KXc5+9AlZpk+WG 4V6QaO5TZPYzpKhr3+LxcnNn6em41FhPanZn8w94eMfWHZHJCy7j0xWBp8yAu+Q3byeeQf FBzoPrcFyRF7uNFYB+/CVK/Dnkbn++Q= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JuIvPqfd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681427493; a=rsa-sha256; cv=none; b=f37A9CYi6wYIV+Z2nOP+xPZjDG0B3LEq/UYarcIk/JBtenbw6CPhKmyGAvtoyPmCf10P5p qp/M3/ymXssdb5rb9bssLfhQjLrRzkQRR2jQSfLvmji+EOdzahhNn64ym2AMgshafNEmuE uWs2BiA5OGhpUGVQVx0FKJyVJCafsHc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427493; h=from:from: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; bh=PiB4O8c7FzfgLpxlGuxco4WipLi6p7uHP+fG5udokS8=; b=JuIvPqfd8MUj3XlrvhNJ04Ljv3pgjIq2eZOtSwqcS6dPe3qBCLCxuRJTv7gO4fEoJmNrC1 l47Y7bHmfzLf7UTPOqIxr0xuP3uPoexl644XjMViNd77Pbq/6sTD22cl+hwajGXuoVFJt+ VOqmgeiZiVTxUrIRF+Qrh1CPKI+dKN0= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-fBPtmP9ZN960Wx1xecQKKg-1; Thu, 13 Apr 2023 19:11:32 -0400 X-MC-Unique: fBPtmP9ZN960Wx1xecQKKg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3eab4df3ef0so822631cf.0 for ; Thu, 13 Apr 2023 16:11:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427491; x=1684019491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PiB4O8c7FzfgLpxlGuxco4WipLi6p7uHP+fG5udokS8=; b=mDDmaaqpZNV+xeFc64MlOXQWbWzczNYbCJG0aBdcbLqowyZ4CmViYRIieryAF5v6Hr t+/cYp15364kMoswzqApZLaJrn0rfB1/IZdnoVSEHL7AL3qWyjkKk5Kxo6NTNctacQqt arANIoTYGCrvSd+LsRkRPsa58S2khyooFFYzLF2UhGg+4xgSJB/GONnyZ6BmcNZ3zqPI XXk/D1QPzIVp02xctVCgFTVuhv7UYa25bGO65Bh2vwA6na0S/ZwdVQnTsx21KvmpcR9L sA+dhYzHN9HlZMFYcLsaQR5EePSZVlxkYhfAP6JzkTFeTyqRhQI8mvVu1fIIgYce8qla yw7w== X-Gm-Message-State: AAQBX9fkoDhBTWvNlb7BZYj0ulGcDTkBx/t8R28DOzIOccV2XGKq4PUE 1vZVJyjKrBTuCHpo15LFmAg2b+IfwMiWd+qwFfBCLpESBWTzVjmYP0JvoHmt+WTtGd2ID4E1vHI /OmGKtuy2alM= X-Received: by 2002:ac8:5813:0:b0:3e6:707e:d3b2 with SMTP id g19-20020ac85813000000b003e6707ed3b2mr1243716qtg.0.1681427491441; Thu, 13 Apr 2023 16:11:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YVqAYBJtjYRo4m3UT95yOx2hm06W56ReVZ3RTAjywmwDlKXwFvUxElkGFKWsmcn3tNMj/n2g== X-Received: by 2002:ac8:5813:0:b0:3e6:707e:d3b2 with SMTP id g19-20020ac85813000000b003e6707ed3b2mr1243678qtg.0.1681427491125; Thu, 13 Apr 2023 16:11:31 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g3-20020ac81243000000b003ea1b97acfasm612446qtj.49.2023.04.13.16.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:11:29 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , Andrew Morton , David Hildenbrand , peterx@redhat.com, Mike Kravetz , Nadav Amit , Andrea Arcangeli Subject: [PATCH 4/6] selftests/mm: Extend and rename uffd pagemap test Date: Thu, 13 Apr 2023 19:11:18 -0400 Message-Id: <20230413231120.544685-5-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413231120.544685-1-peterx@redhat.com> References: <20230413231120.544685-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: B5CE218000E X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: oqrpp896481ebinx8xo6wqf3mwsox738 X-HE-Tag: 1681427493-806514 X-HE-Meta: U2FsdGVkX19FYPX0XfhtAQQAZHPHH8e4aiTNsZWW8whLiI6l0YmPXXHmXofq+V05752zbz0Ty13O/I+H0qqKOywjxwjgARZxzLnTphMp6tbsfjLrWL9CWDh5XAIuAFsnNvooEbCaNA7tdainkrRb5VbuQDBihRAW7MKeQbVpZSZibrYxBnSogrlMGD9wDkPBc3QfwCykhnVdgVvan/hKMLGhgfqHrpjL5SC4tTWmeo95C3LzEaG3U9q6cXw/ZAJfPE/Eg1U2XmzGlryTx4smGq5T07O2dROp6SW9wgr06DGw7yg+5LhS2MoprYlRIAgGR92Cf5B4cjDeTX5lRUBGegU2FP7zYgDL34hNyQRhWHbtnLMhAx8hW4AzGMJ2+aYtOLJrDl6OH7WvX+CkdCdQ4gMwlTOGBqtZfM4l1Bhv5JOuaXqaEpB2PNTMe9njMcJ5HGqmwWegTc07l+kX+kxO4ujYMGWh6F416emsDaJgrrKsD2081elrwKWQSo06vreLVMlujGCuiT4KcbddvqA1dQAfpEShoADERsVT1BQTL9RC9yqsOSDJ5DbwB+Um+G9OQXClIWM4MTFhhsRg4D/M8QxBbgjYK0zgT5/zE0rNTpf0t7Ey0VzF3BiO3F3EzGrWVfi3ytb+M7gw2Acijr82bU7MBKhP9l2n0xAY9rd3pFPOvft+G2/tKGsDNODceOxRfjRBnJXIuq9DbrNjQM32GyGj71TVWNUu4VATQyTh50jrR+7IPWpMIMghFSTFAdefr3dFPOO0mS5dFmP334DU4BeeyKWfvV0z7DkNMmXamMsK8DKIclcub2YttQQX4X+7UUJPuc6/6s3YVU8tJjbXhQ4WS4oQ7ucPn+JYjoziUr4gGxFf0Ix0Cns1+0wcTPZAkKlBWOJxQ0iNY1PNQhfmZHdhfVdWMhlHo495XIsSUo2t+CvXPl1Xb/FKRfeeZLDQ38wbHVDeWQVGs37zpZQ WY/FxDah ciVWpZZBPb1tC9jdkRnR5SD/W47AIvMS6ZEk6fjyyjCAq8sW19uG2ieKhpcaY3FdbkGSPU0UJ1B/+BEcYaZPev+s70csmRSRTBTycsbOHazgpsU/Shv+vw9A86mbWtNlA8tLhsDOzcxeaok3WrIdYSR3R6gDnHAIvu4LSkN0SN+SFPO5CnVuGdRg/6c3AYkc4uBUMB2yfkrnJrejNo9SwUl+jVia4M2VuyT7mr2fD1HsG/MrF7Vbo82XfPDJo0hSVaceeaEy6TzvkEtVDGzuzdvwq7DXAEt6huTxbaiC7U2K/2tNN0NLEZn1LdVfoS6d+wPOsG0Zx2L1q6bYOKl3zS83/YL/xjGzKHjFUN2RZ0+0ft4VtqBxPEAzBH732aeozJ77qJPhrgf+lgD2YmiEQsAu+sHCbiibvfglZhN4MkuIjHUjSQcwMsepcdjtjhID66pj/U1gq3sl30DrXt1Mtyf7pZ6BQCTWDek0g 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: Extend it to all types of mem, meanwhile add one parallel test when EVENT_FORK is enabled, where uffd-wp bits should be persisted rather than dropped. Since at it, rename the test to "wp-fork" to better show what it means. Making the new test called "wp-fork-with-event". Before: Testing pagemap on anon... done After: Testing wp-fork on anon... done Testing wp-fork on shmem... done Testing wp-fork on shmem-private... done Testing wp-fork on hugetlb... done Testing wp-fork on hugetlb-private... done Testing wp-fork-with-event on anon... done Testing wp-fork-with-event on shmem... done Testing wp-fork-with-event on shmem-private... done Testing wp-fork-with-event on hugetlb... done Testing wp-fork-with-event on hugetlb-private... done Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 130 +++++++++++++++---- 1 file changed, 106 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 452ca05a829d..739fc4d30342 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -227,25 +227,65 @@ static int pagemap_open(void) err("pagemap uffd-wp bit error: 0x%"PRIx64, value); \ } while (0) -static int pagemap_test_fork(bool present) +typedef struct { + int parent_uffd, child_uffd; +} fork_event_args; + +static void *fork_event_consumer(void *data) { - pid_t child = fork(); + fork_event_args *args = data; + struct uffd_msg msg = { 0 }; + + /* Read until a full msg received */ + while (uffd_read_msg(args->parent_uffd, &msg)); + + if (msg.event != UFFD_EVENT_FORK) + err("wrong message: %u\n", msg.event); + + /* Just to be properly freed later */ + args->child_uffd = msg.arg.fork.ufd; + return NULL; +} + +static int pagemap_test_fork(int uffd, bool with_event) +{ + fork_event_args args = { .parent_uffd = uffd, .child_uffd = -1 }; + pthread_t thread; + pid_t child; uint64_t value; int fd, result; + /* Prepare a thread to resolve EVENT_FORK */ + if (with_event) { + if (pthread_create(&thread, NULL, fork_event_consumer, &args)) + err("pthread_create()"); + } + + child = fork(); if (!child) { /* Open the pagemap fd of the child itself */ fd = pagemap_open(); value = pagemap_get_entry(fd, area_dst); /* - * After fork() uffd-wp bit should be gone as long as we're - * without UFFD_FEATURE_EVENT_FORK + * After fork(), we should handle uffd-wp bit differently: + * + * (1) when with EVENT_FORK, it should persist + * (2) when without EVENT_FORK, it should be dropped */ - pagemap_check_wp(value, false); + pagemap_check_wp(value, with_event); /* Succeed */ exit(0); } waitpid(child, &result, 0); + + if (with_event) { + if (pthread_join(thread, NULL)) + err("pthread_join()"); + if (args.child_uffd < 0) + err("Didn't receive child uffd"); + close(args.child_uffd); + } + return result; } @@ -295,7 +335,8 @@ static void uffd_wp_unpopulated_test(uffd_test_args_t *args) uffd_test_pass(); } -static void uffd_pagemap_test(uffd_test_args_t *args) +static void uffd_wp_fork_test_common(uffd_test_args_t *args, + bool with_event) { int pagemap_fd; uint64_t value; @@ -311,23 +352,42 @@ static void uffd_pagemap_test(uffd_test_args_t *args) wp_range(uffd, (uint64_t)area_dst, page_size, true); value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); - /* Make sure uffd-wp bit dropped when fork */ - if (pagemap_test_fork(true)) - err("Detected stall uffd-wp bit in child"); - - /* Exclusive required or PAGEOUT won't work */ - if (!(value & PM_MMAP_EXCLUSIVE)) - err("multiple mapping detected: 0x%"PRIx64, value); + if (pagemap_test_fork(uffd, with_event)) { + uffd_test_fail("Detected %s uffd-wp bit in child in present pte", + with_event ? "missing" : "stall"); + goto out; + } - if (madvise(area_dst, page_size, MADV_PAGEOUT)) - err("madvise(MADV_PAGEOUT) failed"); + /* + * This is an attempt for zapping the pgtable so as to test the + * markers. + * + * For private mappings, PAGEOUT will only work on exclusive ptes + * (PM_MMAP_EXCLUSIVE) which we should satisfy. + * + * For shared, PAGEOUT may not work. Use DONTNEED instead which + * plays a similar role of zapping (rather than freeing the page) + * to expose pte markers. + */ + if (args->mem_type->shared) { + if (madvise(area_dst, page_size, MADV_DONTNEED)) + err("MADV_DONTNEED"); + } else { + /* + * NOTE: ignore retval because private-hugetlb doesn't yet + * support swapping, so it could fail. + */ + madvise(area_dst, page_size, MADV_PAGEOUT); + } /* Uffd-wp should persist even swapped out */ value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); - /* Make sure uffd-wp bit dropped when fork */ - if (pagemap_test_fork(false)) - err("Detected stall uffd-wp bit in child"); + if (pagemap_test_fork(uffd, with_event)) { + uffd_test_fail("Detected %s uffd-wp bit in child in zapped pte", + with_event ? "missing" : "stall"); + goto out; + } /* Unprotect; this tests swap pte modifications */ wp_range(uffd, (uint64_t)area_dst, page_size, false); @@ -338,9 +398,21 @@ static void uffd_pagemap_test(uffd_test_args_t *args) *area_dst = 2; value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, false); - - close(pagemap_fd); uffd_test_pass(); +out: + if (uffd_unregister(uffd, area_dst, nr_pages * page_size)) + err("unregister failed"); + close(pagemap_fd); +} + +static void uffd_wp_fork_test(uffd_test_args_t *args) +{ + uffd_wp_fork_test_common(args, false); +} + +static void uffd_wp_fork_with_event_test(uffd_test_args_t *args) +{ + uffd_wp_fork_test_common(args, true); } static void check_memory_contents(char *p) @@ -836,10 +908,20 @@ uffd_test_case_t uffd_tests[] = { .uffd_feature_required = 0, }, { - .name = "pagemap", - .uffd_fn = uffd_pagemap_test, - .mem_targets = MEM_ANON, - .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP, + .name = "wp-fork", + .uffd_fn = uffd_wp_fork_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM, + }, + { + .name = "wp-fork-with-event", + .uffd_fn = uffd_wp_fork_with_event_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | + /* when set, child process should inherit uffd-wp bits */ + UFFD_FEATURE_EVENT_FORK, }, { .name = "wp-unpopulated", From patchwork Thu Apr 13 23:11:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210722 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 7C352C77B61 for ; Thu, 13 Apr 2023 23:11:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16512280003; Thu, 13 Apr 2023 19:11:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 115F5280001; Thu, 13 Apr 2023 19:11:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1FBA280003; Thu, 13 Apr 2023 19:11:41 -0400 (EDT) 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 E417A280001 for ; Thu, 13 Apr 2023 19:11:41 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9E89B14045E for ; Thu, 13 Apr 2023 23:11:41 +0000 (UTC) X-FDA: 80677916802.07.EEF1F07 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 04DF340017 for ; Thu, 13 Apr 2023 23:11:38 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="UQo/qbNM"; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681427499; 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=UrLvr60huy61e3psoajwIv3A4LyU2VRqVkvYCOVTv4c=; b=JhRw8SeqcLJdNQgwZeqK+HXtdmIwqg9mayw5ycpLvNRMjsKPS0/NqlXpBP3Xqqt+VuviU/ 2kjBipSxe1YMggYoA25pLgHrIeeC6DlRFDwfI+hNeHSWce5y+AkOLqrGLCVTei1Qkclykh KfiGOZE8UifqGrbHVNPGKOIt3DYbctI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="UQo/qbNM"; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681427499; a=rsa-sha256; cv=none; b=cG/DIE1VQHfLMr+i0ri1q2h2aEqmwbVJ1y1sO9OabYWKZrVFNVVpzUwdMyjpgRN03ZDctR Fc1qoV+9JOR0aWEYYE8mR0ShfBBOLwYyN2ljm0xGVzXupx3p7gB81sQogKrLV7DyaOCCu9 A76gTaHuGEW6/MA/fm0Ubz7lPgkdchc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427498; h=from:from: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; bh=UrLvr60huy61e3psoajwIv3A4LyU2VRqVkvYCOVTv4c=; b=UQo/qbNMePPZCysoONYr3aHzH9ZXTYwsMcJChlKP8uxgRYJfspZN6c/kfp0SG9jbatqoXq MLRTUOEm+ZfoE8STyo0gyiHxPrn9XjLykFkM8uFVl09dMPnFFr9EVHvfxG8UMkaFdTZYFt xhRW58NVH02bzDOUYyWfFx2ljX4PgyQ= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-5tB_KRW8Noy4J9axxuxzhw-1; Thu, 13 Apr 2023 19:11:37 -0400 X-MC-Unique: 5tB_KRW8Noy4J9axxuxzhw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74acff8cfaeso17909885a.0 for ; Thu, 13 Apr 2023 16:11:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427494; x=1684019494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UrLvr60huy61e3psoajwIv3A4LyU2VRqVkvYCOVTv4c=; b=YM/NDLbbrURTKP59+Bxf1U8kvYI5hmm13kzN6q9m6agBFdMW2tjYQPj/w9FrjPcteZ J4aE/EZ8Tif0FBP7M/mcbNigoNf7uIJc8a5W+bi7zYNGOe+UuWDIgCs5qVOuWArxb/HK mVKBc8cKQcf+KEG+A4gR67VNibSFI/A9MRDsMjyHVBlpZqeYI0NIaKWvyyywHn2har/V q9JC68RAny7DDyhq9T7WjUnsrp8g4n2jQvI5FbrDf1VQcWocqWANKey+2rSV9vhfgpMp +S5MkYs+i1xyGBStMVJ99/nS7V8Z0M2QJSdhVtXSE+k+GFXAWPrHlQuyk1JNienxZYsZ Wklw== X-Gm-Message-State: AAQBX9etXXvDNHC/vHyncgDTbBlYfg2kzlSvSmnxVsnL7rjmopV8AEs0 Ja3qcvi6MvRncL3g6DsQ9XbAknODd/cddCjmgXiy8ZwqkbNztyRwKXPZCeJQb7l3edZ6Iy8N2oL i2N9Chvr2c1U= X-Received: by 2002:a05:622a:19a4:b0:3e8:e986:b20b with SMTP id u36-20020a05622a19a400b003e8e986b20bmr822633qtc.6.1681427493741; Thu, 13 Apr 2023 16:11:33 -0700 (PDT) X-Google-Smtp-Source: AKy350YyNQPwspj+xj10BFWcJDwoT/zFUFT3us77X7aynWNJPLGIpmq+EZfsiE/QhH18vpRqiooHtg== X-Received: by 2002:a05:622a:19a4:b0:3e8:e986:b20b with SMTP id u36-20020a05622a19a400b003e8e986b20bmr822605qtc.6.1681427493424; Thu, 13 Apr 2023 16:11:33 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id g3-20020ac81243000000b003ea1b97acfasm612446qtj.49.2023.04.13.16.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:11:31 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen , Andrew Morton , David Hildenbrand , peterx@redhat.com, Mike Kravetz , Nadav Amit , Andrea Arcangeli Subject: [PATCH 5/6] selftests/mm: Rename COW_EXTRA_LIBS to IOURING_EXTRA_LIBS Date: Thu, 13 Apr 2023 19:11:19 -0400 Message-Id: <20230413231120.544685-6-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413231120.544685-1-peterx@redhat.com> References: <20230413231120.544685-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 04DF340017 X-Stat-Signature: bitxamncn53xhsac44zoiu1a8kzn35nf X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681427498-129109 X-HE-Meta: U2FsdGVkX19hr8OYAJ2ZryVp92eY0P0j5uuxI6qk+6J54IpnH0is3NQ9UU9cffpcV5ZMH8A0G9FiV+XrRmAyDYzTGiyNCkExeEBfgrngCYJhi9QXk3PGxsAdjg1drml00La5K3LLnnqxV2lKw/5IAm1c6BPAE1abZ1e5tMegIg+Saah441hAn9e74FSUxk2OTSyaGZ54QidQZ/2hsvu2yiu+Xf6Ph/OxzcY5YCWuqnf/D8Vj35dYBDzPlfQKvk27da1NOwbxtEb5jl82T8G/PpMfsyHjdSJ6OCLCNsrlCF6quYGWaN9pEFmlx5+/l068PkUOBHciYbBd/Nr47k4kJtOl4w23YGC9c+ZmDvHBDA/WkHtoPbMgtwxqsoQTUOdcs777fGRoRC82/QVXWgOAwkhVWMJcS7xNKwpe2JPmraudCn1Vw2p8I2VX48aGeUUHZgrfelkr54BxosjQQDJ4jcSDRVAj8rjAqBHwk5+lIcdQa3h6ELIY3U4m0kbWrahJEYfWDsz+o9y73bKL4qcjvMXNStZJ95oTjHpMC7ig0nNOhx3+BkWKyJu9TD8FyPi0g8biZ0PFUyKXJFOj11flo+ykjobv1xpQDlOfxmKboPn3YQ/POuMA5ulj687vm8hmk6bGlhk/BadIU5ZumpP1b9KVZUvefcsGD2PG/9WyIiWO5wiP/cBfG4731y6KFNg+8rH9UwfNcphVNdjFioz7ILQVaZKcZ8hQ3OocnO4v3Po6SjmgGYLM7bu/SeSHp5V00LixYj5xpbrWuLxv8goiYZoSCKWrFkyk9i92rhe4dttVocCdoyysXDcAHt7hZpB0RL5umQeWtZfstGnwgAd/z5Guvb45nU+HjlydBUyJAZ1i2qD/CaJ6Cre9z9bHhYsqSiw4mP36T3UzJ+xYX0PBHRKabAabw23SGgMSNLVUya3TiZk+OydSsw3gtjy8p570e4MwnywE4E95wAj2cf6 plhXCK03 TNQ9Ti+UGSOu5KobYnWondxDFLTTOOSjcETfzrL+EaXgtZAxwZdxshbQ2NyQpED1Sreh4riXkxaO5lptJnTxofzDLxd1piGgAtx26fJMo98RVloli+FdMQD8IB2KYmQ7iqy2p+ByHEkYpiSr+67WJpHRdNSEAHfJY1a2CUSKq50cvDt1YQoIfeFCxNYU5t/lpySP4QuoSReLicg1umUoQc/wv45Ue1vaNhF37yRovXLTBj7d1YtMm5DawzR1OcWPgAQNsbMFyfB/681FpQfQs5dflcNP5+qK//AElE6LtL93iC8xEUMQfS2EKv4UuZqKlVJPXa4mtGhUTW4Bo0+HVuojmzJzdezmJZBriC+CEHYo2olxeUP32+bij4GLR/Wz1AIxYjBZz8ddLIZJndm3N0MosRzV88+RfdJAa6oUV+WaTgucOZxG6vfQ2DSVtNOA1vya4KQBrF7EeKamV2hTco042zx4LzRHpezn+d7zjpqhrBz8IDyOg+lfulaRg2+W54WMP6HkTBw5MC+c= 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: The macro and facility can be reused in other tests too. Make it general. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- tools/testing/selftests/mm/Makefile | 8 ++++---- tools/testing/selftests/mm/check_config.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 5a3434419403..9ffce175d5e6 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -161,8 +161,8 @@ warn_32bit_failure: endif endif -# cow_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. -$(OUTPUT)/cow: LDLIBS += $(COW_EXTRA_LIBS) +# IOURING_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. +$(OUTPUT)/cow: LDLIBS += $(IOURING_EXTRA_LIBS) $(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap @@ -175,11 +175,11 @@ local_config.mk local_config.h: check_config.sh EXTRA_CLEAN += local_config.mk local_config.h -ifeq ($(COW_EXTRA_LIBS),) +ifeq ($(IOURING_EXTRA_LIBS),) all: warn_missing_liburing warn_missing_liburing: @echo ; \ - echo "Warning: missing liburing support. Some COW tests will be skipped." ; \ + echo "Warning: missing liburing support. Some tests will be skipped." ; \ echo endif diff --git a/tools/testing/selftests/mm/check_config.sh b/tools/testing/selftests/mm/check_config.sh index bcba3af0acea..3954f4746161 100644 --- a/tools/testing/selftests/mm/check_config.sh +++ b/tools/testing/selftests/mm/check_config.sh @@ -21,11 +21,11 @@ $CC -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1 if [ -f $tmpfile_o ]; then echo "#define LOCAL_CONFIG_HAVE_LIBURING 1" > $OUTPUT_H_FILE - echo "COW_EXTRA_LIBS = -luring" > $OUTPUT_MKFILE + echo "IOURING_EXTRA_LIBS = -luring" > $OUTPUT_MKFILE else echo "// No liburing support found" > $OUTPUT_H_FILE echo "# No liburing support found, so:" > $OUTPUT_MKFILE - echo "COW_EXTRA_LIBS = " >> $OUTPUT_MKFILE + echo "IOURING_EXTRA_LIBS = " >> $OUTPUT_MKFILE fi rm ${tmpname}.* From patchwork Thu Apr 13 23:12:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13210723 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 25D6BC77B76 for ; Thu, 13 Apr 2023 23:12:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEBF8280004; Thu, 13 Apr 2023 19:12:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9BCA280001; Thu, 13 Apr 2023 19:12:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A63E6280004; Thu, 13 Apr 2023 19:12:19 -0400 (EDT) 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 999D4280001 for ; Thu, 13 Apr 2023 19:12:19 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5DC30AB722 for ; Thu, 13 Apr 2023 23:12:19 +0000 (UTC) X-FDA: 80677918398.22.7AFF179 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 6D5BA4000A for ; Thu, 13 Apr 2023 23:12:16 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SnDFCiL0; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681427536; 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=U50mzc3x7opcua/Zq5xIU5DytHBPjAF3IuThARnv+MM=; b=0W1HqvlfmkPjAqA1fmeDu29XMcwz74as3nH9iXpvNZnUeeciEd52HN59OSAwHHmClVshgN q55mDWywB7gJlqHLlYFEZKqNy8K9TNRNwz414Xpjq4viOwcWtEHgb8TYeEP0QJE/4i8hhk wpMqEPiqUgVVt1n4hend58IhhTswLTA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SnDFCiL0; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681427536; a=rsa-sha256; cv=none; b=Dk3cmuMCOdqJN66yu0SmPwTsQS6ozZ1U246SY4m6PgCt6rPMZbwdGTHz8ItuK7CudpTycu 1NAMOjjiUnKJ1oxxz3LxBMrS1B53ASYey046pE8HIOf+gjU+h+MVvSjNo22NBUsaogOLFL ggEukfeASj+x8vNCDIPbigwKrZaU/0U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681427535; h=from:from: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; bh=U50mzc3x7opcua/Zq5xIU5DytHBPjAF3IuThARnv+MM=; b=SnDFCiL0FiDlRm79lTrVqPohkXE+xMtx3eiNJc0d/u1iofU51OEcw/A7HFseB0akyyNxMd 0TdgsIDPXsNfk+QfGrw8tDxL24h1VDooob7LqaoF1b4viq+LSxSWauJXY28Z9P31D63b9V W+EjWpviibMbcnk1UT9D9GzpP0TXLW0= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-_UIwM3ccMSiOcTLcyzfSXg-1; Thu, 13 Apr 2023 19:12:14 -0400 X-MC-Unique: _UIwM3ccMSiOcTLcyzfSXg-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3eab4df3ef0so823901cf.0 for ; Thu, 13 Apr 2023 16:12:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681427532; x=1684019532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U50mzc3x7opcua/Zq5xIU5DytHBPjAF3IuThARnv+MM=; b=SnI256tqqpmyViqYSXDHWMV4leSxVNjViOMlyyefaBoaywJpBMzVcPyfIIoYTvQXhE qDGVPCPEveG4124t9YczvjEm7k+Zzxd9uV8qFBN+r4sdWxcQ2YZyLxRtyva90YHA38Uf YPoG8TS4ePWIN55/l25sfx9kNQey0LUkHmCaoE6tEtlUX1r/RN+k87YubSHo7RbHBW50 T3sdr0uw53iwPM7681stFg8ErlZi/OEU0rUdLRcdZZDssBtQxosFW+ZfPgQpRwvsZ38X XNlOWzDUuxyxgQy86xGTLLc62PBfiuVNgoehSc4pM4z6+PprezbAGF7Y8y4Z8cYB2Xku hB0Q== X-Gm-Message-State: AAQBX9fK6M9+6vlaZmHL8fZX67BusV1dGc5IBY7iXfHRBjMDYcnMm1jw RHZ60CFOYK+OVj9iPhKuRaP5FwlznaB1KV/o/3Xa3VjFAGQBDFJQQ+lTeyXXTZcBU7AQbuw4yZH y8T/YJRglU5V9PwjKltaLN5KGMIWKEkL9p6xYZxnCG3LM+WwDMdMcr5WNhMCobTq/bGIL X-Received: by 2002:a05:622a:1a0b:b0:3e6:3af1:de7a with SMTP id f11-20020a05622a1a0b00b003e63af1de7amr983591qtb.4.1681427532080; Thu, 13 Apr 2023 16:12:12 -0700 (PDT) X-Google-Smtp-Source: AKy350YlByEGJ4UdGFBHdGvGYtpq6JVyaUGtX1ideR+y+TXFaHJemqbrxo5x6y9sTphL6VxiZhrbGw== X-Received: by 2002:a05:622a:1a0b:b0:3e6:3af1:de7a with SMTP id f11-20020a05622a1a0b00b003e63af1de7amr983544qtb.4.1681427531653; Thu, 13 Apr 2023 16:12:11 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id p26-20020ac8741a000000b003dd8ad765dcsm814463qtq.76.2023.04.13.16.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 16:12:11 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , peterx@redhat.com, Mike Kravetz , Andrew Morton , Andrea Arcangeli , Axel Rasmussen , David Hildenbrand Subject: [PATCH 6/6] selftests/mm: Add tests for RO pinning vs fork() Date: Thu, 13 Apr 2023 19:12:09 -0400 Message-Id: <20230413231209.544825-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413231120.544685-1-peterx@redhat.com> References: <20230413231120.544685-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6D5BA4000A X-Rspam-User: X-Stat-Signature: wy4dzwkzqamfyf7pz5omni1smdez1nk9 X-HE-Tag: 1681427536-750624 X-HE-Meta: U2FsdGVkX18atyOGKQEzOpTEvBuT8177e5kE82OWMVnj9rBvDnp78cgVDXxgQgHhrV+gupQdDA/uwfYMmqhJV6ap6MZlz0vqqO1IogEBfaNrkR2Odj0lzhsFuyvGHnKLPs2JEWO2lSRd1DCrlZtp0jB7qn0tRd3t/dcmXx+J7lSOqyrU0UoiAvID4Ji17SvAkSxQ2+5ovuFozNs0e1a5iS8BggEi6tQXb5lJj6HdKbaNCB8BhAGUizRFZH4JHk4rXSFFXXNujh8NrZija1RZzwaTNm6Xtlawegj7/J8cjWuaDydyrsbADJFnvi8K2t3fdTzyzhlh1JsBl73pEs/hwszUeDbfnAI6MdWQWnrvwiS4YIe+Y+Y4tfvqhrgm6xrMeHu3dItJ+L9kkPWkw43tpH7Okm+q84HUj1NOqV1rnFNSJOCx5OLAWG33AYoiUQWpSI1B6ga0Q5oAADxfBtf7jDC6PgxTOF1E5Js1mDyefroM1ihpLMcqxlSodtvasejtTu9DllZ/gfIvkLOOV2cdmcEsdxWLWlL3j2S7tTIHR856q1vgLxspiUUYGWtORgjshTaTARjebhQISRu+dk7PvK5pVcFOEuY6f3GxCGiolwQ6RgtqX3rlM0fUL2nzjclpAWWbxJPw983tz8AsCT5TJKoFcBIhUl285y2tLhbDT0aymmKbMzvbLgBmk1vWQPjYxnREGyMfQK7MQZQXoyoLSMVbWw0f4RqmzTbJsHJ4Ttpo4rohp+ubgCg6AaV4JAuTXAz1Of2kPD7mx7pzVe8EeO582VGhkqzovAtGFPDzUDZQ1238nW+xzJEdK7a28w7+aB+Rc4uKP8mZEbGovDSTU6gPRDUwbrBpaKZuhmB9dpQX8D6UoWouXx4x+o9MwgmKNZ9ZyX9TdzWg+XG8J677jMDxIEAAxAeDG7KpSIckbtNz9I+mW8ypAwRerp6qVdY/56K3jw4M0IHeP95S5Rc kF1kdhik pxfFryOma4HXhf03R8LF++9WG0PBK8vnM3Dr3t20HBCr21j0A0vQdbUQMmarHFLkA6cqgM2YDb1X1qxdN63igEDNCsVq27aqorRJiZv4McIM79zVMejulTdtPTbvmZl3pFyeJcwsINsTclSq4Z9YVNv3u6dNQmHGtw3nAlwbZILEY4kb6Mt8VCK4PgQ7hJ1XGc6sTOhHHKrLVI7q5sroVZMkOBK5iuTpbKDEAXrcBA6+QSVUp+ELZdSTo5IXZb78Rsxw0aKraxg4a6wkRHUBZkiaXrqKRUS1JDUPyluXwJlDnD2ylbG/5A6/UQHS+sKP8sM21+SYV43vWd8B2GRPV2ch1Qg2ttmp0UKawMDcXKZPQdEA4wwDypaaREm4eekBrxbvmn616dNC4cn3ye2Au5A7Xj91LOlTjxqKOxjqQRk0EZ5Ya2L5ZSDlXojRfBE5Ho5GRUjIP3aXAkjdQOEw7a7ojK8CjCv6DU9dX 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: Add 10 one more test to cover RO pinning against fork() over uffd-wp. It covers both: (1) Early CoW test in fork() when page pinned, (2) page unshare due to RO longterm pin. They are: Testing wp-fork-pin on anon... done Testing wp-fork-pin on shmem... done Testing wp-fork-pin on shmem-private... done Testing wp-fork-pin on hugetlb... done Testing wp-fork-pin on hugetlb-private... done Testing wp-fork-pin-with-event on anon... done Testing wp-fork-pin-with-event on shmem... done Testing wp-fork-pin-with-event on shmem-private... done Testing wp-fork-pin-with-event on hugetlb... done Testing wp-fork-pin-with-event on hugetlb-private... done CONFIG_GUP_TEST needed or they'll be skipped. Testing wp-fork-pin on anon... skipped [reason: Possibly CONFIG_GUP_TEST missing or unprivileged] Note that only private pages matter here, but no hurt to also run all of them over shared. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 144 ++++++++++++++++++- 1 file changed, 141 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 739fc4d30342..269c86768a02 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -7,6 +7,8 @@ #include "uffd-common.h" +#include "../../../../mm/gup_test.h" + #ifdef __NR_userfaultfd /* The unit test doesn't need a large or random size, make it 32MB for now */ @@ -247,7 +249,53 @@ static void *fork_event_consumer(void *data) return NULL; } -static int pagemap_test_fork(int uffd, bool with_event) +typedef struct { + int gup_fd; + bool pinned; +} pin_args; + +/* + * Returns 0 if succeed, <0 for errors. pin_pages() needs to be paired + * with unpin_pages(). Currently it needs to be RO longterm pin to satisfy + * all needs of the test cases (e.g., trigger unshare, trigger fork() early + * CoW, etc.). + */ +static int pin_pages(pin_args *args, void *buffer, size_t size) +{ + struct pin_longterm_test test = { + .addr = (uintptr_t)buffer, + .size = size, + /* Read-only pins */ + .flags = 0, + }; + + if (args->pinned) + err("already pinned"); + + args->gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); + if (args->gup_fd < 0) + return -errno; + + if (ioctl(args->gup_fd, PIN_LONGTERM_TEST_START, &test)) { + /* Even if gup_test existed, can be an old gup_test / kernel */ + close(args->gup_fd); + return -errno; + } + args->pinned = true; + return 0; +} + +static void unpin_pages(pin_args *args) +{ + if (!args->pinned) + err("unpin without pin first"); + if (ioctl(args->gup_fd, PIN_LONGTERM_TEST_STOP)) + err("PIN_LONGTERM_TEST_STOP"); + close(args->gup_fd); + args->pinned = false; +} + +static int pagemap_test_fork(int uffd, bool with_event, bool test_pin) { fork_event_args args = { .parent_uffd = uffd, .child_uffd = -1 }; pthread_t thread; @@ -264,7 +312,17 @@ static int pagemap_test_fork(int uffd, bool with_event) child = fork(); if (!child) { /* Open the pagemap fd of the child itself */ + pin_args args = {}; + fd = pagemap_open(); + + if (test_pin && pin_pages(&args, area_dst, page_size)) + /* + * Normally when reach here we have pinned in + * previous tests, so shouldn't fail anymore + */ + err("pin page failed in child"); + value = pagemap_get_entry(fd, area_dst); /* * After fork(), we should handle uffd-wp bit differently: @@ -273,6 +331,8 @@ static int pagemap_test_fork(int uffd, bool with_event) * (2) when without EVENT_FORK, it should be dropped */ pagemap_check_wp(value, with_event); + if (test_pin) + unpin_pages(&args); /* Succeed */ exit(0); } @@ -352,7 +412,7 @@ static void uffd_wp_fork_test_common(uffd_test_args_t *args, wp_range(uffd, (uint64_t)area_dst, page_size, true); value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); - if (pagemap_test_fork(uffd, with_event)) { + if (pagemap_test_fork(uffd, with_event, false)) { uffd_test_fail("Detected %s uffd-wp bit in child in present pte", with_event ? "missing" : "stall"); goto out; @@ -383,7 +443,7 @@ static void uffd_wp_fork_test_common(uffd_test_args_t *args, /* Uffd-wp should persist even swapped out */ value = pagemap_get_entry(pagemap_fd, area_dst); pagemap_check_wp(value, true); - if (pagemap_test_fork(uffd, with_event)) { + if (pagemap_test_fork(uffd, with_event, false)) { uffd_test_fail("Detected %s uffd-wp bit in child in zapped pte", with_event ? "missing" : "stall"); goto out; @@ -415,6 +475,68 @@ static void uffd_wp_fork_with_event_test(uffd_test_args_t *args) uffd_wp_fork_test_common(args, true); } +static void uffd_wp_fork_pin_test_common(uffd_test_args_t *args, + bool with_event) +{ + int pagemap_fd; + pin_args pin_args = {}; + + if (uffd_register(uffd, area_dst, page_size, false, true, false)) + err("register failed"); + + pagemap_fd = pagemap_open(); + + /* Touch the page */ + *area_dst = 1; + wp_range(uffd, (uint64_t)area_dst, page_size, true); + + /* + * 1. First pin, then fork(). This tests fork() special path when + * doing early CoW if the page is private. + */ + if (pin_pages(&pin_args, area_dst, page_size)) { + uffd_test_skip("Possibly CONFIG_GUP_TEST missing " + "or unprivileged"); + close(pagemap_fd); + uffd_unregister(uffd, area_dst, page_size); + return; + } + + if (pagemap_test_fork(uffd, with_event, false)) { + uffd_test_fail("Detected %s uffd-wp bit in early CoW of fork()", + with_event ? "missing" : "stall"); + unpin_pages(&pin_args); + goto out; + } + + unpin_pages(&pin_args); + + /* + * 2. First fork(), then pin (in the child, where test_pin==true). + * This tests COR, aka, page unsharing on private memories. + */ + if (pagemap_test_fork(uffd, with_event, true)) { + uffd_test_fail("Detected %s uffd-wp bit when RO pin", + with_event ? "missing" : "stall"); + goto out; + } + uffd_test_pass(); +out: + if (uffd_unregister(uffd, area_dst, page_size)) + err("register failed"); + close(pagemap_fd); +} + +static void uffd_wp_fork_pin_test(uffd_test_args_t *args) +{ + uffd_wp_fork_pin_test_common(args, false); +} + +static void uffd_wp_fork_pin_with_event_test(uffd_test_args_t *args) +{ + uffd_wp_fork_pin_test_common(args, true); +} + static void check_memory_contents(char *p) { unsigned long i, j; @@ -923,6 +1045,22 @@ uffd_test_case_t uffd_tests[] = { /* when set, child process should inherit uffd-wp bits */ UFFD_FEATURE_EVENT_FORK, }, + { + .name = "wp-fork-pin", + .uffd_fn = uffd_wp_fork_pin_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM, + }, + { + .name = "wp-fork-pin-with-event", + .uffd_fn = uffd_wp_fork_pin_with_event_test, + .mem_targets = MEM_ALL, + .uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | + /* when set, child process should inherit uffd-wp bits */ + UFFD_FEATURE_EVENT_FORK, + }, { .name = "wp-unpopulated", .uffd_fn = uffd_wp_unpopulated_test,