Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3499165ybv; Mon, 10 Feb 2020 00:51:51 -0800 (PST) X-Google-Smtp-Source: APXvYqyQsY7uXPXz+OfpInkKkDPNBh65KqDNUhTcIXp13xE+kDCeJvgKv6PL9L/lOwZAIy0B7lxw X-Received: by 2002:a9d:6e14:: with SMTP id e20mr283710otr.283.1581324711109; Mon, 10 Feb 2020 00:51:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581324711; cv=none; d=google.com; s=arc-20160816; b=n4rZbpHLy5D6KnN0/I/8ULZycWRIJzOfmD3vsO0Y55YncnaXjCPbNbN16lZmYVx0aG 0EAjW04BHot1kImMT1vDHj4bA683rXWxh91CCPx+hknajIpUvVfN9kHclztoSoJAi+7x IzXn1zLyW+NMLa3o4Pb39uD1Qn7tpBmqmkgCtWkqOp/Dl5rh8SSH02YKMF4peJcVOxVH NzDLMwmcXyu8n2rOszKcxsNs8PK9/9WkI9ENsDPWOdxmDKcDBJzSwXhMT1v23p2fl+6a TTKRyvO7/XFsqJDrnsx/jfJc1Os3DyD/jVnBb96snluZ/fsvRhCVNuRppvBnSrYsDdUZ mj/Q== 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=roy5ekPo+Eznt3wkC5IX+uDNoLt1wquk/MlVhHbaf0s=; b=uDBzirBIvUE7ogPDo7rcNWjtLjx4h8iwI1FJG5qGaklw1Z/4Gtp7g1Fe5OruuOpfFW WC+iXWeYvha7etbCXMyxmrexUnXPq/GSGpkShNZSHFhsSLzto5eNW5Oo7ABE6L50xgPs XY97Gin1lVe/VB+hW+UrPJ4iVpuYFy+cw3l3jRaHUNZCjTSWu9Gb+099I1M+j2pVEqc2 9PrdUe5aLW0q5qzqd9HuuIaZvFEcuRP+m2h9ILOpDZrUQqaBKxYOh1SuXVmHNEkMXU/3 wJHFpHC8fevtCdZmOUMV2E1Qm5SzPYmuzQzKWbVjBU8dUX7v739H1LIFGhmCBkl8bEh9 XP3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o25si4582164otk.28.2020.02.10.00.51.39; Mon, 10 Feb 2020 00:51:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727831AbgBJIuP (ORCPT + 99 others); Mon, 10 Feb 2020 03:50:15 -0500 Received: from foss.arm.com ([217.140.110.172]:57658 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727813AbgBJIuN (ORCPT ); Mon, 10 Feb 2020 03:50:13 -0500 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 A42EA31B; Mon, 10 Feb 2020 00:50:12 -0800 (PST) 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 27B143F68F; Mon, 10 Feb 2020 00:50:06 -0800 (PST) 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 8/9] arm/arm64: add mechanism to let user choose which counter to return Date: Mon, 10 Feb 2020 16:49:05 +0800 Message-Id: <20200210084906.24870-9-jianyong.wu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200210084906.24870-1-jianyong.wu@arm.com> References: <20200210084906.24870-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 b1bc8bd198c2..3e43d4e4885e 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -1634,7 +1634,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 09c3f1e5382d..bd7b6a31b6cb 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; @@ -226,7 +232,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 60442f70d3fc..20fbecef1f22 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