From patchwork Sun Nov 6 05:34:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "wuqiang.matt" X-Patchwork-Id: 16068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1340382wru; Sat, 5 Nov 2022 22:46:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5a9Qmw6IgoRAGtWi3/vW8vFhvRq1D0R95YIon8J1+zVxooDboSBU6gin2WxMaJQNzUR6DS X-Received: by 2002:a05:6402:354d:b0:462:51ac:b766 with SMTP id f13-20020a056402354d00b0046251acb766mr44016137edd.415.1667713608380; Sat, 05 Nov 2022 22:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667713608; cv=none; d=google.com; s=arc-20160816; b=p8fU3j3unnp1omiKDxFPgAVpm7JsS9AzwcgCxpoYLqTdq5z3ow7/niJMis227KCxDy lLUOc5QFncW7dkXIXdiQItA6rB0NuOy7fjckQzXMlUFHX+uV5FrZA2gknJu1RJXimMdO VWdBu8MkBgN58qJb91fsxGK9GAt0LrcQypC7ECdW02LjuLnSNyrGoPwfr/PAUQl8F5J8 HZfA9WKiRoC6KQ+djTO6KwbpaB6dRBTt9Hp/T7K+DgmJe3bdksNrgsiYBzSgMQJHQ0HR 9fDYeX+Q4yiKb98yTVg81GGJjEdsZ/znjWD/hVORNHuIYZTi/DEYRImTKfWfI66Uh7tX ppTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OkVJDMV1dLbnY0a97cBJ8dALMRcKW3eBADQn81KDV+U=; b=ivWkczr1ClI3+gzoKb8VFToc8kGGMQCWGBVk8IYB8CB2obcWxSj/bUgoQg27Tp0CV6 jCEmg642vaD19cK8r0AGesYIqGn0kGhrmdhop6ucb6LiGqRHGIojf679c5RYXNcJG5JG PBaDiarRYwLhQIHoKR9vVcfHYDdAlk/tP/vr39h5snHtV/+Rgl6yKcLxPucqJajNq/hy RO6t5n99M0WeCJ13CKqqMplD3de+EGYblqKjOPh5ssaGsl+Hqo3Tdj48mvujVdVKXj5f NVQ3ucGab6Zf5LASHuESrmVYNXZPKNDlr9BP5UPDOiRCAc5vSg6sSUqa7OMdYd8/jTHo f80Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=TGQEp1Ni; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs20-20020a170906dc9400b0079b40c09982si4720351ejc.340.2022.11.05.22.46.24; Sat, 05 Nov 2022 22:46:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=TGQEp1Ni; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229701AbiKFFgV (ORCPT + 99 others); Sun, 6 Nov 2022 01:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbiKFFgP (ORCPT ); Sun, 6 Nov 2022 01:36:15 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8736965AE for ; Sat, 5 Nov 2022 22:36:09 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id q9so7912362pfg.5 for ; Sat, 05 Nov 2022 22:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OkVJDMV1dLbnY0a97cBJ8dALMRcKW3eBADQn81KDV+U=; b=TGQEp1NiL7c1ui00qNnf0UpvEYUfVDnvSWok5/lR1f3GpJuHW4OC/Cy4XizOe/t0ip N/QNbJBzpAANWnVGttDiJJUNbk9lxRVS9gcZs4Hfi4EhqeIFMWpGKxxg7qaYuZqoLHA+ xyvRmoHhKlBvLHXekit6pWiQKYKblnFkUj/joOnpAHPtSVPrSIJk5MECEyGoYT8/jBvr EEvIWFhgkknw7ZeQvMP073JHKzeP5RSBTrZmbPR1ZYKGA+nrfo5G1LyIuCD2GdTqUClm r6FL1ff/QylU5/ODdPaydMSIpahmawJYHWTSVWfsmJKz1XfGSEq7JE32vssD2KT6xm7G YyCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OkVJDMV1dLbnY0a97cBJ8dALMRcKW3eBADQn81KDV+U=; b=cWs4xei4dO+bZcopBLfH+1FRr6+x6KSy2RfwyiX0rAOrffupXEf6aJmbmF41kep3Iq EPrS8faV7IVXafmBZ3CGq5BMWMzJJ6d+mCzEH0fHCwDhfcMWetACMIaujtCaWcqVvdO3 N6gA9WO2juTPtqOhMq9CzV++oLSB0faUJYiojHqY07yLUl0qCrJxuh5FOSbXOX38idWN D1Yv2IcVMuJ+BnCIUy0gD18sqyIFMPvJUp/7m8TEx1KwRR3SxJKRXpVspDFGDv9ArOtS XfhgBKpcReMlmhRg38D8w8l0l9Hf4cqcAAHpDpdrtFIbzJMzfqJ3Xcfhs3LHkX5Vz+LZ q+1Q== X-Gm-Message-State: ACrzQf1HlQvm4DTHH2Md4HxM6ifhuDgDmSxMbHrJOxjcClXSRgYk5hVP +Bik0yJqXJVIvrBeEIevD5bqdg== X-Received: by 2002:a05:6a00:1251:b0:56d:cabd:7207 with SMTP id u17-20020a056a00125100b0056dcabd7207mr26920231pfi.45.1667712968824; Sat, 05 Nov 2022 22:36:08 -0700 (PDT) Received: from devtp.bytedance.net ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q27-20020aa7961b000000b0056bee236e9csm2127121pfg.142.2022.11.05.22.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 22:36:08 -0700 (PDT) From: wuqiang To: mhiramat@kernel.org, davem@davemloft.net, anil.s.keshavamurthy@intel.com, naveen.n.rao@linux.ibm.com, rostedt@goodmis.org, peterz@infradead.org, akpm@linux-foundation.org, sander@svanheule.net, ebiggers@google.com, dan.j.williams@intel.com, jpoimboe@kernel.org Cc: linux-kernel@vger.kernel.org, lkp@intel.com, mattwu@163.com, wuqiang Subject: [PATCH v5 4/4] kprobes: freelist.h removed Date: Sun, 6 Nov 2022 13:34:41 +0800 Message-Id: <20221106053441.103199-5-wuqiang.matt@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106053441.103199-1-wuqiang.matt@bytedance.com> References: <20221102023012.6362-1-wuqiang.matt@bytedance.com> <20221106053441.103199-1-wuqiang.matt@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748724464816747619?= X-GMAIL-MSGID: =?utf-8?q?1748724464816747619?= This patch will remove freelist.h from kernel source tree, since the only use cases (kretprobe and rethook) are converted to objpool. Signed-off-by: wuqiang --- include/linux/freelist.h | 129 --------------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 include/linux/freelist.h diff --git a/include/linux/freelist.h b/include/linux/freelist.h deleted file mode 100644 index fc1842b96469..000000000000 --- a/include/linux/freelist.h +++ /dev/null @@ -1,129 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */ -#ifndef FREELIST_H -#define FREELIST_H - -#include - -/* - * Copyright: cameron@moodycamel.com - * - * A simple CAS-based lock-free free list. Not the fastest thing in the world - * under heavy contention, but simple and correct (assuming nodes are never - * freed until after the free list is destroyed), and fairly speedy under low - * contention. - * - * Adapted from: https://moodycamel.com/blog/2014/solving-the-aba-problem-for-lock-free-free-lists - */ - -struct freelist_node { - atomic_t refs; - struct freelist_node *next; -}; - -struct freelist_head { - struct freelist_node *head; -}; - -#define REFS_ON_FREELIST 0x80000000 -#define REFS_MASK 0x7FFFFFFF - -static inline void __freelist_add(struct freelist_node *node, struct freelist_head *list) -{ - /* - * Since the refcount is zero, and nobody can increase it once it's - * zero (except us, and we run only one copy of this method per node at - * a time, i.e. the single thread case), then we know we can safely - * change the next pointer of the node; however, once the refcount is - * back above zero, then other threads could increase it (happens under - * heavy contention, when the refcount goes to zero in between a load - * and a refcount increment of a node in try_get, then back up to - * something non-zero, then the refcount increment is done by the other - * thread) -- so if the CAS to add the node to the actual list fails, - * decrese the refcount and leave the add operation to the next thread - * who puts the refcount back to zero (which could be us, hence the - * loop). - */ - struct freelist_node *head = READ_ONCE(list->head); - - for (;;) { - WRITE_ONCE(node->next, head); - atomic_set_release(&node->refs, 1); - - if (!try_cmpxchg_release(&list->head, &head, node)) { - /* - * Hmm, the add failed, but we can only try again when - * the refcount goes back to zero. - */ - if (atomic_fetch_add_release(REFS_ON_FREELIST - 1, &node->refs) == 1) - continue; - } - return; - } -} - -static inline void freelist_add(struct freelist_node *node, struct freelist_head *list) -{ - /* - * We know that the should-be-on-freelist bit is 0 at this point, so - * it's safe to set it using a fetch_add. - */ - if (!atomic_fetch_add_release(REFS_ON_FREELIST, &node->refs)) { - /* - * Oh look! We were the last ones referencing this node, and we - * know we want to add it to the free list, so let's do it! - */ - __freelist_add(node, list); - } -} - -static inline struct freelist_node *freelist_try_get(struct freelist_head *list) -{ - struct freelist_node *prev, *next, *head = smp_load_acquire(&list->head); - unsigned int refs; - - while (head) { - prev = head; - refs = atomic_read(&head->refs); - if ((refs & REFS_MASK) == 0 || - !atomic_try_cmpxchg_acquire(&head->refs, &refs, refs+1)) { - head = smp_load_acquire(&list->head); - continue; - } - - /* - * Good, reference count has been incremented (it wasn't at - * zero), which means we can read the next and not worry about - * it changing between now and the time we do the CAS. - */ - next = READ_ONCE(head->next); - if (try_cmpxchg_acquire(&list->head, &head, next)) { - /* - * Yay, got the node. This means it was on the list, - * which means should-be-on-freelist must be false no - * matter the refcount (because nobody else knows it's - * been taken off yet, it can't have been put back on). - */ - WARN_ON_ONCE(atomic_read(&head->refs) & REFS_ON_FREELIST); - - /* - * Decrease refcount twice, once for our ref, and once - * for the list's ref. - */ - atomic_fetch_add(-2, &head->refs); - - return head; - } - - /* - * OK, the head must have changed on us, but we still need to decrement - * the refcount we increased. - */ - refs = atomic_fetch_add(-1, &prev->refs); - if (refs == REFS_ON_FREELIST + 1) - __freelist_add(prev, list); - } - - return NULL; -} - -#endif /* FREELIST_H */