/proc/module: use the same logic as /proc/kallsyms for address exposure

The (alleged) users of the module addresses are the same: kernel
profiling.

So just expose the same helper and format macros, and unify the logic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+27 -9
+8
include/linux/kallsyms.h
··· 14 14 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 15 15 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) 16 16 17 + /* How and when do we show kallsyms values? */ 18 + extern int kallsyms_show_value(void); 19 + #ifndef CONFIG_64BIT 20 + # define KALLSYM_FMT "%08lx" 21 + #else 22 + # define KALLSYM_FMT "%016lx" 23 + #endif 24 + 17 25 struct module; 18 26 19 27 #ifdef CONFIG_KALLSYMS
+1 -7
kernel/kallsyms.c
··· 581 581 { 582 582 } 583 583 584 - #ifndef CONFIG_64BIT 585 - # define KALLSYM_FMT "%08lx" 586 - #else 587 - # define KALLSYM_FMT "%016lx" 588 - #endif 589 - 590 584 static int s_show(struct seq_file *m, void *p) 591 585 { 592 586 unsigned long value; ··· 634 640 * Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to 635 641 * block even that). 636 642 */ 637 - static int kallsyms_show_value(void) 643 + int kallsyms_show_value(void) 638 644 { 639 645 switch (kptr_restrict) { 640 646 case 0:
+18 -2
kernel/module.c
··· 4147 4147 { 4148 4148 struct module *mod = list_entry(p, struct module, list); 4149 4149 char buf[MODULE_FLAGS_BUF_SIZE]; 4150 + unsigned long value; 4150 4151 4151 4152 /* We always ignore unformed modules. */ 4152 4153 if (mod->state == MODULE_STATE_UNFORMED) ··· 4163 4162 mod->state == MODULE_STATE_COMING ? "Loading" : 4164 4163 "Live"); 4165 4164 /* Used by oprofile and other similar tools. */ 4166 - seq_printf(m, " 0x%pK", mod->core_layout.base); 4165 + value = m->private ? 0 : (unsigned long)mod->core_layout.base; 4166 + seq_printf(m, " 0x" KALLSYM_FMT, value); 4167 4167 4168 4168 /* Taints info */ 4169 4169 if (mod->taints) ··· 4186 4184 .show = m_show 4187 4185 }; 4188 4186 4187 + /* 4188 + * This also sets the "private" pointer to non-NULL if the 4189 + * kernel pointers should be hidden (so you can just test 4190 + * "m->private" to see if you should keep the values private). 4191 + * 4192 + * We use the same logic as for /proc/kallsyms. 4193 + */ 4189 4194 static int modules_open(struct inode *inode, struct file *file) 4190 4195 { 4191 - return seq_open(file, &modules_op); 4196 + int err = seq_open(file, &modules_op); 4197 + 4198 + if (!err) { 4199 + struct seq_file *m = file->private_data; 4200 + m->private = kallsyms_show_value() ? NULL : (void *)8ul; 4201 + } 4202 + 4203 + return 0; 4192 4204 } 4193 4205 4194 4206 static const struct file_operations proc_modules_operations = {