Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp880712rwd; Thu, 15 Jun 2023 03:28:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+6wy3E0KYrgc0mDRnLlsGeV6+L3lHQFKEgHDUDMPN/r6Jtcmm3+0rpDGHFJJSyocOTjMc X-Received: by 2002:a05:6358:701d:b0:12b:e105:ebd1 with SMTP id 29-20020a056358701d00b0012be105ebd1mr8278573rwo.29.1686824918454; Thu, 15 Jun 2023 03:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686824918; cv=none; d=google.com; s=arc-20160816; b=FFb765nqUbZKWwm5+YO5DyBww1uFIEHzlI0NmaFfS8sNG7fh97PUiJe64x8m1Z1E5/ xEJUL8nI3IMKp3hl3HGR07u6oS2kFb/Di/aVt1/wIh9j36Bdbq5EqmsL1b7OJgOEA4kL AfED4v2cszGatUAgS/Qr7mC2nJ8DR3ZoW67qOsPxi5GkuVcKq83fYDVVpJzx44e1qiOQ vY9BRjtOxyyyKJB87dK/GbBobzMRSHid2WTie1i89E/V++vJpQNVDHRHMOECbKfEOCrH 38opWtEwmDXjhIlICNSr3ZNkHlxVnLqQmwhiy4s7AYvWRFpSR4+eiZwDK9kS7vlvCejG a00w== 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=i2PrihOCpuD1Z2a7OMN5l+JgHTBKcUsDeS/DnMAYmDQ=; b=SesvM+IR4NADUMsF1mVveSkFdbF/6aWQchmLxOdE4q+LN+CjVL4fcfKdM3GhFN/uXy PQTbrpHadzwI09a66HVo7IL8eHKub+hL9AsCzOrw8yvS5iSD766bRZGnlcRNo4W8SFWw Cd5Ippti+HBVRQ29nD5GZ6ZOc2MYQyehqiGj727NCfmrMDCN6Ar1TwjDK22jxc6TIFVH jLI+9UI9sfxcsBSvilGMnvjQ6QgB5J++fNzVii/ARG1bZGv1LAIgEg/4Uexna480LbM4 S+GhIw5IJ7qp8qyTnW6/1wAAV05jidrUScmA7/paHENBD5YlPGqQRN3wfdYaJMlWhizi INEw== 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 u8-20020a637908000000b0053b8874ceddsi13086445pgc.148.2023.06.15.03.28.25; Thu, 15 Jun 2023 03:28:38 -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; 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 S244837AbjFOKNj (ORCPT + 99 others); Thu, 15 Jun 2023 06:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239841AbjFOKNh (ORCPT ); Thu, 15 Jun 2023 06:13:37 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E9E12710; Thu, 15 Jun 2023 03:13:35 -0700 (PDT) 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 87FDC1FB; Thu, 15 Jun 2023 03:14:19 -0700 (PDT) Received: from [10.57.85.251] (unknown [10.57.85.251]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DABFA3F71E; Thu, 15 Jun 2023 03:13:32 -0700 (PDT) Message-ID: <36565295-ebaa-2a66-3389-ba5eb714ab34@arm.com> Date: Thu, 15 Jun 2023 11:13:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] Revert "Revert "Revert "arm64: dma: Drop cache invalidation from arch_dma_prep_coherent()""" Content-Language: en-GB To: Douglas Anderson , Will Deacon Cc: andersson@kernel.org, amit.pundir@linaro.org, linux-arm-msm@vger.kernel.org, konrad.dybcio@somainline.org, Sibi Sankar , Manivannan Sadhasivam , sumit.semwal@linaro.org, Stephen Boyd , Catalin Marinas , Manivannan Sadhasivam , Marc Zyngier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20230614165904.1.I279773c37e2c1ed8fbb622ca6d1397aea0023526@changeid> From: Robin Murphy In-Reply-To: <20230614165904.1.I279773c37e2c1ed8fbb622ca6d1397aea0023526@changeid> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,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 On 2023-06-15 00:59, Douglas Anderson wrote: > This reverts commit 7bd6680b47fa4cd53ee1047693c09825e212a6f5. > > When booting a sc7180-trogdor based device on mainline, I see errors > that look like this: > > qcom_scm firmware:scm: Assign memory protection call failed -22 > qcom_rmtfs_mem 94600000.memory: assign memory failed > qcom_rmtfs_mem: probe of 94600000.memory failed with error -22 > > The device still boots OK, but WiFi doesn't work. > > The failure only seems to happen when > CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y. When I don't have that set then > everything is peachy. Presumably something about the extra > initialization disagrees with the change to drop cache invalidation. AFAICS init_on_alloc essentially just adds __GFP_ZERO to the page allocation. This should make no difference to a DMA allocation given that dma_alloc_attrs explicitly zeros its allocation anyway. However... for the non-coherent case, the DMA API's memset will be done through the non-cacheable remap, while __GFP_ZERO can leave behind cached zeros for the linear map alias. Thus what I assume must be happening here is that "DMA" from the firmware is still making cacheable accesses to the buffer and getting those zeros instead of whatever actual data which was subsequently written non-cacheably direct to RAM. So either the firmware still needs fixing to make non-cacheable accesses, or the SCM driver needs to correctly describe it as coherent. Thanks, Robin. > Fixes: 7bd6680b47fa ("Revert "Revert "arm64: dma: Drop cache invalidation from arch_dma_prep_coherent()""") > Signed-off-by: Douglas Anderson > --- > > arch/arm64/mm/dma-mapping.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c > index 3cb101e8cb29..5240f6acad64 100644 > --- a/arch/arm64/mm/dma-mapping.c > +++ b/arch/arm64/mm/dma-mapping.c > @@ -36,7 +36,22 @@ void arch_dma_prep_coherent(struct page *page, size_t size) > { > unsigned long start = (unsigned long)page_address(page); > > - dcache_clean_poc(start, start + size); > + /* > + * The architecture only requires a clean to the PoC here in order to > + * meet the requirements of the DMA API. However, some vendors (i.e. > + * Qualcomm) abuse the DMA API for transferring buffers from the > + * non-secure to the secure world, resetting the system if a non-secure > + * access shows up after the buffer has been transferred: > + * > + * https://lore.kernel.org/r/20221114110329.68413-1-manivannan.sadhasivam@linaro.org > + * > + * Using clean+invalidate appears to make this issue less likely, but > + * the drivers themselves still need fixing as the CPU could issue a > + * speculative read from the buffer via the linear mapping irrespective > + * of the cache maintenance we use. Once the drivers are fixed, we can > + * relax this to a clean operation. > + */ > + dcache_clean_inval_poc(start, start + size); > } > > #ifdef CONFIG_IOMMU_DMA