Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3614140rwi; Sun, 16 Oct 2022 14:45:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7jDjd25VK7WUbKhD4K/P7gY+ojvUFNKf6Verr7YAYcIblXd/HFVqJ0do72WMGre6AVVi/E X-Received: by 2002:a17:90a:c782:b0:202:c73e:5488 with SMTP id gn2-20020a17090ac78200b00202c73e5488mr29121780pjb.202.1665956757417; Sun, 16 Oct 2022 14:45:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665956757; cv=none; d=google.com; s=arc-20160816; b=J8ShQsPNJhtiaKSnF+DyB5xq6yky2LB2jWaizW7NwpUCTghKAJnfUvuJ7g9aHnG1vm DwLQZ7Lmj4L8A2GcvhdGqyhyn8+BVhZxak5VItVE7AGSc+ejVsF9OeVsKCAWxmAL0eNr ogoNBuKorVmuD+pTWHj9iCz445WqU691vdSTAk7uODrIJmjsVfvt3EFjJ1QvdBJRKvm4 QKb6d+59saZ3zj2Avc7pVDIMMj5aehh8m4McO4PNJ4cWacBU6Wt+mCheiLID+qjsXBW7 Xry9onwMVJEabzpDbV3lz046iGOFVb1l47LaLBrUTD8dgg5tZUv9C9LN+M52g0yKCyuE hxWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=q0e6wRiWYtxNrMSKQdHqBCY+m8ww2a8PbforbV0yOtg=; b=kvVOEpg3DE2/Z/ZKTTkS86xE/koW/Ad3k6Y1ra/zdphlhU4td+hph7dzHw5Q2+VAMN +BkIaU7MLOcR41S137M5lcP4vYQojlSlTNPKa6M5fp8CXpO3wdSl2ye+Az69Np9daDPD wxy3sugmj7drSfjcvvUfv/Hs0FposKA/VzJrx3N4x+TD2QHFMuZsiwxj1dWLO5N4wYlt Fkn9TSL9hnmX4zcwvyDfHBjpMMf9dJy1+rtfP/Fm51tTSxrBNiooCwB0lPRBtaI0nfcR 23aFhNWxtALvo7cyKGCRvikjg7zAL2bG4tTF1mm6k7/DxK7RysLyBiNJi5Jr9yRw5ncV 6+4g== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a170903234d00b0017f685b47b8si10894841plh.151.2022.10.16.14.45.43; Sun, 16 Oct 2022 14:45:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJPViA (ORCPT + 99 others); Sun, 16 Oct 2022 17:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiJPVh6 (ORCPT ); Sun, 16 Oct 2022 17:37:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D2830F66 for ; Sun, 16 Oct 2022 14:37:57 -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 ams.source.kernel.org (Postfix) with ESMTPS id 90AA7B80D54 for ; Sun, 16 Oct 2022 21:37:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85814C433C1; Sun, 16 Oct 2022 21:37:52 +0000 (UTC) Date: Sun, 16 Oct 2022 22:37:48 +0100 From: Catalin Marinas To: Linus Torvalds Cc: Saravana Kannan , Isaac Manjarres , Herbert Xu , Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , kernel-team@android.com Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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, Oct 14, 2022 at 01:44:25PM -0700, Linus Torvalds wrote: > On Fri, Oct 14, 2022 at 1:24 PM Saravana Kannan wrote: > > Agreed. Even allowing a 64-byte kmalloc cache on a system with a > > 64-byte cacheline size saves quite a bit of memory. > > Well, the *really* trivial thing to do is to just say "if the platform > is DMA coherent, just allow any size kmalloc cache". And just > consciously leave the broken garbage behind. The problem is we don't have a reliable way to tell whether the platform is DMA-coherent. The CPU IDs don't really say much and in most cases it's a property of the interconnect/bus and device. We describe the DMA coherency in DT or ACPI and the latter is somewhat better as it assumes coherent by default. But for DT, not having a 'dma-coherent' property means non-coherent DMA (or no DMA at all). We can't even tell whether the device is going to do any DMA, arch_setup_dma_ops() is called even for devices like the PMU. We could look into defining new properties (e.g. "no-dma") and adjust the DTs but we may also have late probed devices, long after the slab allocator was initialised. A big 'dma-coherent' property on the top node may work but most Android systems won't benefit from this (your laptop may, I haven't checked). I think the best bet is still either (a) bounce for small sizes or (b) a new GFP_NODMA/PACKED/etc. flag for the hot small allocations. (a) is somehow more universal but lots (most) Android devices are deployed with no swiotlb buffer as the vendor knows the device needs and don't need extra buffer waste. Not sure how reliable it would be to trigger another slab allocation on the dma_map_*() calls for the bounce (it may need to be GFP_ATOMIC). Option (b) looks more appealing on such systems, though a lot more churn throughout the kernel. -- Catalin