From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (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 E98773E172C for ; Tue, 12 May 2026 12:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.48 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778590518; cv=pass; b=t8GvgXv95Q5V1QnN/IUgKshOh/7j5Ku3NWsMDR+lNoHJ2dGu8NE7DEORlsup4jdZU0C3UHkBHczukMUaWLg0b/Ml1qBnCUUeMl8w7TQTVeAdCwOOUt9XtkbOZTlLAn3pd7jWmJyUaYgHWMbw8IxKh+XufbynIg1iaXE6nP6c3FI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778590518; c=relaxed/simple; bh=k001GOwiMb4dRczjtWUwITXHZjyE/lTx6um46NJkiUA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=OEFGY+IqTGDp4hp36QnNOXB0mfTP0DahfthNUdbwZPOQrSRss5TNlorFGQEh5HaEU+/btXoqj+WkCj5XhgolsPMMXfw4To7SMeQGJdz8PXNVs1zTdxuZOhAL3uv8O+k40wc0wwTPHJ4jQVBiOAV0CMjk+cw6uZsxoWkyYmKWaQk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=o+KlQdY7; arc=pass smtp.client-ip=74.125.82.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o+KlQdY7" Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-1334825de43so737624c88.0 for ; Tue, 12 May 2026 05:55:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778590516; cv=none; d=google.com; s=arc-20240605; b=YxmJVtVxAMAqEOIMcUMulcHyQealzonjgrCnEhiW00dH3N3FjWg/07A1oFkpxAxcuz a+fixaVj4V2Svc91kx5VMCz23A/B638yFHJHOqD3WrbFIjbU9Wx+cWQqE1iSC9BLwcaM uXHsn3SWFmkJYinUSujrB3NCCmw+4NWEHiDVy1bmkSon0rRN8c4W+AZfSH1Gacb0lGrs cKuNso1lcYAwxgPwoEqf+KCBP7eLirA4MkrQb8U+YsVV8/kORiC58/SHIHGddjjeQl1+ M0yptUTDBZtoHySCK6rK9w7WtxHpq6rnOR8JX0iD5hHpesVSdnkn4KSmyvPJkHazZZjP yO3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=k001GOwiMb4dRczjtWUwITXHZjyE/lTx6um46NJkiUA=; fh=nWVtQLXO2caQR8LV2kCv5d2IeDOiJg+lX+nedpXXbMk=; b=eAxGZHjqEEm79PqOosFo2hB+X/JtxRbNA5AIdXpzwvpD2A+sPZBWUgxFmB0JFe3gvW 1SALMehD8rKDMplxzBEHQ+icxd00EPXZg9RYo/XNhzZ0+PICg2J7Ko06S2VT/mj1GYf5 G4TMiE7MT+c2k9w1qakYPDfXVK6q6ujDyZBLHrG7LWHlVRQ1inQkbzjbDifyeB9OKRA+ /sb3qZ2WnYho97F1Uag9mirD4eAiA8gJUp4XROeHmp3/XtvaQE9pxkYXkFJOUOvJC9EX uiFVP8L/eLOgaLQrpWQnMu2YoEdQ0eH9WKKm1j6qocXCKC22tYEzkVpxQIW9OIzILqKu BQpQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778590516; x=1779195316; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=k001GOwiMb4dRczjtWUwITXHZjyE/lTx6um46NJkiUA=; b=o+KlQdY7IlKaDI47VYq+Z/p5ErFxzXeqQYWFACAM73EmoyN5gyb2udD0P5VnMLUtpS EYv0YrVctlm3z+mM/lfy4VDdrd6661m7utczoRmNTheX2J62h95G8J16nfEg5xpmWxNQ Hk/IRppCdl8iDFwVbYOfvwtCqUgyYI+nGSr4yXh91FCK/I0nQ/QAuCtPHWa2HuRVLayQ IN0YFadSi3WJf1lP1dKbMnGsGh0/3jUfDxNxeAB9Q1ENwEmC7SmgReZmpQ1BZ6ZfWcRU WL9DWl+NI0hsx7wKKl6+W9Gz9eSwZm5DgBV7iCWwpS6FFqWDKUPJ8WxeWFaSOzrta+cV 7E7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778590516; x=1779195316; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k001GOwiMb4dRczjtWUwITXHZjyE/lTx6um46NJkiUA=; b=ZHwAk2m/ff/bwUw80fPHhitCOcJgx7YDzmEuk0QANOsYBU8amdgG0vpdmqoQS+nUcc phLacb+EFN/nsoCRwW/y67XqMRP/kfAfAJgzphLJjJ0TE18lGfovMLpa6q936yxhTMGm cUdoXyGK4t7KkxFwZ/01FZkYOJD70k14AjkesqhV4fqR5dr8eXhqWZH7wSjlxFA1Fx89 k7W2Ls2NS2ob8cs1wD8vewo/LmpPwWDZ8eoZv8jhM7+1r1MdmBb+fzWZ6NH9HVgLJtn1 FpidswZ5HrWUfj6cZSFa2bWNovd695y9rgw3g/zfz+6jJAoZR34ZCMJWY1R4uJcNeZkg 1loA== X-Forwarded-Encrypted: i=1; AFNElJ8nFRUDBDXPoSN3OGQjnX00dN9VEnbcKNiILKcI4gpnuTiY26SgINKwZtTiDaq+gVCak+mGdnWVAKOJikQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxMdjYxJum+kho3jLi5G79Tx26MF6Gm+20wtsSqhnzeLMAA9uGc KvZgp1/avsptdPphdAYWJl4cGuMzd1NMd5lhLAZxjPznoLa1T3RmcS3d5Hm07sjscDiylY8AGTn GPwgbmqi9XrHVk+34HIAAbeh7QG9TeHdAZfxOl0px X-Gm-Gg: Acq92OFBCuLZKzQt2nb+vZDj8ngrgU0Sh8qnvVzdWxqtbW9E8sCTck/0gHfwAIE7RYY 6nZueB5UOxAqB2jgyNSHoTBCXmPwZvyLMJyvp0e7UA43axTis/wG+CXZugoStIk9TbcuDvYqhVd Y4XXrpscyOGzc2NrQQGjFEL32wim3SY3rf4Vhg6U6L5wCxptEoYlWWn/MYLtVM8EopR7GEqS7TQ nRcP4j8mpHLUp4KnSFmRDcbw4QqCUaUaaD6DX0T+XTcorM6Po5OsQIjf0SJftJjR0Lq3ax3Gn8f 9ihaq4rskV6KXHvGduY48rgDanstFcA/Ou9eNUfSVJc9 X-Received: by 2002:a05:7022:2529:b0:12a:6a64:81ee with SMTP id a92af1059eb24-132a7edc7a5mr7596782c88.3.1778590515386; Tue, 12 May 2026 05:55:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260511200136.3201646-1-elver@google.com> <20260511200136.3201646-2-elver@google.com> In-Reply-To: From: Marco Elver Date: Tue, 12 May 2026 14:54:38 +0200 X-Gm-Features: AVHnY4JQX5cZZPTvWGLXHBJoCN4agKvIY9SusDXvPP6Ojv3wTK7cyl5mLfOsNmM Message-ID: Subject: Re: [PATCH v4 2/3] slab: improve KMALLOC_PARTITION_RANDOM randomness To: "Vlastimil Babka (SUSE)" Cc: Andrew Morton , "Gustavo A. R. Silva" , "Liam R. Howlett" , Andrey Konovalov , Bill Wendling , David Hildenbrand , David Rientjes , Dmitry Vyukov , Jann Horn , Justin Stitt , KP Singh , Kees Cook , Lorenzo Stoakes , Matteo Rizzo , Michal Hocko , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Roman Gushchin , Suren Baghdasaryan , linux-hardening@vger.kernel.org, Nicolas Schier , Dennis Zhou , Tejun Heo , Christoph Lameter , Harry Yoo , Hao Li , "Liam R. Howlett" , Alexander Potapenko , Miguel Ojeda , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" On Tue, 12 May 2026 at 12:37, 'Vlastimil Babka (SUSE)' via kasan-dev wrote: > On 5/11/26 22:00, Marco Elver wrote: > > When using CONFIG_KMALLOC_PARTITION_RANDOM, _RET_IP_ was previously used > > to identify the allocation site. _RET_IP_, however, evaluates to the > > caller's parent's instruction pointer rather than the actual allocation > > site; this would lead to collisions where a function performs multiple > > allocations. > > > > With the generalization to kmalloc_token_t, we now generate the token at > > the outermost macro, and using _THIS_IP_ would fix this for all cases. > > Hm but it means in patch 1 we make things even worse and then fix them > again, and also improve what was suboptimal prior to the series. > Would it be instead possible to reorder patches 1 and 2 so we improve the > current state first, and then introduce typed partitioning without any > changes to the randomized one? (aside from changing the previously correcly > used cases _RET_IP_ to _CODE_LOCATION_). It won't work (it could be made to work if _THIS_IP_ wasn't broken). The compiler is supposed to maintain semantics of a static variable in a function, even inline functions, and refer to the same static variable -- and because kmalloc_type is an inline function, if _CODE_LOCATION_ is the non-_THIS_IP_ version, it'd break. Even if _THIS_IP_ wasn't broken, the other complication is introducing the slab.c vs. outside use of kmalloc_type differentiation. Both these problems go away if we make this patch 2 (using _CODE_LOCATION_ on the outer macro, not in an inline function). While I understand that maybe we could have considered this as a stable backport, I think it's borderline; the feature isn't broken per-se, just slightly lower randomness than perhaps intended if size is a constant expression. A minimal fix prior to the macro rework currently eludes me.