From nobody Sun Apr 12 23:21:46 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4B2AC4167B for ; Sun, 18 Dec 2022 05:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbiLRFFL (ORCPT ); Sun, 18 Dec 2022 00:05:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbiLRFEc (ORCPT ); Sun, 18 Dec 2022 00:04:32 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A41DEAD for ; Sat, 17 Dec 2022 21:04:07 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id o12so6118316pjo.4 for ; Sat, 17 Dec 2022 21:04:07 -0800 (PST) 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=oyVXGSBfQ66N/vpiNxVgFLg9BI1lff6swGj32icd6FZI8eLgtvfwoQFYVXSOtNpWNF PHooMjjc2xUCxPK03BcUhC6Dt194C7f1n0xbkBQHKu7QU4I56YMsKMsIcQQ1w1VawMtV ZOaavZta9+n5GOE9kM6HnqwYQ7SfOB/chu7QOvmCzX1gLTsDPI88vlqNFizyVQdRXMC9 JQh8AH1kUa7JFxQQ2XVszNAyLi0bAe5Mj6W0ZU3kfaoPgFa3lSA31VzUDNzldSylmXqm tfnDvH2Db+NaFmEpPA9Xlgv4TeHGZdNoM5iiCYQDcdzNM5uRfWgVUuCAz9U60vv9+UxV xvEg== 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=wQ7aHz2SfNywC20AuDmqyMPaF8bXmgNIZ25pTaCCXN5ZlNjEksxoUql4RG4SKDVNTW 2ixs0DxgifkjbXea65cQwPh3qHQ3L3/1b0LAsXjjS81ZBx9+FdHP8r1lpy47T7spN5IL pP1wpPW3rdqyLI1H/mysIz+wzKejdmmzcD02lKIcw5P5lKOMlp/Y0hYdZrpRxeREDJMn 4QrC6v7PEmkQpd7dZEHQ7LhV9VsQj8EeN6LIjoZiQsp6wpm4GFuFAmGr7Ty5gnlU4jNC 36S8Zy+c4FtOdNsc/oRsHC/NUtAquaGaLlu98w8QztRDpl0UTI4pD1BfWzuLx3f9aiac /sQg== X-Gm-Message-State: ANoB5pmX6wmA1Dg3L9Ge8TUAgqBOgNyqxWSQnDjMHoEufSZM5Bes974O M9UbJqwgtcSilL/TTqdACGCf3g== X-Google-Smtp-Source: AA0mqf5iz0sghyQs9vPP/LF0CKGGNyKHrNANq2LpfVWI6BYvmAOhhDGMAivwz+ap0a0OkLKd7qeluw== X-Received: by 2002:a17:902:d18c:b0:189:df3c:1ba1 with SMTP id m12-20020a170902d18c00b00189df3c1ba1mr34790233plb.38.1671339847179; Sat, 17 Dec 2022 21:04:07 -0800 (PST) Received: from devtp.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id v20-20020a170902ca9400b001708c4ebbaesm4339348pld.309.2022.12.17.21.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Dec 2022 21:04:06 -0800 (PST) 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 v8 4/5] kprobes: freelist.h removed Date: Sun, 18 Dec 2022 13:03:09 +0800 Message-Id: <20221218050310.1338630-5-wuqiang.matt@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221218050310.1338630-1-wuqiang.matt@bytedance.com> References: <20221218050310.1338630-1-wuqiang.matt@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 wo= rld - * 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 freel= ist_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 =3D 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) =3D=3D = 1) - continue; - } - return; - } -} - -static inline void freelist_add(struct freelist_node *node, struct freelis= t_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 =3D smp_load_acquire(&list->head= ); - unsigned int refs; - - while (head) { - prev =3D head; - refs =3D atomic_read(&head->refs); - if ((refs & REFS_MASK) =3D=3D 0 || - !atomic_try_cmpxchg_acquire(&head->refs, &refs, refs+1)) { - head =3D 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 =3D 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 =3D atomic_fetch_add(-1, &prev->refs); - if (refs =3D=3D REFS_ON_FREELIST + 1) - __freelist_add(prev, list); - } - - return NULL; -} - -#endif /* FREELIST_H */ --=20 2.34.1