All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: make MEMFD_CREATE into a selectable config option
@ 2023-06-30  9:08 Thomas Weißschuh
  2023-06-30 13:38 ` Zhangjin Wu
  2023-06-30 15:32 ` Darrick J. Wong
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2023-06-30  9:08 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Andrew Morton
  Cc: linux-fsdevel, linux-kernel, linux-mm, Willy Tarreau,
	Zhangjin Wu, Thomas Weißschuh

The memfd_create() syscall, enabled by CONFIG_MEMFD_CREATE, is useful on
its own even when not required by CONFIG_TMPFS or CONFIG_HUGETLBFS.

Split it into its own proper bool option that can be enabled by users.

Move that option into mm/ where the code itself also lies.
Also add "select" statements to CONFIG_TMPFS and CONFIG_HUGETLBFS so
they automatically enable CONFIG_MEMFD_CREATE as before.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 fs/Kconfig | 5 ++---
 mm/Kconfig | 3 +++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/Kconfig b/fs/Kconfig
index 18d034ec7953..19975b104bc3 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -169,6 +169,7 @@ source "fs/sysfs/Kconfig"
 config TMPFS
 	bool "Tmpfs virtual memory file system support (former shm fs)"
 	depends on SHMEM
+	select MEMFD_CREATE
 	help
 	  Tmpfs is a file system which keeps all files in virtual memory.
 
@@ -240,6 +241,7 @@ config HUGETLBFS
 	bool "HugeTLB file system support"
 	depends on X86 || IA64 || SPARC64 || ARCH_SUPPORTS_HUGETLBFS || BROKEN
 	depends on (SYSFS || SYSCTL)
+	select MEMFD_CREATE
 	help
 	  hugetlbfs is a filesystem backing for HugeTLB pages, based on
 	  ramfs. For architectures that support it, say Y here and read
@@ -264,9 +266,6 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON
 	  enable HVO by default. It can be disabled via hugetlb_free_vmemmap=off
 	  (boot command line) or hugetlb_optimize_vmemmap (sysctl).
 
-config MEMFD_CREATE
-	def_bool TMPFS || HUGETLBFS
-
 config ARCH_HAS_GIGANTIC_PAGE
 	bool
 
diff --git a/mm/Kconfig b/mm/Kconfig
index 09130434e30d..22acffd9009d 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1144,6 +1144,9 @@ config KMAP_LOCAL_NON_LINEAR_PTE_ARRAY
 config IO_MAPPING
 	bool
 
+config MEMFD_CREATE
+	bool "Enable memfd_create() system call" if EXPERT
+
 config SECRETMEM
 	default y
 	bool "Enable memfd_secret() system call" if EXPERT

---
base-commit: e55e5df193d247a38a5e1ac65a5316a0adcc22fa
change-id: 20230629-config-memfd-be6af03b7dca

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: make MEMFD_CREATE into a selectable config option
  2023-06-30  9:08 [PATCH] mm: make MEMFD_CREATE into a selectable config option Thomas Weißschuh
@ 2023-06-30 13:38 ` Zhangjin Wu
  2023-06-30 15:32 ` Darrick J. Wong
  1 sibling, 0 replies; 5+ messages in thread
From: Zhangjin Wu @ 2023-06-30 13:38 UTC (permalink / raw)
  To: linux
  Cc: akpm, brauner, falcon, linux-fsdevel, linux-kernel, linux-mm, viro, w

Hi, Thomas

I have manually applied your patch on v6.4, enabled MEMFD_CREATE (and disabled
TMPFS and HUGETLBFS) for 3 randomly selected virtual boards:

- arm/vexpress-a9
- aarch64/virt
- mipsel/malta

For all of the above boards, the current vfprintf test (uses
memfd_create) of tools/testing/selftests/nolibc/nolibc-test.c passes
without any failure:

    Running test 'vfprintf'
    0 emptymemfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 'init'
     "" = ""                                                  [OK]
    1 simple "foo" = "foo"                                           [OK]
    2 string "foo" = "foo"                                           [OK]
    3 number "1234" = "1234"                                         [OK]
    4 negnumber "-1234" = "-1234"                                    [OK]
    5 unsigned "12345" = "12345"                                     [OK]
    6 char "c" = "c"                                                 [OK]
    7 hex "f" = "f"                                                  [OK]
    8 pointer "0x1" = "0x1"                                          [OK]
    Errors during this test: 0

If this test result is ok for you, here is my:

Tested-by: Zhangjin Wu <falcon@tinylab.org>

Best regards,
Zhangjin

