From patchwork Fri Feb 10 14:27:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajnesh Kanwal X-Patchwork-Id: 1740489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=QaLWA6Hd; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20210112.gappssmtp.com header.i=@rivosinc-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=3mSFr7TZ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PCwzy1ML8z23qt for ; Sat, 11 Feb 2023 01:27:26 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=0fEzcVSqj3NVF/0+jUeQ9cxOrQ8lL1HLzIgjYlVdSkY=; b=QaLWA6Hdx222xK C6fVYp22MsuxjFpZiHO+GzqCl7HMz4GvbsToj6JaCjgMltA/781lc6KhxyyKJ2X6IbibUYJkzRbs1 JaSlvlOa7ghwy7h2DUx64KhveELy1BuwGcrSvgjdDZQdAJVE4c+pxK0pbTUnynMJTuZFbjPhik6CG c0U0EPXJfrLzdSsRTSzATtlt6G7AWH5t7qqwr1hkN4iY8UWS6LzpIk1RgQHfe1HU2EIADicFSHbgJ 13BEBgjBpcAMeuez+dbJ+zs15KL2EAXlH/ddWYAuq7ZUZhAlXRWHPx5DEL7xsFdFNrs7+twvoY3b8 jl6LpjABYYbE/B3CVDcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQUMz-0062KX-Dc; Fri, 10 Feb 2023 14:27:21 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQUMw-0062J3-91 for kvm-riscv@lists.infradead.org; Fri, 10 Feb 2023 14:27:19 +0000 Received: by mail-wr1-x42c.google.com with SMTP id y1so5253470wru.2 for ; Fri, 10 Feb 2023 06:27:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ceHLeqJb/8JC46v9fimPjQQwYVOelzaxlpfKlrdams0=; b=3mSFr7TZiIW7nwfOpoLLswRG9WNFL8JDi1jk9+/T63+a7gMH3vJqvEyLoBVdTZZfiG epkFXDb82SBfTr6eEabrcbpf9x0fJ7P5IroYSeE3SM8SGN1BxNx7nGuE93Kajt7hK8YA ETvf4C3ci3UXi0al3h9dS5AMIQVzmaTwPo2uMk8uTZRIEInFVVlKjo34bgMyxbYZ7IH/ h+vCFY4fG76yJhWzPnzS7KjHvTG2kDuHDXV/womDoH9x3a4aIB+grdQwxA0rKtkDbe7E 0Ys8ZDkanJtP32iHJN93nv2zYWPZh47/FYYkp24fgF+P6Xh4+P3BUGE++jgpdwT5ls21 zFCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ceHLeqJb/8JC46v9fimPjQQwYVOelzaxlpfKlrdams0=; b=X/Ota7jiiQ+toGyCmZugEfm8N0WoPmIqFY7/p8d4Rf3f0b2S0PSdeTi0m/df9nFMey gGG4S6cjAM/tfgKLAIxpfT0sLr5rZUkto5lPoMheXLVcr8oEgLwtdRi6FW1Xj+4LjaR3 0+689n25K2Z0lOtfD2ZVStLHhETKpQu1v7xTG9PLi33I+7zcs3WtPMJqhmwSgLe20LQQ iiiD3CyGw7f9nihLD2sfAJoRW1k8+1rO6JWti03KWmKhWDjq3JhNdFTGqP/vMXQ9xpmZ f5cj0Ip3OKGjfFI3cSIsLSoLwz/9MvtQsdv/70JppGg6iq/Oj1y1UpNdg8AGn6fHY+Ty rebg== X-Gm-Message-State: AO0yUKUo++Vi5/oTUp68gQ1VFlFT+cNVhMoQj0cOcZOpNzryniTt+AHF s+FXw8KeDI0iDOhH4G4Ps+XhQw== X-Google-Smtp-Source: AK7set/Jbyl4v9fxcipnYs583qTKV9G6tdJI07ELZH8BUsyvkjhq67DR+Hc4GkvinyCHgpeLZqPm2A== X-Received: by 2002:adf:f590:0:b0:2c5:48ad:d352 with SMTP id f16-20020adff590000000b002c548add352mr2339253wro.14.1676039236031; Fri, 10 Feb 2023 06:27:16 -0800 (PST) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id j7-20020a5d4487000000b002c3de83be0csm3963968wrq.87.2023.02.10.06.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 06:27:15 -0800 (PST) From: Rajnesh Kanwal To: anup@brainfault.org, atishp@atishpatra.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, Rajnesh Kanwal Subject: [PATCH v2 1/1] riscv/kvm: Fix VM hang in case of timer delta being zero. Date: Fri, 10 Feb 2023 14:27:11 +0000 Message-Id: <20230210142711.1177212-1-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230210_062718_340255_DE111BB8 X-CRM114-Status: UNSURE ( 9.80 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) 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: In case when VCPU is blocked due to WFI, we schedule the timer from `kvm_riscv_vcpu_timer_blocking()` to keep timer interrupt ticking. But in case when delta_ns comes to be zero, we never schedule the timer and VCPU keeps sleeping indefinitely until any activity is done with VM console. Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:42c listed in] [list.dnswl.org] -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 Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In case when VCPU is blocked due to WFI, we schedule the timer from `kvm_riscv_vcpu_timer_blocking()` to keep timer interrupt ticking. But in case when delta_ns comes to be zero, we never schedule the timer and VCPU keeps sleeping indefinitely until any activity is done with VM console. This is easily reproduce-able using kvmtool. ./lkvm-static run -c1 --console virtio -p "earlycon root=/dev/vda" \ -k ./Image -d rootfs.ext4 Also, just add a print in kvm_riscv_vcpu_vstimer_expired() to check the interrupt delivery and run `top` or similar auto-upating cmd from guest. Within sometime one can notice that print from timer expiry routine stops and the `top` cmd output will stop updating. This change fixes this by making sure we schedule the timer even with delta_ns being zero to bring the VCPU out of sleep immediately. Fixes: 8f5cb44b1bae ("RISC-V: KVM: Support sstc extension") Signed-off-by: Rajnesh Kanwal Reviewed-by: Atish Patra --- v2: Added Fixes tag in commit message. v1: https://lore.kernel.org/all/20230210135136.1115213-1-rkanwal@rivosinc.com/ arch/riscv/kvm/vcpu_timer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c index ad34519c8a13..3ac2ff6a65da 100644 --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -147,10 +147,8 @@ static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu) return; delta_ns = kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t); - if (delta_ns) { - hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); - t->next_set = true; - } + hrtimer_start(&t->hrt, ktime_set(0, delta_ns), HRTIMER_MODE_REL); + t->next_set = true; } static void kvm_riscv_vcpu_timer_unblocking(struct kvm_vcpu *vcpu)