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-604476 X-HE-Meta: U2FsdGVkX19TaI6TYp38rhDDNd9cp7qCI3AGWc+ZrpeNQRM9O9jKgz8LSJqkkzRduyTpjusuxUy6steRY1bMNG4s5vmUcZT7MxGFmESjcpVkJqh0TX7hjnhXcneIP4yrdqAjVXtfO38EmneUlMbPRWpSMtqXFuMaOMiPxCO9Y67uAbg7RqJ0h7JLCuCZz8iar0XIDx7DkN1OV5Cz/ufJ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ac6z86MomEZIvMvFaepAeVc63J8nsIyrlcx6Bb+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();