]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
um: Centralize stub size calculations
authorTiwei Bie <tiwei.btw@antgroup.com>
Wed, 27 Aug 2025 00:57:03 +0000 (08:57 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 10 Sep 2025 12:23:52 +0000 (14:23 +0200)
Currently, the stub size is calculated in multiple places. Define
a macro that performs the calculation so that the code is easier
to read and maintain.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
arch/um/include/shared/as-layout.h
arch/um/kernel/um_arch.c
arch/x86/um/shared/sysdep/stub_32.h
arch/x86/um/shared/sysdep/stub_64.h

index eacf18ec9d0cfd28f7e23b48c7269e9f4380f336..7c7e17bce403dfc20ced4c8b43f96a4272f3f383 100644 (file)
@@ -24,7 +24,8 @@
 #define STUB_CODE STUB_START
 #define STUB_DATA (STUB_CODE + UM_KERN_PAGE_SIZE)
 #define STUB_DATA_PAGES 2
-#define STUB_END (STUB_DATA + STUB_DATA_PAGES * UM_KERN_PAGE_SIZE)
+#define STUB_SIZE ((1 + STUB_DATA_PAGES) * UM_KERN_PAGE_SIZE)
+#define STUB_END (STUB_START + STUB_SIZE)
 
 #ifndef __ASSEMBLER__
 
index 2f5ee045bc7a90e248bce585df084349b1e552ca..6cd464c9095f68489acb688a5432ee04947c44ca 100644 (file)
@@ -331,9 +331,7 @@ int __init linux_main(int argc, char **argv, char **envp)
 
        host_task_size = get_top_address(envp);
        /* reserve a few pages for the stubs */
-       stub_start = host_task_size - STUB_DATA_PAGES * PAGE_SIZE;
-       /* another page for the code portion */
-       stub_start -= PAGE_SIZE;
+       stub_start = host_task_size - STUB_SIZE;
        host_task_size = stub_start;
 
        /* Limit TASK_SIZE to what is addressable by the page table */
index df568fc3ceb41afaeb4ffd89deeb0b90c2de667b..9dc2efaf5df1845f706b985619c72b797913bce5 100644 (file)
@@ -129,7 +129,7 @@ static __always_inline void *get_stub_data(void)
                "subl %0,%%esp ;"                                       \
                "movl %1, %%eax ; "                                     \
                "call *%%eax ;"                                         \
-               :: "i" ((1 + STUB_DATA_PAGES) * UM_KERN_PAGE_SIZE),     \
+               :: "i" (STUB_SIZE),                                     \
                   "i" (&fn))
 
 static __always_inline void
index 9cfd31afa7699c13cf89302441c44f0ed032bbc9..9fd56954e2e076fc6d8f2f50c28be52909edbb59 100644 (file)
@@ -133,7 +133,7 @@ static __always_inline void *get_stub_data(void)
                "subq %0,%%rsp ;"                                       \
                "movq %1,%%rax ;"                                       \
                "call *%%rax ;"                                         \
-               :: "i" ((1 + STUB_DATA_PAGES) * UM_KERN_PAGE_SIZE),     \
+               :: "i" (STUB_SIZE),                                     \
                   "i" (&fn))
 
 static __always_inline void