From nobody Thu Oct 24 10:36:40 2024 X-Original-To: dev-commits-src-main@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 4XZ2Qc39s4z5bL7x; Thu, 24 Oct 2024 10:36:40 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XZ2Qc1Pbkz4pcw; Thu, 24 Oct 2024 10:36:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729766200; 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=ToYonaBsTrMXZizR2SO8/qhQkPJpTbffOn6xY970WTo=; b=gm5nM+nVMSXmTiIwbYSlShidT2Vx80Z7ckoP83aNnhdLWNcZHzDxhHN//mMin3Np5AF9sG 6imhg4uNj8oLj+rMjXyAMPWQPuNUQXlg7AgJhDGsIYu50sTMWqyc4cPCBqbusJeueyof7l 965o2uEDg5Yt3IvfOQ1cWyomqXjxCt0uKc+Wyco+v52lKbraJKXKeKv2X0pyYZLpQCJLhe khl70hCtpEXmvqAn8r4xmADxj+6trFIFRLqJlIYsqsYFYgef9zH2Z5kRLfN59gC0nAZPyq qX2pvMasyGJfZqn8Hb+3GlK+QHSSNgOZAPSVNiPqxOHl2wM/pRoB/3zk8K+JXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729766200; 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=ToYonaBsTrMXZizR2SO8/qhQkPJpTbffOn6xY970WTo=; b=v+YiPMfRRUJDqCGfRqTi1y5L9aA0f9aQSDZTvHQaRL8lihsYWfR8q9pJAMK+AG0PPpLIKK u+84R/IhUyfqX++mkPWSDTjX5t1riP2/4tPg99WDVPhmdXgALxFrLFBZbvsfSCy4lmsyxE oXZnAEY70xVVdY8HYR3SMV6FKbMmIF6Y4Om0LBPX+cyTpSpqsv5yCXzr8BjuzS1ilxtqGX z+QM+5oVuMDML/Pnn/Q22aEcoioW72u2Wu2W3/G3T+QjxhtGHMhbs14CKs9NzAda2V9+Y7 3YOA/Hqt1ifeYiE0LMbfqWp7cBoJ1sT7R9S83TNZWu025YJyt1Uw1l6xPw3qIA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729766200; a=rsa-sha256; cv=none; b=HT+Zqhvz4d4d3lY2xaeJOdw/rVwW3NMI7N95m0kdU4raer/3udYL9D2M+BXp04sC/n67F8 IK1iDmrZJ85w+v3WxsobqhOJJz7jH38iYS8euE9DhQ4HqWPnauMraaMSarXG7EBIicWdBt HpAshnBbByqigGpxfJnsmMXC+URvfhGRNYN9k7dTe3tudrMzOPxZIpHh6L6nRKhbGv5ReH k6Kzh3jwGYc5ro8DAQVuTGcvsjXdVdjwBOUYMU8yuWAa13lDD4TEvMOnvnwDR1nvNNrDhy VrM2ppYmj/H+hgOuWGJ0jw+cVWQIWwHuF+G/ieKJUVD9C/rL9hzOjGM3Z6qZaQ== 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 4XZ2Qc10f9zfGY; Thu, 24 Oct 2024 10:36:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49OAaekH059146; Thu, 24 Oct 2024 10:36:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49OAaeGD059143; Thu, 24 Oct 2024 10:36:40 GMT (envelope-from git) Date: Thu, 24 Oct 2024 10:36:40 GMT Message-Id: <202410241036.49OAaeGD059143@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: d7f930b80e89 - main - arm64: Implement efi_rt_arch_call List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: d7f930b80e8928efd9f0bdc0fd48585f8b0b7061 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=d7f930b80e8928efd9f0bdc0fd48585f8b0b7061 commit d7f930b80e8928efd9f0bdc0fd48585f8b0b7061 Author: Andrew Turner AuthorDate: 2024-10-24 09:52:46 +0000 Commit: Andrew Turner CommitDate: 2024-10-24 10:20:48 +0000 arm64: Implement efi_rt_arch_call This is a function that calls into the EFI Runtime Services, but can handle a fault. To support this add a handler in assembly that can restore the kernel state on an exception and return a failure to the caller. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46817 --- sys/arm64/arm64/efirt_machdep.c | 9 ++-- sys/arm64/arm64/efirt_support.S | 101 ++++++++++++++++++++++++++++++++++++++++ sys/arm64/arm64/genassym.c | 6 +++ sys/arm64/include/proc.h | 6 ++- sys/conf/files.arm64 | 1 + 5 files changed, 116 insertions(+), 7 deletions(-) diff --git a/sys/arm64/arm64/efirt_machdep.c b/sys/arm64/arm64/efirt_machdep.c index 47e0a209d8b1..aad3761844e1 100644 --- a/sys/arm64/arm64/efirt_machdep.c +++ b/sys/arm64/arm64/efirt_machdep.c @@ -50,6 +50,7 @@ #include #include +#include #include #include #include @@ -239,6 +240,7 @@ efi_arch_enter(void) { CRITICAL_ASSERT(curthread); + curthread->td_md.md_efirt_dis_pf = vm_fault_disable_pagefaults(); /* * Temporarily switch to EFI's page table. However, we leave curpmap @@ -269,11 +271,6 @@ efi_arch_leave(void) set_ttbr0(pmap_to_ttbr0(PCPU_GET(curpmap))); if (PCPU_GET(bcast_tlbi_workaround) != 0) invalidate_local_icache(); + vm_fault_enable_pagefaults(curthread->td_md.md_efirt_dis_pf); } -int -efi_rt_arch_call(struct efirt_callinfo *ec) -{ - - panic("not implemented"); -} diff --git a/sys/arm64/arm64/efirt_support.S b/sys/arm64/arm64/efirt_support.S new file mode 100644 index 000000000000..b7bef7500ee4 --- /dev/null +++ b/sys/arm64/arm64/efirt_support.S @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2024 Arm Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include + +#include "assym.inc" + +/* + * int efi_rt_arch_call(struct efirt_callinfo *); + */ +ENTRY(efi_rt_arch_call) + sub sp, sp, #(14 * 8) + stp x19, x20, [sp, #(2 * 8)] + stp x21, x22, [sp, #(4 * 8)] + stp x23, x24, [sp, #(6 * 8)] + stp x25, x26, [sp, #(8 * 8)] + stp x27, x28, [sp, #(10 * 8)] + stp x29, x30, [sp, #(12 * 8)] + add x29, sp, #(12 * 8) + + /* Save the stack pointer so we can find it later */ + ldr x23, [x18, #PC_CURTHREAD] + mov x24, sp + str x24, [x23, #TD_MD_EFIRT_TMP] + + mov x22, x0 + + /* Load the function to branch to */ + ldr x9, [x22, #(EC_FPTR)] + + /* Load the arguments */ + ldr x4, [x22, #(EC_ARG1 + (4 * 8))] + ldr x3, [x22, #(EC_ARG1 + (3 * 8))] + ldr x2, [x22, #(EC_ARG1 + (2 * 8))] + ldr x1, [x22, #(EC_ARG1 + (1 * 8))] + ldr x0, [x22, #(EC_ARG1 + (0 * 8))] + + /* Set the fault handler */ + adr x10, efi_rt_fault + SET_FAULT_HANDLER(x10, x11) + + blr x9 + + /* Clear the fault handler */ + SET_FAULT_HANDLER(xzr, x11) + + /* Store the result */ + str x0, [x22, #(EC_EFI_STATUS)] + mov x0, #0 + +.Lefi_rt_arch_call_exit: + ldp x19, x20, [sp, #(2 * 8)] + ldp x21, x22, [sp, #(4 * 8)] + ldp x23, x24, [sp, #(6 * 8)] + ldp x25, x26, [sp, #(8 * 8)] + ldp x27, x28, [sp, #(10 * 8)] + ldp x29, x30, [sp, #(12 * 8)] + add sp, sp, #(14 * 8) + + ret +END(efi_rt_arch_call) + +ENTRY(efi_rt_fault) + /* Clear pcb_onfault */ + SET_FAULT_HANDLER(xzr, x11) + /* Load curthread */ + ldr x1, [x18, #PC_CURTHREAD] + /* Restore the stack pointer */ + ldr x2, [x1, #TD_MD_EFIRT_TMP] + mov sp, x2 + /* Normal exit returning an error */ + ldr x0, =EFAULT + b .Lefi_rt_arch_call_exit +END(efi_rt_fault) + +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c index db076e1ebf48..8612d2eda309 100644 --- a/sys/arm64/arm64/genassym.c +++ b/sys/arm64/arm64/genassym.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,10 @@ ASSYM(BP_KERN_STACK, offsetof(struct arm64_bootparams, kern_stack)); ASSYM(BP_KERN_TTBR0, offsetof(struct arm64_bootparams, kern_ttbr0)); ASSYM(BP_BOOT_EL, offsetof(struct arm64_bootparams, boot_el)); +ASSYM(EC_EFI_STATUS, offsetof(struct efirt_callinfo, ec_efi_status)); +ASSYM(EC_FPTR, offsetof(struct efirt_callinfo, ec_fptr)); +ASSYM(EC_ARG1, offsetof(struct efirt_callinfo, ec_arg1)); + ASSYM(PCPU_SIZE, sizeof(struct pcpu)); ASSYM(PC_CURPCB, offsetof(struct pcpu, pc_curpcb)); ASSYM(PC_CURTHREAD, offsetof(struct pcpu, pc_curthread)); @@ -71,6 +76,7 @@ ASSYM(TD_AST, offsetof(struct thread, td_ast)); ASSYM(TD_FRAME, offsetof(struct thread, td_frame)); ASSYM(TD_LOCK, offsetof(struct thread, td_lock)); ASSYM(TD_MD_CANARY, offsetof(struct thread, td_md.md_canary)); +ASSYM(TD_MD_EFIRT_TMP, offsetof(struct thread, td_md.md_efirt_tmp)); ASSYM(TF_SIZE, sizeof(struct trapframe)); ASSYM(TF_SP, offsetof(struct trapframe, tf_sp)); diff --git a/sys/arm64/include/proc.h b/sys/arm64/include/proc.h index dfd39faadd46..dc2fa2df654d 100644 --- a/sys/arm64/include/proc.h +++ b/sys/arm64/include/proc.h @@ -65,7 +65,11 @@ struct mdthread { struct ptrauth_key apia; } md_ptrauth_kern; - uint64_t md_reserved[4]; + uint64_t md_efirt_tmp; + int md_efirt_dis_pf; + + int md_reserved0; + uint64_t md_reserved[2]; }; struct mdproc { diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 16d70e1addb6..1ed7b57627b4 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -40,6 +40,7 @@ arm64/arm64/debug_monitor.c standard arm64/arm64/disassem.c optional ddb arm64/arm64/dump_machdep.c standard arm64/arm64/efirt_machdep.c optional efirt +arm64/arm64/efirt_support.S optional efirt arm64/arm64/elf32_machdep.c optional compat_freebsd32 arm64/arm64/elf_machdep.c standard arm64/arm64/exception.S standard