From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A839C433EF for ; Tue, 1 Mar 2022 07:58:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E32D8D0002; Tue, 1 Mar 2022 02:58:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 06B658D0001; Tue, 1 Mar 2022 02:58:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4E868D0002; Tue, 1 Mar 2022 02:58:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id D27298D0001 for ; Tue, 1 Mar 2022 02:58:52 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 9956D611AA for ; Tue, 1 Mar 2022 07:58:52 +0000 (UTC) X-FDA: 79195066104.06.C1C7C24 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf10.hostedemail.com (Postfix) with ESMTP id 26ABAC0007 for ; Tue, 1 Mar 2022 07:58:51 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id o8so13757835pgf.9 for ; Mon, 28 Feb 2022 23:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=P4+if8GN83/wfWPDcl6lkO0MQCgRlrUm6Ra8zxANWzo=; b=jVLcKFPzakyWM+RQb/0ul+4n8tO42mKE1SlgxDi7pH+hDRBIdGh0hyyW2huYd6ECd6 EJ0LgH897rdvv5s82GclAiSy0qqr6k6aLxDuXhEp3G4VOfMonvEy+T4NObheJizEW8EN OZAsMYaVuw+tV3YNY1nleT2qJyAJFKuxlGSOGvK0YJHmZNCvc0lyqci5mj9G2GVqhFqL CJ/w9fn5SPl/wlUAjrSbKW81iGp9g5fa8pD97Mj94zRzQ68rpgVBUNzqnL//z0l3kVGE WmTWkWAE+t0oY0YuG+24qtW7tre/KBPtPxwokcrVM2RvwBQCBQHMUao2O1w46D/CnkaJ rM/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P4+if8GN83/wfWPDcl6lkO0MQCgRlrUm6Ra8zxANWzo=; b=gFTLnW3/l/mvO22CfPtHoiPefRSXCU+g8I/uFfhJ73hH8M3ZPMuoJTmn9ooG2EiQiS CujL90Hvc6o38WpTd03J05Pf96OpM6pZIyVioNgubC4MZ5Rip6XADC9230sqDLICE999 JRRH4u3brrd4M8L8LIoOACoUhiVJ+024MsngQNFORJCWKR3NBN1XwjM2Mde+q/80MEUQ lwYiTKMHb2WxnSGL2EaLRVDytE0MeAONJDid1rxD0qVRng5oNnL5UzTOnO9GwD0rz/nH gqeNswrV6zPXrA+NYPiHtNf1miZPEX4pGbMC66HPJ3lrDJx/D6ky8Z8x45pGlvggnc5o UDAQ== X-Gm-Message-State: AOAM533mJ9SqaW4B67Fh5SzRQVROw0hmIJS6P8QBVpPZb3531h+4pcqH AUeRWtBbtQCIjy+eabbpcZI= X-Google-Smtp-Source: ABdhPJwi5i8FBEj6kIQyujAuuTOa0vFqvdtJ0PdLM8pyS8A9utok6C8uWjitfJaMiC2UqTRVYFXtQA== X-Received: by 2002:a63:1d65:0:b0:375:3d96:36b4 with SMTP id d37-20020a631d65000000b003753d9636b4mr21050857pgm.165.1646121531026; Mon, 28 Feb 2022 23:58:51 -0800 (PST) Received: from ubuntu.huawei.com ([119.3.119.18]) by smtp.googlemail.com with ESMTPSA id o12-20020a17090aac0c00b001b9e5286c90sm1662745pjq.0.2022.02.28.23.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 23:58:50 -0800 (PST) From: Xiaomeng Tong To: torvalds@linux-foundation.org Cc: arnd@arndb.de, jakobkoschel@gmail.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, keescook@chromium.org, jannh@google.com, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, Xiaomeng Tong Subject: [PATCH 0/6] list_for_each_entry*: make iterator invisiable outside the loop Date: Tue, 1 Mar 2022 15:58:33 +0800 Message-Id: <20220301075839.4156-1-xiam0nd.tong@gmail.com> X-Mailer: git-send-email 2.17.1 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 26ABAC0007 X-Stat-Signature: bi39uhg5kezbpxpz6mubwsthajk9tcn7 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jVLcKFPz; spf=pass (imf10.hostedemail.com: domain of xiam0nd.tong@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=xiam0nd.tong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-HE-Tag: 1646121531-950847 X-Bogosity: Ham, tests=bogofilter, spamicity=0.001455, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In this discuss[1], linus proposed a idea to solve the use-after-iter problem caused by the inappropriate iterator variable use of list_for_each_entry* macros *outside* the loop. The core of the idea is that make the rule be "you never use the iterator outside the loop". The perfect way should be "you are prohibited by the compiler from using iterator variable outside the loop". Thus, we can declare the iterator variable inside the loop and any use of iterator outside the loop will be report as a error by compiler. "declare the iterator variable inside the *for* loop" needs something above gnu89 (like -std=gnu11), which is the task of PATCH 1. The core patch of this series is PATCH 2, which respectively implements a new iterator-inside macro for each list_for_each_entry* macro (10 variants). The name of the new macro is suffixed with *_inside*, such as list_for_each_entry_inside for list_for_each_entry. The reason for a new macro instead of directly modification on origin macro is that, there are 15000+ callers of there macros scattered in the whole kernel code. We cannot change all of these correctly in one single patch considering that it must be correct for each commit. Thus, we can define a new macro, and incrementally change these callers until all these in the kernel are completely updated with *_inside* one. At that time, we can just remove the implements of origin macros and rename the *_inside* macro back to the origin name just in one single patch. The PATCH 3~6 demonstrate how to change list_for_each_entry* callers into *_inside one. Note all these 4 patch are just to prove the effectiveness of the scheme for each list_for_each_entry* macro (10 variants). I think the reasonable way is to kill all these 15000+ callers *on a file basis*, considering that different macros may be called in the same context and depend on each other, instead of *on a separate macro basis*. [1]: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ Xiaomeng Tong (6): Kbuild: compile kernel with gnu11 std list: add new MACROs to make iterator invisiable outside the loop kernel: remove iterator use outside the loop mm: remove iterator use outside the loop net/core: remove iterator use outside the loop drivers/dma: remove iterator use outside the loop Makefile | 2 +- drivers/dma/iop-adma.c | 9 +-- include/linux/list.h | 156 ++++++++++++++++++++++++++++++++++++++++ kernel/power/snapshot.c | 28 ++++---- kernel/signal.c | 6 +- mm/list_lru.c | 10 +-- mm/slab_common.c | 7 +- mm/vmalloc.c | 6 +- net/core/gro.c | 3 +- 9 files changed, 191 insertions(+), 36 deletions(-) -- 2.17.1