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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C3C6C433F5 for ; Thu, 21 Apr 2022 13:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=inM9H618ghUBRCWkYgVJLpWw3KOnsqm+YBT75i9WWwU=; b=MHFRd8YmYtSYb5 EJjujlVpDEOlHVzBu9scoc4v+WYxZ6DmkXF4r/HFmzKx5HoQoPLtTxofleoh3F4CQWVwbpcZuBIhb 3rs4QZSH1PIYrw88mGA4v5ieJd0v4gQMV9qpX010Wh4l3iy/4S4AYuGNgTmxRW/8rQDwyndMMSaWE OYrb9asjHVSlB47sOXQvI85JWJzh944W+BYJHmqNrgSYwtavWj2nxI7EIOy7TCTB8Ue4ATgZctJad /jNPzRiZgak+bTIKLoqt1pdrt9eyzVdZB1wA/KnF7aKH80fLn40CSXVOjG2ROAq/U0pOKCIvgHeI0 GFiW5rFd2grOLN6aiJFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhWoR-00DYBR-6b; Thu, 21 Apr 2022 13:25:35 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhWoN-00DY93-5O for linux-arm-kernel@lists.infradead.org; Thu, 21 Apr 2022 13:25:32 +0000 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 91C39B82489; Thu, 21 Apr 2022 13:25:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6746C385A5; Thu, 21 Apr 2022 13:25:25 +0000 (UTC) Date: Thu, 21 Apr 2022 14:25:22 +0100 From: Catalin Marinas To: Arnd Bergmann Cc: Christoph Hellwig , 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" Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220421_062531_531264_6C077286 X-CRM114-Status: GOOD ( 32.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 21, 2022 at 02:28:45PM +0200, Arnd Bergmann wrote: > 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. There's also the case with 128-byte cache lines and kmalloc-192. > 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. I think so. If someone complains of a performance regression, we can look at optimising the bounce. I have a suspicion the cost of copying two cache lines is small compared to swiotlb_find_slots() etc. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel