diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 043dc88e8fd902..bb13edc0fa2aca 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -265,7 +265,12 @@ void update_sctlr_el1(u64 sctlr); extern struct task_struct *cpu_switch_to(struct task_struct *prev, struct task_struct *next); -#define task_pt_regs(p) \ +/* + * IAMROOT, 2023.04.08: + * - task용 stack 의 제일 윗부분(최상위 어드레스)에 위치한 pt_regs를 반환 + * - ptrace 용으로 사용될 거라 추정. + */ +#define task_pt_regs(p) \ ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1) #define KSTK_EIP(tsk) ((unsigned long)task_pt_regs(tsk)->pc) diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index 9cf85b2eddc957..10bf1cd8c4b24e 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -250,6 +250,13 @@ static inline unsigned long pstate_to_compat_psr(const unsigned long pstate) * exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for * stack alignment). struct user_pt_regs must form a prefix of struct pt_regs. */ +/* + * IAMROOT. 2023.04.08: + * - google-translate + * 이 구조체는 예외가 발생하는 동안 레지스터가 스택에 저장되는 방식을 + * 정의합니다. sizeof(struct pt_regs)는 스택 정렬을 위해 16의 배수여야 + * 합니다. struct user_pt_regs는 struct pt_regs의 접두사를 형성해야 합니다. + */ struct pt_regs { union { struct user_pt_regs user_regs; diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 40da123da7ac25..58d08a2fac83c5 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -352,6 +352,14 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, * Otherwise we could erroneously skip reloading the FPSIMD * registers for p. */ + /* + * IAMROOT. 2023.04.08: + * - google-translate + * p가 최근에 종료된 다른 작업과 동일한 task_struct 포인터를 할당받은 경우 최근에 + * 종료된 해당 작업을 실행했을 수 있는 CPU에서 p가 연결 해제되었는지 + * 확인합니다. 그렇지 않으면 p에 대한 FPSIMD 레지스터 다시 로드를 잘못 건너뛸 수 + * 있습니다. + */ fpsimd_flush_task_state(p); ptrauth_thread_init_kernel(p); diff --git a/block/blk-ioc.c b/block/blk-ioc.c index 57299f860d41eb..84521432ce1d90 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -300,6 +300,19 @@ int create_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node) * This function always goes through task_lock() and it's better to use * %current->io_context + get_io_context() for %current. */ +/* + * IAMROOT. 2023.04.08: + * - google-translate + * get_task_io_context - 작업의 io_context 가져오기 + * @task: 관심 작업 + * @gfp_flags: 할당 플래그, 할당이 필요한 경우 사용 + * @node: 할당 노드, 할당이 필요한 경우 사용 + * @task의 io_context를 반환합니다. 존재하지 않는 경우 @gfp_flags 및 @node로 + * 생성됩니다. 반환된 io_context는 참조 횟수가 증가합니다. + * + * 이 함수는 항상 task_lock()을 거치며 %current에는 + * %current->io_context + get_io_context()를 사용하는 것이 좋습니다. + */ struct io_context *get_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node) { diff --git a/drivers/base/arch_numa.c b/drivers/base/arch_numa.c index f7bb8e9b3223a4..36550eb048d7bf 100644 --- a/drivers/base/arch_numa.c +++ b/drivers/base/arch_numa.c @@ -36,6 +36,27 @@ static int cpu_to_node_map[NR_CPUS] = { [0 ... NR_CPUS-1] = NUMA_NO_NODE }; * LOCAL_DISTANCE로, 나머지를 REMOTE_DISTANCE로 초기화한다. * - of_numa_parse_distance_map_v1에서 dt에서 읽은 값으로 재설정을 한다. * - numa_distance[from * numa_distance_cnt + to] 의 방식으로 접근한다. + * IAMROOT, 2023.04.08: + * - hip07-d05.dts + * distance-map { + * compatible = "numa-distance-map-v1"; + * distance-matrix = <0 0 10>, + * <0 1 15>, + * <0 2 20>, + * <0 3 25>, + * <1 0 15>, + * <1 1 10>, + * <1 2 25>, + * <1 3 30>, + * <2 0 20>, + * <2 1 25>, + * <2 2 10>, + * <2 3 15>, + * <3 0 25>, + * <3 1 30>, + * <3 2 15>, + * <3 3 10>; + * }; */ static int numa_distance_cnt; static u8 *numa_distance; @@ -436,6 +457,12 @@ void __init numa_set_distance(int from, int to, int distance) /* * Return NUMA distance @from to @to */ +/* + * IAMROOT. 2023.04.08: + * - google-translate + * NUMA 거리 @from을 @to로 반환 + * - from 에서 to 까지 거리를 가져온다 + */ int __node_distance(int from, int to) { if (from >= numa_distance_cnt || to >= numa_distance_cnt) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 5b78739e60e406..026075886b3c55 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -199,6 +199,12 @@ static DEFINE_IDA(proc_inum_ida); * Return an inode number between PROC_DYNAMIC_FIRST and * 0xffffffff, or zero on failure. */ +/* + * IAMROOT. 2023.04.08: + * - google-translate + * PROC_DYNAMIC_FIRST와 0xffffffff 사이의 inode 번호를 반환하거나 실패 시 0을 + * 반환합니다. + */ int proc_alloc_inum(unsigned int *inum) { int i; diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 0db49070cd7ad7..10cfe42ce333b7 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -437,6 +437,10 @@ static __always_inline int bitmap_weight(const unsigned long *src, unsigned int return __bitmap_weight(src, nbits); } +/* + * IAMROOT, 2023.04.08: + * - @map 에서 @start부터 @nbits 수만큼 설정 + */ static __always_inline void bitmap_set(unsigned long *map, unsigned int start, unsigned int nbits) { @@ -451,6 +455,10 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start, __bitmap_set(map, start, nbits); } +/* + * IAMROOT, 2023.04.08: + * - @map 에서 @start부터 @nbits 수만큼 clear + */ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, unsigned int nbits) { diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index 75807ecef880f1..bf857c3c1030c4 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -64,6 +64,10 @@ static inline void proc_free_inum(unsigned int inum) {} #endif /* CONFIG_PROC_FS */ +/* + * IAMROOT, 2023.04.08: + * - stashed = 0, inode num을 할당받아서 반환 + */ static inline int ns_alloc_inum(struct ns_common *ns) { atomic_long_set(&ns->stashed, 0); diff --git a/include/linux/sched.h b/include/linux/sched.h index f9812d696fdc8a..66acd0715296c0 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1274,6 +1274,14 @@ struct task_struct { struct list_head ptrace_entry; /* PID/PID hash table linkage. */ + /* + * IAMROOT, 2023.04.08: + * - 2c4704756cab7cfa031ada4dab361562f0e357c0 커밋에 의해 기존 pids + * 멤버가 변경됨 + * - struct pid_link pids[PIDTYPE_MAX]; + * + struct pid *thread_pid; + * + struct hlist_node pid_links[PIDTYPE_MAX]; + */ struct pid *thread_pid; struct hlist_node pid_links[PIDTYPE_MAX]; struct list_head thread_group; diff --git a/kernel/fork.c b/kernel/fork.c index a9cd0d720a8097..9ca94d5b58dc50 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2652,6 +2652,10 @@ static __latent_entropy struct task_struct *copy_process( stackleak_task_init(p); + /* + * IAMROOT, 2023.04.08: + * - idle thread 용도일 때는 pid 를 만들지 않고 그외에는 pid를 할당 + */ if (pid != &init_struct_pid) { pid = alloc_pid(p->nsproxy->pid_ns_for_children, args->set_tid, args->set_tid_size); @@ -2808,6 +2812,10 @@ static __latent_entropy struct task_struct *copy_process( init_task_pid(p, PIDTYPE_PID, pid); if (thread_group_leader(p)) { + /* + * IAMROOT, 2023.04.08: + * - process를 생성한 경우 + */ init_task_pid(p, PIDTYPE_TGID, pid); init_task_pid(p, PIDTYPE_PGID, task_pgrp(current)); init_task_pid(p, PIDTYPE_SID, task_session(current)); @@ -2832,6 +2840,10 @@ static __latent_entropy struct task_struct *copy_process( attach_pid(p, PIDTYPE_SID); __this_cpu_inc(process_counts); } else { + /* + * IAMROOT, 2023.04.08: + * - thread를 생성한 경우 + */ current->signal->nr_threads++; atomic_inc(¤t->signal->live); refcount_inc(¤t->signal->sigcnt); diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index 3961f062de5fa4..88d5a73da966c3 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c @@ -64,6 +64,14 @@ static inline struct nsproxy *create_nsproxy(void) * Return the newly created nsproxy. Do not attach this to the task, * leave it to the caller to do proper locking and attach it to task. */ +/* + * IAMROOT. 2023.04.08: + * - google-translate + * 새 nsproxy 및 연결된 모든 네임스페이스를 생성합니다. 새로 생성된 nsproxy를 + * 반환합니다. 이것을 작업에 첨부하지 말고 적절한 잠금을 수행하도록 호출자에게 + * 맡기고 작업에 첨부하십시오. + * - TODO. + */ static struct nsproxy *create_new_namespaces(unsigned long flags, struct task_struct *tsk, struct user_namespace *user_ns, struct fs_struct *new_fs) @@ -189,6 +197,10 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk) (CLONE_NEWIPC | CLONE_SYSVSEM)) return -EINVAL; + /* + * IAMROOT, 2023.04.08: + * - container를 하나 생성한다. docker container의 경우 처음 한번만 한다 + */ new_ns = create_new_namespaces(flags, tsk, user_ns, tsk->fs); if (IS_ERR(new_ns)) return PTR_ERR(new_ns); diff --git a/kernel/pid.c b/kernel/pid.c index 3ecc8a0c29ef1a..bfdb89a368fbb7 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -160,6 +160,12 @@ void free_pid(struct pid *pid) call_rcu(&pid->rcu, delayed_put_pid); } +/* + * IAMROOT, 2023.04.08: + * - ns가 별도로 할당되지 않은 경우는 최상위 부모 task가 init_nsproxy를 사용하고 있으므로 + * fork된 task 들도 같은 init_nsproxy를 사용하고 있고 인자 @ns 값은 + * init_pid_ns가 된다 + */ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, size_t set_tid_size) { @@ -178,6 +184,15 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, * for a process in all nested PID namespaces but set_tid_size must * never be greater than the current ns->level + 1. */ + /* + * IAMROOT. 2023.04.08: + * - google-translate + * set_tid_size는 set_tid 배열의 크기를 포함합니다. 가장 중첩된 현재 활성 PID + * 네임스페이스에서 시작하여 set_tid_size PID 네임스페이스까지 가장 중첩된 PID + * 네임스페이스에서 프로세스에 대해 설정할 PID를 alloc_pid()에 알려줍니다. 중첩된 + * 모든 PID 네임스페이스의 프로세스에 대한 PID를 설정할 필요는 없지만 + * set_tid_size는 현재 ns->level + 1보다 커서는 안 됩니다. + */ if (set_tid_size > ns->level + 1) return ERR_PTR(-EINVAL); diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index a76695032664e6..1b6a1f8ed37888 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -36,7 +36,7 @@ static struct kmem_cache *pid_cache[MAX_PID_NS_LEVEL]; /* * IAMROOT, 2023.04.01: - * - ING + * - "pid_(level+1)" 이름으로 kmem cache를 만들어서 반환한다. */ static struct kmem_cache *create_pid_cachep(unsigned int level) { @@ -54,6 +54,12 @@ static struct kmem_cache *create_pid_cachep(unsigned int level) len = sizeof(struct pid) + level * sizeof(struct upid); mutex_lock(&pid_caches_mutex); /* Name collision forces to do allocation under mutex. */ + /* + * IAMROOT. 2023.04.08: + * - google-translate + * 이름 충돌은 뮤텍스 하에 할당을 수행하도록 강제합니다. + * - NOTE. level 크기 만큼 upid 구조체를 증가하여 할당받는다. + */ if (!*pkc) *pkc = kmem_cache_create(name, len, 0, SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, 0); @@ -79,7 +85,7 @@ static void dec_pid_namespaces(struct ucounts *ucounts) /* * IAMROOT, 2023.04.01: - * - ING + * - pid namespace를 생성한다. */ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns, struct pid_namespace *parent_pid_ns) @@ -152,6 +158,10 @@ static void destroy_pid_namespace(struct pid_namespace *ns) call_rcu(&ns->rcu, delayed_free_pidns); } +/* + * IAMROOT, 2023.04.08: + * - CLONE_NEWPID flag 유무에 따라 namespace를 새로 생성하거나 기존걸 반환 + */ struct pid_namespace *copy_pid_ns(unsigned long flags, struct user_namespace *user_ns, struct pid_namespace *old_ns) { diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 1eea6dbc9c063f..5edb72eba2b16b 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1790,6 +1790,21 @@ void sched_init_numa(void) return; bitmap_zero(distance_map, NR_DISTANCE_VALUES); + /* + * IAMROOT, 2023.04.08: + * - ex. node_ids=4 이고 4, 8, 12 가 distanc map 에 설정된 경우 + * distanc_map[0] = 0 + * distanc_map[1] = 0 + * ... + * distanc_map[4] = 1 + * distanc_map[5] = 0 + * ... + * distanc_map[8] = 1 + * ... + * distanc_map[12] = 1 + * ... + * distanc_map[16] = 0 + */ for (i = 0; i < nr_node_ids; i++) { for (j = 0; j < nr_node_ids; j++) { int distance = node_distance(i, j); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 67c92fb086f214..149031ed3f6ce4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -448,6 +448,10 @@ static bool mirrored_kernelcore __meminitdata; int movable_zone; EXPORT_SYMBOL(movable_zone); +/* + * IAMROOT, 2023.04.08: + * - setup_nr_node_ids 에서 설정 + */ #if MAX_NUMNODES > 1 unsigned int nr_node_ids __read_mostly = MAX_NUMNODES; unsigned int nr_online_nodes __read_mostly = 1;