From patchwork Thu Feb 8 23:45:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13550765 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 C6DD2C4829C for ; Thu, 8 Feb 2024 23:45:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 550EF6B0080; Thu, 8 Feb 2024 18:45:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FFF56B0081; Thu, 8 Feb 2024 18:45:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 352F86B0082; Thu, 8 Feb 2024 18:45:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 232456B0080 for ; Thu, 8 Feb 2024 18:45:16 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E94C1A028F for ; Thu, 8 Feb 2024 23:45:15 +0000 (UTC) X-FDA: 81770270190.12.743DDAD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf05.hostedemail.com (Postfix) with ESMTP id B948A10000F for ; Thu, 8 Feb 2024 23:45:13 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707435914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=ujZL4mhDr7yzxxbKq57zSReKTiuTU90o2T0OvCcLQ+FcGo93VHlpDNqSXadaDVatU4Zzwc Gt3iFvlQ3Zm4vfoV9oqxXZ1oxAKdjDOWH6AMqW9zIkxxqDv4Z1EL87ORz7T0RDXz3gx5vJ aBfSVu5HwYTbIdMOX5WsD8xpR5sfqRM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707435914; a=rsa-sha256; cv=none; b=5GxE1myccHJt6aiY0Fi6vSaTBGpaZtQgUeGk6+9u+Q0fCdT1AdwR9PgCvCN0EJ5bfgHKaF BZfDXeFwdXPR1hylDzEnHWN2m4oPlaA3YOdpygH9CJTTuFhgUfvrhHAhpcm4roxLGpkdkq g2D1tAXZ7/y9kfJXwlLk8ieX/SxFvIE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 52DCB2231D; Thu, 8 Feb 2024 23:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=FqIo5CvJ6oX+sMFvUZG+ClyHR4cWlBMV/ux5MN/ol+aO92XWT7VftClRCEZdKUIFqzYobq bbLmF2YqyOIw3TkWci/8KIn+799W0jctO1lgK25+uzR7W6eJXMZYrUGg5hIwJk3KyRGa58 BFUulIJUPi65U4NFdLHvmY0UCPSIoDw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=e9Com5bminDIKvAD8i86K8dC9in6zV+PepP4s9oQpN5dbVpe6CHWBBaeUt5KudzVDTMp8y 6L17clAD++kcEtAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=FqIo5CvJ6oX+sMFvUZG+ClyHR4cWlBMV/ux5MN/ol+aO92XWT7VftClRCEZdKUIFqzYobq bbLmF2YqyOIw3TkWci/8KIn+799W0jctO1lgK25+uzR7W6eJXMZYrUGg5hIwJk3KyRGa58 BFUulIJUPi65U4NFdLHvmY0UCPSIoDw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=e9Com5bminDIKvAD8i86K8dC9in6zV+PepP4s9oQpN5dbVpe6CHWBBaeUt5KudzVDTMp8y 6L17clAD++kcEtAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BEBF413984; Thu, 8 Feb 2024 23:45:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uE7SK4dnxWWUfAAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 23:45:11 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v7 1/4] lib/stackdepot: Move stack_record struct definition into the header Date: Fri, 9 Feb 2024 00:45:36 +0100 Message-ID: <20240208234539.19113-2-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: B948A10000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: in9c7hsugkufch15wyrnbfzizqxc3ghz X-HE-Tag: 1707435913-61344 X-HE-Meta: U2FsdGVkX1+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nLAbs3dfElenygC5zZaObz0RQtmyake0Q51i0QI2yNSYwQcS5F9VRdj6+1USJyePaKmI5s2QyNWDrleR49YcdPdRLXWvwN9Wu7fp5uFozowumVGYhM6LMAMo7ZgPXyU+wrZyDBd2XblACafBFxogFIMryGeUp7qOnjjjNeJ+UEg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In order to move the heavy lifting into page_owner code, this one needs to have access to the stack_record structure, which right now sits in lib/stackdepot.c. Move it to the stackdepot.h header so page_owner can access stack_record's struct fields. Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 44 ++++++++++++++++++++++++++++++++++++++ lib/stackdepot.c | 43 ------------------------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index adcbb8f23600..d0dcf4aebfb4 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -30,6 +30,50 @@ typedef u32 depot_stack_handle_t; */ #define STACK_DEPOT_EXTRA_BITS 5 +#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) + +#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ +#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) +#define DEPOT_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ + STACK_DEPOT_EXTRA_BITS) + +/* Compact structure that stores a reference to a stack. */ +union handle_parts { + depot_stack_handle_t handle; + struct { + u32 pool_index : DEPOT_POOL_INDEX_BITS; + u32 offset : DEPOT_OFFSET_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; + }; +}; + +struct stack_record { + struct list_head hash_list; /* Links in the hash table */ + u32 hash; /* Hash in hash table */ + u32 size; /* Number of stored frames */ + union handle_parts handle; /* Constant after initialization */ + refcount_t count; + union { + unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ + struct { + /* + * An important invariant of the implementation is to + * only place a stack record onto the freelist iff its + * refcount is zero. Because stack records with a zero + * refcount are never considered as valid, it is safe to + * union @entries and freelist management state below. + * Conversely, as soon as an entry is off the freelist + * and its refcount becomes non-zero, the below must not + * be accessed until being placed back on the freelist. + */ + struct list_head free_list; /* Links in the freelist */ + unsigned long rcu_state; /* RCU cookie */ + }; + }; +}; + typedef u32 depot_flags_t; /* diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 5caa1f566553..16c8a1bf0008 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -35,14 +35,6 @@ #include #include -#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) - -#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ -#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) -#define DEPOT_STACK_ALIGN 4 -#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) -#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ - STACK_DEPOT_EXTRA_BITS) #if IS_ENABLED(CONFIG_KMSAN) && CONFIG_STACKDEPOT_MAX_FRAMES >= 32 /* * KMSAN is frequently used in fuzzing scenarios and thus saves a lot of stack @@ -58,41 +50,6 @@ (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) -/* Compact structure that stores a reference to a stack. */ -union handle_parts { - depot_stack_handle_t handle; - struct { - u32 pool_index : DEPOT_POOL_INDEX_BITS; - u32 offset : DEPOT_OFFSET_BITS; - u32 extra : STACK_DEPOT_EXTRA_BITS; - }; -}; - -struct stack_record { - struct list_head hash_list; /* Links in the hash table */ - u32 hash; /* Hash in hash table */ - u32 size; /* Number of stored frames */ - union handle_parts handle; /* Constant after initialization */ - refcount_t count; - union { - unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ - struct { - /* - * An important invariant of the implementation is to - * only place a stack record onto the freelist iff its - * refcount is zero. Because stack records with a zero - * refcount are never considered as valid, it is safe to - * union @entries and freelist management state below. - * Conversely, as soon as an entry is off the freelist - * and its refcount becomes non-zero, the below must not - * be accessed until being placed back on the freelist. - */ - struct list_head free_list; /* Links in the freelist */ - unsigned long rcu_state; /* RCU cookie */ - }; - }; -}; - #define DEPOT_STACK_RECORD_SIZE \ ALIGN(sizeof(struct stack_record), 1 << DEPOT_STACK_ALIGN)