From patchwork Sun Feb 11 12:29:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 199440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1904748dyd; Sun, 11 Feb 2024 04:40:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgLW0UYCT/WfQ6GgvxNm6nCAopRYc9kofxqf7oQVISKWSuUqWdCge9WncqJ7EcQgx3mA8V X-Received: by 2002:a05:6870:3c87:b0:21a:13e6:11d9 with SMTP id gl7-20020a0568703c8700b0021a13e611d9mr5077216oab.43.1707655234777; Sun, 11 Feb 2024 04:40:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707655234; cv=pass; d=google.com; s=arc-20160816; b=DHFg/Ib4WYiHNJkTiToEt1hnlm7bq2Tqgq32I3PfGTFl9yO7t4zIyEsRdIrCq6a2jG 0CzwoJVfcHH4YqoyhAoW56oZ5qH3AWabzLcY1dYFONYcs2DJ+Kiu9o+aMiVEKvhM/yfk T+qmBsq8jSR/ryqvByyABv83cQJ5CpwPsk9TAQ5wzdelJWwHe7Me6Y1o22W0t169Z2nN auvRxeAcsmQ45U6EVqZkRGZGg1rZTQV25ESqLRg18IDmRPtAkgt+xUSIC4XpZHED02E9 Ni3Yu6UHUlUm0NPEmAZrAjurNmwCQS1uTvylgv1Ymzc9uC/zlosMqmN5XYl2koQaWRZE lrlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=g2+Iouf2UVGvs4mCNtCFcBfpV0dyvUFr5y+VeLzPrck=; fh=h6OG0MGJZtCsYQCCLx7T014JcshonuYPKD+bl2E+SVo=; b=CVPY1wptcH4kDWJZuskwrC+hUt/8Ic+kh3b1EhHB84EsQsVpPuSrs3TpEBXA9YBba8 JeTWQc9qOGTFAiAt8YrLSoFNgt3Qio1TftzQf8MDnqhvxlC/uUvSDVnYDt9nLq3kkInt FpgUOFV7FgTQe+78LFb8yK65qPIdKvtbFgrWVKVsnAiigSfWvS5F3+aCgaEB7gJlbYMT 8Lfrr4W6ff+phmsfh+WthNp1/q2XWMab3LwN6K83ofDdMXnldrQPZ8xcwTD75WJ9f/Rv +2jY2L5NQ/8oA/BZ+icAL1PvWYdr7h4SoMkGJ8C9w1PnFa7ZkvzAm/KIZLdBu6Azv3pt r3Ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=UbMOAr5+; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-60749-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60749-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com X-Forwarded-Encrypted: i=2; AJvYcCUXKpxq++/MrTyCtRgVfIEeRXhlp4MikU5Fj5KOkr4sCG8QPF+Uy4+PWYXQ5OUY5W1WPkQSg6oknzEFSvnnnqMe6K6OAQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n27-20020a63721b000000b005d8e28279bcsi4981311pgc.540.2024.02.11.04.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 04:40:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60749-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=UbMOAr5+; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-60749-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60749-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id F2CFBB24329 for ; Sun, 11 Feb 2024 12:36:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 266FD605AC; Sun, 11 Feb 2024 12:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="UbMOAr5+" Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8996D5D8EF for ; Sun, 11 Feb 2024 12:30:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707654641; cv=none; b=jDnDEBzKO5qGMrNOKrUUfZYlXoIOrKVUALfPRsAx3MENAI0yTs3+810+GpB5j9sSgsfbd/5k1fAvXdDBhuSHhqxceXxWBTLo0ozJau6MtZ/lrPlcde4uUVB5OXMAj2Gkm2AkZu4tuaD89i/sQ3xGWdgd/X9KsI6gXi7XdaEm91g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707654641; c=relaxed/simple; bh=Bin3DNZnSCUMXH5aICZHgBTErX76nCGHVd62Jfb1blU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MUy1bfv6j0rXb7fZmq8Pk5j9QqTjf8kQzzlJHuHpyWGLklDzk9cYUVZx/c+ynffJ8tB1Ka2F942mQrbp994pm+sxOhvLSscGHjShKeTjlpOt3+ZX8qgVIJFuMlxUye5l/U76DnmE8XWgY6H1/BDbwLEanzLPinnbcxNDfJIttac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=UbMOAr5+; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-55fc7f63639so3064041a12.1 for ; Sun, 11 Feb 2024 04:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1707654635; x=1708259435; darn=vger.kernel.org; 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=g2+Iouf2UVGvs4mCNtCFcBfpV0dyvUFr5y+VeLzPrck=; b=UbMOAr5+WlTmM231cRZS58cov+cb/YMrF9AnfJR4Ym3F1G5I1zTzgYC2VrZ2cRDkLZ QM1WniK/GGeIwgxoUGc3ObUIX9zKZb131M5hIjtyNkXuLdbNPcFrdroC45A7o3yPTHDT Ckn5O52bVFZk6mj9Uh8PaYd6OdwqUJ+eguYPWNFM0B8hCw2qvhWisQchHfk4+ZJrSsgl VCFpeVbfXI5Ag5GMmZkyYnrQFsFs1TlGXU8ap0N0lLzxUV5/LEjBoc7OPokAhOiHcMLf 4IU5czYho3U7tYh5RrgP0jHyD/eFZ2BScG/pFrxLZdGn7wr0PDjOLjfIDx8+pUElA/4E 7aJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707654635; x=1708259435; 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=g2+Iouf2UVGvs4mCNtCFcBfpV0dyvUFr5y+VeLzPrck=; b=geV5/VhT0f79pT7S9j6zpE48ZplDapl3+Tzwf+wamDyw3JAgJGU0VezVqbCRr0jNjA x/IjC4w9C8Byc6T5sHEv3jEFCkgF9yDGIpsOo+APXYDA6kZibdQRjR+5emx46ZQEwQQS 95ZD/NLyjKxVvShp4piXo8OqjxOYMWN/YtggdhPu0epRBmPOQD0vJyJBZJXVDo9JA9iu 1QL2Jqw4AAgtKSmh1pAAXdXy4SFbmFvqdTRECx9NRwfeVn7v6bLGctY4wAN6AQqABty0 Yn2mU6Pmv/OodnYSyH0jpeWObBhCctlOYdKkyE+sRRAfBTrNLRc+krNSdNMx58XuGqPY 68VA== X-Gm-Message-State: AOJu0YzaGxLH2qVm7iMddLH3OSMgbi94CN7Rcdrlq4rlSmZiU4JtVJcp jOfaWRk4fLzbJN3mQMZiizbZd5E2GQhO///EtEnosmbJxQEVQPKYBNxaOIkFyt2P929gruqK1fu 5 X-Received: by 2002:aa7:db54:0:b0:560:e589:f6dc with SMTP id n20-20020aa7db54000000b00560e589f6dcmr2818776edt.33.1707654635513; Sun, 11 Feb 2024 04:30:35 -0800 (PST) Received: from raven.intern.cm-ag (p200300dc6f267100023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f26:7100:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id fj18-20020a0564022b9200b0056187ca4120sm1024611edb.10.2024.02.11.04.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 04:30:34 -0800 (PST) From: Max Kellermann To: linux-kernel@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v3 21/35] percpu-refcount.h: move declarations to percpu-refcount_types.h Date: Sun, 11 Feb 2024 13:29:46 +0100 Message-Id: <20240211123000.3359365-22-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240211123000.3359365-1-max.kellermann@ionos.com> References: <20240211123000.3359365-1-max.kellermann@ionos.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790606295495459298 X-GMAIL-MSGID: 1790606295495459298 By providing declarations in a lean header, we can reduce header dependencies. Signed-off-by: Max Kellermann --- drivers/target/target_core_pr.c | 1 + drivers/target/target_core_xcopy.c | 1 + include/linux/blkdev.h | 2 +- include/linux/bpf-cgroup-defs.h | 2 +- include/linux/bpf.h | 2 +- include/linux/cgroup-defs.h | 2 +- include/linux/cgroup.h | 1 + include/linux/percpu-refcount.h | 64 +----------------------- include/linux/percpu-refcount_types.h | 71 +++++++++++++++++++++++++++ include/linux/slab.h | 1 - include/target/target_core_base.h | 2 +- 11 files changed, 80 insertions(+), 69 deletions(-) create mode 100644 include/linux/percpu-refcount_types.h diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 6ed604a164f8..0ee29c16a161 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index df06ec0f75fe..37d306570f8a 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6747965c3580..5cd0edada09d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include // for iov_iter_is_aligned() diff --git a/include/linux/bpf-cgroup-defs.h b/include/linux/bpf-cgroup-defs.h index f3b400858129..70b79fd81fee 100644 --- a/include/linux/bpf-cgroup-defs.h +++ b/include/linux/bpf-cgroup-defs.h @@ -5,7 +5,7 @@ #ifdef CONFIG_CGROUP_BPF #include -#include +#include #include struct bpf_prog_array; diff --git a/include/linux/bpf.h b/include/linux/bpf.h index c5c435d04460..e28c74dd67ab 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 99e24f3034df..878deefba0e1 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 24dcff53bd05..19a5e801f77d 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index dd2f19ea08bd..ded13def0acd 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -50,74 +50,12 @@ #ifndef _LINUX_PERCPU_REFCOUNT_H #define _LINUX_PERCPU_REFCOUNT_H -#include +#include #include #include #include #include -struct percpu_ref; -typedef void (percpu_ref_func_t)(struct percpu_ref *); - -/* flags set in the lower bits of percpu_ref->percpu_count_ptr */ -enum { - __PERCPU_REF_ATOMIC = 1LU << 0, /* operating in atomic mode */ - __PERCPU_REF_DEAD = 1LU << 1, /* (being) killed */ - __PERCPU_REF_ATOMIC_DEAD = __PERCPU_REF_ATOMIC | __PERCPU_REF_DEAD, - - __PERCPU_REF_FLAG_BITS = 2, -}; - -/* @flags for percpu_ref_init() */ -enum { - /* - * Start w/ ref == 1 in atomic mode. Can be switched to percpu - * operation using percpu_ref_switch_to_percpu(). If initialized - * with this flag, the ref will stay in atomic mode until - * percpu_ref_switch_to_percpu() is invoked on it. - * Implies ALLOW_REINIT. - */ - PERCPU_REF_INIT_ATOMIC = 1 << 0, - - /* - * Start dead w/ ref == 0 in atomic mode. Must be revived with - * percpu_ref_reinit() before used. Implies INIT_ATOMIC and - * ALLOW_REINIT. - */ - PERCPU_REF_INIT_DEAD = 1 << 1, - - /* - * Allow switching from atomic mode to percpu mode. - */ - PERCPU_REF_ALLOW_REINIT = 1 << 2, -}; - -struct percpu_ref_data { - atomic_long_t count; - percpu_ref_func_t *release; - percpu_ref_func_t *confirm_switch; - bool force_atomic:1; - bool allow_reinit:1; - struct rcu_head rcu; - struct percpu_ref *ref; -}; - -struct percpu_ref { - /* - * The low bit of the pointer indicates whether the ref is in percpu - * mode; if set, then get/put will manipulate the atomic_t. - */ - unsigned long percpu_count_ptr; - - /* - * 'percpu_ref' is often embedded into user structure, and only - * 'percpu_count_ptr' is required in fast path, move other fields - * into 'percpu_ref_data', so we can reduce memory footprint in - * fast path. - */ - struct percpu_ref_data *data; -}; - int __must_check percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release, unsigned int flags, gfp_t gfp); diff --git a/include/linux/percpu-refcount_types.h b/include/linux/percpu-refcount_types.h new file mode 100644 index 000000000000..9f4f93e8faaf --- /dev/null +++ b/include/linux/percpu-refcount_types.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_PERCPU_REFCOUNT_TYPES_H +#define _LINUX_PERCPU_REFCOUNT_TYPES_H + +#include +#include + +struct percpu_ref; +typedef void (percpu_ref_func_t)(struct percpu_ref *); + +/* flags set in the lower bits of percpu_ref->percpu_count_ptr */ +enum { + __PERCPU_REF_ATOMIC = 1LU << 0, /* operating in atomic mode */ + __PERCPU_REF_DEAD = 1LU << 1, /* (being) killed */ + __PERCPU_REF_ATOMIC_DEAD = __PERCPU_REF_ATOMIC | __PERCPU_REF_DEAD, + + __PERCPU_REF_FLAG_BITS = 2, +}; + +/* @flags for percpu_ref_init() */ +enum { + /* + * Start w/ ref == 1 in atomic mode. Can be switched to percpu + * operation using percpu_ref_switch_to_percpu(). If initialized + * with this flag, the ref will stay in atomic mode until + * percpu_ref_switch_to_percpu() is invoked on it. + * Implies ALLOW_REINIT. + */ + PERCPU_REF_INIT_ATOMIC = 1 << 0, + + /* + * Start dead w/ ref == 0 in atomic mode. Must be revived with + * percpu_ref_reinit() before used. Implies INIT_ATOMIC and + * ALLOW_REINIT. + */ + PERCPU_REF_INIT_DEAD = 1 << 1, + + /* + * Allow switching from atomic mode to percpu mode. + */ + PERCPU_REF_ALLOW_REINIT = 1 << 2, +}; + +struct percpu_ref_data { + atomic_long_t count; + percpu_ref_func_t *release; + percpu_ref_func_t *confirm_switch; + bool force_atomic:1; + bool allow_reinit:1; + struct rcu_head rcu; + struct percpu_ref *ref; +}; + +struct percpu_ref { + /* + * The low bit of the pointer indicates whether the ref is in percpu + * mode; if set, then get/put will manipulate the atomic_t. + */ + unsigned long percpu_count_ptr; + + /* + * 'percpu_ref' is often embedded into user structure, and only + * 'percpu_count_ptr' is required in fast path, move other fields + * into 'percpu_ref_data', so we can reduce memory footprint in + * fast path. + */ + struct percpu_ref_data *data; +}; + +#endif diff --git a/include/linux/slab.h b/include/linux/slab.h index a7ee429c0535..df92bb41affb 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 5b9156adceca..1598a4062398 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -5,7 +5,7 @@ #include /* struct config_group */ #include /* enum dma_data_direction */ #include -#include +#include #include /* struct semaphore */ #include