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 7D6D8C433EF for ; Thu, 21 Apr 2022 12:29:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0C066B0071; Thu, 21 Apr 2022 08:29:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBAA76B0073; Thu, 21 Apr 2022 08:29:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5C676B0074; Thu, 21 Apr 2022 08:29:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id B8D366B0071 for ; Thu, 21 Apr 2022 08:29:04 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8A8CC205EF for ; Thu, 21 Apr 2022 12:29:04 +0000 (UTC) X-FDA: 79380815808.05.3D4EA33 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) by imf24.hostedemail.com (Postfix) with ESMTP id 38C2018002A for ; Thu, 21 Apr 2022 12:29:02 +0000 (UTC) Received: from mail-wr1-f41.google.com ([209.85.221.41]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MPGNn-1nXHD11ru1-00PfOr for ; Thu, 21 Apr 2022 14:29:02 +0200 Received: by mail-wr1-f41.google.com with SMTP id h25so441745wrc.13 for ; Thu, 21 Apr 2022 05:29:02 -0700 (PDT) X-Gm-Message-State: AOAM532dlQ0eRO2fVK9NFY3Y3C1k6M3d7MMeKxltTMpIfnUFdKIxGc5S lGCWYUz4EmnfecfUjUiIhxvqTGPpxXzwNgkMHfM= X-Google-Smtp-Source: ABdhPJyqadYzTr9CaMW4jeErNFMhrlpnJnMzlYtnkkJzwlVSfKj0lvPip/UlnRxOq/t4hd40yydjrwOeor7u8jKdAIA= 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:r5t/J4OP23ZNhPmTzvSlkFHxTU73MC7LSGjkm9sPQ+nmxb5dApI MtLXKT0nTWcgHHHKlpcZfwFXWxO+MnabDpOfuKZraM6LBAmtb3NXfElkkStjC7NV5rkf7UX Ic3stGwSHIepM/LW0RgjPPx3DKbfhuA1yTUt/BYhk0RQo9MEgEppPgHj1mOANVFi7qqKy5E mCkWESNyhHxT0hpMrg1qQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:qDOOUgayc+4=:kEBTn10xOTPz4ncncJuXmV 1NyoodHVzFukhE8irMAHklir5tnbJZpzD69TsjyHRBvcwcmshx1cWCWpTkpgEiNPlUU47JD3i QleL4n5O8HxuIpxvlelK9bMfx+Wl13qGxNqxXLQVsCpAWUd0KtUX/mt1EMXxyeUut13Ks8qbC nrqPW3VQlTu8dj22J3HEMCMeuzzK6dfRZdHTYxBQZOvT/Yoimpms5+1wU8MhlUYupoN1wbz8L nuSMwEzbqdZmTyN0h4xL9z92jhxpKe9PS+h7+bokB1ol8RzQ2JmojCjvl3QBF/f5EK/o354RU dt4oPP9V+g09kAd7gNDB/YN05nkd+hLszcI7OTU5UtJnBnjcrk0CHSb6kmGuW/HLHOWOxaVmK qyA7hrlPBKxewxJFr0JdZf21M64+ZjzI14jk64GNwb1qwMOyLnDzCL55ZLXapAgjrerDU76FZ ZIP8WoJP0aq7OSug8Nxrl6FZf5OQljC/pNOU2PpUUCGZmFHruqBtz9ICK2zX1o2Q2cW3Jq/pj RRJKxZzwWZtgQeAXzHRI2yZv8h7lahdYmWyDAw48KTvGHup0fSL2tU/yiWcUjE2MGGQQ3GNtt TLs/RhoqqsqHs5FdamW9lxN+Xt0w3ikfXD8REZHEF63aFnC4Wk8WzL53f1pHyuwe97qYZQeqq NpcHejT4pywEWO2ezCSqZFjpQ8liyH63XDFKW+WsM2JYmWTTBj/99nx4gDWXrJxUY+EQmVntr 5ih6tGfOcCQPyopTbibZTIjV84kzaap5hsHcsdFmiqRzsLZeqbCvNqAnV2FHp9vP4I5oTwdiG dZRI+03ncPylnMrgClqozc+8+fEWWqmBDeryvRikAVojrW5s+Q= X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 38C2018002A X-Stat-Signature: 1843zkfr4bhj5fjpykbwui7dpwwrsubb Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=none (imf24.hostedemail.com: domain of arnd@arndb.de has no SPF policy when checking 217.72.192.74) smtp.mailfrom=arnd@arndb.de X-HE-Tag: 1650544142-541712 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 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