From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 974E4C433DB for ; Tue, 12 Jan 2021 16:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5019223110 for ; Tue, 12 Jan 2021 16:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405066AbhALQwT (ORCPT ); Tue, 12 Jan 2021 11:52:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727622AbhALQwT (ORCPT ); Tue, 12 Jan 2021 11:52:19 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D00E8C061575 for ; Tue, 12 Jan 2021 08:51:38 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id t30so3258669wrb.0 for ; Tue, 12 Jan 2021 08:51:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lAJS/ciMI//6oB+au/tisJfr1aUYml4srA0rz4DDtWU=; b=pg9ptp6tLIOH1e1NfW9ncCZwY5ERzbd6nAeG+1fPw8hytCmDnWVVv+lktiq3Z98quW Dcgpt2s0AMvFuT19S1jNk4H9mxQlgCtbrdvczcyN5mUJxcLmUiD7nhAdIz/za5TqInWf ByL/o6+zdHSEcAK/4S9ZlONamddW9OWxMNUDS25yEV16CROxgQO2mg2HpnqSFJEU40wI 6JkdVhWfsKhTQu4wzqIozuFRBJGkDa74Q7lO5Msm53P7C5NmVcj1LkXGjzau7UqE/uWI RKl97ijQhyGC+TziqSBeBuvSFw1PJT1tsxig13TaEJKtptvdtddBJPcZ7zgm+URkq84M teYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lAJS/ciMI//6oB+au/tisJfr1aUYml4srA0rz4DDtWU=; b=mvNxWn1EL2Y+4v3PVWM9w+GDx0Zo057d6R/+n90YrfrRuWzu2Q/nApOEN7vQmnM6Su onspnGW0zDYlxfbjxMhzVNKoXd94sgX09g5kp/+Txg/RdnSWKGbvYfETSAQh9zPybmd8 2mja7CiMZnO+7f23tP78a4HFEIcCALKDMkS+Ibv7MhreyNM6tZvmw/IPOqYg/7+tjXDP HLjQjnpQCUQ06LbulycIM65q3DwelvkSxxinpY206Cfs2+/T0HPjFlb4JNO1F6t09B2l 5S3S0i6FmoRKBz8M+oi9D4L2P8ezJeeFfVaypu+rvFnxFYNuNRZzTy/EB2W5zACXtKBV 6QWA== X-Gm-Message-State: AOAM531YPkhbZwf7vV7D+EQ8GKL6KHsSa7hkb2d+CSKvVVxUSZ4kLDjA b5rA9keb79hH8JV26wCxYKM= X-Google-Smtp-Source: ABdhPJyMJrJ0h+ZyMZn3PzMPqkOMHh22wE/bmyCFfMJVSBN3S+GzxN/Y3z8MVdsUOVP0JGr2UzLEzg== X-Received: by 2002:adf:c6c4:: with SMTP id c4mr5413286wrh.348.1610470296369; Tue, 12 Jan 2021 08:51:36 -0800 (PST) Received: from localhost.localdomain ([151.68.76.215]) by smtp.gmail.com with ESMTPSA id u205sm4792163wme.42.2021.01.12.08.51.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 08:51:35 -0800 (PST) From: Giancarlo Ferrari To: linux@armlinux.org.uk Cc: giancarlo.ferrari@nokia.com, michal.simek@xilinx.com, Giancarlo Ferrari , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] ARM: kexec: Fix panic after TLB are invalidated Date: Tue, 12 Jan 2021 16:49:06 +0000 Message-Id: <1610470147-22641-1-git-send-email-giancarlo.ferrari89@gmail.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org machine_kexec() need to set rw permission in text and rodata sections to assign some variables (e.g. kexec_start_address). To do that at the end (after flushing pdm in memory, inv D-Cache, etc.) it needs to invalidate TLB [section] entries. If during the TLB invalidation an interrupt occours, which might cause a context switch, there is the risk to inject invalid TLBs, with ro permissions. When trying to assign .text labels, this lead to the following issue: "Unable to handle kernel paging request at virtual address " with FSR 0x80d. Signed-off-by: Giancarlo Ferrari --- arch/arm/kernel/machine_kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c index 76300f3..bbe912d 100644 --- a/arch/arm/kernel/machine_kexec.c +++ b/arch/arm/kernel/machine_kexec.c @@ -176,6 +176,13 @@ void machine_kexec(struct kimage *image) reboot_code_buffer = page_address(image->control_code_page); + /* + * If below part is not atomic TLB entries might be corrupted after TLB + * invalidation, which leads to Data Abort in .text variable assignment + */ + raw_local_irq_disable(); + local_fiq_disable(); + /* Prepare parameters for reboot_code_buffer*/ set_kernel_text_rw(); kexec_start_address = image->start; @@ -183,6 +190,9 @@ void machine_kexec(struct kimage *image) kexec_mach_type = machine_arch_type; kexec_boot_atags = image->arch.kernel_r2; + local_fiq_enable(); + raw_local_irq_enable(); + /* copy our kernel relocation code to the control code page */ reboot_entry = fncpy(reboot_code_buffer, &relocate_new_kernel, -- 2.7.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1A6CC433DB for ; Tue, 12 Jan 2021 16:53:23 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F0492311C for ; Tue, 12 Jan 2021 16:53:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F0492311C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject: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=h5G0VSVPnugRNhpTxQdOo1BAeF9s0DqR9Yy8GeasW6A=; b=19IBPLId6xuV6KFl94MnE7rBiU /FqHu8rbROV1V1Gc2AlWZfk4igkovxgtAFZmG7doDgTa19wwHgrf6clIQ5drXWT83EeRD8KPmuvDn i7l5vP/YaASoUCppcoZaSMPsF40ex83/uZWtsFrmEbA+SGy2HlRppv+YMH7r/OEJMDY7IPMa3+AvS pYa3M6LzkzlcglpcEfaDNFQgNPOwWvhMlWf0p/lxTDSNmg7ChEILSHKBHqCbmIL0xhZgdIS34bPC5 fvqHueI2LWWhuRjx3EsqINNNReKzDs4B1/x7xOVdgalZQUoIVsPabbYOjzR7dihWE0ZHQ2TX+Un4A 9Ub8/KJQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzMtT-0003CI-9w; Tue, 12 Jan 2021 16:51:43 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzMtP-0003AS-Ud for linux-arm-kernel@lists.infradead.org; Tue, 12 Jan 2021 16:51:41 +0000 Received: by mail-wr1-x435.google.com with SMTP id d26so3188349wrb.12 for ; Tue, 12 Jan 2021 08:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lAJS/ciMI//6oB+au/tisJfr1aUYml4srA0rz4DDtWU=; b=pg9ptp6tLIOH1e1NfW9ncCZwY5ERzbd6nAeG+1fPw8hytCmDnWVVv+lktiq3Z98quW Dcgpt2s0AMvFuT19S1jNk4H9mxQlgCtbrdvczcyN5mUJxcLmUiD7nhAdIz/za5TqInWf ByL/o6+zdHSEcAK/4S9ZlONamddW9OWxMNUDS25yEV16CROxgQO2mg2HpnqSFJEU40wI 6JkdVhWfsKhTQu4wzqIozuFRBJGkDa74Q7lO5Msm53P7C5NmVcj1LkXGjzau7UqE/uWI RKl97ijQhyGC+TziqSBeBuvSFw1PJT1tsxig13TaEJKtptvdtddBJPcZ7zgm+URkq84M teYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lAJS/ciMI//6oB+au/tisJfr1aUYml4srA0rz4DDtWU=; b=dnfp9C/r0jBNPvEvqHF7Fpz4YpLxG3XFcGOMTVluX4EpeosYoeanXRF5d2AMdGFV6I igP/dbMeO4BXtaIdYOQM6Uon5OOYSJmC9elBzCOG+4FuKzKIQCkWqb9Fq+CuwN7XAbi1 05DNRGgLzgFgfCzFFRS11y8LTNe2yaAe+ADgttL1kufqAsxthJBt8eOSBC87X7U6F+Ku bLSio6UKKwKdmphA/lEymK7ybOxRs2c0sxvCdZAmYnXe4/jd5UsjqQyz4tTHJmF9PFO8 3QvrX0PHa/M0CqB1keoT1MXTu2x5BVYhwS7VBwmyXt+5wrcmhN2hKhwDitM/7DmGgVOk WF3w== X-Gm-Message-State: AOAM532FE0BMjipd28GOEs3qcOWdGaOescxH6b9GRYoUKEDrFSEmerGX d0Pcg1jZ/uOd89iN4hgNX7DxmGn741a71A== X-Google-Smtp-Source: ABdhPJyMJrJ0h+ZyMZn3PzMPqkOMHh22wE/bmyCFfMJVSBN3S+GzxN/Y3z8MVdsUOVP0JGr2UzLEzg== X-Received: by 2002:adf:c6c4:: with SMTP id c4mr5413286wrh.348.1610470296369; Tue, 12 Jan 2021 08:51:36 -0800 (PST) Received: from localhost.localdomain ([151.68.76.215]) by smtp.gmail.com with ESMTPSA id u205sm4792163wme.42.2021.01.12.08.51.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 08:51:35 -0800 (PST) From: Giancarlo Ferrari To: linux@armlinux.org.uk Subject: [PATCH] ARM: kexec: Fix panic after TLB are invalidated Date: Tue, 12 Jan 2021 16:49:06 +0000 Message-Id: <1610470147-22641-1-git-send-email-giancarlo.ferrari89@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210112_115140_061443_6CE33D2F X-CRM114-Status: GOOD ( 14.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Giancarlo Ferrari , michal.simek@xilinx.com, linux-arm-kernel@lists.infradead.org, giancarlo.ferrari@nokia.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org machine_kexec() need to set rw permission in text and rodata sections to assign some variables (e.g. kexec_start_address). To do that at the end (after flushing pdm in memory, inv D-Cache, etc.) it needs to invalidate TLB [section] entries. If during the TLB invalidation an interrupt occours, which might cause a context switch, there is the risk to inject invalid TLBs, with ro permissions. When trying to assign .text labels, this lead to the following issue: "Unable to handle kernel paging request at virtual address " with FSR 0x80d. Signed-off-by: Giancarlo Ferrari --- arch/arm/kernel/machine_kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c index 76300f3..bbe912d 100644 --- a/arch/arm/kernel/machine_kexec.c +++ b/arch/arm/kernel/machine_kexec.c @@ -176,6 +176,13 @@ void machine_kexec(struct kimage *image) reboot_code_buffer = page_address(image->control_code_page); + /* + * If below part is not atomic TLB entries might be corrupted after TLB + * invalidation, which leads to Data Abort in .text variable assignment + */ + raw_local_irq_disable(); + local_fiq_disable(); + /* Prepare parameters for reboot_code_buffer*/ set_kernel_text_rw(); kexec_start_address = image->start; @@ -183,6 +190,9 @@ void machine_kexec(struct kimage *image) kexec_mach_type = machine_arch_type; kexec_boot_atags = image->arch.kernel_r2; + local_fiq_enable(); + raw_local_irq_enable(); + /* copy our kernel relocation code to the control code page */ reboot_entry = fncpy(reboot_code_buffer, &relocate_new_kernel, -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel