From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCAEC4332E for ; Tue, 2 Mar 2021 17:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D66E64F0B for ; Tue, 2 Mar 2021 17:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351793AbhCBRtq (ORCPT ); Tue, 2 Mar 2021 12:49:46 -0500 Received: from mx2.suse.de ([195.135.220.15]:51960 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1574223AbhCBPO2 (ORCPT ); Tue, 2 Mar 2021 10:14:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1614695381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wUWlX6XFsup9fg8TMDk+EZFrxnEmvEB1W0zT6P/g0lg=; b=WGJFddT1h/cWi7GZzbQf1RzmgR2/OafQDJYF9QBnP67kgRGzbN7Ai9A/qw1mpw+Gh7cw8u Ywawb8gccT4mhwEPhreQwAcEvcCi4nvu+3TvLEysAXCvNAhzx82lrVn+JUf+2a3RDzxMnI kqETNGHJkt6NOEX1/ZuvQPNZ13WiN4M= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 04352ADDD; Tue, 2 Mar 2021 14:29:41 +0000 (UTC) Date: Tue, 2 Mar 2021 15:29:40 +0100 From: Michal Hocko To: Shakeel Butt Cc: Mike Kravetz , syzbot , Andrew Morton , LKML , Linux MM , syzkaller-bugs , Eric Dumazet , Mina Almasry Subject: Re: possible deadlock in sk_clone_lock Message-ID: References: <7b7c4f41-b72e-840f-278a-320b9d97f887@oracle.com> <122e8c5d-60b8-52d9-c6a1-00cd61b2e1b6@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 02-03-21 06:11:51, Shakeel Butt wrote: > On Tue, Mar 2, 2021 at 1:44 AM Michal Hocko wrote: > > > > On Mon 01-03-21 17:16:29, Mike Kravetz wrote: > > > On 3/1/21 9:23 AM, Michal Hocko wrote: > > > > On Mon 01-03-21 08:39:22, Shakeel Butt wrote: > > > >> On Mon, Mar 1, 2021 at 7:57 AM Michal Hocko wrote: > > > > [...] > > > >>> Then how come this can ever be a problem? in_task() should exclude soft > > > >>> irq context unless I am mistaken. > > > >>> > > > >> > > > >> If I take the following example of syzbot's deadlock scenario then > > > >> CPU1 is the one freeing the hugetlb pages. It is in the process > > > >> context but has disabled softirqs (see __tcp_close()). > > > >> > > > >> CPU0 CPU1 > > > >> ---- ---- > > > >> lock(hugetlb_lock); > > > >> local_irq_disable(); > > > >> lock(slock-AF_INET); > > > >> lock(hugetlb_lock); > > > >> > > > >> lock(slock-AF_INET); > > > >> [...] > > Wouldn't something like this help? It is quite ugly but it would be > > simple enough and backportable while we come up with a more rigorous > > solution. What do you think? > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 4bdb58ab14cb..c9a8b39f678d 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -1495,9 +1495,11 @@ static DECLARE_WORK(free_hpage_work, free_hpage_workfn); > > void free_huge_page(struct page *page) > > { > > /* > > - * Defer freeing if in non-task context to avoid hugetlb_lock deadlock. > > + * Defer freeing if in non-task context or when put_page is called > > + * with IRQ disabled (e.g from via TCP slock dependency chain) to > > + * avoid hugetlb_lock deadlock. > > */ > > - if (!in_task()) { > > + if (!in_task() || irqs_disabled()) { > > Does irqs_disabled() also check softirqs? Nope it doesn't AFAICS. I was referring to the above lockdep splat which claims irq disabled to be the trigger. But now that you are mentioning that it would be better to replace in_task() along the way. We have discussed that in another email thread and I was suggesting to use in_atomic() which should catch also bh disabled situation. The big IF is that this needs preempt count to be enabled unconditionally. There are changes in the RCU tree heading that direction. -- Michal Hocko SUSE Labs