Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2091164ybp; Thu, 10 Oct 2019 02:02:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYMpUsJRqMNr/vZmsyEMcyQ7y6qPvsV+yYemT7AyQ5Z+xVoyC/31Q5aaBFoJujrtiXHei6 X-Received: by 2002:a17:906:e113:: with SMTP id gj19mr7088152ejb.203.1570698143926; Thu, 10 Oct 2019 02:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698143; cv=none; d=google.com; s=arc-20160816; b=OFY4NKK6glw3LSOlwI/5EPNEzTHOOfj0kkolLlur5Sax0V7AbYZMLgSKGtv7O8xxIu XWTHSm4bpy0Gh2VW7/oQb52H1IiBLZ/4BPKJxu8hgG7xW5AVpJukL07SyqndyR5nTVo0 z/l35qE2n5BtGsTL4RGMfawnkLZlfSMRCbEqXLmDSDKFulVrcqSmfK5uoWdYv+oR39nX n2H6jNTXmRuWiS3E6OVu8iLCCTLEIhysbj5ww3cX2aFnAVOVA8TWbhjmYyNlPtTKUaUM OL/sWiZyfbKOXdEoxuN89j8pWQJRCDkbNySNBkEUgdGMKJoIQJwe/WGaqIZ4JEfHcd3r +TIg== 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=uB/eTlLJnZV0deP/vdZUVHZXS4T0+qQ0kVKJfC1e2SY=; b=UG5iIdOW4He4wBuP6lh5QE2wJNNjNs5Wt83+ry+qQBminEt4yao/3X3YLEVJGPO8tx /vkBm8RVpDOqAFBjXG+p+ptir8B+5sUHDFtRi3RTtjrG4yA7QeornErfTtsWBsjbd5BA XpT9zePICqkkBrNepkMgfmyeCh/q2B4vqschRGyCwpZfBSWdRC4Tzbld4g/Xda5TcBjh cNZyaPzPdXyago8WgjDEBFo1HjtjziM9iFXARP4zJ9nH7o2El6FCovmrkZLemUhx4oJm czOye6LAtm2KX7zPqlji2gv1UQ3kq2IgbCnADKczHSh99yt8LeZlPHGppKZab3g5w9gh PDfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kaIdY770; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p18si3001517ejn.370.2019.10.10.02.02.00; Thu, 10 Oct 2019 02:02:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kaIdY770; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388794AbfJJInp (ORCPT + 99 others); Thu, 10 Oct 2019 04:43:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:48622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388770AbfJJIno (ORCPT ); Thu, 10 Oct 2019 04:43:44 -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 51C8221929; Thu, 10 Oct 2019 08:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697023; bh=zJrZkbq56cAliUqaDa1Q7mnzYKKcOVVANYJuTaly3Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kaIdY770oHJwvsBN2+hCIDuyjFm8lymNBNSUWWiL/kBeiWsrItYvsW+Y2Y6XfL/a1 r8pPwjay61bZUArpUv9YCcyeN4gJN2AImHeHHVWXyTU5XIb7Iz77O2vaDte6af4rIz ZkWYMCunzMqCtsICGZP5Jwsz8Iv37ReQXFcZtWeU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Chen , Palmer Dabbelt , David Abdurachmanov , Paul Walmsley , Sasha Levin Subject: [PATCH 5.3 140/148] riscv: Avoid interrupts being erroneously enabled in handle_exception() Date: Thu, 10 Oct 2019 10:36:41 +0200 Message-Id: <20191010083620.814265164@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@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: Vincent Chen [ Upstream commit c82dd6d078a2bb29d41eda032bb96d05699a524d ] When the handle_exception function addresses an exception, the interrupts will be unconditionally enabled after finishing the context save. However, It may erroneously enable the interrupts if the interrupts are disabled before entering the handle_exception. For example, one of the WARN_ON() condition is satisfied in the scheduling where the interrupt is disabled and rq.lock is locked. The WARN_ON will trigger a break exception and the handle_exception function will enable the interrupts before entering do_trap_break function. During the procedure, if a timer interrupt is pending, it will be taken when interrupts are enabled. In this case, it may cause a deadlock problem if the rq.lock is locked again in the timer ISR. Hence, the handle_exception() can only enable interrupts when the state of sstatus.SPIE is 1. This patch is tested on HiFive Unleashed board. Signed-off-by: Vincent Chen Reviewed-by: Palmer Dabbelt [paul.walmsley@sifive.com: updated to apply] Fixes: bcae803a21317 ("RISC-V: Enable IRQ during exception handling") Cc: David Abdurachmanov Cc: stable@vger.kernel.org Signed-off-by: Paul Walmsley Signed-off-by: Sasha Levin --- arch/riscv/kernel/entry.S | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index bc7a56e1ca6f4..9b60878a4469c 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -166,9 +166,13 @@ ENTRY(handle_exception) move a0, sp /* pt_regs */ tail do_IRQ 1: - /* Exceptions run with interrupts enabled */ + /* Exceptions run with interrupts enabled or disabled + depending on the state of sstatus.SR_SPIE */ + andi t0, s1, SR_SPIE + beqz t0, 1f csrs sstatus, SR_SIE +1: /* Handle syscalls */ li t0, EXC_SYSCALL beq s4, t0, handle_syscall -- 2.20.1