Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1841707rwb; Thu, 17 Nov 2022 02:54:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4BvzJJlGGaYASo61GDebzg06mSoUEW6IdJmiA+ZVeJYEG2IcaE7xtr/EcV4+dx2DFiJgnr X-Received: by 2002:a17:906:e87:b0:78d:b88f:1548 with SMTP id p7-20020a1709060e8700b0078db88f1548mr1720884ejf.221.1668682451258; Thu, 17 Nov 2022 02:54:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668682451; cv=none; d=google.com; s=arc-20160816; b=KMGtEx31j0B3fnu+3r2kpAS3crKd8AYNZXal1pKlgjSRicP9ukqJPv87JrTpXkUG+O RPeFQGTKXWFFxUwlR4rSf/7AM/fu6+m7/zWwTAXlGwMuqEE4kcASNuzuSqKberGO0nxt TEQ4LIKhxVk3fMIDAvKzYlxfvWRll9hI6C0wxLoHHARC3rnJUc7DAjlsabi+AEXny1TM Jplou9iJfGOsoJSqkK/j50yTQyyRt8nrZ9LknJidY1nm7oxz978c8bb8HXsvQWs5CVYK C+v8HW92b3NnJWNuFRilF0xoYTSHyVMsVFm/Z0k2/QIKODfSxsZwhVCeCrJ2VEJCDFWF x5DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ngYyP8OVpOqdZQIt/strMarOrpc2Oc542UdHTlMeeq0=; b=S5SyJRCMaDXXWHIdRjNM7Wv+0BNBgmHVAHhS1fx4rABV/vs5CgewAO3Hg+PX25kq8H MKd80+Uwo+j5uJ7IhH3Z1qYH1NzzmNEUb9hIY8+JoWcJsExodL4XTfzaeiS7Eex2rDRX iJFYoAxHgkD7yHKBIX48uWvPG7GJz8WPILy0B6p14ZrzyZGJ7TdgsDIV+JZRueGsELo/ 04kPZC71YWXdEVys5UJabPGbYIwu/YJNupnYIpU/M7Ie/4Hoegl0temqanIuJw0cb9Tu FNaqULM1Oh1ozoy6ng8yKCmt6oK/aeuT5INcN1y1ZY4XnDVoHJfOkzxCjSgHRH5vDlIv sXzw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xi5-20020a170906dac500b0078e176ef65csi287692ejb.723.2022.11.17.02.53.49; Thu, 17 Nov 2022 02:54:11 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239493AbiKQKXW (ORCPT + 91 others); Thu, 17 Nov 2022 05:23:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbiKQKXV (ORCPT ); Thu, 17 Nov 2022 05:23:21 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8F524D5FA for ; Thu, 17 Nov 2022 02:23:20 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0FE1913D5; Thu, 17 Nov 2022 02:23:27 -0800 (PST) Received: from [10.57.69.157] (unknown [10.57.69.157]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 396103F73B; Thu, 17 Nov 2022 02:23:19 -0800 (PST) Message-ID: Date: Thu, 17 Nov 2022 10:23:13 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [RFC PATCH] arm64: mm: Add invalidate back in arch_sync_dma_for_device when FROM_DEVICE Content-Language: en-GB To: Ard Biesheuvel , Nanyong Sun Cc: will@kernel.org, catalin.marinas@arm.com, sstabellini@kernel.org, jgross@suse.com, oleksandr_tyshchenko@epam.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, wangkefeng.wang@huawei.com References: <20221117072100.2720512-1-sunnanyong@huawei.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 2022-11-17 08:24, Ard Biesheuvel wrote: > On Thu, 17 Nov 2022 at 07:33, Nanyong Sun wrote: >> >> The commit c50f11c6196f ("arm64: mm: Don't invalidate FROM_DEVICE >> buffers at start of DMA transfer") replaces invalidate with clean >> when DMA_FROM_DEVICE, this changes the behavior of functions like >> dma_map_single() and dma_sync_single_for_device(*, *, *, DMA_FROM_DEVICE), >> then it may make some drivers works unwell because the implementation >> of these DMA APIs lose the original cache invalidation. >> >> Situation 1: > ... >> Situation 2: >> After backporting the above commit, we find a network card driver go >> wrong with cache inconsistency when doing DMA transfer: CPU got the >> stale data in cache when reading DMA data received from device. > > I suppose this means those drivers may lack dma_sync_single_for_cpu() > calls after the inbound transfers complete, and are instead relying on > the cache invalidation performed before the transfer to make the DMA'd > data visible to the CPU. It also commonly goes wrong the other way round when the drivers are correct but DT/ACPI failed to indicate a coherent device as such. If writes from the device actually snoop, they hit the still-present cache line, which then gets invalidated by unmap/sync_for_cpu and the new data is lost. Robin.