Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4565803ybz; Tue, 21 Apr 2020 02:59:18 -0700 (PDT) X-Google-Smtp-Source: APiQypKKzITd+nPkvBXORFD6A+cWJPPzQT8dMHVY7qapkitlrDvsOFL9yZWfCqbuYVtQFOnvoTJe X-Received: by 2002:aa7:d48a:: with SMTP id b10mr15177449edr.284.1587463158275; Tue, 21 Apr 2020 02:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587463158; cv=none; d=google.com; s=arc-20160816; b=keFy9z7b9IjaVW7pprNN9mjigZjvHycUSm2Jo0UP/W9XNjgaI5n115flNsjnqvzdVj ec7/57aZYvMeTAXWACpVNPj9hDmxbHFzxjvJTE7CMAgz8hKLqSPfEHI79GxofdpdN0+y fGH8bd7c9UnBg6eZa00EVsTy41Z2j7Q9Mm8bIp4mgOkixMW3D/lRVW+y0WAtATOWEYa3 jYTXs924uw0UkbVwcMqavET7/VsztoiUhpuHh6hT+IEUAZNuilFWy3eleuwtoZ4Pinx9 sht/4KlieyK+0exLYZ9UOpibYO4XEaeY4N7e2pIr0GkB4AbwB69KXdvkci5HGSTnPUen brnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=rAtUyQR6nXQFgYgJfBETsHlDUUKB0mp2KTEn+eX6ajo=; b=yKfKiASljIxRs+V5V0loc5E3f7n3C/4ioDin+cHrEbhusKhiuvCzbzpRnR4hRwN9pb wCNsF3l0FTaUUpuvCVIU3unjGIsi8NolTZGOnwy0O/+J174mY6AWz1sbtsjnEV0emd5U jCWDRnu0yRMGSFYdBkchnyT+U03Ex0+yVwMw6YS9+DODJ/EORVF584VC+XymmcUfV/Ue RDvujkeu0VOurqIK4c1NW2Z9ggHzDRmrewchMet0umA9/JLLppoiK4g8+dUZOJUiSVdN j/fae980o4oUiVrIl1KfjEm9CkclLz/PStqxH0DqbB6Tk1NTFjt1h7w91osgRUq8PLKq 5N4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si1290171eju.232.2020.04.21.02.58.55; Tue, 21 Apr 2020 02:59:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728633AbgDUJ5p (ORCPT + 99 others); Tue, 21 Apr 2020 05:57:45 -0400 Received: from foss.arm.com ([217.140.110.172]:60790 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbgDUJ5o (ORCPT ); Tue, 21 Apr 2020 05:57:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A1BB01FB; Tue, 21 Apr 2020 02:57:43 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 554A83F73D; Tue, 21 Apr 2020 02:57:39 -0700 (PDT) Date: Tue, 21 Apr 2020 10:57:36 +0100 From: Mark Rutland To: Jianyong Wu Cc: netdev@vger.kernel.org, yangbo.lu@nxp.com, john.stultz@linaro.org, tglx@linutronix.de, pbonzini@redhat.com, sean.j.christopherson@intel.com, maz@kernel.org, richardcochran@gmail.com, will@kernel.org, suzuki.poulose@arm.com, steven.price@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Steve.Capper@arm.com, Kaly.Xin@arm.com, justin.he@arm.com, nd@arm.com Subject: Re: [RFC PATCH v11 5/9] psci: Add hypercall service for ptp_kvm. Message-ID: <20200421095736.GB16306@C02TD0UTHF1T.local> References: <20200421032304.26300-1-jianyong.wu@arm.com> <20200421032304.26300-6-jianyong.wu@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200421032304.26300-6-jianyong.wu@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 21, 2020 at 11:23:00AM +0800, Jianyong Wu wrote: > ptp_kvm modules will get this service through smccc call. > The service offers real time and counter cycle of host for guest. > Also let caller determine which cycle of virtual counter or physical counter > to return. > > Signed-off-by: Jianyong Wu > --- > include/linux/arm-smccc.h | 21 +++++++++++++++++++ > virt/kvm/arm/hypercalls.c | 44 ++++++++++++++++++++++++++++++++++++++- > 2 files changed, 64 insertions(+), 1 deletion(-) > > diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h > index 59494df0f55b..747b7595d0c6 100644 > --- a/include/linux/arm-smccc.h > +++ b/include/linux/arm-smccc.h > @@ -77,6 +77,27 @@ > ARM_SMCCC_SMC_32, \ > 0, 0x7fff) > > +/* PTP KVM call requests clock time from guest OS to host */ > +#define ARM_SMCCC_HYP_KVM_PTP_FUNC_ID \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_32, \ > + ARM_SMCCC_OWNER_STANDARD_HYP, \ > + 0) > + > +/* request for virtual counter from ptp_kvm guest */ > +#define ARM_SMCCC_HYP_KVM_PTP_VIRT \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_32, \ > + ARM_SMCCC_OWNER_STANDARD_HYP, \ > + 1) > + > +/* request for physical counter from ptp_kvm guest */ > +#define ARM_SMCCC_HYP_KVM_PTP_PHY \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_32, \ > + ARM_SMCCC_OWNER_STANDARD_HYP, \ > + 2) ARM_SMCCC_OWNER_STANDARD_HYP is for standard calls as defined in SMCCC and companion documents, so we should refer to the specific documentation here. Where are these calls defined? If these calls are Linux-specific then ARM_SMCCC_OWNER_STANDARD_HYP isn't appropriate to use, as they are vendor-specific hypervisor service call. It looks like we don't currently have a ARM_SMCCC_OWNER_HYP for that (which IIUC would be 6), but we can add one as necessary. I think that Will might have added that as part of his SMCCC probing bits. > + > #ifndef __ASSEMBLY__ > > #include > diff --git a/virt/kvm/arm/hypercalls.c b/virt/kvm/arm/hypercalls.c > index 550dfa3e53cd..a5309c28d4dc 100644 > --- a/virt/kvm/arm/hypercalls.c > +++ b/virt/kvm/arm/hypercalls.c > @@ -3,6 +3,7 @@ > > #include > #include > +#include > > #include > > @@ -11,8 +12,11 @@ > > int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) > { > - u32 func_id = smccc_get_function(vcpu); > + struct system_time_snapshot systime_snapshot; > + long arg[4]; > + u64 cycles; > long val = SMCCC_RET_NOT_SUPPORTED; > + u32 func_id = smccc_get_function(vcpu); > u32 feature; > gpa_t gpa; > > @@ -62,6 +66,44 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) > if (gpa != GPA_INVALID) > val = gpa; > break; > + /* > + * This serves virtual kvm_ptp. > + * Four values will be passed back. > + * reg0 stores high 32-bit host ktime; > + * reg1 stores low 32-bit host ktime; > + * reg2 stores high 32-bit difference of host cycles and cntvoff; > + * reg3 stores low 32-bit difference of host cycles and cntvoff. > + */ > + case ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: Shouldn't the host opt-in to providing this to the guest, as with other features? > + /* > + * system time and counter value must captured in the same > + * time to keep consistency and precision. > + */ > + ktime_get_snapshot(&systime_snapshot); > + if (systime_snapshot.cs_id != CSID_ARM_ARCH_COUNTER) > + break; > + arg[0] = upper_32_bits(systime_snapshot.real); > + arg[1] = lower_32_bits(systime_snapshot.real); Why exactly does the guest need the host's real time? Neither the cover letter nor this commit message have explained that, and for those of us unfamliar with PTP it would be very helpful to know that to understand what's going on. > + /* > + * which of virtual counter or physical counter being > + * asked for is decided by the first argument. > + */ > + feature = smccc_get_arg1(vcpu); > + switch (feature) { > + case ARM_SMCCC_HYP_KVM_PTP_PHY: > + cycles = systime_snapshot.cycles; > + break; > + case ARM_SMCCC_HYP_KVM_PTP_VIRT: > + default: > + cycles = systime_snapshot.cycles - > + vcpu_vtimer(vcpu)->cntvoff; > + } > + arg[2] = upper_32_bits(cycles); > + arg[3] = lower_32_bits(cycles); > + > + smccc_set_retval(vcpu, arg[0], arg[1], arg[2], arg[3]); I think the 'arg' buffer is confusing here, and it'd be clearer to have: u64 snaphot; u64 cycles; ... and here do: smccc_set_retval(vcpu, upper_32_bits(snaphot), lower_32_bits(snapshot), upper_32_bits(cycles), lower_32_bits(cycles)); Thanks, Mark.