Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp915428rwb; Fri, 28 Jul 2023 01:35:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlERVxRfDHBpB+VY1P+qbHkVh8htUSZ1dyyLrsJmnsED2lQY4XQdEhlGMVTbLJ+D6l3AR0YQ X-Received: by 2002:a17:907:2711:b0:992:a85d:278b with SMTP id w17-20020a170907271100b00992a85d278bmr1320506ejk.59.1690533332279; Fri, 28 Jul 2023 01:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690533332; cv=none; d=google.com; s=arc-20160816; b=burphnIONFd8+azPB8f3bOhXKcpnGEVqdyj0lf1B7Jg/258uH/wl/72C71A2i7azIX /c/TXGaX3TEwmnSF7IPIECb69Y6Do7P1dw4/Nr2E0lSZDtOz0LnZGW/e+W7ybZ1hEB8h PrWxH5WalSdT4K1GOJOkLoRmfaGpmadUTy7h/2/f7zEp3nF814nV4C00zgPJeJI5d8FF 3kw1oqRm39g86nblaGhcRygLhz/OrPlzrqeRF0khAy62qLojBbU4F/n5nMR4cd9fD9q5 4BGJ0AETTnEypxpA5IOOtDAVU+ZZO48uw4exUFBzS8bFGC8lxw51H39niLuRdjDkrPMM LJPw== 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=nQ/jFqGaOrEG0x/gULxFpogudeuPZA7i5NaSGSI5ZnE=; fh=7Idcq50Kb2/e7v+HgR3GYv5FM+vrHImK6jR74EbkTLM=; b=rBpG3NC0+aW31cn/ecLogZjhX/ItjOAKKxayUvXqx3avERBlSI8w48lOcG4thPI+Sg oFMvGIh2lFVB+pTbL6/u573dtpGBCvdlC59JlMVxNYAygADTGcqhJ9KSYan7eZVgGuU0 gIGp75YHd8jErIL+5vPkpaJhq0BULNXm63aHZAmRHtqCwDvFNImSa75af0F+e1dPnog2 a0I9Y51gDkvT2mz7gHM2W3PQPU9zEEiKCu2zT9QrjbESguTtwgGrjlSWcmbSOP4V6k/g FizcL5moQdGX5d9+R6AacJZAa7/XR9k3aExpsSflrUlq4mZjboJuvUJdJ3hNF9ZV6a0g vFfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oe3m3yE3; 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 s4-20020a170906c30400b00992a36ceca1si2581555ejz.35.2023.07.28.01.35.07; Fri, 28 Jul 2023 01:35:32 -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=Oe3m3yE3; 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 S234759AbjG1IL6 (ORCPT + 99 others); Fri, 28 Jul 2023 04:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234709AbjG1ILb (ORCPT ); Fri, 28 Jul 2023 04:11:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6133AAA for ; Fri, 28 Jul 2023 01:11:23 -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 EFA1B6202F for ; Fri, 28 Jul 2023 08:11:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63C87C433C8; Fri, 28 Jul 2023 08:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690531882; bh=doFW1+C/8GMIgXMiabeS/f7ocbVsueJcERbaBXOV3hY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Oe3m3yE3SjTIG0W29iXhBxjiSWkrZ/di8Sloax8Ufbpg+5dCap2ob8B1O5GkeaZxs DWmOV43IYHTcTvAeEvPH46xnb2pBtGhZQHoc93wjMTTKEBcKl2aKSZ1SllavdmrUgY xVPY1Noa1Ofjh3TsJ2xIDZ2AD9b3qB/C8a/ceDaY9mu6giNGM65dWxWlQyyhAJrEen uEhOS8LPHKZHQ20G8SNFpzxl7hmCkaJpXfl1hrBBPFlECdDMjsN/VSGySUDTHzObjK W/wtWLAeS3Xiz0g0yINBkiu/SskU3neM6S2DfZd1sXlU9xiAgqr+/LoWv6fTLy8H33 SxzM5lcv3IgwA== Received: from sofa.misterjones.org ([185.219.108.64] 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 1qPIZD-00Haw9-Vc; Fri, 28 Jul 2023 09:11:20 +0100 Date: Fri, 28 Jul 2023 09:11:19 +0100 Message-ID: <87ila4qwuw.wl-maz@kernel.org> From: Marc Zyngier To: Peter Hilber Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland , Daniel Lezcano , Thomas Gleixner Subject: Re: [RFC PATCH 4/7] clocksource: arm_arch_timer: Export counter type, clocksource In-Reply-To: <0290012c-a419-40ac-ed8c-7708fc5a5dd0@opensynergy.com> References: <20230630171052.985577-1-peter.hilber@opensynergy.com> <20230630171052.985577-5-peter.hilber@opensynergy.com> <874jmlza3v.wl-maz@kernel.org> <0290012c-a419-40ac-ed8c-7708fc5a5dd0@opensynergy.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: 185.219.108.64 X-SA-Exim-Rcpt-To: peter.hilber@opensynergy.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, daniel.lezcano@linaro.org, tglx@linutronix.de 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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Thu, 27 Jul 2023 11:22:11 +0100, Peter Hilber wrote: > > On 03.07.23 10:13, Marc Zyngier wrote: > > On Fri, 30 Jun 2023 18:10:47 +0100, > > Peter Hilber wrote: > >> > >> Export helper functions to allow other code to > >> > >> - determine the counter type in use (virtual or physical, CP15 or memory), > >> > >> - get a pointer to the arm_arch_timer clocksource, which can be compared > >> with the current clocksource. > >> > >> The virtio_rtc driver will require the clocksource pointer when using > >> get_device_system_crosststamp(), and should communicate the actual Arm > >> counter type to the Virtio RTC device (cf. spec draft [1]). > > > > I really don't see why you should poke at the clocksource backend: > > > > - the MMIO clocksource is only used in PM situations, which a virtio > > driver has no business being involved with > > > > - only the virtual counter is relevant -- it is always at a 0-offset > > from the physical one when userspace has an opportunity to run > > > > So it really looks that out of the four combinations, only one is > > relevant. > > Thanks for the explanation. Dropping arch_timer_counter_get_type() and > assuming that the CP15 virtual counter is in use should also work for > now. With the physical/virtual counter distinction, I tried to be > future-proof, as per the following considerations: > > The intended consumer of arch_timer_counter_get_type() is the Virtio RTC > device (draft spec [2], patch series [1]). If the Virtio device has > optional cross-timestamp support, it must know the current Linux kernel > view of the current clocksource counter. The Virtio driver tells the > Virtio device the current counter type (in the Arm case, CNTVCT_EL0 or > CNTPCT_EL0). It is intentionally left unspecified how the Virtio device > would know the counter value. AFAIU, if the Linux kernel were a > virtualization host itself, it would be better for the Virtio device to > look at the physical counter, since the virtual counter could be set for > a guest. And in other cases, the guest OSes use a virtual counter with > an offset. The physical counter can equally be offset (and KVM does offset it), just like the virtual counter. With NV, the offsets themselves are partially under control of the guest itself. So either counters *as seen from the guest* are absolutely pointless to an observer on the host. That observer sees a virtual counter that is strictly equal to the physical counter. > This was the rationale to come up with the physical/virtual counter > distinction for the Virtio RTC device. Looking at extensions such as > FEAT_ECV, where the CNTPCT_EL0 value can depend on the EL, or FEAT_NV*, > it might be a bit simplistic. Not just simplistic. It doesn't make sense. For this to work, you'd need to know the global offset that KVM applies to the global counter, plus the *virtualised* CNTPOFF/CNTVOFF values that the guest can change at any time on a *per-CPU* basis. None of that is available outside of KVM, nor would it make any sense anyway. > Does this physical/virtual counter distinction sound like a good idea? > Otherwise I would drop the arch_timer_counter_get_type() in the next > iteration. My take on this is that only the global counter value makes any sense. That value is already available from the host as the virtual counter, because we guarantee that CNTVOFF is 0 when outside of the guest (well, technically, outside of the vcpu_load/vcpu_put section). > > > > > I'm not Cc'd on the rest of the series, so I can't even see in which > > context this is used. But as it is, the approach looks wrong. > > > > Sorry, I will Cc you on all relevant patches in the next iteration, > which I will send out soon. > > The first patch series can be found at [1]. I think the second helper > function in this patch, arch_timer_get_cs(), would still be needed, in > order to supply the clocksource to get_device_system_crosststamp(). We already have to deal with the kvm_arch_ptp_get_crosststamp() monstrosity (which I will forever regret having merged). Surely you can reuse some of that? Thanks, M. -- Without deviation from the norm, progress is not possible.