From patchwork Mon Dec 27 03:05:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 1573279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=RR4gwP+L; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=Kl9q2qVK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JMjGX5rbvz9sXM for ; Mon, 27 Dec 2021 14:05:40 +1100 (AEDT) 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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=jtwtvu4WnaytELkg6o9xTzA+JJYVhWIa17h9oNOKIwU=; b=RR4gwP+L9yTzys edFpBnQ/h3nNmjQsYvlmwmItBv9dcJtt1Sbj8FL+2x0vS2n/V5auYUPFfu/hDQv0gIibiuWA5DHWk D3/+sNNet6ZYr7v1Zq5UxPX5ISyhKm+cX9RUM7EipB6rQAEb68osrc49igamghNJ6h/YKhP9W0HqG vax+y6+WoF3jrgwscz6SE76cSK5EwhRyfYltBMuZ2Vpf8DPEnLLlxXycGRSNhen+JpFFYqgU4y4no bpmS/yGHJrZ2xom5eR3MHrtJY6iZu8VpAGSkRXCKHUhatnBVI/hb987qIJXMwd7cObfRt4YlGa6zf icbhQU23O5AmVVSkmdRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n1gKQ-00G3km-7Q; Mon, 27 Dec 2021 03:05:38 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n1gKL-00G3k6-Uj for kvm-riscv@lists.infradead.org; Mon, 27 Dec 2021 03:05:35 +0000 Received: by mail-pf1-x42b.google.com with SMTP id m1so12590089pfk.8 for ; Sun, 26 Dec 2021 19:05:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=dGqwsw/SIIdqWvaKeKwu/tVA9A1cy1/HMgE5QohgKlU=; b=Kl9q2qVKSrylxgD0urqVHCWFl3B8NzwKjCXYywt+moEF6EXD/nIFuioHvvrjZ74dq4 COyilWJHHpo2PTntECJylnDQUpLNi0uC7dEPEfgfYs4J94ZGcnWPHtANxnJOR6bK+ZPD fX8mQFQGFgKRgySvkzw0xs3FRowwgd9aF1mrTOqiXPFtj+cPE50GyDlOgNrBelN7esFS 843ooQz7wvle/IZJe3eHMOy7wjN8L/NmiJJby6/44yro8owB8wyhiCF5uqZtcfu3BtNc tAOWpVQvSzkv1Z6AVnb1VFyLURI4mptK2uZwM7aO2jkPVHUKYUDwmDXlHHYqVJnHUXN5 tFLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dGqwsw/SIIdqWvaKeKwu/tVA9A1cy1/HMgE5QohgKlU=; b=xgkiVVOhRWFyNOFnRn6FEkoCZvW5A/fPz5SPdExtsc0bRcHwfgt+20hAb93mLHApln X4BveRawoDoMfaJo6SV4VM/2I9x12CYYgOX6O2o1aKAQvw4xEP0jnfiFeVTdLU+8Qx+Y Ru4x+L/DXvB4qsd6JoYcXUv3b6ZoIQPYpb+a/Q8BM2iScf1hEEvM0H0Bcw7ausIemFWY Mrz8WMqpVdcEhcKjW+SFvCT6qivr2JKdMN/krOeN/QUrZ8O4mLvpjL/UbjUXv1PMhw40 qyCtHEnQSfbowHjsDXumaVQ8NENVt8U2NRbh8/VSCdn/97FgCIazfC0e3T1d3ckry5aQ jOfg== X-Gm-Message-State: AOAM531SQFsNKNR2SYnqScYrOtSTubUmjZvIdOSM4HhcsMfuLbrf/rv5 g3jtN/SRkNiobha9bfM3ay0Jjw== X-Google-Smtp-Source: ABdhPJz/JwlWWdFL4Jpz/lZX4PtnvXc+0OjTxMyF4j9YepvyHlXwG6prmSxMMLgq/8ne80iSJ/I4BQ== X-Received: by 2002:a63:cd58:: with SMTP id a24mr13919898pgj.15.1640574333060; Sun, 26 Dec 2021 19:05:33 -0800 (PST) Received: from VincentChen-ThinkPad-T480s.internal.sifive.com (36-226-186-250.dynamic-ip.hinet.net. [36.226.186.250]) by smtp.gmail.com with ESMTPSA id n14sm12818917pgd.80.2021.12.26.19.05.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Dec 2021 19:05:32 -0800 (PST) From: Vincent Chen To: anup.patel@wdc.com, atish.patra@wdc.com Cc: palmer@dabbelt.com, paul.walmsley@sifive.com, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, Vincent Chen Subject: [PATCH v2] KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR Date: Mon, 27 Dec 2021 11:05:14 +0800 Message-Id: <20211227030514.1426-1-vincent.chen@sifive.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211226_190534_045911_0BF61BC8 X-CRM114-Status: UNSURE ( 7.51 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 C [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42b listed in] [list.dnswl.org] X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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 421ecf4e6360..18e7a979740c 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); }