2021-08-10 20:31:30

by Yang Shi

[permalink] [raw]
Subject: [PATCH 1/3 linux-next] Revert "mm,shmem: fix a typo in shmem_swapin_page()"

Due to the change about how block layer detects congestion the
justification of commit 8fd2e0b505d1 ("mm: swap: check if swap backing device
is congested or not") doesn't stand anymore, so the commit could be just
reverted in order to solve the race reported by commit 2efa33fc7f6e ("mm/shmem:
fix shmem_swapin() race with swapoff"), so the fix commit and this fix's fix
commit could be reverted as well.

Suggested-by: Hugh Dickins <[email protected]>
Cc: "Huang, Ying" <[email protected]>
Cc: Miaohe Lin <[email protected]>
Signed-off-by: Yang Shi <[email protected]>
---
This revert is for linux-next/-mm tree only since this commit has not
merged into Linus's tree yet.

mm/shmem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 1bea7f50825b..dcc07d14162e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1711,7 +1711,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
/* Prevent swapoff from happening to us. */
si = get_swap_device(swap);
if (!si) {
- error = -EINVAL;
+ error = EINVAL;
goto failed;
}
/* Look it up and read it in.. */
--
2.26.2


2021-08-10 20:33:37

by Yang Shi

[permalink] [raw]
Subject: [PATCH 2/3] Revert "mm/shmem: fix shmem_swapin() race with swapoff"

Due to the change about how block layer detects congestion the
justification of commit 8fd2e0b505d1 ("mm: swap: check if swap backing device
is congested or not") doesn't stand anymore, so the commit could be just
reverted in order to solve the race reported by commit 2efa33fc7f6e ("mm/shmem:
fix shmem_swapin() race with swapoff"), so the fix commit could be just
reverted as well.

Suggested-by: Hugh Dickins <[email protected]>
Cc: "Huang, Ying" <[email protected]>
Cc: Miaohe Lin <[email protected]>
Signed-off-by: Yang Shi <[email protected]>
---
mm/shmem.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index dcc07d14162e..d5427de5bf02 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1699,8 +1699,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
struct address_space *mapping = inode->i_mapping;
struct shmem_inode_info *info = SHMEM_I(inode);
struct mm_struct *charge_mm = vma ? vma->vm_mm : NULL;
- struct swap_info_struct *si;
- struct page *page = NULL;
+ struct page *page;
swp_entry_t swap;
int error;

@@ -1708,12 +1707,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
swap = radix_to_swp_entry(*pagep);
*pagep = NULL;

- /* Prevent swapoff from happening to us. */
- si = get_swap_device(swap);
- if (!si) {
- error = EINVAL;
- goto failed;
- }
/* Look it up and read it in.. */
page = lookup_swap_cache(swap, NULL, 0);
if (!page) {
@@ -1775,8 +1768,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
swap_free(swap);

*pagep = page;
- if (si)
- put_swap_device(si);
return 0;
failed:
if (!shmem_confirm_swap(mapping, index, swap))
@@ -1787,9 +1778,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
put_page(page);
}

- if (si)
- put_swap_device(si);
-
return error;
}

--
2.26.2

2021-08-10 23:17:00

by Yang Shi

[permalink] [raw]
Subject: Re: [PATCH 2/3] Revert "mm/shmem: fix shmem_swapin() race with swapoff"

On Tue, Aug 10, 2021 at 1:29 PM Yang Shi <[email protected]> wrote:
>
> Due to the change about how block layer detects congestion the
> justification of commit 8fd2e0b505d1 ("mm: swap: check if swap backing device
> is congested or not") doesn't stand anymore, so the commit could be just
> reverted in order to solve the race reported by commit 2efa33fc7f6e ("mm/shmem:
> fix shmem_swapin() race with swapoff"), so the fix commit could be just
> reverted as well.

The updated commit log per the discussion with Hugh:

Due to the change about how block layer detects congestion the
justification of commit 8fd2e0b505d1 ("mm: swap: check if swap backing device
is congested or not") doesn't stand anymore, so the commit could be just
reverted in order to solve the race reported by commit 2efa33fc7f6e ("mm/shmem:
fix shmem_swapin() race with swapoff"), so the fix commit could be just
reverted as well.

And that fix is also kind of buggy as discussed by [1] and [2].

[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/

>
> Suggested-by: Hugh Dickins <[email protected]>
> Cc: "Huang, Ying" <[email protected]>
> Cc: Miaohe Lin <[email protected]>
> Signed-off-by: Yang Shi <[email protected]>
> ---
> mm/shmem.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index dcc07d14162e..d5427de5bf02 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1699,8 +1699,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
> struct address_space *mapping = inode->i_mapping;
> struct shmem_inode_info *info = SHMEM_I(inode);
> struct mm_struct *charge_mm = vma ? vma->vm_mm : NULL;
> - struct swap_info_struct *si;
> - struct page *page = NULL;
> + struct page *page;
> swp_entry_t swap;
> int error;
>
> @@ -1708,12 +1707,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
> swap = radix_to_swp_entry(*pagep);
> *pagep = NULL;
>
> - /* Prevent swapoff from happening to us. */
> - si = get_swap_device(swap);
> - if (!si) {
> - error = EINVAL;
> - goto failed;
> - }
> /* Look it up and read it in.. */
> page = lookup_swap_cache(swap, NULL, 0);
> if (!page) {
> @@ -1775,8 +1768,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
> swap_free(swap);
>
> *pagep = page;
> - if (si)
> - put_swap_device(si);
> return 0;
> failed:
> if (!shmem_confirm_swap(mapping, index, swap))
> @@ -1787,9 +1778,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
> put_page(page);
> }
>
> - if (si)
> - put_swap_device(si);
> -
> return error;
> }
>
> --
> 2.26.2
>