Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4293244ybz; Mon, 20 Apr 2020 20:26:47 -0700 (PDT) X-Google-Smtp-Source: APiQypLg+FXq2u9j5YQL3+zZCwOWIA2X5wmcAWR5VA1mLYbGM7opII8wuoEBh4pKC3OqBik1vVdj X-Received: by 2002:aa7:cc03:: with SMTP id q3mr17427092edt.131.1587439607643; Mon, 20 Apr 2020 20:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587439607; cv=none; d=google.com; s=arc-20160816; b=yJaW9xjd3f6BGuq482YyDUOsi/GZEXktbc1KMomI9I6zIRNZBbkw1YtX3o5vWqEpKF nIuBA8to69O3LLmXNSa3fl1So7qXJ6FpFR3ume6v+39PmQUFDa8h8II5zT4IS2XhZFDu pUPdLX4BGEogKNxb54oOPKTnI8IUMyo81h28RWUvRRwWdlYnLNnWNMiSI0fgP/Lob4Ow XXcMD0m32DiVULIuM+GIpufhpCiJ6ZJ/OfnPVmw5dXb6E2YG6K8p0/yHiEvXP+aIMeYV sRgJyxeTQNy2WRIMpn+f3QdXjeoEDFoM4DkTBTSTKC1y+Mz9KNhgyjK3N937piQ0pZNH 8bKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=XrxPOvJo45eJwTPgQB4UVDxix/Jt6vw9tPchR84Vbtc=; b=dQKblkJf95nIEExsfgzEU1Eq8V1dRHsPDFBBPtEG4ix2xaElXQxaGhyqE/ToSfmKFG GMK3RXZF5GxLsM73DKn4C0kwCaTLRE7pvVlNHGQtqRXu0RYUGcDtODZgvqrvURbC4SKc AyWsR9qLMcc266kxzGd+/O5mbGyWvZNXlQk8KIplSM7ZqAzaDvCWwjs6dClHstt6dpHv Yy4U/ZGfw8u7SPayJb1MwW/l8jXwvhjs3TNT0Eo0vNyzcCe1OxVjgEUikf3vihiUa+9Q kmMuIv2iiW+n9gvoGch8pjBXAVY/NPJp68+9eeKG7ilmJfeTZrdguju0ZENVAs0Ti2iK eyTQ== 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 m9si919052eda.117.2020.04.20.20.26.24; Mon, 20 Apr 2020 20:26:47 -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 S1728465AbgDUDYX (ORCPT + 99 others); Mon, 20 Apr 2020 23:24:23 -0400 Received: from foss.arm.com ([217.140.110.172]:57560 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbgDUDYW (ORCPT ); Mon, 20 Apr 2020 23:24:22 -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 96733C14; Mon, 20 Apr 2020 20:24:21 -0700 (PDT) Received: from entos-d05.shanghai.arm.com (entos-d05.shanghai.arm.com [10.169.40.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6A4193F6CF; Mon, 20 Apr 2020 20:24:15 -0700 (PDT) From: Jianyong Wu To: 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, Mark.Rutland@arm.com, will@kernel.org, suzuki.poulose@arm.com, steven.price@arm.com Cc: 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, jianyong.wu@arm.com, nd@arm.com Subject: [RFC PATCH v11 8/9] arm64: add mechanism to let user choose which counter to return Date: Tue, 21 Apr 2020 11:23:03 +0800 Message-Id: <20200421032304.26300-9-jianyong.wu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421032304.26300-1-jianyong.wu@arm.com> References: <20200421032304.26300-1-jianyong.wu@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In general, vm inside will use virtual counter compered with host use phyical counter. But in some special scenarios, like nested virtualization, phyical counter maybe used by vm. A interface added in ptp_kvm driver to offer a mechanism to let user choose which counter should be return from host. To use this feature, you should call PTP_EXTTS_REQUEST(2) ioctl with flag set bit PTP_KVM_ARM_PHY_COUNTER in its argument then call PTP_SYS_OFFSET_PRECISE(2) ioctl to get the cross timestamp and phyical counter will return. If the bit not set or no call for PTP_EXTTS_REQUEST2, virtual counter will return by default. Signed-off-by: Jianyong Wu Suggested-by: Marc Zyngier --- drivers/clocksource/arm_arch_timer.c | 11 ++++++++++- drivers/ptp/ptp_chardev.c | 8 +++++++- drivers/ptp/ptp_kvm_common.c | 7 ++++--- include/uapi/linux/ptp_clock.h | 4 +++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 47d69b3f2d9a..52f629d9c561 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -1650,7 +1650,16 @@ int kvm_arch_ptp_get_crosststamp(unsigned long *cycle, struct timespec64 *ts, struct arm_smccc_res hvc_res; ktime_t ktime_overall; - arm_smccc_1_1_invoke(ARM_SMCCC_HYP_KVM_PTP_FUNC_ID, &hvc_res); + /* + * an argument will be passed by a0 to determine weather virtual + * counter or phyical counter should be passed back. + */ + if (*ctx) + arm_smccc_1_1_invoke(ARM_SMCCC_HYP_KVM_PTP_FUNC_ID, + ARM_SMCCC_HYP_KVM_PTP_PHY, &hvc_res); + else + arm_smccc_1_1_invoke(ARM_SMCCC_HYP_KVM_PTP_FUNC_ID, + ARM_SMCCC_HYP_KVM_PTP_VIRT, &hvc_res); if ((int)(hvc_res.a0) < 0) return -EOPNOTSUPP; diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index fef72f29f3c8..505ed7eb0ca5 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -122,6 +122,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) struct ptp_pin_desc pd; struct timespec64 ts; int enable, err = 0; + static long flag; switch (cmd) { @@ -149,6 +150,11 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) err = -EFAULT; break; } + /* + * Tell driver to call for physical counter. + * This is only for arm. + */ + flag = req.extts.flags & PTP_KVM_ARM_PHY_COUNTER; if (cmd == PTP_EXTTS_REQUEST2) { /* Tell the drivers to check the flags carefully. */ req.extts.flags |= PTP_STRICT_FLAGS; @@ -235,7 +241,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) err = -EOPNOTSUPP; break; } - err = ptp->info->getcrosststamp(ptp->info, &xtstamp, NULL); + err = ptp->info->getcrosststamp(ptp->info, &xtstamp, &flag); if (err) break; diff --git a/drivers/ptp/ptp_kvm_common.c b/drivers/ptp/ptp_kvm_common.c index 4fdd8ab11a28..39367e230176 100644 --- a/drivers/ptp/ptp_kvm_common.c +++ b/drivers/ptp/ptp_kvm_common.c @@ -36,7 +36,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, spin_lock(&kvm_ptp_lock); preempt_disable_notrace(); - ret = kvm_arch_ptp_get_crosststamp(&cycle, &tspec, &cs); + ret = kvm_arch_ptp_get_crosststamp(&cycle, &tspec, &cs, ctx); if (ret != 0) { pr_err_ratelimited("clock pairing hypercall ret %lu\n", ret); spin_unlock(&kvm_ptp_lock); @@ -57,9 +57,10 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time, } static int ptp_kvm_getcrosststamp(struct ptp_clock_info *ptp, - struct system_device_crosststamp *xtstamp) + struct system_device_crosststamp *xtstamp, + long *flag) { - return get_device_system_crosststamp(ptp_kvm_get_time_fn, NULL, + return get_device_system_crosststamp(ptp_kvm_get_time_fn, flag, NULL, xtstamp); } diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h index 9dc9d0079e98..71e388a82244 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -32,6 +32,7 @@ #define PTP_RISING_EDGE (1<<1) #define PTP_FALLING_EDGE (1<<2) #define PTP_STRICT_FLAGS (1<<3) +#define PTP_KVM_ARM_PHY_COUNTER (1<<4) #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE) /* @@ -40,7 +41,8 @@ #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \ PTP_RISING_EDGE | \ PTP_FALLING_EDGE | \ - PTP_STRICT_FLAGS) + PTP_STRICT_FLAGS | \ + PTP_KVM_ARM_PHY_COUNTER) /* * flag fields valid for the original PTP_EXTTS_REQUEST ioctl. -- 2.17.1