From patchwork Mon Nov 20 18:34:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13461878 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 4332EC197A0 for ; Mon, 20 Nov 2023 18:34:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9B286B03A6; Mon, 20 Nov 2023 13:34:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 661F16B039D; Mon, 20 Nov 2023 13:34:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DFA16B0394; Mon, 20 Nov 2023 13:34:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AF9D86B03A6 for ; Mon, 20 Nov 2023 13:34:44 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7AE0EB4CCB for ; Mon, 20 Nov 2023 18:34:44 +0000 (UTC) X-FDA: 81479183688.08.8615850 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf09.hostedemail.com (Postfix) with ESMTP id 5714514000D for ; Mon, 20 Nov 2023 18:34:41 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=A6pk4gEk; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="mh8c/jJx"; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 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=1700505282; 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=vcj9xI8buQN1G/rc5/jIHh6rM1KaznuLIHKBfsphrRU=; b=dq06OaNiXOcU9i5Py2V9idkGOY9oJIyrV57nbw3viLoTrDw8ke4ofJJqk/xHalERXNIKV7 cQPmWf4Oer+/DGoIwMpsENnUI9+GUawjbLeGCZGYXYGo9zaJcbfvodAKn1eP4A9JkJSd4f QIE/qgT0OCIDahiPFVf6OfNa9Tz6kBE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700505282; a=rsa-sha256; cv=none; b=wrLKfeKc2shiN0/HOfvz7NVlMi1v2aJV4lD+v803VxAlRPcuPYRUtGS1Vmms0a/dxysg7H 6/aH2aSK+XwhYR4TVeudCq9EcdIl3JliWLdy4zVTlAkpGjub+wDQi6BpPiYbQwmMZo2YHG jFhBbB7dI2zSARQs2TtKkpWFbl0/KXg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=A6pk4gEk; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="mh8c/jJx"; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4693A21907; Mon, 20 Nov 2023 18:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1700505280; 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=vcj9xI8buQN1G/rc5/jIHh6rM1KaznuLIHKBfsphrRU=; b=A6pk4gEkvXgGbG5JHyYT2Bzkyi3by2QkL/UHE+Wk1ts8hf/IC0pBzq13xK3reyBKouglBG 57BC1vGB96eU+tgepj5w4PmY6bqABN6QMVWDBrjN/R11nMT5CKdv0/TBDXb+st8aO4WZS1 dshLAIHsoTHMmmH0K5OJHniF7PAiDXE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1700505280; 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=vcj9xI8buQN1G/rc5/jIHh6rM1KaznuLIHKBfsphrRU=; b=mh8c/jJx8hhsHnhhgXP9hnsvmHVjr5nyg7lJ6LFF9i1+3jxBbWZYqKIJ1Wqm2lzBoUWf0A rD2RUjMfd9VM7TCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 042B713499; Mon, 20 Nov 2023 18:34:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OMF+AMCmW2UUMgAAMHmgww (envelope-from ); Mon, 20 Nov 2023 18:34:40 +0000 From: Vlastimil Babka Date: Mon, 20 Nov 2023 19:34:14 +0100 Subject: [PATCH v2 03/21] KASAN: remove code paths guarded by CONFIG_SLAB MIME-Version: 1.0 Message-Id: <20231120-slab-remove-slab-v2-3-9c9c70177183@suse.cz> References: <20231120-slab-remove-slab-v2-0-9c9c70177183@suse.cz> In-Reply-To: <20231120-slab-remove-slab-v2-0-9c9c70177183@suse.cz> To: David Rientjes , Christoph Lameter , Pekka Enberg , Joonsoo Kim Cc: Andrew Morton , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Marco Elver , Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org, linux-hardening@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.12.4 X-Rspamd-Queue-Id: 5714514000D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ghen9pzerw5nhy7u3ys45ue91qeknues X-HE-Tag: 1700505281-344882 X-HE-Meta: U2FsdGVkX1/wCI3msXCfxMfII8QidkaS4jIJdGS4UFEXZwXOvf7d1b16/wM816neDq2KIEZONgR3yJbtkiMYayg0Xk2RSpGIomuJyoz8X6fGf6YnBCeHTukUGQ3D3ZGt6qEqqyD9HvNVlFdlScn1u37sXOTk0hktqXZk/dy+q8llkJiamJmx+QRjhnNkgWaBYg+oeUSXeViAYsDhy/qk3xOZFdSCSfAbvnG7Q2gBwHOMHeDIR13czG5dERMI47NISG+ujbIEqOHs0vf/0XTGENZo0yxUQlslxsZIQq09TC8/N+wiib0p6v7bV3KWlLR2fT8DSd00lzPkIh4cT/V+mDMDRPBzLClubrRnpW1vlcbPx2jIIl3FMPOLoP5c4IAhmEu2j4NuI+SfgF3HdZydX5q1DpNeGeieiEr52A7BNbXsSlVBN4tKsMm9aJi5RSogdp3ZYYs64LdwhSX/ZrdmtXWkOiuRLg5H40acLXcMzFNnZ/oi8Yc+fyKg4SNPax4dwBQcOgBRjk727r5Qepa0k3idzdMTBHjKnG0woVg54QhRDulprsqVso3x0J6nAt01K8ss5hLhnjS4TWPrIZdRLE7gU/8vI8Ofz3MSdUFuF0pY1asQFgFAUQWwn7cwgeBjx27JpVe+UZAB4Rg2JaeOL2NpxUAJY3DbRdNGEWw3lbROHS4SwZWlyTjBB2bl1gpFYAaMaAH9ApG8Hj/neEwLe5+LpmK2hoA6Hr7MV2iYtEHXVLMXawHgHakgo9PahL8HBuvINFT+XWWpnL8Gx2tGk07ABNnFpcAlX6gXWfuoDizB5lEpkIicH5L/Ff5j9xc8MgA6ogz3VS8ZvAnEFFgWek2KZY6N4xi/6YKbZRxBqQNm3PtB60MGg2J5Ir1L9aE7ePjiaCvw/69bY4USLunuriwOns+RcjrcrKd6BYn21eq6K9KF4OVHrj7ss26p/laYtHTNZGNGVNzE+goOHHy vPH7GHkS yIXdr88sD4Ik+IsleimEIf5I5PK9Xk5XZ5JaZhI5F6BMv+b6y0MAby1afY/AkIBToB6KKOpRify41xg3zx88XPYllcGeY6pO97+KLkrKAdVJlDokjq0GPVJhJ+4rU0ASKWoJWmU9m5PZxHP2yLnwUWo22D/pw2oRR6xIPsVqVYYCao8pmmi4jw9dGq8ikcVZ7OnJU/k9owsbyDuCQmhzMlPI/RfUUUyiVNS36Ne3fJYw3OBlQ/Sd8OUneAJCY7J+RVQ7SzsrMtmm+abwcsbBIHQsDGDz7VXLrcnnbD0V78Bh1se34jetGXbQkOaLpBjh2u7iAya8jQSyBqcCllCIPIK0fk0oCaZW+44UYjizcN8L4CeZyebzcqRDwD5klrnlVwagzfL4uWVTZPgDNTy2Fag+76g== 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: With SLAB removed and SLUB the only remaining allocator, we can clean up some code that was depending on the choice. Reviewed-by: Kees Cook Reviewed-by: Marco Elver Signed-off-by: Vlastimil Babka Reviewed-by: Andrey Konovalov Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/kasan/common.c | 13 ++----------- mm/kasan/kasan.h | 3 +-- mm/kasan/quarantine.c | 7 ------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 256930da578a..5d95219e69d7 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -153,10 +153,6 @@ void __kasan_poison_object_data(struct kmem_cache *cache, void *object) * 2. A cache might be SLAB_TYPESAFE_BY_RCU, which means objects can be * accessed after being freed. We preassign tags for objects in these * caches as well. - * 3. For SLAB allocator we can't preassign tags randomly since the freelist - * is stored as an array of indexes instead of a linked list. Assign tags - * based on objects indexes, so that objects that are next to each other - * get different tags. */ static inline u8 assign_tag(struct kmem_cache *cache, const void *object, bool init) @@ -171,17 +167,12 @@ static inline u8 assign_tag(struct kmem_cache *cache, if (!cache->ctor && !(cache->flags & SLAB_TYPESAFE_BY_RCU)) return init ? KASAN_TAG_KERNEL : kasan_random_tag(); - /* For caches that either have a constructor or SLAB_TYPESAFE_BY_RCU: */ -#ifdef CONFIG_SLAB - /* For SLAB assign tags based on the object index in the freelist. */ - return (u8)obj_to_index(cache, virt_to_slab(object), (void *)object); -#else /* - * For SLUB assign a random tag during slab creation, otherwise reuse + * For caches that either have a constructor or SLAB_TYPESAFE_BY_RCU, + * assign a random tag during slab creation, otherwise reuse * the already assigned tag. */ return init ? kasan_random_tag() : get_tag(object); -#endif } void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 8b06bab5c406..eef50233640a 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -373,8 +373,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags); void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags); void kasan_save_free_info(struct kmem_cache *cache, void *object); -#if defined(CONFIG_KASAN_GENERIC) && \ - (defined(CONFIG_SLAB) || defined(CONFIG_SLUB)) +#ifdef CONFIG_KASAN_GENERIC bool kasan_quarantine_put(struct kmem_cache *cache, void *object); void kasan_quarantine_reduce(void); void kasan_quarantine_remove_cache(struct kmem_cache *cache); diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index ca4529156735..138c57b836f2 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -144,10 +144,6 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache) { void *object = qlink_to_object(qlink, cache); struct kasan_free_meta *meta = kasan_get_free_meta(cache, object); - unsigned long flags; - - if (IS_ENABLED(CONFIG_SLAB)) - local_irq_save(flags); /* * If init_on_free is enabled and KASAN's free metadata is stored in @@ -166,9 +162,6 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache) *(u8 *)kasan_mem_to_shadow(object) = KASAN_SLAB_FREE; ___cache_free(cache, object, _THIS_IP_); - - if (IS_ENABLED(CONFIG_SLAB)) - local_irq_restore(flags); } static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache)