From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE6F0C4332F for ; Mon, 14 Nov 2022 17:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GPJ0VoVoc5IgMgR9NfGBg0zjfMyR2nTb7StJzJuBUDc=; b=Nai9wz88ECA1mq HCF2GPGL+c6hCEK0oYjUEN32KMosje+Ep1+VvqtLAxkq/J0KLgQ8g/UsstPcPE02vZyJupLc7aPX0 +G3/abCVj7iMDs8QvtS4Pe369FgMD/3+QGpXg/gY/yHDd0bnPNv8zcj9tVaMEoXFUR1ZSBvYQSxAV +1JKktMf8mxlRJPeKXy9vCSl8QqKjWFOL8RBBieuuTsA8JIMPqAQ7B1/cQP/gutuLZ6s+iH2t1hLZ PBD8FKSSblQUlFX4xza2is6aLRFmwkVklSdOhjKH1PnJ4apmE8Ro3KIV/I2k/XnKQ9GSzmQISOvcU vjN3wYV4F34MCtdgajMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oudPO-003HoO-NY; Mon, 14 Nov 2022 17:38:10 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oudPL-003Hmb-Ix for linux-arm-kernel@lists.infradead.org; Mon, 14 Nov 2022 17:38:09 +0000 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 7FA2F6131A; Mon, 14 Nov 2022 17:38:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3797DC433C1; Mon, 14 Nov 2022 17:38:04 +0000 (UTC) Date: Mon, 14 Nov 2022 17:38:00 +0000 From: Catalin Marinas To: Robin Murphy Cc: Will Deacon , Manivannan Sadhasivam , amit.pundir@linaro.org, andersson@kernel.org, quic_sibis@quicinc.com, sumit.semwal@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Revert "arm64: dma: Drop cache invalidation from arch_dma_prep_coherent()" Message-ID: References: <20221114110329.68413-1-manivannan.sadhasivam@linaro.org> <20221114141109.GG30263@willie-the-truck> <1659929b-1372-cea6-5840-c58369a4252d@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1659929b-1372-cea6-5840-c58369a4252d@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221114_093807_680386_20A62D53 X-CRM114-Status: GOOD ( 28.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 14, 2022 at 03:14:21PM +0000, Robin Murphy wrote: > On 2022-11-14 14:11, Will Deacon wrote: > > On Mon, Nov 14, 2022 at 04:33:29PM +0530, Manivannan Sadhasivam wrote: > > > This reverts commit c44094eee32f32f175aadc0efcac449d99b1bbf7. > > > > > > As reported by Amit [1], dropping cache invalidation from > > > arch_dma_prep_coherent() triggers a crash on the Qualcomm SM8250 platform > > > (most probably on other Qcom platforms too). The reason is, Qcom > > > qcom_q6v5_mss driver copies the firmware metadata and shares it with modem > > > for validation. The modem has a secure block (XPU) that will trigger a > > > whole system crash if the shared memory is accessed by the CPU while modem > > > is poking at it. > > > > > > To avoid this issue, the qcom_q6v5_mss driver allocates a chunk of memory > > > with no kernel mapping, vmap's it, copies the firmware metadata and > > > unvmap's it. Finally the address is then shared with modem for metadata > > > validation [2]. > > > > > > Now because of the removal of cache invalidation from > > > arch_dma_prep_coherent(), there will be cache lines associated with this > > > memory even after sharing with modem. So when the CPU accesses it, the XPU > > > violation gets triggered. > > > > This last past is a non-sequitur: the buffer is no longer mapped on the CPU > > side, so how would the CPU access it? > > Right, for the previous change to have made a difference the offending part > of this buffer must be present in some cache somewhere *before* the DMA > buffer allocation completes. > > Clearly that driver is completely broken though. If the DMA allocation came > from a no-map carveout vma_dma_alloc_from_dev_coherent() then the vmap() > shenanigans wouldn't work, so if it backed by struct pages then the whole > dance is still pointless because *a cacheable linear mapping exists*, and > it's just relying on the reduced chance that anything's going to re-fetch > the linear map address after those pages have been allocated, exactly as I > called out previously[1]. So I guess a DMA pool that's not mapped in the linear map, together with memremap() instead of vmap(), would work around the issue. But the driver needs fixing, not the arch code. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel