Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1333184iof; Tue, 7 Jun 2022 03:35:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycXG7iLUs+W3e5JsboqAP3LV3thoedDqGGv+Gxfi+hG0VKVBslQrm8NHy+XcNeLpJd2Q2d X-Received: by 2002:a05:6402:34d3:b0:431:55c0:fb7 with SMTP id w19-20020a05640234d300b0043155c00fb7mr12602076edc.274.1654598125991; Tue, 07 Jun 2022 03:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654598125; cv=none; d=google.com; s=arc-20160816; b=iZvCHnAbw+LhNWK0dg9dXPLfRmtx9sv1S6vL5+OprjPnbU4Rw4LO+LOmb+wG+iM9xz kYAiY8aOibKcW+qHUVXI0ZlA8/QGk1jdFmXvoJg3mGETYWaQ/I4gwjrjL+lzwOH+2ggW 4ln9gTS8JTvlPXAyY9LiTbjNyzneHM3bGcIRaOnhaTHSovMftnnukaLjuoAc6vEYJ9Vs 3up9+GkuvSQiqPNUIggO3dMpqznB70b/+yUFG+uJftRIMrO+CrZ+AjXUDVPpWkOXHDTg mCof+4fiYUrleXMu726iTDjUtpoqEfeqHXNNxgdgd3WDimLjE1StKw1Pfdx1XG83SupA s2OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=SmvHVjuxKmycEfcpBu6b0V35Xx0fk9EnlQyxfNxv7oQ=; b=T289cH2davhE3QTHgkkSiUH15RskAIT5WB1ogxsMTbEdYS4co9OGsJkCJzS8w4AuHL 58FsgygsayYGr97jggIMqpCs2RL5PBIG3Iuj4GCpfU36XhX4QdNrX/FceVOjIWsNBlhW GlnwAf9N/8Rx+iy/1eArEuESgofl4NKocjvLIMHswJ0MpNIVt2TqREdqCsvPvV7SWfPn pVkUTR5h0hlMC4A6snXqadmGQDgGesBWGOmxNCvzvIpLMEaAH7o8KLiX3I/KT0S8rUMl 5WuYUfCV/r/I502rvLmyvBISGgIWKHBarFmszdUD/7ZJbztOyfEZTsnmsOxOJRJkOFs7 aNZA== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne21-20020a1709077b9500b006feaf0c9605si11645903ejc.676.2022.06.07.03.35.01; Tue, 07 Jun 2022 03:35:25 -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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237576AbiFGHQn (ORCPT + 99 others); Tue, 7 Jun 2022 03:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237581AbiFGHQj (ORCPT ); Tue, 7 Jun 2022 03:16:39 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D7A56758 for ; Tue, 7 Jun 2022 00:16:36 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LHM7C62txz1KCkF; Tue, 7 Jun 2022 15:14:47 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 7 Jun 2022 15:16:35 +0800 Received: from [10.174.178.55] (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 7 Jun 2022 15:16:34 +0800 Subject: Re: [PATCH] ARM: Mark the FDT_FIXED sections as shareable To: Ard Biesheuvel CC: Russell King , , , Kefeng Wang , Linus Walleij , Nicolas Pitre References: <20220606124858.384-1-thunder.leizhen@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: Date: Tue, 7 Jun 2022 15:16:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,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 2022/6/7 1:12, Ard Biesheuvel wrote: > On Mon, 6 Jun 2022 at 17:52, Ard Biesheuvel wrote: >> >> Hello Zhen Lei, >> >> On Mon, 6 Jun 2022 at 14:49, Zhen Lei wrote: >>> >>> commit 7a1be318f579 ("ARM: 9012/1: move device tree mapping out of linear >>> region") use FDT_FIXED_BASE to map the whole FDT_FIXED_SIZE memory area >>> which contains fdt. But it only reserves the exact physical memory that >>> fdt occupied. Unfortunately, this mapping is non-shareable. An illegal or >>> speculative read access can bring the RAM content from non-fdt zone into >>> cache, PIPT makes it to be hit by subsequently read access through >>> shareable mapping(such as linear mapping), and the cache consistency >>> between cores is lost due to non-shareable property. >>> >>> |<---------FDT_FIXED_SIZE------>| >>> | | >>> ------------------------------- >>> | | | | >>> ------------------------------- >>> >>> 1. CoreA read through MT_ROM mapping, the old data is loaded >>> into the cache. >>> 2. CoreB write to update data through linear mapping. CoreA >>> received the notification to invalid the corresponding cachelines, but >>> the property non-shareable makes it to be ignored. >>> 3. CoreA read through linear mapping, cache hit, the old data >>> is read. >>> >> >> Thanks for the excellent write-up, and for what must have been a lot >> of work to narrow down and diagnose! Yes, it took a lot of time, a lot of boards. >> >>> To eliminate this risk, mark the MT_ROM sections as shareable. >>> >>> The other user of MT_ROM is XIP_KERNEL. XIP allows the kernel to run from >>> flash to save RAM space. Not sure if anyone is still using XIP in order to >>> save a little memory and not care about performance degradation. Add a new >>> memory type MT_ROM_XIP to be compatible with it. >>> >>> BTW: Another solution is to memblock_reserve() all the sections that fdt >>> spans, but this will waste 2-4MiB memory. >>> >> >> I agree that we should not add shareable attributes to the memory type >> used by XIP kernels for code regions: NOR flash is not usually >> integrated in a way that allows it to participate in the coherency >> protocol, so that will likely break things. >> >> I think, though, that it would be better to leave MT_ROM alone, and >> introduce a new type MT_MEMORY_RO instead, which is wired up in the >> right way (see below), so that we get NX attributes, and can use it to >> create non-section mappings as well. Right, NX should also be set. I will try MT_MEMORY_RO. >> >> Then, as a followup which does not need to go into -stable, we can >> reduce the size of the mapping: there is really no need for the >> permanent mapping to be section granular - this is only for the early >> asm code that is not able to create 2 levels of page tables. >> > > Actually, on second thought, I think reducing the size of the FDT > mapping is also needed for correctness, as the non-fdt regions could > potentially be covered by a no-map memory reservation, or get mapped > non-cacheable for things like non-coherent DMA. I'll keep the section mapping first, because the fix for adding the shareable attribute is explicit. > . > -- Regards, Zhen Lei