Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp321194lfv; Wed, 13 Apr 2022 04:40:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+E5eTVLR0N8KiHJE6Oa22TLhMdEf1LD4DLUZ/dRh484EPm05WW2XnaZzbaPJydnxhoyvp X-Received: by 2002:a62:1714:0:b0:505:fbff:fe8e with SMTP id 20-20020a621714000000b00505fbfffe8emr8233415pfx.49.1649850058799; Wed, 13 Apr 2022 04:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649850058; cv=none; d=google.com; s=arc-20160816; b=vE9T4pB4OCeNUopDnsjtG24RgGyQguM72//JDcYzSnJC5Yo7RtN8+LfpfYkMhD5quI vSFLFUQG1KPSIJV2CUszI2PMVmSF/q7tLFWskHVd1v3Av8mxjzI3gb4B9+ODkw/Z4opR 9gjhd7vKexGlUPErVU/VcLfT/d+O7plunDpduZ3MSwI+UsdvQVEu57JTUIQ4rzAMW+VB wAQt28HTmXjEXrVZqbl1SvreKh110urIUsddVcctN+HNtcOc5nh49YQzLpCFYIgVfQGk J8gOdtsdCb7SQPjYGb+cIN7v8MxPmGRsQ9GgX72z8sM0FwU8JJ8kyXEU85QSFYy320Lw FGTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Q32mHKPGDkuvDTZO77v5e/9rrL8uc641LsKfnn0e2tU=; b=BDwW/ZhBoV5n6H63G/CzmcKEfD7zsh7yeoyCTvZ6SI2Cc/Yj8k/egrGXA3Y9a8HI9d FHYUIFv1O5zBG5XL0ptnQGaQbw3Os3XEJnh/Scw5k3Fzm5fmDfCKDtLq8dXJAWM6ul1V vF6waGrLntk9qdh92EPJJadYg7WeWBEvJvd/u3EcYj0kL/Febcm+X7D7uxNGniQ8tvvs DzD7t+8duCJ3t7TI6jI5oI4BuJrjC/DY566yCJeg9Um7MYB9eILFIwztlT0YTER6CAY6 VvgMKHEdxs5qnU94xSkSCVsSt5eOxHF/U/eb/Z89Onmn2ctor+SPcenFiHKlO0M0VC6t WcLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k191-20020a6384c8000000b0039d6a49d79fsi5610302pgd.4.2022.04.13.04.40.36; Wed, 13 Apr 2022 04:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229459AbiDMDQd (ORCPT + 99 others); Tue, 12 Apr 2022 23:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbiDMDQ2 (ORCPT ); Tue, 12 Apr 2022 23:16:28 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A81BC5523A for ; Tue, 12 Apr 2022 20:14:07 -0700 (PDT) Received: from cwcc.thunk.org (pool-108-7-220-252.bstnma.fios.verizon.net [108.7.220.252]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 23D3E1MV003624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Apr 2022 23:14:02 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id CD4D815C003E; Tue, 12 Apr 2022 23:14:01 -0400 (EDT) Date: Tue, 12 Apr 2022 23:14:01 -0400 From: "Theodore Ts'o" To: Andrew Cc: Ritesh Harjani , linux-ext4@vger.kernel.org, Andrew Perepechko Subject: Re: [PATCH v3] ext4: truncate during setxattr leads to kernel panic Message-ID: References: <20220402084023.1841375-1-anserper@ya.ru> <20220405095451.kx43cdu2ureywgcq@riteshh-domain> <697a8e92-513c-c81f-e619-57fa94bad4d0@ya.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <697a8e92-513c-c81f-e619-57fa94bad4d0@ya.ru> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Apr 07, 2022 at 09:25:40PM +0300, Andrew wrote: > > dd if=/dev/zero of=/tmp/ldiskfs bs=1M count=100 > mkfs.ext4 -O ea_inode /tmp/ldiskfs -J size=16 -I 512 > > mkdir -p /tmp/ldiskfs_m > mount -t ext4 /tmp/ldiskfs /tmp/ldiskfs_m -o loop,commit=600,no_mbcache > touch /tmp/ldiskfs_m/file{1..1024} > > V=$(for i in `seq 60000`; do echo -n x ; done) > V1="1$V" > V2="2$V" > > for k in 1 2 3 4 5 6 7 8 9; do > ???????setfattr -n user.xattr -v $V /tmp/ldiskfs_m/file{1..1024} > ???????setfattr -n user.xattr -v $V1 /tmp/ldiskfs_m/file{1..1024} & > ???????setfattr -n user.xattr -v $V2 /tmp/ldiskfs_m/file{1024..1} & > ???????wait > done > > umount /tmp/ldiskfs_m Hi Andrew, Thanks for the reproducer. I'll note that with the proposed patch, we will allocate a *large* number of delayed_iput_work structure, and most of the time, it is not necessary to do a delayed_iput, since we won't actually be releasing the ea_inode. That only happens when the ea_inode's refcount goes to zero. So we could significantly reduce the overhead of this patch by plumbing whether the refcount went to zero in ext4_xattr_inode_update_ref() up through ext4_xattr_inode_dec_ref() to ext4_xattr_set_entry(), and have it only call delayed_iput() if the refcount went to zero. Alternatively, we could add a function to fs/ext4/orphan.c which checks whether the old_ea_inode is on the orphan list. And if it is on the orphan list, then we know that the refcount must have gone to zero, and so we need to call delayed_iput(). If the ea_inode isn't on the orphan list, we can just use iput(), which will be fast, since it will only be dropping i_count, and we don't need to worry about the ea_inode getting truncate. Could you take a look at this optimization, and then update the commit description to explain what's happening, inlude the kernel stack, and the reproducer? Many thanks! - Ted