From patchwork Wed Apr 12 16:43:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209357 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 7BCF5C77B6E for ; Wed, 12 Apr 2023 16:43:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12CD2900007; Wed, 12 Apr 2023 12:43:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08EF2900003; Wed, 12 Apr 2023 12:43:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E23E5900007; Wed, 12 Apr 2023 12:43:54 -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 D1AE3900003 for ; Wed, 12 Apr 2023 12:43:54 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8EF344014E for ; Wed, 12 Apr 2023 16:43:54 +0000 (UTC) X-FDA: 80673310788.30.89ECC8C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 5003880025 for ; Wed, 12 Apr 2023 16:43:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UiSBdCkX; spf=pass (imf02.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=1681317832; 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=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=AsnlWDIsTzUmd/K6pNJOAGMcHdYnrrubSdFyAqw66G1wb7QVBmFHsC52sbka/PtwIl01W7 Mlqoc09daweWWL+SOd4cbWwZyl7WamXrYEvCjW8Eq8Sx35ORdK8ouDgFY6NCqYwnYbeGSM akURmVImjxJ4hTZ3uKgrKR/4dCAgabY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UiSBdCkX; spf=pass (imf02.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=1681317832; a=rsa-sha256; cv=none; b=nCXH/KMQDOpvyMMktJqpZUQp8fBxtxECt4lJg0jaDVbmeUpFCd+DKyqPNrMwpu5/zZuLwB QQXiIQtvikKTj7jyrLT/+NHqlLmPZLGbnyf1uTgYHqAzEc8vFZqq0x+aMHXdnVrS3uNZ2X mgpTHogsXGSrVDMvaIW7Cnz7IZ7J2Sw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317831; 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=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=UiSBdCkXjpcG9J1AOia8qgAmMg9tQ/SRB8wjXCpU5wUmRsgmnM3P4K7Ugog5xrYgMM3c25 L4+25BWRROxxiPRWlIhWHyxQJw9ifMYjSdLczW/bs1zze8lwF5TFmIVYfsZQdMU/jPPzg5 9wBE6R1a+euTFX4rRFyTJOfu38+ztG4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-4sTvk3cwOpCxMGknIyacxA-1; Wed, 12 Apr 2023 12:43:46 -0400 X-MC-Unique: 4sTvk3cwOpCxMGknIyacxA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3e947d81d7dso268101cf.1 for ; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317825; x=1683909825; 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=BeK25Zk7G/NLwTDOVvJddw9Gyk0/O/quMsTWu17keu8=; b=LSIPchYdGVCIBeQXTKEITqnLSBhM1CrPTSUgXlO4smZmBIo/FdnVrX60KHO3jrRTHj U0HdlXINIHp9nLwNmzioxxpEMmylA2OXiqnTjsEN2GmViZWVSm4ArvrMWwS/AoTKBpwd aCOzhZ8BT7xyIO0N+Jgn32juJ+XYHh5NrWXoLq0eDdSNefSUoqsFRfhWJHhh6EAwLA05 hY6hQVMFr0S6eyDvXv4NVPJ/xk1zUAI0Z/3CbYUE2ob+eMS2Xdw452yRQLz3ozKX9TAt 9OODsIaGuolztZi9FBftIkecH5VjDojI0YUjF64XKwmlFpNQZjgbWgDwKcLclX1vgTWc btvA== X-Gm-Message-State: AAQBX9cxLnoZ4fbPaUeuiGl8nwXtehAKM0x0b99RdDRK1JYlbui6Sfcc bJmUtFpghTPIElE5FChts252O4ehAjJOyxYgx4IyMxsQmoENF6OB0qmG074u5h0HKasSb0PhEzO 4uxwHZzsYzhk= X-Received: by 2002:a05:622a:1891:b0:3e4:eb39:eb8b with SMTP id v17-20020a05622a189100b003e4eb39eb8bmr4000937qtc.5.1681317825450; Wed, 12 Apr 2023 09:43:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Yl7mWL/S9YEy9zUWOoxCG4PHHcn5sGAnl7GyY2m0LveJWRNpcSER8LkzrTOjY9Kd6J0F5tgw== X-Received: by 2002:a05:622a:1891:b0:3e4:eb39:eb8b with SMTP id v17-20020a05622a189100b003e4eb39eb8bmr4000915qtc.5.1681317825147; Wed, 12 Apr 2023 09:43:45 -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 i18-20020ac860d2000000b003e45a39ed74sm4353141qtm.81.2023.04.12.09.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:44 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz Subject: [PATCH v2 20/31] selftests/mm: Let uffd_handle_page_fault() take wp parameter Date: Wed, 12 Apr 2023 12:43:41 -0400 Message-Id: <20230412164341.328618-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-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: 5003880025 X-Stat-Signature: dqumg8oqgrpw1xjeiohfpx1pyeixymoi X-HE-Tag: 1681317832-250734 X-HE-Meta: U2FsdGVkX19LIJOe041C4iHII2v9JcBbI5VjsHKvCAzGsoC0R5rKTtuUM2J30N0/2yOYKA4kX1kWcCPwG7/8p7FVWjXwjpp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gU2fsdZ3qx8Mb7uW+yCiFTVY9hsGVDMKJNYeHnpCcg7TkoK+RrTJ0SgInkyv5T5RB7j0o8ZkNQzZPQSNytiFx3B0ddPfRilEfLX1mqpLubZ9uDK2byrv9fZtMIKNrz8UqvDQcYDU1gyI8ddigWUmJ2m+0kakd21RKD/WcNyfPipgZq+6S4QUisoBb+mWx4P1vaxpZKLa1el1W6e1/+ktMNTWvVCXTFkqdS5FvCdbBtD16xeci2id5X27pLR/SsoDYLxRN3AdJxJTQDXrXFSWkpHndHbAI4QVlA2e9WsXW5AS8g4GfZxhzZEPz7qYUygAwd++OA6xt7DWoj6E2JTURIVBpd1luKtR4NI= 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: Make the handler optionally apply WP bit when resolving page faults for either missing or minor page faults. This moves towards removing global test_uffdio_wp outside of the common code. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 17 +++++++++-------- tools/testing/selftests/mm/uffd-common.h | 6 ++++-- tools/testing/selftests/mm/uffd-stress.c | 16 ++++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index e746405aa8f3..daa2a95408e6 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -353,7 +353,7 @@ void wp_range(int ufd, __u64 start, __u64 len, bool wp) err("clear WP failed: address=0x%"PRIx64, (uint64_t)start); } -static void continue_range(int ufd, __u64 start, __u64 len) +static void continue_range(int ufd, __u64 start, __u64 len, bool wp) { struct uffdio_continue req; int ret; @@ -361,7 +361,7 @@ static void continue_range(int ufd, __u64 start, __u64 len) req.range.start = start; req.range.len = len; req.mode = 0; - if (test_uffdio_wp) + if (wp) req.mode |= UFFDIO_CONTINUE_MODE_WP; if (ioctl(ufd, UFFDIO_CONTINUE, &req)) @@ -429,7 +429,8 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args) area_dst_alias)); for (b = 0; b < page_size; ++b) area[b] = ~area[b]; - continue_range(uffd, msg->arg.pagefault.address, page_size); + continue_range(uffd, msg->arg.pagefault.address, page_size, + args->apply_wp); args->minor_faults++; } else { /* @@ -459,7 +460,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args) offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; offset &= ~(page_size-1); - if (copy_page(uffd, offset)) + if (copy_page(uffd, offset, args->apply_wp)) args->missing_faults++; } } @@ -555,7 +556,7 @@ static void wake_range(int ufd, unsigned long addr, unsigned long len) addr), exit(1); } -int __copy_page(int ufd, unsigned long offset, bool retry) +int __copy_page(int ufd, unsigned long offset, bool retry, bool wp) { struct uffdio_copy uffdio_copy; @@ -564,7 +565,7 @@ int __copy_page(int ufd, unsigned long offset, bool retry) uffdio_copy.dst = (unsigned long) area_dst + offset; uffdio_copy.src = (unsigned long) area_src + offset; uffdio_copy.len = page_size; - if (test_uffdio_wp) + if (wp) uffdio_copy.mode = UFFDIO_COPY_MODE_WP; else uffdio_copy.mode = 0; @@ -587,7 +588,7 @@ int __copy_page(int ufd, unsigned long offset, bool retry) return 0; } -int copy_page(int ufd, unsigned long offset) +int copy_page(int ufd, unsigned long offset, bool wp) { - return __copy_page(ufd, offset, false); + return __copy_page(ufd, offset, false, wp); } diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index f8d2ad178827..0ec07d025cfe 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -72,6 +72,8 @@ /* Userfaultfd test statistics */ struct uffd_args { int cpu; + /* Whether apply wr-protects when installing pages */ + bool apply_wp; unsigned long missing_faults; unsigned long wp_faults; unsigned long minor_faults; @@ -104,8 +106,8 @@ void userfaultfd_open(uint64_t *features); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp); void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args); -int __copy_page(int ufd, unsigned long offset, bool retry); -int copy_page(int ufd, unsigned long offset); +int __copy_page(int ufd, unsigned long offset, bool retry, bool wp); +int copy_page(int ufd, unsigned long offset, bool wp); void *uffd_poll_thread(void *arg); #define TEST_ANON 1 diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index ce7251ab93ef..747d588c0d69 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -96,6 +96,7 @@ static void uffd_stats_reset(struct uffd_args *args, unsigned long n_cpus) for (i = 0; i < n_cpus; i++) { args[i].cpu = i; + args[i].apply_wp = test_uffdio_wp; args[i].missing_faults = 0; args[i].wp_faults = 0; args[i].minor_faults = 0; @@ -155,7 +156,7 @@ static void *locking_thread(void *arg) static int copy_page_retry(int ufd, unsigned long offset) { - return __copy_page(ufd, offset, true); + return __copy_page(ufd, offset, true, test_uffdio_wp); } pthread_mutex_t uffd_read_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -308,7 +309,7 @@ static void sighndl(int sig, siginfo_t *siginfo, void *ptr) * This also tests UFFD_FEATURE_EVENT_FORK event along with the signal * feature. Using monitor thread, verify no userfault events are generated. */ -static int faulting_process(int signal_test) +static int faulting_process(int signal_test, bool wp) { unsigned long nr; unsigned long long count; @@ -343,7 +344,7 @@ static int faulting_process(int signal_test) if (steps == 1) { /* This is a MISSING request */ steps++; - if (copy_page(uffd, offset)) + if (copy_page(uffd, offset, wp)) signalled++; } else { /* This is a WP request */ @@ -507,6 +508,7 @@ static int userfaultfd_events_test(void) true, test_uffdio_wp, false)) err("register failure"); + args.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); @@ -515,7 +517,7 @@ static int userfaultfd_events_test(void) err("fork"); if (!pid) - exit(faulting_process(0)); + exit(faulting_process(0, test_uffdio_wp)); waitpid(pid, &err, 0); if (err) @@ -551,11 +553,12 @@ static int userfaultfd_sig_test(void) true, test_uffdio_wp, false)) err("register failure"); - if (faulting_process(1)) + if (faulting_process(1, test_uffdio_wp)) err("faulting process failed"); uffd_test_ops->release_pages(area_dst); + args.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create"); @@ -564,7 +567,7 @@ static int userfaultfd_sig_test(void) err("fork"); if (!pid) - exit(faulting_process(2)); + exit(faulting_process(2, test_uffdio_wp)); waitpid(pid, &err, 0); if (err) @@ -628,6 +631,7 @@ static int userfaultfd_minor_test(void) page_size); } + args.apply_wp = test_uffdio_wp; if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args)) err("uffd_poll_thread create");