From nobody Thu Aug 25 11:17:39 2022 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 4MD0mz3MKYz4ZJ1t; Thu, 25 Aug 2022 11:17:39 +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 4MD0mz2sydz3x6Y; Thu, 25 Aug 2022 11:17:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661426259; 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=XoA07tI/a4nfrjNlVMm4GCBcpR7UxvI2V1LrcTQq9/I=; b=WRepIb9piSRPpk95clW9ZF+uJS18KNRIEFrjmJXHUBsMdhz3+lknPmxuGuuXKW/NllvVyu gaqX4zjOnWmR2orsuIlp8WHYtGYTDgIW+vAoRQL5pxaqmeIaxha/rFGigM4drGhRDekkVH WVEbsG8WKGhl+YbQvt7iwiADby2NtH9dS1r7Vs5x2sNFd1mX8ZNUGlxakIfI2lim1XTuhG Q52K21JXNgb+zbclVGsxLpIG/9ZxR8rInnJibaXDSpilXSbEyFlSUmAKT4VnpxK0tSB0UD m8ghgmnwiuVNYZVEJRLUM1pOdV3JVH4R2k2w1jIZq+mCGNNAjoTUQSBANh6vRw== 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 4MD0mz1tKzzm7Q; Thu, 25 Aug 2022 11:17:39 +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 27PBHdC6010571; Thu, 25 Aug 2022 11:17:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27PBHdVS010570; Thu, 25 Aug 2022 11:17:39 GMT (envelope-from git) Date: Thu, 25 Aug 2022 11:17:39 GMT Message-Id: <202208251117.27PBHdVS010570@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: 278111b8a541 - main - Allow the kernel to emulate the physical counter on arm64 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: 278111b8a54141bdaf4c4a045539db21febf053f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661426259; 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=XoA07tI/a4nfrjNlVMm4GCBcpR7UxvI2V1LrcTQq9/I=; b=d9EUswmlPLRcjZKfCdbadkC1b9a9+twWKZtNNoEEUpuW6yb2wOAglfXh9vflRpYQaetvOv HB9uYi6ZV76cX8Uo3/9hF+HMZoEvz2j3QCu34J+ETNVZKbrmEi4bO5KGO2j55MindVulTD IDb01EvIJUVnggdlxlzbFyJmnRoUgO7U0ezkocL40LBmsr9xKHewNLABtNf4upeQfftgtp 4qMfqhPNreTcJXqq3J6qT5W6RNnN4Pf/d7TgXF0Q8Jrz3pT9mwYYNNk6/jV0IVwnavwrLk gad/wDwdo40Ti3n2XxyuTXCEzDVWcjg5CnOjldcEEpOGo3J0xCwdELAWFL7y5A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661426259; a=rsa-sha256; cv=none; b=VnAkAq/PZu3yEU7n2Oz1MLx+biF7viNAIwdInBIH3ohWiqSRhlGkSBcYxdELb+Db8tgm6s cl7EswrJ0QUwjq0GsZszX878dmX4JLg9xn25LjpQcO32d5UcSQPVmdmXOTe2AhDIIOAuwQ k9gX6UoEG/tL69dUGOiDcscBjG9AuGEzfBP9kfe9S+vhLsJYgausfpZTgMd3Tx7FVSMa38 GQld7iDYqPY4uXcwzM6Dq/KLA5+HDsD5XUr0QtQGH0Sn5wp6nTBMyh+0lqZla5FxuoHZaD +zmJlxxa4zCkL3f1yGf8XeCsU2afcDvcAqqi2mxKky7n9UDWoZIyJLhnS8rL1g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=278111b8a54141bdaf4c4a045539db21febf053f commit 278111b8a54141bdaf4c4a045539db21febf053f Author: Andrew Turner AuthorDate: 2022-06-27 12:37:40 +0000 Commit: Andrew Turner CommitDate: 2022-08-25 11:17:23 +0000 Allow the kernel to emulate the physical counter on arm64 When running under a VM we don't have access to the physical counter. Add support to emulate this instruction by handling the trap in the kernel. As it is slow only enable when the hw.emulate_phys_counter tunable is set on boot. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35613 --- sys/arm/arm/generic_timer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index 0e0e8a53bcce..0c242a31d9a7 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -63,6 +63,10 @@ __FBSDID("$FreeBSD$"); #include /* For arm_set_delay */ #endif +#if defined(__aarch64__) +#include +#endif + #ifdef FDT #include #include @@ -235,12 +239,52 @@ setup_user_access(void *arg __unused) isb(); } +#ifdef __aarch64__ +static int +cntpct_handler(vm_offset_t va, uint32_t insn, struct trapframe *frame, + uint32_t esr) +{ + uint64_t val; + int reg; + + if ((insn & MRS_MASK) != MRS_VALUE) + return (0); + + if (MRS_SPECIAL(insn) != MRS_SPECIAL(CNTPCT_EL0)) + return (0); + + reg = MRS_REGISTER(insn); + val = READ_SPECIALREG(cntvct_el0); + if (reg < nitems(frame->tf_x)) { + frame->tf_x[reg] = val; + } else if (reg == 30) { + frame->tf_lr = val; + } + + /* + * We will handle this instruction, move to the next so we + * don't trap here again. + */ + frame->tf_elr += INSN_SIZE; + + return (1); +} +#endif + static void tmr_setup_user_access(void *arg __unused) { + int emulate; - if (arm_tmr_sc != NULL) + if (arm_tmr_sc != NULL) { smp_rendezvous(NULL, setup_user_access, NULL, NULL); +#ifdef __aarch64__ + if (TUNABLE_INT_FETCH("hw.emulate_phys_counter", &emulate) && + emulate != 0) { + install_undef_handler(true, cntpct_handler); + } +#endif + } } SYSINIT(tmr_ua, SI_SUB_SMP, SI_ORDER_ANY, tmr_setup_user_access, NULL);