Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10712291rwb; Fri, 25 Nov 2022 07:08:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7/iyL03WsBiQYil5W6IHMJD7blQj55HHxp6AOYyDH+cjtequhJpWaqbmGil7y3DulWrzGK X-Received: by 2002:a05:6a00:1388:b0:574:d12e:f3d6 with SMTP id t8-20020a056a00138800b00574d12ef3d6mr1386296pfg.78.1669388916753; Fri, 25 Nov 2022 07:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669388916; cv=none; d=google.com; s=arc-20160816; b=SfYAI+ikHuR/xdpkIkvtAFP8cWQbLxU/OUlT1JKuLSiS4L8EpP7O3C30LnrBDhHmAN 5hnGw4D+0DyRfcnwO5pwO1PJhse6zb8HN1JLEPU5qSNNMdG0z8oVMZx2sytPUM2VXEFT Oprf71BCZlHWS4igDxlOUmvrxeltBYCxeDjzVinUNl8/w4J3+R3IwOrr1BFAGX3PRusi 2IOR6xzuSrtKMbCMQVDwz9VzYFDeer+F9okZy+Kx8PRI3QATUP1hpUGBcoqHarEjzTFy szr8adgeMEOEPLgcRs5AhNFHREvDrwPlcrsNWJjmDuHZYWpbHZsnTRGr0PVQCJIm/V2Z km0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cjjkowdasqjbZL4HKdZzzAeDGj5bUMQJndFmjBSDDZc=; b=YgZHJpnCK6TzAvdRDgqZUUeEF/W3+emhIBI9dnp+sNU1MmF5PBP+fO6c2hPre4Ro+H iJ0xtZk8G+qc187bRGDSrJa5LETUzmvZMumtGTW9Ah7y8g0HAmLGyIR2qZvusqiEh9N1 EsRHgy52Miut+lBM5D48VJgwKxfXutvcsdBjuintYtKAVCET8N3rV5/wz+368D3s+8tV YBinNLzM79B3IPE0BpysKCMXvqJFYWBDBI1+vhkaVOXdK8BtxYD/oxdDIsCu7T6Xjyih uD3DWvQofNhN+B1bxS9N/LE4XWwFUY05NB+nd5xfbmYHmmdoK2Jfq7wcNMeI7nTaOk9A mpkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RtMjx0KG; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a63f84a000000b00476c46ff6e9si3985960pgj.572.2022.11.25.07.08.22; Fri, 25 Nov 2022 07:08:36 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RtMjx0KG; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbiKYOqR (ORCPT + 85 others); Fri, 25 Nov 2022 09:46:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbiKYOp4 (ORCPT ); Fri, 25 Nov 2022 09:45:56 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFB233F044; Fri, 25 Nov 2022 06:44:36 -0800 (PST) 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 37CDD624C5; Fri, 25 Nov 2022 14:44:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8978BC433D6; Fri, 25 Nov 2022 14:44:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669387464; bh=MuAwpha+qj7ypes7vfXT4oKy6o8DH33QwZ2K7CESjKA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RtMjx0KGVzlDUNKm+iMxXswVni2hxX+w+hhhpGHCT+Cq9vtG2la0i8kZdrgDcrKre l7YNHyUJopFpdtCU/SylE/gHjsuBb+Y+37fMtJioOR+i1itWiCp2OR2HKNqZoJgYlQ Moww0jEGsfFQQWAiQUcA5XkaMB7TIpgjN2kwWZJs8BkfEDkXlSAywj1wBxzGsT7nHU J/p97AVBmXrTL49HkwK6b12SxQWq3QNdel2QZbgqxXD5QU01m0WZl/ah0L9u5SdVWX xPqTeZGTQef9M5ffcumt42YtbCt+VrPmEb7n8pWuIJRhwE5IPB1pKwxtgN48H03SH3 9s2eEDi3UAp/w== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oyZvr-0005Sz-98; Fri, 25 Nov 2022 15:44:00 +0100 Date: Fri, 25 Nov 2022 15:43:59 +0100 From: Johan Hovold To: Manivannan Sadhasivam Cc: Johan Hovold , Bjorn Andersson , Andy Gross , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Will Deacon , Robin Murphy , Christoph Hellwig , Ard Biesheuvel , Catalin Marinas , linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: dts: qcom: sc8280xp: fix PCIe DMA coherency Message-ID: References: <20221124142501.29314-1-johan+linaro@kernel.org> <20221125142625.GA9892@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221125142625.GA9892@thinkpad> X-Spam-Status: No, score=-7.1 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 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 Fri, Nov 25, 2022 at 07:56:25PM +0530, Manivannan Sadhasivam wrote: > On Thu, Nov 24, 2022 at 03:25:01PM +0100, Johan Hovold wrote: > > The devices on the SC8280XP PCIe buses are cache coherent and must be > > marked as such to avoid data corruption. > > > > A coherent device can, for example, end up snooping stale data from the > > caches instead of using data written by the CPU through the > > non-cacheable mapping which is used for consistent DMA buffers for > > non-coherent devices. > > > > Also, the device may write into the L2 cache (or whatever cache that is > accessible) if there is an entry and the CPU may invalidate it before reading > from the DMA buffer. This will end up in a data loss. I mentioned the above as an example, but clearly it can affect also the other direction (e.g. as described below). > > Note that this is much more likely to happen since commit c44094eee32f > > ("arm64: dma: Drop cache invalidation from arch_dma_prep_coherent()") > > that was added in 6.1 and which removed the cache invalidation when > > setting up the non-cacheable mapping. > > > > Marking the PCIe devices as coherent specifically fixes the intermittent > > NVMe probe failures observed on the Thinkpad X13s, which was due to > > corruption of the submission and completion queues. This was typically > > observed as corruption of the admin submission queue (with well-formed > > completion): > > > > could not locate request for tag 0x0 > > nvme nvme0: invalid id 0 completed on queue 0 > > > > or corruption of the admin or I/O completion queues (malformed > > completion): > > > > could not locate request for tag 0x45f > > nvme nvme0: invalid id 25695 completed on queue 25965 > > > > presumably as these queues are small enough to not be allocated using > > CMA which in turn make them more likely to be cached (e.g. due to > > accesses to nearby pages through the cacheable linear map). Increasing > > the buffer sizes to two pages to force CMA allocation also appears to > > make the problem go away. > > > > I don't think the problem will go away if the allocation happens from CMA > region. It may just decrease the chances of cache hit but it could always > happen due to the existence of linear mapping with cacheable attribute. I never claimed it would fix the problem, I explicitly wrote that it made it less likely to occur (to the point where my reproducer no longer triggers). Johan