From patchwork Fri Jun 10 15:12:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12877699 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 07CF2C43334 for ; Fri, 10 Jun 2022 15:14:06 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YjJ4py8vM5C6BicF+20LAoA4eVzOaThE8cy2papmaY4=; b=JJTA0qbnGoXnsO 4jPlnBbV/14JeTKq8Hr7Qior+Rc6lnJ4vHPx1ijwX9RS+jkxtF+Bv6thdGWVZoL58sVkpWIp/1cLR QxmbXlChBUTRe2GdwJnVbJ8Hs+TpPkPPteVGxn8LYb6Re6xIp264OK+idgkAJb07Egrgser9ZVdoo ARuQDcOjpbAqEEuisnKDhMZ0feqkkptT22rUkaYbqeXVMoqLpzgY3f7PEjL7T240y6AQ4mMBNPQQv Ns/lwObR90fUsgM7TEor7tzHlMZLHLvfMqx+TmEoxg1WqCjRdp5G2HCJ4HTK5b0gn5jBjceCIGrke Ui5NVbyZT6j5Co5AtJ5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzgK0-008i8k-Np; Fri, 10 Jun 2022 15:13:12 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzgJo-008i61-Uz for linux-arm-kernel@lists.infradead.org; Fri, 10 Jun 2022 15:13:02 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 4FE7361F71; Fri, 10 Jun 2022 15:13:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 251D6C341C0; Fri, 10 Jun 2022 15:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654873979; bh=/N4kt8tL+7p6YrFOAl4Ta619t84QRyVreBncJO9IHaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oW0O7dtjGOZ4Kgw1KnlEd60hohaAmJItETFUBcdckHmjbPqJhxtit6o2ifYuWaNpL n78zcSqaSlKIyhjtEZkShLNHak5dzge+3Jc75lsVKnrAEN32kzS4XU4jiZ4FQa8ua9 mcGb/lIVtPRDAOLUo4KurOl1w9bij1U5r1UkHbWHAW7fFiFT1emFIZLp03Y36EA1Xy xbV55eJABbVxS8+qKeZlbi0M6bKbp3OBIG1ZUfkYY/b/vwnE7O1Gv7ja1cA4nfOnMv 7MmSghTa/cFEACowJkm04GWzofrZJouWTRqdae4/cLLY1vut5r5ZcJKaJgxeXdMqQH W/P5ot7rro5/w== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Ard Biesheuvel , Christoph Hellwig , Catalin Marinas , Robin Murphy , Russell King , stable@vger.kernel.org Subject: [PATCH 1/2] arm64: mm: Don't invalidate FROM_DEVICE buffers at start of DMA transfer Date: Fri, 10 Jun 2022 16:12:27 +0100 Message-Id: <20220610151228.4562-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220610151228.4562-1-will@kernel.org> References: <20220610151228.4562-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220610_081301_074657_60EFCAE6 X-CRM114-Status: GOOD ( 12.92 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Invalidating the buffer memory in arch_sync_dma_for_device() for FROM_DEVICE transfers When using the streaming DMA API to map a buffer prior to inbound non-coherent DMA (i.e. DMA_FROM_DEVICE), we invalidate any dirty CPU cachelines so that they will not be written back during the transfer and corrupt the buffer contents written by the DMA. This, however, poses two potential problems: (1) If the DMA transfer does not write to every byte in the buffer, then the unwritten bytes will contain stale data once the transfer has completed. (2) If the buffer has a virtual alias in userspace, then stale data may be visible via this alias during the period between performing the cache invalidation and the DMA writes landing in memory. Address both of these issues by cleaning (aka writing-back) the dirty lines in arch_sync_dma_for_device(DMA_FROM_DEVICE) instead of discarding them using invalidation. Cc: Ard Biesheuvel Cc: Christoph Hellwig Cc: Catalin Marinas Cc: Robin Murphy Cc: Russell King Cc: Link: https://lore.kernel.org/r/20220606152150.GA31568@willie-the-truck Signed-off-by: Will Deacon --- arch/arm64/mm/cache.S | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S index 0ea6cc25dc66..21c907987080 100644 --- a/arch/arm64/mm/cache.S +++ b/arch/arm64/mm/cache.S @@ -218,8 +218,6 @@ SYM_FUNC_ALIAS(__dma_flush_area, __pi___dma_flush_area) */ SYM_FUNC_START(__pi___dma_map_area) add x1, x0, x1 - cmp w2, #DMA_FROM_DEVICE - b.eq __pi_dcache_inval_poc b __pi_dcache_clean_poc SYM_FUNC_END(__pi___dma_map_area) SYM_FUNC_ALIAS(__dma_map_area, __pi___dma_map_area)