Skip to contentSkip to conversation

mm/migrate.c: also overwrite error when it is bigger than zero

PATCH Superseded Wei Yang 3 participants 10 messages Jan 17, 2020 – Jan 19, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/migrate.c: also overwrite error when it is bigger than zero

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

---
 mm/migrate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c +1 -1
index 557da996b936..c3ef70de5876 100644
@@ -1677,7 +1677,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
 	err1 = do_move_pages_to_node(mm, &pagelist, current_node);
 	if (!err1)
 		err1 = store_status(status, start, current_node, i - start);
-	if (!err)
+	if (err >= 0)
 		err = err1;
 out:
 	return err;
Signature · 1 line
2.17.1
author
#1 lore raw
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Quoted 20 lines

---
mm/migrate.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c +1 -1
index 557da996b936..c3ef70de5876 100644
@@ -1677,7 +1677,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
 	err1 = do_move_pages_to_node(mm, &pagelist, current_node);
 	if (!err1)
 		err1 = store_status(status, start, current_node, i - start);
-	if (!err)
+	if (err >= 0)
 		err = err1;

out:

	return err;
Signature · 1 line
2.17.1
Signature · 2 lines
Wei Yang
Help you, Help me
#2 lore raw
Quoted 11 lines · Wei Yang
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Quoted 5 lines

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Yes, it may return a value which is > 0. But, it seems do_pages_move() could return > 0 value even before this commit.

For example, if I read the code correctly, it would do:

If we already have some pages on the queue then add_page_for_migration() return error, then do_move_pages_to_node() is called, but it may return > 0 value (the number of pages that were *not* migrated by migrate_pages()), then the code flow would just jump to "out" and return the value. And, it may happen to be 1.

I'm not sure if it breaks the user interface since the behavior has been existed for years, and it looks nobody complains about it. Maybe glibc helps hide it or people just care if it is 0 and the status.

Quoted 26 lines
Quoted 18 lines

---
mm/migrate.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c +1 -1
index 557da996b936..c3ef70de5876 100644
@@ -1677,7 +1677,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
      err1 = do_move_pages_to_node(mm, &pagelist, current_node);
      if (!err1)
              err1 = store_status(status, start, current_node, i - start);
-      if (!err)
+      if (err >= 0)
              err = err1;

out:

Quoted 3 lines
      return err;

--
2.17.1

--
Wei Yang
Help you, Help me

author
#3 lore raw
Quoted 21 lines · Yang Shi
Quoted 11 lines · Wei Yang
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Quoted 5 lines

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Yes, it may return a value which is > 0. But, it seems do_pages_move() could return > 0 value even before this commit.

Quoted 8 lines

For example, if I read the code correctly, it would do:

If we already have some pages on the queue then add_page_for_migration() return error, then do_move_pages_to_node() is called, but it may return > 0 value (the number of pages that were *not* migrated by migrate_pages()), then the code flow would just jump to "out" and return the value. And, it may happen to be 1.

This is another point I think current code is not working well. And actually, the behavior is not well defined or our kernel is broken for a while.

When you look at the man page, it says:

RETURN VALUE
On success move_pages() returns zero. On error, it returns -1, and sets errno to indicate the error

So per my understanding, the design is to return -1 on error instead of the pages not managed to move.

For the user interface, if original code check 0 for success, your change breaks it. Because your code would return 1 instead of 0. Suppose most user just read the man page for programming instead of reading the kernel source code. I believe we need to fix it.

Not sure how to include some user interface related developer to look into this issue. Hope this thread may catch their eyes.

Quoted 30 lines

I'm not sure if it breaks the user interface since the behavior has been existed for years, and it looks nobody complains about it. Maybe glibc helps hide it or people just care if it is 0 and the status.

Quoted 26 lines
Quoted 18 lines

---
mm/migrate.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c +1 -1
index 557da996b936..c3ef70de5876 100644
@@ -1677,7 +1677,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
      err1 = do_move_pages_to_node(mm, &pagelist, current_node);
      if (!err1)
              err1 = store_status(status, start, current_node, i - start);
-      if (!err)
+      if (err >= 0)
              err = err1;

out:

Quoted 3 lines
      return err;

--
2.17.1

--
Wei Yang
Help you, Help me

Signature · 2 lines
Wei Yang
Help you, Help me
#4 lore raw
Quoted 8 lines · Wei Yang

This is another point I think current code is not working well. And actually, the behavior is not well defined or our kernel is broken for a while.

When you look at the man page, it says:

RETURN VALUE
On success move_pages() returns zero. On error, it returns -1, and sets errno to indicate the error

Is this from your migrate_pages(2) man page?

