Skip to content

Commit

Permalink
xnu-6153.81.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jan 11, 2021
1 parent d4420a4 commit 62e8fb1
Show file tree
Hide file tree
Showing 88 changed files with 10,018 additions and 161 deletions.
3 changes: 3 additions & 0 deletions bsd/conf/files.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ bsd/dev/arm/unix_signal.c standard

bsd/dev/arm64/cpu_in_cksum.s standard

#if defined(KERNEL_INTEGRITY_CTRR)
bsd/tests/ctrr_test_sysctl.c optional config_xnupost
#endif /* defined(KERNEL_INTEGRITY_CTRR) */

bsd/dev/arm64/dtrace_isa.c optional config_dtrace
bsd/dev/arm64/dtrace_subr_arm.c optional config_dtrace
Expand Down
52 changes: 52 additions & 0 deletions bsd/dev/arm64/dtrace_isa.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ typedef arm_saved_state_t savearea_t;
extern lck_attr_t *dtrace_lck_attr;
extern lck_grp_t *dtrace_lck_grp;

#if XNU_MONITOR
extern void * pmap_stacks_start;
extern void * pmap_stacks_end;
#endif

struct frame {
struct frame *backchain;
Expand Down Expand Up @@ -455,6 +459,14 @@ dtrace_getufpstack(uint64_t * pcstack, uint64_t * fpstack, int pcstack_limit)
}
}

#if XNU_MONITOR
static inline boolean_t
dtrace_frame_in_ppl_stack(struct frame * fp)
{
return ((void *)fp >= pmap_stacks_start) &&
((void *)fp < pmap_stacks_end);
}
#endif

