--- /dev/null
+From d653fd524304b2745206e16bdcc079b9b394bfd5 Mon Sep 17 00:00:00 2001
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Date: Thu, 22 Jul 2021 15:46:08 +0200
+Subject: Revert "mm/shmem: fix shmem_swapin() race with swapoff"
+
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+This reverts commit a533a21b692fc15a6aadfa827b29c7d9989109ca which is
+commit 2efa33fc7f6ec94a3a538c1a264273c889be2b36 upstream.
+
+It should not have been added to the stable trees, sorry about that.
+
+Link: https://lore.kernel.org/r/YPVgaY6uw59Fqg5x@casper.infradead.org
+Reported-by: From: Matthew Wilcox <willy@infradead.org>
+Cc: Miaohe Lin <linmiaohe@huawei.com>
+Cc: Ying Huang <ying.huang@intel.com>
+Cc: Alex Shi <alexs@kernel.org>
+Cc: David Hildenbrand <david@redhat.com>
+Cc: Dennis Zhou <dennis@kernel.org>
+Cc: Hugh Dickins <hughd@google.com>
+Cc: Johannes Weiner <hannes@cmpxchg.org>
+Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
+Cc: Matthew Wilcox <willy@infradead.org>
+Cc: Michal Hocko <mhocko@suse.com>
+Cc: Minchan Kim <minchan@kernel.org>
+Cc: Tim Chen <tim.c.chen@linux.intel.com>
+Cc: Wei Yang <richard.weiyang@gmail.com>
+Cc: Yang Shi <shy828301@gmail.com>
+Cc: Yu Zhao <yuzhao@google.com>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Linus Torvalds <torvalds@linux-foundation.org>
+Cc: Sasha Levin <sashal@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/shmem.c | 14 +-------------
+ 1 file changed, 1 insertion(+), 13 deletions(-)
+
+diff --git a/mm/shmem.c b/mm/shmem.c
+index 5fa21d66af20..680d83cab077 100644
+--- a/mm/shmem.c
++++ b/mm/shmem.c
+@@ -1696,8 +1696,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 : current->mm;
+- struct swap_info_struct *si;
+- struct page *page = NULL;
++ struct page *page;
+ swp_entry_t swap;
+ int error;
+
+@@ -1705,12 +1704,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) {
+@@ -1772,8 +1765,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))
+@@ -1784,9 +1775,6 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
+ put_page(page);
+ }
+
+- if (si)
+- put_swap_device(si);
+-
+ return error;
+ }
+
+--
+2.32.0
+
--- /dev/null
+From 4b8817e8e7b08c494784eb7116e5aa1beb492a5f Mon Sep 17 00:00:00 2001
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Date: Thu, 22 Jul 2021 15:43:47 +0200
+Subject: Revert "swap: fix do_swap_page() race with swapoff"
+
+From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+This reverts commit 8e4af3917bfc5e82f8010417c12b755ef256fa5e which is
+commit 2799e77529c2a25492a4395db93996e3dacd762d upstream.
+
+It should not have been added to the stable trees, sorry about that.
+
+Link: https://lore.kernel.org/r/YPVgaY6uw59Fqg5x@casper.infradead.org
+Reported-by: From: Matthew Wilcox <willy@infradead.org>
+Cc: Miaohe Lin <linmiaohe@huawei.com>
+Cc: Ying Huang <ying.huang@intel.com>
+Cc: Alex Shi <alexs@kernel.org>
+Cc: David Hildenbrand <david@redhat.com>
+Cc: Dennis Zhou <dennis@kernel.org>
+Cc: Hugh Dickins <hughd@google.com>
+Cc: Johannes Weiner <hannes@cmpxchg.org>
+Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
+Cc: Matthew Wilcox <willy@infradead.org>
+Cc: Michal Hocko <mhocko@suse.com>
+Cc: Minchan Kim <minchan@kernel.org>
+Cc: Tim Chen <tim.c.chen@linux.intel.com>
+Cc: Wei Yang <richard.weiyang@gmail.com>
+Cc: Yang Shi <shy828301@gmail.com>
+Cc: Yu Zhao <yuzhao@google.com>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Linus Torvalds <torvalds@linux-foundation.org>
+Cc: Sasha Levin <sashal@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/swap.h | 9 ---------
+ mm/memory.c | 11 ++---------
+ 2 files changed, 2 insertions(+), 18 deletions(-)
+
+--- a/include/linux/swap.h
++++ b/include/linux/swap.h
+@@ -503,15 +503,6 @@ static inline struct swap_info_struct *s
+ return NULL;
+ }
+
+-static inline struct swap_info_struct *get_swap_device(swp_entry_t entry)
+-{
+- return NULL;
+-}
+-
+-static inline void put_swap_device(struct swap_info_struct *si)
+-{
+-}
+-
+ #define swap_address_space(entry) (NULL)
+ #define get_nr_swap_pages() 0L
+ #define total_swap_pages 0L
+--- a/mm/memory.c
++++ b/mm/memory.c
+@@ -3302,7 +3302,6 @@ vm_fault_t do_swap_page(struct vm_fault
+ {
+ struct vm_area_struct *vma = vmf->vma;
+ struct page *page = NULL, *swapcache;
+- struct swap_info_struct *si = NULL;
+ swp_entry_t entry;
+ pte_t pte;
+ int locked;
+@@ -3330,16 +3329,14 @@ vm_fault_t do_swap_page(struct vm_fault
+ goto out;
+ }
+
+- /* Prevent swapoff from happening to us. */
+- si = get_swap_device(entry);
+- if (unlikely(!si))
+- goto out;
+
+ delayacct_set_flag(DELAYACCT_PF_SWAPIN);
+ page = lookup_swap_cache(entry, vma, vmf->address);
+ swapcache = page;
+
+ if (!page) {
++ struct swap_info_struct *si = swp_swap_info(entry);
++
+ if (data_race(si->flags & SWP_SYNCHRONOUS_IO) &&
+ __swap_count(entry) == 1) {
+ /* skip swapcache */
+@@ -3510,8 +3507,6 @@ vm_fault_t do_swap_page(struct vm_fault
+ unlock:
+ pte_unmap_unlock(vmf->pte, vmf->ptl);
+ out:
+- if (si)
+- put_swap_device(si);
+ return ret;
+ out_nomap:
+ pte_unmap_unlock(vmf->pte, vmf->ptl);
+@@ -3523,8 +3518,6 @@ out_release:
+ unlock_page(swapcache);
+ put_page(swapcache);
+ }
+- if (si)
+- put_swap_device(si);
+ return ret;
+ }
+