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 3F079C2FC14 for ; Thu, 17 Aug 2023 08:28:14 +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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W5YSXPpv/a8HzjQnVcB8GjoqERe15ZI3b5GGBsH9jus=; b=1sw5+5J8pxhUOz EUFyXGJynwIVaIuWSwvuNArSOqOb41pHzh1U76spYgaoEoH0/T5QLvK4LErZwEIbfcvlWGgKyrPQo ZqW2Rj2Wn6rWsv675MskpXPsiHFOcalPQTve5gMQ2uc4w2tcNcG+x44vUuHFvXvE/8jPOjd4QY+lH Rzo96P85Bl6WYJ1QOnypYH59yBFRF1KYkpi6zqLn2haH+pmkqmaERO19kkJs04XiYOuU/CLuBGYqN ZHokmWfqzwshyyHfBsKycaCPeGYho+Huhvn+lGybH3YPzdDjNrwSpVcO67ZQbPSLPO4+0gLQVSYLr q5KwRUNlM9A9IX/m+nww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWYM7-005ovp-2y; Thu, 17 Aug 2023 08:27:47 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qWYM4-005ovF-37 for linux-arm-kernel@lists.infradead.org; Thu, 17 Aug 2023 08:27:46 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EB36F6261C; Thu, 17 Aug 2023 08:27:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53FAFC433C7; Thu, 17 Aug 2023 08:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692260863; bh=p/0DYIT5ytk/yeTl/K301RDUBvQtBHXWLb7M8QUZPP0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OnxVjs0pTyk2aoIqU3J3O4uFUy8UnL6mnOSTIySnHCqtt9coMqcdFuhHMeZEfjpjW 154dVeAfjzIrlMWrLpmpBGDo6Lt3WkpuMCXLwAvfEltzbkVrq8jF3NSjQPt4dyqZEw w8nayRdkr1NOWactALA9Qjor0mdevJxv7NeAXmHN8gJ2Q9pc8qYqrMGKr1nyJUSsYz tiBwjdvoVBsaSlACorBsVvKgSg9lj585zQ36TIGwtaD3cECYhwFJC/N2IzUxqgGZGy rUQ9RzHwxx5g6M2DjE+lTkzUO6SaQEodDEYZZGsTuKO1pthD57VX+boukv5fyiGF4R Ry9Tfs4E2pj5A== Received: from 82-132-234-11.dab.02.net ([82.132.234.11] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qWYM0-005cc8-Ps; Thu, 17 Aug 2023 09:27:41 +0100 Date: Thu, 17 Aug 2023 09:27:38 +0100 Message-ID: <87bkf6oyyt.wl-maz@kernel.org> From: Marc Zyngier To: Ganapatrao Kulkarni Cc: linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, eauger@redhat.com, miguel.luis@oracle.com, darren@os.amperecomputing.com, scott@os.amperecomputing.com, Christoffer Dall Subject: Re: [PATCH 2/2] KVM: arm64: timers: Adjust CVAL of a ptimer across guest entry and exits In-Reply-To: <20230817060314.535987-3-gankulkarni@os.amperecomputing.com> References: <20230817060314.535987-1-gankulkarni@os.amperecomputing.com> <20230817060314.535987-3-gankulkarni@os.amperecomputing.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 82.132.234.11 X-SA-Exim-Rcpt-To: gankulkarni@os.amperecomputing.com, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, eauger@redhat.com, miguel.luis@oracle.com, darren@os.amperecomputing.com, scott@os.amperecomputing.com, Christoffer.Dall@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230817_012745_115772_9FF2FF95 X-CRM114-Status: GOOD ( 16.14 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org [Fixing Christoffer's email address] On Thu, 17 Aug 2023 07:03:14 +0100, Ganapatrao Kulkarni wrote: > > As per FEAT_ECV, when HCR_EL2.{E2H, TGE} == {1, 1}, Enhanced Counter > Virtualization functionality is disabled and CNTPOFF_EL2 value is treated > as zero. On VHE host, E2H and TGE are set, hence it is required > to adjust CVAL by incrementing it by CNTPOFF_EL2 after guest > exit to avoid false physical timer interrupts and also > decrement/restore CVAL before the guest entry. No, this is wrong. Neither E2H nor TGE have any impact on writing to CNTPOFF_EL2, nor does it have an impact on CNTP_CVAL_EL0. Just read the pseudocode to convince yourself. CNTPOFF_EL2 is applied at exactly two points: when SW is reading CNTPCT_EL0 from EL1 while {E2H,TGE}=={1, 0} and when the HW is comparing CNTPCT_EL0 with the CNTP_CVAL_EL0. In both cases the offset is subtracted from the counter. And that's the point where the running EL matters. Which means that CNTPOFF_EL2 behaves exactly like CNTVOFF_EL2. No ifs, no buts. The behaviour you are describing tends to indicate that your HW is applying CNTPOFF_EL2 to CVAL, which would be a gold plated bug. It doesn't mean that the KVM code is correct either. I'm seeing pretty bad behaviours on a machine without CNTPOFF_EL2. But what you are suggesting is IMO a misunderstanding of the architecture. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel