From patchwork Thu Oct 3 21:17:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13821596 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 8A8A4CF34AD for ; Thu, 3 Oct 2024 21:17:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 127A36B009A; Thu, 3 Oct 2024 17:17:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A8B26B009D; Thu, 3 Oct 2024 17:17:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8AFC8D0007; Thu, 3 Oct 2024 17:17:32 -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 C4E828D0003 for ; Thu, 3 Oct 2024 17:17:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6862FA0C9A for ; Thu, 3 Oct 2024 21:17:32 +0000 (UTC) X-FDA: 82633552344.08.C90702C Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 9CFB0180004 for ; Thu, 3 Oct 2024 21:17:30 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JZoqyKP8; spf=pass (imf06.hostedemail.com: domain of 36Qn_ZgYKCDgYXfcUqaiiafY.Wigfchor-ggepUWe.ila@flex--edliaw.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36Qn_ZgYKCDgYXfcUqaiiafY.Wigfchor-ggepUWe.ila@flex--edliaw.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=1727990121; 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=KkHqwn8Bqw7l/s5v7I5SXTM3ejHc+yrhyoRwQ1tPH9Q=; b=G2PuF7ujQVf7llJeBXh51aaF/Ys/Gi9Vp/GjtbF8J5y5M2VlC4KriYvGtkJPdfWS+uPfxo t/4ECaC68zs8hR8RRf6jnHsiGP3ty/VH5ChWdgJj+Ty4Qm2DAjgbCjZfU+HYddrdJHqVNk 5MgEFTGFKLEAKEtqAETIMiRv94YgpWA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727990121; a=rsa-sha256; cv=none; b=IFNOVAO6His4e1wIb9LizyNl83++JBeTZJZB0u3Su+Wtj2IrQOt9+WhCwKi63cuXR0CoGW uV7UtIoYahbLpTPnMRw7Yd6QgRJd76EavNYhM2kJ+6KpO5Vk8uBR6WmLD8xV7tpF6Us8tK +/LoD4r6EhvzI+KFLhFwG/MWVHCO8P4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JZoqyKP8; spf=pass (imf06.hostedemail.com: domain of 36Qn_ZgYKCDgYXfcUqaiiafY.Wigfchor-ggepUWe.ila@flex--edliaw.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36Qn_ZgYKCDgYXfcUqaiiafY.Wigfchor-ggepUWe.ila@flex--edliaw.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e258c0e02a9so2266717276.3 for ; Thu, 03 Oct 2024 14:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727990249; x=1728595049; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KkHqwn8Bqw7l/s5v7I5SXTM3ejHc+yrhyoRwQ1tPH9Q=; b=JZoqyKP8Pvt27kskTDhvnTOgY/mw4w1qd1w2NL7GvsOtBcSFxWVWIP/rRVjhDE4kNa kUSMka/nPBOVqqpsX0tb5AtkWO00vATEfnBLBHv/i5rmhcjbKbzJZiHK0kJ4MBuiFw/3 yhYGNaMew3hZfaenveml3G3pRRlKPNcHn8MLkINfH/xGMkPpSHoxtaE/WbUTE+9kcB/T jUAn8bG5EMHe3oJXEp7PdDEiUycIAVkAD2krgfx4RnqxOAwLgsv5YKnEjO1V1rCRPZm1 vuL8OAIyhrAexr/Q6hoI7xZEQ18/AJX7kz1zA4ALoXt9dzdYoyff/o4eZGphxZidMmwb 4s0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727990249; x=1728595049; 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=KkHqwn8Bqw7l/s5v7I5SXTM3ejHc+yrhyoRwQ1tPH9Q=; b=mivpleDg/wruIOHiLMQiLkxmLuqWA8pwEseB7i/3lEiYyxaWVoaMt3E8+LaWJrm38W vp8KQfjFtSo7CmlWnbWFjJ7IDaXOd+E00aQD2tIYEXhj8x2zeWZW8fgiMqAbWT1ReTox l1kCa8fqXEgeTHbNHizQmvIQYQPY8hjK72u9vUxh/AAF3BTuaGUCtQIVFv6MI1+ZZUvC mDzp7tV7smkU1eSuD/x/PTI7HLPSWxMU4cBsGDFVT31ZfQLm0N2r9Dqjx2THItRD8z82 th157Jdcg5wKdDrFK13hYadn0aZnaykC1K7qAOB57LSaHNgcVxGJ5XVQOEeOG8rQJedh cg2Q== X-Forwarded-Encrypted: i=1; AJvYcCW/pL91E0V/VYLnUvEOjbxVt5Kw1jVGyT88N4wpr4+foKD+aabH0lp/6VgMGjJ2ov0wmTyF/KJCew==@kvack.org X-Gm-Message-State: AOJu0YwkHqhJNhBhcIViZTngPtdCZ5ThUTZTKXy+DLUHVACdLMPz4Fg6 0suwXPtGyZpaqFbfuSSSYjTCQ2e9ws22ZIIQDhiRsR3650hKiqbjsfvxpalKJwoSCm07EQJ+oIY HOw== X-Google-Smtp-Source: AGHT+IGgqrbal18cXmCsiQESftRs1395vmYgGSaXxFs9pt/ua0r8DPUXmkAbrXpoVABneX6qbZ8gjH/Q2zw= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a25:684d:0:b0:e24:a06b:1aed with SMTP id 3f1490d57ef6-e28936d26b8mr255276.3.1727990249428; Thu, 03 Oct 2024 14:17:29 -0700 (PDT) Date: Thu, 3 Oct 2024 21:17:10 +0000 In-Reply-To: <20241003211716.371786-1-edliaw@google.com> Mime-Version: 1.0 References: <20241003211716.371786-1-edliaw@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241003211716.371786-2-edliaw@google.com> Subject: [PATCH 1/2] selftests/mm: replace atomic_bool with pthread_barrier_t From: Edward Liaw To: linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Lokesh Gidra , Edward Liaw , Peter Xu Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, linux-mm@kvack.org X-Rspamd-Queue-Id: 9CFB0180004 X-Stat-Signature: o9f9nr4h4awrusrirsofikms5wphrjpu X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727990250-896764 X-HE-Meta: U2FsdGVkX1+ZOIFRXGt/hLeeD4MtLiWBlt4MVaBtlOb32x8gfEU92cIdV9oVhQaZL4kkVPL8iv+uGSVwlkyi7mEmjn/sL4vVo9IJBo2IGGSFggKuOFoi2B8IGL2VzjfxfMIj2ZJzFOizbFKpLZdTeUg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AXdayg/7mS4Nt5YT9W2Flfshh7i9gvgXLn9oshE3Pqpy+1WTyMbUAmB12wAUgKMm73sObOOXWbVO5/mx2oj5eYuF73YF+pqQ3pN4b2HLIpo6i0c+J+DZgKjuP+2ZKP7cIVkT1UJLmYn3BsKUvrAS7Nt1QW7j4sE2ova+eYakQA0HUroEotmFvefWkeTq2YOmHWrKxgfumuXBc6uLht/lHirX4uDGF7x7Fc/DepeYCzEKXOQvLJC9ohJ0U5afjlEHZPZjFvpa0CmQq1peGqh7cfdJFG3RcAYPtUmLRefqsyXcjRKmg/O4OU3aFrOH5l9EzqWcCs+ITiIM0PW7L85BgKCFNNFLgfTUwJ1Q== 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: List-Subscribe: List-Unsubscribe: Swaps synchronization primitive with pthread_barrier, so that stdatomic.h does not need to be included. The synchronization is needed on Android ARM64; we see a deadlock with pthread_create when the parent thread races forward before the child has a chance to start doing work. Fixes: 8c864371b2a1 ("selftests/mm: fix ARM related issue with fork after pthread_create") Signed-off-by: Edward Liaw Reviewed-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/uffd-common.c | 5 +++-- tools/testing/selftests/mm/uffd-common.h | 3 +-- tools/testing/selftests/mm/uffd-unit-tests.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 717539eddf98..852e7281026e 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -18,7 +18,7 @@ bool test_uffdio_wp = true; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; uffd_test_case_ops_t *uffd_test_case_ops; -atomic_bool ready_for_fork; +pthread_barrier_t ready_for_fork; static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) { @@ -519,7 +519,8 @@ void *uffd_poll_thread(void *arg) pollfd[1].fd = pipefd[cpu*2]; pollfd[1].events = POLLIN; - ready_for_fork = true; + /* Ready for parent thread to fork */ + pthread_barrier_wait(&ready_for_fork); for (;;) { ret = poll(pollfd, 2, -1); diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index a70ae10b5f62..3e6228d8e0dc 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -33,7 +33,6 @@ #include #include #include -#include #include "../kselftest.h" #include "vm_util.h" @@ -105,7 +104,7 @@ extern bool map_shared; extern bool test_uffdio_wp; extern unsigned long long *count_verify; extern volatile bool test_uffdio_copy_eexist; -extern atomic_bool ready_for_fork; +extern pthread_barrier_t ready_for_fork; extern uffd_test_ops_t anon_uffd_test_ops; extern uffd_test_ops_t shmem_uffd_test_ops; diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index b3d21eed203d..3db2296ac631 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -774,7 +774,7 @@ static void uffd_sigbus_test_common(bool wp) char c; struct uffd_args args = { 0 }; - ready_for_fork = false; + pthread_barrier_init(&ready_for_fork, NULL, 2); fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); @@ -791,8 +791,9 @@ static void uffd_sigbus_test_common(bool wp) if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) err("uffd_poll_thread create"); - while (!ready_for_fork) - ; /* Wait for the poll_thread to start executing before forking */ + /* Wait for child thread to start before forking */ + pthread_barrier_wait(&ready_for_fork); + pthread_barrier_destroy(&ready_for_fork); pid = fork(); if (pid < 0) @@ -833,7 +834,7 @@ static void uffd_events_test_common(bool wp) char c; struct uffd_args args = { 0 }; - ready_for_fork = false; + pthread_barrier_init(&ready_for_fork, NULL, 2); fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); if (uffd_register(uffd, area_dst, nr_pages * page_size, @@ -844,8 +845,9 @@ static void uffd_events_test_common(bool wp) if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) err("uffd_poll_thread create"); - while (!ready_for_fork) - ; /* Wait for the poll_thread to start executing before forking */ + /* Wait for child thread to start before forking */ + pthread_barrier_wait(&ready_for_fork); + pthread_barrier_destroy(&ready_for_fork); pid = fork(); if (pid < 0)