From nobody Fri Feb 03 16:50:32 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P7hVK02h7z3kWCx; Fri, 3 Feb 2023 16:50:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P7hVJ6hdgz3tc4; Fri, 3 Feb 2023 16:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675443032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Fg5XSaVt+utuS05LtUcobc8NF1RPf95THQe6wddRm6E=; b=rqZsVjM+ZY5tThNTuNH8/GX/FLdKG1fEjwow6nIN/V0iFviWbVBgVD6/Yfebnu+gJjcqiE reErNPZsI5MfmxAiisptQlx86toeZ1BxQ1nJRio84TBhmMhRgQlbcTRDqUfSUDVCop4mAl PsC0Q8VaU6bVWpI2pv0BvpRqz+SfENJC2OwzVeprbgXXq55qoGUNoBwJCL0o7aOTE7zQ2M GxZYZB4IA1qU77sT4Ljy8LfUTqv1MNLcUlRmi/KvJoyhrBkvfb/WUU23wDjR8mdiFQ0Sp1 0Ke6RGNo2qRCoUo40F+pzBi4P0PwjjxVk8sRNSrECQbrfMLWam8wud110yXPAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675443032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Fg5XSaVt+utuS05LtUcobc8NF1RPf95THQe6wddRm6E=; b=XKJgXsQzFQHapplTb0dzwTiSGXydku/G0yEANrxs50ludtDF09svMG1Io7E7Jbtcm5JHg6 uSUZey+QgT0Srmv+Sp9DdqdGW2ovjTk0f8zeSrJ8tOMy/dlnffeFOMnfJRAUGqBLyv4hPb 4AnwvT2YG3WdbujryBI2vXGq9MRdtZPGglW1krwEZNvUnfNNFYpjaBf9t3q2xW1PqTObcY rYNkJVdeA9tDTGCWJBLPdcoC6UJb1mq19/m4M8UaxK6zGTr2yjOjPGaIXBLTsFz7W6xrl9 aH3g/LyTt4rfFKm17U0tGffarc0LmBAl2/yLOSdooA8E1MAhA6QksMbdNiSIdw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675443032; a=rsa-sha256; cv=none; b=XoTfua8Wa9kDU1GoMHRApeC07IL/gF0cP/1DdfFvzbnHH51dN8j3jzDXMNYZRxUoD0GHe6 eBrbzQycAvWzBKRe+LXZANaMtWqrSJrZKIUFR1JLKczqSlBQVMw4vYhG3DWsdleZbhUcuv XZeUyDWQSh/govSBfrtbCdsaRd66gbcqj7FmvE6A97uSKcSAOZbrZYaR9Oxyan3gzNVgPH M1WO5j9ibpW9JothSz7NWA0MpyJk5wfyFntx2XDqCwXpdRqV5jkJbK8a+L4Q2bv9ezSEQV 2Q92MrvtLfVjkfdx29pWfbznRAwJLNsu4BYRywpujmIv5vE3PbjoEZ/hZKx7qA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P7hVJ5lySzhxv; Fri, 3 Feb 2023 16:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 313GoWHg009087; Fri, 3 Feb 2023 16:50:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313GoWfG009086; Fri, 3 Feb 2023 16:50:32 GMT (envelope-from git) Date: Fri, 3 Feb 2023 16:50:32 GMT Message-Id: <202302031650.313GoWfG009086@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 2bed14192cec - main - pvclock: Export a vDSO page even without rdtscp available List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2bed14192cec1abcdc4e02ca7b18dafd868095ef Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2bed14192cec1abcdc4e02ca7b18dafd868095ef commit 2bed14192cec1abcdc4e02ca7b18dafd868095ef Author: Mark Johnston AuthorDate: 2023-02-03 15:54:23 +0000 Commit: Mark Johnston CommitDate: 2023-02-03 16:48:25 +0000 pvclock: Export a vDSO page even without rdtscp available When the cycle counter is "stable", i.e., synchronized across vCPUs by the hypervisor, userspace can use a serialized rdtsc instead of relying on rdtscp, just like the kernel timecounter does. This can be useful for performance in guests where the hypervisor hides rdtscp for some reason. To avoid breaking compatibility with older userspace which expects rdtscp to be usable when pvclock exports timekeeping info, hide this feature behind a sysctl. Reviewed by: kib Tested by: Shrikanth R Kamath MFC after: 2 weeks Sponsored by: Klara, Inc. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D38342 --- sys/x86/include/pvclock.h | 1 + sys/x86/x86/pvclock.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sys/x86/include/pvclock.h b/sys/x86/include/pvclock.h index 023acdb80d9c..1306f11fc960 100644 --- a/sys/x86/include/pvclock.h +++ b/sys/x86/include/pvclock.h @@ -121,6 +121,7 @@ struct pvclock { /* Private; initialized by the 'pvclock' API: */ bool vdso_force_unstable; + bool vdso_enable_without_rdtscp; struct timecounter tc; struct cdev *cdev; }; diff --git a/sys/x86/x86/pvclock.c b/sys/x86/x86/pvclock.c index cc2377bdbcf0..3da3373bb2ee 100644 --- a/sys/x86/x86/pvclock.c +++ b/sys/x86/x86/pvclock.c @@ -224,6 +224,9 @@ pvclock_tc_vdso_timehands(struct vdso_timehands *vdso_th, { struct pvclock *pvc = tc->tc_priv; + if (pvc->cdev == NULL) + return (0); + vdso_th->th_algo = VDSO_TH_ALGO_X86_PVCLK; vdso_th->th_x86_shift = 0; vdso_th->th_x86_hpet_idx = 0; @@ -232,7 +235,9 @@ pvclock_tc_vdso_timehands(struct vdso_timehands *vdso_th, vdso_th->th_x86_pvc_stable_mask = !pvc->vdso_force_unstable && pvc->stable_flag_supported ? PVCLOCK_FLAG_TSC_STABLE : 0; bzero(vdso_th->th_res, sizeof(vdso_th->th_res)); - return (pvc->cdev != NULL && amd_feature & AMDID_RDTSCP); + return ((amd_feature & AMDID_RDTSCP) != 0 || + ((vdso_th->th_x86_pvc_stable_mask & PVCLOCK_FLAG_TSC_STABLE) != 0 && + pvc->vdso_enable_without_rdtscp)); } #ifdef COMPAT_FREEBSD32 @@ -242,6 +247,9 @@ pvclock_tc_vdso_timehands32(struct vdso_timehands32 *vdso_th, { struct pvclock *pvc = tc->tc_priv; + if (pvc->cdev == NULL) + return (0); + vdso_th->th_algo = VDSO_TH_ALGO_X86_PVCLK; vdso_th->th_x86_shift = 0; vdso_th->th_x86_hpet_idx = 0; @@ -250,7 +258,9 @@ pvclock_tc_vdso_timehands32(struct vdso_timehands32 *vdso_th, vdso_th->th_x86_pvc_stable_mask = !pvc->vdso_force_unstable && pvc->stable_flag_supported ? PVCLOCK_FLAG_TSC_STABLE : 0; bzero(vdso_th->th_res, sizeof(vdso_th->th_res)); - return (pvc->cdev != NULL && amd_feature & AMDID_RDTSCP); + return ((amd_feature & AMDID_RDTSCP) != 0 || + ((vdso_th->th_x86_pvc_stable_mask & PVCLOCK_FLAG_TSC_STABLE) != 0 && + pvc->vdso_enable_without_rdtscp)); } #endif @@ -284,6 +294,18 @@ pvclock_init(struct pvclock *pvc, device_t dev, const char *tc_name, "vdso_force_unstable", CTLFLAG_RW, &pvc->vdso_force_unstable, 0, "Forcibly deassert stable flag in vDSO codepath"); + /* + * Make it possible to use the vDSO page even when the hypervisor does + * not support the rdtscp instruction. This is disabled by default for + * compatibility with old libc. + */ + pvc->vdso_enable_without_rdtscp = false; + SYSCTL_ADD_BOOL(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, + "vdso_enable_without_rdtscp", CTLFLAG_RWTUN, + &pvc->vdso_enable_without_rdtscp, 0, + "Allow the use of a vDSO when rdtscp is not available"); + /* Set up timecounter and timecounter-supporting members: */ pvc->tc.tc_get_timecount = pvclock_tc_get_timecount; pvc->tc.tc_poll_pps = NULL;