Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp790236imm; Wed, 22 Aug 2018 12:39:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbpOmf3uy9fSg6IP8FQspXsupXFq70n3At0d7ZHFWXDNEWfEQVlRuT3wY34DOmJkQL2mwFT X-Received: by 2002:a17:902:5acc:: with SMTP id g12-v6mr5151125plm.90.1534966750155; Wed, 22 Aug 2018 12:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534966750; cv=none; d=google.com; s=arc-20160816; b=o+VBpf8pC+vvKZmiWlyfjTSRsGqG6tvUhzoTq12c1kchn6l+/WKvZ2u2Vb7oi7h4kB PSNwAWpAEolF+40GGfptNE69gdgfQIt0njOxmEh1AdCxaVCxmLrr1Mr1IxUuYs7GXQv2 BKAQou3hVDllli/OPLz+EX4o0iVKAQR5//mdrSNBbRO5F5cFzEVk0NBSS9A0HrKCOgkc TEdG45BVd7eQCZziODqoGfW4mTyoWHBtYUbmPqX4GycOyWQ7liFAAhMZHjFfbflnFJ3d GLwQzpeQFdu4FBbylzPVB3GgOVguuKPe1QXs0FRGbeVht5cq7KOJUV3q/MtSoZtH3uMN syHg== 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=ufcz6UeIxBD+E+Tn+2REon+gK2+vFl2qb/k/1cEwa80=; b=CFk4C120j8TqYwk+9EyVU5Mtw0HqAKZZv/d+25FqvOVSpobI9YsZVbF4pgCXOdtwut 8PffGJXEf288hIIbh23LJs4Kj4dxKZ1BbXqZKdQkCXL62DOZCtdzeDbtcfKkUdfahngL kG6gdKKtoHeHRb4feQHAoXWhCQFOfSTcEWiXrExF8FxETS8NBygSSyEUSTeS2BWipJNc b4neT+WHnjVRkHQKfp2svPhvtR3vIaijrSvMmEdk6v4wuvFMnrTMC2+MrfbGdhqj9FEe Aqud0PpFAWPVufhG/07qAXn/6UpEiHhNR5M/+u5zFRE1xDbKg+nnS3frUCVQsWA5L4hm pLLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RBFHP5p4; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89-v6si2397402pla.310.2018.08.22.12.38.54; Wed, 22 Aug 2018 12:39:10 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=RBFHP5p4; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728225AbeHVXDt (ORCPT + 99 others); Wed, 22 Aug 2018 19:03:49 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:38441 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbeHVXDt (ORCPT ); Wed, 22 Aug 2018 19:03:49 -0400 Received: by mail-ed1-f68.google.com with SMTP id q15-v6so2113024eds.5; Wed, 22 Aug 2018 12:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ufcz6UeIxBD+E+Tn+2REon+gK2+vFl2qb/k/1cEwa80=; b=RBFHP5p4SThrtULxM0EAntnngokvzbpA6LLUPv6/wp3UNYtkGk43WjaKFd+dPmb/02 AmAR0o080xdZu1fTZ7VYXwc9/9GJaf1DmJ8yJMz+XQfXdkkL1DloA8kAbpndkS85ydRR KWGzdhWHw+R+V0kWCXRa8hGtUzzskAg8cQVL8xBAH5YgP1tiSqdtO+Rf/JxDh7vOP/Qr H7olWc0ObM2gulKRTc/4jsethrpTYyaIuS7g7x43CXXKRMG81OtuW2cvMDOCFuFzNSZt eRw+GUA2j5iL8yTLJAx6HLXV+6be3TlhE+XCJgIOk4ouUfwnACfy2LS98OqaOFUNPQzj IfBg== 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=ufcz6UeIxBD+E+Tn+2REon+gK2+vFl2qb/k/1cEwa80=; b=o5LmqOZPMyYvKtZskrSEzLYb+gOPpnyZWPOOtpGk/ijtcKGwEMitbaTg7iYqD9U6v5 nVRdAoMZ+VxtNiAd9/4qjBAn/2pyUwsfw0I+l9H1MfVIxti6G+4Ur0ez5uuQwsrm7as1 PAxt+shICUue6UdTv2GiWaxQvHHmJXpRPWHrpa5UqPiBY6zMYF43JJF7sZ3LUa/iYBDX 2jR0iNjwy+qUA+O83ZId6X2hymcSk7b1mwVcUF7nKydycz6RQ/4LruHjtNZciSOOEgYE Ue75fGSfYApQso+ttROX50x5j0cI/dHaPbiET1gnCvc9PTuSff3RG2mhuP/ipoqppyiK +Jsw== X-Gm-Message-State: AOUpUlFWz0TaHOClEc5xYYpEOtNr43r/8J8HHAKE8hqniqhs90AVRIqf ymv8Lk0j9/3eHfF/QV1B0cW8gofXf4GuN2XxRDs= X-Received: by 2002:a50:aa83:: with SMTP id q3-v6mr67142423edc.64.1534966655864; Wed, 22 Aug 2018 12:37:35 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:de42:0:0:0:0:0 with HTTP; Wed, 22 Aug 2018 12:37:35 -0700 (PDT) In-Reply-To: <20180724130155.20641-1-mszeredi@redhat.com> References: <20180724064929.GD19722@shao2-debian> <20180724130155.20641-1-mszeredi@redhat.com> From: Marc Dionne Date: Wed, 22 Aug 2018 16:37:35 -0300 Message-ID: Subject: Re: [PATCH v3] vfs: don't evict uninitialized inode To: Miklos Szeredi Cc: Al Viro , Linux Kernel Mailing List , linux-fsdevel@vger.kernel.org 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 On Tue, Jul 24, 2018 at 10:01 AM, Miklos Szeredi wrote: > iput() ends up calling ->evict() on new inode, which is not yet initialized > by owning fs. So use destroy_inode() instead. > > Add to sb->s_inodes list only if inode is not in I_CREATING state (meaning > that it wasn't allocated with new_inode(), which already does the > insertion). > > Reported-by: Al Viro > Signed-off-by: Miklos Szeredi > Fixes: 80ea09a002bf ("vfs: factor out inode_insert5()") > --- > fs/inode.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/fs/inode.c b/fs/inode.c > index 04dd7e0d5142..0aa5b29b6f87 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -1050,6 +1050,7 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, > { > struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); > struct inode *old; > + bool creating = inode->i_state & I_CREATING; > > again: > spin_lock(&inode_hash_lock); > @@ -1083,6 +1084,8 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, > inode->i_state |= I_NEW; > hlist_add_head(&inode->i_hash, head); > spin_unlock(&inode->i_lock); > + if (!creating) > + inode_sb_list_add(inode); > unlock: > spin_unlock(&inode_hash_lock); > > @@ -1117,12 +1120,13 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, > struct inode *inode = ilookup5(sb, hashval, test, data); > > if (!inode) { > - struct inode *new = new_inode(sb); > + struct inode *new = alloc_inode(sb); > > if (new) { > + new->i_state = 0; > inode = inode_insert5(new, hashval, test, set, data); > if (unlikely(inode != new)) > - iput(new); > + destroy_inode(new); > } > } > return inode; > -- > 2.14.3 > FYI with this patch (now merged) I'm seeing warnings whenever an object is created in an overlayfs mount: [ 842.152673] list_add double add: new=ffff88017efe03d8, prev=ffff88015c07ad88, next=ffff88017efe03d8. [ 842.152687] WARNING: CPU: 4 PID: 7592 at lib/list_debug.c:31 __list_add_valid+0x6e/0x80 The call stack looks like this, for the file creation case: [ 842.152746] inode_sb_list_add+0x4e/0x90 [ 842.152753] ? ovl_inode_test+0x20/0x20 [overlay] [ 842.152757] ? ovl_get_redirect_xattr+0x140/0x140 [overlay] [ 842.152759] inode_insert5+0x13e/0x1f0 [ 842.152764] ovl_get_inode.cold.16+0x38/0x44 [overlay] [ 842.152768] ovl_instantiate+0x75/0x130 [overlay] [ 842.152773] ovl_create_or_link+0x1c9/0x7d0 [overlay] [ 842.152776] ? ovl_alloc_inode+0x1b/0x80 [overlay] [ 842.152778] ? inode_sb_list_add+0x4e/0x90 [ 842.152782] ? ovl_fill_inode+0xd8/0x150 [overlay] [ 842.152787] ovl_create_object+0xa1/0xd0 [overlay] [ 842.152791] ovl_create+0x23/0x30 [overlay] .. where the inode passed to inode_insert5 originally comes from new_inode (ovl_create_object -> ovl_new_inode -> new_inode), was already added to the sb list, and doesn't have I_CREATING set. Originally seen from docker's use of overlayfs, but easily reproducible by creating a simple overlay of 2 ext4 directories and creating a new file or directory in the overlay. Marc