1 /*-
2 * Copyright (c) 2015 The FreeBSD Foundation
3 *
4 * This software was developed by Andrew Turner under
5 * sponsorship from the FreeBSD Foundation.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/proc.h>
33 #include <sys/sysctl.h>
34 #include <sys/sysproto.h>
35
36 #include <vm/vm.h>
37 #include <vm/pmap.h>
38 #include <vm/vm_map.h>
39
40 #include <machine/pcb.h>
41 #include <machine/sysarch.h>
42 #include <machine/vmparam.h>
43
44 #include <security/audit/audit.h>
45
46 int
sysarch(struct thread * td,struct sysarch_args * uap)47 sysarch(struct thread *td, struct sysarch_args *uap)
48 {
49 struct arm64_guard_page_args gp_args;
50 struct pcb *pcb;
51 vm_offset_t eva;
52 unsigned long sve_len;
53 int error;
54
55 switch (uap->op) {
56 case ARM64_GUARD_PAGE:
57 error = copyin(uap->parms, &gp_args, sizeof(gp_args));
58 if (error != 0)
59 return (error);
60
61 /* Only accept canonical addresses, no PAC or TBI */
62 if (!ADDR_IS_CANONICAL(gp_args.addr))
63 return (EINVAL);
64
65 eva = gp_args.addr + gp_args.len;
66
67 /* Check for a length overflow */
68 if (gp_args.addr > eva)
69 return (EINVAL);
70
71 /* Check in the correct address space */
72 if (eva >= VM_MAX_USER_ADDRESS)
73 return (EINVAL);
74
75 /* Nothing to do */
76 if (gp_args.len == 0)
77 return (0);
78
79 error = pmap_bti_set(vmspace_pmap(td->td_proc->p_vmspace),
80 trunc_page(gp_args.addr), round_page(eva));
81 break;
82 case ARM64_GET_SVE_VL:
83 pcb = td->td_pcb;
84 sve_len = pcb->pcb_sve_len;
85 error = EINVAL;
86 if (sve_len != 0)
87 error = copyout(&sve_len, uap->parms, sizeof(sve_len));
88 break;
89 default:
90 error = EINVAL;
91 break;
92 }
93
94 return (error);
95 }
96
97 bool arm64_pid_in_contextidr = false;
98 SYSCTL_BOOL(_machdep, OID_AUTO, pid_in_contextidr, CTLFLAG_RW,
99 &arm64_pid_in_contextidr, false,
100 "Save PID into CONTEXTIDR_EL1 register on context switch");
101