Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp522109rdf; Tue, 21 Nov 2023 08:47:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFnwF/vc3ZdCuzobW4iFeYf91dbeU7moN5hXs9ybKIL1bCvNg1iYu28GPDn9eskrLKsouR X-Received: by 2002:a17:902:d484:b0:1cf:5670:243e with SMTP id c4-20020a170902d48400b001cf5670243emr10806656plg.13.1700585254169; Tue, 21 Nov 2023 08:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700585254; cv=none; d=google.com; s=arc-20160816; b=Un+KKxlSEbHVfZGPX2tD6QUyRhKObf2I0E+Uh1h8xeP/oCzSS3odINbUsBDmY7zWVv s8DM8Dnlk+dziuvtYENRl1wR3HtT2cJ9NcZ4AHXAMhkGGHX6r/PYArT1rXrAOIir8wIU gInKikPQ0QdNevjRcjXE+X3fKgeEtLWR5efoZl6PkVqCcY/RRJ5iiuSiBEyZtTYT+rBU rjNJHcc4aQ+CXdGqT+gnQNa3+zmyoyo2H55sr0ukZkBUssFn1Gbe0Vb3kGQTuXyl7U9k GhxBnKeT9pK+slHZUmB5b+jt/2q+xKpmaq8PvCZbNNaK8o6et6ZIbOqQau2o4aTCrh7n IpgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4pN2u4fGcywnuJpGPzQlph9Q+P1Toihu44zlYs+cFFQ=; fh=mgiYqFMMLDYnPM/L5CQVqfnAGbSFJjlpMiK/q7So1D4=; b=eUV/MaOqQEgun3f4pS7dkXfMESkcI0Pngfp/M+9U2hPd1RERhgAl9xWAYoXjhvFZfT MvcuTc+nnj3w21Sy8k61vsmHczfn+N4eVlrD1OgKUM2+sdUr4EQzmv6zWhRloZRPH8Bk HUkhZ/JFczjj6tVcbRzyrnnaV/flEWHJJdAuhFaf2hHEZEURkI77xWNOxrtpoOdcTyBF uGexYK5cgHMcclsjEdblo/oJJZ3qj+l52gzO/BCAePacnBMGjMJ+rrxZIB8hy+HYlB92 vd3b8Khq3gh80TO8jOYCCmD1X8yEBooKrLbTP2QkL35yXIqeJGcxwVROpGnYvi7rN3My HxBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DzxB0nT8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bg4-20020a1709028e8400b001c566ea86eesi10402367plb.177.2023.11.21.08.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 08:47:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DzxB0nT8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3BC5A8079DCF; Tue, 21 Nov 2023 08:47:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233573AbjKUQrU (ORCPT + 99 others); Tue, 21 Nov 2023 11:47:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbjKUQrT (ORCPT ); Tue, 21 Nov 2023 11:47:19 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60FF6100; Tue, 21 Nov 2023 08:47:15 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5bde80aad05so4518816a12.2; Tue, 21 Nov 2023 08:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700585235; x=1701190035; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4pN2u4fGcywnuJpGPzQlph9Q+P1Toihu44zlYs+cFFQ=; b=DzxB0nT8p4NyIUu5ZtyBP5LEh8DnTN2KVJL5FLUCbVf5q5ovC7zgcJol4TBTRCXb2o 7SSQlDq9vPWcYSkWsk141E+Vmm4w+Hnwd1nOMkd0RKZEa2SIhsd+oXaU3QqB4VGkCTIU 5nQhZW/+dmG/p0L8f6+AlaFXwVxAdJx5nsGXAxt1JNiQF+8cHcndF0T9MagiDsMc47cT Bdi4sQubI5zt+eGRlU18z9tkzmiLUZTGZYS9O1tYFCbancpswn66M4zh1FmcnqSQI6Sm 1ET82DcJGjh/6bY8GQ2T193dPEPm3Dgt04/K6TWeqWMXTVUwuZp/ovQw5H2q0nctmVEv MpOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700585235; x=1701190035; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4pN2u4fGcywnuJpGPzQlph9Q+P1Toihu44zlYs+cFFQ=; b=a3ig5k9fgIlUoWRhFi57mhhjeldpHY6Oc48+r44lVN/y/ATw7HzrKFCv32rXJ47NSk gcGS5P19PqTYDE0ZFlc5l7i1P3Oeq2Tn3PI+23oWNd7xJM7jd/J2G08oHeto46TIQH7G KLKvmxiwNSLotlqgjW3biw6I6hB6PvCkuI3a2CnChwHipLkJMwvHfHFpNAYoZhTpVjnX 3XaOFGOxUY8Dqa31U29o++Wdd5vOl/aZBXHo75cHoyZd39Aw5SyZi/M9MNsRuzX5IRZw YjQHaVZ0Z59w5KyT8vZwGDn9Fr2BW04u6Cj9WXBsYKGn+KWBwPnpQyWx8HG5uZkgdgnA FUww== X-Gm-Message-State: AOJu0YxjBnNYLaFsLgR0/L6eoFjsYwPbT/JA4mD0IiSH7FPiqRNnuHjD tPZsQtAEpb0tfRFZIJvW5FD7zToPA5gWOXBL2DM= X-Received: by 2002:a17:90a:4411:b0:280:18bd:ffe7 with SMTP id s17-20020a17090a441100b0028018bdffe7mr9875785pjg.48.1700585234819; Tue, 21 Nov 2023 08:47:14 -0800 (PST) MIME-Version: 1.0 References: <20231120-slab-remove-slab-v2-0-9c9c70177183@suse.cz> <20231120-slab-remove-slab-v2-3-9c9c70177183@suse.cz> In-Reply-To: <20231120-slab-remove-slab-v2-3-9c9c70177183@suse.cz> From: Andrey Konovalov Date: Tue, 21 Nov 2023 17:47:03 +0100 Message-ID: Subject: Re: [PATCH v2 03/21] KASAN: remove code paths guarded by CONFIG_SLAB To: Vlastimil Babka Cc: David Rientjes , Christoph Lameter , Pekka Enberg , Joonsoo Kim , Andrew Morton , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , Andrey Ryabinin , Alexander Potapenko , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 21 Nov 2023 08:47:30 -0800 (PST) On Mon, Nov 20, 2023 at 7:34=E2=80=AFPM Vlastimil Babka wr= ote: > > 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 > --- > 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 *c= ache, 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 free= list > - * 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 ot= her > - * 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 *cach= e, > 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 *)obje= ct); > -#else > /* > - * For SLUB assign a random tag during slab creation, otherwise r= euse > + * 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, str= uct kmem_cache *cache) > { > void *object =3D qlink_to_object(qlink, cache); > struct kasan_free_meta *meta =3D kasan_get_free_meta(cache, objec= t); > - 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, stru= ct kmem_cache *cache) > *(u8 *)kasan_mem_to_shadow(object) =3D 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 *cach= e) > > -- > 2.42.1 > Reviewed-by: Andrey Konovalov Very nice to see SLAB-induced complexity being gone :) Thank you!