Commit ec625021 authored by ZhangPeng's avatar ZhangPeng Committed by Peng Zhang
Browse files

mm/userswap: add VM_USWAP and SWP_USERSWAP_ENTRY

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8KESX


CVE: NA

--------------------------------

VM_USWAP gets set in vma->vm_flags to tell the VM common code that the
userswap is registered. SWP_USERSWAP_ENTRY is the swap entry when
userswap memory is swapped out. In addition, is_userswap_entry() is
introduced to determine whether the entry is a userswap swap entry. Add
the userswap entry case in zap_pte_range() to prevent WARN_ON_ONCE(1).

Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
parent cb1b64b3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -700,6 +700,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
#ifdef CONFIG_X86_USER_SHADOW_STACK
		[ilog2(VM_SHADOW_STACK)] = "ss",
#endif
#ifdef CONFIG_USERSWAP
		[ilog2(VM_USWAP)]	= "us",
#endif /* CONFIG_USERSWAP */
	};
	size_t i;

+7 −0
Original line number Diff line number Diff line
@@ -313,6 +313,13 @@ extern unsigned int kobjsize(const void *objp);
#define VM_NOHUGEPAGE	0x40000000	/* MADV_NOHUGEPAGE marked this vma */
#define VM_MERGEABLE	0x80000000	/* KSM may merge identical pages */

#ifdef CONFIG_USERSWAP
# define VM_USWAP_BIT	62
#define VM_USWAP	BIT(VM_USWAP_BIT)
#else /* !CONFIG_USERSWAP */
#define VM_USWAP	VM_NONE
#endif /* CONFIG_USERSWAP */

#ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
#define VM_HIGH_ARCH_BIT_0	32	/* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_1	33	/* bit only usable on 64-bit architectures */
+13 −1
Original line number Diff line number Diff line
@@ -55,6 +55,18 @@ static inline int current_is_kswapd(void)
 * actions on faults.
 */

/*
 * Userswap entry type
 */
#ifdef CONFIG_USERSWAP
#define SWP_USERSWAP_NUM 1
#define SWP_USERSWAP_ENTRY (MAX_SWAPFILES + SWP_HWPOISON_NUM + \
			    SWP_MIGRATION_NUM + SWP_DEVICE_NUM + \
			    SWP_PTE_MARKER_NUM)
#else
#define SWP_USERSWAP_NUM 0
#endif

/*
 * PTE markers are used to persist information onto PTEs that otherwise
 * should be a none pte.  As its name "PTE" hints, it should only be
@@ -117,7 +129,7 @@ static inline int current_is_kswapd(void)
#define MAX_SWAPFILES \
	((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
	SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
	SWP_PTE_MARKER_NUM)
	SWP_PTE_MARKER_NUM - SWP_USERSWAP_NUM)

/*
 * Magic header for a swap area. The first part of the union is
+12 −0
Original line number Diff line number Diff line
@@ -455,6 +455,18 @@ static inline int pte_none_mostly(pte_t pte)
	return pte_none(pte) || is_pte_marker(pte);
}

#ifdef CONFIG_USERSWAP
static inline int is_userswap_entry(swp_entry_t entry)
{
	return unlikely(swp_type(entry) == SWP_USERSWAP_ENTRY);
}
#else
static inline int is_userswap_entry(swp_entry_t entry)
{
	return 0;
}
#endif

static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry)
{
	struct page *p = pfn_to_page(swp_offset_pfn(entry));
+7 −0
Original line number Diff line number Diff line
@@ -164,6 +164,12 @@ IF_HAVE_PG_ARCH_X(arch_3)
# define IF_HAVE_UFFD_MINOR(flag, name)
#endif

#ifdef CONFIG_USERSWAP
#define IF_HAVE_VM_USWAP(flag, name) {flag, name },
#else
#define IF_HAVE_VM_USWAP(flag, name)
#endif

#define __def_vmaflag_names						\
	{VM_READ,			"read"		},		\
	{VM_WRITE,			"write"		},		\
@@ -196,6 +202,7 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \
	{VM_MIXEDMAP,			"mixedmap"	},		\
	{VM_HUGEPAGE,			"hugepage"	},		\
	{VM_NOHUGEPAGE,			"nohugepage"	},		\
IF_HAVE_VM_USWAP(VM_USWAP,		"userswap"	)		\
	{VM_MERGEABLE,			"mergeable"	}		\

#define show_vma_flags(flags)						\
Loading