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: 92809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4583014vqo; Thu, 11 May 2023 11:28:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6J7hofKMHbG68WLZDy1M6fR8kcEo0QBT5tK2hgiddV/TxQ1FqvNzLC3V/V2X0KWqldor7s X-Received: by 2002:a05:6a20:1441:b0:101:8cad:6db9 with SMTP id a1-20020a056a20144100b001018cad6db9mr11724371pzi.47.1683829736741; Thu, 11 May 2023 11:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683829736; cv=none; d=google.com; s=arc-20160816; b=zQyBZdOZ0tbdfnYCfuSh3JnvnOFg5xvmpm3zKyaKYx+vpOuVw1uLgi5GD5HTB8ogUo FJeLK+pp61ZJRFdn3pwVKCPbxNDl7VIyaAXMtkn/+2aZkCDs+6ZvJEru7tlYJ1BJ7JqG s0X0kxUc09/ytlFT8MyVgqsFzstBnUSGrweNXc6ZrKvlAWRxCIPT2QsuoKUFEgdVtfSm KC81CwLvHewcrn0+wOTAB1PA2RyqMQRwTyamlgIF55mdDEEcdgymw3ZTK3FtNQEKhIj3 yyOb6md4/VkEcb4PwuLqyy2rcFcthQaPGlGevzyGiI22+TIfcgsoWQ42mBXmaiIPEj3+ WSKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=LjUrEJJ1UhaYRGAtGgSCY4PNxG4jgAwHbuTYYPklZWY=; b=zSxnRi+bjrQlC0pF+c9HdOcFpGB4NrIVr+bnM2omt0XHIWnm8HOF3DHeAdzEscLSG6 s88AgrACEp5M3x2AZsP7SLtQlVjXpICXuCPOmMDyXRKtMFMBbW4Ft+Myy7xUJn1gblRb fNR5dovHbPQcYcZv5BjWJK+XHWIuz6UwdioDcCBf4p/faBY1H859/FKVB7JLF826Wjs1 HI4iaKIctWeJVVJ8nqCBzZ4jG+JTBEitkvh17/7nmQsTu2dPxMFw/nHB0ssG9NAXoJtJ bjJCl1BVMacWa4CUPdojAE32fMDPGZl8b54wu4XBOWEFJk3eb6518GEnYr1fMjr4gxOi IF2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=55rn+NwT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a63184e000000b00513929a450esi6835593pgy.123.2023.05.11.11.28.43; Thu, 11 May 2023 11:28:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=55rn+NwT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238915AbjEKSYk (ORCPT + 99 others); Thu, 11 May 2023 14:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238838AbjEKSYi (ORCPT ); Thu, 11 May 2023 14:24:38 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A6795247 for ; Thu, 11 May 2023 11:24:36 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba22ced2f40so12588170276.1 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=Gbt9ndBEjqPwUjy88cc/9UADm2OT0etbASvLU4Q1lNMDqxocI6+0OOxIUhUiMmMikY yMm7Ah5Aef5FM4QCaKNjhzpVnqhvOKEruzipfr51GPv3Xo3yx7QRmWf7lrgU08LpCnFR iu5foEHxZcKU5VW8PAkaqxAb20bmm2iMaKXOw2D35gJixmG4bo/PPN1FxlXI9YHIUZFc NaSWbDUKtSI//hvatotuS+jHhKSrn0kLB46ldmggDTDy/4joYTrP3NwSglLZlCK5a7y/ tWtRzzS0SYGPQf5pV/a7TYdKSRqdZkF/z2T5VyelQncS76Qgo9M04KIffOZzfVoTc6hM ZlkA== X-Gm-Message-State: AC+VfDzo3Af8N4qFfNxRqszKSG9PUSDxbOYAAuEs97Cuv6dYVMEYg//J VWj4GSPrAcPCWuT6Lr1NjZIdRzNkR2/0NPc7dj21 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765623450075839865?= X-GMAIL-MSGID: =?utf-8?q?1765623450075839865?= 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,