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 4D7F8C433EF for ; Fri, 15 Apr 2022 11:38:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 932566B0071; Fri, 15 Apr 2022 07:38:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0C96B0073; Fri, 15 Apr 2022 07:38:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A86C6B0074; Fri, 15 Apr 2022 07:38:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 6D03A6B0071 for ; Fri, 15 Apr 2022 07:38:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 49906801E4 for ; Fri, 15 Apr 2022 11:38:31 +0000 (UTC) X-FDA: 79358915622.12.E9A1E8B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf28.hostedemail.com (Postfix) with ESMTP id 918D5C0005 for ; Fri, 15 Apr 2022 11:38:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 42E73B827B1 for ; Fri, 15 Apr 2022 11:38:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 041DEC385AD for ; Fri, 15 Apr 2022 11:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650022708; bh=vXUC8IDY9bUnBt/qfk3ZWqIDk/HTdhBPloKaZakPo/o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LhNhnbeJ41CGuuGk/t2WMCa+Vocx8kFsV/OMhSXrfjnJNiTMpRSf7klAwBiWfG80m 03ATkfWE7BgUHVlFUa51uRWONW9q9krpd2K8t3FxW+y8agqkIoww7L4g3dWmdaAsqT qDrxd/4fHdSstYFfO3bz8+TmXHExM/h7KQLbdWdpBTwkcLx/XIjHwjpSk6lL5MJzfD wxSlinbSC3Pl0mxKF8sVF4uddfQayCLuLyFndV7PbuLKXs0aU1MpXA2nBCgEve1CYp Ty/1SoU9u134yuw7nJt3FdTk2p3FryH1pZNrV92lE+oXAtrq12g9rlklgG11gLAVwG xeE16waEt6r8w== Received: by mail-ot1-f49.google.com with SMTP id k25-20020a056830151900b005b25d8588dbso5233064otp.4 for ; Fri, 15 Apr 2022 04:38:27 -0700 (PDT) X-Gm-Message-State: AOAM533HKxRNoIkVo5FHNAwLlpy1KJ8zx/7nYw6mgO5thfdsdnB5+mjQ Atj9PcDPBKgGgxCZKMTFVcTlSLNcWp1VbjvlS28= X-Google-Smtp-Source: ABdhPJxbdPyhecm17U5r/LhiKDrO7HSSUFwbD9WNDKBQ8yyN8DJUXRbCwqgih5HaGzzy770gbFQdEBCHF2qQOkGDAO4= X-Received: by 2002:a05:6830:2e7:b0:5b2:68c1:182a with SMTP id r7-20020a05683002e700b005b268c1182amr2485815ote.71.1650022707025; Fri, 15 Apr 2022 04:38:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Fri, 15 Apr 2022 13:38:15 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN To: Herbert Xu Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 918D5C0005 X-Stat-Signature: w3hfir16ho43z1og49caxaknk46519kg Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LhNhnbeJ; spf=pass (imf28.hostedemail.com: domain of ardb@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=ardb@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-HE-Tag: 1650022710-638099 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: On Fri, 15 Apr 2022 at 12:45, Herbert Xu wrote: > > On Fri, Apr 15, 2022 at 12:22:27PM +0200, Ard Biesheuvel wrote: > > > > Subsequent objects are owned by the driver, and it is the > > responsibility of the driver not to modify the fields while it is also > > mapped for DMA (and we have had issues in the past where drivers > > violated this rule). So as long as ARCH_KMALLOC_ALIGN guarantees > > actual DMA minimum alignment for both the start and the end, we > > shouldn't need any explicit padding at the end. > > I don't understand why this is guaranteed. The driver context > size is arbitrary so it could end in the middle of a cacheline. > The slab allocator could well lay it out so that the next kmalloc > object starts right after the end of the context, in which case > they would share a cache-line. > If this is the case, things are already broken today. We never take ARCH_DMA_MINALIGN into account when adding the driver ctx size to the overall allocation size. > The next kmalloc object could be (and in fact is likely to be) > of the same type. > > Previously this wasn't possible because kmalloc guaranteed > alignment. > Either it does or it doesn't. If kmalloc() guarantees the actual DMA alignment at both ends, the situation you describe cannot occur, given that the driver's slice of the request/TFM structure would be padded up to actual DMA alignment, in spite of whether or not ARCH_DMA_MINALIGN exceeds that. So it would never share a cacheline in practice, even though they might live in the same 128 byte aligned region on a system that has a minimum DMA alignment that is lower than that. If kmalloc() does not guarantee that the end of the buffer is aligned to actual DMA alignment, things are already broken today.