From patchwork Mon Nov 13 19:13:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13454357 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 B23C6C07524 for ; Mon, 13 Nov 2023 19:14:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA9656B0260; Mon, 13 Nov 2023 14:14:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A9D9A6B026C; Mon, 13 Nov 2023 14:14:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 556CE6B0266; Mon, 13 Nov 2023 14:14:14 -0500 (EST) 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 34CFD6B0261 for ; Mon, 13 Nov 2023 14:14:14 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 06263140906 for ; Mon, 13 Nov 2023 19:14:14 +0000 (UTC) X-FDA: 81453881628.11.F3CC574 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf15.hostedemail.com (Postfix) with ESMTP id D4D9AA001F for ; Mon, 13 Nov 2023 19:14:11 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=X7VVhHyL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=zRCPFoeZ; dmarc=none; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 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=1699902852; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sRrsgxJwat5NXRr1zzXEwT9soXXRRzcekV8Be8tRJ7Y=; b=Wf3usMncMFDvMIJWoNO7lDsvBHLLTSqBcQu0i+TtrrXps2kkMbJ6fHxjMXtncvQsL9LYNj +zql/XKWCLvci1vDA9A9YqEb44hhGvsrVbTwG+2WtwjrdrVypUwMaDHb80MV3SOCAHsCgW w8gL0NW92kd5y/yRGzHysBYlXhiUnF0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=X7VVhHyL; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=zRCPFoeZ; dmarc=none; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699902852; a=rsa-sha256; cv=none; b=Juw00Eky+Sz3rhXfz1N5nvilDu+Etl3sHy9qSmFrCeKWYNdrIvKfKbjIyTrTRmQbRTsxoB 1vISAhxU8PXI+aS4x9h9doTZI57nFfTcoe/MmfB2Vd6qcVypbmv0ltcZyvQLTBueg2IyVt WZqBpbOjPMNNeyOjNS+guKM3L5aMuFs= 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 0504B21906; Mon, 13 Nov 2023 19:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1699902850; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sRrsgxJwat5NXRr1zzXEwT9soXXRRzcekV8Be8tRJ7Y=; b=X7VVhHyLuw5jRZn5p6oH6ejSLGgR3WPVlTm60bL6sWdiNYHztbNOQXsqe9CFMWqTmaZ3AY D2x+osw9tXWkHMxDHk30QEXQfKJLix4xQsfkUN57u8I8L/5+BSQ9CHWn98tBc06/T/FD45 7mYBlBSp0TXagVjFeR2CGXtvDAN6tDE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1699902850; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sRrsgxJwat5NXRr1zzXEwT9soXXRRzcekV8Be8tRJ7Y=; b=zRCPFoeZ2GTmsf6m0d+7i1K/BRLZjeTx5IgmKVyhLF3sum1/TSGRYltQYoISNmy/QPsNek wpyEGHbfsfHhT1AQ== 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 A64FA13398; Mon, 13 Nov 2023 19:14:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6DkBKIF1UmVFOgAAMHmgww (envelope-from ); Mon, 13 Nov 2023 19:14:09 +0000 From: Vlastimil Babka To: David Rientjes , Christoph Lameter , Pekka Enberg , Joonsoo Kim Cc: Andrew Morton , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Marco Elver , Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Kees Cook , kasan-dev@googlegroups.com, cgroups@vger.kernel.org, Vlastimil Babka Subject: [PATCH 02/20] KASAN: remove code paths guarded by CONFIG_SLAB Date: Mon, 13 Nov 2023 20:13:43 +0100 Message-ID: <20231113191340.17482-24-vbabka@suse.cz> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231113191340.17482-22-vbabka@suse.cz> References: <20231113191340.17482-22-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Queue-Id: D4D9AA001F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 73ruypgbqoorfufrqf43yekm3aj1kewb X-HE-Tag: 1699902851-99195 X-HE-Meta: U2FsdGVkX18GyVf2MTgNFc1iVkd7AzrjVfPcg0gR2qaG3Fhs+HML+V8XeeiD0lcgscIt4PT9Iry+nZAYUFOZ42RMmxbv4DI6nFJJX0I1Grk8I7+2KzyJe0Lp8ada1ag4XwvDYqwfs5DePDUWK/++QOqn2IXXoooguo/aOxvnwNnfUb1XrkkpkGn822JugD/P9bImbWwoeH6Kr3vqH5ovIvFsZjuPE1dScQ1AtlLq/LOMo3aozzwKElq970lKGllzEN9otR8e4pl13AlBWPfPi+dubqFeFGH9eUR0xv0TIcnUNMuYQTy5M2IfMw4kqioynyT5uTMi/fj29JTm6rusjzRSo3N/vnLhSHqpNvwRh8Qv8zHVc4KiFYHsMoSW5MmsxZMkbLsPYIvVHrPyZJdAcH7lS+TFkctNjb0T+V/Z3do08AfyleAmNp7JX8Z2CMeZBroqyTSeeqAj56CYqxrKELlsa/TaNMkLoiyLdZcoP7NmVSC/xt6ybySKuhiJT1ra5ESKM7SEidXX1IgRvdc2qtA3RxeOuhNr9lar9BcAzjvyW280Phc2eLhOhhIm4oSewrQKhIaUXplzm0FsMZVYG6F+z+QSh1p8ImaanPY6BOquBFGlUaZgnjINmvhlfQ3r/ZrhEUTgAe6nRJmp2T4bcJOpYKJHpchGQl5ey5oQ9XHN0KEtK6ru1OyxHgmLE8HJ1YcYd78IAab/J5gcOKGLDZZeAJSNPrMXtzWku7Lr7xfAhIkqatHAv3pIBh3dLuqZq3ymevPdBkaPr0J6a56uktdfa6hoTtueceED7HU8yRh3SP+MQXwToe7wGBbilnqzssWozih4P2l3+r4l977EML7iFuW2EkKTfWyg/nueHzu+UwfH6j/xgco0262gf8o70vzMq+pV0HtygXqTbRS3Rmm+3Fs+djU4SxBouEucwh1Lbg3fZ8r5EgnSy317V2ZWIH+ig/rURAcoDn6qZJp heL84JSS V9Dn8ZDfsUfq5/r9x3UblRy8lZfG6xv/H0O5/FjVVTXJXjVXXL9GiEeKFNgb9kJUVuI8IH3KpGYx76UlO3wkgGMwKxDIIr8r4OJOdeX/obQBObf+G5rACCsQOUK2E3LmvaB+3Ik9oWAa2YNUraKqxivX0F/s5K3ArJv2JXtlmWLh7NQ8Czsh2r9VPfSwvmYS0HxFaHC5SxFnYKDso2V7p8Wi4PwI8ihGrXom/XY8LFsYPdQPPwMuBTJ/y6tvpCSvjZzFaSgrNvKRSJiNKDB9/FlxnM7BwUiKR7DV6YHGNtn85cm5o1ZtHHLgaGg== 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. Signed-off-by: Vlastimil Babka Reviewed-by: Kees Cook Reviewed-by: Marco Elver --- 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)