Received: by 10.223.176.5 with SMTP id f5csp830914wra; Wed, 7 Feb 2018 08:12:10 -0800 (PST) X-Google-Smtp-Source: AH8x226eWXk9kbjb3wHx2LY7kJmIZNpJd3dm5ALFR+gM/h8wnXFGKri2pjIm1xfUzQ8n8hGqaY98 X-Received: by 2002:a17:902:82cb:: with SMTP id u11-v6mr6617663plz.391.1518019930362; Wed, 07 Feb 2018 08:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518019930; cv=none; d=google.com; s=arc-20160816; b=iZ4u/5/42S/UvTUWXDkRwRQ85e3pYJPtJ1MqClVxyNZiMoo3bfcqxrP67Kmg0xARp/ GJBvLCwmGl6udeJ97iH1zEgpQJlErDb6obnqH9J0qG9XOoEUt9Nw8zIhYnp31pNmC9vw oHqk9XbLNHpWPRaJQsswBuVJKX8GHb0e+g/5AGy1vOKL6LJqdT7Yd55ycdi6fpTciu8K /7xT2X2QI6PgI+XU6dGdHVyUBSlMoBtzksvZwRENM/lgfrpMZYfqiGg6uzWUOJEHcVgs e3ejOtrWEEqnY+g0b/uxxEKNSlVC2mHX0UyR8phjri2QL47tHbyaFabL0BiiGv/egKi5 kysQ== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=CdTJbQkC5Jo8RH3N54zrRSAVu2vCqHSv3xKaf77b1nA=; b=bWyCY/UqpJO+8rM1y/i/IIDbbUO2qjjLJhem16JpzTc/pVeF9dulSUJFmbs7s10oX4 53nvra1+GuyoIvagmaY11gYiOnlnUVK6ZIz5Nom+0D/8dwS55O9uomc23TVJ5AkNbIE6 QkVlSF9jS0+zLf7IQ57F8K+CAJBwuyAUYMHgYrDgwgTUuZ5bRlieyUheopBn8otbgaXU mj/LDHtIyxubheo6VmGGYIhwkr9fIqcrGxlqxGi3pXfh/cV87mvOvrGkhH0cSpz0vKVU Wnzp2fVvH8iwti65rdPWoXHGwNHHSluO+Kqyu5zyGl8rt5fXQw7B3dGIygrx8S4w/w3B iaZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mAOeMvlH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id m2si1081586pgs.86.2018.02.07.08.11.55; Wed, 07 Feb 2018 08:12:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mAOeMvlH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1754702AbeBGQJj (ORCPT + 99 others); Wed, 7 Feb 2018 11:09:39 -0500 Received: from mail-io0-f174.google.com ([209.85.223.174]:35937 "EHLO mail-io0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754685AbeBGQJh (ORCPT ); Wed, 7 Feb 2018 11:09:37 -0500 Received: by mail-io0-f174.google.com with SMTP id l17so2547487ioc.3 for ; Wed, 07 Feb 2018 08:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CdTJbQkC5Jo8RH3N54zrRSAVu2vCqHSv3xKaf77b1nA=; b=mAOeMvlHb8PYtET5XOBnTFqNcLABbTpdcuWntVhqIGl8csEmuUeMaAYNkgZZlUf/um KUnecULxWV54sxKgm6ZtFZpE38vRCHVsbMi4CUow04xt2De/ELmGeSxjcROy7MQZhQet B4EcD4VnMv+zg1991OPkYBptHwNo5sNqDfgxuYp0wbAENi+jNuuNj8iEva8wZqSNcALe 0ODrQGjBO0bwW5EuqpKb9BBhHPwQm156UYDL7vjHv/KbfbZg6dFT6Y/KR2Hl3xay9w4c 7ahid15A10yQtTqT3gzC1U+NFx4k1ByX1UHXc1GjaZt8z8DBcdb6xyWNNtnh9dNuyY12 KJRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CdTJbQkC5Jo8RH3N54zrRSAVu2vCqHSv3xKaf77b1nA=; b=XMz3RUaaptZJIQPwi6FA9+fOSJu8l16HoMmNxuy1ntpPBNUb7Pvfo2zAOxrBkv/cLV YDo5odIY6rbd4MUMxmGZMLq0m/SiXw9Fe4NXfzX95v7lK1iBxYpY6p5dSG1RMHFx0eHQ zm8wk/gz7b3IFfhi6BLI56DnZ38FpIUMb5bKjc6S3M6bT/LzpuQ4NR5Gyf8W6c1YRKRE +flFDvrGzJ2+pKZpgz7tyB3dMaWcTmnZqWZGcNPWXxPHdEED8gXuvU2v2Ev2RYSaHgg4 dOprcb3afjqlsleBuIVukMnGQB2uRgNvAg8PKPY23xZqjUMmFUFG151jwZtLdTs//oL0 jGaw== X-Gm-Message-State: APf1xPDrJJakPD4u86j6pgJomL0FUwRwS1sw4Ir9pJ+UDby3O3xXT45v okszBzM+TsJlwF2nP/zFtQgdIg0v6Dcl2Q0ZFCipg4wvrDo= X-Received: by 10.107.51.149 with SMTP id z143mr8179244ioz.287.1518019776595; Wed, 07 Feb 2018 08:09:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.172.135 with HTTP; Wed, 7 Feb 2018 08:09:36 -0800 (PST) In-Reply-To: <20180207080740.GH2269@hirez.programming.kicks-ass.net> References: <20180206004903.224390-1-joelaf@google.com> <20180207080740.GH2269@hirez.programming.kicks-ass.net> From: Joel Fernandes Date: Wed, 7 Feb 2018 08:09:36 -0800 Message-ID: Subject: Re: [PATCH RFC] ashmem: Fix lockdep RECLAIM_FS false positive To: Peter Zijlstra Cc: LKML , Michal Hocko , Minchan Kim , "open list:MEMORY MANAGEMENT" 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 Hi Peter, On Wed, Feb 7, 2018 at 12:07 AM, Peter Zijlstra wrote: > On Mon, Feb 05, 2018 at 04:49:03PM -0800, Joel Fernandes wrote: > >> [ 2115.359650] -(1)[106:kswapd0]================================= >> [ 2115.359665] -(1)[106:kswapd0][ INFO: inconsistent lock state ] >> [ 2115.359684] -(1)[106:kswapd0]4.9.60+ #2 Tainted: G W O >> [ 2115.359699] -(1)[106:kswapd0]--------------------------------- >> [ 2115.359715] -(1)[106:kswapd0]inconsistent {RECLAIM_FS-ON-W} -> >> {IN-RECLAIM_FS-W} usage. > > Please don't wrap log output, this is unreadable :/ Sorry about that, here's the unwrapped output, I'll fix the commit message in next rev: https://pastebin.com/e0BNGkaN > > Also, the output is from an ancient kernel and doesn't match the current > code. Right, however the driver hasn't changed and I don't see immediately how lockdep handles this differently upstream, so I thought of fixing it upstream. >> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c >> index 372ce9913e6d..7e060f32aaa8 100644 >> --- a/drivers/staging/android/ashmem.c >> +++ b/drivers/staging/android/ashmem.c >> @@ -32,6 +32,7 @@ >> #include >> #include >> #include >> +#include >> #include "ashmem.h" >> >> #define ASHMEM_NAME_PREFIX "dev/ashmem/" >> @@ -446,8 +447,17 @@ ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) >> if (!(sc->gfp_mask & __GFP_FS)) >> return SHRINK_STOP; >> >> - if (!mutex_trylock(&ashmem_mutex)) >> + /* >> + * Release reclaim-fs marking since we've already checked GFP_FS, This >> + * will prevent lockdep's reclaim recursion deadlock false positives. >> + * We'll renable it before returning from this function. >> + */ >> + fs_reclaim_release(sc->gfp_mask); >> + >> + if (!mutex_trylock(&ashmem_mutex)) { >> + fs_reclaim_acquire(sc->gfp_mask); >> return -1; >> + } >> >> list_for_each_entry_safe(range, next, &ashmem_lru_list, lru) { >> loff_t start = range->pgstart * PAGE_SIZE; >> @@ -464,6 +474,8 @@ ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) >> break; >> } >> mutex_unlock(&ashmem_mutex); >> + >> + fs_reclaim_acquire(sc->gfp_mask); >> return freed; >> } > > Yuck that is horrible.. so if GFP_FS was set, we bail, but if GFP_FS > wasn't set, why is fs_reclaim_*() doing anything at all? > > That is, __need_fd_reclaim() should return false when !GFP_FS. So my patch is wrong, very sorry about that. That's why I marked it as RFC and wanted to get your expert eyes on it. The bail out happens when GFP_FS is *not* set. Lockdep reports this issue when GFP_FS is infact set, and we enter this path and acquire the lock. So lockdep seems to be doing the right thing however by design it is reporting a false-positive. The real issue is that the lock being acquired is of the same lock class and a different lock instance is acquired under GFP_FS that happens to be of the same class. So the issue seems to me to be: Process A kswapd --------- ------ acquire i_mutex Enter RECLAIM_FS Enter RECLAIM_FS acquire different i_mutex Neil tried to fix this sometime back: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg623909.html but it was kind of NAK'ed. Any thoughts on how we can fix this? Thanks Peter, - Joel