Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16127393rwd; Mon, 26 Jun 2023 06:11:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XJCk7XPQffYunK5wmUWxMJVyr33JB+qtYqFER+43dHDAxXstLDjcSt39jQFubTzU/tjGe X-Received: by 2002:aa7:ccc3:0:b0:51d:7e6b:7aa1 with SMTP id y3-20020aa7ccc3000000b0051d7e6b7aa1mr4944778edt.11.1687785092064; Mon, 26 Jun 2023 06:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687785092; cv=none; d=google.com; s=arc-20160816; b=x7wnIeJqo5hmN6TEzHtA9Jsktvtp3vwl0+KhFpykBDBeWmceUM/t34g6KiSRlYEoTX 7Db/6X3bS5RhfBG9tBGIakXv45rzkLNX8ndDfjr6eHgLxB5U8P9L5z0KOnQUIA7ffPHj 02omSL49fv6Wz1JQ/2i4alNbL9T7noBYQ9T6mlAbqxz4pUZ4F+N3p4i71BdomIiyMap4 vnY1sgY82ynvofcFYK+skHNpSxtSZHbhypUdjtBIBXwPEbq0R693v000SMdD+9hga+Nz 6tMJGwvOSFu07RIxhA2J/swhhwztVrLtOyRdQQBNu3oXfD1e7kspB5o5kI8dm06OHfl9 cTGw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=p6JfJgn7WigU75C2F7rQV1RIBlnMRsvyrWJCIdw/dCA=; fh=g9R67Jh3/bk856kmA8XVLoP0slgbpj3g5F2jAGnuQIc=; b=DGT/H0/cI8gjt2KNSypcjfQMizqzJlojHIIWBmKQN7owD2Prx8fS4IBnIrCGLtcJiR LoOyI6iSIRaT0AzgLgoQlOURxUyWidqWWxQ+fdqLn0i6YBiKiPRr7Ltjq9p7phIG4/+M PeUBE3AgklHyEp1GA10V/OmSiUBjD13Z8XbfzSVGQqWV8O8m70mkaYB1wcNf5lsJAIZg bynNg7VY3gm10eoVDWYVqGuzgwhpvo/5ZM34jLYN/eAUUsl541mDeCy7dKZw0n6Rc/un jQElwxCfMvctel6vb6tTGsKl4aVRm3xuR8v4EjFcEyWD3E2bRcS5MkIMu/O2vTrQi9K4 Aa0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=eys9iBcH; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="VXWH/ebY"; 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 n10-20020aa7c78a000000b0051bf671a7fasi2581467eds.577.2023.06.26.06.11.07; Mon, 26 Jun 2023 06:11:32 -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; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=eys9iBcH; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="VXWH/ebY"; 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 S229601AbjFZNKF (ORCPT + 99 others); Mon, 26 Jun 2023 09:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjFZNKE (ORCPT ); Mon, 26 Jun 2023 09:10:04 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E699B9; Mon, 26 Jun 2023 06:10:03 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3A4031F8AB; Mon, 26 Jun 2023 13:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1687785002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p6JfJgn7WigU75C2F7rQV1RIBlnMRsvyrWJCIdw/dCA=; b=eys9iBcHZeEhwoM+4xJcArAsNTJEoZ4F5/JuvySgzA6lig0YQ2tKBwmhJgJeGuTKW0ojic uU6ctK6n8OkxZ1BPLsNhpVVwGfa3dN5NOYQdiORfGNJsaHjXve08g9PgKOjHS89z+XuLtS G20EEJ5kA0P7k0HkW1y/WVHUf7dDKB8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1687785002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p6JfJgn7WigU75C2F7rQV1RIBlnMRsvyrWJCIdw/dCA=; b=VXWH/ebYmCkoxq1Jrdwc3zdPADBQ/c6B+J2fQ2Otd4ECu7PfiGlen3urUdNidZRR7g2tvt zOaSHX36FGPHZwAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9D9F613483; Mon, 26 Jun 2023 13:10:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hTf9JSmOmWQaXgAAMHmgww (envelope-from ); Mon, 26 Jun 2023 13:10:01 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 472B1A0754; Mon, 26 Jun 2023 15:09:57 +0200 (CEST) Date: Mon, 26 Jun 2023 15:09:57 +0200 From: Jan Kara To: Baokun Li Cc: Jan Kara , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH] quota: fix race condition between dqput() and dquot_mark_dquot_dirty() Message-ID: <20230626130957.kvfli23djxc2opkq@quack3> References: <20230616085608.42435-1-libaokun1@huawei.com> <20230616152824.ndpgvkegvvip2ahh@quack3> <20230622145620.hk3bdjxtlr64gtzl@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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 Hello! On Sun 25-06-23 15:56:10, Baokun Li wrote: > > > I think we can simply focus on the race between the DQ_ACTIVE_B flag and > > > the DQ_MOD_B flag, which is the core problem, because the same quota > > > should not have both flags. These two flags are protected by dq_list_lock > > > and dquot->dq_lock respectively, so it makes sense to add a > > > wait_on_dquot() to ensure the accuracy of DQ_ACTIVE_B. > > But the fundamental problem is not only the race with DQ_MOD_B setting. The > > dquot structure can be completely freed by the time > > dquot_claim_space_nodirty() calls dquot_mark_dquot_dirty() on it. That's > > why I think making __dquot_transfer() obey dquot_srcu rules is the right > > solution. > Yes, now I also think that making __dquot_transfer() obey dquot_srcu > rules is a better solution. But with inode->i_lock protection, why would > the dquot structure be completely freed? Well, when dquot_claim_space_nodirty() calls mark_all_dquot_dirty() it does not hold any locks (only dquot_srcu). So nothing prevents dquot_transfer() to go, swap dquot structure pointers and drop dquot references and after that mark_all_dquot_dirty() can use a stale pointer to call mark_dquot_dirty() on already freed memory. Honza -- Jan Kara SUSE Labs, CR