Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3651894pxb; Mon, 24 Jan 2022 14:29:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2MmVY8SBq6IbIxqTw50nv32Wz17Ji+D1GhcuhkJk/vxaodIbT1a2DNnOYoyyDc9XTqU7Q X-Received: by 2002:a63:7e0a:: with SMTP id z10mr13194056pgc.567.1643063342521; Mon, 24 Jan 2022 14:29:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063342; cv=none; d=google.com; s=arc-20160816; b=dX8z9pGuO4pfIVrOtXUK3+zsQsFysR8zeeE74WsyOD3MHWtHxNhftB0zPbNUfrL+Hi MM3Fk1XoJAAH2uNJXHXS1BwXJTAELgyyP+tNt6X0NNsBGiQP+qzaWpWlIMjZ9QNrlY6D wuYZrra69k2e9DYONLNlLdii0uDQMNeRyHzadgfqTJk07HkH60rQnZ0f+Sq7Ge1ypsyX 8SLxkEvqtxD1LprHK7NmejR69kw2pf/xUL4fOBr2UvsS3EcV22Yx4h4AUUESheH+LlIp 5mfJlJjQpuSkeEAFw8L0rozUMb4nQMdIDRySOVW2T+6Ir+SiH9mLVLGw82+QA3Anb3g3 1OXQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ldge1Ao2SSK5M8NgUGjnkGoQuS44d2MdX0Q7bcpIjxc=; b=vbObqu7hEAbVP+35ahVDkMa7oRY5e4H4C73DwW8qsfQEW+i6VV11CK1pFnNiBwo1LK IBQwIvApVnYwDwGoWD+A9w2uS3GiaedHpPiZlyPYpSz4cAFE4WAEmI6SvQ7d3xcgSCcf F1hDg12Q39aXbtkM6hNDhGJM3qRLIo72GNLpRneZJBZB7lSw9qz4nJNL2xC0WMuqTkue 0Ytwao8jr7kas/+fCUiE8VMbFF/fW8wGMs0eyIoNY34x7v1BZo3XskSdtoQyhDwwUb0e UW/06TndZRZb+yvl9KSUxHAIwIrdqc0LG5FStgB9l04F5sQP7KQW8LDT+jeVT2Nzp3Rr HoXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vcgph0N9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x24si14467303pga.411.2022.01.24.14.28.50; Mon, 24 Jan 2022 14:29:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vcgph0N9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1452950AbiAXWRM (ORCPT + 99 others); Mon, 24 Jan 2022 17:17:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1448508AbiAXVM6 (ORCPT ); Mon, 24 Jan 2022 16:12:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 325E6C06E00D; Mon, 24 Jan 2022 12:10:52 -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 EFCF4B8121A; Mon, 24 Jan 2022 20:10:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 276B4C340E5; Mon, 24 Jan 2022 20:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055049; bh=sPzD3sIHCoQZ6kq2zRn0RcdzuU13RsPBbpmhmt4Sj7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vcgph0N9XDuqUqGDjRvT1AbwfnWB/qVHz4r2zigyhs4jex3GyC6vrRNdsmfXnM0df vHrto3vipvZ3OF+u9qgRWgmmGSDPiG/kQj78uCyq7tCSiZyXvSM4aZH2paW10tKWCk EDh9RnyHQ+8FSabFJjZDdCiCbXAi0akYAFMqw9RA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nick Kossifidis , Alexandre Ghiti , Palmer Dabbelt Subject: [PATCH 5.15 024/846] riscv: Dont use va_pa_offset on kdump Date: Mon, 24 Jan 2022 19:32:21 +0100 Message-Id: <20220124184101.760975660@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Kossifidis commit a11c07f032a0e9a562a32ece73af96b0e754c4b3 upstream. On kdump instead of using an intermediate step to relocate the kernel, that lives in a "control buffer" outside the current kernel's mapping, we jump to the crash kernel directly by calling riscv_kexec_norelocate(). The current implementation uses va_pa_offset while switching to physical addressing, however since we moved the kernel outside the linear mapping this won't work anymore since riscv_kexec_norelocate() is part of the kernel mapping and we should use kernel_map.va_kernel_pa_offset, and also take XIP kernel into account. We don't really need to use va_pa_offset on riscv_kexec_norelocate, we can just set STVEC to the physical address of the new kernel instead and let the hart jump to the new kernel on the next instruction after setting SATP to zero. This fixes kdump and is also simpler/cleaner. I tested this on the latest qemu and HiFive Unmatched and works as expected. Fixes: 2bfc6cd81bd1 ("riscv: Move kernel mapping outside of linear mapping") Signed-off-by: Nick Kossifidis Reviewed-by: Alexandre Ghiti Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/kernel/kexec_relocate.S | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) --- a/arch/riscv/kernel/kexec_relocate.S +++ b/arch/riscv/kernel/kexec_relocate.S @@ -159,25 +159,15 @@ SYM_CODE_START(riscv_kexec_norelocate) * s0: (const) Phys address to jump to * s1: (const) Phys address of the FDT image * s2: (const) The hartid of the current hart - * s3: (const) kernel_map.va_pa_offset, used when switching MMU off */ mv s0, a1 mv s1, a2 mv s2, a3 - mv s3, a4 /* Disable / cleanup interrupts */ csrw CSR_SIE, zero csrw CSR_SIP, zero - /* Switch to physical addressing */ - la s4, 1f - sub s4, s4, s3 - csrw CSR_STVEC, s4 - csrw CSR_SATP, zero - -.align 2 -1: /* Pass the arguments to the next kernel / Cleanup*/ mv a0, s2 mv a1, s1 @@ -214,7 +204,15 @@ SYM_CODE_START(riscv_kexec_norelocate) csrw CSR_SCAUSE, zero csrw CSR_SSCRATCH, zero - jalr zero, a2, 0 + /* + * Switch to physical addressing + * This will also trigger a jump to CSR_STVEC + * which in this case is the address of the new + * kernel. + */ + csrw CSR_STVEC, a2 + csrw CSR_SATP, zero + SYM_CODE_END(riscv_kexec_norelocate) .section ".rodata"