Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp187588lqz; Fri, 29 Mar 2024 12:54:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUSeW08T5z606nqfaZNl8PqJ5kf4DDX4Ev9oD41LvneasPaZ566yKrl/84V5H8BfSE4So8ReYrFlhGUZRehNvdFEQzFA1wSl1OsLha6Q== X-Google-Smtp-Source: AGHT+IF31Q6GpcOc9FJkcJNzqD1962AX/8Q2UKJoxqFQVzdBVweMlVyihNJrPoWuO0yJinCyoD4Q X-Received: by 2002:a05:622a:1742:b0:431:523f:85d1 with SMTP id l2-20020a05622a174200b00431523f85d1mr10127370qtk.8.1711742061079; Fri, 29 Mar 2024 12:54:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711742061; cv=pass; d=google.com; s=arc-20160816; b=btqajr3BPlNw5cm4DefhwU1UEtDGKtRR3CxBsQ9AaYIUeY4x+n/d7YQ/2QCSq5Hb2s DvR++dB1QT8LDRPnQ/N/TMFWolFGMlOA5ZtXI05c+P5S8hubC6oCCtdJ4s5KUGXkuGMz kvZtizhPJKzlCRk7YPLXFFfwu2OuM82nhVZGD11XTN5BKw8nbdzpq8Vyn2ywbJN0EOyu fNGavMJ/jc2jVXTbIE22IMG7qhHhm+705W5r9mA+dDgQpW15NUBZAw+xiD4iJKCaeozs K7ai3DyZz4bouEXtzWhBQER3XosvI24VvowpmXW1BXHLkxxqQN+gn69W8EqKHoYIjDVl UbOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=G/k0Q/Cqu4caC0vRXY/1WMaPVU0yKqTUoHv1iZWn3v0=; fh=n1blAugKy3pCtIoNjZi05Jo4/A1oxGGVbu8UlDEkioQ=; b=ybM9qS/97hy4hJTO43ou0jZbvLon8PNDOJ3mZfP1zbR6db4V3n1ufYybcOPlTp54wp bnCwNXWums0UXuYcUQ4XaGudTIQJLOF9un4sJHd1bYYvmq8W2+s//yuRnTr/497VdWbu CXwvvNBV5idtSFfGMCpDD2eQJ0YsLdOxznhC3L/mYGawj49EwWiWsY9Y1P8MKtEVKdNo BuZ0t5R9ovmpr7apSjePP+Iy6EP1HnnDDAHK352jiYAiBCbIYh6u8/iOayvCizVhFwcl uPswKSO75btfY0bcr2WHZgJWfdt0+n0ejgML4w9ToI5XObambb2z/eJYwrCFe5apNOQv 9jOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GKkycvFk; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-125368-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125368-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o9-20020a05622a008900b00432b7689f42si3845322qtw.101.2024.03.29.12.54.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 12:54:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125368-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GKkycvFk; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-125368-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125368-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 324221C21C62 for ; Fri, 29 Mar 2024 19:54:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C1D313AD1E; Fri, 29 Mar 2024 19:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="GKkycvFk" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59E8F12FB12; Fri, 29 Mar 2024 19:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711742046; cv=none; b=ouE3rxCtJwhYADvaQnL9nlupheQcLw3+NdASrliPDQTsPbYAZh03TwttJnaEuGKCs+ylQgVLeNzleQbL6BOyvd6XwcVFBr4ilxwjUUjeb6KnmBoNFPSjdYOYOU9W8J3IaCxXdX83HKXQOvydbM39sgHd1VEX4Tk/3p3UC/NXvbE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711742046; c=relaxed/simple; bh=7FIgZdhSuFmBFq7x61DjTJQ6bzsgrfBW8fIPAWIE+MU=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=n6PikM7JyVbcz/ILB1pCaYVakWY7coAO0Q1F8epSZlNYh3fiZU7PcQUw/opb/qrJKXSpns6vPxsdE3opxDLzMku8PdSH01/QlSC9v+Qz/ZUbkHQD8vkPOMWPjfC3id0ysxdyqZ1+UJRYSMynWFOebhGytOV1nHSM/Ipvl4V5CZs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=GKkycvFk; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1711742042; bh=7FIgZdhSuFmBFq7x61DjTJQ6bzsgrfBW8fIPAWIE+MU=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=GKkycvFkCWp+5HTjbw8G0xXWaauEjnFnSHlwt8uaT6BT4Bg/7HmDKPatTDArsxdRm G+Lcy90jN5PMAcqWlHcl/GVZpMc1HPY/ckbwi0RXmo5Qjp0g3WKVHfyOd5TX79bwWy CfRH41Gu6cQjnLTEUjGg9EcODbPekwDb+vR3jzVzkx7zrV0z2AzNMnat27He8ow+dV UGZ1nAyaT1MDSBBJuGm+sMND3htxnkklKcJUZbF0+3ECEj/PIbmBFV+XfUKNE2vMlP PRmK74mnrrbVPG6NMDXqSyk5PY/vQDEyX9XWJ5pRTK1+y9pgiGeO/N5kkwJyYRUBFy Ba0POAplPiXKA== Received: from [100.113.15.66] (ec2-34-240-57-77.eu-west-1.compute.amazonaws.com [34.240.57.77]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 94ED33781FCE; Fri, 29 Mar 2024 19:53:50 +0000 (UTC) Message-ID: Date: Sat, 30 Mar 2024 00:54:20 +0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , linux-kselftest@vger.kernel.org, kernel-team@android.com, Lokesh Gidra , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev Subject: Re: [PATCH v3] selftests/mm: Fix ARM related issue with fork after pthread_create To: Edward Liaw , linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Morton , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Jann Horn References: <20240325194100.775052-1-edliaw@google.com> Content-Language: en-US From: Muhammad Usama Anjum In-Reply-To: <20240325194100.775052-1-edliaw@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/26/24 12:40 AM, Edward Liaw wrote: > Following issue was observed while running the uffd-unit-tests selftest > on ARM devices. On x86_64 no issues were detected: > > pthread_create followed by fork caused deadlock in certain cases > wherein fork required some work to be completed by the created thread. > Used synchronization to ensure that created thread's start function has > started before invoking fork. > > Signed-off-by: Lokesh Gidra > [edliaw: Refactored to use atomic_bool] > Signed-off-by: Edward Liaw Reviewed-by: Muhammad Usama Anjum > --- > > v2: restored accidentally removed uffd_test_case_ops when merging > v3: fixed commit subject to use selftests/mm prefix > > tools/testing/selftests/mm/uffd-common.c | 3 +++ > tools/testing/selftests/mm/uffd-common.h | 2 ++ > tools/testing/selftests/mm/uffd-unit-tests.c | 10 ++++++++++ > 3 files changed, 15 insertions(+) > > diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c > index b0ac0ec2356d..7ad6ba660c7d 100644 > --- a/tools/testing/selftests/mm/uffd-common.c > +++ b/tools/testing/selftests/mm/uffd-common.c > @@ -18,6 +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; > > static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) > { > @@ -518,6 +519,8 @@ void *uffd_poll_thread(void *arg) > pollfd[1].fd = pipefd[cpu*2]; > pollfd[1].events = POLLIN; > > + ready_for_fork = true; > + > for (;;) { > ret = poll(pollfd, 2, -1); > if (ret <= 0) { > diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h > index cb055282c89c..cc5629c3d2aa 100644 > --- a/tools/testing/selftests/mm/uffd-common.h > +++ b/tools/testing/selftests/mm/uffd-common.h > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > > #include "../kselftest.h" > #include "vm_util.h" > @@ -103,6 +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 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 2b9f8cc52639..4a48dc617c6b 100644 > --- a/tools/testing/selftests/mm/uffd-unit-tests.c > +++ b/tools/testing/selftests/mm/uffd-unit-tests.c > @@ -775,6 +775,8 @@ static void uffd_sigbus_test_common(bool wp) > char c; > struct uffd_args args = { 0 }; > > + ready_for_fork = false; > + > fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); > > if (uffd_register(uffd, area_dst, nr_pages * page_size, > @@ -790,6 +792,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 */ > + > pid = fork(); > if (pid < 0) > err("fork"); > @@ -829,6 +834,8 @@ static void uffd_events_test_common(bool wp) > char c; > struct uffd_args args = { 0 }; > > + ready_for_fork = false; > + > fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); > if (uffd_register(uffd, area_dst, nr_pages * page_size, > true, wp, false)) > @@ -838,6 +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 */ > + > pid = fork(); > if (pid < 0) > err("fork"); > -- > 2.44.0.396.g6e790dbe36-goog > > -- BR, Muhammad Usama Anjum