From nobody Mon Feb 20 16:24:23 2023 X-Original-To: dev-commits-src-branches@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 4PL76H1vf3z3t23g; Mon, 20 Feb 2023 16:24:23 +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 4PL76H1Sljz4Crs; Mon, 20 Feb 2023 16:24:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676910263; 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=g4sGq0QZnhkcGO2+5AsTGpgn94wJF8jQcMd18CGIkKg=; b=aoM7qc5r97hmoFhszP45qrRBAtkjUHS6NF1qQUJs41KixONvnUSY9v6ozE9SluCoZtaWmP wIO+/Xi20olaAU6kS6J/VSzJh7wuv6Be+7EyCyEV1LbeoJl4zXyJ1He25doKpZCeh/PC8g tdNnuXVKob5UDKg8vjDQGRhFsomCER6IWFKYxP0VJZY7ubAN1lfrZ9coJAtGW6J+MBKqeB jDzHI6oElcrP9P3g/gSY+HbQeWag92PoA9nvhX/pAGDMKrLB0TuFhhMzOSmd372EvVbudE oEQQKaZvjg2NCQB9RlPRTGgPepr4PGVtzIzOq2puwA2WYpbu+H7tQD6TMn7vDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676910263; 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=g4sGq0QZnhkcGO2+5AsTGpgn94wJF8jQcMd18CGIkKg=; b=uFqRlqvKZx2SiLmymuZnR3rsjGWbcrhLd5ItVw/nysKYe1P80GGjxT8BkKOAZuT/OcmKSv H0eIfzNhiSqVU5fTPxHczJs2wxEcO7fYlUvAmCVSjD63iwSAaIXMDnPrvLcB8vjtfkOHfl +EJc4kGH1V0KISIKB1F/HxkQJCGoZ9Sl1Zuz5ZSteoM+3gZ++qfRyo7hCzWnt7tNLamdsv J/pSjVuw/AQMLkw9H2d0qp2SjxReUIdLoOfB/4LUFcHdVWIdbWz6l56yRkMNCNCdd8fzg5 k86Pg7P5UricDBjdzfPT8i/Jiex5ei7CpkhVlv64hdeJGQPMklE4YlFJyS94BA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676910263; a=rsa-sha256; cv=none; b=KeV9wHAQG1xiPBHDY4ewonVUjnJX794t9P3gt6uiriclOi0q0ELox+6Au7pyWNfw2224fj HfjrmYMEgqBIKrwmSR4RpNRIyN1yI+h+HLnMZkbceAUX6LFh+gDZrc33vKrk7KsVJe9Hn7 BfUf0zFq7QC3hhMr7pzPQ9riTLjGaVgsOFA4y5mAIHJC7YhGZ6ZSzdW7+wswDmNoHFTQln ZoRv2oREhE7IQDgKD6r+7gac3ngsY/kTLn/KjWtEOtctkAVPiR2pqn3Ndoa/9AdUTfhobf eH+o2K6Zr4NrjDU8j632bRcR5Ohyo0i6F0D/ZMEtDTlb3XJY3FjTXQbSlnm/rg== 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 4PL76H0XdXznX8; Mon, 20 Feb 2023 16:24:23 +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 31KGON97064673; Mon, 20 Feb 2023 16:24:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31KGONOK064672; Mon, 20 Feb 2023 16:24:23 GMT (envelope-from git) Date: Mon, 20 Feb 2023 16:24:23 GMT Message-Id: <202302201624.31KGONOK064672@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 14d014c3a9b7 - stable/13 - pvclock: Export a vDSO page even without rdtscp available List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 14d014c3a9b7966db0557462e773298c8bf70dc2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=14d014c3a9b7966db0557462e773298c8bf70dc2 commit 14d014c3a9b7966db0557462e773298c8bf70dc2 Author: Mark Johnston AuthorDate: 2023-02-03 15:54:23 +0000 Commit: Mark Johnston CommitDate: 2023-02-20 16:24:08 +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 (cherry picked from commit 2bed14192cec1abcdc4e02ca7b18dafd868095ef) --- 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;