Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1632455pxb; Wed, 9 Feb 2022 00:39:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuB8e0zmP6/m0RGTtcF1LSCipgKKH85nNykb92SGkAIMdOGaaQ9cBQmmWEW6cTryLqwj6t X-Received: by 2002:a17:902:8d96:: with SMTP id v22mr1053462plo.77.1644395957063; Wed, 09 Feb 2022 00:39:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644395957; cv=none; d=google.com; s=arc-20160816; b=DWvAtXap9iYLKLW/M6WufI+lYNuWeDydT/e0kvmZ/LLysbW9FYyF/crUkQVtqF8ZcN NkXs56a2dHv3zYvygiV5bvMYoJctneogiuMi29RGFXI5GjAXNYZ17Tq40b8wGOAf0HaS sO/s8j1xOLuBeYCFOe3EQmtIa375vpdUgcjXmAPfDdDIzq9OEUnkbVxfOdAKdln2LFaJ DFvduRxF2E5FPDAcrKV+mX4WWHrq384GLHRo3yMCGyASscAM9Cw2A5Gr4Fx6LX9q4giX OjiNjf7L+dAJpoqOjvGOMmHI7zCVt8Xia3k7TqTXWbeADJvEf/gzXO1GIV7a/KBpuSos 5VUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ResiOMSkqLaFwecOSm6Y41C9FDzk+Q7FwcTKW53EBiY=; b=AP0X08SvTIVKnFyVln99dXgQKx27Q0Fp5V6OS9MEzyVHtN8tskKehLvJVqq3heYVHT 6TDSl7CcaYxNkl3C0mPQnQh5qeJlmEAuSquPKr/UIXFz2XpzVIyBeK8dEhdsW0la6zrb IO+cWugBYm+Xteq8zbOwavG9LNpu+TJ/p8e3vnRjciIaZbBVgZ8UJQMmZswf1dHfLZBa JiUL3OvCRcUGccag53eYHnhBVLRLYiKQw9ZreF1qHmqPOS+mz2RRLsuqNPfEPMxfdPrD /fo2JGzICmJl+xmQqaVm8+x2sgl1F1I0bnpxWKlGoaRoZueJkvJByF5NUpFpcnF9JaBW zDZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YWLicH1n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 72si16001458pgb.211.2022.02.09.00.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 00:39:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YWLicH1n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 22B72C05CBAB; Wed, 9 Feb 2022 00:38:20 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383355AbiBHQj5 (ORCPT + 99 others); Tue, 8 Feb 2022 11:39:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232725AbiBHQj4 (ORCPT ); Tue, 8 Feb 2022 11:39:56 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C5010C061576 for ; Tue, 8 Feb 2022 08:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644338394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ResiOMSkqLaFwecOSm6Y41C9FDzk+Q7FwcTKW53EBiY=; b=YWLicH1npxuQ3j3nI3QYmk1ganMa/7eL/GI8wG0qMApjMEOSzm/P6HIq2kV1F+eB6gBOuS aJvX6lz+rTqIRCy2IhqqeuPuJ6ZaHWHDXOCqrzj0Jl8L3qNOLOV4L/JTxJkOmfPkZKNL4N C2bCXxQRZkAdjyw+KIYVfknizG0/Osk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649-5Oas98BiM-KtHahzRmNmEw-1; Tue, 08 Feb 2022 11:39:51 -0500 X-MC-Unique: 5Oas98BiM-KtHahzRmNmEw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3AD21006AB3; Tue, 8 Feb 2022 16:39:49 +0000 (UTC) Received: from llong.com (unknown [10.22.35.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 094E2879D3; Tue, 8 Feb 2022 16:39:21 +0000 (UTC) From: Waiman Long To: Christian Brauner , "Eric W. Biederman" , Andrew Morton , Jens Axboe , Alexey Gladkov , David Hildenbrand , Jann Horn , Al Viro Cc: linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH] copy_process(): Move fd_install() out of sighand->siglock critical section Date: Tue, 8 Feb 2022 11:39:12 -0500 Message-Id: <20220208163912.1084752-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I was made aware of the following lockdep splat: [ 2516.308763] ===================================================== [ 2516.309085] WARNING: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected [ 2516.309433] 5.14.0-51.el9.aarch64+debug #1 Not tainted [ 2516.309703] ----------------------------------------------------- [ 2516.310149] stress-ng/153663 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire: [ 2516.310512] ffff0000e422b198 (&newf->file_lock){+.+.}-{2:2}, at: fd_install+0x368/0x4f0 [ 2516.310944] and this task is already holding: [ 2516.311248] ffff0000c08140d8 (&sighand->siglock){-.-.}-{2:2}, at: copy_process+0x1e2c/0x3e80 [ 2516.311804] which would create a new lock dependency: [ 2516.312066] (&sighand->siglock){-.-.}-{2:2} -> (&newf->file_lock){+.+.}-{2:2} [ 2516.312446] but this new dependency connects a HARDIRQ-irq-safe lock: [ 2516.312983] (&sighand->siglock){-.-.}-{2:2} : [ 2516.330700] Possible interrupt unsafe locking scenario: [ 2516.331075] CPU0 CPU1 [ 2516.331328] ---- ---- [ 2516.331580] lock(&newf->file_lock); [ 2516.331790] local_irq_disable(); [ 2516.332231] lock(&sighand->siglock); [ 2516.332579] lock(&newf->file_lock); [ 2516.332922] [ 2516.333069] lock(&sighand->siglock); [ 2516.333291] *** DEADLOCK *** [ 2516.389845] stack backtrace: [ 2516.390101] CPU: 3 PID: 153663 Comm: stress-ng Kdump: loaded Not tainted 5.14.0-51.el9.aarch64+debug #1 [ 2516.390756] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 2516.391155] Call trace: [ 2516.391302] dump_backtrace+0x0/0x3e0 [ 2516.391518] show_stack+0x24/0x30 [ 2516.391717] dump_stack_lvl+0x9c/0xd8 [ 2516.391938] dump_stack+0x1c/0x38 [ 2516.392247] print_bad_irq_dependency+0x620/0x710 [ 2516.392525] check_irq_usage+0x4fc/0x86c [ 2516.392756] check_prev_add+0x180/0x1d90 [ 2516.392988] validate_chain+0x8e0/0xee0 [ 2516.393215] __lock_acquire+0x97c/0x1e40 [ 2516.393449] lock_acquire.part.0+0x240/0x570 [ 2516.393814] lock_acquire+0x90/0xb4 [ 2516.394021] _raw_spin_lock+0xe8/0x154 [ 2516.394244] fd_install+0x368/0x4f0 [ 2516.394451] copy_process+0x1f5c/0x3e80 [ 2516.394678] kernel_clone+0x134/0x660 [ 2516.394895] __do_sys_clone3+0x130/0x1f4 [ 2516.395128] __arm64_sys_clone3+0x5c/0x7c [ 2516.395478] invoke_syscall.constprop.0+0x78/0x1f0 [ 2516.395762] el0_svc_common.constprop.0+0x22c/0x2c4 [ 2516.396050] do_el0_svc+0xb0/0x10c [ 2516.396252] el0_svc+0x24/0x34 [ 2516.396436] el0t_64_sync_handler+0xa4/0x12c [ 2516.396688] el0t_64_sync+0x198/0x19c [ 2517.491197] NET: Registered PF_ATMPVC protocol family [ 2517.491524] NET: Registered PF_ATMSVC protocol family [ 2591.991877] sched: RT throttling activated One way to solve this problem is to move the fd_install() call out of the sighand->siglock critical section. Before commit 6fd2fe494b17 ("copy_process(): don't use ksys_close() on cleanups"), the pidfd installation was done without holding both the task_list lock and the sighand->siglock. Obviously, holding these two locks are not really needed to protect the fd_install() call. So move the fd_install() call down to after the releases of both locks. Fixes: 6fd2fe494b17 ("copy_process(): don't use ksys_close() on cleanups") Signed-off-by: Waiman Long --- kernel/fork.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index d75a528f7b21..007af7fb47c7 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2323,10 +2323,6 @@ static __latent_entropy struct task_struct *copy_process( goto bad_fork_cancel_cgroup; } - /* past the last point of failure */ - if (pidfile) - fd_install(pidfd, pidfile); - init_task_pid_links(p); if (likely(p->pid)) { ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace); @@ -2375,6 +2371,9 @@ static __latent_entropy struct task_struct *copy_process( syscall_tracepoint_update(p); write_unlock_irq(&tasklist_lock); + if (pidfile) + fd_install(pidfd, pidfile); + proc_fork_connector(p); sched_post_fork(p, args); cgroup_post_fork(p, args); -- 2.27.0