Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1122143ybt; Tue, 7 Jul 2020 08:15:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOLvsIhxw/TQmuklz7DcTubcZM5uJZeKerFWgqkW6A47ZzVy8jE9xtIvm/6q1RmWclbpJi X-Received: by 2002:a17:906:c7c3:: with SMTP id dc3mr34117936ejb.376.1594134945867; Tue, 07 Jul 2020 08:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594134945; cv=none; d=google.com; s=arc-20160816; b=srt80ii1d0rFFfSHYgESQ7NSbj9P4fxNXhy7ZJJ0Js8lYXl++tVNywbo3WnvhLMafZ zpwjv8qEGEfryOIXAC5zGrOEh5y6BBxG9xV53w3onLXhDnmd21CMHSEx0N3knXw7WZA4 1HcutqBAzM1VZBYdIIuH8NDcef/2qL3ek3S+/GRvOJVJ2FsXjo701sDglT90FslH5K+M 4qd/MgjTBSyP/pirbuaZA689ymfy5CNmTxFGZtQaYB8rwH7i1MT6HBs1GY4EhH1jwfff T8+TlH9tsrSqV3WmdZtdeAvMm3bO0n9Bo2aQNzI8Muag/DZ3IHOsHCJ6KekxGAI1UTxV ZU9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U7WGiJqFmzL20/0Mcf1CQp9sYmHxOpbeODb0qDD1e8c=; b=jz6WsasMdKQE5nlFqsOz7ekfs/yqVfddW2Rj0MAfVId0hEOuJbSGKEjoG4n6yul8UF pRIWm+nAVQOyEf65jVNpIAye9F74BSsZy3kMDiW4iIcV34h0yDZMsdcSJ756mOyboOUk 5bX3CR0NUdjwtO7WaY/VZFrc9YsiqpI1f87JUsRk7hYMvbas3G5+vdewbcYgtO6Rls/6 TOYiHlFer3eQuexvoQ6ckEPPUuC98dDeicc9WLikU0yyBaB01GlP83VcdEV3wIFA3hEf vGa7xIUstNpp4OqjOUSiJvK4RSbhL00vc2CoUazVjbmJKTsfdGekoqoDUq7U+NfXKHG6 hFxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Nuoa88iJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lx8si14865208ejb.415.2020.07.07.08.15.22; Tue, 07 Jul 2020 08:15:45 -0700 (PDT) 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=@kernel.org header.s=default header.b=Nuoa88iJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728721AbgGGPOk (ORCPT + 99 others); Tue, 7 Jul 2020 11:14:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:54008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728699AbgGGPOi (ORCPT ); Tue, 7 Jul 2020 11:14:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9F70D2065D; Tue, 7 Jul 2020 15:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594134878; bh=EVkMoYKSScI/1nCIFD/Npq8qkoLSoWrYTsbBpiPzHbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nuoa88iJfIyYZ01KxuGO/wejtZadOADy8hHawUlxE7r2/TLuNVTrWmTyVJ7wO8HAu s4thZ3Cx+NRgEN8bX0Ex2+uSJ9iNBrCKURnrEAWzpuFaHZkkgqOWtxksr+TabYBVUI SAR9W1UjX+3YarT27vObsCwbMrZOaK1dzxO66Tr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hauke Mehrtens , Thomas Bogendoerfer Subject: [PATCH 4.9 22/24] MIPS: Add missing EHB in mtc0 -> mfc0 sequence for DSPen Date: Tue, 7 Jul 2020 17:13:54 +0200 Message-Id: <20200707145750.055711629@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145748.952502272@linuxfoundation.org> References: <20200707145748.952502272@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hauke Mehrtens commit fcec538ef8cca0ad0b84432235dccd9059c8e6f8 upstream. This resolves the hazard between the mtc0 in the change_c0_status() and the mfc0 in configure_exception_vector(). Without resolving this hazard configure_exception_vector() could read an old value and would restore this old value again. This would revert the changes change_c0_status() did. I checked this by printing out the read_c0_status() at the end of per_cpu_trap_init() and the ST0_MX is not set without this patch. The hazard is documented in the MIPS Architecture Reference Manual Vol. III: MIPS32/microMIPS32 Privileged Resource Architecture (MD00088), rev 6.03 table 8.1 which includes: Producer | Consumer | Hazard ----------|----------|---------------------------- mtc0 | mfc0 | any coprocessor 0 register I saw this hazard on an Atheros AR9344 rev 2 SoC with a MIPS 74Kc CPU. There the change_c0_status() function would activate the DSPen by setting ST0_MX in the c0_status register. This was reverted and then the system got a DSP exception when the DSP registers were saved in save_dsp() in the first process switch. The crash looks like this: [ 0.089999] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) [ 0.097796] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) [ 0.107070] Kernel panic - not syncing: Unexpected DSP exception [ 0.113470] Rebooting in 1 seconds.. We saw this problem in OpenWrt only on the MIPS 74Kc based Atheros SoCs, not on the 24Kc based SoCs. We only saw it with kernel 5.4 not with kernel 4.19, in addition we had to use GCC 8.4 or 9.X, with GCC 8.3 it did not happen. In the kernel I bisected this problem to commit 9012d011660e ("compiler: allow all arches to enable CONFIG_OPTIMIZE_INLINING"), but when this was reverted it also happened after commit 172dcd935c34b ("MIPS: Always allocate exception vector for MIPSr2+"). Commit 0b24cae4d535 ("MIPS: Add missing EHB in mtc0 -> mfc0 sequence.") does similar changes to a different file. I am not sure if there are more places affected by this problem. Signed-off-by: Hauke Mehrtens Cc: Signed-off-by: Thomas Bogendoerfer Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/traps.c | 1 + 1 file changed, 1 insertion(+) --- a/arch/mips/kernel/traps.c +++ b/arch/mips/kernel/traps.c @@ -2137,6 +2137,7 @@ static void configure_status(void) change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX, status_set); + back_to_back_c0_hazard(); } unsigned int hwrena;