Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp693982rwb; Thu, 15 Dec 2022 00:52:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5b2omouV+Ngjf5iSI89BkRfn4sgVxIgeqfm0VAhhU0llxf+T5V5JSDH/dzNY30sIT8n6rN X-Received: by 2002:a17:907:d0e:b0:7c0:a4e9:615b with SMTP id gn14-20020a1709070d0e00b007c0a4e9615bmr31004581ejc.61.1671094344260; Thu, 15 Dec 2022 00:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671094344; cv=none; d=google.com; s=arc-20160816; b=FebGm4Vwq/wTPzXmUnS2PrNP87U0JtR49wRwTCBg1lTZu3SMFQbZGlFd0A4pY+HsWf k5tomRnzkTm5d3P25xdDUChBUKaBOCaMOx8puuvyF8F8bQrzqDBeVVOryP8RVSZU0alM XPHl8Mufr+Iz+vPR64/ESLyKDHegw5D2Ez3tReT2GssswawTsPiwtbEH7k++fDd+JVbU nlSvyIxRb1QfS/Ola/70lMo0HfDKhR+qGHRCAzQSgL+ditrdHGULKmW9z3XWrG5JtGqY bczY984qTUqr+kPV9w5XmMBquUZuDbn/4HSqdVlTjnneA5wL62pUtYru8vqFYpraDPU+ Apog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=FikWI/l5AjZP/tASMxSkWRsninfKg7konnJ54xHO4Ho=; b=N4VQQPI0h8KhpnCCAUXbvoXMi/pk6Q2u0ExqMJkL9715Pa3RgClmBsYZ6vegGv1FFZ M+5crZUU3SLSfqRFhTlTpz+HRFsjqdk5uEmf9M/rATqzUTBixEo6/7XJCW7YoWP3ukOt OrHkHOWUcCL8/m7eRJYYRa/9lMluhIw7wVSxNj5P531zTFmzAMxORJOhFcwUfcQz9d3O 8g02PQdYAfAxYiw439suPCm+AzyRtM1AmkfV/qKIdaEMlhAw2CRakUVYJl9eJozU6Tu3 FVgeY+vppAU4W3ChSlHKqJDDkMfAWmMfZomSbiNQIxo0lEpS/wVVPVi/MW8NUTzUEuyU PxYw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga25-20020a1709070c1900b007c0e3900f27si14927041ejc.43.2022.12.15.00.52.01; Thu, 15 Dec 2022 00:52:24 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbiLOIuP (ORCPT + 99 others); Thu, 15 Dec 2022 03:50:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229752AbiLOIt6 (ORCPT ); Thu, 15 Dec 2022 03:49:58 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657D03D3A0 for ; Thu, 15 Dec 2022 00:49:57 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NXmBl1YWVz4f3jJF for ; Thu, 15 Dec 2022 16:49:51 +0800 (CST) Received: from [10.174.178.134] (unknown [10.174.178.134]) by APP4 (Coremail) with SMTP id gCh0CgDnV9Ww35pjHIUSCQ--.16773S3; Thu, 15 Dec 2022 16:49:54 +0800 (CST) Subject: Re: [RFC PATCH] ext4: dio take shared inode lock when overwriting preallocated blocks To: Zhang Yi , Theodore Ts'o , Jan Kara Cc: linux-ext4@vger.kernel.org, adilger.kernel@dilger.ca, yukuai3@huawei.com, ritesh.list@gmail.com References: <20221203103956.3691847-1-yi.zhang@huawei.com> <20221214170125.bixz46ybm76rtbzf@quack3> <442e060a-de74-1e54-4fa3-5e4d35597dbe@huawei.com> From: Zhang Yi Message-ID: Date: Thu, 15 Dec 2022 16:49:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <442e060a-de74-1e54-4fa3-5e4d35597dbe@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID: gCh0CgDnV9Ww35pjHIUSCQ--.16773S3 X-Coremail-Antispam: 1UD129KBjvJXoW7AFy7Cr4xCw13uw15Zr4xJFb_yoW8KF48pF WrK3W5Kw4Dtry7urn2qF97WFyF93yktrWUZFZaq3WUAryq9rnagrnrtFWUAay0qrZ3Jayq vF4aqry3CFyqvaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS 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 2022/12/15 16:41, Zhang Yi wrote: > On 2022/12/15 2:52, Theodore Ts'o wrote: >> On Wed, Dec 14, 2022 at 06:01:25PM +0100, Jan Kara wrote: >>> >>> Besides some naming nits (see below) I think this should work. But I have >>> to say I'm a bit uneasy about this because we will now be changing block >>> mapping from unwritten to written only with shared i_rwsem. OTOH that >>> happens during writeback as well so we should be fine and the gain is very >>> nice. >> >> Hmm.... when I was looking potential impacts of the change what >> ext4_overwrite_io() would do, I looked at the current user of that >> function in ext4_dio_write_checks(). >> >> /* >> * Determine whether the IO operation will overwrite allocated >> * and initialized blocks. >> * We need exclusive i_rwsem for changing security info >> * in file_modified(). >> */ >> if (*ilock_shared && (!IS_NOSEC(inode) || *extend || >> !ext4_overwrite_io(inode, offset, count))) { >> if (iocb->ki_flags & IOCB_NOWAIT) { >> ret = -EAGAIN; >> goto out; >> } >> inode_unlock_shared(inode); >> *ilock_shared = false; >> inode_lock(inode); >> goto restart; >> } >> >> ret = file_modified(file); >> if (ret < 0) >> goto out; >> >> What is confusing me is the comment, "We need exclusive i_rwsem for >> changing security info in file_modified().". But then we end up >> calling file_modified() unconditionally, regardless of whether we've >> transitioned from a shared lock to an exclusive lock. >> >> So file_modified() can get called either with or without the inode >> locked r/w. I realize that this patch doesn't change this >> inconsistency, but it appears either the comment is wrong, or the code >> is wrong. >> >> What am I missing? >> > > IIUC, both of the comment and the code are correct, the __file_remove_privs() > in file_modified() should execute under exclusive lock, and we have already > check the IS_NOSEC(inode) and could make sure taking exclusive lock before we > remove privs. If we take share lock, __file_remove_privs() will return directly > because below check. So it's find now, but it looks that call file_update_time() > is enough for the shared lock case. > > int file_update_time(struct file *file) static int __file_remove_privs(struct file *file, unsigned int flags) > { ... > if (IS_NOSEC(inode) || !S_ISREG(inode->i_mode)) > return 0; > ... > } > > Thanks, > Yi. >