From patchwork Wed Jun 19 22:48:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704692 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 8CC6CC2BA1A for ; Wed, 19 Jun 2024 22:49:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECEEE8D0084; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7DF26B00BC; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD0768D0084; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AD53B6B00BD for ; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3861EA42BE for ; Wed, 19 Jun 2024 22:49:47 +0000 (UTC) X-FDA: 82249132014.08.FE11BD9 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf08.hostedemail.com (Postfix) with ESMTP id D6B7D16000A for ; Wed, 19 Jun 2024 22:49:44 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="smRbBT/c"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=g3E3XRzi; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="smRbBT/c"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=g3E3XRzi; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837380; a=rsa-sha256; cv=none; b=4XFETcaG8/LRM3LJ2v1Zd8dwOuqR25qUIEQFgfmooExn7MzjvSMa4FTkgrBX7V9s9MxNTC 2uAH3XDRSu9hoh8IQLPXEaJ5MNN9XLvqGlO2frkRfta6DzbEgK/Dq6frvwQEaWbA3soYDz eR3oQNTpVgCxLJ+gB9wQ6fYjUzF/GFE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="smRbBT/c"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=g3E3XRzi; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="smRbBT/c"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=g3E3XRzi; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837380; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r7eLs3qWVHkCYzNUctfASvMgvFekhPcbd8a5b9Uty8M=; b=AzhH21Oi3rS3rFLHj0Wd0s8kFZTvvd+OB2AQ1VYRmUnKDRV2I/iVvJGF8bI+qVGfxBNrX/ HoBf6XbdMdVG7PM+qX6Bj86oYtK7hl4q5tPqttgQ7AlGCkYkxb8cKvcu9+UuyudkHvXVIO UGqsG9EuqKTVXHN6hRMqDV2T9IgIDuI= Received: from imap1.dmz-prg2.suse.org (unknown [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-out2.suse.de (Postfix) with ESMTPS id 25D261F7F5; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r7eLs3qWVHkCYzNUctfASvMgvFekhPcbd8a5b9Uty8M=; b=smRbBT/csZSGJtlsJ4JN3oklSIC7vbquyuWyYFQK4X7uOph5tB+4a752AntXvJy1S6SyqH IS3Q3mHFdaV3Nuk7YxxoaL7OyDll3aJ5H4tMiqF2zEByxywgSPn6DUWnsDAtqd2l0oVEwI Ih3Y7GYugjJN390WQpBeTcoBGFUj6Z4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r7eLs3qWVHkCYzNUctfASvMgvFekhPcbd8a5b9Uty8M=; b=g3E3XRziF6HgkAAPS88wKQ5lNo4texbHFNeFeEwV0v4mYHhP+i771BZm1quZ/kUsnkbfs9 f1WTtAqzsMR7PdDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r7eLs3qWVHkCYzNUctfASvMgvFekhPcbd8a5b9Uty8M=; b=smRbBT/csZSGJtlsJ4JN3oklSIC7vbquyuWyYFQK4X7uOph5tB+4a752AntXvJy1S6SyqH IS3Q3mHFdaV3Nuk7YxxoaL7OyDll3aJ5H4tMiqF2zEByxywgSPn6DUWnsDAtqd2l0oVEwI Ih3Y7GYugjJN390WQpBeTcoBGFUj6Z4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r7eLs3qWVHkCYzNUctfASvMgvFekhPcbd8a5b9Uty8M=; b=g3E3XRziF6HgkAAPS88wKQ5lNo4texbHFNeFeEwV0v4mYHhP+i771BZm1quZ/kUsnkbfs9 f1WTtAqzsMR7PdDw== 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 0152E13ABD; Wed, 19 Jun 2024 22:49:42 +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 0PuTO4Zgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:42 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:48:55 +0200 Subject: [PATCH v2 1/7] fault-inject: add support for static keys around fault injection sites MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-1-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4698; i=vbabka@suse.cz; h=from:subject:message-id; bh=/cKM1m+IMVDzuJzFS+1fl48bPoWvR2tEgzVaVUXVT8A=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2Byf1V3Bpp5LNGsY/c7Mzv3/GsPZ55FjBkLd LX7xvgBpSWJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNgcgAKCRC74LB10kWI mrooB/987gBj0pha0dvAhFXZiGUJdrVCDtQ6t2BV/SIlkveQM37wjVIcJKlT46POmu0EAVLbGts rfVWVX5e4aCI80nZ5KpkSs0COyqzR+4Eym09R0s0Mm29ctQ8BJYXISybtjvacF6lT2sDF1PvZG8 i3JzV58YERvX5BU+hxW2HjtgpEHgCzBBjFK/t/heKLFCeork00ZpNgQXER2fUDtpVCd4m62wTb9 aJr4p+K+XdUOvo164UnmBjTbqVN9BjUYA1laDaYyZ5+8942w7HBeyumYAqx3oJBarTi3ujoosjc 1Yyw2OhX6svXSoURISrllNMod+BTK/2jVgFrBLmcWyLPRwOW X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Stat-Signature: k5ycomu18w6zjhefuuqgmqjh5wfjsh3m X-Rspamd-Queue-Id: D6B7D16000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718837384-733428 X-HE-Meta: U2FsdGVkX18hz2Rgi/1uA+034FdGfgN4injVQLgWiI/jcdtiSzH0KNO632uSu4HtmDOvtpBeXyHLG3i5jNI5k1JeZj9OWtU1rjv4wiB1xUgFYbcGh4HYpf/d7cKlQvzq03SOQYPJCCq+yzPO7NT+omYN9iBWnxI0eR2NFlVgvBUO/t8sxDyQOGqHcMChzlA0oUZcIe3k0pN15aDJAJYX/s2ShbFGwznvpGbjoIpDQP0Ll/k12CUaII1ktT6JcXYBplWFLpzPNjo3yAVJt9VOU3rJhzhp2dmoVlTW0uuLVCYD+Pw38nR5ujjCSDk7Yxz8IgZktI4D00ZREwR4BAU4oHoR1KfHFcgkqSFolpaIDslXZVuszHcthUxC0s3LRnLEob5/PoID2kRvFVxHb496fPJSsDouyaFb1dzPU2Apvm60kzTEUrR4MphPzB2HVjpHE5y4AsRUsADq0KoQcQfWjXkJlvaWcpt3KYcgHnx36NXZ+l39mXXa/FHmnmji4+jCOdxRa7AH7eH7xd0sLk7zRFM1+iKBj6Q9G05GSstKN3dlSqPUN6IeU6PLRuG7pOYWcjetB6SHR8QkbcGoI5oufkvDYz/g4a38/cQBiQriiy8SrfdYuQWfTRKddr5PDOowM5gcUomKVrkaIJlYod/jBzXvrYxIU8u3/7v3SfZliAayK/RqxIwGghnGoxO1qhNh5vEWIREChV9nORB7+jL4/Vku0AcZNS/5Tl+mpoanHxXi9/zIsovGIWKeP9bxbjOaZo09dDYskdHoB2ge5zOBTQdIbGx4uQ3DqPtE8HYVnGgLD1RrPif+/vZCX4KJe85ucuUIyA7DqKJA6HPz1pXNghd8kFd30WD2ux1SpbS0SxTQ1iwPdGjKWv38Gb8gx/A0RQQjeHDpz7DBbr7FhmdqavA3cPmzDpyV2rzTvaUcIirpcx1477UCELWW6oflJ3pE9yTSFMlBWVyGF2K4JXV l3LYveSm sEzEVVEXJGHpIF5U3mD9Zk8hN4XHhNW64Le/crCZl+h+xAIi0zeO11UpNBifxBSOVFOuujLz848NTe4ml4rVKErfZFKaW8Yuq/o81PsPGuKWoa3uFVnWBzyzc6M6pEKubM1+yW1bJ68M5leBu7SzZd47jhI8KJ/ldifd5EDqd4sXZ20yr6hs0KegjXTSCMc3v7oZ5KA77+xFohvmo+9qpHP5dOEZfz1wM9lVCQBjlGb3kvtmquuSiWMWLT6lrQWh2yokmz8hrmk7EI9qkMUaDOY0Pw6AqfjBgulMgco2qTdEDF7Y= 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: Some fault injection sites are placed in hotpaths and incur overhead even if not enabled, due to one or more function calls leading up to should_fail_ex() that returns false due to attr->probability == 0. This overhead can be eliminated if the outermost call into the checks is guarded with a static key, so add support for that. The framework should be told that such static key exist for a fault_attr, by initializing fault_attr->active with the static key address. When it's not NULL, enable the static key from setup_fault_attr() when the fault probability is non-zero. Also wire up writing into debugfs "probability" file to enable or disable the static key when transitioning between zero and non-zero probability. For now, do not add configfs interface support as the immediate plan is to leverage this for should_failslab() and should_fail_alloc_page() after other necessary preparatory changes, and not for any of the configfs based fault injection users. Signed-off-by: Vlastimil Babka --- include/linux/fault-inject.h | 7 ++++++- lib/fault-inject.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h index 6d5edef09d45..cfe75cc1bac4 100644 --- a/include/linux/fault-inject.h +++ b/include/linux/fault-inject.h @@ -9,6 +9,7 @@ #include #include #include +#include /* * For explanation of the elements of this struct, see @@ -30,13 +31,14 @@ struct fault_attr { unsigned long count; struct ratelimit_state ratelimit_state; struct dentry *dname; + struct static_key *active; }; enum fault_flags { FAULT_NOWARN = 1 << 0, }; -#define FAULT_ATTR_INITIALIZER { \ +#define FAULT_ATTR_INITIALIZER_KEY(_key) { \ .interval = 1, \ .times = ATOMIC_INIT(1), \ .require_end = ULONG_MAX, \ @@ -44,8 +46,11 @@ enum fault_flags { .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \ .verbose = 2, \ .dname = NULL, \ + .active = (_key), \ } +#define FAULT_ATTR_INITIALIZER FAULT_ATTR_INITIALIZER_KEY(NULL) + #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER int setup_fault_attr(struct fault_attr *attr, char *str); bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags); diff --git a/lib/fault-inject.c b/lib/fault-inject.c index d608f9b48c10..de9552cb22d0 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -35,6 +35,9 @@ int setup_fault_attr(struct fault_attr *attr, char *str) atomic_set(&attr->times, times); atomic_set(&attr->space, space); + if (probability != 0 && attr->active) + static_key_slow_inc(attr->active); + return 1; } EXPORT_SYMBOL_GPL(setup_fault_attr); @@ -166,6 +169,12 @@ EXPORT_SYMBOL_GPL(should_fail); #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS +/* + * Protect updating probability from debugfs as that may trigger static key + * changes when changing between zero and non-zero. + */ +static DEFINE_MUTEX(probability_mutex); + static int debugfs_ul_set(void *data, u64 val) { *(unsigned long *)data = val; @@ -186,6 +195,38 @@ static void debugfs_create_ul(const char *name, umode_t mode, debugfs_create_file(name, mode, parent, value, &fops_ul); } +static int debugfs_prob_set(void *data, u64 val) +{ + struct fault_attr *attr = data; + + mutex_lock(&probability_mutex); + + if (attr->active) { + if (attr->probability != 0 && val == 0) { + static_key_slow_dec(attr->active); + } else if (attr->probability == 0 && val != 0) { + static_key_slow_inc(attr->active); + } + } + + attr->probability = val; + + mutex_unlock(&probability_mutex); + + return 0; +} + +static int debugfs_prob_get(void *data, u64 *val) +{ + struct fault_attr *attr = data; + + *val = attr->probability; + + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(fops_prob, debugfs_prob_get, debugfs_prob_set, "%llu\n"); + #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER static int debugfs_stacktrace_depth_set(void *data, u64 val) @@ -218,7 +259,7 @@ struct dentry *fault_create_debugfs_attr(const char *name, if (IS_ERR(dir)) return dir; - debugfs_create_ul("probability", mode, dir, &attr->probability); + debugfs_create_file("probability", mode, dir, attr, &fops_prob); debugfs_create_ul("interval", mode, dir, &attr->interval); debugfs_create_atomic_t("times", mode, dir, &attr->times); debugfs_create_atomic_t("space", mode, dir, &attr->space); From patchwork Wed Jun 19 22:48:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704694 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 0F680C2BA1A for ; Wed, 19 Jun 2024 22:49:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57CF08D0090; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E5056B00BC; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E09DD6B00BD; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AB86A6B00BB for ; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 34A2A14157E for ; Wed, 19 Jun 2024 22:49:47 +0000 (UTC) X-FDA: 82249132014.05.A1A333C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf09.hostedemail.com (Postfix) with ESMTP id EA6C5140011 for ; Wed, 19 Jun 2024 22:49:44 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837375; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SdsKJ3YYCBij3yKRV4JKQ4JYpIGTARpLvBVnleZ5Fz0=; b=N5E2P+fqY1ddGSfhUIC0aH+z6q1OZv1Uf8gP6DTLYAYrbe7u37nfsZuNEUnOOSjX+IHps7 aJdSPavDPuX2my4/tKf0TvGKxO3EVwRyNY9YvQr8e8MmFhdKVKp0gPsMS7VgZO/9PNzQi8 l7Z+goMhCij0d9s7g51DFnVGkA/2aa0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837375; a=rsa-sha256; cv=none; b=tNE1ttpBaxJGU+Kb+dm4xMX9GSWi1YA08CdmeIaWfD0KBjsSvnDihtWhRtFEqkb99zZLvg 5jn6NsL8E/6H0CEM373XcBDfScyQfXBOYGQdLghvVvATQdVXWI+HQtu6kcASXKtgxlJZ42 71Z5kKNlaJ2Co//Pbgle50CkdbH+MGg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 41DA621A2E; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) 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 1F2C313AC3; Wed, 19 Jun 2024 22:49:43 +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 EHVGB4dgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:43 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:48:56 +0200 Subject: [PATCH v2 2/7] error-injection: support static keys around injectable functions MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-2-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6789; i=vbabka@suse.cz; h=from:subject:message-id; bh=nCcr0F2SycRd4ZmkZlDmyM/fEKeGlbV/Lf6N6wPJuRc=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2B1Frl4h+MJPB9HCCgG1OKOEt9S1LyDBVAEU 7M0ia0/FuiJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNgdQAKCRC74LB10kWI mp78B/0Vz6PDUOi8A2kc1lduJ93rou5JOVEFkLMCT4JoJKKbCqgoG658Fnnx3HlaQKP7S28r1fP 3vgXATaULFd5SCEjA0oxzDNE6YzK5EL7BA3K1xGx2ofu2hYba8jUh2vCZNZdX5+CZfVZ0ia4k1F HeqTxFmhEPAcJdAKjraSQVpcrsT7x5vV2wQojWCTDZ6JdWc8oL0+KJgVJG2ZQa3s8WdwYCP3nLu 7jplQLjhYrn1Z/XT2KfZoM2MkKZtaAbOHvn26QSrMM7DkuEfK4dHHHDCMXkU9NPJ7I3zN5sUNll X6uoyBbRQtQVe7e4xWwoXZNVn1VN3YvXt5fClIg6WZkAwvHt X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EA6C5140011 X-Stat-Signature: ct961pxzzafw948a1sze48g7p4k5wpaf X-Rspam-User: X-HE-Tag: 1718837384-268822 X-HE-Meta: U2FsdGVkX19oky5qktV2eBvnrSINPDyhBNWnGRrguofVoOWCkijGPNxg8cakupjaGdpnSlNDd1/+braS9FlNivdnS/cLkZ6CYFJptdxKIw1X26s1KmRhUicxYt5Z/NSdiLwHr4G1DwvHAFhE15KPQuQbfQOKfJe3BPvtYYBcnQUjxeWujA3QiFPcEK8XHZnVHp5gOc/s7GtJ4xP8JiDRpRFRnAc0V+P1I2xyv/XDvkJIA2d4AEIzsoOpPbDMDbFW+KwAbd6Qx+YD1r/mjKgoEOx/qKKw9PHyVLWyUujb9F/BGW/0NtjO+FFyU8nPriBN6lNmNwx1ahcGmtMFX5KIdVtxC9sDjm8z1If1p7dLHEw/+lwBXjhZvK4qkVGlyskUSm5+v44ewMPmR0w6PqiS4TMgIuwQJj51N86K2hTsp2rCpQq1dVxPJ9HT3p6cXEpaluHVScixFGChkCRFIW5EK3BK6oLE+dKh+MrglZL6Tduh4jMbvkHZaHCHIwRmBojEozZh9cOzuqwSJpCxFwTUPnre7Xjm5ElxMkwFFgclSiCT7FwmfRtnIvsbVG1DREf/VFF4/dxA2xr2HZVPld+bSWu9RC/srMGyHlFJJUCiam1n5FodRQYZWbvsWXvmtoZgI3EakpcBOjcKuOYTIG4lXudk9QStbjfX+2tkczJeYOKOghD4Omn2ypkijpRa8t1m5f1sBBAMsP/uvECLIzJ8A8sKonqGLj4m2vdnyDdPivjF3y88ILG3Sukc/rTZ896s7hhg23NTEhh+0kUSS85CCvfzA3D8Z3lKwjlyEo2m5Nurs4DUcWd6MZ4EKt52I94bL5h+1MaXlCkymaAAVKnepNxT+FglZQCMvBxJJwx4auH3LkH/2s//rHKcCpNBaKSZyqRx8nCuKAKChmCc9xnCmd+CBPjzrv0EYAU0biH22/Rybe8Oh5tLA1MO0n720QTA9AeoOVaZT1r7gm3gTKX I6/miaVM uJVT5PTBYyqvSxCNZ1zR+PnE0PFRNJt+iOG7dDPFqEFyorhzKJxddDJLXtrm3eF9uIITbZf+3bZjoHH5nY67L/v4fgHrHgUuE1F+ctcF6+gZPCh4kYjKWHAREiYcTlVUcTcHj8qnAN0Rsk6Mwuuzd4+aNQ15nB91icc1flm8+yKAPb1J91P095xUG9t29T6cTa6vp 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: Error injectable functions cannot be inlined and since some are called from hot paths, this incurs overhead even if no error injection is enabled for them. To avoid this overhead when disabled, allow the callsites of error injectable functions to put the calls behind a static key, which the framework can control when error injection is enabled or disabled for the function. Introduce a new ALLOW_ERROR_INJECTION_KEY() macro that adds a parameter with the static key's address, and store it in struct error_injection_entry. This new field has caused a mismatch when populating the injection list from the _error_injection_whitelist section using the current STRUCT_ALIGN(), so change the alignment to 8. During the population, copy the key's address also to struct ei_entry, and make it possible to retrieve it by get_injection_key(). Finally, make the processing of writes to the debugfs inject file enable the static key when the function is added to the injection list, and disable when removed. Signed-off-by: Vlastimil Babka Reviewed-by: Steven Rostedt (Google) --- include/asm-generic/error-injection.h | 13 ++++++++++++- include/asm-generic/vmlinux.lds.h | 2 +- include/linux/error-injection.h | 12 ++++++++++-- kernel/fail_function.c | 10 ++++++++++ lib/error-inject.c | 19 +++++++++++++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h index b05253f68eaa..eed2731f3820 100644 --- a/include/asm-generic/error-injection.h +++ b/include/asm-generic/error-injection.h @@ -12,6 +12,7 @@ enum { struct error_injection_entry { unsigned long addr; + unsigned long static_key_addr; int etype; }; @@ -25,16 +26,26 @@ struct pt_regs; * 'Error Injectable Functions' section. */ #define ALLOW_ERROR_INJECTION(fname, _etype) \ -static struct error_injection_entry __used \ +static struct error_injection_entry __used __aligned(8) \ __section("_error_injection_whitelist") \ _eil_addr_##fname = { \ .addr = (unsigned long)fname, \ .etype = EI_ETYPE_##_etype, \ } +#define ALLOW_ERROR_INJECTION_KEY(fname, _etype, key) \ +static struct error_injection_entry __used __aligned(8) \ + __section("_error_injection_whitelist") \ + _eil_addr_##fname = { \ + .addr = (unsigned long)fname, \ + .static_key_addr = (unsigned long)key, \ + .etype = EI_ETYPE_##_etype, \ + } + void override_function_with_return(struct pt_regs *regs); #else #define ALLOW_ERROR_INJECTION(fname, _etype) +#define ALLOW_ERROR_INJECTION_KEY(fname, _etype, key) static inline void override_function_with_return(struct pt_regs *regs) { } #endif diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 5703526d6ebf..1b15a0af2a00 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -248,7 +248,7 @@ #ifdef CONFIG_FUNCTION_ERROR_INJECTION #define ERROR_INJECT_WHITELIST() \ - STRUCT_ALIGN(); \ + . = ALIGN(8); \ BOUNDED_SECTION(_error_injection_whitelist) #else #define ERROR_INJECT_WHITELIST() diff --git a/include/linux/error-injection.h b/include/linux/error-injection.h index 20e738f4eae8..48da027c0302 100644 --- a/include/linux/error-injection.h +++ b/include/linux/error-injection.h @@ -6,10 +6,13 @@ #include #include +struct static_key; + #ifdef CONFIG_FUNCTION_ERROR_INJECTION -extern bool within_error_injection_list(unsigned long addr); -extern int get_injectable_error_type(unsigned long addr); +bool within_error_injection_list(unsigned long addr); +int get_injectable_error_type(unsigned long addr); +struct static_key *get_injection_key(unsigned long addr); #else /* !CONFIG_FUNCTION_ERROR_INJECTION */ @@ -23,6 +26,11 @@ static inline int get_injectable_error_type(unsigned long addr) return -EOPNOTSUPP; } +static inline struct static_key *get_injection_key(unsigned long addr) +{ + return NULL; +} + #endif #endif /* _LINUX_ERROR_INJECTION_H */ diff --git a/kernel/fail_function.c b/kernel/fail_function.c index d971a0189319..d39a9606a448 100644 --- a/kernel/fail_function.c +++ b/kernel/fail_function.c @@ -27,6 +27,7 @@ struct fei_attr { struct list_head list; struct kprobe kp; unsigned long retval; + struct static_key *key; }; static DEFINE_MUTEX(fei_lock); static LIST_HEAD(fei_attr_list); @@ -67,6 +68,11 @@ static struct fei_attr *fei_attr_new(const char *sym, unsigned long addr) attr->kp.pre_handler = fei_kprobe_handler; attr->kp.post_handler = fei_post_handler; attr->retval = adjust_error_retval(addr, 0); + + attr->key = get_injection_key(addr); + if (IS_ERR(attr->key)) + attr->key = NULL; + INIT_LIST_HEAD(&attr->list); } return attr; @@ -218,6 +224,8 @@ static int fei_open(struct inode *inode, struct file *file) static void fei_attr_remove(struct fei_attr *attr) { + if (attr->key) + static_key_slow_dec(attr->key); fei_debugfs_remove_attr(attr); unregister_kprobe(&attr->kp); list_del(&attr->list); @@ -295,6 +303,8 @@ static ssize_t fei_write(struct file *file, const char __user *buffer, fei_attr_free(attr); goto out; } + if (attr->key) + static_key_slow_inc(attr->key); fei_debugfs_add_attr(attr); list_add_tail(&attr->list, &fei_attr_list); ret = count; diff --git a/lib/error-inject.c b/lib/error-inject.c index 887acd9a6ea6..982fbedd9ad5 100644 --- a/lib/error-inject.c +++ b/lib/error-inject.c @@ -17,6 +17,7 @@ struct ei_entry { struct list_head list; unsigned long start_addr; unsigned long end_addr; + struct static_key *key; int etype; void *priv; }; @@ -54,6 +55,23 @@ int get_injectable_error_type(unsigned long addr) return ei_type; } +struct static_key *get_injection_key(unsigned long addr) +{ + struct ei_entry *ent; + struct static_key *ei_key = ERR_PTR(-EINVAL); + + mutex_lock(&ei_mutex); + list_for_each_entry(ent, &error_injection_list, list) { + if (addr >= ent->start_addr && addr < ent->end_addr) { + ei_key = ent->key; + break; + } + } + mutex_unlock(&ei_mutex); + + return ei_key; +} + /* * Lookup and populate the error_injection_list. * @@ -86,6 +104,7 @@ static void populate_error_injection_list(struct error_injection_entry *start, ent->start_addr = entry; ent->end_addr = entry + size; ent->etype = iter->etype; + ent->key = (struct static_key *) iter->static_key_addr; ent->priv = priv; INIT_LIST_HEAD(&ent->list); list_add_tail(&ent->list, &error_injection_list); From patchwork Wed Jun 19 22:48:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704696 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 4F8FAC2BA1A for ; Wed, 19 Jun 2024 22:49:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 592706B01B1; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D16C8D0092; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D1988D0091; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D45266B00BD for ; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 944EB161603 for ; Wed, 19 Jun 2024 22:49:48 +0000 (UTC) X-FDA: 82249132056.03.F671EF2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf10.hostedemail.com (Postfix) with ESMTP id 572BDC000C for ; Wed, 19 Jun 2024 22:49:46 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=mtxCY5NO; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=2+cvj+i4; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=mtxCY5NO; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=2+cvj+i4; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837381; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GJmQfB+SFKwkGljPkMoSf+PzrKg2yTJDdkhioKlFbR0=; b=O0fYYgZaPPgveOlghgyR9xFJpmsqD3XVgES5e8Mco2Ngu0ZEvSJVRmERXZ63Ajwmy3a/QY G+CyqCRpqpn22Ssc8xrESu2K6q4bVJXAuQK+V1u4rc+zU4j3sPnQ4T/BxduGuW1KFYZHXQ unZbUo107vTAy7nmvt1WY030P5S3mho= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=mtxCY5NO; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=2+cvj+i4; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=mtxCY5NO; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=2+cvj+i4; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837381; a=rsa-sha256; cv=none; b=uN4PoUJoVi7n8uGexXXdN9o3UwSfFZHMr/HhlGKWhiFPjRjaWi589UwtlTv3bakZBZxyTr FvUmsEMvmpBqWRhCt8N7ZBA3ZCoSdo+wwAGj9Q4w5hbD83CoLEzSGE7vTxfifAoC43v21y om1/F2UQLuDPlTtei7N3S5eal1XAkK4= Received: from imap1.dmz-prg2.suse.org (unknown [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 5C51F21A5C; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJmQfB+SFKwkGljPkMoSf+PzrKg2yTJDdkhioKlFbR0=; b=mtxCY5NOZUMLeNOQo2490WnZzrZz5lK6g9Qm7Ex4Shmq2UVpwBxwZP+nWMnZFY2Qk8nBs1 siLzlqttayrh4IykYENtS8rfrWC8ksDwhasAHMwn4I+ihPTkA8zNMcN6XlS3RF8s2wohXI U+CXOQeOPkjiu8wHU+JqsGy5rejV9nA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJmQfB+SFKwkGljPkMoSf+PzrKg2yTJDdkhioKlFbR0=; b=2+cvj+i4DhZ6XKrKA7se2fWikyWEQBDFIpBjv+eA7nIqPwGQ03LS2LkiZhUbMyFqEGyfvQ qHnQkg3JJUtkfiDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJmQfB+SFKwkGljPkMoSf+PzrKg2yTJDdkhioKlFbR0=; b=mtxCY5NOZUMLeNOQo2490WnZzrZz5lK6g9Qm7Ex4Shmq2UVpwBxwZP+nWMnZFY2Qk8nBs1 siLzlqttayrh4IykYENtS8rfrWC8ksDwhasAHMwn4I+ihPTkA8zNMcN6XlS3RF8s2wohXI U+CXOQeOPkjiu8wHU+JqsGy5rejV9nA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJmQfB+SFKwkGljPkMoSf+PzrKg2yTJDdkhioKlFbR0=; b=2+cvj+i4DhZ6XKrKA7se2fWikyWEQBDFIpBjv+eA7nIqPwGQ03LS2LkiZhUbMyFqEGyfvQ qHnQkg3JJUtkfiDQ== 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 3D08413AAA; Wed, 19 Jun 2024 22:49:43 +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 SCSeDodgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:43 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:48:57 +0200 Subject: [PATCH v2 3/7] bpf: support error injection static keys for perf_event attached progs MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-3-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4256; i=vbabka@suse.cz; h=from:subject:message-id; bh=RHlcQH9C6ly4CbQFrHL5k0pueBGzmfFJHg6uosgSnqE=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2B4jX+g3Xf4kDO7RN55ImULUpPLAS31+cJIL VWj6k4LZzmJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNgeAAKCRC74LB10kWI mk8pCACesvfkTPT71qvqKXfyLJtHc/HZ29/KezJP030k0GlFWTkG41XeSOf+Jc9jxoC1871A4SK EWFDuN7tbL8sEOdT7cBJU0MBEXQSDEYNDcoGyZxl98cLsAJ9XHVdkhNOzgJJgPRwcnPT10ejR6X Eb39gdyBoKUdHWD8IoRYiCpG6/Wx8PRQUjK59shva6E514qQRimzOvre6ZR5OQrcynjumq8WrVE n12/Bf0XbXqhrgaM1emVNUHExQn1U7iCYwHGEzlGPNvC8Mi+wQG9Xsq7xvjA5OSOUmmmDusj3eC 3soz/74FQINFipML/55CmhoPIFrOsjPyQbm5FZDYbWm25i7L X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 572BDC000C X-Stat-Signature: 7gh54nc9cs9zdkfqgbzps737knuhmg71 X-Rspam-User: X-HE-Tag: 1718837386-535326 X-HE-Meta: U2FsdGVkX18tsdHnyEXXnN5epwr/czOc8XHe9l/WzBJcJ/izvw1sJRWH3OiReLi+Lt6blCWEjd/mo5S4CChK/5MRHbMr0sRCcmEkgIAYjyJ5FeSW9qccYSerDmGzyFzVLr8A9XwqkzPKumg8F+nYneUJRP7m3la7rATgssMKgQOyhbOxnj9FNra1Mx+MgcrA4taa/2P8SeIULeF6ErVfM/AqaslOBFYkcdZYBCYsb9r3lUH6s1x5/ocaXuoJ1mpzcrLhIVU3U8j2uKK79HjfrVQugXxP1wLujY3FlXfgCvkJXnA6ETpI3cg7WtAvJ9llfuGtrVK4xXi1x9SLdJf6rPx4Wd5U8Vx3W/U8RZe+ZWbRT5FfQawUSHwRYgnp/jj0Tlyg0E4o8AIjC24USzdENfZgyvliTK33AV4c9sBntT+IJgcJyLYDIAzyfc/WqHbZi4bcxz5QKeJmDiR+BgGcn5YFNi5iZeD9CE4It7kx4C7jdiRjOoGxkm4sjQIcTzzcCPxnB6gom0buMdXxrzh4OXAt7uw7GLBxBH39tQSoPIB3PytwvStKhW/DnU3tpbf22H2t2mj/L7h454BneHtksdCqS3yfkEGnuPAiXsjbn5kEPtvy59tvEA6tIl27WUAPCq2DJ0oQG2Vb0L3YiCydf6USbHuT4hfoxPK4MQmdAkyeiLhZVPcvrmL9cuEwf9fwOD2+4+VycXZa+Qpgn45l07e5AXF9MypJiqQGqupwNKe5G0fKupnqhAUWdNr14hVAnSJetIYad2USc5XBmtbooyv+cbcm8LVA3YC7bBedzEx+CHOJhyRttASQXGoliWH7UGwQGJqnkZm2K0IP3KfaARhuZUtozu7nJZed+SYTmmW0pZegyoigXm9Pw5h7QQZnyE4ccindiXZ9IUAXhRkgwMf50SlfKidXZJ7OVmWOZhFUjYzLW4X6OC8YNl1VQ7lIa6EZTwpuIMMpYw/ZS/w Qshq+LXb GB3f12WnqOEfvDgzBB79WWPMu1cnpX0OsO2JQRUvolD4XLvaWNCMivIvxKNouba1f17dNvGOCUKNyLzHBP8cu54MD4+mFZyjStY94OSrXHSK/KSuPudApw8CP32EGFkdwc++UfWK2LNYaK3LglazjFVi2fQyutfCxVyjEwsIMiHj/LD4NHqzc71se+W8gfUm71i5HW4wWf8W93T2EMBHriiZd6U2LO1BYBiPrJ4u8eQP+8MAihSMxMIxT7+mIhLj8F3lDqUS8gLg8xEYD4OA1xodd9apkcxWxB9S2Xxtd97q5s8KCvZG4suZhxuPNHAaNv94alDV5lZF6Zr31iC8Xri3PW3YnPBHct3e9 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: Functions marked for error injection can have an associated static key that guards the callsite(s) to avoid overhead of calling an empty function when no error injection is in progress. Outside of the error injection framework itself, bpf programs can be atteched to perf events and override results of error-injectable functions. To make sure these functions are actually called, attaching such bpf programs should control the static key accordingly. Therefore, add the static key's address to struct trace_kprobe and fill it in trace_kprobe_error_injectable(), using get_injection_key() instead of within_error_injection_list(). Introduce trace_kprobe_error_injection_control() to control the static key and call the control function when attaching or detaching programs with kprobe_override to perf events. Signed-off-by: Vlastimil Babka --- kernel/trace/bpf_trace.c | 6 ++++++ kernel/trace/trace_kprobe.c | 30 ++++++++++++++++++++++++++++-- kernel/trace/trace_probe.h | 5 +++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index f5154c051d2c..944de1c41209 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2283,6 +2283,9 @@ int perf_event_attach_bpf_prog(struct perf_event *event, rcu_assign_pointer(event->tp_event->prog_array, new_array); bpf_prog_array_free_sleepable(old_array); + if (prog->kprobe_override) + trace_kprobe_error_injection_control(event->tp_event, true); + unlock: mutex_unlock(&bpf_event_mutex); return ret; @@ -2299,6 +2302,9 @@ void perf_event_detach_bpf_prog(struct perf_event *event) if (!event->prog) goto unlock; + if (event->prog->kprobe_override) + trace_kprobe_error_injection_control(event->tp_event, false); + old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); ret = bpf_prog_array_copy(old_array, event->prog, NULL, 0, &new_array); if (ret == -ENOENT) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 16383247bdbf..1c1ee95bd5de 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -61,6 +61,7 @@ struct trace_kprobe { unsigned long __percpu *nhit; const char *symbol; /* symbol name */ struct trace_probe tp; + struct static_key *ei_key; }; static bool is_trace_kprobe(struct dyn_event *ev) @@ -235,9 +236,34 @@ bool trace_kprobe_on_func_entry(struct trace_event_call *call) bool trace_kprobe_error_injectable(struct trace_event_call *call) { struct trace_kprobe *tk = trace_kprobe_primary_from_call(call); + struct static_key *ei_key; - return tk ? within_error_injection_list(trace_kprobe_address(tk)) : - false; + if (!tk) + return false; + + ei_key = get_injection_key(trace_kprobe_address(tk)); + if (IS_ERR(ei_key)) + return false; + + tk->ei_key = ei_key; + return true; +} + +void trace_kprobe_error_injection_control(struct trace_event_call *call, + bool enable) +{ + struct trace_kprobe *tk = trace_kprobe_primary_from_call(call); + + if (!tk) + return; + + if (!tk->ei_key) + return; + + if (enable) + static_key_slow_inc(tk->ei_key); + else + static_key_slow_dec(tk->ei_key); } static int register_kprobe_event(struct trace_kprobe *tk); diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 5803e6a41570..d9ddcabb9f97 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -212,6 +212,8 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(symbol); #ifdef CONFIG_KPROBE_EVENTS bool trace_kprobe_on_func_entry(struct trace_event_call *call); bool trace_kprobe_error_injectable(struct trace_event_call *call); +void trace_kprobe_error_injection_control(struct trace_event_call *call, + bool enabled); #else static inline bool trace_kprobe_on_func_entry(struct trace_event_call *call) { @@ -222,6 +224,9 @@ static inline bool trace_kprobe_error_injectable(struct trace_event_call *call) { return false; } + +static inline void trace_kprobe_error_injection_control(struct trace_event_call *call, + bool enabled) { } #endif /* CONFIG_KPROBE_EVENTS */ struct probe_arg { From patchwork Wed Jun 19 22:48:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704693 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 BFB5BC27C53 for ; Wed, 19 Jun 2024 22:49:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E7F66B00BB; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D8A58D0091; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6C408D008F; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AC5C56B00BC for ; Wed, 19 Jun 2024 18:49:47 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 326281615A0 for ; Wed, 19 Jun 2024 22:49:47 +0000 (UTC) X-FDA: 82249132014.07.8CFD6D6 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf16.hostedemail.com (Postfix) with ESMTP id E98CF18000F for ; Wed, 19 Jun 2024 22:49:44 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837378; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rh8eO3kA3ELL8Nh5M7QOXpKcI9PqUg1Ec5K8z4cuJgc=; b=7Z18B4WQi5/vVLoDKTuSW+b+kibvvgC8jcnwAPzzxu4bRiyQ4r+WE5dQeAQMBEqvUUBFEJ 2AESl210at+qo8NOBhbjyozJTCFLGlCKL2iefug3YRctLyejNlvDGnhTpAGZf7eHCMY0kn GGTNewutOVJRMpuMOYjPQxbs+xw1wIM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837379; a=rsa-sha256; cv=none; b=i5C0pxuB4I17ZiTWyfg0JdD9EUdKNyPLIijqoBROTfIWhx2y2/pSwXi4cNRX1UByj2tfAk lx2F6INCGekkZiiljrGdntHWV7SP5y+uzo2SjOyszBoBAGm/XO7UH5oj0IuajEV42y+Xo2 ZUXlGGhoIWZkrW48yxwzPqIxFu6zWwc= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 78F4B21A5F; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) 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 593BA13ABD; Wed, 19 Jun 2024 22:49:43 +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 QO+DFYdgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:43 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:48:58 +0200 Subject: [PATCH v2 4/7] bpf: support error injection static keys for multi_link attached progs MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-4-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4495; i=vbabka@suse.cz; h=from:subject:message-id; bh=3qciDcxlabL8RPKApoikpRFG6GtFoTLNySS+QbqQz9Q=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2B7A+FYtqvio9GTWv3xme47MHxydtFu6JcXT U9aKA8HdJyJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNgewAKCRC74LB10kWI mtXfB/9Wf8ufmNZ+KgSqZhasEn0ZqY1pTjQK/1k4ql5arsN4WjQN5LONf7zFbsRueo1MccTXI8j /fH+X3PTcoSG6fRMjz3+vuHCOkrsWH3yUtKIWVCjSGbCnoTDSPalLr/doZP8HAWLrmhpFni/wZC 6VZHYbuRigc7AohRXcOu7R4Px5zhFhdbb+6z1EZkeKJzmzriFXhSIczEoPYa6g6RmKDL/HsZiEY Iwcv1O2H9gYU+430HbPN6am111EVHOeM6rY2MCwZaJjWJjd3at7bfhl/tIQWnAM0gal51sJCbR6 2uksKs0VJHgNrhMdsLGxDLtpwTXG5HrhbVle/JopZQNha/Sy X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Stat-Signature: zni4yen6gwroj93wcc8j5j3yz3wxymey X-Rspam-User: X-Rspamd-Queue-Id: E98CF18000F X-Rspamd-Server: rspam02 X-HE-Tag: 1718837384-800182 X-HE-Meta: U2FsdGVkX19oyBd+wiHZMwYTu2PDmXI+RdwdJuzkDkQLXmdinc3zDI5Gi4hxsIfuplWzusP5tKFqwJRpJmUkV/V6EJHPzJzdCbe314GTj0ilQmN+4QOSfH08SRduaP0fenGsZ+/sqiEp+Sejo7m0h6ajdEPYxuYIzOpx+jTHTNc/so6GvO79JC6naBHjR+7NnJwLmGwQa4okgn+xt6XOZ/ObjAArjckbv5WtcDouyKYgerXJBdilV5YdCZ+iQRZduWYGqrIR7sFKb8RauA+ZEuYSnf3ep5rIryeRKhc3BzLTSzxX60kdT0MJaicdTmaeEXQNXTJV6FV6oP5zsgYSlBn6TwrWi+qGea96oM5oTS1iwStCMMXozL7fQd2EmuEx+iinCanJGS3p4YPnmk5dp4ZT5oLZczRUKj0JgPkJ+C0giVL66Sdr+ufg6hmPa8THFrfVVKZj2Nqco+hJ+u8uvHMW8RZ62xOwJQ+GQUKwXWcSbykt05RkZLqO2CR5vk0N4JbTGRQuR+/le4447P2jPWe0gXw2VpciTd56kJfSonEEpaG0NXuGoZ2CrKdcTgNjdcz4xB5G8HOtCPRnqHedEV0NfzmVVtVRS27SvkGngFRZlQuEUhexCIof30xNK0wG65x6eU2EBICa1Sv1Q1RIBg4mcFvcqdHfaoUVRIhozg1oj2j84gHXRch7Qqh7+Q0yv2gwfHl3L/FB7IUrEf2L2jIhYG2nTfqLm2YjRkhsUJQX8NipFRvzbNXF5F0hPxXHckrHXOt9bBL9Z4pU0hHVAk4CpfLa9ZGMe2KVcy8V3gh3uUaokEaxFhdmRPN0n+F+KMn1zK83M9MRaRl+LVpC+OqJSWBEFGBAscmA+K00RKq4oW3wNNwyRSwcn7qpwnMQtPoXtcpFY9Cnwe4FZgFiI9ChJUKZelU6Ng1pO6/zuE8DLGrULRc6moWfwT/BVMy4t1B/0TZDfsKoLVcINnd HNEtepuc 7uAXMx5J2ze8KhrnnHhxOaZdDphTA2HUhxZaCfT/wmeYWHO+MaFRNpCglpjX1cbJoinqlIcm+N3JMnzYCVIDcatE2ycUztOKBfJ+/ilIBpoM5SOmh42B/x1P5Zixciy2EWvtvJv0X8KjRDabZYwPHv/BSf/k1/gyrSbq7Nt4EMx9EiIZgEypZxYMTJGVOVbifEcfQTciyxQEP+iBfAio3oQL64hhFj+cE0+TJ3f1mdXEZkxM= 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: Functions marked for error injection can have an associated static key that guards the callsite(s) to avoid overhead of calling an empty function when no error injection is in progress. Outside of the error injection framework itself, bpf programs can be atteched to kprobes and override results of error-injectable functions. To make sure these functions are actually called, attaching such bpf programs should control the static key accordingly. Therefore, add an array of static keys to struct bpf_kprobe_multi_link and fill it in addrs_check_error_injection_list() for programs with kprobe_override enabled, using get_injection_key() instead of within_error_injection_list(). Introduce bpf_kprobe_ei_keys_control() to control the static keys and call the control function when doing multi_link_attach and release. Signed-off-by: Vlastimil Babka --- kernel/trace/bpf_trace.c | 59 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 944de1c41209..ef0fadb76bfa 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2613,6 +2613,7 @@ struct bpf_kprobe_multi_link { struct bpf_link link; struct fprobe fp; unsigned long *addrs; + struct static_key **ei_keys; u64 *cookies; u32 cnt; u32 mods_cnt; @@ -2687,11 +2688,30 @@ static void free_user_syms(struct user_syms *us) kvfree(us->buf); } +static void bpf_kprobe_ei_keys_control(struct bpf_kprobe_multi_link *link, bool enable) +{ + u32 i; + + for (i = 0; i < link->cnt; i++) { + if (!link->ei_keys[i]) + break; + + if (enable) + static_key_slow_inc(link->ei_keys[i]); + else + static_key_slow_dec(link->ei_keys[i]); + } +} + static void bpf_kprobe_multi_link_release(struct bpf_link *link) { struct bpf_kprobe_multi_link *kmulti_link; kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link); + + if (kmulti_link->ei_keys) + bpf_kprobe_ei_keys_control(kmulti_link, false); + unregister_fprobe(&kmulti_link->fp); kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt); } @@ -2703,6 +2723,7 @@ static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link) kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link); kvfree(kmulti_link->addrs); kvfree(kmulti_link->cookies); + kvfree(kmulti_link->ei_keys); kfree(kmulti_link->mods); kfree(kmulti_link); } @@ -2985,13 +3006,19 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3 return arr.mods_cnt; } -static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt) +static int addrs_check_error_injection_list(unsigned long *addrs, struct static_key **ei_keys, + u32 cnt) { - u32 i; + struct static_key *ei_key; + u32 i, j = 0; for (i = 0; i < cnt; i++) { - if (!within_error_injection_list(addrs[i])) + ei_key = get_injection_key(addrs[i]); + if (IS_ERR(ei_key)) return -EINVAL; + + if (ei_key) + ei_keys[j++] = ei_key; } return 0; } @@ -3000,6 +3027,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr { struct bpf_kprobe_multi_link *link = NULL; struct bpf_link_primer link_primer; + struct static_key **ei_keys = NULL; void __user *ucookies; unsigned long *addrs; u32 flags, cnt, size; @@ -3075,9 +3103,24 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr goto error; } - if (prog->kprobe_override && addrs_check_error_injection_list(addrs, cnt)) { - err = -EINVAL; - goto error; + if (prog->kprobe_override) { + ei_keys = kvcalloc(cnt, sizeof(*ei_keys), GFP_KERNEL); + if (!ei_keys) { + err = -ENOMEM; + goto error; + } + + if (addrs_check_error_injection_list(addrs, ei_keys, cnt)) { + err = -EINVAL; + goto error; + } + + if (ei_keys[0]) { + link->ei_keys = ei_keys; + } else { + kvfree(ei_keys); + ei_keys = NULL; + } } link = kzalloc(sizeof(*link), GFP_KERNEL); @@ -3132,10 +3175,14 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return err; } + if (link->ei_keys) + bpf_kprobe_ei_keys_control(link, true); + return bpf_link_settle(&link_primer); error: kfree(link); + kvfree(ei_keys); kvfree(addrs); kvfree(cookies); return err; From patchwork Wed Jun 19 22:48:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704695 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 C8D0BC27C53 for ; Wed, 19 Jun 2024 22:49:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CFA66B00BC; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 667D48D0091; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 498798D008F; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0E8328D0090 for ; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B7451415AF for ; Wed, 19 Jun 2024 22:49:47 +0000 (UTC) X-FDA: 82249132014.14.9224373 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf02.hostedemail.com (Postfix) with ESMTP id 7673980007 for ; Wed, 19 Jun 2024 22:49:45 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=LNWxnnz1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=roVh2sJJ; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=LNWxnnz1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=roVh2sJJ; spf=pass (imf02.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837377; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X7+XAotVIvWS2vTh75oVQOPFwsOci6tWQZhDoSRQGx4=; b=nX/MAO+iVkX8QJUDZbS4fjhqSP2IsyBZyestRvj1YRmQ0QA67ZxMZjXPHUMuSIAQVBTYkJ HYjaTSBv3tQYj+7pnkNMjR93bMhxACFvUwESeFhSh0OlUcXcDWCNIWI3Fr2ZWRqKzK5DZ2 L2+UVJqWM8IsnDIWXy698yqkFX/0rfo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837377; a=rsa-sha256; cv=none; b=2HBXTYKL4MZkTAK6NVvF+lK84gj8Nnn3R2nUERJAvzUmz595xd1Vnf9KbU/YLegP4vgwm+ Cxperhox4APUNrrOsY5S827OSvPKUyrGS+KA36TQzLzV9F5EGtxF8svu8/It8Go8XupQa9 /G+SgErA2fWOJHxSH4gHUgIAnaLg5JU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=LNWxnnz1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=roVh2sJJ; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=LNWxnnz1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=roVh2sJJ; spf=pass (imf02.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (unknown [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-out2.suse.de (Postfix) with ESMTPS id 994E01F7F7; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7+XAotVIvWS2vTh75oVQOPFwsOci6tWQZhDoSRQGx4=; b=LNWxnnz1OKuGoWGrMXrwTd2enyzJN73ypy1Cuy1qZtBotKAAqp2aq65A1gK7qZ8U54E2Lz FILu5L+orwbhDShXDMWDHPD659eTlwmmC78MWsxkCr/n6HetuhQ8GeFlOmDbT43Vpg8zeO i6yA9AvNuoYhNrFm1SRXWVMJ9lI5Fo0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7+XAotVIvWS2vTh75oVQOPFwsOci6tWQZhDoSRQGx4=; b=roVh2sJJLOmM0oiL35sPyLjBSwOuoRsf/nGyJvEjjBe2kt/FPev0yfzWJK/1XF1/iK2GOP 56CsF5e9QNpjsaBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7+XAotVIvWS2vTh75oVQOPFwsOci6tWQZhDoSRQGx4=; b=LNWxnnz1OKuGoWGrMXrwTd2enyzJN73ypy1Cuy1qZtBotKAAqp2aq65A1gK7qZ8U54E2Lz FILu5L+orwbhDShXDMWDHPD659eTlwmmC78MWsxkCr/n6HetuhQ8GeFlOmDbT43Vpg8zeO i6yA9AvNuoYhNrFm1SRXWVMJ9lI5Fo0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7+XAotVIvWS2vTh75oVQOPFwsOci6tWQZhDoSRQGx4=; b=roVh2sJJLOmM0oiL35sPyLjBSwOuoRsf/nGyJvEjjBe2kt/FPev0yfzWJK/1XF1/iK2GOP 56CsF5e9QNpjsaBg== 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 76B2913AC3; Wed, 19 Jun 2024 22:49:43 +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 gBasHIdgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:43 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:48:59 +0200 Subject: [PATCH v2 5/7] bpf: do not create bpf_non_sleepable_error_inject list when unnecessary MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-5-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1591; i=vbabka@suse.cz; h=from:subject:message-id; bh=+HcqYdgaWT9BrUacvRJSWp4CDbAKfRkRibADsrgT2bU=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2B9IzDEAVKG5FXS38RcYZUyeL9j5X2CdCydU Xm/auj9IMKJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNgfQAKCRC74LB10kWI mieMB/0Z2oYYCWNAmVEuHX7NW7yYno6Akg2QEWBe10L/+QsV4Wfjt61ibXRZyOYv5dL16q+TyVM Gofehb9TgIuIG9fzbiv/IkDt0D9UULaagQwhJUpdnLAOYxw7FRr1nYbjmJt/cNOUtR8cMo6x1PG 33Gevml4l4phxiCJEnvCSO9Xum+ZBP/F3GOvVXDBDIF/vXVBhmF0iRyvefoi9o66f+guBziQc0j DDNd0wet/qYXslsYfyo9XtYY9+dP/5/d9pwYbcsvP8BN9uQkE3IeYQHe/Thldx8B/855/bItiKc AkAI9cbY8cY4/mKYag0vVzO6xNXmffLfuOg01lsVKyX58qWE X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Stat-Signature: 5wrn7fgre5cco8de5rjw715aqkmr4bfm X-Rspamd-Queue-Id: 7673980007 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718837385-488125 X-HE-Meta: U2FsdGVkX1/I7/BKHF2rsvLiaCtAJyO97yoIoYckAjjlzDhK4iTM6c99s6vckyj0G2ihs5DiYOG+CG8tzRdzEub9I0Z6UgJuMrMHp+wc0gtjG/cEAPkCQlKBxTaWu9RTDGN14PmUPK1+FzMw26LOU6rbZPvaSLO+CEtfj9iiLnyQo51nD8aVjelhGO+BqujU4z7UFuRq/8mhE9nnjBb7XnIzd2weD1ynHYj8vtu34V/6lq/W4EbBb/Y8degzBz23o0DG5nWWWTct1cQ4ffuHAqQAGH68CVmhcdHelHCwS+aa4zZ7jVUeiAtQyt+r/02hZU26JddmHSlevqofa4+BTydHiaifc92+Tvs+mxk029LwqgCqCY0vxY2InKL5CwbGcmYsEkfW8ZULV/3nNGZ2VFWSVRfVPa7OZo65/4Jl34YK4H7uIia+/JOFcjlWvFtH1KRTu+jQaiR9bs8sIudd01Lm311EcAg7jY20iIemFp9sBMEYgYqCSenerNAX9l0D0GYYznKL0boTeX/1XSBy7MT7o/W9A2gtixsk4O637M4ecqm1FndUVXWzflQfMXfc4/nuT5CdwqziKyUWYji/SEBHB0RSk+zGsp/31GuApkH34lio+tgnZeVbZE/hdMsHP5gT1UaSQEMkTYpDGYmjEd5TKhXOEgVLcUZJp3pn+9NXhkKi7v7wNH1JC1Oljpe3PBME8vqSxBVdBU3exOemITBj2vhqv5jfN+qZW8kv9VL1Mdc70MTsry0YD2peS4DNjgwsN90ButQFvNk9dwFDcTuXLeJTH0FtRFVjAl/UoHxSj04K12s78Dedp04Z2rhMbEfv3do0NNtp67BB/fIQ1N4P/epIU+KJ0B3IwOKNtg1/1HNdsQfElYTPh1T5CLtfPVtSo/VY5vYGaY8Jwl2rmHhazWLf+Y5Qwna4trqhlxIO7nadVsu6cmcHgoULIZJqmfvzUsu5rt4JQIIZpDh hZv7Khc3 +xralWS5ekV1quHV/XbKUKNeB+rmOaLUDf7rvUsuBkHNdZPI1JbTZJWDTFb11xURAqCBVZOzKXDdCvRHYD1pf7wP7LO6enKvOEZT12V2rR5tHxkpnykOqV0jrHsAa4thy40znHIDtM0hYTcnlv3mqn+ZmY+2eG7dZdM7puaYuTurDJvpFjrtV4+gi33e+xlKJWls1CyIc1g7kCKHZKiKTyzyBnbKdV02u+W94KoiSHZQzsXcXHgIw2wepSZdiKAmX0Ef3FaXFg9Pft8KcspsUruSQIEEaPwN36aiCtg/AfO1gJ6TXUu+Brfw6gPh+VoFOBsX+q3gl61ElvYCawFGiqyXRIA== 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: When CONFIG_FUNCTION_ERROR_INJECTION is disabled, within_error_injection_list() will return false for any address and the result of check_non_sleepable_error_inject() denylist is thus redundant. The bpf_non_sleepable_error_inject list thus does not need to be constructed at all, so #ifdef it out. This will allow to inline functions on the list when CONFIG_FUNCTION_ERROR_INJECTION is disabled as there will be no BTF_ID() reference for them. Signed-off-by: Vlastimil Babka --- kernel/bpf/verifier.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 77da1f438bec..5cd93de37d68 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -21044,6 +21044,8 @@ static int check_attach_modify_return(unsigned long addr, const char *func_name) return -EINVAL; } +#ifdef CONFIG_FUNCTION_ERROR_INJECTION + /* list of non-sleepable functions that are otherwise on * ALLOW_ERROR_INJECTION list */ @@ -21061,6 +21063,19 @@ static int check_non_sleepable_error_inject(u32 btf_id) return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id); } +#else /* CONFIG_FUNCTION_ERROR_INJECTION */ + +/* + * Pretend the denylist is empty, within_error_injection_list() will return + * false anyway. + */ +static int check_non_sleepable_error_inject(u32 btf_id) +{ + return 0; +} + +#endif + int bpf_check_attach_target(struct bpf_verifier_log *log, const struct bpf_prog *prog, const struct bpf_prog *tgt_prog, From patchwork Wed Jun 19 22:49:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704697 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 EF64DC27C53 for ; Wed, 19 Jun 2024 22:50:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C5278D0092; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 731518D0091; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FCFF6B01F0; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D527C6B01B1 for ; Wed, 19 Jun 2024 18:49:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 88023A092C for ; Wed, 19 Jun 2024 22:49:48 +0000 (UTC) X-FDA: 82249132056.13.63DB78E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf15.hostedemail.com (Postfix) with ESMTP id 3D532A0003 for ; Wed, 19 Jun 2024 22:49:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OctDuuKS; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=j+2cW9Bf; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=njbQ6Amv; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=W6ttRn13; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837382; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IKuT+N7+Lb5VqApn1kbaOItiOKwDSbQEIH+cYViP3f4=; b=IvuLaj+efRY1V6UJIo8M/9nFUT/5+3TfZIA0I1LUQR+YQyn0jjwEhcBwnFJIgQbxd95MPf BE+Y6k/cs75lXDU5gl4Fra5bu0s+xIY9i8LVL0Uv4GgEq7T5MD6/Wc5M5EXWn3wJlhdZnR ujinpNR968YevsUi3SQt7dWquJkC62Q= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=OctDuuKS; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=j+2cW9Bf; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=njbQ6Amv; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=W6ttRn13; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837382; a=rsa-sha256; cv=none; b=2a8zrLhvw9+U/jule41aCzDtlnX7mlfdAXriIXXxq8P+b3AOUIndGLjEBcQczOCtSutiuz 67/Rhgmw+MtMO3yCQGI+rpP3yliHRRv2tPdiJvjV/3fzggqV1hIHyNCPuA6GrqIlimqVv6 NOcNbyulmvfGLVNN1RhUEK/UkqKrGJE= Received: from imap1.dmz-prg2.suse.org (unknown [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 B6C7121A61; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837385; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IKuT+N7+Lb5VqApn1kbaOItiOKwDSbQEIH+cYViP3f4=; b=OctDuuKSC4UF+wjKtoVyH0QvGLpF8XAqLyIbYfZfqUqDqbAwL2bcO3E1Pn+AnZ3eyibQfJ 6tYt02lob+xX6VBjZqZpNYNoAFLn6kK0OzL6sjX7j4tN4Djr5FmBiXSud2Nwi+ztUQq/Zn 90QlsQZrnKA+lNEaCE4uWXQHIrkgSYU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837385; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IKuT+N7+Lb5VqApn1kbaOItiOKwDSbQEIH+cYViP3f4=; b=j+2cW9Bfl+vq0dFzwR4Z8VJ/wS4ujClcEsbZnU5mUWOOkqMaN8pzA61v7a4cLcVPI6cou5 oo7W4FlMxtS0HUCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IKuT+N7+Lb5VqApn1kbaOItiOKwDSbQEIH+cYViP3f4=; b=njbQ6AmvOqf/I3slNL642nz7dBav5v8cX1pr5wFiS4LsJeEcIXUKP4JeIGDMoYpMT1ZHst BoNAr/7ULUHsi0/LTIHKAQvyJs2XwZsVIxHGH1g8+c1W4/i2GGHXiON2JJcEy7S/UNuL8L xJNvP++tshk5rMe3z2U9GcJdCDP19Jw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IKuT+N7+Lb5VqApn1kbaOItiOKwDSbQEIH+cYViP3f4=; b=W6ttRn13nlD24fhIhJolQ8tSxHCj36d2kgYmU/rAvTHIozAnRoU5Z5qBqx+Xe4FxOmedZz 1dd53nZh0GPG6TCQ== 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 972F913AAA; Wed, 19 Jun 2024 22:49:43 +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 eNSiJIdgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:43 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:49:00 +0200 Subject: [PATCH v2 6/7] mm, slab: add static key for should_failslab() MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-6-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5370; i=vbabka@suse.cz; h=from:subject:message-id; bh=ldvIP2V3S2F517OMbSSDg7KW3uQS+0XOj9fkVOyN4sA=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2CAyioCEBExL2f8WncWFmFMWNZmaTFD1Cae+ fsvxwAVOTSJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNggAAKCRC74LB10kWI moEGB/9t+BV2+IAq6SNJND2pIHnMkyYyiUiRMgkXxQEQLNZbKEmMr1y1PoT7g7IbtFutozCfC6P bWrARbt2jfDNJOj/yOgVfB0zY6h9vQlmoqe8jjatje4Lt3s25DwGW6BgQl8PwkCPUNdQLfBevS/ AYIXYRcHbUOYW/qvyFYFXpUaCDhSmv0MLe1twno9XP42wpIZW1tw1gBuz+4UY284502W7uAXa2g cySWbAiKUS9owip7X8JnR7HvnnWXngktOPjsSzDdpuHPNzMa+FjgMBXyHemCi0nrD5+CCZyLUBo WPwX6uGMzVlf+cD+P/EYDIixpxBcEuaOvo6PBJfQfQxFxkWP X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3D532A0003 X-Stat-Signature: 8fguen5hhr5689co4eagiecet5war3xq X-HE-Tag: 1718837386-759694 X-HE-Meta: U2FsdGVkX1/T2KHXBJAA3g8PmZsbelnmaSJIs4vjAfNqDX7CVR0jQkdEXib61qt9d5xKYBcXx+4j7Ay6L/kYc7t75O+EFfkR3WN8A0cafV9SoClfNLCRpU68VLvX3lYvyx3EOLStpwCLK4KIbEKWxisddreFZCviDZGtMRrCXR593enEeA45ptEadD/OfCzPLoE9ggcsWCFb7BbF3rWYCmjXjuyRV9xZsaxOC4BpBbgGByBII7w5baI/TIlvYJ4g9/jWNIl7vmdpM8rCtDfbFxo00bAJbznxijNhA2XUPwzdvQ+HYwwfFNtni1xHKSpuxkxWQU/AlpskGkp4TUIq/8w0xyVnxrEOXB0alVzODhAPRh7T62pUkdfrSsKNYIrk+8zg3e5yEQHhqfgYo26D267xkUG5niCQ6NOlQvZ6bbbn1OKKmrsVwniGHqpyV84o4JyOfBvh90PgB2K8Ja0lKvQOHCZtNEgTi45qpFw9rVN2ytYHZBZ7B7whJ/dshNe2VNjTGVYn48LKpZpbDH+0Muhyzkhw2+mflUEmkP+0uel74Gs2sdp9vW0vJ9+xjLbPJTovDRx/IOB3mG+k3AEqG88tP70xZBHlY/bcESFgC+JBVOW4M49tGfQPhEmVcqLaZzGji+tf9N3NyuEugNz4Q7eBDAdGomHrecol+FN/d5DvShTvQSZFWO3S5pSJ7yfnMlTYAF6nxqDgqlTV8JMcvVshtmoKqyv8+uf1RdPbx1iToTsacnqxpqQ7Km8bH+cCwc8z80aXKMhytcn9JREZQo6NGMwq85o19ab5YVk/IY35HidxHSwkWl69XfI2/ou/D3ana20Lr6h3qgFOlrxujXuG+hgfPZeNDWbTmAnrl7XgUpqac9SWREUjzynsK+SwZUw8GRV8mgpAL8Js3rMRAw6LH2wS5bNmqFzyximhAHKe4o6+xt3+NH8qgPn2lrirJc+9JxS4YLJtIKS3CNV Zdu/xfUy lh3yAsXGDuMqdI4LNZNqR9uHJv7RgSpHBOU0FK++qG3vgx45YaqBki9Div98BjQP4y5wSHyuPzhAZmEHyGV4IkZNGCcS1dm1822cIlbrB4e6uw9Z2d/2lTqyo0K3p8VcrBpaM7JYhcyUFSeH8dGhxPoZAZh7dMzSJH0NdfV47Dy6WFPCbA9PL/8h9kdkqXPp3wheLawdGGyRbqaKokJPPQ0oiqvkxMx5Dr+EvQFoiWsDS83eZN3qW7ufs7WfKlhWQu06ZD0z1dS8UWgn253TNYXvzEUndXV67sY+aqqdfQwFMQHnm7KUjfYAGoracfMeJzp4mjoUMtrYhE3SY+cv2ERQ7hmcUDD5qMvSkAvWaD7wPorYflI5233loE+rFjkvFgJM77IknkSjDPOensMaBJb0LaA== 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: Since commit 4f6923fbb352 ("mm: make should_failslab always available for fault injection") should_failslab() is unconditionally a noinline function. This adds visible overhead to the slab allocation hotpath, even if the function is empty. With CONFIG_FAILSLAB=y there's additional overhead, even when the functionality is not activated by a boot parameter or via debugfs. The overhead can be eliminated with a static key around the callsite. Fault injection and error injection frameworks including bpf can now be told that this function has a static key associated, and are able to enable and disable it accordingly. Additionally, compile out all relevant code if neither CONFIG_FAILSLAB nor CONFIG_FUNCTION_ERROR_INJECTION is enabled. When only the latter is not enabled, make should_failslab() static inline instead of noinline. To demonstrate the reduced overhead of calling an empty should_failslab() function, a kernel build with CONFIG_FUNCTION_ERROR_INJECTION enabled but CONFIG_FAILSLAB disabled, and CPU mitigations enabled, was used in a qemu-kvm (virtme-ng) on AMD Ryzen 7 2700 machine, and execution of a program trying to open() a non-existent file was measured 3 times: for (int i = 0; i < 10000000; i++) { open("non_existent", O_RDONLY); } After this patch, the measured real time was 4.3% smaller. Using perf profiling it was verified that should_failslab was gone from the profile. With CONFIG_FAILSLAB also enabled, the patched kernel performace was unaffected, as expected, while unpatched kernel's performance was worse, resulting in the relative speedup being 10.5%. This means it no longer needs to be an option suitable only for debug kernel builds. Acked-by: Alexei Starovoitov Reviewed-by: Roman Gushchin Signed-off-by: Vlastimil Babka --- include/linux/fault-inject.h | 4 +++- mm/failslab.c | 2 +- mm/slab.h | 3 +++ mm/slub.c | 30 +++++++++++++++++++++++++++--- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h index cfe75cc1bac4..0d0fa94dc1c8 100644 --- a/include/linux/fault-inject.h +++ b/include/linux/fault-inject.h @@ -107,9 +107,11 @@ static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) } #endif /* CONFIG_FAIL_PAGE_ALLOC */ +#ifdef CONFIG_FUNCTION_ERROR_INJECTION int should_failslab(struct kmem_cache *s, gfp_t gfpflags); +#endif #ifdef CONFIG_FAILSLAB -extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags); +bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags); #else static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) { diff --git a/mm/failslab.c b/mm/failslab.c index ffc420c0e767..878fd08e5dac 100644 --- a/mm/failslab.c +++ b/mm/failslab.c @@ -9,7 +9,7 @@ static struct { bool ignore_gfp_reclaim; bool cache_filter; } failslab = { - .attr = FAULT_ATTR_INITIALIZER, + .attr = FAULT_ATTR_INITIALIZER_KEY(&should_failslab_active.key), .ignore_gfp_reclaim = true, .cache_filter = false, }; diff --git a/mm/slab.h b/mm/slab.h index 5f8f47c5bee0..792e19cb37b8 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * Internal slab definitions @@ -160,6 +161,8 @@ static_assert(IS_ALIGNED(offsetof(struct slab, freelist), sizeof(freelist_aba_t) */ #define slab_page(s) folio_page(slab_folio(s), 0) +DECLARE_STATIC_KEY_FALSE(should_failslab_active); + /* * If network-based swap is enabled, sl*b must keep track of whether pages * were allocated from pfmemalloc reserves. diff --git a/mm/slub.c b/mm/slub.c index 0809760cf789..11980aa94631 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3874,13 +3874,37 @@ static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s, 0, sizeof(void *)); } -noinline int should_failslab(struct kmem_cache *s, gfp_t gfpflags) +#if defined(CONFIG_FUNCTION_ERROR_INJECTION) || defined(CONFIG_FAILSLAB) +DEFINE_STATIC_KEY_FALSE(should_failslab_active); + +#ifdef CONFIG_FUNCTION_ERROR_INJECTION +noinline +#else +static inline +#endif +int should_failslab(struct kmem_cache *s, gfp_t gfpflags) { if (__should_failslab(s, gfpflags)) return -ENOMEM; return 0; } -ALLOW_ERROR_INJECTION(should_failslab, ERRNO); +ALLOW_ERROR_INJECTION_KEY(should_failslab, ERRNO, &should_failslab_active); + +static __always_inline int should_failslab_wrapped(struct kmem_cache *s, + gfp_t gfp) +{ + if (static_branch_unlikely(&should_failslab_active)) + return should_failslab(s, gfp); + else + return 0; +} +#else +static __always_inline int should_failslab_wrapped(struct kmem_cache *s, + gfp_t gfp) +{ + return false; +} +#endif static __fastpath_inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags) @@ -3889,7 +3913,7 @@ struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags) might_alloc(flags); - if (unlikely(should_failslab(s, flags))) + if (should_failslab_wrapped(s, flags)) return NULL; return s; From patchwork Wed Jun 19 22:49:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13704699 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 750C9C2BA1A for ; Wed, 19 Jun 2024 22:50:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F24D98D008F; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE9D18D0091; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 863BF8D008F; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 17D066B00BF for ; Wed, 19 Jun 2024 18:49:49 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BBE1BA416C for ; Wed, 19 Jun 2024 22:49:48 +0000 (UTC) X-FDA: 82249132056.26.F93A8C7 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf24.hostedemail.com (Postfix) with ESMTP id 6F91618000C for ; Wed, 19 Jun 2024 22:49:46 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=oBxQ6Ia7; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=hkjarJfU; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TynXPAks; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=L985X4si; spf=pass (imf24.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718837380; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=En1fgwGBp3akxqcTlyA7z2SXZocSGyKqoIqkTPWBt38=; b=SDtg5d5yGGDydjQAe9LMWRKHAgl3JFmrKv4tIEPTmrFFTk64lOn7mlhoXpm9yxCa/Y46HP 2E0ZJ9IXI/+rhKTj4Etf40pDnRE0+3fOEsrEH+DFzT9hz/YFw6sBWRpJeCFVkwoCdyvzgN AHHoioGpYntKrZk8OLPFg2hppiR+S/Q= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=oBxQ6Ia7; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=hkjarJfU; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TynXPAks; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=L985X4si; spf=pass (imf24.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718837380; a=rsa-sha256; cv=none; b=doGFO5nUA4CFlNSuFpLoAZ7TvyLaba8s0IGs4WXFSWoyTqOTTUw5DMnqVedKIiqyYazKKp Q9/Gwk8NJVAi82a7v6yvR1WHw1lja3o4qEaNpmn/8UsGeExSsIJEukMxUtAzH3zxVyUWk5 MZo/9vCn9sZTbCGwEwQlBfjCd6dShh0= Received: from imap1.dmz-prg2.suse.org (unknown [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 D50FF21A6D; Wed, 19 Jun 2024 22:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837385; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=En1fgwGBp3akxqcTlyA7z2SXZocSGyKqoIqkTPWBt38=; b=oBxQ6Ia700L8P7MHC2ZSj7lYOClW/b+nn74PtnoV77STyNfZuJ3s/3FxFvQ5ON/6/R+4CE h1v2V61d1EUmbIDPC9LkVI94UA1fx7FZyzcOsTllmIb3LpdGX+e/CqM1Qq4PPQSvsp62af TuKzhlqNZ2MZIuhtI7+mCA6VvjGjO2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837385; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=En1fgwGBp3akxqcTlyA7z2SXZocSGyKqoIqkTPWBt38=; b=hkjarJfUCCuhuk1r1+VTczH1jn0SrePROWGO6/JuDQUTIuFa3Kwopbx0FvR7OLsgc+7hff PXUElSpJDIwp0hBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=En1fgwGBp3akxqcTlyA7z2SXZocSGyKqoIqkTPWBt38=; b=TynXPAkshMLovoWJEyMGcwthd+0VNECCmYJf+upAlVaI4TBVa+V6WzmLxCDjoVKizHIo8z beBAnPxk8Tok4UFc8dN+SfSIuFPzGJKktIyQ5FT2rmT7UliqCKiboQSnua+P+muJ5d4aOd fgXUBfIUGrD6WUh4tQSVTqKwK0xvg9Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1718837383; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=En1fgwGBp3akxqcTlyA7z2SXZocSGyKqoIqkTPWBt38=; b=L985X4siXKopQT7WhbmtjCdC4M0g8YD/5UflTdx8IHiUaLXCG9QyIeO73rbief4APg1G1f rLISpErk9/ETi2Cg== 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 B4FCC13ABD; Wed, 19 Jun 2024 22:49:43 +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 +GboK4dgc2aFIAAAD6G6ig (envelope-from ); Wed, 19 Jun 2024 22:49:43 +0000 From: Vlastimil Babka Date: Thu, 20 Jun 2024 00:49:01 +0200 Subject: [PATCH v2 7/7] mm, page_alloc: add static key for should_fail_alloc_page() MIME-Version: 1.0 Message-Id: <20240620-fault-injection-statickeys-v2-7-e23947d3d84b@suse.cz> References: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> In-Reply-To: <20240620-fault-injection-statickeys-v2-0-e23947d3d84b@suse.cz> To: Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland Cc: Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4477; i=vbabka@suse.cz; h=from:subject:message-id; bh=lrkvm9m+5V6rPH6PUfaXjT75wU3B7FL1fWu0EmMg4jI=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBmc2CDq4C5vfd3OGsJTJXwWPnIR++a/CyqxA3pF yu5aRhqYhCJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZnNggwAKCRC74LB10kWI mtY9B/9F48jU4mg4DvmDG0e36QW+ooxwNCrSVM1MXSjv46DlcqK9YtApZrvOymhCnd03BmprQnE cTZiAw/ZIIuNLlW8D09hcNpB/oGulWuhpMehEB0iTP3UfItTOMOU1N30LODDF/abWn0v2qzp6LD ZtThwT/w0IM8z8/K4/oMDfoZinMXGXnFPV+b4fBbs/27R3btbUs9N3VZFkDLvC7eXmK3vAl0Bzw updjoZ7nNW0dqQnrOjDOl1T/DzDGQYdzGRoD3k7b3RnW8x25qFRY/ZejhS3tKEntPDl8Cg3C89i t0Jo4FimVrnSavpJWzGth87QCgsmpfVPo2Almyo5yxTbQ8Ee X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Stat-Signature: su4644k4w5rrxf3d8hwz9in7c7k88suc X-Rspam-User: X-Rspamd-Queue-Id: 6F91618000C X-Rspamd-Server: rspam02 X-HE-Tag: 1718837386-859980 X-HE-Meta: U2FsdGVkX1+f3XZ/L7RCBkGHngh1suFVyHNi8KE5kC+rmvng3kCARjHgZaVDl1CXiEtvfEFFaa94cLFDHk8L7TJ9H/zHCja8xYiiZ5Mpx1qkWrMq8EBS/JgrDCveUmdO8PyGRml7sy02+DxLX/HLxSEpFNhRahX6yaM7mdcKUGYEairMgaq4CiKZjCHANbyZppzutwKsjONtUhy9SDUqvh35u3jPe4f+EKK3PIgcR5JfP90uuGV8POf/NwcyopS2FwEBtypjURAFR5xl5gK5plgarG4ds7/yTxbN5mg8ge3wNIWlG6WbQ6Zx1JBUXJDOwxB9GCEjytsOejc2lB6ALWpj8GaYK3g6EZhTq0MR4DwWliIQfb/OV2ATa38DsX6EjhTCdG6OEyrjJuWMqTlT8dleX+jx5d/+R9uMZK5zMnHNIiGfSSL+w1r26LnaNtgFsIjCTUE1ntb8USP/fn0Sj5Imjmeia+lebGt7OLU9AcYf5RNBkmVHlp9B78JfHkYb1dexzMEr9VA3Vzs8yjKSRIFipezWGqZj3j8Pup5+EIYRD9fj9n/tOYT+VIhYOCzoZpwG6PqPt5u1TYN/5D3ZuUV//Wn9MRpLMiyrQ9wgFyoGwWnSo8u397d8nlKm5aJ2qEUG9bHG8yy/7u3SYo1W5bt02kIcxwd4ogXZ8wiYAyQqNSiRe0crWHTpNBsmkf9UpUCXpKgTxUmHE1JwRHPYFYQWGGUMgeW/ojlW4KwyeY12788vEerqk1Adb3yHt3TOIRShf8K9Tm+87W7KUCrxUKBSFAYzMlvJEx0rDfg5JMt9KoocSuEK2mE2QmsRyqSMUGkwE49Nufm0FkzRMiJQsPjsL2XYrNDcGPihrK7cyXi6WA/9pBtigHuX0lDL2HHiiERaVgpJlSvYBwFBHGeyUZJLW6db4R5qBIptX3Q+K3DOBJKIZO9e2QD6ltwV9YmZ7myaJl55GW3jBkChWg/ TaTvJjHP H5TVKu8Z4kF7F7O9qFnfqtoMEgBrPT7LGga+2M5gcBTXXLy6kH0USTSi3WrWYG3h83rV51A/zEOHU4yMwC1Pc8q1Im0f3PrO5cxP7y5pU93bGVoN11aTTEO2bDJrnAGlZaMQ2IYRg/wqLRPPL2BLVpU0tTSUbNFjXZ4FHmMFc/zlUd6k4X7TKkn1rdeYyqIr3qjsIjluZJPPTfVHDC3g3dPlZ0FMrs9haZyhoQvqqmrBwhgB5TC8NMCCKfvskEEJbyjNicXTveR8hlcdn+ulgICK422fVM3MyXcPevSHAkAYvDIDIwcGBOZ2ePY9eqnVEVxvWnZzOTzoVw2K4MxrIEd09tPBbscoE6ySY 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: Similarly to should_failslab(), remove the overhead of calling the noinline function should_fail_alloc_page() with a static key that guards the callsite in the page allocator hotpath, and is controlled by the fault and error injection frameworks and bpf. Additionally, compile out all relevant code if neither CONFIG_FAIL_ALLOC_PAGE nor CONFIG_FUNCTION_ERROR_INJECTION is enabled. When only the latter is not enabled, make should_fail_alloc_page() static inline instead of noinline. No measurement was done other than verifying the should_fail_alloc_page is gone from the perf profile. A measurement with the analogical change for should_failslab() suggests that for a page allocator intensive workload there might be noticeable improvement. It also makes CONFIG_FAIL_ALLOC_PAGE an option suitable not only for debug kernels. Reviewed-by: Roman Gushchin Signed-off-by: Vlastimil Babka --- include/linux/fault-inject.h | 3 ++- mm/fail_page_alloc.c | 3 ++- mm/internal.h | 2 ++ mm/page_alloc.c | 30 +++++++++++++++++++++++++++--- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h index 0d0fa94dc1c8..1a782042ae80 100644 --- a/include/linux/fault-inject.h +++ b/include/linux/fault-inject.h @@ -96,8 +96,9 @@ static inline void fault_config_init(struct fault_config *config, struct kmem_cache; +#ifdef CONFIG_FUNCTION_ERROR_INJECTION bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order); - +#endif #ifdef CONFIG_FAIL_PAGE_ALLOC bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order); #else diff --git a/mm/fail_page_alloc.c b/mm/fail_page_alloc.c index b1b09cce9394..0906b76d78e8 100644 --- a/mm/fail_page_alloc.c +++ b/mm/fail_page_alloc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include "internal.h" static struct { struct fault_attr attr; @@ -9,7 +10,7 @@ static struct { bool ignore_gfp_reclaim; u32 min_order; } fail_page_alloc = { - .attr = FAULT_ATTR_INITIALIZER, + .attr = FAULT_ATTR_INITIALIZER_KEY(&should_fail_alloc_page_active.key), .ignore_gfp_reclaim = true, .ignore_gfp_highmem = true, .min_order = 1, diff --git a/mm/internal.h b/mm/internal.h index b2c75b12014e..8539e39b02e6 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -410,6 +410,8 @@ extern char * const zone_names[MAX_NR_ZONES]; /* perform sanity checks on struct pages being allocated or freed */ DECLARE_STATIC_KEY_MAYBE(CONFIG_DEBUG_VM, check_pages_enabled); +DECLARE_STATIC_KEY_FALSE(should_fail_alloc_page_active); + extern int min_free_kbytes; void setup_per_zone_wmarks(void); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2e22ce5675ca..b6e246acb4aa 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3008,11 +3008,35 @@ struct page *rmqueue(struct zone *preferred_zone, return page; } -noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) +#if defined(CONFIG_FUNCTION_ERROR_INJECTION) || defined(CONFIG_FAIL_PAGE_ALLOC) +DEFINE_STATIC_KEY_FALSE(should_fail_alloc_page_active); + +#ifdef CONFIG_FUNCTION_ERROR_INJECTION +noinline +#else +static inline +#endif +bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) { return __should_fail_alloc_page(gfp_mask, order); } -ALLOW_ERROR_INJECTION(should_fail_alloc_page, TRUE); +ALLOW_ERROR_INJECTION_KEY(should_fail_alloc_page, TRUE, &should_fail_alloc_page_active); + +static __always_inline bool +should_fail_alloc_page_wrapped(gfp_t gfp_mask, unsigned int order) +{ + if (static_branch_unlikely(&should_fail_alloc_page_active)) + return should_fail_alloc_page(gfp_mask, order); + + return false; +} +#else +static __always_inline bool +should_fail_alloc_page_wrapped(gfp_t gfp_mask, unsigned int order) +{ + return false; +} +#endif static inline long __zone_watermark_unusable_free(struct zone *z, unsigned int order, unsigned int alloc_flags) @@ -4430,7 +4454,7 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, might_alloc(gfp_mask); - if (should_fail_alloc_page(gfp_mask, order)) + if (should_fail_alloc_page_wrapped(gfp_mask, order)) return false; *alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, *alloc_flags);