Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vdso/timens: Refactor copy-pasted find_timens_vvar_page() helper into one copy

find_timens_vvar_page() is not architecture-specific, as can be seen from
how all five per-architecture versions of it are the same.

(arm64, powerpc and riscv are exactly the same; x86 and s390 have two
characters difference inside a comment, less blank lines, and mark the
!CONFIG_TIME_NS version as inline.)

Refactor the five copies into a central copy in kernel/time/namespace.c.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20221130115320.2918447-1-jannh@google.com

authored by

Jann Horn and committed by
Thomas Gleixner
d6c494e8 e0d3da98

+24 -109
-22
arch/arm64/kernel/vdso.c
··· 151 151 mmap_read_unlock(mm); 152 152 return 0; 153 153 } 154 - 155 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 156 - { 157 - if (likely(vma->vm_mm == current->mm)) 158 - return current->nsproxy->time_ns->vvar_page; 159 - 160 - /* 161 - * VM_PFNMAP | VM_IO protect .fault() handler from being called 162 - * through interfaces like /proc/$pid/mem or 163 - * process_vm_{readv,writev}() as long as there's no .access() 164 - * in special_mapping_vmops. 165 - * For more details check_vma_flags() and __access_remote_vm() 166 - */ 167 - WARN(1, "vvar_page accessed remotely"); 168 - 169 - return NULL; 170 - } 171 - #else 172 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 173 - { 174 - return NULL; 175 - } 176 154 #endif 177 155 178 156 static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
-22
arch/powerpc/kernel/vdso.c
··· 129 129 130 130 return 0; 131 131 } 132 - 133 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 134 - { 135 - if (likely(vma->vm_mm == current->mm)) 136 - return current->nsproxy->time_ns->vvar_page; 137 - 138 - /* 139 - * VM_PFNMAP | VM_IO protect .fault() handler from being called 140 - * through interfaces like /proc/$pid/mem or 141 - * process_vm_{readv,writev}() as long as there's no .access() 142 - * in special_mapping_vmops. 143 - * For more details check_vma_flags() and __access_remote_vm() 144 - */ 145 - WARN(1, "vvar_page accessed remotely"); 146 - 147 - return NULL; 148 - } 149 - #else 150 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 151 - { 152 - return NULL; 153 - } 154 132 #endif 155 133 156 134 static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
-22
arch/riscv/kernel/vdso.c
··· 137 137 mmap_read_unlock(mm); 138 138 return 0; 139 139 } 140 - 141 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 142 - { 143 - if (likely(vma->vm_mm == current->mm)) 144 - return current->nsproxy->time_ns->vvar_page; 145 - 146 - /* 147 - * VM_PFNMAP | VM_IO protect .fault() handler from being called 148 - * through interfaces like /proc/$pid/mem or 149 - * process_vm_{readv,writev}() as long as there's no .access() 150 - * in special_mapping_vmops. 151 - * For more details check_vma_flags() and __access_remote_vm() 152 - */ 153 - WARN(1, "vvar_page accessed remotely"); 154 - 155 - return NULL; 156 - } 157 - #else 158 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 159 - { 160 - return NULL; 161 - } 162 140 #endif 163 141 164 142 static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
-20
arch/s390/kernel/vdso.c
··· 44 44 return (struct vdso_data *)(vvar_page); 45 45 } 46 46 47 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 48 - { 49 - if (likely(vma->vm_mm == current->mm)) 50 - return current->nsproxy->time_ns->vvar_page; 51 - /* 52 - * VM_PFNMAP | VM_IO protect .fault() handler from being called 53 - * through interfaces like /proc/$pid/mem or 54 - * process_vm_{readv,writev}() as long as there's no .access() 55 - * in special_mapping_vmops(). 56 - * For more details check_vma_flags() and __access_remote_vm() 57 - */ 58 - WARN(1, "vvar_page accessed remotely"); 59 - return NULL; 60 - } 61 - 62 47 /* 63 48 * The VVAR page layout depends on whether a task belongs to the root or 64 49 * non-root time namespace. Whenever a task changes its namespace, the VVAR ··· 68 83 } 69 84 mmap_read_unlock(mm); 70 85 return 0; 71 - } 72 - #else 73 - static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) 74 - { 75 - return NULL; 76 86 } 77 87 #endif 78 88
-23
arch/x86/entry/vdso/vma.c
··· 98 98 } 99 99 100 100 #ifdef CONFIG_TIME_NS 101 - static struct page *find_timens_vvar_page(struct vm_area_struct *vma) 102 - { 103 - if (likely(vma->vm_mm == current->mm)) 104 - return current->nsproxy->time_ns->vvar_page; 105 - 106 - /* 107 - * VM_PFNMAP | VM_IO protect .fault() handler from being called 108 - * through interfaces like /proc/$pid/mem or 109 - * process_vm_{readv,writev}() as long as there's no .access() 110 - * in special_mapping_vmops(). 111 - * For more details check_vma_flags() and __access_remote_vm() 112 - */ 113 - 114 - WARN(1, "vvar_page accessed remotely"); 115 - 116 - return NULL; 117 - } 118 - 119 101 /* 120 102 * The vvar page layout depends on whether a task belongs to the root or 121 103 * non-root time namespace. Whenever a task changes its namespace, the VVAR ··· 121 139 mmap_read_unlock(mm); 122 140 123 141 return 0; 124 - } 125 - #else 126 - static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) 127 - { 128 - return NULL; 129 142 } 130 143 #endif 131 144
+6
include/linux/time_namespace.h
··· 45 45 void free_time_ns(struct time_namespace *ns); 46 46 void timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk); 47 47 struct vdso_data *arch_get_vdso_data(void *vvar_page); 48 + struct page *find_timens_vvar_page(struct vm_area_struct *vma); 48 49 49 50 static inline void put_time_ns(struct time_namespace *ns) 50 51 { ··· 140 139 struct task_struct *tsk) 141 140 { 142 141 return; 142 + } 143 + 144 + static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) 145 + { 146 + return NULL; 143 147 } 144 148 145 149 static inline void timens_add_monotonic(struct timespec64 *ts) { }
+18
kernel/time/namespace.c
··· 192 192 offset[CLOCK_BOOTTIME_ALARM] = boottime; 193 193 } 194 194 195 + struct page *find_timens_vvar_page(struct vm_area_struct *vma) 196 + { 197 + if (likely(vma->vm_mm == current->mm)) 198 + return current->nsproxy->time_ns->vvar_page; 199 + 200 + /* 201 + * VM_PFNMAP | VM_IO protect .fault() handler from being called 202 + * through interfaces like /proc/$pid/mem or 203 + * process_vm_{readv,writev}() as long as there's no .access() 204 + * in special_mapping_vmops(). 205 + * For more details check_vma_flags() and __access_remote_vm() 206 + */ 207 + 208 + WARN(1, "vvar_page accessed remotely"); 209 + 210 + return NULL; 211 + } 212 + 195 213 /* 196 214 * Protects possibly multiple offsets writers racing each other 197 215 * and tasks entering the namespace.