From patchwork Mon Mar 25 19:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13602833 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 C987FC54E64 for ; Mon, 25 Mar 2024 19:41:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 615A06B0095; Mon, 25 Mar 2024 15:41:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59ED36B0096; Mon, 25 Mar 2024 15:41:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 418906B0098; Mon, 25 Mar 2024 15:41:07 -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 2A9326B0095 for ; Mon, 25 Mar 2024 15:41:07 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0BD7A16050C for ; Mon, 25 Mar 2024 19:41:07 +0000 (UTC) X-FDA: 81936579774.26.FCC6C75 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf23.hostedemail.com (Postfix) with ESMTP id 54C5B14000E for ; Mon, 25 Mar 2024 19:41:05 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=BJCrSoTV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3T9MBZgYKCDQUTbYQmWeeWbU.SecbYdkn-ccalQSa.ehW@flex--edliaw.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3T9MBZgYKCDQUTbYQmWeeWbU.SecbYdkn-ccalQSa.ehW@flex--edliaw.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711395665; 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: references:dkim-signature; bh=cX0Tst/fD3eEaDcxw6zP7p1X7prwnotLNua44hovj0E=; b=eQy3YS8IQ7Ie3155Z6Z+styI+jy4UyqMnop/tGMcJl8Fc4PSgzrT/WBJ8qDRANXWLBMELs 6ASNRujyVYTYPj7+nFwxqTLCGvsRQi1g6Mu6N9JJADtsfZjADRMZ7cQ8QBQSY7mPFxMsE1 vLMg8u9cG+cY2Zap0BcRgiyHmwL9UMk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=BJCrSoTV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3T9MBZgYKCDQUTbYQmWeeWbU.SecbYdkn-ccalQSa.ehW@flex--edliaw.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3T9MBZgYKCDQUTbYQmWeeWbU.SecbYdkn-ccalQSa.ehW@flex--edliaw.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711395665; a=rsa-sha256; cv=none; b=70Hb1BZi2R9XVmmO8mb6g33Jn8NaVP+sF2/YyflIQIuY8nwFBtODJPx37P4CjQLjiwuY+5 ijs3mjRxIkkh7jf8gMsRdrxkOyN0ylaK6tIOvVze/TbP5aks+fMEPnwGnneLN+e8LaGJdU F9LdqKzbAK+99UNrqTOS8W9+v7Nfufk= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1e0a5e0c734so11772965ad.0 for ; Mon, 25 Mar 2024 12:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711395664; x=1712000464; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=cX0Tst/fD3eEaDcxw6zP7p1X7prwnotLNua44hovj0E=; b=BJCrSoTV4Gn4d28nhduikh4odJkIZYxGqbR9Nr1cEBS5yWvn409DgwDKEZTWHKeUE9 f+Ux2tuyB/eupYo4wsdq4d2tTyWnSIl9j86o+iPVp1PJVUxo2gAZFrcfe2Wzj0h67Zhz 7PpImFJz5PS1WkfT303fQMjlbO8rATdubOUxoSyoaTf7oEBb83hlWJfIWGALyfrP2zMk CTyIHlDan9tNRXgkIqeJu3kAng1VtLhAwVNR/B9hBuVDKjfG66pn0H2ilckuhCA3oWdE x7pt9nnUroTmkP8RzrW2f5mzQkBAPko2z6obxlSsV4RVjUM6v3HHqid/iplw+6jXomkk cw7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711395664; x=1712000464; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cX0Tst/fD3eEaDcxw6zP7p1X7prwnotLNua44hovj0E=; b=LlYmgAVdDh6GgOolMaszeM4jD6x5+Scni/N7BlsDypjrf46If1accsT1M5z8M25+tx jesIFB9ksUAeQun2+gbNqQGHlE48+hV+/vhg8pQwAFtbjBDE9g5fwFjP2anh4SxFVESi E2/CYbd2VwzlIdcdZWT7BbaQWYMy0qiuDZLP563snGTAxYFI4aKL+K9vgL1hT1tqlYI9 DOiTrtv/CjiabA24MVybPS8RE9fJHeChaa/9/0KJRoC4B1o/KjVFRp6kN1H8Cx2/r8Xn h6AJWsCp5RMHt87CrESoFxj7veKv52330sLzgm79iRdAXCf88T5RZlGJPy8yDRwWrzg2 FGiA== X-Forwarded-Encrypted: i=1; AJvYcCUSUrB7CTuzRw1i37mBQxa0/JcUo91S3F2Wz+7P4zPb0Q9rAITF2WgrsPUY/pOrXruOJolYFlRYz3hOv33LfkKQXt0= X-Gm-Message-State: AOJu0YyssB0ozwM8nNsRXmPqICLne0yhy55LwFavXPwind5sJwooHGFI 1cW6usqXIGGCvapSwlwjBC0eeXJIIXI1dm3XVExhRFZUiUFvr13cV8xzpGQ/cxqp0+gvHALOXf0 kkA== X-Google-Smtp-Source: AGHT+IHu0ZTXU78B+0X+LXpELIc87+D4aJxq4bKR0NhoBZQXd5O+HZEP47xhnKe66UWD9zpspAK+wE700/M= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:902:d2cf:b0:1de:f18c:ce4 with SMTP id n15-20020a170902d2cf00b001def18c0ce4mr662860plc.0.1711395663954; Mon, 25 Mar 2024 12:41:03 -0700 (PDT) Date: Mon, 25 Mar 2024 19:40:52 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Message-ID: <20240325194100.775052-1-edliaw@google.com> Subject: [PATCH v3] selftests/mm: Fix ARM related issue with fork after pthread_create From: Edward Liaw To: 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 Cc: linux-kselftest@vger.kernel.org, kernel-team@android.com, Edward Liaw , Lokesh Gidra , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev X-Rspam-User: X-Stat-Signature: t9jidpd5557jz1chpphq3cx4rj3kzab6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 54C5B14000E X-HE-Tag: 1711395665-359622 X-HE-Meta: U2FsdGVkX1/MRN2+43kN9Sf9d5rnX3QroBX77hRo7G3a3FVrl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zEQS2D9sD4rie2eHz4Qg6BX/nZBwbQ0iYdie5esuihrHONKkaDpacNMcnFoqwt/LDKzXEq/BBTpc55gMMJz61/39Qj6cC/c4tLlBTjTH0T2TDeQurRJRJq4Vo/zzU8UEHW8mMQ6aH4dTKItRbcaaiaMj0ENEvbM7Xzi8M9iU58QKqO8Jw07JKif5qpg9qDReWSZTSq4NPmGtJweSz+HLIQXuHL3SpYLQpFjV8IqVjw0Ag8nnnITT/Es2V/TPf5tjgMOF4VSVkER+BrTZTwAgUHkDh4igOY0Q9jSMxGChxUSm9rT/3Euh7heMC2SzcfMaJO4qrzy82dn5V4CCPo6rjFkeXHMnPvUPxlRY1+JewCikhLaziIBan1DL9UMD7Aju9aMcbFJNbu509vhqurOkj+IY55x7UHwJTdpknYObySx3l5yv+JHvnnqAGoED6rrf3z6RV6TmZ23vGNybhoGbLl33rsTEgJREwuoxU9PfeVkwzc7f67V+cZlOptFbaSNiAI/4EPaC1B1JeWLFJK/66zjUK2N5P5tPuiEoCCkgrPoa0aRUFy3eHijeWF5gaXZ4ixZLNcQyuKcven+2++Dkpk 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: 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(+) -- 2.44.0.396.g6e790dbe36-goog 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");