Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp398666rwb; Thu, 22 Sep 2022 00:50:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qY+x2IxZnF8eYF/UuFqoFY3k2x60iVtAJiKpyfHX9D9VwBG63M1IGdMlmMVFLx/d1g78H X-Received: by 2002:a63:5a50:0:b0:429:8580:fc61 with SMTP id k16-20020a635a50000000b004298580fc61mr2001876pgm.215.1663833055420; Thu, 22 Sep 2022 00:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663833055; cv=none; d=google.com; s=arc-20160816; b=R4rBAzjcj/hRaTc41CjB7Aen5fGEtbcCNIrEYxWfwW4TGUBrCrv7gkL/A+npeq5MjT YOk7KOTkkc9We1idN0mgSu++wu9urHdUNG+YHetjr/98IDYpEYC1Sp50j8ASY2qUbpZ6 OUEn7Jb/T3W61TTarMW7IUgaLurP8DY8qvalWphbyJ5oydsZ9BfFxpz4G5505F2EmWBe Fgid12m1TXjKhEv+qO2k7d7OQs6sp1x9W+SxtboUy2fPbkMSBw78NyVkhDWwSCdIrMKT imEyxn4Woe1BRBE5cqDFpt6uEYUdN4xLjhowCcvzYCWLjPhxbO4oRXAP7JwaaFrs9uwJ 6MVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Rlx+g80fQNNi35AdT4MsCypj1opcT0H+co2QF8BgHTU=; b=w0EnIJ7MOM8EwAkRgPCmh5i9mqu6p/eYZH9PEgJKRkyqINvdgq2Kvo6TDAwDiduXPR dMHrcEEAuZIOV5WmCA58hpEehqu3+JtdkX7F9fZdxIzdkzODI5aOu0r5sGRpbBcu7YQl 4PJiFPS9PfOmq5WS0HEJi0HhYIjLKmhi2HzZ7X+4cJ3QpxjMl9vPu4qhMxlhNLxfEcC1 +gFGe0BPjBw6S2LpArk6kspaQjGbeTFofszmePHYm/sW878DsHk6HtMZTm54JvTlBVZF RP7uagc7asSMuGrizW4/qv1AdTyaBTgh6HfU8RIUoP0ycEmoM8VF9En4iy4S+xutWiOX yV7Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j71-20020a63804a000000b0043be648a7besi5114545pgd.815.2022.09.22.00.50.44; Thu, 22 Sep 2022 00:50:55 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229887AbiIVHcG (ORCPT + 99 others); Thu, 22 Sep 2022 03:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbiIVHcD (ORCPT ); Thu, 22 Sep 2022 03:32:03 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E27979A43 for ; Thu, 22 Sep 2022 00:32:02 -0700 (PDT) Received: (Authenticated sender: alex@ghiti.fr) by mail.gandi.net (Postfix) with ESMTPSA id BD6071C0009; Thu, 22 Sep 2022 07:31:56 +0000 (UTC) Message-ID: Date: Thu, 22 Sep 2022 09:31:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 1/2] riscv: Fix crash during early errata patching Content-Language: en-US To: Samuel Holland , Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: Albert Ou , Guo Ren , Heiko Stuebner , Paul Walmsley , linux-kernel@vger.kernel.org References: <20220922054743.30159-1-samuel@sholland.org> From: Alexandre Ghiti In-Reply-To: <20220922054743.30159-1-samuel@sholland.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE 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 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. Thanks, Alex > > 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); > }