Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp532305rwb; Fri, 18 Nov 2022 05:06:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5XUOjBtFpmgPecWU16SUt6oxBBOcfvVs6iYur3yTW/XYvell5m8A624IvrOn0ovtj0KFUe X-Received: by 2002:a17:906:3951:b0:7ae:ed2:5367 with SMTP id g17-20020a170906395100b007ae0ed25367mr5809247eje.521.1668776802601; Fri, 18 Nov 2022 05:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668776802; cv=none; d=google.com; s=arc-20160816; b=xUypXGw2VqzANmTMTzpRRxUO1BzghbZIge9BPok6hqG9RAM1pKxwSsW88HG5DLbp9w /uLWJwyPxS2ofUxWPrIsMtNTnion88/MnC8dkylBKIEC79W6cyGDgIE+L6evy2tz6HWU S4Vn0SplKQNNL5IiV98OKnqMSVMeMfp+WxLCGlNsDs6w3W9yOp27x9cU/uPKs8gFTtfV /YXQrY7os/nj8/mafYiVhPmD/kAR7g7lQrfj0/WLd7jczT3A5oxZODFPzN3tlcp3w8ua mv7A72XQ31NKdTxHV0xPuZJ7VVcT+19ASXCoFC/DUR526+/ekXVeXYaUFNT/2AbfZDpQ dzSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kY0cIJctP/lWQSp/0eTfVMod7Odnv8wBpdbwRD7BaA4=; b=0FfGcni3GsTmAEW3XjhPSEOJg7aDWs5nVGh3hgzXZoaCT2HtsUmTaDXnezJr1Dv1wO 2gBlSev/ALaFT2CtwvBJWXBd7iWG55aBcAG8nZQxh/vgbiYAKPhiGqA8ne3Tu1p8uCkb cM2KI33uh02vhA4nOqzC0DCworxjda/42N3p6REzAYZUT5jjKR8+iIDGqILuSyGMqNYW 3NDYEBSDngMLy2zgypEWq0be/Saw9ZJzvhL+PvOeXa6wSzQnR0dyx3woVM558MdUrd5B 0TbDZyE69oHCJ+Qqalh3ZivLsYKg9Oxln0b+ahMTipmfPktlPQloI2L1QSO8Dq1Ac2FF 51yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T3iPjRBN; 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 wy4-20020a170906fe0400b007a31138203asi3089759ejb.669.2022.11.18.05.06.17; Fri, 18 Nov 2022 05:06:42 -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=T3iPjRBN; 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 S241106AbiKRMeI (ORCPT + 91 others); Fri, 18 Nov 2022 07:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240920AbiKRMeC (ORCPT ); Fri, 18 Nov 2022 07:34:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAD96CD0 for ; Fri, 18 Nov 2022 04:33:57 -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 ams.source.kernel.org (Postfix) with ESMTPS id A50EDB82304 for ; Fri, 18 Nov 2022 12:33:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88EF0C433C1; Fri, 18 Nov 2022 12:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668774835; bh=Z2fM/T11X1JbB9QleHXKH+hbS5Bk9HGFuktcfgKbH8A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T3iPjRBNF2ZfqPaqUr6W4k0+iNaLxUOY8QUNc6W9c8v3VCztTphdYJuloJRAzvBJG E7AJEScYrW7G0Of/D1PzDVOt4Hq+dsxEbFr4I/LY5z8gwrOk5DxMbxK0pmReey+qMO D8dAqS629neXU5HMu98AKDTXnIvB1iQWyIlaNSULIfJ8mPf43G+YTLwAvsLqzqXHed ltLDl/TzHS4u6+wPqRDPpayfu9Zw0hdW/96V+KIE0SmnuiB8qtPnTTOD6GCMx3fUYn znegCqRe2NvbhDS3QnYQ36vNX5t8d6nCR20XBTwrpBd/9ktBGg+whKLnXDL0jKdRIR EpVKwnkmjzAxw== Date: Fri, 18 Nov 2022 12:33:49 +0000 From: Will Deacon To: Manivannan Sadhasivam Cc: Catalin Marinas , Robin Murphy , 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: <20221118123349.GC3697@willie-the-truck> References: <20221114110329.68413-1-manivannan.sadhasivam@linaro.org> <20221114141109.GG30263@willie-the-truck> <1659929b-1372-cea6-5840-c58369a4252d@arm.com> <20221118105402.GA184726@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221118105402.GA184726@thinkpad> User-Agent: Mutt/1.10.1 (2018-07-13) 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 18, 2022 at 04:24:02PM +0530, Manivannan Sadhasivam wrote: > On Mon, Nov 14, 2022 at 05:38:00PM +0000, Catalin Marinas wrote: > > 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. > > > > Okay, thanks for the hint. Can you share how to allocate the dma-pool that's > not part of the kernel's linear map? I looked into it but couldn't find a way. The no-map property should take care of this iirc Will