From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00ACAC36002 for ; Wed, 9 Apr 2025 14:30:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD8D6280056; Wed, 9 Apr 2025 10:30:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B88546B01B1; Wed, 9 Apr 2025 10:30:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A51E0280056; Wed, 9 Apr 2025 10:30:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 82D3D6B01AE for ; Wed, 9 Apr 2025 10:30:21 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 01273140C30 for ; Wed, 9 Apr 2025 14:30:22 +0000 (UTC) X-FDA: 83314740726.26.8F66828 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf12.hostedemail.com (Postfix) with ESMTP id 634784001D for ; Wed, 9 Apr 2025 14:30:21 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744209021; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RB4y15HeG3IyoLrNLXGDFdMsrnSXps/NRZaM/5DoiBM=; b=EHGTVff1AmL2NL+d0eepxdUeYtAo+gd2UgPuFflVRtoMZBiCSB1BPa/C7IQ5kiWcckBqju yVrQWH8FIOeiIZtoW/LmsfwqTS43MdwF94rQ2cUrvUHu8/ylC7pMz7MNI0U8rd34F32CoF GeT11H7jLNtwXsBTb/PUQBnnzNqZj0o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744209021; a=rsa-sha256; cv=none; b=QYZET/V8wP3ZNzP1dfcbEmyzSLMAh1Bk8wBemDDoGyrOarYzOBdc5XNHnBN382JA6byrwF 2VEDJogBNG7uJmgyV1AM4EhXfu1bwW8KEMraRVUkuzSpEVdbspd0ZqeJPd8BedoY1nDJjE mNU67MaZPgRy0AuWFD/sD01MNTP3BjE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C9517A498DC; Wed, 9 Apr 2025 14:24:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E710C4CEE2; Wed, 9 Apr 2025 14:30:18 +0000 (UTC) Date: Wed, 9 Apr 2025 15:30:16 +0100 From: Catalin Marinas To: Vlastimil Babka Cc: Petr Tesarik , Feng Tang , Harry Yoo , Peng Fan , Hyeonggon Yoo <42.hyeyoo@gmail.com>, David Rientjes , Christoph Lameter , "linux-mm@kvack.org" Subject: Re: slub - extended kmalloc redzone and dma alignment Message-ID: References: <20250404155303.2e0cdd27@mordecai> <39657cf9-e24d-4b85-9773-45fe26dd16ae@suse.cz> <20250408072732.32db7809@mordecai> <42cb9ae4-e479-4f52-8e4c-f4bc3cb54971@suse.cz> <53cc9e92-8a57-4989-af4e-26ced40de91c@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <53cc9e92-8a57-4989-af4e-26ced40de91c@suse.cz> X-Stat-Signature: x8y8kswq7hyazkikrofqyknmg4bo3gsc X-Rspam-User: X-Rspamd-Queue-Id: 634784001D X-Rspamd-Server: rspam08 X-HE-Tag: 1744209021-858566 X-HE-Meta: U2FsdGVkX1/knAfRnjp4MpF12ar230prwlAlyknaaDKDlBDleKKNVZmUPDDu9KlimjTYN1c7dydbNpFcDNXZCSoYrsDMhRPENAWFbJF6VLRvQIV4yHlmbx850swiAmDhywU5gfNX4MAPInjgP6k3KLTPIAg96NpwZR3vWscmwaMsdI2i1T8jdu/IuHNs8r2f6HwKE+8Wn29pNfju0LiOAfeFus9TAWSw83I9NfLAwte9OXAsm59pB8Bzb/rnbNbT6r0bdeoqMqPl9wxcvQGvcbviAM4nDVefj1injUU40zHwdusxUUZMAwDBVLkmnyBjxw0+XJqjsKGASjZSegHeRumI207d496qG17Bl0p2x7bkojtZh0RmtvnLAnnnfknwU4YuZ1TcUCQtPrFM3K9eDa1QQkoap/wH9jWoj5vslg3YO/7hoEpJ87tw5E/00HYrL3Be0znJnMiiXbNvf9H+wnT1UnUQnqSnKGk8l+Di0DBsuGCMUXoTnQzpXlR8uOc03GromFZx0uk6AJ/K5ng7R/uYEP9hdG84sFmhhO365Yzu4I69udh5qdneTWTHR4xcAsvRUG6Dc+IhqeLTEgJXQ/CFju+ixLoq66EUNzGu/gUCrf6eejtwfwcUxU0H8JPg0T8CnoByVHAgRbzWj11RQYR9nyb9LE0GKVlznP1CUe3uv6gYgZK9xX8gCZ9BmWOzXFP49C8fTfoYf4QWseMj0pBAbSmQXcO7FMsCu+f5Rc81LSTqqXNOmYk1+9tWE9kb1Jd+uyyxWoi8LAu9DelvMZFCGijax4YAjcUNRv44P1ktHq9r1y1Bxwg2LshKci3a9/Jgg5OC+oDg/0fhjhLbC15xwYsYI35rXeL3sRTQQzID9ASlTc8DTowcxsJaJ7Z1Xnl2Ewkpuu+XBjRR0ma05zguFalEpzdxbedOfSFswVSKsN6c/D5p/v013qmAmUWjalgVtPnwbxcMY+5Q+DN lbtFEtCc 6bPJTqrsrQuaDEVGzXgt4A5RUHfh0Z6lRF6s8wCVZybjYVqpamdpriAuMRBCrA60NIubBVu+TxEDV5ZTpyBXHRcx4WPUDw4TElLcUXbzgl0UuWliPhl6BNzirmYTP20XIwqrUza77vOllUWCKWC2b3C5p87i56/NQwjdO2SomVMJwhgCy5/ojdAJjjA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Apr 09, 2025 at 02:22:10PM +0200, Vlastimil Babka wrote: > On 4/9/25 1:11 PM, Catalin Marinas wrote: > > On Wed, Apr 09, 2025 at 10:51:43AM +0200, Vlastimil Babka wrote: > >> On 4/8/25 5:07 PM, Catalin Marinas wrote: > >>> Assuming I got kmalloc redzoning right, I think there's still a > >>> potential issue. Let's say we have a system with 128-byte DMA alignment > >>> required (the largest cache line size). We do a kmalloc(104) and > >>> kmalloc_size_roundup() returns 128, so all seems good to the DMA code. > >>> However, kmalloc() redzones from 104 to 128 as it tracks the original > >>> size. The DMA bouncing doesn't spot it since the > >>> kmalloc_size_roundup(104) is aligned to 128. > >> > >> Note that kmalloc_size_roundup() is supposed to be used *before* > >> kmalloc(), such as dma_resv_list_alloc() does. Then there's no issue as > >> no redzoning would not be done between 104 and 128, there would be only > >> the additional redzone at 128+. > > > > Yes, if people use it this way. devm_kmalloc() via alloc_dr() also seems > > to be handling this. However, given the original report, I assume there > > We can probably ignore my original private discussion as motivation as > it wasn't confirmed (and I'm not sure it will) that it was really a case > involving DMA alignment. It was just something I thought might be > possible explanation and wanted to doublecheck with people more > knowledgeable. > > Unless you mean original report as 120ee599b5bf ("staging: octeon-usb: > prevent memory corruption") that Feng mentioned. I was referring to your private discussion. IIUC the one Feng mentioned was about the SLOB allocator which I recall did not guarantee natural alignment for power-of-two allocations. > > are drivers that have a problem with redzoning at the end of the buffer. > > So I'm not aware of any issues reported due to the extended redzoning. Thanks for confirming. I guess we can ignore this potential issue then as long as drivers take care of the alignment or use devm_kmalloc(). > > I did a quick test with kmem_cache_create() of 104 bytes with > > SLAB_HWCACHE_ALIGN (64 bytes) and it has a similar problem with the > > redzone from byte 104 onwards. Here we don't have the equivalent of > > kmalloc_size_roundup() that a driver can use. > > AFAIK SLAB_HWCACHE_ALIGN exists for performance reasons, not to provide > dma guarantees as kmalloc(). So I'd say users of kmem_cache_create() > would have to do their own rounding - you mentioned > dma_get_cache_alignment()? And there's an align parameter too when > creating caches. I just checked and the align parameter only ensures the start of the buffer, the redzone start is not aligned. Anyway, as in the other subthread with Petr, I think most architectures would benefit from an update to the DMA cache maintenance to avoid corrupting the redzone. -- Catalin