Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5808999rwb; Mon, 14 Nov 2022 09:43:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AH3DjvrweGHqwxZMxlTASvSrtmh156f4s2FzYq4JcWOXdUTszePAGTWiNVdsHfA5OLTzI X-Received: by 2002:a17:903:2403:b0:186:9fb9:1f8c with SMTP id e3-20020a170903240300b001869fb91f8cmr335538plo.69.1668447812521; Mon, 14 Nov 2022 09:43:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668447812; cv=none; d=google.com; s=arc-20160816; b=bNHFk/ZCfa7zhI3k456Jh6g5BpncOcaw0m88ZzGF7CoQHspwdkhn1yvD6J4HsNkIvs CHZZfS8I1/QziIn2oWEded9HBLG6ver6w6OJPYbulcI6pNktbeT0HRwUjmr2T62A7t+K fCUNeE5G50z+2dvBafCOExFPMPObz+7VuVId1vBQ9YSJ2KIC9IXegWoyFflv8PQ0V7mJ Q0YMpYS8b7Rj1zLrcjDOLzn0nWLPd4aWIZeki73w93cABfplvbmb1AE2xMibwZ5xqvsO w6j5eEn9f3NaXi8EauYZoo5Dk2nkTWMENptlCVlUCm7F2wMIP+MqfGsLEiTH3AgQGGI6 eTAg== 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; bh=188xhc/zHOrXHGQWQpqhlklN266/qOwg2kZRIkBXoR0=; b=EfUZZ8Z+OFPcl2Gmagr/xTgKbLJ31e60Ovb04Vf08QOgy2Gy0/T6v1cd4K0gFYBZbo UPCrJtAn7qXKCCjP+ggThmf34K8DPYykg5C4q3LYJab0X12SyAXWnxj5cjZjT9ABYjGI GprrK3UCXH3KLe2Zvfsx/oKkBwL7S5o5WUHZb9g2KWIhWYmNJ4Dy1B/YbNEz5w1ZeEF7 As1sqmV0jgpQ1KTNDmiwMWXGfkIl1OEYP1+1QdLw73/M4sgWTafGUcZNNLndAWNxopzk vghq4FmkwuBJB9YdTMtRlN8jsAYYlSU7qFPiuvmNcjCoBSTNFpOPVK4bfUORpu4UvWwP Oe6A== 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 r22-20020a170902be1600b00186de874df8si8663278pls.442.2022.11.14.09.43.17; Mon, 14 Nov 2022 09:43:32 -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=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235995AbiKNRiL (ORCPT + 89 others); Mon, 14 Nov 2022 12:38:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbiKNRiI (ORCPT ); Mon, 14 Nov 2022 12:38:08 -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 998DA4091E for ; Mon, 14 Nov 2022 09:38:07 -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 80FD861321 for ; 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1659929b-1372-cea6-5840-c58369a4252d@arm.com> X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 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