Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp575068rdh; Sun, 24 Sep 2023 02:48:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqOKCpgDAz3kaM+f3Yq1YjmUSyaKrK/q6NlxzZs8uX6ZujHt4BNlZI3BeaJY0+ZYAjGPjx X-Received: by 2002:a25:f205:0:b0:d80:8aa6:5abc with SMTP id i5-20020a25f205000000b00d808aa65abcmr3073074ybe.61.1695548936568; Sun, 24 Sep 2023 02:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695548936; cv=none; d=google.com; s=arc-20160816; b=YAKs451lsaeHSs84WfwFwpYC0U8C5G7nD6kRRU9nPnlTaDocyRoxzlbcTfB7COk2Ud 8M0NeLBAF3wQOLyF338Mk6c54fbOtYBYCbtVWkR12owFp617nPa6mNbDd6MAwqdLLj23 UqjJ4mAJ420pPeizbkK8nnlziWcutYLEbHRngL2Bdtixal5t1yKgUbcyY6KbA+01YyFC 6q1Yb/vSu1jlsI2evLZo8i3YMBbuzqCK8aQTRrHS/eXFVyj7JYoyewIItkSvUpL+wYhu Uq3TKtsXhypLEJdu29W+4BggXxpMniNiADCMlvw58AvgUem6TWtMy1/L1Rl0m/vcYquU tOag== 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=7Psb1e9dfGGUrzlJFngaomIEavB3bqwhpvtxB5cAF9U=; fh=k+eCuzdb3Me1VAxvC46zvg304hJsaqqFuxNtfV4vfuE=; b=Wvdzitqc1NjIl+tOfxz6tVin+TaXvS0qBBF7B8mfQoVog5d/qFO4co9AMFxIBwidv/ uenYOsBKLlAgAR6cR1PNEPrVJKiJoHnU8RYbbjBFbh9CvHZm1pSYa2N7bxu6wrnHB+MS j0JztnuY+5R7Ip+tqP8maTZuGmd5XzyTG5e+nXkStS1myNUIN6GpA42NMHDtXVJutcUE xFHsrik24Sh5fMxl4svaM4WJHJqyN8OaNMaURqJCZLqCSkBuwNoXZZjj67whD0ZBn/3J nkBLgFHQ0eyeR8UuVq3/ee4YAGjO3l6K+fDD+I5ChfI/wTTJBV0DUdt1auNwWg6fAAtc Djrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GPcFfcKb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z19-20020a63e113000000b00580e32f778csi1856631pgh.506.2023.09.24.02.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 02:48:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GPcFfcKb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3BA698080E29; Sun, 24 Sep 2023 02:48:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229487AbjIXJsz (ORCPT + 99 others); Sun, 24 Sep 2023 05:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjIXJsy (ORCPT ); Sun, 24 Sep 2023 05:48:54 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C7B7F1 for ; Sun, 24 Sep 2023 02:48:48 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B8E3C433C7; Sun, 24 Sep 2023 09:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695548927; bh=AzIkdfwzXD+T+Gna4WqEJFhKjFVAJriX5oQpitHh260=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GPcFfcKbd512J1G4iCQvmxZHCFALgWbCbXsu6UYm+2OERysWxhW7wcU7ANrj2JcUH sG/x2uXB9d/ZeduKnmtKwtgVbqNJI4v6/WPY6inZquoXrtcyPiLqQNXrU18XOr3h8C xFray+p8KneW2cA1AcNpPORJ1JjWt2pkqIdIv4tuDHKksASYlJG6O3Rg3RQO8ci18B vwEa41l6VK8aW6AZ8uOp2FR4Qjlh8/BXojWPwUwKBe6lWp2ElFlnBlqxxs6uvwYUlI WrGIIzyyTM4vgnDs0yKdhsOqmh7JvSQxq3GKOwDF8Jl2qAkRZIm2C6L3sCR3NH0Koi jvV5GpLGtmQyQ== Received: from [85.255.234.76] (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 1qkLjJ-00FfbA-4e; Sun, 24 Sep 2023 10:48:45 +0100 Date: Sun, 24 Sep 2023 10:48:41 +0100 Message-ID: <87v8bz52bq.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, Christoffer.Dall@arm.com, eauger@redhat.com, miguel.luis@oracle.com, darren@os.amperecomputing.com, scott@os.amperecomputing.com Subject: Re: [PATCH v2 2/2] KVM: arm64: timers: Save restore CVAL of a ptimer across guest entry and exits In-Reply-To: <38722ba7-b7d9-368b-f946-b6c0c0a661b8@os.amperecomputing.com> References: <20230904114218.590304-1-gankulkarni@os.amperecomputing.com> <20230904114218.590304-3-gankulkarni@os.amperecomputing.com> <86bkeadzf0.wl-maz@kernel.org> <8634zben3d.wl-maz@kernel.org> <38722ba7-b7d9-368b-f946-b6c0c0a661b8@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: 85.255.234.76 X-SA-Exim-Rcpt-To: gankulkarni@os.amperecomputing.com, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Christoffer.Dall@arm.com, eauger@redhat.com, miguel.luis@oracle.com, darren@os.amperecomputing.com, scott@os.amperecomputing.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=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 24 Sep 2023 02:48:54 -0700 (PDT) On Tue, 19 Sep 2023 07:15:44 +0100, Ganapatrao Kulkarni wrote: > > > > On 18-09-2023 04:59 pm, Marc Zyngier wrote: > > On Fri, 15 Sep 2023 10:57:46 +0100, > > Ganapatrao Kulkarni wrote: > >> > >> This patch did not work. > >> After adding changes as in below diff, it is started working. > > > > Thanks for looking into this. > > > >> > >> diff --git a/arch/arm64/kvm/hyp/vhe/switch.c > >> b/arch/arm64/kvm/hyp/vhe/switch.c > >> index b0b07658f77d..91d2cfb03e26 100644 > >> --- a/arch/arm64/kvm/hyp/vhe/switch.c > >> +++ b/arch/arm64/kvm/hyp/vhe/switch.c > >> @@ -117,7 +117,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu) > >> val = __vcpu_sys_reg(vcpu, CNTHP_CVAL_EL2); > >> > >> if (map.direct_ptimer) { > >> - write_sysreg_s(val, SYS_CNTP_CVAL_EL0); > >> + write_sysreg_el0(val, SYS_CNTP_CVAL); > > > > Duh, of course. Silly me. > > > >> isb(); > >> } > >> } > >> @@ -161,8 +161,6 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) > >> > >> ___deactivate_traps(vcpu); > >> > >> - write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); > >> - > >> if (has_cntpoff()) { > >> struct timer_map map; > >> u64 val, offset; > >> @@ -173,7 +171,7 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) > >> * We're exiting the guest. Save the latest CVAL value > >> * to memory and apply the offset now that TGE is set. > >> */ > >> - val = read_sysreg_s(SYS_CNTP_CVAL_EL0); > >> + val = read_sysreg_el0(SYS_CNTP_CVAL); > >> if (map.direct_ptimer == vcpu_ptimer(vcpu)) > >> __vcpu_sys_reg(vcpu, CNTP_CVAL_EL0) = val; > >> if (map.direct_ptimer == vcpu_hptimer(vcpu)) > >> @@ -182,12 +180,13 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) > >> offset = read_sysreg_s(SYS_CNTPOFF_EL2); > >> > >> if (map.direct_ptimer && offset) { > >> - offset = read_sysreg_s(SYS_CNTPOFF_EL2); > >> - write_sysreg_s(val + offset, SYS_CNTP_CVAL_EL0); > >> + write_sysreg_el0(val + offset, SYS_CNTP_CVAL); > >> isb(); > >> } > >> } > >> > >> + write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); > > > > Why moving the HCR_EL2 update? I don't grok what it changes. Or is it > > This the line of code which flips the TGE and making timer cval ready > to handle the TGE flip is more safe way(avoids even corner case of > false interrupt triggers) than changing after the flipping? That's pretty dubious. Do you actually see it firing on your HW? > > > that you end-up with spurious interrupts because your GIC is slow to > > retire interrupts that are transiently pending? > > IIUC, If there are any transient interrupts or asserted already, > anyway they will be handled when irq is unmasked. That's the idea. But my question is whether you observe spurious interrupts when not changing the ordering. Thanks, M. -- Without deviation from the norm, progress is not possible.