Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp29475lfe; Fri, 15 Apr 2022 17:56:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8/yBw/Wu8CnSuqgAgD09vHNEi/XQ/z7QUX5tXrRqMIU1/z/uQJ9TGK1EQJq/ogPo5oh6v X-Received: by 2002:a17:903:31c8:b0:158:d060:eab7 with SMTP id v8-20020a17090331c800b00158d060eab7mr1471705ple.5.1650070585931; Fri, 15 Apr 2022 17:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650070585; cv=none; d=google.com; s=arc-20160816; b=bDwCFCwHm220VsmZT9AqtSMTxL67Gnq0Ac5HUr3M2E4Ewh738tAxWWDK2WzgypKzKi zjlmy533UjdWQtPy6Dh8GG3q5KYagzbz+g3KhH3vsuPgq5TmgfOGUeNZYIvrM5bTtfsD Ggb4qniMnjV0X80/gsz0FcQVGikT3UvMS0vV+0G9uzLTQf8lCxsmPDGVa/2JUvu9I10L JrQiiSBFgvgyuhhxf5XjV73/+SJ4r7U3UmzlEjHiLmjhnrof2ZqYKP4kiwVd/9zFGbZR SqXILZUgKcTKAcrXzCZl1T0UWgOIppx9p7dtDzCLYlLQYz0LvT+0n4/C/EsPpPlGBb3/ UJGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ELW8Zy8lhGURF7JX3Q+WSf6wsMAwW6MYn2aD8xeZZ9Q=; b=JAV70n42oGUgele6i8V6tF3OSwtNUW8OyqhusmbceLNomvzKjuyzQoORP3FLj9h7Ki oZdSXdIYIowHeOia9i3mhREb+JXTCBqNtIi6S2eo981wbJI9/nDF5VKlaZ7DePUBa6uI E5cQZNBtJmkp0Ihr1FmF9wV69RMMcH6oRGO9CIBxZMiS7IPjyvDAn4Y6PH5ZGjD4z2I6 4HRk/Ufh9R+opjJ5loBc9w72saebg2ljdisL2c8LD39uA/xCDq6J3jTGeWqGReonykBS i/yM+nHpqhY9xThbtPZEJGokK15ffDlNkZsCz5zSKszSsRS55ZvsXiL3IGqw8sJflWuL w5jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LhNhnbeJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l11-20020a170903120b00b0015873958cc9si2919884plh.515.2022.04.15.17.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:56:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LhNhnbeJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6CD4C117CA9; Fri, 15 Apr 2022 17:42:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352656AbiDOLk7 (ORCPT + 99 others); Fri, 15 Apr 2022 07:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233670AbiDOLk4 (ORCPT ); Fri, 15 Apr 2022 07:40:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2162F5DE59 for ; Fri, 15 Apr 2022 04:38:29 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 9FEFE62291 for ; Fri, 15 Apr 2022 11:38:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00A58C385AC 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-f41.google.com with SMTP id g17-20020a9d6191000000b005e8d8583c36so5221465otk.8 for ; Fri, 15 Apr 2022 04:38:27 -0700 (PDT) X-Gm-Message-State: AOAM533JiXtBt4gU3tg45572aow06Cu8JKndck6+ayt3s/QCdibV4wbP WUbtQCahY5BcBnct7BIM0zdm0J5OErPcxHi7aAI= 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-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.