Arm Linux Kernel Hacks

rousalome.egloos.com

포토로그 Kernel Crash


통계 위젯 (화이트)

493
557
422263


[부록 C] 리눅스 커널 프로젝트에 기여하기: 패치 코드 리뷰 과정과 업스트림(병합) 확인 부록

이렇게 메일로 패치 코드를 전달한 후 memory management/vmalloc 서스 시스템 메인테이너인 'Andrew Morton'로부터 답장이 왔습니다.
보낸사람: Andrew Morton <akpm@linux-foundation.org>
받는사람: Austin Kim <austindh.kim@gmail.com> 
참조:    linux-mm@kvack.org,
    linux-kernel@vger.kernel.org
제목: Re: [PATCH] mm/vmalloc: move 'area->pages' after if statement

Fair enough.  But we can/should also do this?

--- a/mm/vmalloc.c~mm-vmalloc-move-area-pages-after-if-statement-fix
+++ a/mm/vmalloc.c
@@ -2409,7 +2409,6 @@ static void *__vmalloc_area_node(struct
        nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
        array_size = (nr_pages * sizeof(struct page *));

-       area->nr_pages = nr_pages;
        /* Please note that the recursion is strictly bounded. */
        if (array_size > PAGE_SIZE) {
                pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask,
@@ -2425,6 +2424,7 @@ static void *__vmalloc_area_node(struct
        }

        area->pages = pages;
+       area->nr_pages = nr_pages;

        for (i = 0; i < area->nr_pages; i++) {
                struct page *page;

답장의 내용은 다음과 같습니다.
   
    Fair enough.  But we can/should also do this?    
    좋아. 그런데 다음과 같이 수정하는 것은 어떨까?
   
필자가 수정한 패치 코드에서 뭔가 추가하면 좋은 내용이 보여 메인테이너인 Andrew Morton이 패치 코드를 알려준 것이었습니다. 필자는 '고맙다, 동의한다'라고 답장을 보냈습니다.


필자가 이메일을 통해 Maintainer와 이메일로 의견을 교환한 내역은 다음 사이트에서 확인할 수 있습니다.
https://lkml.org/lkml/2019/8/30/952
https://patchwork.kernel.org/patch/11122851/

https://lkml.org와 https://patchwork.kernel.org 사이트는 리눅스 커널 메일링 리스트를 통해 커널 개발자가 나눈 이메일 내용을 보관하는 사이트입니다.


하루 후 다음과 같은 메일이 전달됐습니다. 패치가 리뷰되면서 'Signed-off-by', 'Acked-by'와 'Reviewed-by'와 같이 커널 개발자로 받은 도장이 보입니다. 필자가 처음에 'Signed-off-by'로 자신의 이메일 주소를 추가한 다음 메인테이너가 'Signed-off-by'를 추가한 것입니다.
제목: + mm-vmalloc-move-area-pages-after-if-statement.patch added to -mm tree

The patch titled
     Subject: mm/vmalloc.c: move 'area->pages' after if statement
has been added to the -mm tree.  Its filename is
     mm-vmalloc-move-area-pages-after-if-statement.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/mm-vmalloc-move-area-pages-after-if-statement.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/mm-vmalloc-move-area-pages-after-if-statement.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Austin Kim <austindh.kim@gmail.com>
Subject: mm/vmalloc.c: move 'area->pages' after if statement

If !area->pages statement is true where memory allocation fails, area is
freed.

In this case 'area->pages = pages' should not executed.  So move
'area->pages = pages' after if statement.

Link: http://lkml.kernel.org/r/20190830035716.GA190684@LGEARND20B15
Signed-off-by: Austin Kim <austindh.kim@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Roman Penyaev <rpenyaev@suse.de>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/vmalloc.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/mm/vmalloc.c~mm-vmalloc-move-area-pages-after-if-statement
+++ a/mm/vmalloc.c
@@ -2417,13 +2417,15 @@ static void *__vmalloc_area_node(struct
        } else {
                pages = kmalloc_node(array_size, nested_gfp, node);
        }
-       area->pages = pages;
-       if (!area->pages) {
+
+       if (!pages) {
                remove_vm_area(area->addr);
                kfree(area);
                return NULL;
        }

+       area->pages = pages;
+
        for (i = 0; i < area->nr_pages; i++) {
                struct page *page;

_

Patches currently in -mm which might be from austindh.kim@gmail.com are

mm-vmalloc-move-area-pages-after-if-statement.patch

이 이메일을 받고 난 후 23일 후에 리눅스 커널 메인 브랜치에 병합(Merge)된 것을 확인할 수 있었습니다.
author Austin Kim <austindh.kim@gmail.com> 2019-09-23 15:36:42 -0700
committer Linus Torvalds <torvalds@linux-foundation.org> 2019-09-24 15:54:10 -0700
commit 7ea362427c170061b8822dd41bafaa72b3bcb9ad (patch)
tree 3b31fc56753b3fcfd467ae6b19b714dd4776ee26
parent 688fcbfc06e4fdfbb7e1d5a942a1460fe6379d2d (diff)
download linux-next-7ea362427c170061b8822dd41bafaa72b3bcb9ad.tar.gz
mm/vmalloc.c: move 'area->pages' after if statement
If !area->pages statement is true where memory allocation fails, area is
freed.

In this case 'area->pages = pages' should not executed.  So move
'area->pages = pages' after if statement.
...
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index f095843..fcadd3e 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2409,7 +2409,6 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
  nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
  array_size = (nr_pages * sizeof(struct page *));
 
- area->nr_pages = nr_pages;
  /* Please note that the recursion is strictly bounded. */
  if (array_size > PAGE_SIZE) {
  pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask,
@@ -2417,13 +2416,16 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
  } else {
  pages = kmalloc_node(array_size, nested_gfp, node);
  }
- area->pages = pages;
- if (!area->pages) {
+
+ if (!pages) {
  remove_vm_area(area->addr);
  kfree(area);
  return NULL;
  }
 
+ area->pages = pages;
+ area->nr_pages = nr_pages;
+
  for (i = 0; i < area->nr_pages; i++) {
  struct page *page;



출처는 다음 사이트입니다.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=7ea362427c170061b8822dd41bafaa72b3bcb9ad


최신 리눅스 커널 코드를 검색해보니 필자와 메인테이너가 제안한 코드가 반영이 됐음을 확인할 수 있습니다. 
[https://elixir.bootlin.com/linux/v5.4-rc1/source/mm/vmalloc.c]
static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
pgprot_t prot, int node)
{
...

/* Please note that the recursion is strictly bounded. */
if (array_size > PAGE_SIZE) {
pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask,
PAGE_KERNEL, node, area->caller);
} else {
pages = kmalloc_node(array_size, nested_gfp, node);
}

if (!pages) {
remove_vm_area(area->addr);
kfree(area);
return NULL;
}

area->pages = pages;
area->nr_pages = nr_pages;


"혹시 궁금한 점이 있으면 댓글로 질문 남겨주세요. 아는 한 성실히 답변 올려드리겠습니다!" 

Thanks,
Austin Kim(austindh.kim@gmail.com)


[부록 A] GCC 지시어
   * inline    
   * noinline    
   * __noreturn   
   * unused   
[부록 B] 리눅스 커널 실력을 키우는 방법
[부록 C] 리눅스 커널 프로젝트에 기여하기  
C.1 리눅스 커널 오픈소스 프로젝트 소개 
   * 용어  
C.2 설정 방법 
C.3 패치 코드를 작성한 후 이메일로 보내기  
C.5 리눅스 커널 오픈소스 프로젝트로 얻는 지식 


# Reference: For more information on 'Linux Kernel';

디버깅을 통해 배우는 리눅스 커널의 구조와 원리. 1

디버깅을 통해 배우는 리눅스 커널의 구조와 원리. 2


 

핑백

덧글

댓글 입력 영역