From patchwork Thu May 11 18:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13238355 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 6529CC77B7F for ; Thu, 11 May 2023 18:24:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C52A36B0074; Thu, 11 May 2023 14:24:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDC2C6B0075; Thu, 11 May 2023 14:24:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E04E6B0078; Thu, 11 May 2023 14:24:38 -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 8E1706B0074 for ; Thu, 11 May 2023 14:24:38 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 51E3C1C7DBF for ; Thu, 11 May 2023 18:24:38 +0000 (UTC) X-FDA: 80778799836.02.C2A9449 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf13.hostedemail.com (Postfix) with ESMTP id 52AC420006 for ; Thu, 11 May 2023 18:24:36 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=55rn+NwT; spf=pass (imf13.hostedemail.com: domain of 34zJdZA0KCOYIfMTZIaUcaaMVOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=34zJdZA0KCOYIfMTZIaUcaaMVOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--axelrasmussen.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683829476; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LjUrEJJ1UhaYRGAtGgSCY4PNxG4jgAwHbuTYYPklZWY=; b=74WItFJrP5GX7cSvhz5bHBwPM5hao7Q0SFREAFdeUZISmBnfo3uSyS77GFF5w7WEGUhCQs eUxBgBVWzGkCBTSoZZfXG4D/ZyVaqCKSKalS/MwtMz8AzvTYmBStiePMm2uLTqGjzVJtZk zZu7TDM4cYL4JoOx9T78YRg7YJzEo5Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683829476; a=rsa-sha256; cv=none; b=SBTm87AT78FW7s5YiW0gTsl34u5uewwU/HXw8iofErBg3UDHALpE7/T8Nksu/4hw2OW1D8 rnTrS0YS9ub0CSeLAVjuxKO163oEoxqrFwyJVBb+RyXmkSmWhwR1+N3I7p3UdwA35nmzYT OeLJbEqxX1hVrDh6+vEc0NAUGSTUbhI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=55rn+NwT; spf=pass (imf13.hostedemail.com: domain of 34zJdZA0KCOYIfMTZIaUcaaMVOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=34zJdZA0KCOYIfMTZIaUcaaMVOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--axelrasmussen.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba2b9ecfadaso10144911276.2 for ; Thu, 11 May 2023 11:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683829475; x=1686421475; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LjUrEJJ1UhaYRGAtGgSCY4PNxG4jgAwHbuTYYPklZWY=; b=55rn+NwTS9qkN6o3EHQH9tg5nvgfFAoVfIi3Ps/Vx2UwN/K9+YFrkS/lHydkVA1cxR iowaGUww07beE3ntNfoSK93Fb1ceSg9jZe+0OTW9gkOExIsspD5MajhZSLmPMFNhTmMt gYuZl1WAugwIYddYiwJQaO7nq+GtN5jEQblGC1v623/h5p5sdc5Fgzt9DS2LFIrWogJ1 uW449MkphLCiIDXFZtwUGTOaENHChuPdfQqfcJ0QFEkS+4bIncJToGHvvADNkuPgQdkG R3TQXk6+FSc/Ziwfvc5dNOcdLIdSb14/ToPdMXENIjkpjZO8fNcFVpbUtLbpkbE1w/zq 6kkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683829475; x=1686421475; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LjUrEJJ1UhaYRGAtGgSCY4PNxG4jgAwHbuTYYPklZWY=; b=HHPeeEK/KEDqT60l4lUs79MrZ95RJ5DHVfugHkLXxcavXMeUYi8QsGKStjY73n9h3X tsrp9RL9/8J1FgyrHlj0hVLM9X3GhoF3B5hc/dHd+9W/WzAVP7+B+bE+jET7bs8tuZiR STKj7/yGT6zOIw7sHxPEhVIiShJG0lNQ1ZkFwHhnrVw9ffz4LQMO0BGBwTzzKyljkVvL c5C2KVIAapQNKp2o+REy6vgp00IBXddGnCgt4/OUKywVSpic87FDyhoczXZXhTk5HAug RJ8QLVMrtF6fnbLTA1VBp4iJS1yJmWiShflM4qUoOzWMke56gXT7cwxA5IjkZ3FN16Kc LOYA== X-Gm-Message-State: AC+VfDw1R3mWXfytvloh4z4py48vB3LAxe8M+etUu4eBdYalq/ePa7mK wrJ4SpWc/xYZzv3yNIm38+YWJCgz0U+lma/QceXz X-Google-Smtp-Source: ACHHUZ5tH1DV1GALQ1Ob1t3RTbPs1BmNd7Keg/peKTDa9epscPLL3nUgdVKOqLkDNSlWMLhG0C8f2l/D/e6LqknAyPsd X-Received: from axel.svl.corp.google.com ([2620:15c:2d4:203:1119:8675:ddb3:1e7a]) (user=axelrasmussen job=sendgmr) by 2002:a05:6902:154f:b0:b78:8bd8:6e77 with SMTP id r15-20020a056902154f00b00b788bd86e77mr14316791ybu.8.1683829475459; Thu, 11 May 2023 11:24:35 -0700 (PDT) Date: Thu, 11 May 2023 11:24:25 -0700 In-Reply-To: <20230511182426.1898675-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20230511182426.1898675-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230511182426.1898675-2-axelrasmussen@google.com> Subject: [PATCH 2/3] selftests/mm: refactor uffd_poll_thread to allow custom fault handlers From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Christian Brauner , David Hildenbrand , Hongchen Zhang , Huang Ying , James Houghton , "Liam R. Howlett" , Miaohe Lin , "Mike Rapoport (IBM)" , Nadav Amit , Naoya Horiguchi , Peter Xu , Shuah Khan , ZhangPeng Cc: Axel Rasmussen , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org X-Stat-Signature: 8d8hm1kepoheff1pmh9cfbhw44ez56uk X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 52AC420006 X-Rspam-User: X-HE-Tag: 1683829476-773733 X-HE-Meta: U2FsdGVkX19QtW4aVhcUN6G8APKZIdSI101q1i7x4qbb5D/hV2NEIVDkjk/MnW7Vf08nhAn/C1KRGGtn7ABH82oPtVutklxeLVJ0Fezl1LzzNdHQoJGrrQ6e9Q63+xjAvZk4VGAcSmZr6WuTwwwqS7NC2jtdp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q4vKNsRgJ/pNj/+thsDy82YVDZ1K0agE3WW2fnEOwIBmb+bScwk82YLrezmcK52PO3qrtQOVJiSp04yNHKK+vDHlMhvlmELPfJ0m/V7qeZpJYh7ohrEh4MF1zJeqi80MuWaNgOYt3A7pK6omHyOzbRwN/0BgQd9HvKA4W+uiNzxLUwhiKnZEA0i4cO8qawM9DijtHc03PPbFFCWqF34lsaRrk3v6+L6yEEd3tQFrVOu+eTFBONyUFEvSYU4KCUS+snv7G20VIXnknveMc6IdwShi2Dtftgyu0R6zIUtVZKdj/EU0fE2GreNtBsTW2Wh5hIUonzt6fqpy39q2sfSYlMYFiVayo2K+hKlGUqH9QgWuEUC3A7+6sr5YZ+qDiiCTNhgOTJLJy9Kcmaavl7EUUwvaGe+FPRLtAwK4itUU3eZd6XVBIRRxwSnXc4uEfIkUAqoKs= 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: Previously, we had "one fault handler to rule them all", which used several branches to deal with all of the scenarios required by all of the various tests. In upcoming patches, I plan to add a new test, which has its own slightly different fault handling logic. Instead of continuing to add cruft to the existing fault handler, let's allow tests to define custom ones, separate from other tests. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/mm/uffd-common.c | 5 ++++- tools/testing/selftests/mm/uffd-common.h | 3 +++ tools/testing/selftests/mm/uffd-stress.c | 6 ++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 61c6250adf93..c9756dbffe7d 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -499,6 +499,9 @@ void *uffd_poll_thread(void *arg) int ret; char tmp_chr; + if (!args->handle_fault) + args->handle_fault = uffd_handle_page_fault; + pollfd[0].fd = uffd; pollfd[0].events = POLLIN; pollfd[1].fd = pipefd[cpu*2]; @@ -527,7 +530,7 @@ void *uffd_poll_thread(void *arg) err("unexpected msg event %u\n", msg.event); break; case UFFD_EVENT_PAGEFAULT: - uffd_handle_page_fault(&msg, args); + args->handle_fault(&msg, args); break; case UFFD_EVENT_FORK: close(uffd); diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 6068f2346b86..b28d88b9937e 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -77,6 +77,9 @@ struct uffd_args { unsigned long missing_faults; unsigned long wp_faults; unsigned long minor_faults; + + /* A custom fault handler; defaults to uffd_handle_page_fault. */ + void (*handle_fault)(struct uffd_msg *msg, struct uffd_args *args); }; struct uffd_test_ops { diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index f1ad9eef1c3a..47e1464935a8 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -199,10 +199,8 @@ static int stress(struct uffd_args *args) locking_thread, (void *)cpu)) return 1; if (bounces & BOUNCE_POLL) { - if (pthread_create(&uffd_threads[cpu], &attr, - uffd_poll_thread, - (void *)&args[cpu])) - return 1; + if (pthread_create(&uffd_threads[cpu], &attr, uffd_poll_thread, &args[cpu])) + err("uffd_poll_thread create"); } else { if (pthread_create(&uffd_threads[cpu], &attr, uffd_read_thread,