Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2941934iog; Mon, 20 Jun 2022 07:58:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v5tnGfayOM5x8a04VEl+JpfaoAk9Q1b1CYZ9/0Ece15ZDUPun5RWGnRMkmOhIKw9QnKM2X X-Received: by 2002:a05:6a00:2402:b0:4e1:46ca:68bd with SMTP id z2-20020a056a00240200b004e146ca68bdmr24869522pfh.70.1655737111619; Mon, 20 Jun 2022 07:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655737111; cv=none; d=google.com; s=arc-20160816; b=mYev9u+0ViS1HG5PjYCW2x7+i8NfB1gR5l5XJ9KXDj5MWxh6fcpgbeO8i4npGDmgUf s1cR9QhCfeGEbKmcWoq0x5DWSO4sS16ioagHig078urTFYJsuhDSlD/WPt+rPgeTOiuC bz5H2WBAvRBDuJ6r0Bz0fVVBvEZCc/Kj9DjAkIiVW5Sc2A6qr9T+5zhI9JueaXGEvPPt Op0dBtyMwPsGSN0Yh95o45HVl2SbBjEzUp35NAiUJPtcsCRX5MhPY3dTtmrkIBIy8jvO ursqzUGKTAoYluIvm1j+hqLd8JzneAdIX4js4RF0fNXYOCO7Tnd8JpD1C5YkAI2svFSv Ir5w== 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=uOFbzOCsJ86KTk9fk4JSjLISuG9rCuNuJ6y87lYgU9Y=; b=qTMhuTqn1tzwAjrJ/NrxhPetUtgmoYxujWCpWDx4o15jZRwPUiT6CC8j1NWdicRqtE jo7PcPeeWJY+o9Pzewr9GzNaxCygA6qgeFo5568M8nKLJBGCEx9qpIQvKUa502Nm/zha TGXt+MQA/7chsH8bjr3pg05+SlMnv3i6vOjE+RdR8KkJ0+eRhSXLmlWfOnp9y6PaCoD4 SkfQoicDNRVCd0yJM9HRv17COIoIVYK5vA0ESS/Xfu9FCtTdqTxdT8S9ecgsLRCHhbtj Em2FiMIOaObT3qqOnN9umF6YO2dT+bmRY42wMLYH5icwk69Yh2KTM4ROcpHcvS9Chdk1 SJqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sCUJGHDD; 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 g84-20020a625257000000b005251a325ea0si5673796pfb.269.2022.06.20.07.58.19; Mon, 20 Jun 2022 07:58:31 -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=sCUJGHDD; 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 S244338AbiFTNFG (ORCPT + 99 others); Mon, 20 Jun 2022 09:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244350AbiFTNDe (ORCPT ); Mon, 20 Jun 2022 09:03:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A0001E3D2; Mon, 20 Jun 2022 05:58:09 -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 81ED4B811A0; Mon, 20 Jun 2022 12:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94840C3411B; Mon, 20 Jun 2022 12:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655729887; bh=GCtSDrZL6nWMsE7xon+QL1MQ8Yl7NvnYp4rWylqCoIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sCUJGHDDK37iSZgYKphCmlX/yEf9T9faWSN0y8FjgYFPwPnzXLzx9HiwXThbH6pr1 JgZJu5sDUD6GEYks6ndhKjktxAjoMSEg19ElLllMy62/38UfVZePnwPgGWZaMw+zcj v/CNQG+i/LmYaqn+7x1Gha+AFdkrqbD0TeVj7Xzg= 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.18 106/141] arm64: mm: Dont invalidate FROM_DEVICE buffers at start of DMA transfer Date: Mon, 20 Jun 2022 14:50:44 +0200 Message-Id: <20220620124732.676698576@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124729.509745706@linuxfoundation.org> References: <20220620124729.509745706@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 @@ -218,8 +218,6 @@ SYM_FUNC_ALIAS(__dma_flush_area, __pi___ */ 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)