Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3721682pxb; Mon, 24 Jan 2022 16:18:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdS6zwSeiB4zR2Rc5iZIm5bn+F2dPDGg2+j7hZR1Tgnj/zfe0eOTj2rt7+RuA80g/5xegy X-Received: by 2002:a17:902:b105:b0:14a:b4c8:2ac7 with SMTP id q5-20020a170902b10500b0014ab4c82ac7mr16199034plr.148.1643069936292; Mon, 24 Jan 2022 16:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069936; cv=none; d=google.com; s=arc-20160816; b=tfYRSxir4iq6eBJCVT0zIkl0edxS8eLexea4sDLpGRGrUn+bpR2F80uChQP3KY41gE 1A7WVBq3m4vZkGXaKUTtBiXZ/va0nBJ9yLhDXbiz3d/1O5l6CCIQp7dSkjDhM8IpvepO /JLqDa4Kur/o+1F9N2P7kvAhinpzW/Qs+noSSkWIUGI5E2HdnxwTXAk14Gu7CN3fSsJU f1teSEbulFgvZC6wbwsR2TmmsJVNZG2ODCo+JqufLIFwVuqy9xI2sQgaKJS4e/Q0iAEB PWCwIHs8Nrhg0W6YseNO7IZEOpRa+nMSpabAVuzDAWywllxBgJfaFuOB4GDIQ33p44Fe 6Gow== 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=QhfUsgSiEvE/0P/EIMScyX+J7XBK7mD3I79ZY8wCLRM=; b=qpXbsORTDp0jRdvPP6K5e3q+HtCLtgYxccx6chWmU82O2CV1eWbWhygoS8Q7E1YVby sbQuc5mTnc6e5SMlDV2yxaZ6GFsBy31IBj6EQNe51wZW7RbB0iWnC5suzA1XCZVaIQFn 3XKme09y/j0Fw1Ie1JWYfYggJmAOu9GpI9JA6Snl2Kylx96nggHivMFP/cx2nzvGRiRv nsjHKQwdDe3yJ5XW9KdymSqf9TX0GqMWybZsSqC0xVBYcwufYy5cGSpiYjKqOEC16K+X M1Gq78W2blblxyEPXb32ATcrw1Dq4/6N/98AJb5Qr53dZAaLWYrLw8dB12D4ix3dciGY 0S4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hU3k0x9Z; 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 g10si3144499pfj.219.2022.01.24.16.18.44; Mon, 24 Jan 2022 16:18:56 -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=hU3k0x9Z; 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 S2373364AbiAYANh (ORCPT + 99 others); Mon, 24 Jan 2022 19:13:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1835200AbiAXX2X (ORCPT ); Mon, 24 Jan 2022 18:28:23 -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 4D4BBC06137D; Mon, 24 Jan 2022 13:33:28 -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 149FFB8123A; Mon, 24 Jan 2022 21:33:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69D7CC340E4; Mon, 24 Jan 2022 21:33:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060005; bh=6CwbdUP4ArC4/Ck5geh/sApqB5cTzwvQjDurpINfABc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hU3k0x9Zec7rdHcx652bIfCY0hHbKEq7oAPdJItOH51xaUl2f0RUxUS4gPZfsFJ6k MMfzMVLKTAHiJA6b+sh85RPItndC89tc0hyth2TH+hw0FEGPjLBqPwnY3e6unxjZBZ b7k5D93ptRxepU0y9Lhn9yUKyyjtYxlJaks0QRg4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Chen , Anup Patel , Sasha Levin Subject: [PATCH 5.16 0808/1039] KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR Date: Mon, 24 Jan 2022 19:43:17 +0100 Message-Id: <20220124184152.471697105@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Vincent Chen [ Upstream commit 33e5b5746cc2336660c8710ba109d9a3923627b5 ] When the last VM is terminated, the host kernel will invoke function hardware_disable_nolock() on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR must be cleared before clearing hideleg CSR. Fixes: 99cdc6c18c2d ("RISC-V: Add initial skeletal KVM support") Signed-off-by: Vincent Chen Reviewed-by: Anup Patel Signed-off-by: Anup Patel Signed-off-by: Sasha Levin --- arch/riscv/kvm/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c index 421ecf4e6360b..2e5ca43c8c49e 100644 --- a/arch/riscv/kvm/main.c +++ b/arch/riscv/kvm/main.c @@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void) void kvm_arch_hardware_disable(void) { + /* + * After clearing the hideleg CSR, the host kernel will receive + * spurious interrupts if hvip CSR has pending interrupts and the + * corresponding enable bits in vsie CSR are asserted. To avoid it, + * hvip CSR and vsie CSR must be cleared before clearing hideleg CSR. + */ + csr_write(CSR_VSIE, 0); + csr_write(CSR_HVIP, 0); csr_write(CSR_HEDELEG, 0); csr_write(CSR_HIDELEG, 0); } -- 2.34.1