Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4456870rwb; Sat, 21 Jan 2023 12:20:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsI3CcjBK5Pda/yP8dA6SlZp94UlgdXgVuPcjQLknJh7PICv9I0Z/M0+hJvA8L2sjIh5vpa X-Received: by 2002:a05:6a20:8f1a:b0:b6:1b23:e9ec with SMTP id b26-20020a056a208f1a00b000b61b23e9ecmr22930949pzk.29.1674332429590; Sat, 21 Jan 2023 12:20:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674332429; cv=none; d=google.com; s=arc-20160816; b=brNmIOBbL/D3vXN/TjX+OuA0zo45RnXJwTAWtUYSf0OXgW91gXhjGlRS0nesN1edtz Gkfs9NQ0G6hN66YR5JuJ2kQKB0agPGxcyQJpy/OcpxmlzRStGXyOfIfpjYpJ4ehEq1eN R77eWbAg+3EZ5lwpMjS38zPkY2cK0hJlG5a6XS1DMyBQxNn6KCQxp7o054eGOC90ef91 OrQd4cDb7iHE/m89CfC6jLDuXJd/0uK4MQcQyBYR7MAcJyA5HqCArPldTYClsJcHufM6 mUZHLt+/QTt5p3//GJPpzuiXdVGBlUTPF+YuCJEwtp6gdlRizPpogIyh8NPG4tHrOFoL SMqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=+7vn6FJZBW3ikBxFe0qPdDLONLsi4C2GNXv/wpFG9m8=; b=f0MU0JEqhx8APjCFJgWwrt2O+tw99s/V/t/1c2D9qtbgAZsPbdb7dfq7Sr2WqQklYS 6AZtiCZ9KXGEFMrnKVN9byCDxz0OOaE/xn61jvyqkE3I1XQqpN02pwrmjzgtdhGHJ6FW TTeOpCzAIVyu27oxJ36ShZfVRKkvoJN5eeZUWl/marLvx8YJMGbymRl3s3ZImoip/cjW 9S2LsgkLsgUoNw2uWwPFKAZ7yuzegHexerVOKoytJRjbdBNH5yY24JvBwoafswT2Su3A AEjK3DS+HMz1azCVaxkMdCxyPQe6nlHOGnhkYAs1moiruY4tjbNBBMW4imT9TzTD0DK5 /8Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b=EeObT9K0; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=cTR6G7Gx; 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 b37-20020a631b25000000b004965dbd5c9esi44280563pgb.822.2023.01.21.12.20.23; Sat, 21 Jan 2023 12:20:29 -0800 (PST) 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=@arndb.de header.s=fm2 header.b=EeObT9K0; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=cTR6G7Gx; 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 S229790AbjAUTat (ORCPT + 50 others); Sat, 21 Jan 2023 14:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjAUTas (ORCPT ); Sat, 21 Jan 2023 14:30:48 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44C4697; Sat, 21 Jan 2023 11:30:47 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id E1E865C0107; Sat, 21 Jan 2023 14:30:44 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Sat, 21 Jan 2023 14:30:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1674329444; x=1674415844; bh=+7vn6FJZBW 3ikBxFe0qPdDLONLsi4C2GNXv/wpFG9m8=; b=EeObT9K0sJ+FiQXaSyOV5ga30V vMENd25mxMVpvuqYXP47vEmUcqJ99KsL6t+jqXWWzOGGLK3D4c/P0q7R2wuvQhxS /Fpi6CJlO7JZXJjV91rA33MYhRyBo9JD36h8kmluTE7BFX3cOIjN+TUuaX+QV+nm v/ARpRV0JeGZBNZwvKAIvUXgfUEdIhTwhMgHU9zT+G9OAbedXljWSZzBJLMdGOr7 hbrlQLKBUkThiq7CNb4Ilu4xTF1EKFYvIIa0ATWGQ8zP24ddyZFw+pGe9eV6JQuw LOlR7Dtte5BgL8lCm3okHwbG1xSFpwsQhm9WM3vHsQPxu8c+DCZnhACQeHuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1674329444; x=1674415844; bh=+7vn6FJZBW3ikBxFe0qPdDLONLsi 4C2GNXv/wpFG9m8=; b=cTR6G7GxX8c4+1ur1pwyc3RbXEnxrgZ8WXRA0PWJtdUS YyC72cTt8LmfsOI9awxVYbm0TXCfNQHKuKjNQ5dEewa7VP1PZ/XgIKiTUvqfJCPm XFAn2eTyr80TEoqMnIpCPIBnTvy+zuKZTb8p/ZukSpVeNlnmPNFVfspievqoz09V qFTKcyuBTPqy61mIH74DEwH52xSnXxm4FgjF1F8Z+j0LctAS7zeUvxKP6hOoFRBd PqVXuLizjSMlKzNTX9YWl0R1LgIuxix9fW22FFr+U2Ueje9sjlOEbXnhHFP0HP9H /g+niDqrLn/Rrarg94OzjmzuGgNHN4Ly5mpgqC447g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddugedguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrg htthgvrhhnpeffheeugeetiefhgeethfejgfdtuefggeejleehjeeutefhfeeggefhkedt keetffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grrhhnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id DC75DB60086; Sat, 21 Jan 2023 14:30:42 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-85-gd6d859e0cf-fm-20230116.001-gd6d859e0 Mime-Version: 1.0 Message-Id: <6a64b0b5-0ebc-43a5-a3d8-483a845a0b5e@app.fastmail.com> In-Reply-To: <20230121143733.GA7415@lst.de> References: <20230106185526.260163-2-prabhakar.mahadev-lad.rj@bp.renesas.com> <6f7d06ef-d74d-4dfc-9b77-6ae83e0d7816@app.fastmail.com> <9017adf0-acd4-4c43-8aea-3579b214b477@app.fastmail.com> <45d6eb0c-cbe3-4a83-aa12-3483638473ae@app.fastmail.com> <20230110070144.GG10289@lst.de> <02988e70-b099-46fd-b260-2d537c50543a@app.fastmail.com> <20230113054807.GA23179@lst.de> <20230121143733.GA7415@lst.de> Date: Sat, 21 Jan 2023 20:30:23 +0100 From: "Arnd Bergmann" To: "Christoph Hellwig" Cc: Prabhakar , "Conor.Dooley" , "Geert Uytterhoeven" , =?UTF-8?Q?Heiko_St=C3=BCbner?= , guoren , "Andrew Jones" , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "open list:RISC-V ARCHITECTURE" , "open list" , devicetree@vger.kernel.org, Linux-Renesas , "Lad, Prabhakar" , "Philipp Tomsich" , "Nathan Chancellor" , "Atish Patra" , "Anup Patel" , "Tsukasa OI" , "Jisheng Zhang" , "Mayuresh Chitale" , "Will Deacon" Subject: Re: [RFC PATCH v6 1/6] riscv: mm: dma-noncoherent: Switch using function pointers for cache management Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED 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 Sat, Jan 21, 2023, at 15:37, Christoph Hellwig wrote: > On Fri, Jan 20, 2023 at 06:04:37PM +0100, Arnd Bergmann wrote: >> Having looked at this some more, I see that the powerpc >> version is a bit problematic here as well: this one >> flushes the partial cache lines before and after the >> DMA transfer, while only invalidating the full >> cache lines. > > That feels really odd, and might be worth a bug report to the > PPC maintainers. Right, my first step would be to change all of the current outliers to use the same set of operations where possible. >> Aside from the question for how to handle flush vs invalidate >> on DMA_FROM_DEVICE, I'm still trying to figure out how to >> best handle highmem with architecture specific cache management >> operations. The easy approach would be to leave that up >> to the architecture, passing only a physical address to >> the flush function. > > I suspect that is a good enough first step. Especially as I remember > that some architectures have physical address based cache management > anyway (unless we removed them in the meantime). ok >> A nicer interface might be to move the >> loop over highmem pages out into common code, flush >> lowmem pages by virtual addresss, and have a separate >> callback for highmem pages that takes a page pointer, >> like > > I'd rather avoid multiple callbacks if we can. But maybe solve > the simple problem first and just pass the paddr and then > iterate from there. Ok, fair enough. This means we can't easily put the kmap_atomic() into common code for highmem, though the per-page loop would still work. >> struct dma_cache_ops { >> void (*dma_cache_wback_inv)(void *start, unsigned long sz); >> void (*dma_cache_inv)(void *start, unsigned long sz); >> void (*dma_cache_wback)(void *start, unsigned long sz); >> #ifdef CONFIG_HIGHMEM >> void (*dma_cache_wback_inv_high_page)(struct page *, size_t start, unsigned long sz); >> void (*dma_cache_inv_high_page)(struct page *, size_t start, unsigned long sz); >> void (*dma_cache_wback_high_page)(struct page *, size_t start, unsigned long sz); > > Btw, I really don't think these should be indirect calls. > For sane architectures there should be exactly one way to call them, > and the onces that have different implementations really should be > using alternatives instead of expensive indirect calls. I was thinking of using STATIC_CALL() as an optimization here, which I find easier to read and understand than alternatives. One advantage here is that this allows the actual cache operations to be declared locally in the architecture without letting drivers call them, but still update the common code to work without indirect branches. The main downside is that this is currently only optimized on powerpc and x86, both of which don't actually need CPU specific callbacks. ARC, ARM, and MIPS on the other hand already have indirect function pointers, RISC-V would likely benefit the most from either alternatives or static_call, as it already uses alternatives and has one implementation that is clearly preferred over the others. Arnd