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) From patchwork Thu Oct 3 21:17:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13821597 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 E3192CF34C3 for ; Thu, 3 Oct 2024 21:17:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D6196B041F; Thu, 3 Oct 2024 17:17:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 785176B041E; Thu, 3 Oct 2024 17:17:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64E486B041F; Thu, 3 Oct 2024 17:17:37 -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 3FD916B041D for ; Thu, 3 Oct 2024 17:17:37 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ABB46A0CBD for ; Thu, 3 Oct 2024 21:17:36 +0000 (UTC) X-FDA: 82633552512.27.FDFC95D Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf11.hostedemail.com (Postfix) with ESMTP id DD6BE40016 for ; Thu, 3 Oct 2024 21:17:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=xMX95Dij; spf=pass (imf11.hostedemail.com: domain of 37Qn_ZgYKCDwcbjgYuemmejc.amkjglsv-kkitYai.mpe@flex--edliaw.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=37Qn_ZgYKCDwcbjgYuemmejc.amkjglsv-kkitYai.mpe@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=1727990214; 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=BVeNglwTN7akCXDmRlldGSc/rW6sZdc88WuvUouG7/c=; b=aZMsAeHcsSgkhoMQTmWkxhhkF5H5VEVKi2kcsF1hOqIbIqJjx4qey6okVZUZM8cevbxKnF HsqcwgOSs9nYOL509eLU/vlsEqSBYs+nI6njHbaXb6wKbbynxT/iiOi2FgOLXzIxgYjWWy eMZ3WVI7MJ7QHwa5klaKSPX8xc4L7Uw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=xMX95Dij; spf=pass (imf11.hostedemail.com: domain of 37Qn_ZgYKCDwcbjgYuemmejc.amkjglsv-kkitYai.mpe@flex--edliaw.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=37Qn_ZgYKCDwcbjgYuemmejc.amkjglsv-kkitYai.mpe@flex--edliaw.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727990214; a=rsa-sha256; cv=none; b=ESVK00jw49KMYLmiHIbstdfTSiAdJJA+IYgd5X2uSVnw83JR0H97z+YENHhJCLKpY5ya8U SqFocp+tI+NXgYNuZU5BG2UR/pWYS9/3jgjN9HMBn8jC8/xjhZxFpUJnFWMgH67dCDsxsT EfBa3MUsTtYFLMooQeioppSEKmDAgm8= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7191f154abdso2458472b3a.2 for ; Thu, 03 Oct 2024 14:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727990253; x=1728595053; 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=BVeNglwTN7akCXDmRlldGSc/rW6sZdc88WuvUouG7/c=; b=xMX95Dijb8+ee+xLUg5sUH1Qrwq2b+7uR2EjGfiRUzbd63lLbQe5SV0h/BN/Cdi/U0 U2i5X9JoRXW0nNAOScZk/2zhgJyb5qkU89Ao8RHnYWxVW02RjIIeCoUpErUZv1skW9/m DgUvX+CxpXI6lFqZsDcdPIgIGCME/6VQrMjwx1R6r9lqyNfN/mOAPCctYQz5lQivUMoK bi3mXIM1dmQdF9Vy6MxKbwjOpHCL6qU+WcNEtQdY4FOokl1stxhxlScW5cphkaVWAn6m dOY873UaYZUScivMViXhXgVwAfkKjiKJ7V2mxa9MfJgWosSRUSLJnGJJapwRPwYKM/0S wf7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727990253; x=1728595053; 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=BVeNglwTN7akCXDmRlldGSc/rW6sZdc88WuvUouG7/c=; b=cDKZa2KgPG61ArJpSux+zD/v0Z5r67/GouZcYUtaja4qct5akgqv6eO5ASKvJfYrqY VNUyQDGuysQwa0EBuIJqEnYasx/xYclAIz4NWWgg09ko3w8CO7gVM6YKgsZh8sgRYtcD bagG0HZ+aYD83G+U3+Dh7g37DzgAV9jY2QVBuJSr0k3rvzWYyZhiz6dZsSuiFzZ2ZntG 4qWxwJqUj5htMDme4iLNpybjh+hSFXcPAObhMz29d/XfDOSRcSrgJq20gavylx1IFkqH VfCXdlKQgrNt6ztbU8pi0I/1jeVXZ3E8uFTy16CHIEkBfLn0/lF8r5GBj7nTq8fQiwAK oXVw== X-Forwarded-Encrypted: i=1; AJvYcCW6X9MQgqApEevDE4Yci7SuHf8Bw7aSpS9lU73g7BXfUWyCSrYgkLETsXA0owe/PuSmD3mR8oG9bA==@kvack.org X-Gm-Message-State: AOJu0YwdbZhOoDQHjN48GnsfuqZvB1AhY688ZWyJVrJNIp/blwtSzduY LI/Afr61PXqrsZwLK/ETj2NVuTqnBmdLCTudxO8xiqJlVesNJk7tP26ow4BWRDjaASK4wBzaHEN kkA== X-Google-Smtp-Source: AGHT+IF1wAIWxriS35+1+9s9R25YDFII/xuSGjwNB1DYXJzZFTeclXhMlYEUs67ru5vh0bxduTAAmrtUyuM= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:858b:b0:717:8e0f:3e5c with SMTP id d2e1a72fcca58-71de24930e7mr686b3a.5.1727990253229; Thu, 03 Oct 2024 14:17:33 -0700 (PDT) Date: Thu, 3 Oct 2024 21:17:11 +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-3-edliaw@google.com> Subject: [PATCH 2/2] selftests/mm: fix deadlock for fork after pthread_create on ARM 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-Rspam-User: X-Stat-Signature: cmiojgfnuwgwz3n9igrhzj6rq48qk147 X-Rspamd-Queue-Id: DD6BE40016 X-Rspamd-Server: rspam11 X-HE-Tag: 1727990254-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bHjw0vo7C1Uc65LWgzamn4WSP1oNotdhMmuO+2rYyWJHqk7vdTKIXfGSBKKhdaXzhDHeWW3S1ZTpY9moePyH7TIsfE17+xws0JxQ3nokQfO6dnrm/xaYCOkCjxqx2vYjPTTgZ1djZzdY8EW694Eml1EYWyoaQxPEQL2xXvY1aUsqD/ZjIecl6pyu/fIrUDnQv3Y1MxL8ah2/H+tYvG5aPR3H22rqfAYac6z86MomEZIvMvFaepAeVc63J8nsIyrlcx6Bb+VJ0WyzCy4qZIOBBw99xa+p6knJVl08x9ufUdjCsNQ7OpcDuFNqVDVTVdZ4ADmw25qmZi0OxXOhDt7EAmpauy875UeB2uGYP7+ePCKzWtePrxodh6aInn3xmTFMse+pVYs7MYG/t9xWR0XqXXjnM7ZZoSy2S7Ow3xZRWFe7O5FH5pW9EBVlehWKqg0Awx4Ns6LLpemoWDbiR+pzW8ebDJedWHT85lHvcQw/jsKU+8CSSkWIiCG6+rw93pFsp72UzRzulw/BPioGw== 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: On Android with arm, there is some synchronization needed to avoid a deadlock when forking after pthread_create. Fixes: cff294582798 ("selftests/mm: extend and rename uffd pagemap test") Signed-off-by: Edward Liaw --- tools/testing/selftests/mm/uffd-unit-tests.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 3db2296ac631..c8a3b1c7edff 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -241,6 +241,9 @@ static void *fork_event_consumer(void *data) fork_event_args *args = data; struct uffd_msg msg = { 0 }; + /* Ready for parent thread to fork */ + pthread_barrier_wait(&ready_for_fork); + /* Read until a full msg received */ while (uffd_read_msg(args->parent_uffd, &msg)); @@ -308,8 +311,12 @@ static int pagemap_test_fork(int uffd, bool with_event, bool test_pin) /* Prepare a thread to resolve EVENT_FORK */ if (with_event) { + pthread_barrier_init(&ready_for_fork, NULL, 2); if (pthread_create(&thread, NULL, fork_event_consumer, &args)) err("pthread_create()"); + /* Wait for child thread to start before forking */ + pthread_barrier_wait(&ready_for_fork); + pthread_barrier_destroy(&ready_for_fork); } child = fork();