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 13CF8C00140 for ; Wed, 24 Aug 2022 11:24:49 +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=OSgB46bTUWA5VRQLkDB9L3Dck+GDjiUJmXH1jb7XnlY=; b=dHJ88YITxjrwRO 8pQbiWGOWtubywPwU7VDwuu7vOJ795vOZCN8Fx36cs3QLH/319s/6ok3Wdc/ury1oBeS4b0M7mtfT 6U78GeXYcubzcIVnmscAvFOWiG+vhvlvnFJrA441kmdBSd0MtqJwzFbb0jRkJK0iPEGysnBYw0jeD +Sxe8u0OYt8a3PqcSACfMVe0A4sCCa4IHbT6OAxuCksu3SzuMM+/0DAX3sI8QJnS1pgVNoMN0KlY8 ZqOY7s1c9EnFjHJoOm5+Y1fbsMqaevt4D99hidTVCHkjizg+bLrZTq8yfRz8D23TFPyQxjc01qgM9 dJNMi/ZM7Eht+9b75z6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQoU2-00CQ8v-3P; Wed, 24 Aug 2022 11:23:42 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQoTz-00CQ7J-Jo for linux-arm-kernel@lists.infradead.org; Wed, 24 Aug 2022 11:23:41 +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 0DA93B822E4; Wed, 24 Aug 2022 11:23:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80D57C433B5; Wed, 24 Aug 2022 11:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661340216; bh=06TcaKc1LUY5asc9vvSrJk3BhKr5PNVB3L+cJBDnS2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oAD8XvKqRvKLUIPcgC0D4YCdpwV52MyCcTqfwj6rKn+zmBRYHtLoPaUiv0YivFAT+ s121f0JokScdOaz2XxIqkUa0rbLQogtJO3gFVWOTDeTUz5sEkWBwZ+7TmBQ6egEbzn 3GZmoyE1TThT8wkKzaUaxWqBJFgBn2JWxaKBTC6aW9X2PUL5K9PRvuTmO7HC7hkuER 7Z65Vor7emDkl99+8AjzERt2wXAPFBbLUD2iSP5pONcqUsbhQCKnIVdoQxPWW0lUDg b4uKWpNITYdex+AxDt2AtYO6eiFLlotH+eLX2LywMAN0322Or44KoC/isCJcaZKdfW iVMbI7rhJsubQ== Date: Wed, 24 Aug 2022 12:23:31 +0100 From: Will Deacon To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Mark Rutland , Robin Murphy , Christoph Hellwig Subject: Re: [PATCH] arm64: dma: Drop cache invalidation from arch_dma_prep_coherent() Message-ID: <20220824112331.GA18117@willie-the-truck> References: <20220823122111.17439-1-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220824_042339_970544_7058D1E7 X-CRM114-Status: GOOD ( 32.52 ) 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 Hi Ard, Cheers for having a look. On Wed, Aug 24, 2022 at 11:58:46AM +0200, Ard Biesheuvel wrote: > On Tue, 23 Aug 2022 at 14:21, Will Deacon wrote: > > > > arch_dma_prep_coherent() is called when preparing a non-cacheable region > > for a consistent DMA buffer allocation. Since the buffer pages may > > previously have been written via a cacheable mapping and consequently > > allocated as dirty cachelines, the purpose of this function is to remove > > these dirty lines from the cache, writing them back so that the > > non-coherent device is able to see them. > > > > On arm64, this operation can be achieved with a clean to the point of > > coherency; a subsequent invalidation is not required and serves little > > purpose in the presence of a cacheable alias (e.g. the linear map), > > since clean lines can be speculatively fetched back into the cache after > > the invalidation operation has completed. > > > > Relax the cache maintenance in arch_dma_prep_coherent() so that only a > > clean, and not a clean-and-invalidate operation is performed. > > > > Cc: Catalin Marinas > > Cc: Mark Rutland > > Cc: Robin Murphy > > Cc: Christoph Hellwig > > Cc: Ard Biesheuvel > > Signed-off-by: Will Deacon > > --- > > > > I'm slightly wary about this change as other architectures seem to do > > clean+invalidate here, but I'd like to hear what others think in any > > case. > > > > Assuming that the architecture never permits non-cacheable accesses to > hit in the caches [i.e., if the behavior the ARM ARM describes in > 'Behavior of caches at reset' is the only exception], As long as the allocated lines are clean, then the non-cacheable access won't hit. > then I agree that invalidation should make no difference. However, given > the fact that we are dealing with mismatched attribute mappings here, > retaining the invalidate seems like the safer bet. (IIRC, the > justification for permitting the linear map's mismatched attributes is > that we never access the region via its linear address, and so we are > unlikely to be affected by any conflicts. Purging cachelines that cover > this region seems like a sensible thing to do in that respect.) It's certainly harmless to keep the invalidation, but I also don't think it's serving any real purpose either given that the clean lines can be pulled straight back in by speculative accesses through the linear map. > Why are you proposing to change this? Some hardware folks were asking me why we had the invalidation here and then I realised that it's not necessary. An alternative to removing it would be to add a comment saying it's not needed, but it's a bit weird writing that! Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel