linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage
@ 2016-07-09 17:17 chengang
  2016-07-11 21:17 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: chengang @ 2016-07-09 17:17 UTC (permalink / raw)
  To: akpm, vbabka, mhocko
  Cc: kirill.shutemov, mingo, dave.hansen, dan.j.williams, hannes,
	jack, iamjoonsoo.kim, jmarchan, dingel, oleg, linux-mm,
	linux-kernel, Chen Gang, Chen Gang

From: Chen Gang <chengang@emindsoft.com.cn>

For a pure output parameter:

 - When callee fails, the caller should not assume the output parameter
   is still valid.

 - And callee should not assume the pure output parameter must be
   provided by caller -- caller has right to pass NULL when caller does
   not care about it.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 include/linux/mm.h | 5 ++---
 mm/gup.c           | 6 +++---
 mm/mlock.c         | 2 +-
 mm/nommu.c         | 1 -
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index b21e5f3..5c560fd 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2205,10 +2205,9 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
 			      unsigned int *page_mask);
 
 static inline struct page *follow_page(struct vm_area_struct *vma,
-		unsigned long address, unsigned int foll_flags)
+				unsigned long address, unsigned int foll_flags)
 {
-	unsigned int unused_page_mask;
-	return follow_page_mask(vma, address, foll_flags, &unused_page_mask);
+	return follow_page_mask(vma, address, foll_flags, NULL);
 }
 
 #define FOLL_WRITE	0x01	/* check pte is writable */
diff --git a/mm/gup.c b/mm/gup.c
index 96b2b2f..9684b06 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -222,8 +222,6 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
 	struct page *page;
 	struct mm_struct *mm = vma->vm_mm;
 
-	*page_mask = 0;
-
 	page = follow_huge_addr(mm, address, flags & FOLL_WRITE);
 	if (!IS_ERR(page)) {
 		BUG_ON(flags & FOLL_GET);
@@ -298,7 +296,8 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
 
 	page = follow_trans_huge_pmd(vma, address, pmd, flags);
 	spin_unlock(ptl);
-	*page_mask = HPAGE_PMD_NR - 1;
+	if (page_mask)
+		*page_mask = HPAGE_PMD_NR - 1;
 	return page;
 }
 
@@ -574,6 +573,7 @@ retry:
 		if (unlikely(fatal_signal_pending(current)))
 			return i ? i : -ERESTARTSYS;
 		cond_resched();
+		page_mask = 0;
 		page = follow_page_mask(vma, start, foll_flags, &page_mask);
 		if (!page) {
 			int ret;
diff --git a/mm/mlock.c b/mm/mlock.c
index ef8dc9f..626eb58 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -438,7 +438,7 @@ void munlock_vma_pages_range(struct vm_area_struct *vma,
 
 	while (start < end) {
 		struct page *page;
-		unsigned int page_mask;
+		unsigned int page_mask = 0;
 		unsigned long page_increm;
 		struct pagevec pvec;
 		struct zone *zone;
diff --git a/mm/nommu.c b/mm/nommu.c
index 95daf81..c1a0a89 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1749,7 +1749,6 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
 			      unsigned long address, unsigned int flags,
 			      unsigned int *page_mask)
 {
-	*page_mask = 0;
 	return NULL;
 }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage
  2016-07-09 17:17 [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage chengang
@ 2016-07-11 21:17 ` Andrew Morton
  2016-07-12 17:03   ` Chen Gang
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2016-07-11 21:17 UTC (permalink / raw)
  To: chengang
  Cc: vbabka, mhocko, kirill.shutemov, mingo, dave.hansen,
	dan.j.williams, hannes, jack, iamjoonsoo.kim, jmarchan, dingel,
	oleg, linux-mm, linux-kernel, Chen Gang

On Sun, 10 Jul 2016 01:17:05 +0800 chengang@emindsoft.com.cn wrote:

> For a pure output parameter:
> 
>  - When callee fails, the caller should not assume the output parameter
>    is still valid.
> 
>  - And callee should not assume the pure output parameter must be
>    provided by caller -- caller has right to pass NULL when caller does
>    not care about it.

Sorry, I don't think this one is worth merging really.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage
  2016-07-11 21:17 ` Andrew Morton
@ 2016-07-12 17:03   ` Chen Gang
  2016-07-13  7:50     ` Michal Hocko
  0 siblings, 1 reply; 5+ messages in thread
From: Chen Gang @ 2016-07-12 17:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: vbabka, mhocko, kirill.shutemov, mingo, dave.hansen,
	dan.j.williams, hannes, jack, iamjoonsoo.kim, jmarchan, dingel,
	oleg, linux-mm, linux-kernel, Chen Gang

On 7/12/16 05:17, Andrew Morton wrote:
> On Sun, 10 Jul 2016 01:17:05 +0800 chengang@emindsoft.com.cn wrote:
> 
>> For a pure output parameter:
>>
>>  - When callee fails, the caller should not assume the output parameter
>>    is still valid.
>>
>>  - And callee should not assume the pure output parameter must be
>>    provided by caller -- caller has right to pass NULL when caller does
>>    not care about it.
> 
> Sorry, I don't think this one is worth merging really.
> 

OK, thanks, I can understand.

It will be better if provide more details: e.g.

 - This patch is incorrect, or the comments is not correct.

 - The patch is worthless, at present.

 - ...

By the way, this patch let the callee keep the output parameter no touch
if callee no additional outputs, callee assumes caller has initialized
the output parameter (for me, it is OK, there are many cases like this).

Thanks.
-- 
Chen Gang (陈刚)

Managing Natural Environments is the Duty of Human Beings.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage
  2016-07-12 17:03   ` Chen Gang
@ 2016-07-13  7:50     ` Michal Hocko
  2016-07-17  0:13       ` Chen Gang
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2016-07-13  7:50 UTC (permalink / raw)
  To: Chen Gang
  Cc: Andrew Morton, vbabka, kirill.shutemov, mingo, dave.hansen,
	dan.j.williams, hannes, jack, iamjoonsoo.kim, jmarchan, dingel,
	oleg, linux-mm, linux-kernel, Chen Gang

On Wed 13-07-16 01:03:10, Chen Gang wrote:
> On 7/12/16 05:17, Andrew Morton wrote:
> > On Sun, 10 Jul 2016 01:17:05 +0800 chengang@emindsoft.com.cn wrote:
> > 
> >> For a pure output parameter:
> >>
> >>  - When callee fails, the caller should not assume the output parameter
> >>    is still valid.
> >>
> >>  - And callee should not assume the pure output parameter must be
> >>    provided by caller -- caller has right to pass NULL when caller does
> >>    not care about it.
> > 
> > Sorry, I don't think this one is worth merging really.
> > 
> 
> OK, thanks, I can understand.
> 
> It will be better if provide more details: e.g.
> 
>  - This patch is incorrect, or the comments is not correct.
> 
>  - The patch is worthless, at present.

I would say the patch is not really needed. The code you are touching
works just fine and there is no reason to touch it unless this is a part
of a larger change where future changes would be easier to
review/implement.

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage
  2016-07-13  7:50     ` Michal Hocko
@ 2016-07-17  0:13       ` Chen Gang
  0 siblings, 0 replies; 5+ messages in thread
From: Chen Gang @ 2016-07-17  0:13 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Andrew Morton, vbabka, kirill.shutemov, mingo, dave.hansen,
	dan.j.williams, hannes, jack, iamjoonsoo.kim, jmarchan, dingel,
	oleg, linux-mm, linux-kernel, Chen Gang


On 7/13/16 15:50, Michal Hocko wrote:
> On Wed 13-07-16 01:03:10, Chen Gang wrote:
>> On 7/12/16 05:17, Andrew Morton wrote:
>>> On Sun, 10 Jul 2016 01:17:05 +0800 chengang@emindsoft.com.cn wrote:
>>>
>>>> For a pure output parameter:
>>>>
>>>>  - When callee fails, the caller should not assume the output parameter
>>>>    is still valid.
>>>>
>>>>  - And callee should not assume the pure output parameter must be
>>>>    provided by caller -- caller has right to pass NULL when caller does
>>>>    not care about it.
>>>
>>> Sorry, I don't think this one is worth merging really.
>>>
>>
>> OK, thanks, I can understand.
>>
>> It will be better if provide more details: e.g.
>>
>>  - This patch is incorrect, or the comments is not correct.
>>
>>  - The patch is worthless, at present.
> 
> I would say the patch is not really needed. The code you are touching
> works just fine and there is no reason to touch it unless this is a part
> of a larger change where future changes would be easier to
> review/implement.
> 

OK, thanks. I shall try to find other kinds of patches in linux/include,
next.  :-)

-- 
Chen Gang (陈刚)

Managing Natural Environments is the Duty of Human Beings.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-17  0:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-09 17:17 [PATCH] mm: gup: Re-define follow_page_mask output parameter page_mask usage chengang
2016-07-11 21:17 ` Andrew Morton
2016-07-12 17:03   ` Chen Gang
2016-07-13  7:50     ` Michal Hocko
2016-07-17  0:13       ` Chen Gang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).