> 
> The memfd_create() syscall, enabled by CONFIG_MEMFD_CREATE, is useful on
> its own even when not required by CONFIG_TMPFS or CONFIG_HUGETLBFS.
> 
> Split it into its own proper bool option that can be enabled by users.
> 
> Move that option into mm/ where the code itself also lies.
> Also add "select" statements to CONFIG_TMPFS and CONFIG_HUGETLBFS so
> they automatically enable CONFIG_MEMFD_CREATE as before.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  fs/Kconfig | 5 ++---
>  mm/Kconfig | 3 +++
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/Kconfig b/fs/Kconfig
> index 18d034ec7953..19975b104bc3 100644
> --- a/fs/Kconfig
> +++ b/fs/Kconfig
> @@ -169,6 +169,7 @@ source "fs/sysfs/Kconfig"
>  config TMPFS
>  	bool "Tmpfs virtual memory file system support (former shm fs)"
>  	depends on SHMEM
> +	select MEMFD_CREATE
>  	help
>  	  Tmpfs is a file system which keeps all files in virtual memory.
>  
> @@ -240,6 +241,7 @@ config HUGETLBFS
>  	bool "HugeTLB file system support"
>  	depends on X86 || IA64 || SPARC64 || ARCH_SUPPORTS_HUGETLBFS || BROKEN
>  	depends on (SYSFS || SYSCTL)
> +	select MEMFD_CREATE
>  	help
>  	  hugetlbfs is a filesystem backing for HugeTLB pages, based on
>  	  ramfs. For architectures that support it, say Y here and read
> @@ -264,9 +266,6 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON
>  	  enable HVO by default. It can be disabled via hugetlb_free_vmemmap=off
>  	  (boot command line) or hugetlb_optimize_vmemmap (sysctl).
>  
> -config MEMFD_CREATE
> -	def_bool TMPFS || HUGETLBFS
> -
>  config ARCH_HAS_GIGANTIC_PAGE
>  	bool
>  
> diff --git a/mm/Kconfig b/mm/Kconfig
> index 09130434e30d..22acffd9009d 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -1144,6 +1144,9 @@ config KMAP_LOCAL_NON_LINEAR_PTE_ARRAY
>  config IO_MAPPING
>  	bool
>  
> +config MEMFD_CREATE
> +	bool "Enable memfd_create() system call" if EXPERT
> +
>  config SECRETMEM
>  	default y
>  	bool "Enable memfd_secret() system call" if EXPERT
> 
> ---
> base-commit: e55e5df193d247a38a5e1ac65a5316a0adcc22fa
> change-id: 20230629-config-memfd-be6af03b7dca
> 
> Best regards,
> -- 
> Thomas Weißschuh <linux@weissschuh.net>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: make MEMFD_CREATE into a selectable config option
  2023-06-30  9:08 [PATCH] mm: make MEMFD_CREATE into a selectable config option Thomas Weißschuh
  2023-06-30 13:38 ` Zhangjin Wu
@ 2023-06-30 15:32 ` Darrick J. Wong
  2023-06-30 19:55   ` Thomas Weißschuh
  2023-07-03 22:48   ` Mike Kravetz
  1 sibling, 2 replies; 5+ messages in thread
From: Darrick J. Wong @ 2023-06-30 15:32 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Alexander Viro, Christian Brauner, Andrew Morton, linux-fsdevel,
	linux-kernel, linux-mm, Willy Tarreau, Zhangjin Wu

On Fri, Jun 30, 2023 at 11:08:53AM +0200, Thomas Weißschuh wrote:
> The memfd_create() syscall, enabled by CONFIG_MEMFD_CREATE, is useful on
> its own even when not required by CONFIG_TMPFS or CONFIG_HUGETLBFS.

If you don't have tmpfs or hugetlbfs enabled, then what fs ends up
backing the file returned by memfd_create()?  ramfs?

