From nobody Fri Sep 01 10:07:11 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 4RcYc01KkJz4sKTg; Fri, 1 Sep 2023 10:07:12 +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 4RcYc00Ydhz3ZhW; Fri, 1 Sep 2023 10:07:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693562832; 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=p65XuJPD3atCP2p2X8S0W99yvw37SZQRQlSF0eWkz3g=; b=FK09NpxWzRdBoYtk3fM50vpP8o3/rouEid/+H1nRyKlgQ498qjT5+GVlGLyXSS7PeykeJC OGEF2gBlXn0lMHQpdmrVa0p8P2wm2ra5fgUaidTnDT9DJZ0/4e1LmtZLmAmSEk8JumrS2M ks2tL9Fy9/j7ytooT2lsweaj/MS8W5cPD/VwV6qNY1VqI8rWaI28lBil3wOgvb2yADMqv2 Vc1CRxUXkda2Mdw4y61Nw2QeYFwwYEEhtm2RK2JGz5uCLKDvltwSDJ+I62Q+lBmdooBusf NsesJmMDWc5vDYcsIiyZ+oqh70yganSEGMyhQ3CkZNzqCKiSnEfm65AwrZXYPg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693562832; a=rsa-sha256; cv=none; b=RoLpy+qjg8HNd950kys0gUXFYvYAH3xoBgY5WDZKH9Fe/cfZjHyMMqyQtE+KMbRf+CvCrr EHUE6P9nhlpyUnlfIbzYR2JGdAw0LgO/i+25qXrjaqNee0SMFnLcPLafB65nAQJc6z+vwa Vh/YfMFsZ8O7mpEeU/qOj7mlDehVmwL1hCznBDCyA5gIMDYTsSO/UJyFAIAM32pWt9Wy/j 2qOFRyka4vtJ20jwaEhd2p/N7UkJe6RTRMI8vpHN6719MW4NZRRXAmOAiNpJjPCqqTh6ZD 28eQYvmqeZh+oQahPVdRR1ac/Kn5Q2kDOHp1E/WqyASt68e0L6sa1J0SOiFyhQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693562832; 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=p65XuJPD3atCP2p2X8S0W99yvw37SZQRQlSF0eWkz3g=; b=J/UlA092ttJhA/wJNSueakzrmeqW8NXW1+4AqvOok1AMSPDSlXPwa2L/dXGzm3ihaqbtVl 1MguMcwnnr0a5UiVpPOHSRWHNzIBQwWdv5GnQb7jgM9MFpueA9EAFccCGv+hS9nLdaNboU 230XFl7lHhudyOwWqFjo+rzHpdM11ekFO41VEM9oL5Wea4NJfZBJSf+nioLxvsI1ricENY zsuaQS8ox6YwPmCokxqeSkAf8HmD8fNrLvmQMhWgdYG4pL6Vmx9M3uVFiVQx906PEQH6Bp cLTn3bNx+kZmmG2RxJkEAwjVqCMLedU6TW1nDEfMxIKX/HbmJSldx+g69PR9CQ== 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 4RcYbz6l3gzwkS; Fri, 1 Sep 2023 10:07:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 381A7BEM092305; Fri, 1 Sep 2023 10:07:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 381A7BIQ092302; Fri, 1 Sep 2023 10:07:11 GMT (envelope-from git) Date: Fri, 1 Sep 2023 10:07:11 GMT Message-Id: <202309011007.381A7BIQ092302@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 7ad28b73ec1f - main - arm: Add a userspace physical timer check 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7ad28b73ec1fd78a28a708da442d4a4c9e573172 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=7ad28b73ec1fd78a28a708da442d4a4c9e573172 commit 7ad28b73ec1fd78a28a708da442d4a4c9e573172 Author: Andrew Turner AuthorDate: 2023-08-23 12:34:09 +0000 Commit: Andrew Turner CommitDate: 2023-09-01 09:49:18 +0000 arm: Add a userspace physical timer check We currently use the same Arm generic time in both userspace and the kernel. As we always enable userspace access to the virtual timer we can tell userspace to use it. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D41565 --- sys/arm/arm/generic_timer.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index b9562620848f..998259c5c90f 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -110,7 +110,8 @@ struct arm_tmr_softc { uint32_t clkfreq; int irq_count; struct eventtimer et; - bool physical; + bool physical_sys; + bool physical_user; }; static struct arm_tmr_softc *arm_tmr_sc = NULL; @@ -271,7 +272,7 @@ setup_user_access(void *arg __unused) /* Always enable the virtual timer */ cntkctl |= GT_CNTKCTL_PL0VCTEN; /* Enable the physical timer if supported */ - if (arm_tmr_sc->physical) { + if (arm_tmr_sc->physical_user) { cntkctl |= GT_CNTKCTL_PL0PCTEN; } set_el1(cntkctl, cntkctl); @@ -333,7 +334,7 @@ static unsigned arm_tmr_get_timecount(struct timecounter *tc) { - return (arm_tmr_sc->get_cntxct(arm_tmr_sc->physical)); + return (arm_tmr_sc->get_cntxct(arm_tmr_sc->physical_sys)); } static int @@ -347,11 +348,11 @@ arm_tmr_start(struct eventtimer *et, sbintime_t first, if (first != 0) { counts = ((uint32_t)et->et_frequency * first) >> 32; - ctrl = get_ctrl(sc->physical); + ctrl = get_ctrl(sc->physical_sys); ctrl &= ~GT_CTRL_INT_MASK; ctrl |= GT_CTRL_ENABLE; - set_tval(counts, sc->physical); - set_ctrl(ctrl, sc->physical); + set_tval(counts, sc->physical_sys); + set_ctrl(ctrl, sc->physical_sys); return (0); } @@ -375,7 +376,7 @@ arm_tmr_stop(struct eventtimer *et) struct arm_tmr_softc *sc; sc = (struct arm_tmr_softc *)et->et_priv; - arm_tmr_disable(sc->physical); + arm_tmr_disable(sc->physical_sys); return (0); } @@ -387,10 +388,10 @@ arm_tmr_intr(void *arg) int ctrl; sc = (struct arm_tmr_softc *)arg; - ctrl = get_ctrl(sc->physical); + ctrl = get_ctrl(sc->physical_sys); if (ctrl & GT_CTRL_INT_STAT) { ctrl |= GT_CTRL_INT_MASK; - set_ctrl(ctrl, sc->physical); + set_ctrl(ctrl, sc->physical_sys); } if (sc->et.et_active) @@ -616,7 +617,7 @@ arm_tmr_attach(device_t dev) phandle_t node; pcell_t clock; #endif - int error; + int error, user_phys; int i, first_timer, last_timer; sc = device_get_softc(dev); @@ -680,18 +681,28 @@ arm_tmr_attach(device_t dev) * coordinated with the virtual machine manager. */ if (!HAS_PHYS) { - sc->physical = false; + sc->physical_sys = false; first_timer = GT_VIRT; last_timer = GT_VIRT; } else #endif /* Otherwise set up the secure and non-secure physical timers. */ { - sc->physical = true; + sc->physical_sys = true; first_timer = GT_PHYS_SECURE; last_timer = GT_PHYS_NONSECURE; } + /* + * The virtual timer is always available on arm and arm64, tell + * userspace to use it. + */ + sc->physical_user = false; + /* Allow use of the physical counter in userspace when available */ + if (TUNABLE_INT_FETCH("hw.userspace_allow_phys_counter", &user_phys) && + user_phys != 0) + sc->physical_user = sc->physical_sys; + arm_tmr_sc = sc; /* Setup secure, non-secure and virtual IRQs handler */ @@ -790,10 +801,10 @@ arm_tmr_do_delay(int usec, void *arg) else counts = usec * counts_per_usec; - first = sc->get_cntxct(sc->physical); + first = sc->get_cntxct(sc->physical_sys); while (counts > 0) { - last = sc->get_cntxct(sc->physical); + last = sc->get_cntxct(sc->physical_sys); counts -= (int32_t)(last - first); first = last; } @@ -830,7 +841,7 @@ arm_tmr_fill_vdso_timehands(struct vdso_timehands *vdso_th, { vdso_th->th_algo = VDSO_TH_ALGO_ARM_GENTIM; - vdso_th->th_physical = arm_tmr_sc->physical; + vdso_th->th_physical = arm_tmr_sc->physical_user; bzero(vdso_th->th_res, sizeof(vdso_th->th_res)); return (1); }