Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1610933pxb; Thu, 14 Apr 2022 09:53:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4TdgEX+7yiz4rmKNdBefma/yznkQbv2CFvJeeDTFgqe/mQ22MqVpLAZt9mzu50T+y7j6U X-Received: by 2002:a17:90a:e295:b0:1cb:8b15:1232 with SMTP id d21-20020a17090ae29500b001cb8b151232mr5300029pjz.172.1649955185223; Thu, 14 Apr 2022 09:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649955185; cv=none; d=google.com; s=arc-20160816; b=Ya7tGtTw1GeUnsOqmEz0r/w9bz1B3FgU6X45W/42KGSDNghOgD97VvUdN8FxBHenPh wfbCMLVeH6TyrNekiuJjvrUcV3qDAZwf5invimRyL1OLtMYYxkIGKQzz6x2FDOeESnmj 4NvFQvq3ahe3uKAC+VJ9fn17vvh0sO1TKc6CcS9FFvwU+/FBjsj3MyxmM7Wdhalz5ery CEsbBQd4JXcxezGVOJ5vNMgSWRhZV83vaN1jj0Q6Uqdtu2r2D6jWNJ3T0Yxm0XkH902W U30/KPNBQDRRkSP3NrvqQow9cI5grNaGsfBSvmIVcvYEivvxAXcF5D6rmyXfVItEUKK/ gagw== 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=q/DBgAkv4OQEV7GLgkTJlWv+q3kLHi60Bd65fMkiVGg=; b=LQ3fZJcagiQ/tTzQmNamirzvrpYZeAPVnajz088tI6vLbZtyelzB18aQYLbz8CfrXI /OlQXt8NUKKGSYFg1yXsUJvXrHU/WbA0fGmEl/Het+5ighE7yB6NiduMbT1uVP0lxrUI Iwi06aZvMJ4OvjfCdcXu8+f/jSMw9ZZQHOgxvxmca7J8Qy9f1tXa1KlZQxKtxhWup15q 8q4vJCAc0zrwnY7Fm85rmbQkG/1fQJOxQlVU/eUn5TR9fm/1qcJ12fFHb+DCW9pzfJR6 DpAH19yXt48uthcNjwQIwlSzbFcShuS9XFJAIT4TGbIyvyOcK0dKtQo1ZuEddYkURbgr FmvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dxlaLoqs; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 61-20020a17090a0fc300b001c7bfb058absi2195328pjz.99.2022.04.14.09.52.50; Thu, 14 Apr 2022 09:53:05 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dxlaLoqs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233005AbiDMT4w (ORCPT + 99 others); Wed, 13 Apr 2022 15:56:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238606AbiDMT4h (ORCPT ); Wed, 13 Apr 2022 15:56:37 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 783437B563 for ; Wed, 13 Apr 2022 12:53:46 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id u19so5458414lff.4 for ; Wed, 13 Apr 2022 12:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=q/DBgAkv4OQEV7GLgkTJlWv+q3kLHi60Bd65fMkiVGg=; b=dxlaLoqslihL0u5ALJQQNQLkyAJAatT6/BflQltbOe8/sf91WvaHNbi7GO1b9Fv7ym eGx41ozm92iUi2qBs53105A6bIUDq03qjk/3IVzSMTq9V8X0glNvjMmX3ZXtjpTtmSaa IGbV8DgLGUxm4m7Y3DonNhNx06/iV90eFeUS0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=q/DBgAkv4OQEV7GLgkTJlWv+q3kLHi60Bd65fMkiVGg=; b=b2VACvzvZQNsfz0TnXAzK14/tL2m8a00ckmKGNN3CHex6u4QX0SEecSSqXwJYjPqQX FYW5hDxJpkfnnu8JlpNqPaC3D9HCa1H3zK6cBhfSMuen1Na4npCD5kl0gaAcFhlk4S1p 8Eqj+EzlYubbow7qH/bO2R3wVGAZzuhLEvNlo68QhtH/JSJFSuGuJm3zn70mbt0jKRJn K+6HBnW+t+gRfCDlISLzXEXiv79sJ6glB5bLIUm/MBZoxMMaNwqwxKSlDKMiOjIxy8Ke PJTWqYd3lM4yra0A/epsi3p6ggxJOl1uGnle2hZONaB4JVH+E37bKVjwMbrdaqQQPwxh f97w== X-Gm-Message-State: AOAM530cVY85/Q4SFLAvXEvCjQHLgMg+qQyG9VHQ9MlEE1hdH8IbA9Qj nP9aoVuOT7N8waZ89JfGIeB382++XvktiqJW X-Received: by 2002:a05:6512:3d08:b0:46b:a03f:6896 with SMTP id d8-20020a0565123d0800b0046ba03f6896mr13768385lfv.120.1649879624522; Wed, 13 Apr 2022 12:53:44 -0700 (PDT) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com. [209.85.167.42]) by smtp.gmail.com with ESMTPSA id q14-20020a0565123a8e00b0044a7b26ae1dsm4232016lfu.109.2022.04.13.12.53.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Apr 2022 12:53:41 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id k5so5434498lfg.9 for ; Wed, 13 Apr 2022 12:53:40 -0700 (PDT) X-Received: by 2002:ac2:4203:0:b0:448:8053:d402 with SMTP id y3-20020ac24203000000b004488053d402mr28805493lfh.687.1649879620574; Wed, 13 Apr 2022 12:53:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Wed, 13 Apr 2022 09:53:24 -1000 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: Ard Biesheuvel , Herbert Xu , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , 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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Tue, Apr 12, 2022 at 10:47 PM Catalin Marinas wrote: > > I agree. There is also an implicit expectation that the DMA API works on > kmalloc'ed buffers and that's what ARCH_DMA_MINALIGN is for (and the > dynamic arch_kmalloc_minalign() in this series). But the key point is > that the driver doesn't need to know the CPU cache topology, coherency, > the DMA API and kmalloc() take care of these. Honestly, I think it would probably be worth discussing the "kmalloc DMA alignment" issues. 99.9% of kmalloc users don't want to do DMA. And there's actually a fair amount of small kmalloc for random stuff. Right now on my laptop, I have kmalloc-8 16907 18432 8 512 1 : ... according to slabinfo, so almost 17 _thousand_ allocations of 8 bytes. It's all kinds of sad if those allocations need to be 64 bytes in size just because of some silly DMA alignment issue, when none of them want it. Yeah, yeah, wasting a megabyte of memory is "just a megabyte" these days. Which is crazy. It's literally memory that could have been used for something much more useful than just pure and utter waste. I think we could and should just say "people who actually require DMA accesses should say so at kmalloc time". We literally have that GFP_DMA and ZOME_DMA for various historical reasons, so we've been able to do that before. No, that historical GFP_DMA isn't what arm64 wants - it's the old crazy "legacy 16MB DMA" thing that ISA DMA used to have. But the basic issue was true then, and is true now - DMA allocations are fairly special, and should not be that hard to just mark as such. We could add a trivial wrapper function like static void *dma_kmalloc(size_t size) { return kmalloc(size | (ARCH_DMA_MINALIGN-1); } which now means that the size argument is guaranteed to be big enough (not not overflow to zero) that you get that aligned memory allocation. We could perhaps even have other special rules. Including really specific ones, like saying - allocations smaller than 32 bytes are not DMA coherent, because we pack them which would allow those small allocations to not pointlessly waste memory. I dunno. But it's ridiculous that arm64 wastes so much memory when it's approximately never needed. Linus