From nobody Wed Jun 28 20:47:35 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 4Qrttv4ZRxz4kbZq; Wed, 28 Jun 2023 20:47:35 +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 4Qrttv3ZWpz3p35; Wed, 28 Jun 2023 20:47:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687985255; 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=E90x7aqqvPWFURy5O9UggDcwkwcwLrrX3+aSp3gRy/U=; b=oOZaz0TIpys5Vbq3hFWui2Um5NroGy1XhEMODPBD/FaZ5wIPUTzBCLsKso+jYawzpELXNT Sz10OMzI9wZNgBsYa1NlAIoALQeuncLUGzEueSLmz9sL4qiDp2/aolKeZQ0UCfP31SgzcU Lvu/XyF6DgKEm9O8ZLXVmflnEGIcTJxEjSLdQV4tTaP49m65weZlHQqcFIwWYwz1iL8j9w +l/HdnHKqnE7ib6Td4oFytbjk11XsjXw8+V2Z3PHQKKVl0PMUudMHabV7dSL6Fd7YdK3qC xgS12xYmNrcZ4NenUh+KSvpfeqM02jq/833hDR6PreFwZsg9Q+yMJ2d/VKEfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687985255; 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=E90x7aqqvPWFURy5O9UggDcwkwcwLrrX3+aSp3gRy/U=; b=HvKIZujLgA+56NeGzsQGarLOExjIoKuMakN07JV8zKQVZU123oz8RQc9dwoDrKTv46nm8D Niumgozwd3/+MwavqlX259UJ3gxPry/AkPrHHRcR20wEMiAyYDLyu1luXWvpmO346pzfEw yocfTx2LE8SFWvWRKj4ft3lMxWNEa9hxk7c6dZ3Jc/TUpE1d2OV2TcjKVYstxtXeYNmpcP kdFvevrvej9u6xjdmUODdnx/gKF33mtQT8YlNxBtVu4zaIvSM89UKe0WVUFA8iyKoz26EF 5zgfClmZNbyJXV9kAkv833Dcg5JwHqc9OIbqIM/usM7m4FBpfLlpQaO5SAZOvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687985255; a=rsa-sha256; cv=none; b=X3BjemJ8a9hrkn2ym5zk5IrR0Nr8I1R9mX4NVnYXngfaM8REZDdWNg5wbvuDP/PlOuQrt2 ds7Y7Ji1g5z+xAFOl/GJyeijAw1WIvnWEERQZDHli1YptlsYEckJOU0gDoNwU5pq2QwZdE kB481e61M770E920pPfQow3PaQ8r7Ld/W56mPL2LDmRQylcY8CM7YGZzMVZOYD6lCXt0U1 L806lk92TTuaTn+RBoWOEJXAdR871fZwPMrmOxR9qWXwy1VvzrRkO+Bq1YjbDT2+J40/eH lLDCx1hAmRXnY0hFWYE+he0q+IOks9WfhW1/4D2rvo5Fy/pd4jIhWRuoeDtelA== 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 4Qrttv2Q5Fzp5D; Wed, 28 Jun 2023 20:47:35 +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 35SKlZWV058536; Wed, 28 Jun 2023 20:47:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35SKlZeT058535; Wed, 28 Jun 2023 20:47:35 GMT (envelope-from git) Date: Wed, 28 Jun 2023 20:47:35 GMT Message-Id: <202306282047.35SKlZeT058535@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: fbec1f91951f - main - arm64: Add a masked get_kernel_reg() 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: fbec1f91951fe01c1c590bab5e6c16a30884f352 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=fbec1f91951fe01c1c590bab5e6c16a30884f352 commit fbec1f91951fe01c1c590bab5e6c16a30884f352 Author: Mark Johnston AuthorDate: 2023-06-28 20:12:47 +0000 Commit: Mark Johnston CommitDate: 2023-06-28 20:29:49 +0000 arm64: Add a masked get_kernel_reg() This lets consumers fetch the value of a system register and apply a mask over individual fields. That is, each field in the returned value will be the "smaller" of the two provided by "mask" and the value saved in kern_cpu_desc. This will be used by vmm to sanitize host system register fields. Reviewed by: andrew MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. (hardware) Differential Revision: https://reviews.freebsd.org/D40500 --- sys/arm64/arm64/identcpu.c | 90 +++++++++++++++++++++++++++++----------------- sys/arm64/include/cpu.h | 1 + 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index e96f0a089784..01e663ff47c2 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -1721,38 +1721,6 @@ user_mrs_handler(vm_offset_t va, uint32_t insn, struct trapframe *frame, return (1); } -bool -extract_user_id_field(u_int reg, u_int field_shift, uint8_t *val) -{ - uint64_t value; - int i; - - for (i = 0; i < nitems(user_regs); i++) { - if (user_regs[i].reg == reg) { - value = CPU_DESC_FIELD(user_cpu_desc, i); - *val = value >> field_shift; - return (true); - } - } - - return (false); -} - -bool -get_kernel_reg(u_int reg, uint64_t *val) -{ - int i; - - for (i = 0; i < nitems(user_regs); i++) { - if (user_regs[i].reg == reg) { - *val = CPU_DESC_FIELD(kern_cpu_desc, i); - return (true); - } - } - - return (false); -} - /* * Compares two field values that may be signed or unsigned. * Returns: @@ -1808,6 +1776,64 @@ update_lower_register(uint64_t val, uint64_t new_val, u_int shift, return (val); } +bool +extract_user_id_field(u_int reg, u_int field_shift, uint8_t *val) +{ + uint64_t value; + int i; + + for (i = 0; i < nitems(user_regs); i++) { + if (user_regs[i].reg == reg) { + value = CPU_DESC_FIELD(user_cpu_desc, i); + *val = value >> field_shift; + return (true); + } + } + + return (false); +} + +bool +get_kernel_reg(u_int reg, uint64_t *val) +{ + int i; + + for (i = 0; i < nitems(user_regs); i++) { + if (user_regs[i].reg == reg) { + *val = CPU_DESC_FIELD(kern_cpu_desc, i); + return (true); + } + } + + return (false); +} + +/* + * Fetch the specified register's value, ensuring that individual field values + * do not exceed those in the mask. + */ +bool +get_kernel_reg_masked(u_int reg, uint64_t *valp, uint64_t mask) +{ + struct mrs_field *fields; + uint64_t val; + + for (int i = 0; i < nitems(user_regs); i++) { + if (user_regs[i].reg == reg) { + val = CPU_DESC_FIELD(kern_cpu_desc, i); + *valp = 0; + fields = user_regs[i].fields; + for (int j = 0; fields[j].type != 0; j++) { + *valp |= update_lower_register(mask, val, + fields[j].shift, 4, fields[j].sign); + } + return (true); + } + } + + return (false); +} + void update_special_regs(u_int cpu) { diff --git a/sys/arm64/include/cpu.h b/sys/arm64/include/cpu.h index 1ea497756698..0bb320f2e0a0 100644 --- a/sys/arm64/include/cpu.h +++ b/sys/arm64/include/cpu.h @@ -213,6 +213,7 @@ void ptrauth_mp_start(uint64_t); void update_special_regs(u_int); bool extract_user_id_field(u_int, u_int, uint8_t *); bool get_kernel_reg(u_int, uint64_t *); +bool get_kernel_reg_masked(u_int, uint64_t *, uint64_t); void cpu_desc_init(void);