From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 706C7C8303D for ; Fri, 4 Jul 2025 15:39:57 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=G+Sb8ybeToB+ZZ+ddW/bGRTsIfZ2wQQtHjaRTeD5wXw=; b=WANQ6u36g4nu39 kAsvi7/iu6G84YjtzjibBYf6pvtIiXiD3AjzigrNWX2SwI3UcDcrtXeXZT8V1igw+TnDttpqxOhSA SALMH5NFn23NmUaSLzAdyxnWQbpfNdBHRjrWZSq/3EXHdMXagfQjqGsbxSTXQOIS4oHLxvsfRmhq7 DFmEzo6d0CXo7OwuBm66qmFtgx44cP/pA3eHaqFS2GCXVE0UKOegsu13tvYaFlKduJMt7jgxJoNhi siqOboOgc2hHM92Rmhj4H0SFuSZYYFrOtBBC6Hs4wTAPbr/p6YO+1NeCVS9Oll9WbZRSmL0CJfArY yBiorpxmrWYuGu0ddTpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uXiW5-0000000Eqrh-0uzq; Fri, 04 Jul 2025 15:39:57 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uXiV6-0000000Eqcv-0UC3 for kvm-riscv@lists.infradead.org; Fri, 04 Jul 2025 15:38:57 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-747fba9f962so883100b3a.0 for ; Fri, 04 Jul 2025 08:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1751643535; x=1752248335; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zp7uD1poiW059gGzU86bprSx2F9Pa7gwCpaEXnEz8mU=; b=Kwbn9sg/CqprvKLPuaPfmZvFgOmrRaex8WRCDvudqzCU52vf7PaqdrxYnG6Mp2UsX1 p3j+APsT0Ie70zsRZ9QqnZkhpUyXExJR2PDk6xj8QHC+qm79jY+QG3aVFBwoWg+UcHJE Wf1FCF38BUiw7rL4WBIS0Wtc4VXNfWS7DJ5BSzloz5KZaY/rAjfUWd6A3LC2PU/N9AQi iqPc2AiGCZPYGDSjh9f9TTeQvhmwj0Qzzcf3OPLb0aBR8zKNUr/HmnU0uABoxxi9sc0O eTG80umyNX3Ld8/xqwkiIB2yaPInFZcKKzApAOGGAfOHaTo/yMpAaNGOPR4eZw3UH7Gk h9ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751643535; x=1752248335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zp7uD1poiW059gGzU86bprSx2F9Pa7gwCpaEXnEz8mU=; b=DWQwz3Jgq+N70Rj27WnEP7Cwbzjh3N0R/5vtwRe2Q4+mFVh6qPjogj3nIVktAzqENJ hRY4/1/TEHfg2myX1GoSgjaTz2wJiECAQHccW1K0BW1ws55w24vFH1V9DmdC9fTWHtQK +ldJGtAr117jW/THIEyrsY19xXdE7PwRRo/36zi6lQcx+Ebm/cxTwW3uIrr8zjrT5XPb +APhkcYKo9tqMtlDD5ow4XeSxywlXoAPSXywTvzTKdr+ZjwxqOg/cKT++/kbJFlwOeYd gMVWX4IoDkcgP/noOv5igeGz9KqPUM0FGa/hJaUm2VImaIiB6X8koKLASNAjpn7pwbdx xEFw== X-Forwarded-Encrypted: i=1; AJvYcCU/2y8WRFlP82sFsazmB8nKxeVqQ6f9wDBNgYGBWF8VL025/qb0Ix2AZOlllqQSVH/4/pWPm9EOnHQ=@lists.infradead.org X-Gm-Message-State: AOJu0YxVcMCCq27gSYdzjZ2t1dy6rp7/HFIJW4noYDEUGOnJ0/PH35nO tqxMMhDTd6sIZKxPni9XkPX6zVdFus6w8QSHS4uh3uFHBZE5TSPi+vYkwtBGpsH4m9oN3hjGHq9 ZWPSgqBw= X-Gm-Gg: ASbGnct0tqB3qi04gpE1A1PoLqB3+ScmxLuh5yXHUyExOXacyQtgglOnnJlFb9YvC/3 HGiybynuXdN7CXziJW8UKKyszSbojKVlee1RwRgE0xMx70W/UWvJ2YjsyoVLevVsCE9gU0KQmRp caIX4RuQhnMqmig8+ws727s3/tWyEJesYeACjDbKPoztervPRUf7zzJHZGjFF9BgHEbRB9evxm4 bCjEc6IyFEGyG14uXk3Ne5tAvNTBshAtFhKMSpwb2kOARmE+6RY5qelZTfj+H0jCz7DhdzVm+Qt BDJROERNb8wJlrsZdzfnEI62YxYHBAxoMUv5jxwqG9ArcOVq8X292EnpdHrmSK2KNyW4YUlm2XX CJKDxHx3V3OwoANHAeac= X-Google-Smtp-Source: AGHT+IGIXVrx9PSDrG3EEvpjwpw1PdozZsTf2OUe+pqrmlHyZJisYpgboZx4tCy5PCWnKNZpHdxUDw== X-Received: by 2002:a05:6a20:a11d:b0:220:3804:f3d6 with SMTP id adf61e73a8af0-22595173066mr5303101637.2.1751643535243; Fri, 04 Jul 2025 08:38:55 -0700 (PDT) Received: from localhost.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b38ee63003bsm2084818a12.62.2025.07.04.08.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:38:54 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alexandre Ghiti , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , Heinrich Schuchardt Subject: [PATCH 1/2] RISC-V: KVM: Disable vstimecmp before exiting to user-space Date: Fri, 4 Jul 2025 21:08:37 +0530 Message-ID: <20250704153838.6575-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704153838.6575-1-apatel@ventanamicro.com> References: <20250704153838.6575-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250704_083856_157213_2095B3C0 X-CRM114-Status: GOOD ( 10.01 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org If VS-timer expires when no VCPU running on a host CPU then WFI executed by such host CPU will be effective NOP resulting in no power savings. This is as-per RISC-V Privileged specificaiton which says: "WFI is also required to resume execution for locally enabled interrupts pending at any privilege level, regardless of the global interrupt enable at each privilege level." To address the above issue, vstimecmp CSR must be set to -1UL over here when VCPU is scheduled-out or exits to user space. Fixes: 8f5cb44b1bae ("RISC-V: KVM: Support sstc extension") Fixes: cea8896bd936 ("RISC-V: KVM: Fix kvm_riscv_vcpu_timer_pending() for Sstc") Reported-by: Heinrich Schuchardt Closes: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2112578 Signed-off-by: Anup Patel --- arch/riscv/kvm/vcpu_timer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c index ff672fa71fcc..85a7262115e1 100644 --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -345,8 +345,24 @@ void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu) /* * The vstimecmp CSRs are saved by kvm_riscv_vcpu_timer_sync() * upon every VM exit so no need to save here. + * + * If VS-timer expires when no VCPU running on a host CPU then + * WFI executed by such host CPU will be effective NOP resulting + * in no power savings. This is because as-per RISC-V Privileged + * specificaiton: "WFI is also required to resume execution for + * locally enabled interrupts pending at any privilege level, + * regardless of the global interrupt enable at each privilege + * level." + * + * To address the above issue, vstimecmp CSR must be set to -1UL + * over here when VCPU is scheduled-out or exits to user space. */ + csr_write(CSR_VSTIMECMP, -1UL); +#if defined(CONFIG_32BIT) + csr_write(CSR_VSTIMECMPH, -1UL); +#endif + /* timer should be enabled for the remaining operations */ if (unlikely(!t->init_done)) return; -- 2.43.0 -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F26D62DE6EA for ; Fri, 4 Jul 2025 15:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751643539; cv=none; b=kPPm3UuUcfc2soxim59hr+mFUWZGqIdFWJuAMPLJ5oCaSQeRZDgKTWQhY4VyzUVzz+AXqyH95dpN0YMJC7V7YCmIYxPCqJT0k+NcBz9F6eUDhDsttnpLp52IhEedtBCOKGF6SI7QAUq1VmbfSy/DHzeKKrlFvX93KutcPS+8aHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751643539; c=relaxed/simple; bh=Rn0ct3v4rW64OlY7++1Oc0LAQJA4hk8QYtJnzRwiqYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sbpaVVSxss0ptrDQtbw9cSK4j5qzjX/f4gzQ2oD0AkPPuVEBTiMH2WB8UeqodmXZx0J4ny8DqGm4ayJlPZzuUB0y6C50uWi3Dy8ZbuhneiJWiuwO0/Gzx5TcFI9sjc4f35Syf7K8ZqSalsF2RhOlyh9YZPxRSfwCuXuWJln6EuQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=HHCkA/GO; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="HHCkA/GO" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-747fba9f962so883113b3a.0 for ; Fri, 04 Jul 2025 08:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1751643536; x=1752248336; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zp7uD1poiW059gGzU86bprSx2F9Pa7gwCpaEXnEz8mU=; b=HHCkA/GOZXOkxIV/OVBar8WxFX4UU10HhVy9r1NiTIpqR8B8PYIbuhF7WHfM517tCp QovJGsdJqljBllpUi5QprabMLvxVssEt7xCRxC5KiOysrYPrZyUFkH3veorfgko79Q4h 99hr5MbjdSxCTsUsfLT9TagYoFUUuwwVs3NFXiXItEQdywEG/AldsZNOT5RqKqjY+UN5 jgFigWf2+j+3brebVCPZF55prJwKPNvqSI9D/hZHCU8jreqUpqdOlNe8G2cOa4bX0nnt WUFcfiBhZLG3XtyLGKsOhYPxy0I3Cytof/cVKEAZrCgeNuuwH/o4HN3+Ey2Hl1ybF7XO DjlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751643536; x=1752248336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zp7uD1poiW059gGzU86bprSx2F9Pa7gwCpaEXnEz8mU=; b=dDzhbmXWnD8I5adKHxREQExSzGBRD97n/wFiVykXIMPqrF4uduDvniX8KyDNnsYcH9 aeaaQR3JJNbDL8T1pYd+fPYFxHN0hiVMwnlEEKzsJ1ObCSr3oPSowRfBQCmvefkiIdC/ pCTuESJ5HsQPFAW9URLoV5qTm0B8jbx+MqXainCh47fSDpuiu6Z75MpqtpQiBjd5BpFi Lr7qR4fcGw0VxAtMqD6XnSPyUhlwpkUsAU2psbqX49eimhARPjG2/IWtq0nTMiWRsX9S a59bn9PpnGrCiPCF213pZNGh1dP3cAPbjNw0/n4E5eUEToZ4oq3y6zzRovjeTvNy4h5H n1Tg== X-Forwarded-Encrypted: i=1; AJvYcCVLvIrjUts6iGFHHF3Gzwx7PXExJx9JGiwFSxE0Y+E0gFo/bvbalAMpA3p2dJTriTovscU=@vger.kernel.org X-Gm-Message-State: AOJu0YwPOUn7elrSdPDOlG0GY+MNj2B8G+uebzddXTj06wnNrp2a9PnG JnaXXfux9ALGobFYhbkOx/AA8QLMBVhPkYpEnb8H0q/0lQf4zBHxBW6TDh1NkInLLAQ= X-Gm-Gg: ASbGncsIjGABxyWJQhq83ELiwZehx6M6wGbpWT8I7c6Qx4AWcGTAooKV0gSziOGDHc9 x+8D/b3AffKTr6xc6nGjlTzvivGhP+jDweXQBYamTahti9rj8BW2Qn+I52YhK/4KY4jQdS+upGr hPzR1uEQeLSoAG60PUAg93la7tCKAstmnmkCGUXch74dprUWAZ4kf2kMXk1naEPzz23cDa8bhdh qUW687yyJH39/BT9KM/o8DVrE/fTSOkXRSz7GgUXbkFTst0LSAjF+RZz7iGNYgvmcCd6A4G1ngN nfrPsRLDwIEXtqRDg09WkHUFIVJCF6iUycHcXjcw11zhctIdzwPVKpdTnszZhcMtSKvZQ9OZ9A7 Wtgv24NqNiyWk6ZaMqw0= X-Google-Smtp-Source: AGHT+IGIXVrx9PSDrG3EEvpjwpw1PdozZsTf2OUe+pqrmlHyZJisYpgboZx4tCy5PCWnKNZpHdxUDw== X-Received: by 2002:a05:6a20:a11d:b0:220:3804:f3d6 with SMTP id adf61e73a8af0-22595173066mr5303101637.2.1751643535243; Fri, 04 Jul 2025 08:38:55 -0700 (PDT) Received: from localhost.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b38ee63003bsm2084818a12.62.2025.07.04.08.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:38:54 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alexandre Ghiti , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , Heinrich Schuchardt Subject: [PATCH 1/2] RISC-V: KVM: Disable vstimecmp before exiting to user-space Date: Fri, 4 Jul 2025 21:08:37 +0530 Message-ID: <20250704153838.6575-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704153838.6575-1-apatel@ventanamicro.com> References: <20250704153838.6575-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If VS-timer expires when no VCPU running on a host CPU then WFI executed by such host CPU will be effective NOP resulting in no power savings. This is as-per RISC-V Privileged specificaiton which says: "WFI is also required to resume execution for locally enabled interrupts pending at any privilege level, regardless of the global interrupt enable at each privilege level." To address the above issue, vstimecmp CSR must be set to -1UL over here when VCPU is scheduled-out or exits to user space. Fixes: 8f5cb44b1bae ("RISC-V: KVM: Support sstc extension") Fixes: cea8896bd936 ("RISC-V: KVM: Fix kvm_riscv_vcpu_timer_pending() for Sstc") Reported-by: Heinrich Schuchardt Closes: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2112578 Signed-off-by: Anup Patel --- arch/riscv/kvm/vcpu_timer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c index ff672fa71fcc..85a7262115e1 100644 --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -345,8 +345,24 @@ void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu) /* * The vstimecmp CSRs are saved by kvm_riscv_vcpu_timer_sync() * upon every VM exit so no need to save here. + * + * If VS-timer expires when no VCPU running on a host CPU then + * WFI executed by such host CPU will be effective NOP resulting + * in no power savings. This is because as-per RISC-V Privileged + * specificaiton: "WFI is also required to resume execution for + * locally enabled interrupts pending at any privilege level, + * regardless of the global interrupt enable at each privilege + * level." + * + * To address the above issue, vstimecmp CSR must be set to -1UL + * over here when VCPU is scheduled-out or exits to user space. */ + csr_write(CSR_VSTIMECMP, -1UL); +#if defined(CONFIG_32BIT) + csr_write(CSR_VSTIMECMPH, -1UL); +#endif + /* timer should be enabled for the remaining operations */ if (unlikely(!t->init_done)) return; -- 2.43.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31689C8303D for ; Fri, 4 Jul 2025 15:40:04 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=hT8pZ8I49V6CaRBxus03WgZ4PgeboidJHqFR8zQhdIQ=; b=MMCS1UADkvh0nW RhqiW3gI2NcD4TsMn+/Joxhn26AWpzh6r5aLel7GNQuEL7G/egZ1lHhoxlz9uo7u2rv8w/LONVzy3 YboBszEAB3aqi6wBDcpeTe9i+uBGKENj42QZF8UpD8wEMgj3EAcw1mcZ2r/rarzA/L39FTA0A2TM1 YctFZXKFIRiUPROOtiS62HPXfgvuhcI2NV/e34Azb479sy8v8a1hlJdmuQ6kRDfT0k4Q0JJYECbIW J/xbqJga0dc6Bisrc5sQp8xM5nY3vBuihZnwzRo35A+DEtitorEx/IJG6/QXdud2xKx0mDl/8fQNt pQU77jaZOjYYFEiUFsQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uXiW5-0000000Eqru-2MLk; Fri, 04 Jul 2025 15:39:57 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uXiV6-0000000Eqcu-0UHL for linux-riscv@lists.infradead.org; Fri, 04 Jul 2025 15:38:58 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-747fba9f962so883099b3a.0 for ; Fri, 04 Jul 2025 08:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1751643535; x=1752248335; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zp7uD1poiW059gGzU86bprSx2F9Pa7gwCpaEXnEz8mU=; b=Kwbn9sg/CqprvKLPuaPfmZvFgOmrRaex8WRCDvudqzCU52vf7PaqdrxYnG6Mp2UsX1 p3j+APsT0Ie70zsRZ9QqnZkhpUyXExJR2PDk6xj8QHC+qm79jY+QG3aVFBwoWg+UcHJE Wf1FCF38BUiw7rL4WBIS0Wtc4VXNfWS7DJ5BSzloz5KZaY/rAjfUWd6A3LC2PU/N9AQi iqPc2AiGCZPYGDSjh9f9TTeQvhmwj0Qzzcf3OPLb0aBR8zKNUr/HmnU0uABoxxi9sc0O eTG80umyNX3Ld8/xqwkiIB2yaPInFZcKKzApAOGGAfOHaTo/yMpAaNGOPR4eZw3UH7Gk h9ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751643535; x=1752248335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zp7uD1poiW059gGzU86bprSx2F9Pa7gwCpaEXnEz8mU=; b=CgCDM93eHoQhoJAxCk5zg7/1xWzUkrfXyB7FKeRsG++Waqay0PWyeuhKD2sFf+lXbh 4dmtAkdV7aIJqAqYIFPv3d/9OM2/B7MOr1kAO/+mlnIEnAmW59lQGdR1bDEfECcVrITA aCY1sjP0gCjfX6vDimtxTepE9jmJxf5uRuIang6RZszBvtYje6eeplJo33sT1LlBXPe9 krcA88xmw95WcAzIEm4nZlHWXt2Li6+kl7QK7FnvocjSqQeFWWiCnBN+A66DG1SFKPk+ drMety6CXVaKO9QGdYCtnJFo/6pNGAe2mk1IaybbWDX1dj/5ZEs8Z0MCOCYc6cK7qNll xGyA== X-Forwarded-Encrypted: i=1; AJvYcCXF+NiMplPqNdfT+AJJylWViuLHAT+20tRShjHG8Hm6HNsWxmyKvbAI/krwQVG4NphZoDr8hw4d8hL5UQ==@lists.infradead.org X-Gm-Message-State: AOJu0YyBOQWNK8/nAd6EOYB83mWxJD2YfL2Z0HpoM6fm5MlwSH/Gptre rCoHAtR4nisZGj4yoNWDcoTqIodqQerPiFRVMI6ydJuOFGmNSfbZI8c4F9QpZrKKHnY= X-Gm-Gg: ASbGncuQTZZfucEUNOdbPRDycvEqucDnrTcokF9sLvAjheRPkHvojN7ZYACSDltucR5 +ENXGjOj3IglOn5+d+Ud5j7lI3+nMyzMSVJyuSE4wYZnfpwORODGboKkOWK+6qWAGPmk1B9vVqG NaONeEf+B0u6/JNHIlRh25whfHf6Skzd22U2NWWghYO5uisjURZItfFyp/eYhcDdrZRIYoizHxu bW5liLm3MZpxg9OzbhlI6AH/1jFm1ZpG0XjaJB3QLgbb0n9XKrnDfSnsF66zAGuxfzhOLBOLut7 TqF89rlytMVdIFMc4dobT54jn6zIZ+ad9UeRisdpg3a0ZVVvM3a88boeVWvSmHricqrLZkXo6q3 suN9/Xr05JoQrjOMCl4E= X-Google-Smtp-Source: AGHT+IGIXVrx9PSDrG3EEvpjwpw1PdozZsTf2OUe+pqrmlHyZJisYpgboZx4tCy5PCWnKNZpHdxUDw== X-Received: by 2002:a05:6a20:a11d:b0:220:3804:f3d6 with SMTP id adf61e73a8af0-22595173066mr5303101637.2.1751643535243; Fri, 04 Jul 2025 08:38:55 -0700 (PDT) Received: from localhost.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b38ee63003bsm2084818a12.62.2025.07.04.08.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:38:54 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alexandre Ghiti , Andrew Jones , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , Heinrich Schuchardt Subject: [PATCH 1/2] RISC-V: KVM: Disable vstimecmp before exiting to user-space Date: Fri, 4 Jul 2025 21:08:37 +0530 Message-ID: <20250704153838.6575-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704153838.6575-1-apatel@ventanamicro.com> References: <20250704153838.6575-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250704_083856_156760_8B6FA712 X-CRM114-Status: UNSURE ( 9.99 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org If VS-timer expires when no VCPU running on a host CPU then WFI executed by such host CPU will be effective NOP resulting in no power savings. This is as-per RISC-V Privileged specificaiton which says: "WFI is also required to resume execution for locally enabled interrupts pending at any privilege level, regardless of the global interrupt enable at each privilege level." To address the above issue, vstimecmp CSR must be set to -1UL over here when VCPU is scheduled-out or exits to user space. Fixes: 8f5cb44b1bae ("RISC-V: KVM: Support sstc extension") Fixes: cea8896bd936 ("RISC-V: KVM: Fix kvm_riscv_vcpu_timer_pending() for Sstc") Reported-by: Heinrich Schuchardt Closes: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2112578 Signed-off-by: Anup Patel --- arch/riscv/kvm/vcpu_timer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c index ff672fa71fcc..85a7262115e1 100644 --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -345,8 +345,24 @@ void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu) /* * The vstimecmp CSRs are saved by kvm_riscv_vcpu_timer_sync() * upon every VM exit so no need to save here. + * + * If VS-timer expires when no VCPU running on a host CPU then + * WFI executed by such host CPU will be effective NOP resulting + * in no power savings. This is because as-per RISC-V Privileged + * specificaiton: "WFI is also required to resume execution for + * locally enabled interrupts pending at any privilege level, + * regardless of the global interrupt enable at each privilege + * level." + * + * To address the above issue, vstimecmp CSR must be set to -1UL + * over here when VCPU is scheduled-out or exits to user space. */ + csr_write(CSR_VSTIMECMP, -1UL); +#if defined(CONFIG_32BIT) + csr_write(CSR_VSTIMECMPH, -1UL); +#endif + /* timer should be enabled for the remaining operations */ if (unlikely(!t->init_done)) return; -- 2.43.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv