History

random: do not export add_vmfork_randomness() unless needed

Since add_vmfork_randomness() is only called from vmgenid.o, we can guard it in CONFIG_VMGENID, similarly to how we do with add_disk_randomness() and CONFIG_BLOCK. If we ever have multiple things calling into add_vmfork_randomness(), we can add another shared Kconfig symbol for that, but for now, this is good enough. Even though add_vmfork_randomess() is a pretty small function, removing it means that there are only calls to crng_reseed(false) and none to crng_reseed(true), which means the compiler can constant propagate the false, removing branches from crng_reseed() and its descendants. Additionally, we don't even need the symbol to be exported if CONFIG_VMGENID is not a module, so conditionalize that too.

Jason A. Donenfeld committed 4 years ago

Commit a4107d31 parent af6b54e2 files · +6 −0Browse files

Unified · Split

2 files
  1. drivers/char/random.c +4 −0
  2. include/linux/random.h +2 −0
drivers/char/random.c+4−0
@@ -1168,6 +1168,7 @@ void add_bootloader_randomness(const void *buf, size_t size) · 1167 unmodified lines
1168}1168}
1169EXPORT_SYMBOL_GPL(add_bootloader_randomness);1169EXPORT_SYMBOL_GPL(add_bootloader_randomness);
1170 1170
1171#if IS_ENABLED(CONFIG_VMGENID)
1171/*1172/*
1172 * Handle a new unique VM ID, which is unique, not secret, so we1173 * Handle a new unique VM ID, which is unique, not secret, so we
1173 * don't credit it, but we do immediately force a reseed after so1174 * don't credit it, but we do immediately force a reseed after so
@@ -1181,7 +1182,10 @@ void add_vmfork_randomness(const void *unique_vm_id, size_t size) · 7 unmodified lines
1181 pr_notice("crng reseeded due to virtual machine fork\n");1182 pr_notice("crng reseeded due to virtual machine fork\n");
1182 }1183 }
1183}1184}
1185#if IS_MODULE(CONFIG_VMGENID)
1184EXPORT_SYMBOL_GPL(add_vmfork_randomness);1186EXPORT_SYMBOL_GPL(add_vmfork_randomness);
1187#endif
1188#endif
1185 1189
1186struct fast_pool {1190struct fast_pool {
1187 union {1191 union {
include/linux/random.h+2−0
@@ -34,7 +34,9 @@ extern void add_input_randomness(unsigned int type, unsigned int code, · 33 unmodified lines
34extern void add_interrupt_randomness(int irq) __latent_entropy;34extern void add_interrupt_randomness(int irq) __latent_entropy;
35extern void add_hwgenerator_randomness(const void *buffer, size_t count,35extern void add_hwgenerator_randomness(const void *buffer, size_t count,
36 size_t entropy);36 size_t entropy);
37#if IS_ENABLED(CONFIG_VMGENID)
37extern void add_vmfork_randomness(const void *unique_vm_id, size_t size);38extern void add_vmfork_randomness(const void *unique_vm_id, size_t size);
39#endif
38 40
39extern void get_random_bytes(void *buf, size_t nbytes);41extern void get_random_bytes(void *buf, size_t nbytes);
40extern int wait_for_random_bytes(void);42extern int wait_for_random_bytes(void);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t