From patchwork Thu Mar 21 18:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 13599274 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 125EFC6FD1F for ; Thu, 21 Mar 2024 18:10:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5463D6B008A; Thu, 21 Mar 2024 14:10:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F4BD6B008C; Thu, 21 Mar 2024 14:10:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3944E6B0092; Thu, 21 Mar 2024 14:10:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 23C8E6B008A for ; Thu, 21 Mar 2024 14:10:14 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C411C40A6C for ; Thu, 21 Mar 2024 18:10:13 +0000 (UTC) X-FDA: 81921835506.03.082D190 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf28.hostedemail.com (Postfix) with ESMTP id E2A7EC001F for ; Thu, 21 Mar 2024 18:10:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JrnzJeKc; spf=pass (imf28.hostedemail.com: domain of 3Anj8ZQYKCBs54C91N7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--edliaw.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3Anj8ZQYKCBs54C91N7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--edliaw.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711044612; a=rsa-sha256; cv=none; b=R2RQbV8HW78CZyR599/wfRA+wDe3lIhIllmqiJq4FkGGn3AX2Zb9vVFLxGIwsFub7lKL4u OVI38D9C89rKTzAd5r/X7WRlyAmoFapDdrIE4QchrmbCe/p4Wc6FJwMh0ycFsyjpT+iHym jr1l2DVvM7LBOuClpAIECbfWbAgIcl0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JrnzJeKc; spf=pass (imf28.hostedemail.com: domain of 3Anj8ZQYKCBs54C91N7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--edliaw.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3Anj8ZQYKCBs54C91N7FF7C5.3FDC9ELO-DDBM13B.FI7@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=1711044612; 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=PbnhbS3nC1f/Uw+2QJySA42Qs2PFTt6bDMzEjk8k/Mc=; b=ltsq0Pug48dfMuWxNFrhOoIShSEc/LK4Yt/mdI/aoJHSot0MTb6F9hiVuBe8PFpYFdjCjz S0HPmaEwxcCggwcNpIWZW7FY/vaq1fSLNNCLbORsuz6ggFakDwkVLsJXRYf7zf9K3DIzEQ LJy2hIBLxKBDOxU0xC9vSNJTMzBzLsU= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6ea7f05b546so190104b3a.2 for ; Thu, 21 Mar 2024 11:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711044610; x=1711649410; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=PbnhbS3nC1f/Uw+2QJySA42Qs2PFTt6bDMzEjk8k/Mc=; b=JrnzJeKcAYY6uP+O5XoF3O5/aOatOgiycnPuByKm4I0jIZDvjqFP9qXEmohwcYsgbr HUu4DhgAi0p4SlNeFFZuZAnBAAySPr+5IDSN6kN6bjPk/0xvBLAlisBwAnIH95Xb/w16 //xiK6QJllELEhz9VbwK6xrTzEBt2bHsCPiRhtGYt46vtBPoZacOUGfX1QaIhsiswz5C Fn8eNKIyRta8tNY5pz5xOkB2rHlN5gHYBMq63mzG4JG8RXW0918PX4AjrSpx5wqRvBov 7iRVOQQQqDHmcIHEswqZS/KXx0KEaGBlXlov4ZbjF6ayv3ZkmaUKLGGeBWX88isjS0wr rkbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711044610; x=1711649410; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PbnhbS3nC1f/Uw+2QJySA42Qs2PFTt6bDMzEjk8k/Mc=; b=JHSYCggnDSFdq++NDJegnGKSE4ZX7pRSYOJ72avy+x+OemaPgTc35Qk/kWEeWO0ICN 5hxEE9/4JPRVnq1m4RdxQUhh2hu2K0+O2uWG51NOq7aRBBkSzItng390n4FQNhCCNp/2 FuFbE79acufDIF4rtgP7jsLpEB4VlKB9ivEUHhguFzJnN1Ou0eHH82z0+/ELNQfmWvlU 2jEe93KLED4fz9HTpAjMMKvFcxsdGKwjx6FDOs86FNozfdyboRtEIijrAwHH6uqS76fw P5JpH06hnZQ8FNF5dcxEmSqwYUD/+J6Rzk4+y0xEjFjHUKQrBC3qevypaYofCvMF733C eSwg== X-Forwarded-Encrypted: i=1; AJvYcCVLXe9Lp+B86/wkTRPybzNtVIN7eBFQKS9hwMWLtiCrSQ9JWUQsxSIprwlySmj0eXutD7Nu2Gn5Q2RCHOZESMIPUvs= X-Gm-Message-State: AOJu0Yy7HFDgKRIwn6CXX/vHIy+NbFer+vn0MiWgnYl9HpclcR6aL4Tl hD35SIOSdPL7lqdnAJ6EC5yfYhIj0zH2DBvTHLBTz5lGwJMTvI0GJm8xCExNqV1/4mHG6I5R4KM Qhg== X-Google-Smtp-Source: AGHT+IFYni3VvlWRaTmYz+82jv0WpYU31SYMq2cohi3G9fHRYPBqE7DFoZnmZbyg80iXWTMzj1CSpz2vwMs= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:938b:b0:6e7:3fcb:38ba with SMTP id ka11-20020a056a00938b00b006e73fcb38bamr10155pfb.6.1711044610507; Thu, 21 Mar 2024 11:10:10 -0700 (PDT) Date: Thu, 21 Mar 2024 18:09:28 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Message-ID: <20240321180933.1029746-1-edliaw@google.com> Subject: [PATCH v1] uffd-unit-tests: Fix ARM related issue with fork after pthread_create From: Edward Liaw To: linux-kernel@vger.kernel.org, Andrew Morton , Shuah Khan Cc: linux-kselftest@vger.kernel.org, kernel-team@android.com, Edward Liaw , Lokesh Gidra , linux-mm@kvack.org X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E2A7EC001F X-Stat-Signature: km9u3eqjhrhc1f9w6ghq6gbyawgdn6c1 X-Rspam-User: X-HE-Tag: 1711044611-95348 X-HE-Meta: U2FsdGVkX1+Nbn8EI7hbeF/9LSGqTOLUFomDVEIxTQmrf4LORd+dAukh4rNC3EvsLvwYY5NfLvAnbcUwVH6kn411QHgM9DaVva1OpfdhEfCYOPZk4ucnGokX1Qgznug2LvLTrpT6Cgj+QScZEtV7PCM0sS8tMjok3uwRCq8Oeph3i6i1JrUTTsYKEijf9ALVpD0GE96SSc+MWJWJzCsmFLF8hY2dMCPVOqr5V3Xz4LTppLNy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BzN2/Plluzb6v7EPHj+RParc/MLXj3HMI3tkYUQ2uC5azQVnkadaL+/Q0FPy4GgXEOO0fyoKWlXnBASQKPemwU5uGlFYrqOSuwHa5lJZduyrf7j9yNKS/wNImevhr9sUblw3ZHBbJQXg/QAQSCgo2O1exm8l/HPwUnO5xMq4UWHGj2un25cGlI22wdLbEMfJwpxSFHXhzjYvhv3HpGJhfU1ncaZA3sxRbKMSu7OF9C+TH1/OyaGkYjwl1BdsDO8fr92hWU8D4FdYvRdj3BhZjYd7inPlEGrWCOwxBYdGY9DxAL2Hse+2operKSPU+hR9GcdH4sQwhKfx5u4CJzEzAgYdd4jEEQ== 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 --- tools/testing/selftests/mm/uffd-common.c | 4 +++- tools/testing/selftests/mm/uffd-common.h | 2 ++ tools/testing/selftests/mm/uffd-unit-tests.c | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index b0ac0ec2356d..14ed98c3a389 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -17,7 +17,7 @@ bool map_shared; 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 +518,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");