From patchwork Mon Apr 17 19:53:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13214488 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 7C983C77B76 for ; Mon, 17 Apr 2023 19:53:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 155ED6B007B; Mon, 17 Apr 2023 15:53:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 106B78E0002; Mon, 17 Apr 2023 15:53:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE9498E0001; Mon, 17 Apr 2023 15:53:28 -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 DD5E96B007B for ; Mon, 17 Apr 2023 15:53:28 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B09CF1A060E for ; Mon, 17 Apr 2023 19:53:28 +0000 (UTC) X-FDA: 80691932496.11.7351EB3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 87F671C0007 for ; Mon, 17 Apr 2023 19:53:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c297cepQ; spf=pass (imf21.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=1681761206; 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=4kH7JNUmkrK1TIcnPTAjFCorjkRaA4Lvx3pRbnAdGF0=; b=ThM8Jy0LAaDM4K3UmyKPeNc7X82rafzd8eFJPBBiyMrTxZkTsonGSwi9ZTHEW5krYSU4vz HB+FLxxxkAD/jUzsAbJpzJpkp+WK51uVjwmBCdYrU4MBk/WK10uf34VIqcOM8xKdRfXvv9 4dG040yvy9fh6pvdPhKO52AWZfjOCwM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c297cepQ; spf=pass (imf21.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=1681761206; a=rsa-sha256; cv=none; b=lLP089XlLaAAeITQV8EqWbDchVct1xxAmQd7oqUhSMt7+W6/zERB5FtPnGaqZyfILSxEpp 7TwQXgd/NgTPhrkKcF/eNEKpdaJe6GB9U5TVmFQ21SGzGr8JeREI1VjYp3/SpA6IyYe/l8 iHF78fluULzb3pgj4Aytc7S40tJu1B4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761205; 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=4kH7JNUmkrK1TIcnPTAjFCorjkRaA4Lvx3pRbnAdGF0=; b=c297cepQFvarQ5pqK9s4YFmCcQdkWGT24LACG5guK2QVmkeEON52kVB9DzL1e/WK9bWeyL mLeWEpuWUGCSn57eTBVaYV6rrgyo01CHH52w7Yqd89XZwcenyWqhAs6h6vgbVV5u0bDqz6 CQBw4zrsEQt0ldLpxMLP3eXOCDGKkTQ= 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-646-K9zGQh5mOe2nqAkhKfK69g-1; Mon, 17 Apr 2023 15:53:22 -0400 X-MC-Unique: K9zGQh5mOe2nqAkhKfK69g-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3ef3116d1dcso1936961cf.1 for ; Mon, 17 Apr 2023 12:53:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761202; x=1684353202; 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=4kH7JNUmkrK1TIcnPTAjFCorjkRaA4Lvx3pRbnAdGF0=; b=CoueRYAMUG82sZOFMgW1zN4Az4hOZlEnc6/NktHozN6+vZAtxJhRz81tmE43pTTEU2 E/cqsmiBQvmVipTJUuCRzeHKUoOmlVO/62YQfrsRde5DqMQKRSWFY2L4YWsRuVma8I55 ymE0v3gNHIb+Pn6ZcvMUkwhtXB8VVmuMXS+eT1hHPAeAvc0rEEsgIgayXVbs4CLtXRiI 7ObxJkxOIS/KS8Ii+R2OgjpY1atFwCiNVV82Wuj4ai0NQzloyHA7fg/4aZIS1yWVcxmE ZGZGReSs6THQqyI2b2MgCBHjD73IujLFrtnxrA/jfy1ewYVmXUjwc8qVTi05MP2RZlo1 TPdw== X-Gm-Message-State: AAQBX9eIkNNLZkEI/LsiLt8xLqo037NwfUuVNeQ8FxmJ6nGFxXWlHgVv 2GiDU83QSq+O0muf8BoHjeagqaoA7hAyl1oxIrklAW11uShLiiSSOuEaW8SsqV1lN3v1LpttLb8 rGOKzYupYrMo= X-Received: by 2002:a05:622a:19a4:b0:3e8:e986:b20b with SMTP id u36-20020a05622a19a400b003e8e986b20bmr17654467qtc.6.1681761201983; Mon, 17 Apr 2023 12:53:21 -0700 (PDT) X-Google-Smtp-Source: AKy350ZImFWbK1bH7N466hKMggFlbQGVKGvl3FHNzHOn9K4F9JpZRZ/yhdls5xIATBP5zpu3FcayoQ== X-Received: by 2002:a05:622a:19a4:b0:3e8:e986:b20b with SMTP id u36-20020a05622a19a400b003e8e986b20bmr17654449qtc.6.1681761201723; Mon, 17 Apr 2023 12:53:21 -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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:21 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand , linux-stable Subject: [PATCH v2 1/6] mm/hugetlb: Fix uffd-wp during fork() Date: Mon, 17 Apr 2023 15:53:12 -0400 Message-Id: <20230417195317.898696-2-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230417195317.898696-1-peterx@redhat.com> References: <20230417195317.898696-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 87F671C0007 X-Stat-Signature: 3sg5x6ihrr6nxc11a7szog1rm94itzhk X-HE-Tag: 1681761206-546014 X-HE-Meta: U2FsdGVkX1+xDJpitoZTmvaPj9Brmxa22wpPdZ4ouG9W2RTy+n33DBTRSatC6fVtSmPHksuU3LI1S1lYcnRttcdGUKQmrK43Qq1DvrZFLvZajkn0xF9HAqwgnrZvlspXhRKV6HEDOtVKAjJGHg4OStW1lXSacnPmk8QjToeQsPbvs30zcCwC4HaZ2fQnO9MTBurLMM/oSwVtpRkK6cZej7HUG4vlxCnMtaLwV6DMbYi0S5BkUUj4r/nquYH1JXkdFKxY7IeN50bwHSbnPZ/AJBThbCE4WJU++ujs1f70zOl6dHUmiMCVXLazJq3vLJtpk6CV20TOO0QgeqG8tsyKJiwPEgFqPh6cB5Wful0O/nM3+RLkvlC2i3TG4pxaxY89eEssZyFKc8hCULPznqwCF21TiUWf/Owc+N5WI65oj8C0k/uuMn7sX4jYbC8W3IhBOZ8qAMb0bJ5j/EViVVtpVonnvn8AeaSmD4OS3Jby041WR/IxOMSCy8tEBkM3MglWF+bRqPMKxcPOnRfxEpDHtlWprUpqnUxYlOkiALbcx8yhIgJ/3KOkLhQU6OXY1Eb9CIYQqXqc+1Y28DTpt4uXSCc5pN/GZ5gkLsmsWr6jZMUdzb6tgguz1zwOFUC+chMGbR3dRTtjL2ySN0z4Ze7O71eyZtKgH7ru/u8LXUVjuwv572uhBF4l3Cv72dNs8wyC/XwglThnxjyEEk8peplhFACZoDT34QDVXu/y9rpHqWirMTfQpwqv1z38gTNCGamAYda773aHysp0fTbWX7Yh9LGmSY2BhooRDwimqhQBQot893SnFR+zAKnEhemcBPO6lERWkmXEfEOyn+ja7Fanz9D0HSm5aYUasoVZLjOiudgi/KcYUNsP/8hbtO53lh/EOunZUup4oVxsSJflLPge78MDXj0iA5jQH4daH9nlG8M+CY50T8E2tT4fPD9LLcnmbEO3N7G0VL8k7/3LAOK Fts40O4D ZXFtcnK9yc+VIad+Pa6ClxYUXPsXfP5Av+zJcjVj/Zkd4BGe6M1WvrMyFMcOWZPmc0i5g9rlj8rIQ54prvuer++swsIYGkTk5Re/SGybxtfCIoakuIbKibpqF+KhUr2NVSlB8xc1ZTMmWWeC3CPiljEz42UBCqGe1dxg02E1i0WHvoaxxpN5j6iX/Ckn0t/I2D5eexM0ToNZYHqfyBXkC6pZfAdCuUgiNNk7mIeC4XOF/9XV/Cj3eX1lq6JRUPiPoYGD61RLA9xcH3o0hJZgA42FfO4PhfpHtk2fUDcn1CTWMJk9Ms5iZAJlvaWMSwoAEfXyeED/vjVU1tICzhAeW07XzczhANZA5txtR4PDFXvGldOyLbsk5u2I6U62f1dT3TY0IwmvzxvKw4KvIehPTK4F9cDY2C2ZL1X45X/8ADlEr28/I+oYbnKGAfNa1JqbTNRB3JDJSoypdJ54KdcKvlaGcFxIO4ikyI/ssYmiHf1eeVIuslrinMNNTt9Tmk3jGbwkp7S9cGherLkfuQOGgupy0RQ== 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()") Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- mm/hugetlb.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f16b25b1a6b9..0213efaf31be 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,12 @@ 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); + bool uffd_wp = pte_swp_uffd_wp(entry); if (!is_readable_migration_entry(swp_entry) && cow) { /* @@ -5050,10 +5052,10 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, swp_offset(swp_entry)); entry = swp_entry_to_pte(swp_entry); if (userfaultfd_wp(src_vma) && uffd_wp) - entry = huge_pte_mkuffd_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 Mon Apr 17 19:53:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13214489 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 99E47C77B72 for ; Mon, 17 Apr 2023 19:53:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 240B06B007E; Mon, 17 Apr 2023 15:53:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F1548E0002; Mon, 17 Apr 2023 15:53:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01C978E0001; Mon, 17 Apr 2023 15:53:30 -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 E52456B007E for ; Mon, 17 Apr 2023 15:53:30 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B9D2B806B7 for ; Mon, 17 Apr 2023 19:53:30 +0000 (UTC) X-FDA: 80691932580.21.235E04C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 8495C1C0007 for ; Mon, 17 Apr 2023 19:53:28 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YgAOFWRb; spf=pass (imf18.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=1681761208; 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=ZZajLRXbE1gHSG0/rWcJydl4VAkwntQbZfH27HHj2cI=; b=5suKwCf3cdUeDXwsvprJeyxzW0a7GY8E5GDetdY95tnWg64itOMiPka1XllOy8x+rLxcRK yW29Sx/enWWuJ+TRdUafh0qa1c93kKGh7KPgsq3+0GYk6ddkj8B2lErSCAeyQ761csxA78 xFUFtRjfarDVr18yZ5PklmaV4DFNj4k= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YgAOFWRb; spf=pass (imf18.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=1681761208; a=rsa-sha256; cv=none; b=Dfe9x8v5OLKLQVh3qxc49er8ANKcJYoyM8WGtRAwuTfr0fLD/Sduzmx2MBW9QQ9X9rlslu WKNNuHpuLfF1uBsYn0n8ylzl67MnqIqIn4hQSvoqPlfJ/dKqfW5yxo3TNMuctd9Lz8IsCl BLwgp1HMA4j2az+27hP2mP6l7/fDIyg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761207; 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=ZZajLRXbE1gHSG0/rWcJydl4VAkwntQbZfH27HHj2cI=; b=YgAOFWRbRZYCjZ4335n4h/zs2N2oH0HWBOaxXrq7EfLtmHWo08MHDBD5J/2Jm3MoqBdDJU VvzgK6Ro4NBdZ1CnyhrZJnWCaHYecAUEOg/O/E1W3/w3bi8rD9Z/OdhNTW+ZQE6rTkwPG0 8264GiNQUIYro77xnxrIQZL6SU6IfEw= 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-190-m4X3MQhXNXykyIGB8D0j6w-1; Mon, 17 Apr 2023 15:53:26 -0400 X-MC-Unique: m4X3MQhXNXykyIGB8D0j6w-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3ed767b30easo1904891cf.1 for ; Mon, 17 Apr 2023 12:53:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761204; x=1684353204; 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=ZZajLRXbE1gHSG0/rWcJydl4VAkwntQbZfH27HHj2cI=; b=bt7xBY6iFwT5FtU8ruE2R72nXkh7HDLQlZvVpjzOzkQtMJYWDJws1R7jEkeaBUlfac GZbLYpMcNFD8Qtz9D7e5nu8DPkDVDbLoDsP3ehysj2+waTtIiJ4BQkztjntZ+J08+lPo tTgcMVUfL23AI0w7HFluvvh2d0nvAlQ1jWjRhbROcGBehQQ/GByX+EvRq2I4OEJap1ci IrgvPDG78FGtx4/udwOgqFPfZGkgXD3PgYVLW9tdIDbu9L9f8PhHhPbUkMrm2fF8Lnas vQaFR3ZG0bMr092DCXhI+Aox6nLxRxBqahTYTiDoO1mXgdGeCiRMapBRm0IZKQjFupq/ VKog== X-Gm-Message-State: AAQBX9cdWRtCWxZNJwDMJRqZc+bZhtwgH4VqXbuVyKEt/5vj+t4SzRS2 CQbc/+AKVdZ3PTVnzaQUfmUu+gdWdKfw+qOSgXQzj3DwTV6QpPK3N6ZXHiX5m6cEhZ2GXZUnXGB +/nw/WMGc89oiSVRPVH4= X-Received: by 2002:a05:622a:1a9b:b0:3ea:ef5:5b8c with SMTP id s27-20020a05622a1a9b00b003ea0ef55b8cmr19155678qtc.3.1681761204286; Mon, 17 Apr 2023 12:53:24 -0700 (PDT) X-Google-Smtp-Source: AKy350aPbpBAnSBo8hIMWFwYiZl6fBgvrueoUnmaQeBSdZmgAZBXgdsikL50SEQY0Q9p7+B82l1+8Q== X-Received: by 2002:a05:622a:1a9b:b0:3ea:ef5:5b8c with SMTP id s27-20020a05622a1a9b00b003ea0ef55b8cmr19155663qtc.3.1681761204064; Mon, 17 Apr 2023 12:53: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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:23 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand , linux-stable Subject: [PATCH v2 2/6] mm/hugetlb: Fix uffd-wp bit lost when unsharing happens Date: Mon, 17 Apr 2023 15:53:13 -0400 Message-Id: <20230417195317.898696-3-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230417195317.898696-1-peterx@redhat.com> References: <20230417195317.898696-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8495C1C0007 X-Stat-Signature: aojuckoe5h6zbtto9467xkomax5h9c93 X-HE-Tag: 1681761208-306167 X-HE-Meta: U2FsdGVkX18naXPLt8q2zvzYx3X6o4lB9Nnin5iFUOtKGoz1PSFo7D42+qcvfvJ8NWu2I3SruLCRjBifLsh6H9Y99N5iwE467lkeHXTE5yPVxNrLuR2pmuYFF9N6PJHr0UxGugSK8t9hC4/ShVwJERNRJdbu7oANS3pbqlqVkw5Ffg7z5e4WXTSlyGh7xz2MVnswuHOlT9MyBqlj5XjEoe5vZHSURi1gC5//8ZhnqtkN1iB7GEUVGdj5SDVi/TPehx1H0XqusKn45C+QX68SK1710EjOEMkEy7rlbTRQIHjZpvoe1MfhgqlRVfrtRGW665PTUYWJaCZekJ6J6akkrcQD6ZuXBy/TzhczDlcFtCpQD8e+iBGdIlCdAwPGV10jbe8f7/nVFxbQqY51C3F6ruUSywiT6NvYWL9C8wvABhBTSJw6T2Pki3pn4zhFXrrSiLrl7lmp4jRZ16zIVfwg1Q+u7ackpFY5RRQXBRF28/BlZ7fzxGYJMbY6Q9cM1AZIHMpaW0C11jwmzi/ZdXOPiz55cNRAae3diYyvKJIAAF3piIS4lWL+lFQu/sUNUzurYgr9HNLk8UKqEV3+WGyUsTGv6BMc/jCEWD++1JHckg3QvOlUc2K2flpkwoY54XswIERZzGfSE+e0t9v5gdAFMl8fRBHFKBFGbq1x+fCLYpt/7zMDeUfCEcvXv5xqBIgRc0/Enz/rfismfIjh+zO1PLGbbVohzFzJymWZjSCaXVwKGj9fojVMULvHEHl+UcqZStZd5iwRaFDv6IUIi0+IYgO1iFi3dgA4ahDblTKdZCUOswugnw9MSVQ7RCQBpa0kTDCtqjRbLJno2tLSVi/pyR4FQ1vets1gADLCB+Uo2CM9VnKDz+Olp/EAfhdPbddfnyorZKbyqvLJ8Xhl/SRP+0jGkQMfUkFKkvr2cjOvAA0Sy/9oi29xpJ3YS4dg8/tGrHTprqQk68P3vZ55Adu O4aRxqTK dyb1fc6ifM5JSxql0boaj9vjxt13RBNed5GpS603TK/DxtWp+YzYwZZVqyOUuSkKiTokDF4XmwnQqs1xGbFVIgBD7D6LXRIrBh6LOpBU0c+sNFQRPVaOKnLPqBEJfickEXFFnBK9b6FQ0yd7r4CurryMa2JUd3hR9yp2OapfQKBnx5CFLkGSba1bzLFMPzEd/oa2SFvUP5P+Y/3/F5bKmXb0vUVIA53CFfWMuwBhGhfmnnP9Z1n17WWsXlrA8Z+eAZbVe708aGwlxLpKwvZ4Ebqn+BwYMTBQipiyHie0BDtCApR/UzeTObkXwjMEpjTfxjJ9oOWXjAnWT0Yz5vh9XFyLpOxfj3FcchHyN5RTjyopwWqo169zM2LAICaYjRuKFlr+Q4PA5Sd1qvJgyQ7+7XkiRps4Kb8bCX++V9GusyeEGX1ssrfaKJmaw8cl/FObElhuQ7RugHM/7EeVa6KdwC4o211jR4lhYpawAJIpJVqcfc71gcQIscn2V0g/sfLQnVlJEuUexYW5ugABP72LchYgClx8lclViOzRGgegM4qPMNzqdUXSmECPPPcSf+SNgBsYjRmjiYAkuFC0= 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 Reviewed-by: David Hildenbrand Reviewed-by: Mike Kravetz Signed-off-by: Peter Xu --- mm/hugetlb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0213efaf31be..cd3a9d8f4b70 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 Mon Apr 17 19:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13214490 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 4AF43C77B76 for ; Mon, 17 Apr 2023 19:53:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8AAB6B0081; Mon, 17 Apr 2023 15:53:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3B018E0002; Mon, 17 Apr 2023 15:53:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB50C8E0001; Mon, 17 Apr 2023 15:53:33 -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 AD0AB6B0081 for ; Mon, 17 Apr 2023 15:53:33 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7A1051A060E for ; Mon, 17 Apr 2023 19:53:33 +0000 (UTC) X-FDA: 80691932706.01.FD253F7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 66125A000A for ; Mon, 17 Apr 2023 19:53:31 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hkiTDCUl; spf=pass (imf15.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=1681761211; 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=swuLEEc8hNZPp74szbyE+lxJmMoJXpIYiFr2iwHywYCpTqeSfrn6Ye4ESQ3fLQyYfoZ7fg /TYDdIu6ZQPo6WsKGIjy6gCROsiQeMkR179d+jC6dI4qdGfu7EEpEzSxYyNQGa4jhG5KMT d8cMbou/h9AewGZVtw8eiaz6/FHNQM0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hkiTDCUl; spf=pass (imf15.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=1681761211; a=rsa-sha256; cv=none; b=wfL8SKm0f3ph44+jW0Cgb0FprOPcf6P4r4A6SB5X6rdvid6VWvbLmzdzrp0Q4yBm09D7WB lO+CpuEd1um1JCB6ID1tOJV7neM5UUNIsDsD4eL4uTPtPw/b4SX+sFVPjaz11NgF8bV3LC zdIrho9hWE8htTv7LLpzVY8h+QEEqHU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761210; 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=hkiTDCUlCBT3A+g7WD3e+kzku6Nny0wR/HLEVs1lkDFLlNrqZJHVFA97h65NqcJLePoWTz fFcJof5X9IvWQwZGvTNnSthcrXd72QSmqo0uHvKr6Ux58oDK/BFk0Qbdv//0hkw6/Hzhmo U0/6Ii/s/Y+as+OQMzx2HyBXmaH7uSg= 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-376-CVDYZVBFN9WEyA-3bcccdg-1; Mon, 17 Apr 2023 15:53:27 -0400 X-MC-Unique: CVDYZVBFN9WEyA-3bcccdg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3ed767b30easo1905001cf.1 for ; Mon, 17 Apr 2023 12:53:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761207; x=1684353207; 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=l7qNVnQac3AG7A1P9/EM9r6fsD8HYoXZs3mYf8uz9kxyjM1EpD6I2fuRyr24e7SNop iY/iS89bZwneo+WfSc2xX1dvPKdJPy+cJdtOz1kE6GdBvNjW4cKm/EXUv5Ad+1SMUUWf SVBDcuvSMVUNEX6AVaSWlJTlsNoNU4ps225KRglWadJNrdOEaCRbJP1hMGN3yv0ClGbb XzIFu2SX4NSJiE7dW4zXjCe7+T6NGWUUOViOFY/xHBCWfPTVh9Xu2JM4cMUh7uriOQLh jdEtZnFTq09/1Y1eZSqnx/fNF5w3w+gWfH8mKUviXqDhCHXmJHkNNfqFbCEJINHMEYsX 9fSw== X-Gm-Message-State: AAQBX9dLFiR+3GcBZcMvAu/JK4ZS9DzgzOFIVTo1zOQzDNyJtJszQzx+ 6XEny5X5EnoyIFhiuGmCOoomN/lchopcF4ZRmzIzLOV6lilaFATbUtNkbvDesHUsSRSSC7WRRCQ T+vL4h8nseHY= X-Received: by 2002:ac8:4e43:0:b0:3bf:cf77:a861 with SMTP id e3-20020ac84e43000000b003bfcf77a861mr19130137qtw.4.1681761206739; Mon, 17 Apr 2023 12:53:26 -0700 (PDT) X-Google-Smtp-Source: AKy350atiTLtabqgcPaZB1CQI3pkzcoQyHjGkW0AJzAmgZF9tCzczfoqxlZpXO4VXi+keofELA+BDw== X-Received: by 2002:ac8:4e43:0:b0:3bf:cf77:a861 with SMTP id e3-20020ac84e43000000b003bfcf77a861mr19130115qtw.4.1681761206528; Mon, 17 Apr 2023 12:53: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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand Subject: [PATCH v2 3/6] selftests/mm: Add a few options for uffd-unit-test Date: Mon, 17 Apr 2023 15:53:14 -0400 Message-Id: <20230417195317.898696-4-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230417195317.898696-1-peterx@redhat.com> References: <20230417195317.898696-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 5eaag1mxpbokoygh76363ay7q9n3ghyb X-Rspam-User: X-Rspamd-Queue-Id: 66125A000A X-Rspamd-Server: rspam06 X-HE-Tag: 1681761211-165650 X-HE-Meta: U2FsdGVkX19XTd7skDqNbVV1UZ0n3wbXiEo8VixlI459KbQtaTD97tbJ4gvNq2U6VCoW1t+z6GKjJfkV57gPI1n0f1Ig6u7+GrjHX1oFWMv/RjV336Ydy7F5FmB/CWuKYa0wmCXR+80Dw1nLemGOS0bZrGD/ywrxwH8aJgPLNRH0AfeJn147VSnSo6kYUx6nDYeonLV/wfEM8KWdWoOomFRjqtKzuEDMIsP4F6IPIlnHBK6Ne5x2CyHNNpuJ5bzLQBKjl4UTswLVQtg8KwJHrlULY64IarKZGRyhGoaHnzAfpHvkYpXLPHEjL9ECyXuHwl8qE7X/A1CImvNAl5uyTVhQIDS6NRRX+QQyOFdepng4FP+zmkTDfD6FdgmeOkeTPLnx3bwUHg1DwwAoM5o+RU7Gm4ny+VNHn3yzwEG0MXlvo8kVS9kFrrWYdZqwzhYu4QdjuPVym1wG5iHVdMkeoZrgvyvUlpLoQL59CABS5Euiw0CX4Zsj6aWIFELgpbr/AbEasbm5c60HR0GiAquA6Au01HsaiAl4fe6zldMBFypwSU186dfYW0iXNohOnNLl/2vpiZ/k03YzH6DKTevebxXmDf5QfS8+4FeYULiKWbDURgGSe0vlCxlENo6TyTig/88DBxtb5HTKaPLlaMD5v9SmTl6bEW+tCBK7HOtIgN1eAFGJEqbP/8qd3w+miCK297JUK9KVwg7neEUCTiB6ZHFEIpsAbBuFEyemKnMDWPK3q/DKeljQMUN6efEUHhAhT0Szv0hhVQlh3ABIuUlZviUcDlCo7nTkGlcfsxHaYg3l4BX0HR7V+/fTfrFU1BvtNy1OlW0gMn2gLsHX34gdCXNx1QqsR/jrmfOV+2tlR2X6HmU2CxKG1zM48DSgWaEx2tJX6j5Fdmj6mUK0q286Spsd19FObnHeTShIgmhZaezsmwMJ+TKfOplYFlki7ypFnwMpnlksgmTIHpAUqQi Yzasr1pw kHCLetPKAN2BrZxcH0NqMRRkHYTfGjQ85M8qIYtByQxdwBntImkQyug5df552NGPIYFyfTCMBqbwGpdD76Zf0RY5StbpE9GQyw4qNH8LmC3ykY/UzK8bDaDz3NKCIZCvSVnP02jPvlVtlHJY4Jw3m/MQAXek9k44HNpeYDdDp4MnyUk9Q1iqZ2ccCqRvtOxQgSr83Mj6N9l9Pb2vd2gZ/W6uxRKmApXesa4LEBxMZoI7yZ8+BGIIz11LyTLMuFDq7eOF3yb+1Vto6wnAvy7s2vMMRzt3hKht0Cmy/PIjCGaTOhvqdzXhbmtBY1BmsU6au4/xF/DngfeCFzucGp56IPWg6OyYovV1DEORzUccMsj5Ok+2KkePlTt6RcT9eftbAVl2RakPiNQNd+mcPp2DaPnnDUnun5KsHLIs+4b00ds3daxViNumnrBsySfHXyatUMIeJUr9p57sC6TbeV2AeHFlBHIAAQdhcHxHYF/d4LZ+xZs9mtTgl9HFeveZTsxwM7f/j X-Bogosity: Ham, tests=bogofilter, spamicity=0.000203, 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 Reviewed-by: David Hildenbrand --- 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 Mon Apr 17 19:53: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: 13214491 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 96BFFC77B78 for ; Mon, 17 Apr 2023 19:53:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 269038E0001; Mon, 17 Apr 2023 15:53:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23F1B6B0085; Mon, 17 Apr 2023 15:53:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B99A8E0001; Mon, 17 Apr 2023 15:53:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id ED20F6B0083 for ; Mon, 17 Apr 2023 15:53:35 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EDD97406A6 for ; Mon, 17 Apr 2023 19:53:33 +0000 (UTC) X-FDA: 80691932706.28.03E7FD5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.145.221.124]) by imf24.hostedemail.com (Postfix) with ESMTP id D0BCE180008 for ; Mon, 17 Apr 2023 19:53:31 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tf8u88+e; spf=fail (imf24.hostedemail.com: domain of peterx@redhat.com does not designate 216.145.221.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=1681761211; a=rsa-sha256; cv=none; b=D8ZcCawecMep8gPpsXQiFawGsbLsS21L3cY+GUEK99yB9T+9M0uqLmOziUUEADWM5EKPS7 9QcZlSGbbRqSGxSeNF+wYkg9655gxUfgSyIFBv9MBYduOpX4WKnQmVkhFf5In5UNOtPPA2 XTNPqXp7UaKz6GbITtJTM74lSxdc5CQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tf8u88+e; spf=fail (imf24.hostedemail.com: domain of peterx@redhat.com does not designate 216.145.221.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=1681761211; 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=bKARL3IrexsppLzPgsHthXh5jBWTTgcgQuviAuzUWURQXem9//1eWm8GsUomTF7KSUus4s iKgpitvFmPOstO3SUznqxAqR6Ynd1EmDYt5Gbv1aTy9DmSaeLm27XNy0GdmQSIvNE0LImZ +GILUGeBDoMh4Ea3uc4Cf/HC4IW9V4k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761211; 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=Tf8u88+epEWJXGLRprZSoxk4cdAPRPY0rewzIs+tX3j2WbnLQLGiMmgtImxlUymoKTlAn6 wCaqxBG1XjINeCoc621shbki4U7jn4qOMsNPH0dxjZ5emXoJ8EA667KJOQyue/4GICqgCm hTHjEbz3zzAdiErONminIFE6BWub8jo= 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-2-CZ1nmkKgMUOL7c-j2WG8TQ-1; Mon, 17 Apr 2023 15:53:30 -0400 X-MC-Unique: CZ1nmkKgMUOL7c-j2WG8TQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74ad69ad9a1so62327785a.0 for ; Mon, 17 Apr 2023 12:53:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761209; x=1684353209; 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=KCOLtjp4r5l5RhTLDFcRW/tJ6/wlY7XkzyRNI3Wfq6E4q0HhIDrbq6yLTaRc8U3juF 1Kmhv5HI+sZZc0PqRUMFYfs+E9Skwdkm4FMR4jdk+jfbKeyuUxq0RpYAwAois9gsgtb9 I5XlWLDQZGiHE5ODZT/D0VKWcoZa7j/hAUT/h7EEh8j1NOrBGleswhwffha1azztdY2B 7gUb2o58aNR3iOTw66idCvgmQjO81RQKgjwnpQ+oC984PTmSh1aMtY/nG9nfekIomUrN xdW+s52QqpmO/m+jaWTwckF5OaBwNmMxWmUpozy0QWP7r6Z6iUPUvI1zeyoeTkKaSW15 6URA== X-Gm-Message-State: AAQBX9dUTZxDFX2ddsPPbF1HuiWvx5ax/oYc1MnaM3h7jxQHRO2WCYA4 ZzPOR2TFUNhbIpESn4hBWPrWOcSc8NxekqV2CJ3ZhIpYwawEKQ0TiRwjpk4q9cbcwfC9z1f4v51 /vHhNK5+rCBQ= X-Received: by 2002:a05:622a:1352:b0:3ef:37fa:e1d6 with SMTP id w18-20020a05622a135200b003ef37fae1d6mr1229501qtk.2.1681761209320; Mon, 17 Apr 2023 12:53:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Y/Xr56P7wXtTgHgR9HpSg1x1E8ea69mUaTjl3roEaHjKyTAe98r0gM0V7aTgCT/jxwZH4gBA== X-Received: by 2002:a05:622a:1352:b0:3ef:37fa:e1d6 with SMTP id w18-20020a05622a135200b003ef37fae1d6mr1229477qtk.2.1681761209061; Mon, 17 Apr 2023 12:53: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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:28 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand Subject: [PATCH v2 4/6] selftests/mm: Extend and rename uffd pagemap test Date: Mon, 17 Apr 2023 15:53:15 -0400 Message-Id: <20230417195317.898696-5-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230417195317.898696-1-peterx@redhat.com> References: <20230417195317.898696-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: D0BCE180008 X-Rspamd-Server: rspam01 X-Stat-Signature: 8f4daec3izog7n7ed9wdsn1u1sz9cj1q X-HE-Tag: 1681761211-290510 X-HE-Meta: U2FsdGVkX1+HnZrGhq1auyMD4pRCCq5kuE9H3g2oPEaIjuvJUepNlT2xXwXrNf2QcCbMETiozShCbHa9rzXpqeeXmvgnVzC+ul/flHioZ6q3vC9gJU7ZSyDEV8+AM8VviGY1xf7w9Gk/EvIdQ6F7ye2MulritijMrhvnSkmWINOEbsgARFOH7F3/WCfXblqUojy4kID8IuuhU4UAA5thqedBT+5xRBXEF2lyN4KixbxEdfWgziqbj9K7S/ABg9pt9NxGE5ifEO67pZtU1Do/abRkF7L0q7adrbwJ9FsN2TbsERp4gUjx2jfQXO3yc74ILEJnWuG5B2iiDZp4Zsd5u3RRmROvNj/GrXctmr3UfZOCm99Iqh/wJnJ4xM9FDsUtOzpRDHtpN+Cz3486uPWD3nCbAvoO9inXaaSDCQG0r7UcOx6/EsDeSovSxrNKMm3CSl8tDcoB1HT/q5RdAmVrGgTrdr496xlK8Brzin/TKAuEK/Pi3CMs0iSY5F2SEel1HZQ13WJgDAoEZ8AtoVEOFq04OTbf2GdIZM6PZSSLBDO8yTuPH9BnSHCKjIbLY0jH1oPM2gLDQdXsiFwaNvXcG7LwRWW5W2WKDgvYTrxJYLjCa6z/rBRuJEMgbsFbNuuh8h2th7iWLjRxtDQcVjdXZhsVMOpB5gt0WAQhBcs+Vq94u53Ftg8yuJ83EDTEOJFUBFyLnFDpWK8VRXgN6VGUWXxrXeVfw+mkEB0+uaHpv3mLN1cEUYuHCq8tUaYZUtefqLzA2cQdcTwLN71Pw37DLxnEZznTDlj/XvE559IKrBMnXCo6SfqkD1NYFbMO+ZwC/9S+Z+9Lix9xzUJKcPRjQJEAFPNEaeRNlN6+dhojYe1vtyc92UU+yBtCXq+0S6JBWSbfq8v4YZ+Kl8omdZpqSOuoK2qJvb5V1gyrHQJN3Sg2zxthDgYXXqdCywxV3gtE9FyykpAuuXLl/GHrDK7 sCFWS4UB Em2lKKzDjWYO79lujq+BfguGJuZ5Zzo7W5i4RgasAPCCHDzQCuGnXJENpQaw3UgygNhprflhVO+IzFt0HvFTkTdRgLe9A7u8lQM9jMLvIzJrT7WXNwrm2hR9nQr2lff57KbNtBY8U5A3VGTqKGrv3y69pND+kIwaFqTbI2QteHzWMrt9VXr6hNtrWYtbMGi9pSIh0jUq72N0HcfWrN++FWs0AInHDkZE+aG+diwws4X2D3/uBigeqZ4ZApaUGWL99NyO24KE2kEO1TkrMNsKtgjPV8bJ7mJ6tsOg1lldFkjVMozr4OMLYvQ5PPNrd98D/UJ1erBBybLjM/Ca+iyTvHMnR2QAa4w1eunGesQ0pDL/78Q3M9y3ORPsk5ZaIqR8GkFffKmrqbqBS9iPka9bXPSzBm8MgJ8XCXpGnFx6tEk8Cyy9c5pbxzwQLr0TC+HqaumRxiEV3t+5VJZJLtlql3K3ov9UitRLnvNYeyNSd8VJB6kTcFQ80ztIJhQxgxbt3hT3fbAcRYpzatzb1g+SQXx1naSCWzuVbJpgPDMK8bd/F6V+6BwkyifUVV8M3maT8Jq3Q 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 Mon Apr 17 19:53: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: 13214492 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 342DEC77B76 for ; Mon, 17 Apr 2023 19:53:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB7E76B0087; Mon, 17 Apr 2023 15:53:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6701900002; Mon, 17 Apr 2023 15:53:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A12E28E0003; Mon, 17 Apr 2023 15:53:38 -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 88E326B0085 for ; Mon, 17 Apr 2023 15:53:38 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4FC49ABF08 for ; Mon, 17 Apr 2023 19:53:38 +0000 (UTC) X-FDA: 80691932916.15.FC0DA7A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 3DF99160002 for ; Mon, 17 Apr 2023 19:53:36 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XyNUCSLx; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1681761216; 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=nL6ukD3uQsP0j8aiX/3IiND2lFTW26LLUmGTHQFycOk=; b=iwUA6oYDYKjh2GfisPys8ta8ommneERhy6ALKcyQ82Gtus1DEWTqptgnMc9PPrTmjQAq/r Er9MAarPg/2y0SzXGB0p9MJgOI8tiQlxTpa1PoeAX0sV5LLQWrZmDCyrdaOfJRq6unGP+b i0G0NsK1dWXPCVgNuBB+/B3Eosyg0W0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XyNUCSLx; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1681761216; a=rsa-sha256; cv=none; b=DKzm3yA/37CWkNgpC0yNyaL+aszVhKp98u6jcbSpUDvkM4BpB+Ux5W2P3X7ZDATSsBSYW4 qkpmEovlQcf9DXxARmJKDyvWg6fU3hMqoifl0lGva26HczCcl3jrC6E7GQQxaQi6I0Lpxy Gu25AQH/y49TLyTm3r5r3PzVDjGjGOk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761215; 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=nL6ukD3uQsP0j8aiX/3IiND2lFTW26LLUmGTHQFycOk=; b=XyNUCSLxrpkDsuAFHwj7F042gQjeaTQZRASPB4/AbdNgppi2Iso2L9KoOq6gKg6Wr50A6U W5CtnjAvhZCXOKdaH3j3uBUe0yX62jq7BpPeDoyn4J0hO1MpVzsQ/SLEbabfSp8eYNlsxZ qyCjUZYO/OQF7QkLE9u/WkV2TXx5PRY= 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-98-LiP7VFIsPaW39EmLtnUdEw-1; Mon, 17 Apr 2023 15:53:34 -0400 X-MC-Unique: LiP7VFIsPaW39EmLtnUdEw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74accc750c1so34639385a.0 for ; Mon, 17 Apr 2023 12:53:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761211; x=1684353211; 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=nL6ukD3uQsP0j8aiX/3IiND2lFTW26LLUmGTHQFycOk=; b=B1Xq/aRrZfBLrvuiXDHH5QFc8v/lr869HaXX1CO8hhVOCp2BfDVwtIDlhDrr8kAIif 8IFQ+xde1R/DPUoUaUqJI6hJSem8v5uYFsPqfaoLbNCZUL7Xy5L75/ROd58bbpfBa9Oc gxAb7o/O6sdDhBnH1j1rlls5fudE+Y46m3kxuT6BS+9mm3sEkQholjzibZMJfbfiPxWw rNH5nQHkgOM3I2QhMQzj//UqisF4Nc++giYWgEWfmwAy+p7lor5tbL3qwgYuor3WDjCf kYPuHmhU/hTi7SKx40IkEsnRgGLRQrv9RNmntFQGH+pEFxajYw3JANJCTI7f0BDicLg4 DXZw== X-Gm-Message-State: AAQBX9chtLM0ScNJekF7r+/RMmCj6cbVhgSS8m35GXIC8kKWmu2D+Dxy 6oC5Ux30RF33q2LNc6Dp74iZmcqjPK3dQ4OGZTQX0QiNnumZ0kFGWYqSyXY9wezmpoL+z/dgdxZ atG/3N84KbUmVF4/aQYs= X-Received: by 2002:a05:6214:5095:b0:5ef:55d8:7164 with SMTP id kk21-20020a056214509500b005ef55d87164mr16879399qvb.5.1681761211271; Mon, 17 Apr 2023 12:53:31 -0700 (PDT) X-Google-Smtp-Source: AKy350ZYsrWygXMFCyj7XgLRO6y6vn18wQ8faUnma5Zhq/ehDr1HRYT9sovIA6wDuciwvG7UbAnfUQ== X-Received: by 2002:a05:6214:5095:b0:5ef:55d8:7164 with SMTP id kk21-20020a056214509500b005ef55d87164mr16879362qvb.5.1681761210964; Mon, 17 Apr 2023 12:53:30 -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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:29 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand Subject: [PATCH v2 5/6] selftests/mm: Rename COW_EXTRA_LIBS to IOURING_EXTRA_LIBS Date: Mon, 17 Apr 2023 15:53:16 -0400 Message-Id: <20230417195317.898696-6-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230417195317.898696-1-peterx@redhat.com> References: <20230417195317.898696-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3DF99160002 X-Stat-Signature: dd5en3xiqe6xwu49ps9fydy6wraai6h5 X-HE-Tag: 1681761216-574952 X-HE-Meta: U2FsdGVkX18N/am5zGuEf9D7rgFMJt7KffKKwRqpj3jgU1z9BSLAVDQJdukzI3tmAGMFFWzoJOvUkoF/jHoOP4z6gAM3Bq+Ll8BYwNPILiem+u6tCMBHoE79jYs6dd4lQ6F5RRt/WoDrY8CyvqjGbrzZ0RDXc4+sVo4gvbcQOoBxtq6UcyITloRTZktGfsyO0JacVl2Uc3kB5fLtx2EPUUy9LPs03Gc9DsFZVbr3LWlUDlX7md6iW1y4ekTGaiJ4SZc+cOQTXo2sbfpQACK5BUOSZLszSz2fasRHlxamg3x9gtOdaG9WtnFosWGASt9A8WDJiUzRe4b7hVQW/zhI5NgfkrzCdYfT6ospv81it07hP7C8UOPX/UJz7X1tm+OTBrQasePGQ2H20dsMwc7eMM1NUqA76t5PcvOuwfmOZ7yc2ZfG/0yykeVU7D7UlIuxTerejvkZgXM2qUAlmKhHpiV9+6pGnZufeZz/VyfjPif4dd4Cxqlr0JWfuroN3i0XvztdinMc2Qb2QQX1OKRFKIjk3HwpfaybpvLeB+ajXhAy9eRnlpVJA7uZ62hwJfpfBTVtD4atrMeg5gN0QVrpWeZDgYZJCUt+OcIn8BNf4fCCFlZyjs8LJ05w9Oobrm865hZ0JAmJyPZfU2AZB/lGwqpc6WXe89M2Y7DRf6VeX1tURFKMwmXcm1KcSLgoP4e7LI0NE1sGA6+TTwumTGHM5+kPMXQoLCrxaC50QZJFn98Jd02uyFHo2YOaA4yVT5p1GM9QGdKik7bEwtL7mIwFpJZoi9IdrSgYFWt1jxQYOG22GRR/soVLlruUD52UFtsq+wRpCltag5FU2oFaXXbt8JZwHzIDdRzbQj8m90X55ELY+c6fkoaLdDl4edIqaYdG12lliqfbNqbXgP+QqWjbvtO7Qmp9Nfs6xThTuyD9PL6dR+lW3Wiav2xASo8T3cPx/FF5Qd2pR0c3dUdqyxk aVtIbcRu lXu7nqlw9wqknGYVdyIHj1PxULBtEf0ClG1RBgCWuyAy//OxmZEXwSKDdB+q0TH/ONiiS/b1eEI/96WJv370LR2SUra241XmLE4j1osI2odzatP25jSIit/j2kndjAaMhAb+eI+lJ/Qs/Jo+6iGnWHvYFngvH9GF6xFjAIwm5BL/Hd89G8cW1VufPmK2DnMXPXzwsAOdx0CoGhED9jqHaK3HV3eT6Mq+MAGJotQl35BaNCBqJF7ChM5QbE52lXow61yhcxB3YFtLAczw0T29BwoSYAnvcElrBtEW1gMPPmfWWpjhWv/BbybclK7FBax93LMfsrtwlN7ELq2AVqpyfP6tEe++4niqMt0tlQhknW53CqBW7Fwy+YMg1rVDlIxL00+gBawZaNuIPyB0FyIrZSlXMeeBE+finLakuisPpp18x38gm3Lo90cWyj4kfszYE6LVnKYe/zI6qZhatODxMnfu6EqX6jG9rPUEoPEvKGTBFo5rF1p1us0N6QqlswOI9a9X5SLlpOi+5iGE= 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. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- 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 63c03a6414fc..0ee00769b53f 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 Mon Apr 17 19:53: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: 13214493 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 44755C77B72 for ; Mon, 17 Apr 2023 19:53:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9E9F8E0003; Mon, 17 Apr 2023 15:53:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE4E28E0002; Mon, 17 Apr 2023 15:53:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB6B66B0085; Mon, 17 Apr 2023 15:53:38 -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 9BCD38E0002 for ; Mon, 17 Apr 2023 15:53:38 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4AB6FABEDB for ; Mon, 17 Apr 2023 19:53:38 +0000 (UTC) X-FDA: 80691932916.22.F7E5DD4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 247F318001C for ; Mon, 17 Apr 2023 19:53:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pk4NV7oU; spf=pass (imf16.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=1681761216; 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=y7gltokQzFShDFjL1ksnnTsH6QcBiNJdLCM4WiStCBA=; b=DKG+UFPnpFjv4KRdjw10taQaDvS1PMf0T0CoeQGO+1ekV5X3ETYUWf+5cRbjMtLBOHP2As AEo29KUCSMhhppEUpMvYN7ai1/2AUuUtnzlF3BeLcdCtH3NLJ7r2zc08n5PhuqsbMCtv9T BCxPwfif7rJXi2UZVtRWICuvvgN69kc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pk4NV7oU; spf=pass (imf16.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=1681761216; a=rsa-sha256; cv=none; b=KKZeEpJsSv05kCfrEln7DJvE6X5P+g8QCCNG3QSdR+UnWX2eV4X0Uxp8qBXUa4ckenoq3w eHRGHoXDJBNF2QmUkHIOm+qlZQ8MSqEIGXfj2oO1IHCzBN3EgUHNSoV1mD2ABMWSsx+ZY3 2LUiuwGnyZgiq3RWVR1KaQCoH/jDq7Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681761215; 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=y7gltokQzFShDFjL1ksnnTsH6QcBiNJdLCM4WiStCBA=; b=Pk4NV7oUz4DgOZxvBuwnr8LJ1ph6mirwx6YH7eq8VZf3Qm3hpAFINCvRQeddPc1/rWe3Jz yWviLhObqD4Cyt7GvJON30cw+UCKpNvKMQvNKoIYyUJ5A3OaYM7Wt/Jidwiwdjp+ARyQDm QUHHy1r6Isr2bvPVjF2xvf9Sy0Vx7VY= 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-455-VOa5ZpRoMa-AVjf2DCg3lA-1; Mon, 17 Apr 2023 15:53:34 -0400 X-MC-Unique: VOa5ZpRoMa-AVjf2DCg3lA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3ef2cb3bfbfso4069031cf.0 for ; Mon, 17 Apr 2023 12:53:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761213; x=1684353213; 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=y7gltokQzFShDFjL1ksnnTsH6QcBiNJdLCM4WiStCBA=; b=KicB+/2faOCHbEMpD/xClx3Y6PXM+EKZ8cwN54idkrhGxXeGoF5p6QPt/jkvWS+rkn 8ITWwLXVsGFABVUom7mGpj+5vB/VjN20jwAhls6xsYK9U0AljQ6L2FaotFf4W8vXw+Fq 8pf3kkHeOwq/pUV7c4MXCif7+IMYN0UQg4GwM7Qm1ey+7bPWxjdXSqNnxgeEePLl3nIN he2HhKdArLW0hZMBhOf4qKCXUWemfr2XDcEYRCEdHDaWKbdFkwH8KRvf4Pu5UMd6iJjp 1eATHP9NNgPQd+mo6gU3LF+6wkjegwMQuF6L6LzrzrLVvMF7K9Yf5ohoOv7KJCubOk4e eU8g== X-Gm-Message-State: AAQBX9e6sglk9dIUX1VD/sl5Kxo1tobpLzzi4JL1uQo+VzW2etjr2MgF jLRzNR9HVFlWcqjX5NK99hvgxi4/nquPphPq4q3IOxSaY+fiKH2Ci7fexMhj/+4UcQqNTd0Iag5 KUmDTwkKVcRQ= X-Received: by 2002:a05:622a:1aaa:b0:3ee:5637:29cc with SMTP id s42-20020a05622a1aaa00b003ee563729ccmr9226099qtc.0.1681761213573; Mon, 17 Apr 2023 12:53:33 -0700 (PDT) X-Google-Smtp-Source: AKy350b6uFndWE+tj9O/onYcGkZ0fK6zrVlztfCRN9qHsXGXyZEKmCVQ7jywbyXKWj+B4rqOxPDQOw== X-Received: by 2002:a05:622a:1aaa:b0:3ee:5637:29cc with SMTP id s42-20020a05622a1aaa00b003ee563729ccmr9226079qtc.0.1681761213267; Mon, 17 Apr 2023 12:53: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 r17-20020ac87ef1000000b003edfb5d7637sm1731278qtc.73.2023.04.17.12.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:53:32 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Andrea Arcangeli , =?utf-8?q?Mika_Penttil=C3=A4?= , Andrew Morton , peterx@redhat.com, Axel Rasmussen , Nadav Amit , David Hildenbrand Subject: [PATCH v2 6/6] selftests/mm: Add tests for RO pinning vs fork() Date: Mon, 17 Apr 2023 15:53:17 -0400 Message-Id: <20230417195317.898696-7-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230417195317.898696-1-peterx@redhat.com> References: <20230417195317.898696-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 247F318001C X-Stat-Signature: 1midgxi4yssq8a19aoe9p1tkqhhodckw X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681761215-554936 X-HE-Meta: U2FsdGVkX18ETYmoPbUOTD1M5ohGKCXbQ0RU70/pm4NL9tjkIRrkTx7ls7xVrPklM/ivvbWiIBdoU5ULQRMPHcYbQiY1ujWVXKHmvbIlkD3bBc/d1k2xIRT35G+GuUwHGSdTHBhkxTKuyw80NMwKwEzset9LPGOCRQmr1tm1pz2AtxmCl8fA+Uf+7jQ8zHjQyJWfYlFQ6eBqhNnEngCOP81Hg21LYFwQZqll72Ix+O77ATqH0e/hnL2nkvCC/QZKPsINSNnXG9jQwejuw+lpNNpSRELMFAzuFCFb3uSNgrJhxxOINdXT+Y391z98Vscv3OM/7XLFTdrlch7xfi51thQT27ftdNv38SOoy4+j54+lMQELeMSZiyx89F9rcjZdH5PpgX9moMB3OU03HanJmif7i33utMhqQhkD3pBCeC0idrvwUm7UrksTzOWsdYQ1W8IF8B3qTOUWM3hEsqncGLxj0Wb5Xw25zxHLVmgoIcMXQ8ep+df8vN0C+7nLiwRy3vARay+TmlWjXftBpJnFLifhDAU8lbs8MH/WEQEalpIngCb98yJ0U0XJzCD2yqVoAbQ6XuJn2VZ/matovRtqfaY1dZtrDYUf96p/ig5aDiyySNS+j53QySUGfvO1Sxh+0Mp9hmvc/Vo51JtHRtcycW3p7DsKYfWPd+3qytq24TMPoFSz/YsYgNaxOAXh3C1+s4BQ0Oa4K29agM7w6oxjZMFM4nricay9BnMJhssqQ6m/2+imj2NFWzWlj+dogZCA3E9qLBjjONVzt4hD74DeRXu6ca7jI+IL3kzGhULWwhqL/1LsveUqruSVUH8/G4Cb0PNUowIrijCaJdG/A0qMKESoZceUeFUpyMGl10nIaUCJaNtxx6qCc0IF1P8h0dgQQvAfpgi9qXz9rA9D4+5Vz9/42ug5pMAa2p7/QTyWn3jWNnRYdnDI2T1n1khJ1CIP5jRF1RuHkW8nUKTWZwe 0TLo8cue DowQj87GRRAys+JyV0TTZ1Nd91u0PWgTxTu512jQYr0ShR4LlDhQU40is/2UehaZ4ZexBgDCr4NusyaCOa1KSmMmhWNzoad3JmjmlodQMFnCzlyCmKTRoxvNFN15osybBomniXK17Noch4yqDz42D3n2ATwqGaiMsIyd4xSH8HJ6amUybOmAOlTpJgntKtIREM7BV+03NJdbuVqiQJ6+KFjC/ZjyK8KbYCUzrfe171G5HaEOtVBx/TF9usU2/P871F+pogHu2SLMGU96HdprcG9IwS5YcX3/D7cbsu/l4j/3HERltsCYFbXtNz05RcwdbtByaO/f/aRw1TJbBlZMs8JoW3AFzmVehZGu3GdaWyDO18bkDRTEkWW0KnxVfcBiHi0kZTmVfJo1yeQvJrw7fUt4z0CGnugPQ1G7xaf/abvbmSjvLf0UAvr/m2NDr7mY73UE5+O1njr0aj/bfy5ZqZ0s2gxsPKitUMffk 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 a test suite (with 10 more sub-tests) 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 the major test goal is on private memory, but no hurt to also run all of them over shared because shared memory should work the same. 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,