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: 198694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp522367dyd; Thu, 8 Feb 2024 15:45:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoP/bYS2xXgqktdSQnqITYdHxE+Dz2T5ZqkTk0LO/us5zOVSO3PypajWT28AvC8ZEHrfRP X-Received: by 2002:a05:6a20:6f91:b0:19e:b920:89d3 with SMTP id gv17-20020a056a206f9100b0019eb92089d3mr129763pzb.14.1707435949687; Thu, 08 Feb 2024 15:45:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435949; cv=pass; d=google.com; s=arc-20160816; b=PRulXh1V6HH17egBT+eBbDCyPSfNu/oDBWIBZOCeVKeJkTtd9oX7fhWsed/sx10EqN xNFg7tOM/lKY0TBEgrhax5dYKl47lROU85AecNcadsfF4CiVP2mHWzkO6fhnoPJSAhKH sYvxJvytkGjQofBM/XoiqQoBnZLRtqY0fv+f61hVIPxFXJmuUsJA9pXFpHHsoCxEOr6q 6+RweO+0fM5hQDxq9QVu4nDJ33r52acaupjJ0fpMwmR19aSDhLmT/d5BwIvHRV+8lFFX 7hbk3DT/Vrk5TlSAdQUVlWrG/9uEYaTSjSyCHlMEQT/ctt3l07BezGD94+Lx2UbNrtDz TNnA== 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=mVeUunaerEMUBIjeZnDTAXXaeSu91TfU4vhKvopCXs0=; b=S9R5DUnAR57PCmJVQpzgiTe+1pEvjY2YXJwM4/iacwZPhIBA2FFKoXYt3mXgbmWC3P f43beapfCu//9/VX6GUw8MlJ0yeyTwn+aIFhIUMlIabbFLmgLYMLsLrWArmDhzjGCcRp c5+zI2ra3Fe0JnLWY1vRrTRHSPXkQ2lrW98pbxx/hUC+GqbxgyboDkCl+sk+Qr1ywQkC 7bgSCYkHUE/5GcV/Nb/NIIGEDX2gZscViAjRuAXWaX5MZuQfzfFKfnjMz5s811mW59Gt GuX+iJuLwdAqa2sUhg6q+UpG5ck/0uigDCkuZAqSbm7z1vRNJLVILfQq0mgl5xY2lscH OS2g==; 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; 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; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58878-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCUtisK7Kl5pInbixWnuab8t78VTdYBboanlyltYFmjQXEBRXlFeEyndu8bOrvLyL63i4MpL/b5NZeywVod/NvY9NjXaDQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id nh24-20020a17090b365800b002961cc0cda1si528849pjb.83.2024.02.08.15.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:45:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58878-ouuuleilei=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; 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; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58878-ouuuleilei=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 706E0287029 for ; Thu, 8 Feb 2024 23:45:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02DA151C4E; Thu, 8 Feb 2024 23:45:20 +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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376358405231329 X-GMAIL-MSGID: 1790376358405231329 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)