Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp1832282rdb; Thu, 17 Aug 2023 03:32:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEl6BRTIWRxKkFscgdplfqPxWL9i92m2p008ZDh3IL8QuObOouaaeOITkWwqdnsXuclicsp X-Received: by 2002:a05:6402:494:b0:523:3f1e:68c4 with SMTP id k20-20020a056402049400b005233f1e68c4mr3920964edv.34.1692268378436; Thu, 17 Aug 2023 03:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692268378; cv=none; d=google.com; s=arc-20160816; b=SQ3ZId/7C2xxh5SnRHYGbdnnKLfJ1yQqNaTDdazTVJSX5ncQoCHmSd2EdpMxXYyRTX PC/rKxTc7yBYz1KcKhja5uZYOgnmo52W6cVX0ymdArs7J+Q51ZsEndEQMTdKa6Y8UgXu e62IYpsDZk1Vv5Rkjb94XssM+JXpwfGE2ol5Se2whq+tWuSricVowhjrCtiEb4izAb3x g++v9zfFoUXc0g3ohxMcSJSdtaHrdfTl0JMogeh1f9ha7MTD6xyrOq+IMhXT7ffc7Fjm F1YRL3kLCScc7dXBvRfjxcqNF4JJRxeadWDfqSuFZAQVUWB3gzafjy++2IWRqjc9yXsr Hn6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=Y4/X/fwF2WJ056ifS7Fb5uYthusOzf45wlhB/UMcTW0=; fh=NHp5wDEIFClwe9WhFz3etp1idycoE0VYhAX33qCrjvU=; b=TrF0JO6n2MLL0fv/NyNUgnTUl0pdEB1YJ6jARG67Fn2yAb/sakbngeoEDdt2G42Djr nXlhIuP6EMjE+O5oeEUpNeUWLFx2aQwsB4DU0JGuiOh4WFptSrQVV69P9yLg4yAGNV42 LeFgz3ggMSUniDqlVEmrjTGkQ+VN2IAcVua28YwWHx1P9UyVJoTniZu2ltjriHi9Yak8 TeJ0aUqXGpLybcMjd8cr8ZSzfD7wY9cJs4gwn2eNfccWGFLp7we09RAM8F2SIsxzBwVy hsQBehgmeHJkCrksL5wHM2IK3Safg9EecPft3vZRY58BEiLpD9rp4/upGDotVN9Y/ZUV VEjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OnxVjs0p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc3-20020a056402204300b005255da75263si6830691edb.224.2023.08.17.03.32.33; Thu, 17 Aug 2023 03:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OnxVjs0p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348890AbjHQI2F (ORCPT + 99 others); Thu, 17 Aug 2023 04:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348982AbjHQI1x (ORCPT ); Thu, 17 Aug 2023 04:27:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556B630DF for ; Thu, 17 Aug 2023 01:27:44 -0700 (PDT) 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 E835061522 for ; 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") Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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.