Commit e3452806 authored by Guo Fan's avatar Guo Fan Committed by Cheng Jian
Browse files

userswap: add a new flag 'MAP_REPLACE' for mmap()



hulk inclusion
category: feature
bugzilla: 47439
CVE: NA

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

To make sure there are no other userspace threads access the memory
region we are swapping out, we need unmmap the memory region, map it
to a new address and use the new address to perform the swapout. We add
a new flag 'MAP_REPLACE' for mmap() to unmap the pages of the input
parameter 'VA' and remap them to a new tmpVA.

Signed-off-by: default avatarGuo Fan <guofan5@huawei.com>
Signed-off-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: default avatarJing Xiangfeng <jingxiangfeng@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: default avatarCheng Jian <cj.chengjian@huawei.com>
parent 8bc9bb27
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -665,6 +665,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
		[ilog2(VM_PKEY_BIT4)]	= "",
		[ilog2(VM_PKEY_BIT4)]	= "",
#endif
#endif
#endif /* CONFIG_ARCH_HAS_PKEYS */
#endif /* CONFIG_ARCH_HAS_PKEYS */
#ifdef CONFIG_USERSWAP
		[ilog2(VM_USWAP)]	= "us",
#endif
	};
	};
	size_t i;
	size_t i;


+5 −0
Original line number Original line Diff line number Diff line
@@ -236,6 +236,11 @@ extern unsigned int kobjsize(const void *objp);


#define VM_CHECKNODE 0x200000000
#define VM_CHECKNODE 0x200000000


#ifdef CONFIG_USERSWAP
/* bit[32:36] is the protection key of intel, so use a large value for VM_USWAP */
#define VM_USWAP      0x2000000000000000
#endif

#ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
#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_0	32	/* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_1	33	/* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_1	33	/* bit only usable on 64-bit architectures */
+11 −1
Original line number Original line Diff line number Diff line
@@ -52,6 +52,16 @@ static inline int current_is_kswapd(void)
 * actions on faults.
 * 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)
#else
#define SWP_USERSWAP_NUM 0
#endif

/*
/*
 * Unaddressable device memory support. See include/linux/hmm.h and
 * Unaddressable device memory support. See include/linux/hmm.h and
 * Documentation/vm/hmm.rst. Short description is we need struct pages for
 * Documentation/vm/hmm.rst. Short description is we need struct pages for
@@ -92,7 +102,7 @@ static inline int current_is_kswapd(void)


#define MAX_SWAPFILES \
#define MAX_SWAPFILES \
	((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
	((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
	SWP_MIGRATION_NUM - SWP_HWPOISON_NUM)
	SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - SWP_USERSWAP_NUM)


/*
/*
 * Magic header for a swap area. The first part of the union is
 * Magic header for a swap area. The first part of the union is
+7 −0
Original line number Original line Diff line number Diff line
@@ -130,6 +130,12 @@ IF_HAVE_PG_IDLE(PG_idle, "idle"), \
#define IF_HAVE_VM_SOFTDIRTY(flag,name)
#define IF_HAVE_VM_SOFTDIRTY(flag,name)
#endif
#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						\
#define __def_vmaflag_names						\
	{VM_READ,			"read"		},		\
	{VM_READ,			"read"		},		\
	{VM_WRITE,			"write"		},		\
	{VM_WRITE,			"write"		},		\
@@ -161,6 +167,7 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \
	{VM_MIXEDMAP,			"mixedmap"	},		\
	{VM_MIXEDMAP,			"mixedmap"	},		\
	{VM_HUGEPAGE,			"hugepage"	},		\
	{VM_HUGEPAGE,			"hugepage"	},		\
	{VM_NOHUGEPAGE,			"nohugepage"	},		\
	{VM_NOHUGEPAGE,			"nohugepage"	},		\
IF_HAVE_VM_USWAP(VM_USWAP,		"userswap"	)		\
	{VM_MERGEABLE,			"mergeable"	}		\
	{VM_MERGEABLE,			"mergeable"	}		\


#define show_vma_flags(flags)						\
#define show_vma_flags(flags)						\
+4 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,10 @@
#define MAP_SYNC	0x80000		/* perform synchronous page faults for the mapping */
#define MAP_SYNC	0x80000		/* perform synchronous page faults for the mapping */
#define MAP_PA32BIT	0x400000	/* physical address is within 4G */
#define MAP_PA32BIT	0x400000	/* physical address is within 4G */


#ifdef CONFIG_USERSWAP
#define MAP_REPLACE	0x1000000
#endif

/* Bits [26:31] are reserved, see mman-common.h for MAP_HUGETLB usage */
/* Bits [26:31] are reserved, see mman-common.h for MAP_HUGETLB usage */


#define MCL_CURRENT	1		/* lock all current mappings */
#define MCL_CURRENT	1		/* lock all current mappings */
Loading