Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2294522pxb; Wed, 9 Feb 2022 15:24:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwS2hLu4vTLVwaHyTkTNUnmRVH4gInLa6O9gJX8Dr+j8peIat0v3Ey9uF5e3kWMgHlSzbm2 X-Received: by 2002:a63:6b43:: with SMTP id g64mr3757613pgc.396.1644449085922; Wed, 09 Feb 2022 15:24:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644449085; cv=none; d=google.com; s=arc-20160816; b=WTi9pDckyKx+X9lazxZaCQLN7rTjXhY/Ffna2xUYBzrIWYqe+nHHJH5xrk5Kxr3bl3 czxSbDTj9NQG9DE6K4gdFCt+g/+8lZHJXJF8hJXb8RCxQgT9ssLJMpHTSXQz0npPBsh/ 59wYTHLs2X4AgJjVrWmAYrs6zscKF4v2l7k5jflWOk0Z3QFEAAGVrOJNz5+e8Qhu9aT4 WnoZzaTcDYCSBlYpB2V7zULmKCNd12Ug7gkbZBV3w2cv0uTKl6uqzd5C2lpypDwvptCn Kv5WoLtS9PR3gK4pg67b/gbbMZiYwF2tHh/40k2wVrARjvVaTMevHjL8I+Wbvtx/aEmk 1+Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=eIjJUygyxHXPgN46Sjy8Ltda+2mp0eB5nkAXcxqUDoo=; b=qQ84qOWmDWa7vfYnpC2Skw7F0bd5d4IPlL/dp7edEvzlR6WixKfDuRuqrc8xVkFvFe dY4fdLSTVt5w52r2SZXARzKO22e/RmniVH4A+O5tMxCkj7pqgB0Z7H23ccrEXKFRciFl 1Tw1gL+a2L4MDViwd9aWFmtr0e5UaeDJxtrd34AaX5G7OLTrCUBsK4OBtfasJwZE923a gt8o3ftq5cb9LYgmEjS73ItHkAYCG/jR7IbU1A/t8nyy1noDUmsBEH7Xpz8RXCvDdubk Yz/kGbMl6C/un6NElPIxdcSEylhg6frLci7s3mfvxD28FZdifrJrMzS1DJe9AphDU43U DlVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f187si17620676pgc.312.2022.02.09.15.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:24:45 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 20F28E0650BB; Wed, 9 Feb 2022 15:19:33 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235301AbiBIWTQ (ORCPT + 99 others); Wed, 9 Feb 2022 17:19:16 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235265AbiBIWTM (ORCPT ); Wed, 9 Feb 2022 17:19:12 -0500 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36D64C102FD8 for ; Wed, 9 Feb 2022 14:19:15 -0800 (PST) Received: from in02.mta.xmission.com ([166.70.13.52]:43354) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nHvIu-000X1v-Ps; Wed, 09 Feb 2022 15:19:12 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:38336 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nHvIt-00176x-He; Wed, 09 Feb 2022 15:19:12 -0700 From: "Eric W. Biederman" To: Waiman Long Cc: Christian Brauner , Andrew Morton , Jens Axboe , Alexey Gladkov , David Hildenbrand , Jann Horn , Al Viro , linux-kernel@vger.kernel.org References: <20220208163912.1084752-1-longman@redhat.com> Date: Wed, 09 Feb 2022 16:18:46 -0600 In-Reply-To: <20220208163912.1084752-1-longman@redhat.com> (Waiman Long's message of "Tue, 8 Feb 2022 11:39:12 -0500") Message-ID: <87h797adkp.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1nHvIt-00176x-He;;;mid=<87h797adkp.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18LSrxsvSPswVlXbrhxSryV2nXTnOmUDHk= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Waiman Long X-Spam-Relay-Country: X-Spam-Timing: total 639 ms - load_scoreonly_sql: 0.40 (0.1%), signal_user_changed: 17 (2.6%), b_tie_ro: 13 (2.0%), parse: 2.0 (0.3%), extract_message_metadata: 27 (4.2%), get_uri_detail_list: 5 (0.8%), tests_pri_-1000: 28 (4.4%), tests_pri_-950: 2.2 (0.3%), tests_pri_-900: 1.78 (0.3%), tests_pri_-90: 111 (17.4%), check_bayes: 108 (16.9%), b_tokenize: 18 (2.8%), b_tok_get_all: 14 (2.2%), b_comp_prob: 6 (0.9%), b_tok_touch_all: 64 (10.0%), b_finish: 1.37 (0.2%), tests_pri_0: 427 (66.8%), check_dkim_signature: 1.08 (0.2%), check_dkim_adsp: 4.2 (0.7%), poll_dns_idle: 1.11 (0.2%), tests_pri_10: 2.3 (0.4%), tests_pri_500: 14 (2.2%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] copy_process(): Move fd_install() out of sighand->siglock critical section X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Waiman Long writes: > 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 The fd_install can not be moved earlier and it does need to be moved outside the locks. Reviewed-by: "Eric W. Biederman" > --- > 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);