Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp853161pxb; Fri, 22 Apr 2022 12:38:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcUNX0E1z6NyAgpTPmM+ZqnqmcVFE64UDbAF0XSfni0Txpg4dtMSgQl27JEix4kA8RuT4x X-Received: by 2002:a63:81c3:0:b0:3aa:93f4:2887 with SMTP id t186-20020a6381c3000000b003aa93f42887mr5255888pgd.213.1650656332985; Fri, 22 Apr 2022 12:38:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650656332; cv=none; d=google.com; s=arc-20160816; b=ujYdkYeLFiAVoCMbvz3fz2904s/59vOklzBLU7Q7hK9Ea/3KlMCN/31OVC9vXouQ81 JzZPaznw2uVFloSljPZWIRjF4I/0TfHjxEPbV8HW/u1T5gY4akVpYLHq4f0t6EPYmCgS GtIzxbklYuE6f4gBsiCnpR8cTq6HL6TSo/W8f6RDQKZp3TvejPwalzCTjWVwtM4jrjPN qNUjMaBOjRxv7LICV8Mz+BESf9FD0ZZhsRCtC3xcflHiBJODM0mEhIn42zdYJ+wuIgqB tUeOF9/3BiKaf2guxDDvg9jpmtjIi4ww+X6a5JIhRhGWZxWvEtqT4d+bhcQPwQQ0zj4N ieXA== 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; bh=LJQG4WCOmu1nKF8VJIsT7aXzwO9UMNuxUauJJkSz2H8=; b=AHoA94n/seF8XlvzglCWkK7KT030xtMd0cGTXfPIJ+me7JdwBV/cVj7zkqmRz8m4ms 0AMZV4LJt5hAGMo/DKSHfPJFNy50VaJKQ3WPbqsQgYSLqwqtxea0XcBDtRvdZ/EwfHAi jGxZjN1D6muHCth2KGOKF+i1hKqFmohllWsDnTafjQY8pDiEKvJbWJLFdnUrdFnyt6Dw leEYY3zT2WyA5y7eKgdS8bzWMxxAqrpFltnMJbZd0UbrUL9bSB2597vCeQ2qJBq7Pn0a jY9aJav2s8b22YeHK+bK/V2rwM0jJHUDzPlBEajEN5b01OfzpEXUaTUuvYd4MRYRccJw sMtw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u10-20020a056a00098a00b0050604ac89e3si9746695pfg.345.2022.04.22.12.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:38:52 -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; 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 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F2900162F13; Fri, 22 Apr 2022 11:44:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384516AbiDUMbz (ORCPT + 99 others); Thu, 21 Apr 2022 08:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238064AbiDUMbx (ORCPT ); Thu, 21 Apr 2022 08:31:53 -0400 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF90830F5F for ; Thu, 21 Apr 2022 05:29:03 -0700 (PDT) Received: from mail-wr1-f46.google.com ([209.85.221.46]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.113]) with ESMTPSA (Nemesis) id 1Mz9d7-1o3sCr0PUh-00wFuh for ; Thu, 21 Apr 2022 14:29:02 +0200 Received: by mail-wr1-f46.google.com with SMTP id c10so6497701wrb.1 for ; Thu, 21 Apr 2022 05:29:02 -0700 (PDT) X-Gm-Message-State: AOAM5303eIhiHW2OXcNvzULmxK1/MO2JJpDPRHDIOxH7Z4J8lDj+5por ZlA1N/FssBU9dPTeriklK9O5uPKBSxbPFqtIvCU= X-Received: by 2002:a5d:6da5:0:b0:20a:8805:6988 with SMTP id u5-20020a5d6da5000000b0020a88056988mr17868464wrs.317.1650544141749; Thu, 21 Apr 2022 05:29:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Thu, 21 Apr 2022 14:28:45 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN To: Catalin Marinas Cc: Christoph Hellwig , Arnd Bergmann , Ard Biesheuvel , Herbert Xu , Will Deacon , Marc Zyngier , 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-Provags-ID: V03:K1:XTyVPEm3RsEN9JtE8woFm8LpifiPwRnHjaL++GMBK3CPFEt8qv4 yt8D8LEzYWO10ceT9RaimWtbWGQGyN1fqBZmEU+Thg4nm48MD4Csty9R68pclElugMaRdN6 mnbjghDgd+7jXCiv99p1mbleZt0+DPtFYmv92ai1aojcOEs64agfyWlO33OZOoZuV2OBJiR 838Nz7A71YTlEuuAgiIjA== X-UI-Out-Filterresults: notjunk:1;V03:K0:/4hb8++/ZaA=:xpqKLOkTxF0CERdiBM78jf b/qVe5maEnBMuwmSTtg78X0RKh6YF0cDoRElJmTHhGyqTlNiHM0auWTrgzS/IGMT6Ik78xPrr d30Xh+37YglrgoTQCn5lGnzRT93iMhD/FxhMdvyDD38FvggidlKpJQSerpXpxyS5YDdmN1IPU DSELY2AVX9YrxjbuG3tOhlWeC0Js2Nac8+DAmIKAemjxqH24eCGns8UkvO2O36B6FcWikTL4C E/8hdDh8T7OkhGvUiA3PRGzZseHpO1Zp0donPISqKUc2IU99yJiTtT9pc5nQXpkyDxgHZ2wnr Iztp2gJKgHiJBF+lpw7xTfRV3bF9NDVI4bk8qmqrlzEnGhS+4d0B5CoMg0MDfcI4AtYKTMMPE /spy/rJ9OeOP8vcv9XwrarnOGuzL5LSqEgqmYWIT2GQBe2sIB3XaQLJTuM+FwiznTeOmQ//4s zKN2k0jwMmq3doXQIBTW5eBRnVVW8Ru6V8xopZqO15oKi0Y4WxbbzqISxXB/TBfa0WnCBOSgm GoUvaHYi8NctKwFn2t/Z/0uHyD7jpNAHMEk+wkEsSGLLLJKzKIcc2iL64L2DTKhEJ0zjPxM6M R+X7z3Uq8dKjxBb9eDN1gLhgbbmbnE1yVrM8BJKG+oNVBIJ82bVgsHt+x0n8SCG4e/LaQVNfn zEEHNM7rA6xG5sPVuM8FD7ssM118/2qH5j6dTCDoTPEd9LnxC6aEwmPHXIt1kZ3xQKgpIgydz 1CbUF2j+ttYRQ5uINHLXQN52kk1f9/SNkleyh7ayCBCIHa8nP0O8GV81OCe7pVatMXjaX8rjk FlpxWnZBVjjNATrlfo3p05g+wdLoBQiMfO4Tr/y999sSUbCr5k= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 Thu, Apr 21, 2022 at 1:06 PM Catalin Marinas wrote: > > On Thu, Apr 21, 2022 at 12:20:22AM -0700, Christoph Hellwig wrote: > > Btw, there is another option: Most real systems already require having > > swiotlb to bounce buffer in some cases. We could simply force bounce > > buffering in the dma mapping code for too small or not properly aligned > > transfers and just decrease the dma alignment. > > We can force bounce if size is small but checking the alignment is > trickier. Normally the beginning of the buffer is aligned but the end is > at some sizeof() distance. We need to know whether the end is in a > kmalloc-128 cache and that requires reaching out to the slab internals. > That's doable and not expensive but it needs to be done for every small > size getting to the DMA API, something like (for mm/slub.c): > > folio = virt_to_folio(x); > slab = folio_slab(folio); > if (slab->slab_cache->align < ARCH_DMA_MINALIGN) > ... bounce ... > > (and a bit different for mm/slab.c) I think the decision to bounce or not can be based on the actual cache line size at runtime, so most commonly 64 bytes on arm64, even though the compile-time limit is 128 bytes. We also know that larger slabs are all cacheline aligned, so simply comparing the transfer size is enough to rule out most, in this case any transfer larger than 96 bytes must come from the kmalloc-128 or larger cache, so that works like before. For transfers <=96 bytes, the possibilities are: 1.kmalloc-32 or smaller, always needs to bounce 2. kmalloc-96, but at least one byte in partial cache line, need to bounce 3. kmalloc-64, may skip the bounce. 4. kmalloc-128 or larger, or not a slab cache but a partial transfer, may skip the bounce. I would guess that the first case is the most common here, so unless bouncing one or two cache lines is extremely expensive, I don't expect it to be worth optimizing for the latter two cases. Arnd