Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp167087pxh; Thu, 7 Apr 2022 17:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNMv5a9hZ+AbcA5ooEQuR2rMLjyyroG4gnlSgjGVimFD4CeQ5m8dHoWkNZtnZwRfwJVNAv X-Received: by 2002:a17:90b:3e82:b0:1c7:2920:7c54 with SMTP id rj2-20020a17090b3e8200b001c729207c54mr19112846pjb.2.1649378333920; Thu, 07 Apr 2022 17:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649378333; cv=none; d=google.com; s=arc-20160816; b=lAG4rcWtS5O4LuuKuYVyOHv8gNTy25allTcx34ccKu3c6aI+A9PBX1rcb3tJKu52iw Ew9MDWzhMN9qd7La1g8UHPqOxwS1AcoeM2ADsAsNro6O5QaKFxw4DhZfjb+YbUBBSrif Qh3ixpYAkyQ06VKbefcyEPZGdCcnvZf3HyrKMyauiCj8kE5HKql7CRuflwftHT85Lowd Pifs8iwt2aXSlqQSJ6u14tdcqsxIZzRfA5FzFZCw1kWoJpglkUjmMvGdzSlxkY4D7A4L B6TH9M4DCyUAqHTfI2RgXERh79SQzprQWdJtseuBPTLwSSou3mJ/mQ6Zt663+d/eNB/q NbbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=PfNmVPJPOYhZo6mM9f4K9oOc3fjfxWYYQ/iwukBRnhg=; b=HllRrgzZ1xCIu7DNOq5E8XtmNVxBHyWZsF4nH5HtADQEvp2GB0LN4JTom/ct/D4SyB hVPlL7sA9xfuf8y0e5euwwx7SAQp1hiMeanO7/chcA/xY7ZoFcpSEq+tJagh2RG4KY1T J8ll4GPGwT/4yfCQBgzpEdtwL7HMufUtkYJwbFl4iqD1QfwFOSXY1ykIJPyg1v6bGKUl cQR9JMM9B2aiyzu/X90aLfv4Q5plhAd2RYsPMd68QOEFu8y9t3K0Y7QfsJxR2QQ96FfQ +9sY7CP8kSlIZc8kqVe3MoWeyV4kSfKkOCLs74B9oXUqdeP5UF77qNFqIT7QcWW9VYMS w3jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oraFk9ph; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n4-20020a63b444000000b003816043ef5bsi21921931pgu.336.2022.04.07.17.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 17:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oraFk9ph; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CA0E12C2706; Thu, 7 Apr 2022 17:09:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232680AbiDHALN (ORCPT + 99 others); Thu, 7 Apr 2022 20:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbiDHALK (ORCPT ); Thu, 7 Apr 2022 20:11:10 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4634A2BFC3A for ; Thu, 7 Apr 2022 17:09:08 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id q19so10470836wrc.6 for ; Thu, 07 Apr 2022 17:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=PfNmVPJPOYhZo6mM9f4K9oOc3fjfxWYYQ/iwukBRnhg=; b=oraFk9phjJ55S9hBviFxzSiOkTOQTu7UEJ9re7/6lyBOUw0OQY89NWl6Ih4kH21IxI JY/Yrq8t02I1lVWV/dazvMWc2BWNt/XABfRSqbA+YkgHiA2e7CFE2FSgmQKSUBipDFr1 kbhtpFbZs1XVFAVOJrzhEIfBJPAgz/8PlT/SVTWvFEGhdpX2pDqm/wTCxDVZiRrs6MPv d1r57kJMyzc+7H/5vZBXlyo9BKJqMRWmbxjN6s4VZ9DlhJiA4cv9p2qZGCwKZXAAXePN IZJZdvnGIHvqg/W0D+nn8uBPZBNLQbbUfpN7jHKCH5/QZWDSXgnpZzux4fkQNehLuU0/ Ehxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=PfNmVPJPOYhZo6mM9f4K9oOc3fjfxWYYQ/iwukBRnhg=; b=pkEOwBeWahH5oyws9d9CUGyUpICFaG9RfoHqIx5ZY/QhFCuvpo5GBbmENQVCLTzfht 40qbRyWzPVu1HaYSzRbON3kenyiYBs1J1Iz/yQcxO8Oto4krIi09Bmtkgjn0iI0OJfVk C9ONcv7gvWRFMI1NNjJxYF8LWsD1eStzgdGe4neHkIklukYrjg03Zcl3kSbmcBnrT9IT BDbat9MaxxSL9I2WJw+lZAicQByYztWMRSreFq5Vo8v1Pwa6mccbNxt240r7IWXuHu9X 0QlsUuXmwctpM5ic+yi0na39Rky/dMF3edSJjhotebpmaPHgzo2fQmIkPFt/Q35Gw+iQ lPkg== X-Gm-Message-State: AOAM532Gd8vumKNMOAkYuF23rro5tBRHAxtizlYgKTerIjxGsrqWoQ+d ShEKdsUWYdUiNrjTkzfSR0E= X-Received: by 2002:a5d:6c65:0:b0:204:119d:37e2 with SMTP id r5-20020a5d6c65000000b00204119d37e2mr12255514wrz.635.1649376546646; Thu, 07 Apr 2022 17:09:06 -0700 (PDT) Received: from smtpclient.apple ([185.238.38.242]) by smtp.gmail.com with ESMTPSA id u7-20020a5d6da7000000b00203d9d1875bsm20728387wrs.73.2022.04.07.17.09.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Apr 2022 17:09:06 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue() From: Jakob Koschel In-Reply-To: Date: Fri, 8 Apr 2022 02:09:05 +0200 Cc: Bob Peterson , cluster-devel , LKML , Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." Content-Transfer-Encoding: quoted-printable Message-Id: <0EB429B0-8A2F-4247-8F84-F6A78BD030F0@gmail.com> References: <20220331223857.902911-1-jakobkoschel@gmail.com> To: Andreas Gruenbacher X-Mailer: Apple Mail (2.3696.80.82.1.1) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-kernel@vger.kernel.org > On 4. Apr 2022, at 16:58, Andreas Gruenbacher = wrote: >=20 > Hi Jakob, >=20 > On Fri, Apr 1, 2022 at 12:40 AM Jakob Koschel = wrote: >> In preparation to limiting the scope of a list iterator to the list >> traversal loop, use a dedicated pointer to iterate through the list = [1]. >>=20 >> Since that variable should not be used past the loop iteration, a >> separate variable is used to 'remember the current location within = the >> loop'. >>=20 >> To either continue iterating from that position or start a new >> iteration (if the previous iteration was complete) = list_prepare_entry() >> is used. >=20 > I can see how accessing an iterator variable past a for_each_entry > loop will cause problems when it ends up pointing at the list head. Well, as long as you only use it to access the list head, there should be no problem, hence no bug. The issue are more the cases that use other members of that 'bogus' pointer and there were plenty of such cases [1]. That's why the goal is to "not use the iterator variable after the loop" so the scope can be lowered and such cases are avoided by construction. > Here, the iterator variables are not accessed outside the loops at > all, though. So this patch is ugly, and it doesn't even help. I do agree that this patch is ugly. I'm open to suggestions on how to improve the code allowing to lower the scope of 'bd1' to the traversal loop. But I don't agree that the iterator variables are not used outside of the loops. (If with loops you mean the list traversals). The iterator variables are not used "after" in terms of code location = but since it's wrapped by a while loop they are used "after" in regards of execution time. =46rom the second iteration of the while loop onwards, it will used the leftover 'bd1' pointer from the previous iterations list traversal, = hence using the variables "outside of the traversal loops". Lowering the scope will not be possible because of this. >=20 >> Link: = https://lore.kernel.org/all/CAHk-=3DwgRr_D8CB-D9Kg-c=3DEHreAsk5SqXPwr9Y7k9= sA6cWXJ6w@mail.gmail.com/ [1] >> Signed-off-by: Jakob Koschel >> --- >> fs/gfs2/lops.c | 16 ++++++++++++---- >> 1 file changed, 12 insertions(+), 4 deletions(-) >>=20 >> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c >> index 6ba51cbb94cf..74e6d05cee2c 100644 >> --- a/fs/gfs2/lops.c >> +++ b/fs/gfs2/lops.c >> @@ -653,7 +653,7 @@ static void gfs2_before_commit(struct gfs2_sbd = *sdp, unsigned int limit, >> bool is_databuf) >> { >> struct gfs2_log_descriptor *ld; >> - struct gfs2_bufdata *bd1 =3D NULL, *bd2; >> + struct gfs2_bufdata *bd1 =3D NULL, *bd2, *tmp1, *tmp2; >> struct page *page; >> unsigned int num; >> unsigned n; >> @@ -661,7 +661,7 @@ static void gfs2_before_commit(struct gfs2_sbd = *sdp, unsigned int limit, >>=20 >> gfs2_log_lock(sdp); >> list_sort(NULL, blist, blocknr_cmp); >> - bd1 =3D bd2 =3D list_prepare_entry(bd1, blist, bd_list); >> + tmp1 =3D tmp2 =3D list_prepare_entry(bd1, blist, bd_list); >=20 > We should actually be using list_entry() here, not = list_prepare_entry(). I'm not sure if you are referring to using list_entry() here in the = original or in the changed version. I don't see how that would be much better in either cases. 'bd1' can be = NULL in both cases which would break when simply using list_entry(). In the original code, = 'bd1' would be NULL for the first iteration of the while loop and in the updated = version it would be NULL in the first iteration + every time the list traversal in = the previous iteration did not break early. Just using 'bd1 =3D list_entry(bd1, blist, bd_list);' when initializing = would work in the original code. But it's not solving the scope issue where 'bd1' is used outside of the = list traversal loop. >=20 [1] = https://lore.kernel.org/linux-kernel/20220308171818.384491-1-jakobkoschel@= gmail.com/ Thanks, Jakob