Skip to content

Commit

Permalink
98th
Browse files Browse the repository at this point in the history
  • Loading branch information
ybgwon committed Apr 8, 2023
1 parent 43793e3 commit f4807fa
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 3 deletions.
7 changes: 6 additions & 1 deletion arch/arm64/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions arch/arm64/include/asm/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions arch/arm64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions block/blk-ioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
27 changes: 27 additions & 0 deletions drivers/base/arch_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions fs/proc/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions include/linux/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions include/linux/proc_ns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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(&current->signal->live);
refcount_inc(&current->signal->sigcnt);
Expand Down
12 changes: 12 additions & 0 deletions kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions kernel/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down
14 changes: 12 additions & 2 deletions kernel/pid_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
15 changes: 15 additions & 0 deletions kernel/sched/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f4807fa

Please sign in to comment.