Message ID | 20231120-slab-remove-slab-v2-3-9c9c70177183@suse.cz |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp135940vqb; Mon, 20 Nov 2023 10:34:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNY91dpJYMRAnBEWRW2z96XdtEBau+B9jlJ6IE12hQcL3AlZpvcatTFYW7t4qBnhLafpAb X-Received: by 2002:a9d:744b:0:b0:6cf:6837:e4aa with SMTP id p11-20020a9d744b000000b006cf6837e4aamr8693805otk.27.1700505295706; Mon, 20 Nov 2023 10:34:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700505295; cv=none; d=google.com; s=arc-20160816; b=urMyU9rRbacLC0SC+xH00JJ1YjOBRT507CY5AkGJOBlx6o2+4HgnFPhqSqRpEIDPLg fhXCD9hwEtPifjnPLfzSIqDfChfS8YxXAZUpfqDldxqMv2QWQBLTUeyVgHu6J14m/UXd 7f4pTgFzVsor4SLglKHegNtyh+bwhRuoRKWbgsGiZptpYB0kX7S87q3vAwTYIj1nGnLf r1moWRfCTByLGfCwQuwW+Gv8vXo4wr2YQGSBdN9uPU0soc5rDP4q9pVbsOWLdAiS9zON ySO6ENSCXtDTrIE3BVscx8plO6bY2aLOblgNhkdmgeVaHzQbbo5Y5reIodDJaLlCcsK5 ywqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature:dkim-signature; bh=vcj9xI8buQN1G/rc5/jIHh6rM1KaznuLIHKBfsphrRU=; fh=ONqwzSuNvSIo96fWAp0pW54nN9xAdzTfApSlC7LEvRU=; b=o6yv1Dofqd4oZyF0JDhtlQv9ragGvC/cm/XgH4zS8Pe5tXjv5dJqx9IShmj82xqEbm 5bagc4/U16pXMsUOhRtqGLiDodJShvvqvW0vQ2qtiXbZpjR6hVHzzAQAFV2GmdUFm3hF gEOAquF6YI+9J1ZTlBmg7k9bkVGSdGZNUD0n1Zqiz9QKWAlWYpjsKllD+xpCRZuU8zZ6 O3FMRarJisCaPfo1NaTMfeYeji7T6bcBAjJ0sMXIU3uf7YnXNr+dB+LLduNRWEbxrdIA uVtAaRiUcy/1JS8gaTl3PlUzN5aZMWPkgLTeUVvltzP7enrMKNV6PR/Tx0H4frzM4Byh OsMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=A6pk4gEk; dkim=neutral (no key) header.i=@suse.cz header.b="mh8c/jJx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a20-20020a634d14000000b005be1ee5ef0dsi8875836pgb.15.2023.11.20.10.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 10:34:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=A6pk4gEk; dkim=neutral (no key) header.i=@suse.cz header.b="mh8c/jJx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 44F3580FA869; Mon, 20 Nov 2023 10:34:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232383AbjKTSev (ORCPT <rfc822;heyuhang3455@gmail.com> + 27 others); Mon, 20 Nov 2023 13:34:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbjKTSep (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Nov 2023 13:34:45 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB51CB; Mon, 20 Nov 2023 10:34:42 -0800 (PST) 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 <vbabka@suse.cz>); Mon, 20 Nov 2023 18:34:40 +0000 From: Vlastimil Babka <vbabka@suse.cz> 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 <rientjes@google.com>, Christoph Lameter <cl@linux.com>, Pekka Enberg <penberg@kernel.org>, Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Andrew Morton <akpm@linux-foundation.org>, Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin <roman.gushchin@linux.dev>, Andrey Ryabinin <ryabinin.a.a@gmail.com>, Alexander Potapenko <glider@google.com>, Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Marco Elver <elver@google.com>, Johannes Weiner <hannes@cmpxchg.org>, Michal Hocko <mhocko@kernel.org>, Shakeel Butt <shakeelb@google.com>, Muchun Song <muchun.song@linux.dev>, Kees Cook <keescook@chromium.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org, linux-hardening@vger.kernel.org, Vlastimil Babka <vbabka@suse.cz> X-Mailer: b4 0.12.4 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 1.30 X-Spamd-Result: default: False [1.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; MID_RHS_MATCH_FROM(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_RATELIMIT(0.00)[to_ip_from(RL563rtnmcmc9sawm86hmgtctc)]; BAYES_SPAM(5.10)[100.00%]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_TWELVE(0.00)[24]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[linux-foundation.org,gmail.com,linux.dev,google.com,arm.com,cmpxchg.org,kernel.org,chromium.org,kvack.org,vger.kernel.org,googlegroups.com,suse.cz]; RCVD_COUNT_TWO(0.00)[2]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 10:34:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783109040664614132 X-GMAIL-MSGID: 1783109040664614132 |
Series |
remove the SLAB allocator
|
|
Commit Message
Vlastimil Babka
Nov. 20, 2023, 6:34 p.m. UTC
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 <keescook@chromium.org> Reviewed-by: Marco Elver <elver@google.com> Signed-off-by: Vlastimil Babka <vbabka@suse.cz> --- mm/kasan/common.c | 13 ++----------- mm/kasan/kasan.h | 3 +-- mm/kasan/quarantine.c | 7 ------- 3 files changed, 3 insertions(+), 20 deletions(-)
Comments
On Tue, Nov 21, 2023 at 3:34 AM Vlastimil Babka <vbabka@suse.cz> wrote: > > 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 <keescook@chromium.org> > Reviewed-by: Marco Elver <elver@google.com> > Signed-off-by: Vlastimil Babka <vbabka@suse.cz> > --- [...] > 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); > } FYI there's a slight conflict (easy to resolve, though) when I tried to merge this on top of linux-next, due to a recent change in KASAN: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=0e8b630f3053f0ff84b7c3ab8ff98a7393863824 Thanks, Hyeonggon
On Mon, Nov 20, 2023 at 7:34 PM Vlastimil Babka <vbabka@suse.cz> wrote: > > 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 <keescook@chromium.org> > Reviewed-by: Marco Elver <elver@google.com> > Signed-off-by: Vlastimil Babka <vbabka@suse.cz> > --- > 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) > > -- > 2.42.1 > Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Very nice to see SLAB-induced complexity being gone :) Thank you!
On Mon, Nov 20, 2023 at 07:34:14PM +0100, Vlastimil Babka wrote: > 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 <keescook@chromium.org> > Reviewed-by: Marco Elver <elver@google.com> > Signed-off-by: Vlastimil Babka <vbabka@suse.cz> > --- > 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) Looks good to me, Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > -- > 2.42.1 > >
On Tue, Dec 5, 2023 at 1:27 PM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > On Mon, Nov 20, 2023 at 07:34:14PM +0100, Vlastimil Babka wrote: > > 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 <keescook@chromium.org> > > Reviewed-by: Marco Elver <elver@google.com> > > Signed-off-by: Vlastimil Babka <vbabka@suse.cz> > > --- > > 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) > > Looks good to me, > Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> nit: Some KASAN tests depends on SLUB, but as now it's the only allocator KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in mm/kasan/kasan_test.c can be removed > > > > > -- > > 2.42.1 > > > >
On 12/5/23 05:48, Hyeonggon Yoo wrote: > On Tue, Dec 5, 2023 at 1:27 PM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: >> >> On Mon, Nov 20, 2023 at 07:34:14PM +0100, Vlastimil Babka wrote: >> > 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 <keescook@chromium.org> >> > Reviewed-by: Marco Elver <elver@google.com> >> > Signed-off-by: Vlastimil Babka <vbabka@suse.cz> >> > --- >> > 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) >> >> Looks good to me, >> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks! > nit: Some KASAN tests depends on SLUB, but as now it's the only allocator > KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in > mm/kasan/kasan_test.c can be removed Hmm I see, but will rather also leave it for later cleanup at this point, thanks! >> >> > >> > -- >> > 2.42.1 >> > >> >
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)