From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 CF0E637BE80 for ; Tue, 11 Aug 2026 05:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786426987; cv=none; b=BLRaPDGhmOrngGs+y6FirSz7UUvdtSCv6hXLgfRNECX2bHO2L0UI3kfz2cwNypiwQAV0m80ymkP/fsyPXTRKtUuemhZR3STNxCMPZGO8zbJn7Ch/iFgtxm0p+y1FKZtAq7ffLbaROvEHkLB/bVrnYpY8gXiwj52DKKviiOdPaRg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786426987; c=relaxed/simple; bh=jen/KcC3hJEwLywdx6gJec70M4mKp+4HASXJz53zBQk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JxywkAFCDy8/Ik9MqCMH9aqHkU5WMadz34pCyTXyrWpIeLRcBXbK0d+4m0+XA9CBmhCG+G89YjutYNiiALWa6yzr182+wnro3bz4RZhHuHriMd+iRp694FlTLjGrKkiEiKsZKNv+foXFOWaZh5QAkFPtuzYM2Pn5gH0ASvhZ+5c= 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=gseM0srr; arc=none smtp.client-ip=209.85.128.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gseM0srr" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4954f5e8020so13305585e9.2 for ; Mon, 10 Aug 2026 22:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786426983; x=1787031783; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=hwYASxEZOdWoj37YH1RdRjVEdz25n+52dFAwjvk67KQ=; b=gseM0srripBCZKVf6pTgk9Xf3lVDbJQkRLGkZZyEh859bbswB2aIHLnc1f8rTyFqIx nBlYMKShg8vSFH2Ds7bA9ZycINyr/DLVznvpeseY3pgUbI4b5ZEYCHX436761Q67gS// qDn7epm329qKWMxwyXm2/LbJDuuXnRp1bPBtdHTptaXo3FlEsafc04gyCWun4U1rYUq5 I4wpiA91T9LYe/ruayg0pneaQRdaSdUwzuW3JgvJppfvG32Lq/7srflScK/w3VO3JnWD 3N5n5AMZdggviTrAjJuMuV/DMvWWLcyrJWjSaE/fjchZ/SDTqyLYTrFfpOLnowjxKF9e ZINQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786426983; x=1787031783; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hwYASxEZOdWoj37YH1RdRjVEdz25n+52dFAwjvk67KQ=; b=XGnIXPWPiBN5MOqZGpeKCctrzhKvPbvwEAtH3MIlwLGOPyU0qMdFUcOnZj7/+bNlT+ 9LxbkAcggw5sD1VDHQZoBNojHcAzTLJtjiaU2+KcTXHmg+eOP9P2N03tX9aE30o2+GtG XKI3K6tDCYQvtUybTgv4jtrzx4qJ0QEYh3TAEiATVXEjlELoRHUvdsZs8oJF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MRMpR48= X-Received: by 2002:a05:600c:3553:b0:499:7312:2d5f with SMTP id 5b1f17b1804b1-49978494c8cmr10369445e9.19.1786426982735; Mon, 10 Aug 2026 22:43:02 -0700 (PDT) Received: from MacBook-Pro-von-Karl (dynamic-2a02-3100-a133-e401-bc8e-d36c-2d08-c5e0.310.pool.telefonica.de. [2a02:3100:a133:e401:bc8e:d36c:2d08:c5e0]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499740c46efsm39080525e9.4.2026.08.10.22.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 22:43:02 -0700 (PDT) Date: Tue, 11 Aug 2026 07:43:00 +0200 From: Karl Mehltretter To: Catalin Marinas Cc: Vlastimil Babka , Harry Yoo , Andrew Morton , Rasmus Villemoes , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] slab: align ZERO_SIZE_PTR to ARCH_KMALLOC_MINALIGN Message-ID: References: <20260808105622.62026-1-kmehltretter@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Aug 10, 2026 at 03:26:37PM +0100, Catalin Marinas wrote: > On Sat, Aug 08, 2026 at 12:56:22PM +0200, Karl Mehltretter wrote: > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index 32c9f8ed7ae20..0798a714da87f 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -259,13 +259,16 @@ enum _slab_flag_bits { > > > > /* > > * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. > > + * It satisfies the alignment promised by __assume_kmalloc_alignment > > + * and keeps the historic value 16 where that is already aligned. > > * > > * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault. > > * > > * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can. > > * Both make kfree a no-op. > > */ > > -#define ZERO_SIZE_PTR ((void *)16) > > +#define ZERO_SIZE_PTR ((void *)(ARCH_KMALLOC_MINALIGN > 16 ? \ > > + ARCH_KMALLOC_MINALIGN : 16)) > > > > #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \ > > (unsigned long)ZERO_SIZE_PTR) > > @@ -622,6 +625,12 @@ static inline bool kmem_dump_obj(void *object) { return false; } > > #define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) > > #endif > > > > +/* > > + * Keep ZERO_SIZE_PTR below PAGE_SIZE and the low pointer poison values. > > + * 128 is the largest in-tree ARCH_KMALLOC_MINALIGN. > > + */ > > +static_assert(ARCH_KMALLOC_MINALIGN <= 128); > > I'm not sure we should bother with this, or at least make it strictly > less than PAGE_SIZE since 128 doesn't have any meaning for the slab > allocator. > Thanks for the review! The case I had in mind when choosing 128 was POISON_POINTER_DELTA == 0, where LIST_POISON1 is 256 (0x100). With the current range check, an architecture with non-coherent DMA and 256-byte cache lines would make kfree(LIST_POISON1) a silent no-op. Looking at this again, I think ZERO_OR_NULL_PTR() should match only NULL and ZERO_SIZE_PTR, rather than the whole range below the sentinel. This would also stop unrelated low pointer values from being silently accepted. I'll include that change in v2. Thanks, Karl