The latest version of the migrate_pages(2) man page in the git repo has this for RETURN VALUE.

RETURN VALUE
On success migrate_pages() returns the number of pages that could not be moved (i.e., a return of zero means that all pages were successfully moved). On error, it returns -1, and sets errno to indicate the error.

Signature · 1 line
Mike Kravetz
#6 lore raw
In reply to Wei Yang
Quoted 32 lines · Wei Yang
Quoted 21 lines · Yang Shi
Quoted 11 lines · Wei Yang
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Quoted 5 lines

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Yes, it may return a value which is > 0. But, it seems do_pages_move() could return > 0 value even before this commit.

Quoted 8 lines

For example, if I read the code correctly, it would do:

If we already have some pages on the queue then add_page_for_migration() return error, then do_move_pages_to_node() is called, but it may return > 0 value (the number of pages that were *not* migrated by migrate_pages()), then the code flow would just jump to "out" and return the value. And, it may happen to be 1.

Quoted 2 lines

This is another point I think current code is not working well. And actually, the behavior is not well defined or our kernel is broken for a while.

Yes, we already spotted a few mismatches, inconsistencies and edge cases in these NUMA APIs.

Quoted 8 lines

When you look at the man page, it says:

RETURN VALUE
On success move_pages() returns zero. On error, it returns -1, and sets errno to indicate the error

So per my understanding, the design is to return -1 on error instead of the pages not managed to move.

So do I.

Quoted 5 lines

For the user interface, if original code check 0 for success, your change breaks it. Because your code would return 1 instead of 0. Suppose most user just read the man page for programming instead of reading the kernel source code. I believe we need to fix it.

Yes, I definitely agree we need fix it. But the commit log looks confusing, particularly "on error, the real error code is not returned". If the error is returned by add_page_for_migration() then it will not be returned to userspace instead of reporting via status. Do you mean this?

Quoted 38 lines

Not sure how to include some user interface related developer to look into this issue. Hope this thread may catch their eyes.

Quoted 30 lines

I'm not sure if it breaks the user interface since the behavior has been existed for years, and it looks nobody complains about it. Maybe glibc helps hide it or people just care if it is 0 and the status.

Quoted 26 lines
Quoted 18 lines

---
mm/migrate.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c +1 -1
index 557da996b936..c3ef70de5876 100644
@@ -1677,7 +1677,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
      err1 = do_move_pages_to_node(mm, &pagelist, current_node);
      if (!err1)
              err1 = store_status(status, start, current_node, i - start);
-      if (!err)
+      if (err >= 0)
              err = err1;

out:

Quoted 3 lines
      return err;

--
2.17.1

--
Wei Yang
Help you, Help me

--
Wei Yang
Help you, Help me

#9 lore raw
In reply to Yang Shi
Quoted 22 lines · Yang Shi
Quoted 11 lines · Wei Yang
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Quoted 5 lines

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Yes, it may return a value which is > 0. But, it seems do_pages_move() could return > 0 value even before this commit.

Quoted 7 lines

For example, if I read the code correctly, it would do:

If we already have some pages on the queue then add_page_for_migration() return error, then do_move_pages_to_node() is called, but it may return > 0 value (the number of pages that were *not* migrated by migrate_pages()), then the code flow would just jump to "out" and return the value. And, it may happen to be 1.

Just figured out this is another regression introduced by a49bd4d71637 ("mm, numa: rework do_pages_move"). Already posted a patch to fix it.

Quoted 31 lines

I'm not sure if it breaks the user interface since the behavior has been existed for years, and it looks nobody complains about it. Maybe glibc helps hide it or people just care if it is 0 and the status.

Quoted 26 lines
Quoted 18 lines

---
mm/migrate.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c +1 -1
index 557da996b936..c3ef70de5876 100644
@@ -1677,7 +1677,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
      err1 = do_move_pages_to_node(mm, &pagelist, current_node);
      if (!err1)
              err1 = store_status(status, start, current_node, i - start);
-      if (!err)
+      if (err >= 0)
              err = err1;

out:

Quoted 3 lines
      return err;

--
2.17.1

--
Wei Yang
Help you, Help me

author
#5 lore raw
In reply to Mike Kravetz
Quoted 4 lines · Mike Kravetz
Quoted 3 lines · Wei Yang

This is another point I think current code is not working well. And actually, the behavior is not well defined or our kernel is broken for a while.

Quoted 8 lines
Quoted 5 lines

When you look at the man page, it says:

RETURN VALUE
On success move_pages() returns zero. On error, it returns -1, and sets errno to indicate the error

Is this from your migrate_pages(2) man page?

