Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp798713pxp; Fri, 11 Mar 2022 15:26:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSyJrgI24P0XGgfIse1DvKK14zqk+Jl+E8B+sZ1cFHJZEpwkDPKDOw//9ZHs9aGAMJ5bYH X-Received: by 2002:a17:90a:3d44:b0:1bf:584d:7fa with SMTP id o4-20020a17090a3d4400b001bf584d07famr13084581pjf.217.1647041201856; Fri, 11 Mar 2022 15:26:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647041201; cv=none; d=google.com; s=arc-20160816; b=JCff6E/RWcFCt+l0qQvER0zUjpnykGpIlD9dt0SKKlBZKZRXmefzJaxym9/I2hQzWF gkbtlHVt/+2IhUox1i0jr3/bxXuM0POAwKBQ3stPy1YcQTS44Xx38pjK2ml+dJQg3fd9 fZYurp10DyscZfuYTLqFDwp+EXYhnqpX5d7Cb4VRMghqTshOoUX5DvVJgiYHDG7rcM8B I5BsR4a6pqfz3O9gcOiis0YzbX/pYJLBKqPqPUytTuS/eRgYLPqsEAxph/oEAlXpd+d5 DZTqJYxCd6vFDEMqwmP31lygy2LgWjJ7aYaCAf4Evy1uLI44Wm3G/QRLNpIZWddFpjYo iF8w== 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=MpXiSYabOrYwVZBoUNg0nqtYEvuBi16Uja5dFf2EH0o=; b=a6PDFcdwUCdxYAXyfq2RLRt0I4auNQS/7CP5cVPCIrLaRIltMT7HfmX+XdAbhTvdel Gnz9A+xdFMXl929AfXXB3iarEHhUuKV+J4IaTr9FPlRwTYueWlZnrt4q9fHT1CUpp0OS 0Vt++u0ZwjkZLnEDJUmg4+fmyRHE9A7wZjnpmu4nE5SjR9NjwJuUcFYSyv1PQ0g1me9C XbwPcRtgNAGJkQHXmfqATV12Az7CnrIhI1fIP+nTBF/jkFvj/8Stxp7u6omIMtYfN5c9 6VTZI4Y2g2NIL/MP/vaGdos1QVp7PNabb2MDhnQ0CJfSbDMrn3iYDf2NKoomsGHGC4tc UdZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k2nh2gjD; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m1-20020a639401000000b00372cbbdd8d6si9014386pge.637.2022.03.11.15.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 15:26:41 -0800 (PST) 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=@linaro.org header.s=google header.b=k2nh2gjD; 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=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 B52CA3BEFEB; Fri, 11 Mar 2022 14:13:40 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244651AbiCKO3E (ORCPT + 99 others); Fri, 11 Mar 2022 09:29:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349253AbiCKO3D (ORCPT ); Fri, 11 Mar 2022 09:29:03 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51B5012624 for ; Fri, 11 Mar 2022 06:27:58 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id i66so5202429wma.5 for ; Fri, 11 Mar 2022 06:27:58 -0800 (PST) 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=MpXiSYabOrYwVZBoUNg0nqtYEvuBi16Uja5dFf2EH0o=; b=k2nh2gjDZ2GWduILDMTVTdPhwUGy/gKiaKiDAAeWeNvWs+qTTrNrgWKCpvV5YZTUem oS/VqO60ezzCYtbnUQI49E+RYcTTpPSClCwilaRKFbUWSxsD5nb47zN5aSspNsfFktFZ FkbA1p2tgEoHpfs74AHjwcd7z1Fmq06KPg4uI1LJjNZjy+w0+El9JAo7Kd2WQgnuoWT+ HpMizIPvpJ4kBD8vcbDXLo7JWtSiBBROSlbVgdGvOfUJcbc+q2t6xbeJDOeNJ7IgcDkf oPtG5W7BIAAQOD9tgIZbFNVeFcpnIzkbhUQGtMeyPsJMSxGYr8R3kg3jnU3j/sB/SxSq Xk9A== 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=MpXiSYabOrYwVZBoUNg0nqtYEvuBi16Uja5dFf2EH0o=; b=3fzgZfMBQOjxDaR0cu8EyLXv15decE+ifsOqEtvm55YRptfBdMPzf0Avy7UhQaeVqx Ltx8sNBVdp4576SMPhvAbhDO/QMyG/fa7KdGRQWLcrxAg8fKBD6rkw561DYJbKweywnI l+iOubm7R//WxQk/mT75J3Sq1zokMPEPpM/wv34Jw4myvPDeFpYuBUw+YEBSHF60Kewj W/luX3p4vGLSbwNALUYDGc8uS3M1fNtvU1kRz9NrvhtdMgwVtgo8A/gttctbAybtNE27 coMAmbd36HDG3Q/aJ8w0bJWgekeEisDrD7++oGdoImQSqFuZwyHJsqv5rAZHE3NdGiPb hHcg== X-Gm-Message-State: AOAM532ifQgsUgYdxk4C7cUmjpk1ZRPff7lk8BdPut1+U4vaNhtszjNA Fw9nck26YUJV/fi+9OwYckyUtQ== X-Received: by 2002:a1c:f718:0:b0:380:ed20:6557 with SMTP id v24-20020a1cf718000000b00380ed206557mr16407510wmh.53.1647008876745; Fri, 11 Mar 2022 06:27:56 -0800 (PST) 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 u23-20020a7bcb17000000b0037bdfa1665asm14118274wmj.18.2022.03.11.06.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 06:27:56 -0800 (PST) Date: Fri, 11 Mar 2022 14:27:54 +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 Subject: Re: [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Message-ID: <20220311142754.a3jnnjqxpok75qgp@maple.lan> References: <20220304025109.15501-1-xiam0nd.tong@gmail.com> 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 Sat, Mar 05, 2022 at 04:35:36PM -0800, Linus Torvalds wrote: > On Sat, Mar 5, 2022 at 1:09 PM Linus Torvalds > wrote: > What do people think? Is this clever and useful, or just too > subtle and odd to exist? > NOTE! I decided to add that "name of the target head in the target > type" to the list_traversal_head() macro, but it's not actually used > as is. It's more of a wishful "maybe we could add some sanity checking > of the target list entries later". > > Comments? It is possible simply to use spelling to help uncover errors in list_traverse()? Something like: #define list_traversal_head(type, name, target_member) \ union { \ struct list_head name; \ type *name##_traversal_mismatch_##target_member; \ } And: #define list_traverse(pos, head, member) \ for (typeof(*head##_traversal_mismatch_##member) pos = list_first_entry(head, typeof(*pos), member); \ !list_entry_is_head(pos, head, member); \ pos = list_next_entry(pos, member)) If I deliberately insert an error into your modified exit.c then the resulting errors even make helpful suggestions about what you did wrong: kernel/exit.c:412:32: error: ‘struct task_struct’ has no member named ‘children_traversal_mismatch_children’; did you mean ‘children_traversal_mismatch_sibling’? The suggestions are not always as good as the above (children_traversal_mismatch_ptrace_entry suggests ptraced_traversal_mismatch_ptrace_entry) but, nevertheless, it does appears to be robust in detecting incorrect traversal. > diff --git a/include/linux/list.h b/include/linux/list.h > index dd6c2041d09c..1e8b3e495b51 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -25,6 +25,9 @@ > #define LIST_HEAD(name) \ > struct list_head name = LIST_HEAD_INIT(name) Seeing this in the diff did set me thinking about static/global list heads. 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). Perhaps in the grand scheme of things this doesn't matter. Across the whole tree and all architecture I see only ~1200 instances so even in the worst case and with padding everywhere the wasted RAM is only a few kb. Nevertheless I was curious if there is any cunning tricks to avoid this? Naturally LIST_HEAD() could just declare a union but that would require all sites of use to be updated simultaneously and I rather like the way list_traverse_head() is entirely incremental. Daniel.