Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2541985rwb; Sat, 19 Nov 2022 19:03:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf72SiOT9VmkRVxHZDJVd10gGCdrJY66paJ4jXZO+pZCI6nj+a6D9kKkpcTgWD3EzonsOtM2 X-Received: by 2002:a05:6a00:2483:b0:56c:12c0:aaf1 with SMTP id c3-20020a056a00248300b0056c12c0aaf1mr1010337pfv.50.1668913433559; Sat, 19 Nov 2022 19:03:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668913433; cv=none; d=google.com; s=arc-20160816; b=vr8BdKpUWSGmVH4vMmEJ3jQt+jR7Nz6piKteH8CGJIY2OWoXeLuV4dVlpKjFZxKl8v BiYffYr3lmlp0QH0E5Yx3STWo+41W4/e11wflDWOcT/oh4lYZpDMymENUy+L37K+RcdG A8Q0YP/s69Cy+8nwX3BHvRCGrqr7lYEqWEKzXn4eIXYNfaHNQGlszxBNAr6gPwhYr/fx zt+7NrEDN/DM0yWTNMNckSTEwSc9rTqPbZrgIHlw2YrGez7ADuw9KnpagNxMVT6uZdXJ V/Ja69v6WjjnM5LBxIgIs61nCQqHsWLXqPNObYTaNxGctxSZ88MsrlKnuzdu6dF+Bdib jRrA== 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 :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=duV7zTQYpdQbRoQcwQxHH0FNxzsaluCLmzvFNp7TnNQ=; b=FXYdHwKOC3TFecT8+oS2xTZChNgD3BKoqcR8rccmIL6ZWF7DMLCipzhxDj/z/2ifGv MoJQf0e7Ed9PNLnGtJH/8RBE+U81o1uaBX4EC6EY9FhRqsiBfgY0fG4b2WK+mO2zF/nO 67aUEro/UZeUiWVXRJraEVm6GCT8BT9Gnpik3lRt3scMeCTUbko6K2KRMIqJtBaWOTS0 BecHnKn7/j8Otr5QRC7frPgevaHCIMRdD0F093z3yBbKQnoNjG7086D6yEVJM4oKfSUw KLy6BcwbehImWlCIXRwyTgy0dgwlv9OyiHfPQEUCh3kUt6VqwUIJ9V8gayTPLFYCDN7N OFvg== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a631a4b000000b0047761ad8456si876235pgm.166.2022.11.19.19.03.42; Sat, 19 Nov 2022 19:03:53 -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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229455AbiKTC6r (ORCPT + 92 others); Sat, 19 Nov 2022 21:58:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiKTC6q (ORCPT ); Sat, 19 Nov 2022 21:58:46 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DAE3A7C1F for ; Sat, 19 Nov 2022 18:58:44 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NFFVd6lf3zqSPH; Sun, 20 Nov 2022 10:54:49 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 20 Nov 2022 10:58:41 +0800 Received: from [10.174.179.79] (10.174.179.79) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 20 Nov 2022 10:58:40 +0800 Subject: Re: [RFC PATCH] arm64: mm: Add invalidate back in arch_sync_dma_for_device when FROM_DEVICE To: Robin Murphy , Ard Biesheuvel CC: , , , , , , , , References: <20221117072100.2720512-1-sunnanyong@huawei.com> From: Nanyong Sun Message-ID: Date: Sun, 20 Nov 2022 10:58:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.79] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 18:23, Robin Murphy wrote: > 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. > > . Is it acceptable?  Does the coherent device MUST run with coherent identifier? At least they can run with no wrong before.