Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp772803rwb; Fri, 23 Sep 2022 04:05:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4kuBYMF3HdFP+H3z+ov/2L+x7e8OS+wpp6f28TKtdSQ5v+eIEHODNKUvqIJ1pYhNI4WdOb X-Received: by 2002:a63:eb0e:0:b0:429:aefa:9fa9 with SMTP id t14-20020a63eb0e000000b00429aefa9fa9mr6914788pgh.122.1663931130846; Fri, 23 Sep 2022 04:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663931130; cv=none; d=google.com; s=arc-20160816; b=QS4A9jJbbzpODLcT08UfEB/FcRO69npM5nASIbV6UbkF7BVZKDzdCmpeX2JCVSmnRg gi+fQIFU1IrSGNSIcS364x7GuA3LsMnQhb5PE/RYdBQ/fLAi0hh316HqVxcIYAsCil1O a8XF4BOzGLmYspW2HZU5FBAbdCfDROlOJnc+c3+sj8JujKhOvb4ne4QZKQRVVNPlGXUm 1fl3E/CBS22QOGTrXZ+HsN+OwSL4/kdgEAJUCjHvu36KVLzVdNDpSeWtY3DdY6uBzwhm IVpd/EdW68XkaEkVXtY2IO23acIjmoJUWhFiy6Rtv3WnNkcRX5GYbyEy2kS3wvRKhraW 3r1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=i+RFHRDZY89aeKyPu8/TuW3CdYELUkeV+PudCtI32c8=; b=CTe0g56zACARpA2jTqB/xcZmpghKscqeCVjhzgucPmo4QKcaMF8+NwOblJ3AUAExcN ItBmnRYYarb+s/0x8Ca5CcC3aeeUoaa0wO13lThnbNtuUoG529kQ2Y6Owb29Ynhl3PL/ 0JhQ1wVDCgeAWas8mRamNRo3yRmUTxtFQ6Iun1CmvjhYVP++yewqVpyjIoORswHN6AHM m31OthH19owO2ko7RlPdPofG4jGm0TGw9i2yQdQh/6aQH1a/r1ecditIpazDLD7n2x86 9JN3b5zUHKnOeHBRpCXsinrvhHMasE+xDT7mxphRIrFpQmAVQ6p8KGl2Dh4UfcAtisof HgIg== 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=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v9-20020a631509000000b00434d869e339si9263218pgl.512.2022.09.23.04.05.18; Fri, 23 Sep 2022 04:05:30 -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=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiIWKS7 (ORCPT + 99 others); Fri, 23 Sep 2022 06:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbiIWKSu (ORCPT ); Fri, 23 Sep 2022 06:18:50 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29C8212DEC7 for ; Fri, 23 Sep 2022 03:18:47 -0700 (PDT) Received: from p508fdb48.dip0.t-ipconnect.de ([80.143.219.72] helo=phil.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1obflV-0005l1-VU; Fri, 23 Sep 2022 12:18:37 +0200 From: Heiko Stuebner To: Samuel Holland , Palmer Dabbelt , linux-riscv@lists.infradead.org, Alexandre Ghiti Cc: Albert Ou , Guo Ren , Paul Walmsley , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] riscv: Fix crash during early errata patching Date: Fri, 23 Sep 2022 12:18:37 +0200 Message-ID: <3805269.R56niFO833@phil> In-Reply-To: References: <20220922054743.30159-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SPF_HELO_TEMPERROR 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 Hi, Am Donnerstag, 22. September 2022, 09:31:56 CEST schrieb Alexandre Ghiti: > Hi Samuel, > > On 9/22/22 07:47, Samuel Holland wrote: > > The patch function for the T-Head PBMT errata calls __pa_symbol() before > > relocation. This crashes when CONFIG_DEBUG_VIRTUAL is enabled, because > > __pa_symbol() forwards to __phys_addr_symbol(), and __phys_addr_symbol() > > checks against the absolute kernel start/end address. > > > > Fix this by directly using the underlying kernel_mapping_va_to_pa(). > > > I'd rather fix __phys_addr_symbol so that we can use __pa_symbol and > then take advantage of the address range check. Instead of using _end in > phys_addr_symbol, we have access to the size of the kernel mapping, so > we could do something like that: > > diff --git a/arch/riscv/mm/physaddr.c b/arch/riscv/mm/physaddr.c > index f981b1f95fa0..150691aef058 100644 > --- a/arch/riscv/mm/physaddr.c > +++ b/arch/riscv/mm/physaddr.c > @@ -22,7 +22,7 @@ EXPORT_SYMBOL(__virt_to_phys); > phys_addr_t __phys_addr_symbol(unsigned long x) > { > unsigned long kernel_start = kernel_map.virt_addr; > - unsigned long kernel_end = (unsigned long)_end; > + unsigned long kernel_end = kernel_map.virt_addr + kernel_map.size; > > /* > * Boundary checking aginst the kernel image mapping. > so I did the whole set of original code - works without DEBUG_VIRTUAL - breaks with DEBUG_VIRTUAL and then applied you suggested change to __phys_addr_symbol, which fixes the breakage. And I guess making this usable at all times also makes a lot of sense, so Tested-by: Heiko Stuebner Reviewed-by: Heiko Stuebner > > Fixes: a35707c3d850 ("riscv: add memory-type errata for T-Head") > > Signed-off-by: Samuel Holland > > --- > > > > arch/riscv/errata/thead/errata.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c > > index 202c83f677b2..83174f13783e 100644 > > --- a/arch/riscv/errata/thead/errata.c > > +++ b/arch/riscv/errata/thead/errata.c > > @@ -76,8 +76,9 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al > > if (cpu_req_errata & tmp) { > > /* On vm-alternatives, the mmu isn't running yet */ > > if (stage == RISCV_ALTERNATIVES_EARLY_BOOT) > > - memcpy((void *)__pa_symbol(alt->old_ptr), > > - (void *)__pa_symbol(alt->alt_ptr), alt->alt_len); > > + memcpy((void *)kernel_mapping_va_to_pa((unsigned long)alt->old_ptr), > > + (void *)kernel_mapping_va_to_pa((unsigned long)alt->alt_ptr), > > + alt->alt_len); > > else > > patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len); > > } >