It is from my move_pages(2) man page.

Quoted 10 lines

The latest version of the migrate_pages(2) man page in the git repo has this for RETURN VALUE.

RETURN VALUE
On success migrate_pages() returns the number of pages that could not be moved (i.e., a return of zero means that all pages were successfully moved). On error, it returns -1, and sets errno to indicate the error.

Signature · 1 line
Mike Kravetz
Signature · 2 lines
Wei Yang
Help you, Help me
author
#7 lore raw
In reply to Yang Shi
Quoted 56 lines · Yang Shi
Quoted 32 lines · Wei Yang
Quoted 21 lines · Yang Shi
Quoted 11 lines · Wei Yang
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Quoted 5 lines

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Yes, it may return a value which is > 0. But, it seems do_pages_move() could return > 0 value even before this commit.

Quoted 8 lines

For example, if I read the code correctly, it would do:

If we already have some pages on the queue then add_page_for_migration() return error, then do_move_pages_to_node() is called, but it may return > 0 value (the number of pages that were *not* migrated by migrate_pages()), then the code flow would just jump to "out" and return the value. And, it may happen to be 1.

Quoted 2 lines

This is another point I think current code is not working well. And actually, the behavior is not well defined or our kernel is broken for a while.

Yes, we already spotted a few mismatches, inconsistencies and edge cases in these NUMA APIs.

Quoted 8 lines

When you look at the man page, it says:

RETURN VALUE
On success move_pages() returns zero. On error, it returns -1, and sets errno to indicate the error

So per my understanding, the design is to return -1 on error instead of the pages not managed to move.

So do I.

Quoted 5 lines

For the user interface, if original code check 0 for success, your change breaks it. Because your code would return 1 instead of 0. Suppose most user just read the man page for programming instead of reading the kernel source code. I believe we need to fix it.

Quoted 6 lines

Yes, I definitely agree we need fix it. But the commit log looks confusing, particularly "on error, the real error code is not returned". If the error is returned by add_page_for_migration() then it will not be returned to userspace instead of reporting via status. Do you mean this?

Sorry for the confusion.

Here I mean, if add_page_for_migratioin() return 1, and the following err1 from do_move_pages_to_node() is set, the err1 is not returned.

The reason is err is not 0 at this point.

Signature · 2 lines
Wei Yang
Help you, Help me
#8 lore raw
Quoted 65 lines · Wei Yang
Quoted 56 lines · Yang Shi
Quoted 32 lines · Wei Yang
Quoted 21 lines · Yang Shi
Quoted 11 lines · Wei Yang
Quoted 8 lines · Wei Yang

If we get here after successfully adding page to list, err would be the number of pages in the list.

Current code has two problems:

* on success, 0 is not returned
* on error, the real error code is not returned

Quoted 5 lines

Well, this breaks the user interface. User would receive 1 even the migration succeed.

The change is introduced by e0153fc2c760 ("mm: move_pages: return valid node id in status if the page is already on the target node").

Yes, it may return a value which is > 0. But, it seems do_pages_move() could return > 0 value even before this commit.

Quoted 8 lines

For example, if I read the code correctly, it would do:

If we already have some pages on the queue then add_page_for_migration() return error, then do_move_pages_to_node() is called, but it may return > 0 value (the number of pages that were *not* migrated by migrate_pages()), then the code flow would just jump to "out" and return the value. And, it may happen to be 1.

Quoted 2 lines

This is another point I think current code is not working well. And actually, the behavior is not well defined or our kernel is broken for a while.

Yes, we already spotted a few mismatches, inconsistencies and edge cases in these NUMA APIs.

Quoted 8 lines

When you look at the man page, it says:

RETURN VALUE
On success move_pages() returns zero. On error, it returns -1, and sets errno to indicate the error

So per my understanding, the design is to return -1 on error instead of the pages not managed to move.

So do I.

Quoted 5 lines

For the user interface, if original code check 0 for success, your change breaks it. Because your code would return 1 instead of 0. Suppose most user just read the man page for programming instead of reading the kernel source code. I believe we need to fix it.

Quoted 6 lines

Yes, I definitely agree we need fix it. But the commit log looks confusing, particularly "on error, the real error code is not returned". If the error is returned by add_page_for_migration() then it will not be returned to userspace instead of reporting via status. Do you mean this?

Quoted 6 lines

Sorry for the confusion.

Here I mean, if add_page_for_migratioin() return 1, and the following err1 from do_move_pages_to_node() is set, the err1 is not returned.

The reason is err is not 0 at this point.

Yes, I see your point. Please elaborate this in the commit log.

Quoted 4 lines

--
Wei Yang
Help you, Help me