From nobody Tue Nov 26 08:33:26 2024 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1225204009 for ; Fri, 18 Oct 2024 17:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729271887; cv=none; b=VStiXTPurOStx+oMMmv+8unXKwEBM5B7okxKIg8pf/bl+JMNWBHuWoGoV5uiVRUwZ7XGXYunhcEc3XMDCm2ZyN3fFZNqaGda9KtP52XppnsSCuXMIVq5trXvHaoJ5sqJ2PKXkj0abHTNXbW5wRPBUPZIQq4Smgs171GWF80Zop8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729271887; c=relaxed/simple; bh=+ENvV6jp4xly72yGU6pYCi2Z9gHRmWJGCF79OSN5WJo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Dv/90qF0HjIakT7ViVHmM7BA8lI8OHFzVl6TBWzeeesptcAFVb4fIU9sBAQrbIwQKnltPhTqs/SURpTLBkovoxE5CC2h7jnI0gCXqjtART/4DBSsVf8gFSLmXUtvpoa1onJ6ubTk5fS2gGvVUoD3yxmo3FqwOmJugfNFGlfcBmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=j7rCSTF6; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j7rCSTF6" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e29facda92so2646393a91.1 for ; Fri, 18 Oct 2024 10:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729271885; x=1729876685; darn=vger.kernel.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=09rqkYzv1mj2i541CG3quDs2Oto4Z5t/2Gr1EPh2MJY=; b=j7rCSTF6uath0EDHr79tpDSZrVXkdSv6A1vgi3o3+Lrcx/qH230Dvj7iAsCwBgbi2U iD5/C79JM+dFeadoKVP1bablz6eVhgYStpYi3caz45dV1PyI1f3vSvNrBZ+KHNYkPH7H QWSOnQlNYttYkTdNcrQ80OD5259LKq8Ndl1CRz+nGT2esTmJVjSYXLYOKLqPuY9cj0lW eI3tr3P/3HVEAcBKnPq9yg6E6PnmflP5iARc2iju4a5Ihfnng00I5TcbuYZ8CCAxv/eG eU0ampj4EAVoqGakmWoxEOcxCHBM5MvFHS7QiCQFYoJzbC4mmB6XXWij5+ih6VN/yZJ8 LlpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729271885; x=1729876685; 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=09rqkYzv1mj2i541CG3quDs2Oto4Z5t/2Gr1EPh2MJY=; b=JXe5Bap4oE+jqkkfeDx2d7DNBhovbaUSXLQwDc1VqWZx9PoDsTKkkNuL7prgE3tXlT LqrPwdLqQavVDz9zcEwxJ1R2i+hj2aK7DPMHZkt7X27yXcR5JB5w732VSw8ANemsvNxz KlWaY7k+T4O4N+TdKmXzYgR+6UTq2dN/F4NA+F4t5jUxOQ0Sm/eMjMszPq4Ju8oeEdEP lzdG5d4JgoKc0uknL9RyDJcOL8oF0n4WdlRf6qsOcWhoByH39gJOse6QqBt0IFXoOk4v guDwlChFXuDCUnsgmZnHAzWbG45BOKDHDO2uIAZC/s3ywhXr96/Usxc9WJyOaIzyxzIG owwQ== X-Gm-Message-State: AOJu0YzH5lG4N2GccEqWlu2YvSTkq+3tDDbC94PrGaCZDd3JG+NzU9Tb wHyQTiJfaDrLOMl8AT5AyNAq0pm2P4GcdOKxFuOMnTNLQyXYvioa+ocKIHJrSeahH/gpiWbjNPa tHg== X-Google-Smtp-Source: AGHT+IFCzoFKtcQsGl5HORvI+qdsZRNBp3NS1MD2ovvhIYOdGqZKLlvaQri87EIXebpvo+p31wOY+8NUM+A= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:90a:dc02:b0:2e0:72ab:98e9 with SMTP id 98e67ed59e1d1-2e561511115mr9463a91.0.1729271884764; Fri, 18 Oct 2024 10:18:04 -0700 (PDT) Date: Fri, 18 Oct 2024 17:17:22 +0000 In-Reply-To: <20241018171734.2315053-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241018171734.2315053-1-edliaw@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Message-ID: <20241018171734.2315053-2-edliaw@google.com> Subject: [PATCH 1/3] Revert "selftests/mm: fix deadlock for fork after pthread_create on ARM" From: Edward Liaw To: linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Edward Liaw , Peter Xu Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, linux-mm@kvack.org, Ryan Roberts Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit e142cc87ac4ec618f2ccf5f68aedcd6e28a59d9d. fork_event_consumer may be called by other tests that do not initialize the pthread_barrier, so this approach is not correct. The subsequent patch will revert to using atomic_bool instead. Fixes: e142cc87ac4e ("fix deadlock for fork after pthread_create on ARM") CC: Ryan Roberts Signed-off-by: Edward Liaw --- tools/testing/selftests/mm/uffd-unit-tests.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/s= elftests/mm/uffd-unit-tests.c index c8a3b1c7edff..3db2296ac631 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -241,9 +241,6 @@ static void *fork_event_consumer(void *data) fork_event_args *args =3D data; struct uffd_msg msg =3D { 0 }; =20 - /* 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)); =20 @@ -311,12 +308,8 @@ static int pagemap_test_fork(int uffd, bool with_event= , bool test_pin) =20 /* 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); } =20 child =3D fork(); --=20 2.47.0.105.g07ac214952-goog From nobody Tue Nov 26 08:33:26 2024 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 809CD204008 for ; Fri, 18 Oct 2024 17:18:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729271891; cv=none; b=abIKIscx0reiW/RRfqbHXN2v040iIzk9pUa3YjSCRrEvdc+8Gv6PmfvKa19g8d+j+baqMiC1MtjLzce2WijC/mDVxASYN6P0BhqFDsxJBPayiv4nxT/B6nVvRts3lp0TuKW4VUPD3iIMNIH949YRIT/fKQb1o8e6Gmzq2HymUAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729271891; c=relaxed/simple; bh=dk+2Ao6eBpxXZJV7TRzBnZbcedhZSUClpihRKk8bXbI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fJIB4NX2GTRgUaLUakQPrzh2dw2HGyAptQnkBVTCTXo1g27dTeDlmpfh38VJpnpiP79DjYDEo1Ke+oYJjGKE7BP2er6kltBrDEIbXBJZaBbnO9vcbYMi/5Kjc7ep/rBycyeeAvLgIOXv+WdfC4yJaQtTsFazqIQeyCOBj5EeZuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KpSm8Rxr; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KpSm8Rxr" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7ea6efcd658so2069196a12.3 for ; Fri, 18 Oct 2024 10:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729271889; x=1729876689; darn=vger.kernel.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=UFQHSO14/jAsIAlP6YyLD1M4ZuBPXyCrx6oOfYWGU30=; b=KpSm8RxrYr55Npp2bcvPnLS05eEC2nBVpbBPkdlZ/Rk16b/Iic2onQ0TlySUvtiNbu 88quujpBumZhGCAUJWV/bMhfzlNgmDV0iZUUPgpOsav1XJ8YP16MoC2+pXQs5nnZaIvP /VyOgGK2oweUgvrtD+B3WqcLFDuZekHaBL8IilJz7UZuosTXS+xOQrJGLpgaS1W6ciGX wkTU+Y8eRw5h+ZMg60D7bTtrSleAfP0UOfqlTGr4W4oqCXVkqHaTSLNfvQfEgNPSoYGd Z4/0J/N+oAP8d2McOo8oQPVDjtSiFdjYFQeM22KFVvWbPsGM7j7bHbCSaWDCEavksbNl 2v+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729271889; x=1729876689; 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=UFQHSO14/jAsIAlP6YyLD1M4ZuBPXyCrx6oOfYWGU30=; b=fcwZ3nlw7jIfXkNHkVwei80wg3SfrGfAs5NHeCJVPoUjkQlPdM8+LlwXTzBJFC1w46 L7vUy5rrcyqQ4ltW40VahnmU5t20rxa40TN8mmoqSgvsVrIjRtv3M0jT577LpkIDNEAX BW9vb9oyVxlKz7nVihL6UqPqDFgdh57x1UMHns6s5dVsTmIJjVJLVT57lzN7nhyf6fzH EzoO6rS3n5Y7gcjJeFBbv5dW7msVMnFcGBvabzZSOH8lKZRR9zWRr04SfxkOGLIN34aZ vZ8+43MMwCAoOOYB7Kv+H2w4HdDeXldVNzA6C/ePVqwf8btIHXKj5G+3JqE4oNDqyDGU gZmQ== X-Gm-Message-State: AOJu0YxQjIv/cmufAwAiFnV/599B2Csln5eLX2toWuy0VZVqjZZDQxIM +PFV3ws0dtHHkYnqWSmQc9SLYR1zgffJCsIkhR5NqzqOeLRI7o2/vwQ6+RX5ldrwDuYwVeDsdzi NHA== X-Google-Smtp-Source: AGHT+IElgKqKmBxxYFR30EicUCVFsCvFx4Ofclcxsw9+z9zau8/mq1g11dMoqL/6qwWZQUMW1ChAG57xdLs= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a63:3858:0:b0:7e9:f93c:22b9 with SMTP id 41be03b00d2f7-7eacc895cf2mr3205a12.10.1729271888448; Fri, 18 Oct 2024 10:18:08 -0700 (PDT) Date: Fri, 18 Oct 2024 17:17:23 +0000 In-Reply-To: <20241018171734.2315053-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241018171734.2315053-1-edliaw@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Message-ID: <20241018171734.2315053-3-edliaw@google.com> Subject: [PATCH 2/3] Revert "selftests/mm: replace atomic_bool with pthread_barrier_t" From: Edward Liaw To: linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Edward Liaw , Peter Xu Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, linux-mm@kvack.org, Ryan Roberts Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit e61ef21e27e8deed8c474e9f47f4aa7bc37e138c. uffd_poll_thread may be called by other tests that do not initialize the pthread_barrier, so this approach is not correct. This will revert to using atomic_bool instead. Fixes: e61ef21e27e8 ("selftests/mm: replace atomic_bool with pthread_barrie= r_t") CC: Ryan Roberts Signed-off-by: Edward Liaw --- 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, 10 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selft= ests/mm/uffd-common.c index 852e7281026e..717539eddf98 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 =3D true; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; uffd_test_case_ops_t *uffd_test_case_ops; -pthread_barrier_t ready_for_fork; +atomic_bool ready_for_fork; =20 static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) { @@ -519,8 +519,7 @@ void *uffd_poll_thread(void *arg) pollfd[1].fd =3D pipefd[cpu*2]; pollfd[1].events =3D POLLIN; =20 - /* Ready for parent thread to fork */ - pthread_barrier_wait(&ready_for_fork); + ready_for_fork =3D true; =20 for (;;) { ret =3D poll(pollfd, 2, -1); diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selft= ests/mm/uffd-common.h index 3e6228d8e0dc..a70ae10b5f62 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -33,6 +33,7 @@ #include #include #include +#include =20 #include "../kselftest.h" #include "vm_util.h" @@ -104,7 +105,7 @@ extern bool map_shared; extern bool test_uffdio_wp; extern unsigned long long *count_verify; extern volatile bool test_uffdio_copy_eexist; -extern pthread_barrier_t ready_for_fork; +extern atomic_bool ready_for_fork; =20 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/s= elftests/mm/uffd-unit-tests.c index 3db2296ac631..b3d21eed203d 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 =3D { 0 }; =20 - pthread_barrier_init(&ready_for_fork, NULL, 2); + ready_for_fork =3D false; =20 fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); =20 @@ -791,9 +791,8 @@ static void uffd_sigbus_test_common(bool wp) if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) err("uffd_poll_thread create"); =20 - /* Wait for child thread to start before forking */ - pthread_barrier_wait(&ready_for_fork); - pthread_barrier_destroy(&ready_for_fork); + while (!ready_for_fork) + ; /* Wait for the poll_thread to start executing before forking */ =20 pid =3D fork(); if (pid < 0) @@ -834,7 +833,7 @@ static void uffd_events_test_common(bool wp) char c; struct uffd_args args =3D { 0 }; =20 - pthread_barrier_init(&ready_for_fork, NULL, 2); + ready_for_fork =3D false; =20 fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); if (uffd_register(uffd, area_dst, nr_pages * page_size, @@ -845,9 +844,8 @@ static void uffd_events_test_common(bool wp) if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) err("uffd_poll_thread create"); =20 - /* Wait for child thread to start before forking */ - pthread_barrier_wait(&ready_for_fork); - pthread_barrier_destroy(&ready_for_fork); + while (!ready_for_fork) + ; /* Wait for the poll_thread to start executing before forking */ =20 pid =3D fork(); if (pid < 0) --=20 2.47.0.105.g07ac214952-goog From nobody Tue Nov 26 08:33:26 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA0F42040A9 for ; Fri, 18 Oct 2024 17:18:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729271895; cv=none; b=LK7gL4Nyn3ZY9lAKN6KOxzfksulz+27bP5FBbsXj69D6gzwUdH4opZRHH/xCmziwtaKC4EjuWZJDg27XAgPN5VYsXSFNUlMXlXay4M8JmE6GR5itBp1lFnpa2A22Qk24o4GenSw7HtAxeKDu2zvGgwWZzVYaHHHJblbAd/vLPlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729271895; c=relaxed/simple; bh=hE7oRewSRIwjPXZwf3rEvS9LnJl6BbPZ+AoeFZLef0s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fO6cQ0iY9F5FZvGnU8kYIyy3lGWIsjzAfVwM2O/OjXpwjKpWC9nC2z7W1VRF3fiTHWFO+Q3BMGWI4h2hLd31udS1bKJQmR4pRSD+1TL0S66nmEr4iri1s8JDoQf0ZQcps5Vxbw6MWnm5e6SSdUfMMDQnEH/RTatw61sdN9PeAvY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WBgT7Qj8; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WBgT7Qj8" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e17bb508bb9so3880907276.2 for ; Fri, 18 Oct 2024 10:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729271893; x=1729876693; darn=vger.kernel.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=dqicHt23y2Txc3ltQfz9r7Ld+Ys6zd7l3ho/WLmRnAI=; b=WBgT7Qj8ZsqPbDiwgmq6YgD84bUCH3CGJAQCPU9cdEf/4ALsZTgVvsjVZK0k5fSQZG 2MKuwjom24kcqrmIBDeNYQo06/lDL20BYyIxk4i1kyZVGTEQqcmU2SSWgJESYQVj4tNG kFpAjjIlOLqPpUStXyoVEw460gZ+0CynJt6HtTNbE7ApFtE2SBioj4mRQTmprKRsfzi8 rf2jYrASH23IKupKaof6NY++2nrlZg8SJiRawtXdQuKK+9m4316zvM2Qah6CANao4wzW jmV9WIstskir3W4pez1nXtfLGdsdGsuSzC8SH5WmalQCwwgZk3KnQoX/8EpXRml/CYN+ 018A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729271893; x=1729876693; 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=dqicHt23y2Txc3ltQfz9r7Ld+Ys6zd7l3ho/WLmRnAI=; b=EjtY/0m4//0zeeRwHRs8dWrifdAGPUiMxWmh2GvEzRS66lygusRsjdIuBmSkQBJCRv eoYDR4KnHQvMGJh5eiSQ56fbtkBT8wWQig3LevXGMAWXlFu3CmJUvCD9ihMxkeS78+cg BLGHX8UV5cJgpsO7P49i358b7lICj/n4JHcuk6xHIG5bMUsk8/+/8NKqaAjL+AiFdKYG /7VmTyaXHH7jcsYJSqp4yEYHFm1j99Wdoj4H9577RJ8iIViNxC1s2H1CkVHRdHX6nlYA Dan59wfQhxtomjqHD3HdJ/+dBvJ7AANO5AcGfjkd7vdFtoTxjzd3baByhx/Yjeal91x2 H4Mw== X-Gm-Message-State: AOJu0YwDlsa2LuobO+mKQ9E+V4USrLHhlBh7x1Lr/wuS4gNtkRJly4Xz OERBKBZWDKIIocufbJwdmY0/H3qhN2bcWdWk+CYeeovj/T951nuG6mOB3e7eX6Q7fWYh9aLmmMZ VUg== X-Google-Smtp-Source: AGHT+IETe8cpTBCpQKyA4kbFf3lNf2xFOaZ0iITih7uovjfurWUIEAi/snUf1XNhONUTm2/f6zAtyiP2pUI= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a25:360c:0:b0:e22:3aea:6eb5 with SMTP id 3f1490d57ef6-e2bb158a8cbmr4986276.7.1729271892276; Fri, 18 Oct 2024 10:18:12 -0700 (PDT) Date: Fri, 18 Oct 2024 17:17:24 +0000 In-Reply-To: <20241018171734.2315053-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241018171734.2315053-1-edliaw@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Message-ID: <20241018171734.2315053-4-edliaw@google.com> Subject: [PATCH 3/3] selftests/mm: fix deadlock for fork after pthread_create with atomic_bool From: Edward Liaw To: linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Edward Liaw , Peter Xu Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, linux-mm@kvack.org, Ryan Roberts Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some additional 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: cff294582798 ("selftests/mm: extend and rename uffd pagemap test") CC: Ryan Roberts Signed-off-by: Edward Liaw --- tools/testing/selftests/mm/uffd-unit-tests.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/s= elftests/mm/uffd-unit-tests.c index b3d21eed203d..a2e71b1636e7 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -241,6 +241,8 @@ static void *fork_event_consumer(void *data) fork_event_args *args =3D data; struct uffd_msg msg =3D { 0 }; =20 + ready_for_fork =3D true; + /* Read until a full msg received */ while (uffd_read_msg(args->parent_uffd, &msg)); =20 @@ -308,8 +310,11 @@ static int pagemap_test_fork(int uffd, bool with_event= , bool test_pin) =20 /* Prepare a thread to resolve EVENT_FORK */ if (with_event) { + ready_for_fork =3D false; if (pthread_create(&thread, NULL, fork_event_consumer, &args)) err("pthread_create()"); + while (!ready_for_fork) + ; /* Wait for the poll_thread to start executing before forking */ } =20 child =3D fork(); --=20 2.47.0.105.g07ac214952-goog