Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6143607iog; Thu, 23 Jun 2022 12:15:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1udpoM5GavQAWTXy6+m1afZa/WTG8X3BxWNmtuPa/s5W6XZ/AXjns00YP8uMrzvGl+Rda+I X-Received: by 2002:a17:90b:390e:b0:1ed:1133:8711 with SMTP id ob14-20020a17090b390e00b001ed11338711mr3510617pjb.90.1656011702909; Thu, 23 Jun 2022 12:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011702; cv=none; d=google.com; s=arc-20160816; b=ChbHHjrqvtYlrZUXJoURE/+xE+Df8/YbNxRf1MdIA8Q8YFoixwg2ytToCQ/UBXvWAV zj99FpoW4D/FxYWm+4+72T8sYbZ3YGaj0EMXJsAnOQ3W9Kpa/tLqRxYlww9Z6yOmpV/H ibaN4FguFzPTjnLRQHI/bUHQKoy7qVOK9AlfU05mb2nHoYzHiUyZ38oMcoHdJgZnVir3 L9icDT2Hsw3KuZ4kN7SzGw5VCdN/XB5gWdEz11/a/R9qMva4w9oFsYD/JZhMtYkyf/Z5 ziZmIJ3uGEn4SQ4LHJIEaEmeYM410EAsT4j7J5XnDI6v4XrrS7i7Qn7xaW4t2z/TGuPJ GcRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QsTkG4SA1dX2egJPM7vxVHXIltBNCM6Y44Ng7x3JxqY=; b=ocTMnr8iCKgPrRXygSFLa9/PIbTzfv9B+RaoD28sgNs9LCWJEjrZy0KhUycogFMnvy wo2fGE436kIqDIi1ee6c23LZThK9jHTLQif1Cbx8xQ8c6XgPPh+Z4wfTe3G/fxN2byTW xKVqhfvvQ+mtm4pQ+eDRsThMwaYeV+3jn7VbRBT7uuUWYlgBjvHNo4RT1D+vTwVX15fw hqn752b9gMgxC8Ud87Z4WaDvt/xkSWV1anfhvZh38zEmA3felzT0G/9kMYB95p8y95+x NmHbB5olBe1LDXJc2rtGASe5bzDNrymn8GCoJSXHVN5t5pt00Fo8Fays9+Ie6tMLYhJp 6UWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dzWIarz2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a63ef09000000b00408cab62ca2si28035102pgh.152.2022.06.23.12.14.51; Thu, 23 Jun 2022 12:15:02 -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=@linuxfoundation.org header.s=korg header.b=dzWIarz2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235253AbiFWRwH (ORCPT + 99 others); Thu, 23 Jun 2022 13:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234794AbiFWRvt (ORCPT ); Thu, 23 Jun 2022 13:51:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E7129916C; Thu, 23 Jun 2022 10:12:28 -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 1807CB82497; Thu, 23 Jun 2022 17:12:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6014DC3411B; Thu, 23 Jun 2022 17:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004340; bh=eu8taC3+k0XkN2TBzLNscttMDmRGc+9CZ71xf50kf/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzWIarz2lqMdYHPl5BneNmdhzPgvRZe9Ab544mrZa/TcBFx6DSaWHqBZ7CoTF/G8d ibFmuZ61FGk+StazFPdRr55CNLzbWB2/2llywjza1Abk7mox2czd9zjbE7jFs9s8Qy 5Amnbgoaqdp45vYWXMBjW4WTL3reMT2oRdU/uAK8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Christoph Hellwig , Robin Murphy , Russell King , Will Deacon , Catalin Marinas Subject: [PATCH 5.15 9/9] arm64: mm: Dont invalidate FROM_DEVICE buffers at start of DMA transfer Date: Thu, 23 Jun 2022 18:44:52 +0200 Message-Id: <20220623164322.563116261@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164322.288837280@linuxfoundation.org> References: <20220623164322.288837280@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Will Deacon commit c50f11c6196f45c92ca48b16a5071615d4ae0572 upstream. 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: Robin Murphy Cc: Russell King Cc: Link: https://lore.kernel.org/r/20220606152150.GA31568@willie-the-truck Signed-off-by: Will Deacon Reviewed-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20220610151228.4562-2-will@kernel.org Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/mm/cache.S | 2 -- 1 file changed, 2 deletions(-) --- a/arch/arm64/mm/cache.S +++ b/arch/arm64/mm/cache.S @@ -231,8 +231,6 @@ SYM_FUNC_END_PI(__dma_flush_area) */ SYM_FUNC_START_PI(__dma_map_area) add x1, x0, x1 - cmp w2, #DMA_FROM_DEVICE - b.eq __dma_inv_area b __dma_clean_area SYM_FUNC_END_PI(__dma_map_area)