Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp899057pxp; Wed, 16 Mar 2022 20:35:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiIeQeUhx2yCCo8BlbtLRbN+3eHuJ3TqgOgD6IzBxUre3qdMEb+VIzlZvpQ41ERiiXqIMp X-Received: by 2002:a17:902:d4c2:b0:151:d590:a13d with SMTP id o2-20020a170902d4c200b00151d590a13dmr2526637plg.85.1647488157385; Wed, 16 Mar 2022 20:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647488157; cv=none; d=google.com; s=arc-20160816; b=FiPru6808bZ/Vj+t7xY1j16iMH+ycFl4SKX7JkuZE9C+YAQ6DTKHnfmbGysyJ82BCk QFNKP5IaiGqq/feKEwEX4Ya5fcF+fiHlhDnCj+AyZl6Uu19FRtD6Ip7+11aiwnB/NJa1 K7IJHjh47oZ1Q6j2YVgMOC3TFGzporZ/Ia2/3zgcSz6kFY92fpqXNqC/fW/HspzqQLdh IGEa56pFcjziO3sxqrSe9VFzhXiLRx52uf+uQs8aT1mMe5cLI5BnvLk8w8BAqedDX5Nx d2wb/ZuGfr6F337djYvsNflqKulaQw4NUAY0e82OKqJcJOFEQf3j0IdtmBPn27fuURXO NiQw== 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:dkim-signature; bh=wAgk6NoEkSGQYtklkyp/XBe3mmZFGzBwfiqA3+Hd+Uc=; b=ViWjr5Sd0XRFrzynnwOH9zFMfPsZecCd54gg+E0cecsRvVwWpNIBg8SxufY1jRlBFD Bv0o4ARnWYDafbGfwvnDgXYb36EKLhT5zzY0eEYMl++QhjIGVmgK0/3gzRWOExhtEFne VcGA6heS8BZMGgVP9hXtx+RNArynLmhdeeqIvR2eUqpsN6CVqAMAd8Sw2Ob1CF2dgTr9 u0zp/hsnH/9oxyNX/S6IzeoH0C2SroEYt/Z8rX5iXdhdrUW7tVafyp58NmGWrF/yiv+e 0TzxkbWhgrgS60hWEU4O82n8EPpH6S7hXMZ0lcAoinEaUrmTzMW00Gm/2/znLpDs7OHk ZNpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UaDuw6uE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q6-20020a17090311c600b0015348674bdesi3844362plh.31.2022.03.16.20.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:35:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UaDuw6uE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2A81351E5E; Wed, 16 Mar 2022 20:31:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357317AbiCPPrG (ORCPT + 99 others); Wed, 16 Mar 2022 11:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240242AbiCPPrE (ORCPT ); Wed, 16 Mar 2022 11:47:04 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB336D1B4 for ; Wed, 16 Mar 2022 08:45:49 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id p9so3519712wra.12 for ; Wed, 16 Mar 2022 08:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=wAgk6NoEkSGQYtklkyp/XBe3mmZFGzBwfiqA3+Hd+Uc=; b=UaDuw6uE+eA3eoFtbNNWGH31fmxdFNfCd+8KTwJiz+XVa67E6qGA7rnSF18inN9r7Y qagW0lhTrjPtdLbMts8uQresOtZcaucElVE6QTjJOHL4nHQiHmARLSAiHbxM+ilNC8I9 0pB+mcIYzA8CpBXVvR2Muc6zTjci9aX7iOglulhiX/5PGxKANkvqyGmlBXTy1HgQZtZa dbiMZu3JglXKMidVnZzd7qJ7o28dPtoNgg2mpDLH8lwkr9ymuiri75xLap5GrnGWoiKM 2YmMN97zjLq8pQYxfLoXbmyytnuWDrXDEPJT6p/AzVirsoxEYO2L+1VZIt0QeRwrV5A/ a5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=wAgk6NoEkSGQYtklkyp/XBe3mmZFGzBwfiqA3+Hd+Uc=; b=CK9amKJUfxr6WVkV1GDZLHxFOSK/2WXuGHDzA0EkqFad/okddXgyEdIC6dtwq6Dj06 02T6h7fUcoi+W9GZGU8i70OrSWgn+c5Tdj9ezZ4xI5cDA7TlzERRAt/ytzzVBNRIHc6W lJVa0osIn99aN4B/buXHfVI8KTpp4ts8dIsHu2LLSV+yzBVQdWiAbc+3aytmgNNUVED4 XSaLawnGHCsoer57VIc4wze+WCIyE6zIfp+nvscK6yPnDCog7a8D6Aey9LtOjzOhH+oT fRugwUkgEi2aZRRHvTkYGs1qIBlR+vEJ+D5s4HTnmrLkg/7h3+pNeKWDaRY9Rk3b4ncu aJXg== X-Gm-Message-State: AOAM5308GPso80axpTPuxzHwM9xyzTn6sP2vL/gw6Ag1065nibfAwT+k YJn6x+OQIzGhMDhTLscVb8NSmA== X-Received: by 2002:a5d:4cc1:0:b0:1f0:98e7:6af0 with SMTP id c1-20020a5d4cc1000000b001f098e76af0mr409578wrt.363.1647445547485; Wed, 16 Mar 2022 08:45:47 -0700 (PDT) Received: from maple.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id 11-20020a05600c26cb00b0037ff53511f2sm4927285wmv.31.2022.03.16.08.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:45:46 -0700 (PDT) Date: Wed, 16 Mar 2022 15:45:44 +0000 From: Daniel Thompson To: Linus Torvalds Cc: Xiaomeng Tong , Arnd Bergmann , Greg Kroah-Hartman , Jakob Koschel , Jann Horn , Kees Cook , Linux Kbuild mailing list , Linux Kernel Mailing List , Linux-MM , Netdev , =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Subject: Re: [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Message-ID: <20220316154544.bfewwi7zseyyja47@maple.lan> References: <20220304025109.15501-1-xiam0nd.tong@gmail.com> <20220311142754.a3jnnjqxpok75qgp@maple.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 Fri, Mar 11, 2022 at 10:41:06AM -0800, Linus Torvalds wrote: > On Fri, Mar 11, 2022 at 6:27 AM Daniel Thompson > wrote: > > > > It is possible simply to use spelling to help uncover errors in > > list_traverse()? > > I'd love to, and thought that would be a lovely idea, but in another > thread ("") Barnabás Pőcze pointed out that we actually have a fair > number of cases where the list member entries are embedded in internal > structures and have a '.' in them: > > https://lore.kernel.org/all/wKlkWvCGvBrBjshT6gHT23JY9kWImhFPmTKfZWtN5Bkv_OtIFHTy7thr5SAEL6sYDthMDth-rvFETX-gCZPPCb9t2bO1zilj0Q-OTTSbe00=@protonmail.com/ > > which means that you can't actually append the target_member name > except in the simplest cases, because it wouldn't result in one single > identifier. > > Otherwise it would be a lovely idea. When I prototyped this I did actually include a backdoor to cover situations like this but I ended up (incorrectly at appears) editing it out for simplicity. Basically the union is free so we can have more than one type * member: #define list_traversal_head(type, name, target_member) \ union { \ struct list_head name; \ type *name##_traversal_type; \ type *name##_traversal_mismatch_##target_member; \ } This allows that the single structure cases to be checked whilst nested structures (and array which I noticed also crop up) have a trap door such as list_traverse_unchecked(). I did a quick grep to estimate how many nested/array cases there are and came up with around 2.5% (roughly ~200 in ~8500, counting only the single line users of list_for_each_entry() ). As you say, lovely idea but having to use special API 2.5% of the time seems a bit on the high side. BTW, a complete aside, but whilst I was looking for trouble I also spotted code where the list head is an array which means we are not able to lookup the travesral type correctly: list_for_each_entry(modes[i], &connector->modes, head) However I found only one instance of this so it much more acceptable rate of special cases than the 2.5% above. > > > [this bit used to quote the definition of LIST_HEAD() ;-) ] > > For architectures without HAVE_LD_DEAD_CODE_DATA_ELIMINATION then the > > "obvious" extension of list_traversal_head() ends up occupying bss > > space. Even replacing the pointer with a zero length array is still > > provoking gcc-11 (arm64) to allocate a byte from bss (often with a lot > > of padding added). > > I think compilers give objects at least one byte of space, so that two > different objects get different addresses, and don't compare equal. > > That said, I'm not seeing your issue. list_traversal_head() is a > union, and always has that 'struct list_head' in it, and that's the > biggest part of the union. Perhaps its a bit overblown for the safe of a few kilobytes (even if there were two traversal types members) but I was wondering if there is any cunning trick for LIST_HEAD() since we cannot have an anonymous union outside a struct. In short, is this the best we can do for LIST_TRAVERSE_HEAD(): #define LIST_TRAVERSE_HEAD(type, name, target_member) \ type * name##_traversal_type; \ struct list_head name = LIST_HEAD_INIT(name) #define STATIC_LIST_TRAVERSE_HEAD(type, name, target_member) \ static type * name##_traversal_type; \ static list_head name = LIST_HEAD_INIT(name) Daniel.