void
dtrace_getpcstack(pc_t * pcstack, int pcstack_limit, int aframes,
Expand All @@ -464,13 +476,21 @@ dtrace_getpcstack(pc_t * pcstack, int pcstack_limit, int aframes,
struct frame *nextfp, *minfp, *stacktop;
int depth = 0;
int on_intr;
#if XNU_MONITOR
int on_ppl_stack;
#endif
int last = 0;
uintptr_t pc;
uintptr_t caller = CPU->cpu_dtrace_caller;

if ((on_intr = CPU_ON_INTR(CPU)) != 0) {
stacktop = (struct frame *) dtrace_get_cpu_int_stack_top();
}
#if XNU_MONITOR
else if ((on_ppl_stack = dtrace_frame_in_ppl_stack(fp))) {
stacktop = (struct frame *) pmap_stacks_end;
}
#endif
else {
stacktop = (struct frame *) (dtrace_get_kernel_stack(current_thread()) + kernel_stack_size);
}
Expand All @@ -496,6 +516,14 @@ dtrace_getpcstack(pc_t * pcstack, int pcstack_limit, int aframes,
if (arm_kern_regs) {
nextfp = (struct frame *)(saved_state64(arm_kern_regs)->fp);

#if XNU_MONITOR
on_ppl_stack = dtrace_frame_in_ppl_stack(nextfp);

if (on_ppl_stack) {
minfp = pmap_stacks_start;
stacktop = pmap_stacks_end;
} else
#endif
{
vm_offset_t kstack_base = dtrace_get_kernel_stack(current_thread());

Expand All @@ -517,6 +545,30 @@ dtrace_getpcstack(pc_t * pcstack, int pcstack_limit, int aframes,
last = 1;
}
} else {
#if XNU_MONITOR
if ((!on_ppl_stack) && dtrace_frame_in_ppl_stack(nextfp)) {
/*
* We are switching from the kernel stack
* to the PPL stack.
*/
on_ppl_stack = 1;
minfp = pmap_stacks_start;
stacktop = pmap_stacks_end;
} else if (on_ppl_stack) {
/*
* We could be going from the PPL stack
* to the kernel stack.
*/
vm_offset_t kstack_base = dtrace_get_kernel_stack(current_thread());

minfp = (struct frame *)kstack_base;
stacktop = (struct frame *)(kstack_base + kernel_stack_size);

if (nextfp <= minfp || nextfp >= stacktop) {
last = 1;
}
} else
#endif
{
/*
* This is the last frame we can process; indicate
Expand Down
24 changes: 24 additions & 0 deletions bsd/dev/arm64/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ SYSCTL_PROC(_machdep, OID_AUTO, wake_conttime,
0, 0, sysctl_wake_conttime, "I",
"Continuous Time at the last wakeup");

#if defined(HAS_IPI)
static int
cpu_signal_deferred_timer(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
{
int new_value = 0;
int changed = 0;

int old_value = (int)ml_cpu_signal_deferred_get_timer();

int error = sysctl_io_number(req, old_value, sizeof(int), &new_value, &changed);

if (error == 0 && changed) {
ml_cpu_signal_deferred_adjust_timer((uint64_t)new_value);
}

return error;
}

SYSCTL_PROC(_machdep, OID_AUTO, deferred_ipi_timeout,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
0, 0,
cpu_signal_deferred_timer, "I", "Deferred IPI timeout (nanoseconds)");

#endif /* defined(HAS_IPI) */

/*
* For source compatibility, here's some machdep.cpu mibs that
Expand Down
30 changes: 19 additions & 11 deletions bsd/kern/kern_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

#include <security/audit/audit.h>

#if CONFIG_MACF
#include <security/mac_framework.h>
#endif /* CONFIG_MACF */

#if CONFIG_CSR
#include <sys/codesign.h>
#include <sys/csr.h>
Expand Down Expand Up @@ -221,7 +225,7 @@ collectth_state(thread_t th_act, void *tirp)
* coredump_flags Extra options (ignore rlimit, run fsync)
*
* Returns: 0 Success
* EFAULT Failed
* !0 Failure errno
*
* IMPORTANT: This function can only be called on the current process, due
* to assumptions below; see variable declaration section for
Expand Down Expand Up @@ -252,7 +256,7 @@ coredump(proc_t core_proc, uint32_t reserve_mb, int coredump_flags)
int error1 = 0;
char stack_name[MAXCOMLEN + 6];
char *alloced_name = NULL;
char *name;
char *name = NULL;
mythread_state_flavor_t flavors[MAX_TSTATE_FLAVORS];
vm_size_t mapsize;
int i;
Expand All @@ -276,11 +280,16 @@ coredump(proc_t core_proc, uint32_t reserve_mb, int coredump_flags)
((sugid_coredump == 0) && /* Not dumping SUID/SGID binaries */
((kauth_cred_getsvuid(cred) != kauth_cred_getruid(cred)) ||
(kauth_cred_getsvgid(cred) != kauth_cred_getrgid(cred))))) {
#if CONFIG_AUDIT
audit_proc_coredump(core_proc, NULL, EFAULT);
#endif
return EFAULT;
error = EFAULT;
goto out2;
}

#if CONFIG_MACF
error = mac_proc_check_dump_core(core_proc);
if (error != 0) {
goto out2;
}
#endif

#if CONFIG_CSR
/* If the process is restricted, CSR isn't configured to allow
Expand All @@ -289,10 +298,8 @@ coredump(proc_t core_proc, uint32_t reserve_mb, int coredump_flags)
if (cs_restricted(core_proc) &&
csr_check(CSR_ALLOW_TASK_FOR_PID) &&
csr_check(CSR_ALLOW_APPLE_INTERNAL)) {
#if CONFIG_AUDIT
audit_proc_coredump(core_proc, NULL, EFAULT);
#endif
return EFAULT;
error = EPERM;
goto out2;
}
#endif

Expand All @@ -306,7 +313,8 @@ coredump(proc_t core_proc, uint32_t reserve_mb, int coredump_flags)

if (((coredump_flags & COREDUMP_IGNORE_ULIMIT) == 0) &&
(mapsize >= core_proc->p_rlimit[RLIMIT_CORE].rlim_cur)) {
return EFAULT;
error = EFAULT;
goto out2;
}

(void) task_suspend_internal(task);
Expand Down
4 changes: 4 additions & 0 deletions bsd/kern/kern_memorystatus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,11 @@ int max_jetsam_threads = JETSAM_THREADS_LIMIT;
* - Raise the jetsam threshold ("clear-the-deck")
* - Enabled parallel jetsam on eligible devices
*/
#if __AMP__
int fast_jetsam_enabled = 1;
#else /* __AMP__ */
int fast_jetsam_enabled = 0;
#endif /* __AMP__ */

/* Routine to find the jetsam state structure for the current jetsam thread */
static inline struct jetsam_thread_state *
Expand Down
22 changes: 22 additions & 0 deletions bsd/kern/kern_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,28 @@ SYSCTL_PROC(_kern_perfcontrol_callout, OID_AUTO, update_cycles,
(void *)PERFCONTROL_STAT_CYCLES, PERFCONTROL_CALLOUT_STATE_UPDATE,
sysctl_perfcontrol_callout_stat, "I", "");

#if __AMP__
extern int sched_amp_idle_steal;
SYSCTL_INT(_kern, OID_AUTO, sched_amp_idle_steal,
CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
&sched_amp_idle_steal, 0, "");
extern int sched_amp_spill_steal;
SYSCTL_INT(_kern, OID_AUTO, sched_amp_spill_steal,
CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
&sched_amp_spill_steal, 0, "");
extern int sched_amp_spill_count;
SYSCTL_INT(_kern, OID_AUTO, sched_amp_spill_count,
CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
&sched_amp_spill_count, 0, "");
extern int sched_amp_spill_deferred_ipi;
SYSCTL_INT(_kern, OID_AUTO, sched_amp_spill_deferred_ipi,
CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
&sched_amp_spill_deferred_ipi, 0, "");
extern int sched_amp_pcores_preempt_immediate_ipi;
SYSCTL_INT(_kern, OID_AUTO, sched_amp_pcores_preempt_immediate_ipi,
CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
&sched_amp_pcores_preempt_immediate_ipi, 0, "");
#endif /* __AMP__ */
#endif /* __arm__ || __arm64__ */

#if __arm64__
Expand Down
5 changes: 4 additions & 1 deletion bsd/kern/kern_xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ reboot(struct proc *p, struct reboot_args *uap, __unused int32_t *retval)
}

if (uap->opt & RB_PANIC && uap->msg != USER_ADDR_NULL) {
if (copyinstr(uap->msg, (void *)message, sizeof(message), (size_t *)&dummy)) {
int copy_error = copyinstr(uap->msg, (void *)message, sizeof(message), (size_t *)&dummy);
if (copy_error != 0 && copy_error != ENAMETOOLONG) {
strncpy(message, "user space RB_PANIC message copyin failed", sizeof(message) - 1);
} else {
message[sizeof(message) - 1] = '\0';
}
}

Expand Down
4 changes: 2 additions & 2 deletions bsd/kern/policy_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ common_hook(void)
return rv;
}

#if (MAC_POLICY_OPS_VERSION != 58)
#if (MAC_POLICY_OPS_VERSION != 59)
# error "struct mac_policy_ops doesn't match definition in mac_policy.h"
#endif
/*
Expand Down Expand Up @@ -322,9 +322,9 @@ const static struct mac_policy_ops policy_ops = {
CHECK_SET_HOOK(proc_check_setlcid)
CHECK_SET_HOOK(proc_check_signal)
CHECK_SET_HOOK(proc_check_wait)
CHECK_SET_HOOK(proc_check_dump_core)

.mpo_reserved5 = (mpo_reserved_hook_t *)common_hook,
.mpo_reserved6 = (mpo_reserved_hook_t *)common_hook,

CHECK_SET_HOOK(socket_check_accept)
CHECK_SET_HOOK(socket_check_accepted)
Expand Down
98 changes: 98 additions & 0 deletions bsd/kern/sys_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4024,6 +4024,104 @@ SYSCTL_PROC(_machdep_remotetime, OID_AUTO, conversion_params,
#endif /* CONFIG_MACH_BRIDGE_RECV_TIME */

#if DEVELOPMENT || DEBUG
#if __AMP__
#include <pexpert/pexpert.h>
extern int32_t sysctl_get_bound_cpuid(void);
extern void sysctl_thread_bind_cpuid(int32_t cpuid);
static int
sysctl_kern_sched_thread_bind_cpu SYSCTL_HANDLER_ARGS
{
#pragma unused(oidp, arg1, arg2)

if (!PE_parse_boot_argn("enable_skstb", NULL, 0)) {
return ENOENT;
}

int32_t cpuid = sysctl_get_bound_cpuid();

int32_t new_value;
int changed;
int error = sysctl_io_number(req, cpuid, sizeof cpuid, &new_value, &changed);
if (error) {
return error;
}

if (changed) {
sysctl_thread_bind_cpuid(new_value);
}

return error;
}

SYSCTL_PROC(_kern, OID_AUTO, sched_thread_bind_cpu, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
0, 0, sysctl_kern_sched_thread_bind_cpu, "I", "");

extern char sysctl_get_bound_cluster_type(void);
extern void sysctl_thread_bind_cluster_type(char cluster_type);
static int
sysctl_kern_sched_thread_bind_cluster_type SYSCTL_HANDLER_ARGS
{
#pragma unused(oidp, arg1, arg2)
char buff[4];

if (!PE_parse_boot_argn("enable_skstb", NULL, 0)) {
return ENOENT;
}

int error = SYSCTL_IN(req, buff, 1);
if (error) {
return error;
}
char cluster_type = buff[0];

if (!req->newptr) {
goto out;
}

sysctl_thread_bind_cluster_type(cluster_type);
out:
cluster_type = sysctl_get_bound_cluster_type();
buff[0] = cluster_type;

return SYSCTL_OUT(req, buff, 1);
}

SYSCTL_PROC(_kern, OID_AUTO, sched_thread_bind_cluster_type, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
0, 0, sysctl_kern_sched_thread_bind_cluster_type, "A", "");

extern char sysctl_get_task_cluster_type(void);
extern void sysctl_task_set_cluster_type(char cluster_type);
static int
sysctl_kern_sched_task_set_cluster_type SYSCTL_HANDLER_ARGS
{
#pragma unused(oidp, arg1, arg2)
char buff[4];

if (!PE_parse_boot_argn("enable_skstsct", NULL, 0)) {
return ENOENT;
}

int error = SYSCTL_IN(req, buff, 1);
if (error) {
return error;
}
char cluster_type = buff[0];

if (!req->newptr) {
goto out;
}

sysctl_task_set_cluster_type(cluster_type);
out:
cluster_type = sysctl_get_task_cluster_type();
buff[0] = cluster_type;

return SYSCTL_OUT(req, buff, 1);
}

SYSCTL_PROC(_kern, OID_AUTO, sched_task_set_cluster_type, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
0, 0, sysctl_kern_sched_task_set_cluster_type, "A", "");
#endif /* __AMP__ */
#endif /* DEVELOPMENT || DEBUG */

extern uint32_t task_exc_guard_default;
Expand Down
1 change: 1 addition & 0 deletions bsd/net/dlil.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include <net/if_llatbl.h>
#include <net/net_api_stats.h>
#include <net/if_ports_used.h>
#include <net/if_vlan_var.h>
#include <netinet/in.h>
#if INET
#include <netinet/in_var.h>
Expand Down
Loading

0 comments on commit 62e8fb1

Please sign in to comment.