Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp603364rdb; Thu, 8 Feb 2024 15:45:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTAuCY+zeq97xzSzPGjBK0UV0yDtD9nDfsVy11QqeLxk8IHWV4sliPKDBkK+oe8eCIRT23 X-Received: by 2002:a05:6830:4dc:b0:6e2:7958:340c with SMTP id s28-20020a05683004dc00b006e27958340cmr1071915otd.0.1707435929704; Thu, 08 Feb 2024 15:45:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435929; cv=pass; d=google.com; s=arc-20160816; b=p5ML3HHNMLy9kkVIFDmO+4C+kw/NO+8CqQut3hoI2QqjwmL+D23r6lZPE7q7o0UHkD XTYgK3dCpzIPK5b8NJpMgZLrygKL2nQXAPA1sQte5q6nrrFa0XPtPGBOZieGV9OY171I 5/7e84CaG3Xk9cqHKiza30lGj/2hJE7WN/SdFTFsTbNmwiqCSRLxIeWPdwu46ikZ+Nx7 OmUGIiBGyiGr52GZaU9nZKD2xLG0bAGN88MqWxPneOxq4RN/NfyiQ6/siZHou+WynsZM XvMSvoFMZ1Ms/QLNgYxGtsWm1MfSq9zdTUh0lBir/EBWIuAllBJvp9wvD5g3l0DvCMsc KyCg== 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:dkim-signature :dkim-signature:dkim-signature; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; fh=oQZCikS5BAs/pKFk03t92nbGmDcaY8jtybJFgKQkQWs=; b=i6qbAysopei69282SW1XOj6orzRH+GIDjuQv49iYFlcfgfOTkpMkOEZMsKsgGrUxuv PATQxANHTwPfRVjDY22dRVXuYSxK/f5keDX3Q1s2K3wPVW2f/O1n5vcJqWDcds3zca0E 2U39xNQhD+ymyXoxurTAgzDAc0h6ubuxAsMdaQdxkquoqjY+URSkXzyTtPTPZAzsZwFH vHAgxRSUmBfn2Q3O2bc/FLdkPocyS8hKUM0u1j31No9sCqaReKfW0iC471TSj49+k+3p Bkmh+jjuphEUFxfxYfIW6HywXo333dGEABegtZHuy7n94eoNe/scakp6fv3GuUXH66Tc hwXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58878-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCXhxAT2soFcjNZmsvm/TA50xV0Py+olx+CZa+Wp7+aCePvHc0Ub1fx9KXUv9CWldlvoGEJtZK2VEmfudZteU4FDrfiaUFWA+h+J5HY8sg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t30-20020a63b25e000000b005ce087e0049si614050pgo.696.2024.02.08.15.45.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:45:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58878-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58878-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4AADA286ED8 for ; Thu, 8 Feb 2024 23:45:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6076051018; Thu, 8 Feb 2024 23:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="FqIo5CvJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="e9Com5bm"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="FqIo5CvJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="e9Com5bm" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 1AB9B50267 for ; Thu, 8 Feb 2024 23:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707435916; cv=none; b=Q/GuHL9+oywkO2z3VJ4tTb49be1x0UOJiVaEgEddeqlDXviEoQQgqRIGcr0qgzNCEeOxYulrwnE67IJ8Jtem9rQB0xCc5I8Hh+Pp5FfKCGYThYDNfLYMzVpSN+yJQbOvXjxsBWnu8Ngchk8E1XhQCEZJ+vPGshTDMtVGCRuTLFg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707435916; c=relaxed/simple; bh=wdjyH8x1YZucLguMDb3KPjDfIknPxybLEtYyM3a0pcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IsJurOFWSh6MzLgeEEkVehitK0/yXz6LeX7/xSXScxsWbPv5zZ/XHDM2zsvY97cZ7Bx8Q4hiwRJePqIttsBuGmRR6F0psYSUdRZ4hTwUY0MjVXh+Me/z3aVuJ6VOrBFcfNeQ4Oqx4vddiVqFe2cf44UveBBUnsgxLhnaV7jKiuM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=FqIo5CvJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=e9Com5bm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=FqIo5CvJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=e9Com5bm; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO 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) -- 2.43.0