(Not an objection, I'm just curious...)

--D

> Split it into its own proper bool option that can be enabled by users.
> 
> Move that option into mm/ where the code itself also lies.
> Also add "select" statements to CONFIG_TMPFS and CONFIG_HUGETLBFS so
> they automatically enable CONFIG_MEMFD_CREATE as before.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  fs/Kconfig | 5 ++---
>  mm/Kconfig | 3 +++
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/Kconfig b/fs/Kconfig
> index 18d034ec7953..19975b104bc3 100644
> --- a/fs/Kconfig
> +++ b/fs/Kconfig
> @@ -169,6 +169,7 @@ source "fs/sysfs/Kconfig"
>  config TMPFS
>  	bool "Tmpfs virtual memory file system support (former shm fs)"
>  	depends on SHMEM
> +	select MEMFD_CREATE
>  	help
>  	  Tmpfs is a file system which keeps all files in virtual memory.
>  
> @@ -240,6 +241,7 @@ config HUGETLBFS
>  	bool "HugeTLB file system support"
>  	depends on X86 || IA64 || SPARC64 || ARCH_SUPPORTS_HUGETLBFS || BROKEN
>  	depends on (SYSFS || SYSCTL)
> +	select MEMFD_CREATE
>  	help
>  	  hugetlbfs is a filesystem backing for HugeTLB pages, based on
>  	  ramfs. For architectures that support it, say Y here and read
> @@ -264,9 +266,6 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON
>  	  enable HVO by default. It can be disabled via hugetlb_free_vmemmap=off
>  	  (boot command line) or hugetlb_optimize_vmemmap (sysctl).
>  
> -config MEMFD_CREATE
> -	def_bool TMPFS || HUGETLBFS
> -
>  config ARCH_HAS_GIGANTIC_PAGE
>  	bool
>  
> diff --git a/mm/Kconfig b/mm/Kconfig
> index 09130434e30d..22acffd9009d 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -1144,6 +1144,9 @@ config KMAP_LOCAL_NON_LINEAR_PTE_ARRAY
>  config IO_MAPPING
>  	bool
>  
> +config MEMFD_CREATE
> +	bool "Enable memfd_create() system call" if EXPERT
> +
>  config SECRETMEM
>  	default y
>  	bool "Enable memfd_secret() system call" if EXPERT
> 
> ---
> base-commit: e55e5df193d247a38a5e1ac65a5316a0adcc22fa
> change-id: 20230629-config-memfd-be6af03b7dca
> 
> Best regards,
> -- 
> Thomas Weißschuh <linux@weissschuh.net>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: make MEMFD_CREATE into a selectable config option
  2023-06-30 15:32 ` Darrick J. Wong
@ 2023-06-30 19:55   ` Thomas Weißschuh
  2023-07-03 22:48   ` Mike Kravetz
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2023-06-30 19:55 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Alexander Viro, Christian Brauner, Andrew Morton, linux-fsdevel,
	linux-kernel, linux-mm, Willy Tarreau, Zhangjin Wu

On 2023-06-30 08:32:36-0700, Darrick J. Wong wrote:
> On Fri, Jun 30, 2023 at 11:08:53AM +0200, Thomas Weißschuh wrote:
> > The memfd_create() syscall, enabled by CONFIG_MEMFD_CREATE, is useful on
> > its own even when not required by CONFIG_TMPFS or CONFIG_HUGETLBFS.
> 
> If you don't have tmpfs or hugetlbfs enabled, then what fs ends up
> backing the file returned by memfd_create()?  ramfs?

ramfs, correct.

It goes via mm/memfd.c -> mm/shmem.c -> fs/ramfs/ .

Thomas

> (Not an objection, I'm just curious...)
> 
> --D
> 
> > Split it into its own proper bool option that can be enabled by users.
> > 
> > Move that option into mm/ where the code itself also lies.
> > Also add "select" statements to CONFIG_TMPFS and CONFIG_HUGETLBFS so
> > they automatically enable CONFIG_MEMFD_CREATE as before.
> > 
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> >  fs/Kconfig | 5 ++---
> >  mm/Kconfig | 3 +++
> >  2 files changed, 5 insertions(+), 3 deletions(-)

> [..]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: make MEMFD_CREATE into a selectable config option
  2023-06-30 15:32 ` Darrick J. Wong
  2023-06-30 19:55   ` Thomas Weißschuh
@ 2023-07-03 22:48   ` Mike Kravetz
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Kravetz @ 2023-07-03 22:48 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Thomas Weißschuh, Alexander Viro, Christian Brauner,
	Andrew Morton, linux-fsdevel, linux-kernel, linux-mm,
	Willy Tarreau, Zhangjin Wu

On 06/30/23 08:32, Darrick J. Wong wrote:
> On Fri, Jun 30, 2023 at 11:08:53AM +0200, Thomas Weißschuh wrote:
> > The memfd_create() syscall, enabled by CONFIG_MEMFD_CREATE, is useful on
> > its own even when not required by CONFIG_TMPFS or CONFIG_HUGETLBFS.
> 
> If you don't have tmpfs or hugetlbfs enabled, then what fs ends up
> backing the file returned by memfd_create()?  ramfs?
> 
> (Not an objection, I'm just curious...)
> 

It looks like shmem/tmpfs falls back to ramfs?

-- 
Mike Kravetz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-03 22:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-30  9:08 [PATCH] mm: make MEMFD_CREATE into a selectable config option Thomas Weißschuh
2023-06-30 13:38 ` Zhangjin Wu
2023-06-30 15:32 ` Darrick J. Wong
2023-06-30 19:55   ` Thomas Weißschuh
2023-07-03 22:48   ` Mike Kravetz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.