Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2598491rdb; Wed, 21 Feb 2024 12:50:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcROmt8JoEAnJxs9XLYLorvtRziKKrandrcY5dq73JegdqnPmwj6ZgY8qsD5WYBZ7eUQIMm2FypKZE89FbKCmYxhLI0WGI3lto+YwXOw== X-Google-Smtp-Source: AGHT+IGoz1FUdXvIQ/D5SQabZ60QsNmWR3unXamypt5wZ1UsAWVpxekdfLjCtcoI+DQtW/4+PVNq X-Received: by 2002:a17:902:da8c:b0:1db:d826:45a1 with SMTP id j12-20020a170902da8c00b001dbd82645a1mr999214plx.9.1708548637484; Wed, 21 Feb 2024 12:50:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708548637; cv=pass; d=google.com; s=arc-20160816; b=Qbn32MOVmUyujPIV5RzAn3QICrEuVnDfvCzLMx0BFcWZcEk2QsbU67PWsy8mIp+1N0 71iLAW8Nzz6QR0LaER5fulUoiW8fH7aa9HRNoTg2ENJApctyZtivmi59M4lFgV1/8anw WVnlcbrwQvZe5vuUNA3L48LozgdOVzlX6kZbmLPWTIaYfxXbUVzAkKtiEpPbC1MDxhGM 9oew5tMqsu8/+yl4U85/+L5Qlr/sVymL1/dIaEudFf4T5ae6o/pcC+/SmRtbQISEd7Yx gEr8A2RzBgkPAlVstibO5XJcrzyQ++/dZR4h9naFQVP73Prnlgn0aWkPLVxRp5VJfeTr X48g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=SFWkqH9yqFlq6IROzTMH9jhnehwNcliel89qplM6at4=; fh=54TQIq/atsXolgfQSWgOSPM65Dszet16FHqZjL9uFuE=; b=L61a28e1GgMQCxaGXLgoY6UTLDqtc+dx22MueXOIKiy3cpOE2xcskzzi3ly0C3koqO yuMyepcU1zW9Oy2bjNm4nSB+isqtIkpE1aprG70cDCGLvsm5dSzEkuuLoDb01oM5vt9n Eb3YhJrD+4pEPgWvyIOBVXkZQ6htV6F22Vxa6NFV1VHkVMPOw2Ku96Gze3f/3bGtCIwq KakObjL9Ge4id58ViTFBh3zO398ff7/hE1DhFMzVMj77Mx5aebbWsSIoGrUrkVqffWpa Zm3HiH7YIAjvGYjSrrQTXu00Bm2Ob+OuUKav75MDFxcKsxKDks7TrMXYkfV1wPuXIDoL NHfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iE6XCpuF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75478-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m15-20020a63f60f000000b005dc1004e0b7si8855323pgh.100.2024.02.21.12.50.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 12:50:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iE6XCpuF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75478-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 174D3B214C5 for ; Wed, 21 Feb 2024 20:49:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E4DF85260; Wed, 21 Feb 2024 20:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iE6XCpuF" Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C43380610 for ; Wed, 21 Feb 2024 20:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708548554; cv=none; b=jY80123ZAVnaNv6guCzxfz9w1y3EGRHXjUu2UPI0aPN5c8Eaw2t/jXDSp35v9QICWJwko/KXvu8gO4zN7whztg+Ze/z21t+HOO9bQutDRFjFyJlHmJ2as/yLT6MMXfIOQE9UHdHhsTlxCkytc/SutvAtiG/+1qS0iwyuuEzbvqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708548554; c=relaxed/simple; bh=TAFRD/N26PP0ABAhbf3UPHWnQ6/QGPs/Av0FUApdALs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Lb2FHkWkfE3NgW+9FBwXQlf+DxOfKojv2wF7Ot2B3BGkx1RFFnhGxgwB4bOopsnrcePXRs9K8xO0Or5cknIrRT+V9u9VN5FWwMWTIHdFS1UFyBnAzSABA5P4CY9ntzwLGQJJSIajPqiVlobke4KaNBqfQax8ypbI4GcwqJr79Dg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iE6XCpuF; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-41278553215so6719375e9.2 for ; Wed, 21 Feb 2024 12:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708548551; x=1709153351; 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=SFWkqH9yqFlq6IROzTMH9jhnehwNcliel89qplM6at4=; b=iE6XCpuFpHW2gEMo7kyGiwy7DF6c4Wjd5JYUIMkf9NHmR1t2LoiEsyOg26RMCcb2bB JHAdxfknatQb7Y6bs1RlCkRcEN3KzObUqxGhO3fOtQhN1xwZlivJcedZSVaCWgwTtdCf gTFs5PUK+XGRN4XWWdUtM0wYMy/dK5BFZCCwvz4VFoBrkjyZnWaZR7qysjevPMrROVBs nEQbnzr7G8WSkwfuh+U9TY4t2o2OtxXXzQKbTi0vIiUYVSuhvvVRNEX41YkLC9GIiVpK eqCxjvRbq0ul0Nc7DLsC8DE9zaSfuDLH1n+RXXGpelTMWdA3c2NRpLDI1w+QZUsgQ6yn osrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708548551; x=1709153351; 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=SFWkqH9yqFlq6IROzTMH9jhnehwNcliel89qplM6at4=; b=CLGRparc5x3EpOvxEoywstdrj/x2uEp0edtd25h3JeA1/ylCI0t+YdpEHYCJU0Z+Ew s9FltPJ9hNwDyoqh+n6vsemU4sE0Djrwy+YF806krrNsekI+zSV+FrWeig8bs0vrRxxe 8GFqpyTlurdHJG0Ennvtjx8NOVB2D+wszJNhX9VUfG/D68gz2IoPFUd7Av/612FTRLnY 3nHlYV8P1/W5OVJJHzjqmVmyvmnpVNLEmh72ofVHAkqMr8rC+oiwWiceEiNtRDIacOdd yF8m58aqk5EshbLnDAMqU9xPz7a25KnbUbbOkOWlhr6U/p7+gMPIcR0+626O68LTcaYP Doqw== X-Forwarded-Encrypted: i=1; AJvYcCUxLy8GkwBhlIsHl6Z7PvZSOQ40Co+Ot/C3ZCimLd3lkZyasUtRYUPEXYl20MXowAtj/4qr2wDJrHTj4VmE2g5ov1Xln+StHTAxZ7gc X-Gm-Message-State: AOJu0YyD0EllNYykf2dp8duVosoRF7EGsUcKVuCPy7XVUJN9nGpVMxwV ztbUKHNVz0MXCqk7zJt7nCbJm/41p7GZ50g53lwoxonhgUWlTaPZy718+MUTNmdmTFTfmp0uXOY wXfVH0GZP4hm1SHju9XYYAJBZw7zxpbipyD8= X-Received: by 2002:a05:600c:1f8b:b0:412:4a57:388f with SMTP id je11-20020a05600c1f8b00b004124a57388fmr10806274wmb.15.1708548550675; Wed, 21 Feb 2024 12:49:10 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240220-slab-cleanup-flags-v1-0-e657e373944a@suse.cz> <20240220-slab-cleanup-flags-v1-3-e657e373944a@suse.cz> In-Reply-To: <20240220-slab-cleanup-flags-v1-3-e657e373944a@suse.cz> From: Andrey Konovalov Date: Wed, 21 Feb 2024 21:48:59 +0100 Message-ID: Subject: Re: [PATCH 3/3] mm, slab, kasan: replace kasan_never_merge() with SLAB_NO_MERGE To: Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vincenzo Frascino , Zheng Yejian , Xiongwei Song , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 20, 2024 at 5:58=E2=80=AFPM Vlastimil Babka wr= ote: > > The SLAB_KASAN flag prevents merging of caches in some configurations, > which is handled in a rather complicated way via kasan_never_merge(). > Since we now have a generic SLAB_NO_MERGE flag, we can instead use it > for KASAN caches in addition to SLAB_KASAN in those configurations, > and simplify the SLAB_NEVER_MERGE handling. > > Signed-off-by: Vlastimil Babka > --- > include/linux/kasan.h | 6 ------ > mm/kasan/generic.c | 16 ++++------------ > mm/slab_common.c | 2 +- > 3 files changed, 5 insertions(+), 19 deletions(-) > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index dbb06d789e74..70d6a8f6e25d 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -429,7 +429,6 @@ struct kasan_cache { > }; > > size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object); > -slab_flags_t kasan_never_merge(void); > void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, > slab_flags_t *flags); > > @@ -446,11 +445,6 @@ static inline size_t kasan_metadata_size(struct kmem= _cache *cache, > { > return 0; > } > -/* And thus nothing prevents cache merging. */ > -static inline slab_flags_t kasan_never_merge(void) > -{ > - return 0; > -} > /* And no cache-related metadata initialization is required. */ > static inline void kasan_cache_create(struct kmem_cache *cache, > unsigned int *size, > diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c > index df6627f62402..d8b78d273b9f 100644 > --- a/mm/kasan/generic.c > +++ b/mm/kasan/generic.c > @@ -334,14 +334,6 @@ DEFINE_ASAN_SET_SHADOW(f3); > DEFINE_ASAN_SET_SHADOW(f5); > DEFINE_ASAN_SET_SHADOW(f8); > > -/* Only allow cache merging when no per-object metadata is present. */ > -slab_flags_t kasan_never_merge(void) > -{ > - if (!kasan_requires_meta()) > - return 0; > - return SLAB_KASAN; > -} > - > /* > * Adaptive redzone policy taken from the userspace AddressSanitizer run= time. > * For larger allocations larger redzones are used. > @@ -372,13 +364,13 @@ void kasan_cache_create(struct kmem_cache *cache, u= nsigned int *size, > /* > * SLAB_KASAN is used to mark caches that are sanitized by KASAN > * and that thus have per-object metadata. > - * Currently this flag is used in two places: > + * Currently this flag is used in one place: > * 1. In slab_ksize() to account for per-object metadata when > * calculating the size of the accessible memory within the ob= ject. > - * 2. In slab_common.c via kasan_never_merge() to prevent merging= of > - * caches with per-object metadata. Let's reword this to: SLAB_KASAN is used to mark caches that are sanitized by KASAN and that thus have per-object metadata. Currently, this flag is used in slab_ksize() to account for per-object metadata when calculating the size of the accessible memory within the object. > + * Additionally, we use SLAB_NO_MERGE to prevent merging of cache= s > + * with per-object metadata. > */ > - *flags |=3D SLAB_KASAN; > + *flags |=3D SLAB_KASAN | SLAB_NO_MERGE; > > ok_size =3D *size; > > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 238293b1dbe1..7cfa2f1ce655 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -50,7 +50,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, > */ > #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER = | \ > SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ > - SLAB_FAILSLAB | SLAB_NO_MERGE | kasan_never_merge()) > + SLAB_FAILSLAB | SLAB_NO_MERGE) > > #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ > SLAB_CACHE_DMA32 | SLAB_ACCOUNT) > > -- > 2.43.1 > Otherwise, looks good to me. Reviewed-by: Andrey Konovalov Thanks!