Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp766675ybz; Wed, 15 Apr 2020 18:31:13 -0700 (PDT) X-Google-Smtp-Source: APiQypLQsUzKy0M8CFeD+tM1gsBNYjvXi4Jq7f7jnKcBYbS/wdwXdfvjqm1nyxbomaI6HyIJgwCc X-Received: by 2002:aa7:d78b:: with SMTP id s11mr28605211edq.226.1587000672888; Wed, 15 Apr 2020 18:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587000672; cv=none; d=google.com; s=arc-20160816; b=JtzTxj1eBiTpegtXjFBZSY+vOSew/YyBNFILWCUdRzivwnvFG0kZVxxKyrsMQ6OlkD Es+NPrWoa9fryXQagURyGSp0jz4LeXgneXYfkqi9riBlQMtkX13SFyX16364yYhgyxa1 lrg+YaOQjOnUnRCaGIXsWgQZvQFV0GURm1IY4Woga7iQrxG0QyywK7zfGDntOyAeR5V1 dYw98R7NJI+NHT8IQ2wZAATR5rINtltMTv/f7jM1HZ1x01RI3fifve/v+p3eEWJDur/L PCaQTvPvJ0GmRDUBA20Xeopa9mK1rw26QQO7d73ngcLsA6JNxqSGNEHxq2hR7LNHkoZD 6r6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=t2o9MD3Hx6j5/2C8h4jmxn6G4Qx8JbK6fPjj2wD7HKk=; b=MZixvABOY5hQ+BTB3dorp5z1/V6G/yKG7wVHE7HhCJoveBEHkEGOAxZf3tPeG9TsQu pnV/G1RjAB2/EXT+TubTRxgvpdVcKxMh394qvw8P6Rkgbn9FzuyiDEo4GCAUB8liFSOw bWPq+crVtjPPMYASz+H0PWkdNHM2OvWrTqmc2H/pfVTBcEPVRHtRAflhGm1bnR9zhxgl bifZxqwUgQTq3eFCXXV0WAdGlOUaPactZs1yRVMpLDPB32VZwXjOqwinfbyuEFFFhftV /Im3zMT5DHbnHqzl7IwAjr/Umqqf2uoRFgJO+3fBAYeIDhSe1uBXCpAia8I0SBxufXwd DopA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=v3Q4agCB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si12494637edl.2.2020.04.15.18.30.49; Wed, 15 Apr 2020 18:31:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=v3Q4agCB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731906AbgDPB1w (ORCPT + 99 others); Wed, 15 Apr 2020 21:27:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731316AbgDPB1n (ORCPT ); Wed, 15 Apr 2020 21:27:43 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17762C061A0F for ; Wed, 15 Apr 2020 18:27:43 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id j16so15288539oih.10 for ; Wed, 15 Apr 2020 18:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=t2o9MD3Hx6j5/2C8h4jmxn6G4Qx8JbK6fPjj2wD7HKk=; b=v3Q4agCBYVmBhWbMuZkEpyPnLrtl6162KII7OlIrGBCXNS8obmeAAZ1YZ7ReQqgmwd CobR5EWoRPmEQOw1D32pdKHYow3Oql5QhZMPcaZcd9Ya7dzAmeuqesFd2QJD9hBTHAaF 4aEn/iwDVdkAjjRh3O0zpvXWQlxr/9dOmLErzMqiKW0hGc1N9SRZv0n/N5Ha+3s9K3HT 1JIdh/xFfiayvg43GtxopNevoehLA4e455U2OgRHw7YBwKsyaKhfepyz4Oypc6CZ6b27 nbsQHeA5NmLgdldX8nf3hiZfZImCrXDNaDEOTjnpA+EGZwwtgMyQrqPs9sMX7W5HgxJm H1Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=t2o9MD3Hx6j5/2C8h4jmxn6G4Qx8JbK6fPjj2wD7HKk=; b=aTdZ/nFqdiDJ9ZhOGcVITnq+/GJIBUTfhtOKUiQjwa4u0A8QrPNfhGlYT4HQYZFrJG iTQEMBs+mbMRZ8+NC98XEwIscaTRtzU81gyYC9oGat7WbwdVjFhkLZ+u13jMoqg2ZmK4 rNkqL8bV2CHGADevgYHSVsMAESfmdBp/UCEeFDSuMr5YAEzE+osYnRrUAHWaH7KB0TQX eCqT3FLdyz3uA0zMX+ANdIwckLULYi38k/+93o7MH7rBXndPA4DA+LWsURNE+myeqJ7r EKW9UVDGWQdwpVdiOHNA0Ja/9wHiF7QDDlbZz/3fyMHZp/XJ19bo14WxUmCMJWIwaZdp Uodw== X-Gm-Message-State: AGi0Pub8gGlcVDZMVYHIhvJIeK4YR7Q8qRReQCThQ5z/mZh2JDYq9qZm GDEROrcHHIP9O3N4LIOafXHDrg== X-Received: by 2002:aca:f50e:: with SMTP id t14mr1423038oih.156.1587000461949; Wed, 15 Apr 2020 18:27:41 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id o8sm3379889oom.34.2020.04.15.18.27.40 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Wed, 15 Apr 2020 18:27:41 -0700 (PDT) Date: Wed, 15 Apr 2020 18:27:21 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Yang Shi cc: syzbot , Andrew Morton , Hugh Dickins , Linux Kernel Mailing List , Linux MM , syzkaller-bugs@googlegroups.com Subject: Re: possible deadlock in shmem_mfill_atomic_pte In-Reply-To: Message-ID: References: <000000000000571acf05a229cb2f@google.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 13 Apr 2020, Yang Shi wrote: > On Tue, Mar 31, 2020 at 10:21 AM syzbot > wrote: > > > > Hello, > > > > syzbot found the following crash on: > > > > HEAD commit: 527630fb Merge tag 'clk-fixes-for-linus' of git://git.kern.. > > git tree: upstream > > console output: https://syzkaller.appspot.com/x/log.txt?x=1214875be00000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=27392dd2975fd692 > > dashboard link: https://syzkaller.appspot.com/bug?extid=e27980339d305f2dbfd9 > > compiler: gcc (GCC) 9.0.0 20181231 (experimental) > > > > Unfortunately, I don't have any reproducer for this crash yet. > > > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > > Reported-by: syzbot+e27980339d305f2dbfd9@syzkaller.appspotmail.com > > > > WARNING: possible irq lock inversion dependency detected > > 5.6.0-rc7-syzkaller #0 Not tainted > > -------------------------------------------------------- > > syz-executor.0/10317 just changed the state of lock: > > ffff888021d16568 (&(&info->lock)->rlock){+.+.}, at: spin_lock include/linux/spinlock.h:338 [inline] > > ffff888021d16568 (&(&info->lock)->rlock){+.+.}, at: shmem_mfill_atomic_pte+0x1012/0x21c0 mm/shmem.c:2407 > > but this lock was taken by another, SOFTIRQ-safe lock in the past: > > (&(&xa->xa_lock)->rlock#5){..-.} > > > > > > and interrupts could create inverse lock ordering between them. > > > > > > other info that might help us debug this: > > Possible interrupt unsafe locking scenario: > > > > CPU0 CPU1 > > ---- ---- > > lock(&(&info->lock)->rlock); > > local_irq_disable(); > > lock(&(&xa->xa_lock)->rlock#5); > > lock(&(&info->lock)->rlock); > > > > lock(&(&xa->xa_lock)->rlock#5); > > > > *** DEADLOCK *** > > This looks possible. shmem_mfill_atomic_pte() acquires info->lock with > irq enabled. > > The below patch should be able to fix it: I agree, thank you: please send to akpm with your signoff and Reported-by: syzbot+e27980339d305f2dbfd9@syzkaller.appspotmail.com Fixes: 4c27fe4c4c84 ("userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support") Acked-by: Hugh Dickins I bet that 4.11 commit was being worked on before 4.8 reversed the ordering of info->lock and tree_lock, changing spin_lock(&info->lock)s to spin_lock_irq*(&info->lock)s - this one is the only hold-out; and not using userfaultfd, I wouldn't have seen the lockdep report. > > diff --git a/mm/shmem.c b/mm/shmem.c > index d722eb8..762da6a 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -2399,11 +2399,11 @@ static int shmem_mfill_atomic_pte(struct > mm_struct *dst_mm, > > lru_cache_add_anon(page); > > - spin_lock(&info->lock); > + spin_lock_irq(&info->lock); > info->alloced++; > inode->i_blocks += BLOCKS_PER_PAGE; > shmem_recalc_inode(inode); > - spin_unlock(&info->lock); > + spin_unlock_irq(&info->lock); > > inc_mm_counter(dst_mm, mm_counter_file(page)); > page_add_file_rmap(page, false);