Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1846209ybh; Tue, 14 Jul 2020 08:48:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0iiTLevT3itZejJzpFlqVftku54/SAvp9J9wlcp8Xpv+dlbh7kmvJRpLgYrFR4u29r85J X-Received: by 2002:aa7:c353:: with SMTP id j19mr5099959edr.219.1594741680865; Tue, 14 Jul 2020 08:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594741680; cv=none; d=google.com; s=arc-20160816; b=tyXfGwi5r+fp7zBTWZZZkixrzKNS43LPT2ZC1RwZXzovyXNkPRamZcVkroKROq5iKN Vii8BOW35ZU5J0zgBqMwqAVBQUTnaI7xDsS3Wc+WMNbByr2x9i4fvo1ep8y1wX3kc4In asid8dS5/6sl+1MZA9/x31FuqXMu6FnClJIbNy5ifK9IEFnlc9f0saE8nJOAFzkGfiog qQ/14RNYPHoTa5KyMvVCn6jM3gPHjOujD+g0aiAiFH24BT7pIz+qqMmIq9Pm3L/9CxjH fVNle0lzsadlP6k0kUtpXqNkHtXuZjt5c8UzTBA1pmaRwoeIhLJOVqNjOxumDPCCWweR IfGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QXa/a8+v6atJW9I3K/8i8cY/Lmvtpiv+5qg62twrTiI=; b=jLG+154XvQFSpBnVWRuErrrJ769xvaiUEvCL2li9+vZdssoCgilBwJOyY2dADr1qjv 2xDed68rct8TUv2l/sPTNVQL1BNaIE5u6Yl6WpzY8z4K6i6g0JmRZfL9BbGYI5ZesAp9 Bxsw/eDx3vuwSp90ra34XQMcuQRJ0O3tME6zJqgS1yJyC4J+JwXLqZTwAjgGgYdLv9pR pOmBbeIGTL2HlqFvTy2g1BqpbgLMjd2gYvRnYmjYw5HaZf7BTqJybRxtSDtqzTA91SJk dUG5/lPTNdHmMwaWM557+i9Anp9uXlVkp7W4cnv3sEDJYevdq37moqf0b31xkRI87wZZ GvFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mn0Ryrht; 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 d26si11468639edp.518.2020.07.14.08.47.37; Tue, 14 Jul 2020 08:48:00 -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=mn0Ryrht; 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 S1727775AbgGNPrI (ORCPT + 99 others); Tue, 14 Jul 2020 11:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726546AbgGNPrI (ORCPT ); Tue, 14 Jul 2020 11:47:08 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE403C061755 for ; Tue, 14 Jul 2020 08:47:07 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id b15so17719144edy.7 for ; Tue, 14 Jul 2020 08:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QXa/a8+v6atJW9I3K/8i8cY/Lmvtpiv+5qg62twrTiI=; b=mn0RyrhtCpG4LO11bnCZa/lH0u4e10/twWy/TsKJcWSQwrFQ5uc6hzPuo8XA/9zijo WXpQOqlkhvbUvdaMnYvaL5yMyMBiI13+6TT7c2XLV0U0dSXQYpZixce2KzXkEc9EMl61 OqZZyQ5PLT6Z1OFgRTGde6rsKiTpakTwwGXYbmnV9rjo/Kjf6jGOKvwGN+YRjLW9lkhC kRnWpIq1+3mRuVGMoYQC1U7VWPy3zx8sqXja+EjvisR61blv1JMOgRN/U/u/wo35VUQo WZNr9i8Jsh/wLAI1XKQxMW1+KlUDFBsmTNNVjEHsl9KYkXD8OHwk3pGLriKFn9pzN7k3 84yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QXa/a8+v6atJW9I3K/8i8cY/Lmvtpiv+5qg62twrTiI=; b=A6aMEGV/VxvHrE8O0D7vegzYrHgQD1Wo1ud8GO7VOxnA9H1jF2MNAx7Z3W6aQ3MAxp rUIQs8k1pzN6j6VqYxGy6jvcoOpCbKgG/x6CWoITmbVAC18F8iFjEqZfQcDLx96Wryuc gz6eY0uktFc2gfhx34Tk1slGZZVsSh9IyAX4ACqPmCDDRtw2FA+MGzpfW4GludiE0Ube YrVlq/CqFMtGR2bNA6bPjhuqd5TRPz/tl6n7JT2wFMX9NddnQIBiVOB9aegRKqboQM7x Yr/xQnBxYKeX/JtYwOdefgDyTLXEc7t6POhfNgcFToroTIsBGz8o3s/FRT0QJpaMkj+s 8Kgg== X-Gm-Message-State: AOAM530PHPI5yGzjVJYnJiGnsqoxvUeLJhOKWZcUArXcWOl/3w48j9te hokWM0oHTVxiCYXoLaAQYOhvZz0nz32WKQmUrHYhxA== X-Received: by 2002:aa7:dd8e:: with SMTP id g14mr5326572edv.208.1594741626195; Tue, 14 Jul 2020 08:47:06 -0700 (PDT) MIME-Version: 1.0 References: <0000000000000b5f9d059aa2037f@google.com> <20200714033252.8748-1-hdanton@sina.com> <20200714053205.15240-1-hdanton@sina.com> <20200714140859.15156-1-hdanton@sina.com> <20200714141815.GP24642@dhcp22.suse.cz> In-Reply-To: <20200714141815.GP24642@dhcp22.suse.cz> From: Todd Kjos Date: Tue, 14 Jul 2020 08:46:55 -0700 Message-ID: Subject: Re: possible deadlock in shmem_fallocate (4) To: Michal Hocko , Suren Baghdasaryan , Hridya Valsaraju Cc: Hillf Danton , Eric Biggers , syzbot , akpm@linux-foundation.org, =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Christian Brauner , "open list:ANDROID DRIVERS" , Greg Kroah-Hartman , Hugh Dickins , "Joel Fernandes (Google)" , LKML , Linux-MM , Martijn Coenen , syzkaller-bugs , Todd Kjos , Markus Elfring Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Suren Baghdasaryan +Hridya Valsaraju who support the ashmem driver. On Tue, Jul 14, 2020 at 7:18 AM Michal Hocko wrote: > > On Tue 14-07-20 22:08:59, Hillf Danton wrote: > > > > On Tue, 14 Jul 2020 10:26:29 +0200 Michal Hocko wrote: > > > On Tue 14-07-20 13:32:05, Hillf Danton wrote: > > > > > > > > On Mon, 13 Jul 2020 20:41:11 -0700 Eric Biggers wrote: > > > > > On Tue, Jul 14, 2020 at 11:32:52AM +0800, Hillf Danton wrote: > > > > > > > > > > > > Add FALLOC_FL_NOBLOCK and on the shmem side try to lock inode upon the > > > > > > new flag. And the overall upside is to keep the current gfp either in > > > > > > the khugepaged context or not. > > > > > > > > > > > > --- a/include/uapi/linux/falloc.h > > > > > > +++ b/include/uapi/linux/falloc.h > > > > > > @@ -77,4 +77,6 @@ > > > > > > */ > > > > > > #define FALLOC_FL_UNSHARE_RANGE 0x40 > > > > > > > > > > > > +#define FALLOC_FL_NOBLOCK 0x80 > > > > > > + > > > > > > > > > > You can't add a new UAPI flag to fix a kernel-internal problem like this. > > > > > > > > Sounds fair, see below. > > > > > > > > What the report indicates is a missing PF_MEMALLOC_NOFS and it's > > > > checked on the ashmem side and added as an exception before going > > > > to filesystem. On shmem side, no more than a best effort is paid > > > > on the inteded exception. > > > > > > > > --- a/drivers/staging/android/ashmem.c > > > > +++ b/drivers/staging/android/ashmem.c > > > > @@ -437,6 +437,7 @@ static unsigned long > > > > ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) > > > > { > > > > unsigned long freed = 0; > > > > + bool nofs; > > > > > > > > /* We might recurse into filesystem code, so bail out if necessary */ > > > > if (!(sc->gfp_mask & __GFP_FS)) > > > > @@ -445,6 +446,11 @@ ashmem_shrink_scan(struct shrinker *shri > > > > if (!mutex_trylock(&ashmem_mutex)) > > > > return -1; > > > > > > > > + /* enter filesystem with caution: nonblock on locking */ > > > > + nofs = current->flags & PF_MEMALLOC_NOFS; > > > > + if (!nofs) > > > > + current->flags |= PF_MEMALLOC_NOFS; > > > > + > > > > while (!list_empty(&ashmem_lru_list)) { > > > > struct ashmem_range *range = > > > > list_first_entry(&ashmem_lru_list, typeof(*range), lru); > > > > > > I do not think this is an appropriate fix. First of all is this a real > > > deadlock or a lockdep false positive? Is it possible that ashmem just > > > > The warning matters and we can do something to quiesce it. > > The underlying issue should be fixed rather than _something_ done to > silence it. > > > > needs to properly annotate its shmem inodes? Or is it possible that > > > the internal backing shmem file is visible to the userspace so the write > > > path would be possible? > > > > > > If this a real problem then the proper fix would be to set internal > > > shmem mapping's gfp_mask to drop __GFP_FS. > > > > Thanks for the tip, see below. > > > > Can you expand a bit on how it helps direct reclaimers like khugepaged > > in the syzbot report wrt deadlock? > > I do not understand your question. > > > TBH I have difficult time following > > up after staring at the chart below for quite a while. > > Yes, lockdep reports are quite hard to follow and they tend to confuse > one hell out of me. But this one says that there is a reclaim dependency > between the shmem inode lock and the reclaim context. > > > Possible unsafe locking scenario: > > > > CPU0 CPU1 > > ---- ---- > > lock(fs_reclaim); > > lock(&sb->s_type->i_mutex_key#15); > > lock(fs_reclaim); > > > > lock(&sb->s_type->i_mutex_key#15); > > Please refrain from proposing fixes until the actual problem is > understood. I suspect that this might be just false positive because the > lockdep cannot tell the backing shmem which is internal to ashmem(?) > with any general shmem. But somebody really familiar with ashmem code > should have a look I believe. > > -- > Michal Hocko > SUSE Labs