From patchwork Fri Nov 26 18:04:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Kossifidis X-Patchwork-Id: 12641313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50958C433EF for ; Fri, 26 Nov 2021 18:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=AefxoNBtpDxj/LMykXn88EwxZ+czmokNMCq8T8alfrg=; b=O1Vnb8Z+B4xcKf aDVcNjA9jM5EAQECnlQtVWwIm0yGmuQEsy6gt9VSZLSsp4ZRUOsEvDVf4X8wFvPC1ceitJBxSTNDw l5lh8xddmVg0h+NPupweSQvtHKlAhI8DemFdzrMutzIrIR4xF7g12jStY8i9KnZc/W2vu3mfmKs5D 8WajDHAY+yUDANKHIUI2OqCRkD9rqggBwvtzpdM92k2FCce0EMTx7mtJiXo49ABzoWhKFOQdnmmPf leN0Q+VRi8NTwF2cz25vln5lOaMF8kJO14FFIHrVOsZGCXWBngun2EbEHviA09KgYgHJecsqdeMiG yaq1xBgLM2LLGV2S1Erg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqfdG-00BQlo-UG; Fri, 26 Nov 2021 18:07:35 +0000 Received: from mailgate.ics.forth.gr ([139.91.1.2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqfaQ-00BPR5-Vw for linux-riscv@lists.infradead.org; Fri, 26 Nov 2021 18:04:44 +0000 Received: from av3.ics.forth.gr (av3in.ics.forth.gr [139.91.1.77]) by mailgate.ics.forth.gr (8.15.2/ICS-FORTH/V10-1.8-GATE) with ESMTP id 1AQI4aXJ005325 for ; Fri, 26 Nov 2021 20:04:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; d=ics.forth.gr; s=av; c=relaxed/simple; q=dns/txt; i=@ics.forth.gr; t=1637949871; x=1640541871; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MvanV+rEo5Xp6JFqBDVWF0EkA5TJE46GGGiVMEKsDCs=; b=FnOdAaVKWdeWfD32YJZr3dXhwr4GmvkQmb75s8DqlIVzNaxG2U+kBK2wstVT/r24 qd6LtgsI02hUtMbJbtkA5uxduTycAwZcew7DU4NFeiN3JmF9UYyTdsARDcGAGv8h C3pABgRfhwllFY+KFeNSqBaq8LKraZqXjYUP3e63X0iujbodhvDpQXR2UeNk9uvi 3oVRkMzWx6yBtpaGEcSu1+j5nIYHlY8x3UbZ+SxW75SH16MxM2Ta2dFcsRFd5ZHA 2PQHCxlmO1GtHcPE8OgrOBMbSNX6mDRsZ5pdQgDPa5faxOwCjHgTj3wdne/Q1ZN7 XjaBAXfsWon7gHVIWi3zuw==; X-AuditID: 8b5b014d-9a2477000000460a-a9-61a121afd79c Received: from enigma.ics.forth.gr (enigma-2.ics.forth.gr [139.91.151.35]) by av3.ics.forth.gr (Symantec Messaging Gateway) with SMTP id 99.14.17930.FA121A16; Fri, 26 Nov 2021 20:04:31 +0200 (EET) X-ICS-AUTH-INFO: Authenticated user: mick@ics.forth.gr at ics.forth.gr From: Nick Kossifidis To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Nick Kossifidis , Alexandre Ghiti , stable@vger.kernel.org Subject: [PATCH 1/3] riscv: Don't use va_pa_offset on kdump Date: Fri, 26 Nov 2021 20:04:09 +0200 Message-Id: <20211126180411.187597-1-mick@ics.forth.gr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFLMWRmVeSWpSXmKPExsXSHT1dWXe94sJEg7erOSye3fnKarH19yx2 i8u75rBZbPvcwmbR/O4cu8XLyz3MFm2z+C0WbHzE6MDh8eblSxaPwx1f2D3unZjG6vFw0yUm j81L6j0uNV9n9/i8SS6APYrLJiU1J7MstUjfLoEr49cxo4IdIhU7e14wNzBuFehi5OSQEDCR 2LJlIXMXIxeHkMAxRolry56zQSTcJG7f38kKYrMJaErMv3SQBcQWEXCXWD35DxNIA7PARkaJ 2+u2MoMkhAWsJa7s/cUEYrMIqEocP3UJrIFXwFzi9ZbPrBBD5SVOLTvIBBEXlDg58wlYDTNQ vHnrbOYJjDyzkKRmIUktYGRaxSiQWGasl5lcrJeWX1SSoZdetIkRHHyMvjsYb29+q3eIkYmD 8RCjBAezkgivc+D8RCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8vHoT4oUE0hNLUrNTUwtSi2Cy TBycUg1MER+P/TLYrLphzYub31+Ur9ZWmyknycvUPefvu83mymVrPP8VeLkteGZhWHwmc+6k D+0Hp51YfHTGS/n387zN+TbpqqZJLuyv2nPxH/OCy5M3TnbJT3207eQz33M+f6QKYhw51LZ0 FXgpNorEWap6rowKb38UqMAXni4Rv3dJoVQBX/fMFSUcuYfKc37W2uxTcjc6HvKnz4rjdLUp 395jejlvTRc8eBj2oEbqwU0m1cunNTqKFNcFHNGZdTuX3UDxTLhV3IGsp59fCS9Pjq/TUM55 7WO4RbUvcs/pyMUaS+pff1ZfsDokZO/lc7ktsycumMX2j0nM++LyI9sEXz+3Zk6+XbDxs2vO sx+6AWwFSizFGYmGWsxFxYkAQfKrE60CAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_100439_503446_4F0ADFD5 X-CRM114-Status: GOOD ( 15.21 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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. v2: I removed the direct jump after setting satp as suggested. Fixes: 2bfc6cd81bd1 ("riscv: Move kernel mapping outside of linear mapping") Signed-off-by: Nick Kossifidis Reviewed-by: Alexandre Ghiti Cc: # 5.13 Cc: # 5.14 --- arch/riscv/kernel/kexec_relocate.S | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/kexec_relocate.S b/arch/riscv/kernel/kexec_relocate.S index a80b52a74..059c5e216 100644 --- 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" From patchwork Fri Nov 26 18:04:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Kossifidis X-Patchwork-Id: 12641311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C35FDC433FE for ; Fri, 26 Nov 2021 18:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mn3JuN/xlS0zGJz7nLl7kvRUkM3LujhiE0HMb0EE2Rk=; b=ueqciyqv1llCYZ 7qLjGouil0WrVtgrHlV1qbfvtLnUMmgpJMzoyrxUrBIP8yOO7mGnFFlt4bCz/4nt54Pg2kRThCDOX g20Qdr4aXJ1G5Yc1HSTn1rzWDktizbxJmh9nSRrUG8GZ2mNZTkVd+WoG3iuZ/6WnpKN1WRT4gMc73 4A24DoaZ6ox+BlF+IIv8kC7CaWf6L4xe8h2283WU23FeqQyUyGssbKIlVchbdiVbiwLVQbSNJ0vQ2 XFm6RjDPVkqnBEuu56+5d4nA6OVMxjex+Rxgikb6w7zFqOMOkj7FqV0TQiS94iLfDTUj1cIK4SBow hdSKythNZ2GPq54+Dm1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqfcw-00BQdy-Qu; Fri, 26 Nov 2021 18:07:15 +0000 Received: from mailgate.ics.forth.gr ([139.91.1.2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqfaQ-00BPR4-Vu for linux-riscv@lists.infradead.org; Fri, 26 Nov 2021 18:04:44 +0000 Received: from av3.ics.forth.gr (av3in.ics.forth.gr [139.91.1.77]) by mailgate.ics.forth.gr (8.15.2/ICS-FORTH/V10-1.8-GATE) with ESMTP id 1AQI4afv005326 for ; Fri, 26 Nov 2021 20:04:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; d=ics.forth.gr; s=av; c=relaxed/simple; q=dns/txt; i=@ics.forth.gr; t=1637949871; x=1640541871; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=G7hqs6XkmVh0r9F43+KthFWHpCGCPs2cR9auzvLaORA=; b=H3h33uTpd/IsJk+daVt9SOGxKcwSc3JQvvUO4P/bsRTpmRh0ABxdeN5TNHhfKpJy ODtc7hnx/7GBDrtLhaCMuURv2Fl5FNjFkimyiSTY+ZYF8MUzbkSJKRnPK+I/VbC0 uuPJajveHuJK4pCI6Kzlr0ZwxzcynHaR1Lep8nJV9vvg3zOUrJzfCriDbzbY2l0o UYg0/OPBylkTs/snrHI7efIOTyvdi8nodJTexDl5ejt1UUc5Ld5rGFN23J1eGX6o JiqHmgQt3+P04UOJIg2mfAluUSkMcn32yWG/8PBSilsQzmHGVetmXNlKGRnuNQg5 Eq7wG6xauTMeLxco+H2CiA==; X-AuditID: 8b5b014d-9ba4a7000000460a-aa-61a121af4fbd Received: from enigma.ics.forth.gr (enigma-2.ics.forth.gr [139.91.151.35]) by av3.ics.forth.gr (Symantec Messaging Gateway) with SMTP id A9.14.17930.FA121A16; Fri, 26 Nov 2021 20:04:31 +0200 (EET) X-ICS-AUTH-INFO: Authenticated user: mick@ics.forth.gr at ics.forth.gr From: Nick Kossifidis To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Nick Kossifidis , stable@vger.kernel.org Subject: [PATCH 2/3] riscv: use hart id instead of cpu id on machine_kexec Date: Fri, 26 Nov 2021 20:04:10 +0200 Message-Id: <20211126180411.187597-2-mick@ics.forth.gr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211126180411.187597-1-mick@ics.forth.gr> References: <20211126180411.187597-1-mick@ics.forth.gr> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBLMWRmVeSWpSXmKPExsXSHT1dWXe94sJEgxub2Sy2/p7FbnF51xw2 i22fW9gsmt+dY7d4ebmH2aJtFr/Fgo2PGB3YPd68fMnicbjjC7vHw02XmDw2L6n3uNR8nd3j 8ya5ALYoLpuU1JzMstQifbsEroy1O96zFezjqlh79wVLA+N/ji5GTg4JAROJi98vs3QxcnEI CRxjlOj7dp8FIuEmcfv+TlYQm01AU2L+pYNgcREBd4nVk/8wgTQwC7QzSsy89QcsISzgJTH/ +lRGEJtFQFViydEGJhCbV8BcovXXQWaIofISp5YdBIpzcHAKWEjs+B0JEhYCKnm/aSUrRLmg xMmZT8BGMgOVN2+dzTyBkW8WktQsJKkFjEyrGAUSy4z1MpOL9dLyi0oy9NKLNjGCA5PRdwfj 7c1v9Q4xMnEwHmKU4GBWEuF1DpyfKMSbklhZlVqUH19UmpNafIhRmoNFSZyXV29CvJBAemJJ anZqakFqEUyWiYNTqoFJZJ6q4QOtFWucG7Rbd5l6F5p8Eb+v+yEtdT7rwX+ruZ/OVHQ63DWr lE/9/MXq8u9a9VW/xdfMD79ok7jkrLn9d4Mldy5tfZ/qtELratfM7Pchxvd+Xt7PZ/ftGcvO V9eddSZfjTFlaLqhb3JKQKMoIG/ellj/hua4KV/enZ2718dngZa5vIhAU8i+gPxZLttjHrOp qz53UY1leDuvp69RvubDpu8vX5Ztfv147s/Q/ZeeHX4acUXRuHNTgsgM/ZMSz7aYtV37VMt0 y1Qpvte6ypWD4f2BeEaH7QkHZdc6T7+4yPbOd9bGnxftO9ofPj/Cs95WoUtXSGm6wp3dj1Yp mdzPbbtr4ptfvLicv5lDiaU4I9FQi7moOBEAHofzrrsCAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_100439_458808_CE017F09 X-CRM114-Status: UNSURE ( 9.57 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org raw_smp_processor_id() doesn't return the hart id as stated in arch/riscv/include/asm/smp.h, use smp_processor_id() instead to get the cpu id, and cpuid_to_hartid_map() to pass the hart id to the next kernel. This fixes kexec on HiFive Unleashed/Unmatched where cpu ids and hart ids don't match (on qemu-virt they match). Fixes: fba8a8674f68 ("RISC-V: Add kexec support") Signed-off-by: Nick Kossifidis Cc: stable@vger.kernel.org --- arch/riscv/kernel/machine_kexec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c index e6eca271a..cbef0fc73 100644 --- a/arch/riscv/kernel/machine_kexec.c +++ b/arch/riscv/kernel/machine_kexec.c @@ -169,7 +169,8 @@ machine_kexec(struct kimage *image) struct kimage_arch *internal = &image->arch; unsigned long jump_addr = (unsigned long) image->start; unsigned long first_ind_entry = (unsigned long) &image->head; - unsigned long this_hart_id = raw_smp_processor_id(); + unsigned long this_cpu_id = smp_processor_id(); + unsigned long this_hart_id = cpuid_to_hartid_map(this_cpu_id); unsigned long fdt_addr = internal->fdt_addr; void *control_code_buffer = page_address(image->control_code_page); riscv_kexec_method kexec_method = NULL; From patchwork Fri Nov 26 18:04:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Kossifidis X-Patchwork-Id: 12641315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD176C433EF for ; Fri, 26 Nov 2021 18:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f2a8lKHmzWkRikGamuLstgtB/Ag1ZWo/Bcjo17XoDpo=; b=ThTaNfEkFLv+OD bh1s8Hg5KL8f//lVGbGZYBM9j8aAsEFDdHnm09yXlOyKEYbZHODhiP+6F8hpQ6iWyHE+TbIy2d9O5 UhW0FYbMgaWonTFQFHj/WZdfibk1YL0qxLy15VLYHsC8bpRJU9S54Mup61LD58oUrUC/efN3xqG99 zXxRZ9eg6nF7MftscutzO/wKW6yIY6lKUp51kGM4Dfu5+nFtZ5ViZVMaH1IXsOEEPYyyNVsG8VLSO YxUNqivaYaTkTfNf6vye0IddN2czCqy1OUWKwD7gM9Ccb+XcmN4fZ3UyTZOaVHjL9451Z79bNKz/9 7+kMaBTsBDmwNBuzvIdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqfdX-00BQtX-4j; Fri, 26 Nov 2021 18:07:51 +0000 Received: from mailgate.ics.forth.gr ([139.91.1.2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqfaQ-00BPR6-Vy for linux-riscv@lists.infradead.org; Fri, 26 Nov 2021 18:04:44 +0000 Received: from av3.ics.forth.gr (av3in.ics.forth.gr [139.91.1.77]) by mailgate.ics.forth.gr (8.15.2/ICS-FORTH/V10-1.8-GATE) with ESMTP id 1AQI4aco005327 for ; Fri, 26 Nov 2021 20:04:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; d=ics.forth.gr; s=av; c=relaxed/simple; q=dns/txt; i=@ics.forth.gr; t=1637949871; x=1640541871; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HwZwqj1Qv59IMeyNmkXzER8KB6AH7iTuvaLwYU2PapU=; b=BVqeGD+8xaZowUssCk5lhXjmAYmLl2S5BxHrzCurO5rm/Ls5vv0HyVT9i84ORE5l A8VsKL3znz+puvAGTBeK2hqTn5EgCKSNb64bNqojcL9a96y4XHtrOq11/qamrxXo muPEUW4P/PoeqxHqGee2mEw7ug/DK3THPrdJBc7Uq3CqVzz2SYIOTkJNbqm1Vm5v gMHrvscXnZOw//NDeJDKvZzm+UPL92rz5tEZR5TiNsG8VZFEgFB+C3WLxRkits3E qDLXKAoDogthUOU/7SxtPhPkVO4S1kNJ7dIh/w6eipMiWPvBVvNt6FEF7vaoNCp8 19WuOEQ9VHXxW7KRWaX8dw==; X-AuditID: 8b5b014d-9a2477000000460a-ab-61a121affcd5 Received: from enigma.ics.forth.gr (enigma-2.ics.forth.gr [139.91.151.35]) by av3.ics.forth.gr (Symantec Messaging Gateway) with SMTP id B9.14.17930.FA121A16; Fri, 26 Nov 2021 20:04:31 +0200 (EET) X-ICS-AUTH-INFO: Authenticated user: mick@ics.forth.gr at ics.forth.gr From: Nick Kossifidis To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Nick Kossifidis Subject: [PATCH 3/3] riscv: try to allocate crashkern region from 32bit addressible memory Date: Fri, 26 Nov 2021 20:04:11 +0200 Message-Id: <20211126180411.187597-3-mick@ics.forth.gr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211126180411.187597-1-mick@ics.forth.gr> References: <20211126180411.187597-1-mick@ics.forth.gr> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrILMWRmVeSWpSXmKPExsXSHT1dWXe94sJEg5/HeSy2/p7FbnF51xw2 i22fW9gsmt+dY7d4ebmH2aJtFr8Dm8ebly9ZPA53fGH3eLjpEpPH5iX1Hpear7N7fN4kF8AW xWWTkpqTWZZapG+XwJXxbuEepoIDAhVHNi9gbGCcy9vFyMkhIWAi0fLzClsXIxeHkMAxRomp SzYyQiTcJG7f38kKYrMJaErMv3SQBcQWEXCXWD35DxOIzSyQL7HtyznmLkYODmGBKIk5v8xB wiwCqhLdD6czg9i8AuYSTTd/sEGMlJc4tewgE0g5p4CFxI7fkSBhIaCS95tWskKUC0qcnPmE BWK6vETz1tnMExj5ZiFJzUKSWsDItIpRILHMWC8zuVgvLb+oJEMvvWgTIzgUGX13MN7e/Fbv ECMTB+MhRgkOZiURXufA+YlCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeXn1JsQLCaQnlqRmp6YW pBbBZJk4OKUamHjsE5N4f8/xspgfHv27T6FjpdbE6VbfD/QfsJcrOMzQk3NNmPfBjTV2XK1p QhudhPYt5HxxeuqKZ81rNV9YP5n4/Cofa1ef5PL7pmdur06XmX9Ny/MyJ6u+23PGrqg/h7f+ 1mc4G8HfVXvYtiRjzq4PGk/Y92Wmv2zZs6RdwIBxi77Zyc4pMRMTVcuDOy//jNRco2MS9/Ll wo+T0rlyFutxN21uC5u+IvRp4e+cN6Ive1vfVO2aafr73apWe+u1rpWFcWej1lXIsjK9D/7u du2cf1sGo32NtUK5qGeM46b7q92VGx5fTOjYK5n4/Vfv5ZA2m6ulCQ4lz8yCe0/cr3h7/kZ1 Ojf3ptdfpFivKrEUZyQaajEXFScCAHgKg0a0AgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211126_100439_451613_F35D8BCB X-CRM114-Status: GOOD ( 14.13 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When allocating chrash kernel region without explicitly specifying its base address/size, memblock_phys_alloc_range will attempt to allocate memory top to bottom (memblock.bottom_up is false), so the crash kernel region will end up in highmem on 64bit systems. This way swiotlb can't work on the crash kernel, since there won't be any 32bit addressible memory available for the bounce buffers. Try to allocate 32bit addressible memory if available, for the crash kernel by restricting the top search address to be less than SZ_4G. If that fails fallback to the previous behavior. I tested this on HiFive Unmatched where the pci-e controller needs swiotlb to work, with this patch it's possible to access the pci-e controller on crash kernel and mount the rootfs from the nvme. Signed-off-by: Nick Kossifidis --- arch/riscv/mm/init.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 24b2b8044..1963a517e 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -812,13 +812,22 @@ static void __init reserve_crashkernel(void) /* * Current riscv boot protocol requires 2MB alignment for * RV64 and 4MB alignment for RV32 (hugepage size) + * + * Try to alloc from 32bit addressible physical memory so that + * swiotlb can work on the crash kernel. */ crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE, - search_start, search_end); + search_start, + min(search_end, (unsigned long) SZ_4G)); if (crash_base == 0) { - pr_warn("crashkernel: couldn't allocate %lldKB\n", - crash_size >> 10); - return; + /* Try again without restricting region to 32bit addressible memory */ + crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE, + search_start, search_end); + if (crash_base == 0) { + pr_warn("crashkernel: couldn't allocate %lldKB\n", + crash_size >> 10); + return; + } } pr_info("crashkernel: reserved 0x%016llx - 0x%016llx (%lld MB)\n",