Skip to content

Commit 68b1edd

Browse files
author
Peter Zijlstra
committed
static_call: Fix static_call_set_init()
It turns out that static_call_set_init() does not preserve the other flags; IOW. it clears TAIL if it was set. Fixes: 9183c3f ("static_call: Add inline static call infrastructure") Reported-by: Sumit Garg <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Jarkko Sakkinen <[email protected]> Tested-by: Sumit Garg <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent bee6457 commit 68b1edd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

kernel/static_call.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,30 @@ static inline void *static_call_addr(struct static_call_site *site)
3535
return (void *)((long)site->addr + (long)&site->addr);
3636
}
3737

38+
static inline unsigned long __static_call_key(const struct static_call_site *site)
39+
{
40+
return (long)site->key + (long)&site->key;
41+
}
3842

3943
static inline struct static_call_key *static_call_key(const struct static_call_site *site)
4044
{
41-
return (struct static_call_key *)
42-
(((long)site->key + (long)&site->key) & ~STATIC_CALL_SITE_FLAGS);
45+
return (void *)(__static_call_key(site) & ~STATIC_CALL_SITE_FLAGS);
4346
}
4447

4548
/* These assume the key is word-aligned. */
4649
static inline bool static_call_is_init(struct static_call_site *site)
4750
{
48-
return ((long)site->key + (long)&site->key) & STATIC_CALL_SITE_INIT;
51+
return __static_call_key(site) & STATIC_CALL_SITE_INIT;
4952
}
5053

5154
static inline bool static_call_is_tail(struct static_call_site *site)
5255
{
53-
return ((long)site->key + (long)&site->key) & STATIC_CALL_SITE_TAIL;
56+
return __static_call_key(site) & STATIC_CALL_SITE_TAIL;
5457
}
5558

5659
static inline void static_call_set_init(struct static_call_site *site)
5760
{
58-
site->key = ((long)static_call_key(site) | STATIC_CALL_SITE_INIT) -
61+
site->key = (__static_call_key(site) | STATIC_CALL_SITE_INIT) -
5962
(long)&site->key;
6063
}
6164

@@ -190,7 +193,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
190193
}
191194

192195
arch_static_call_transform(site_addr, NULL, func,
193-
static_call_is_tail(site));
196+
static_call_is_tail(site));
194197
}
195198
}
196199

@@ -349,7 +352,7 @@ static int static_call_add_module(struct module *mod)
349352
struct static_call_site *site;
350353

351354
for (site = start; site != stop; site++) {
352-
unsigned long s_key = (long)site->key + (long)&site->key;
355+
unsigned long s_key = __static_call_key(site);
353356
unsigned long addr = s_key & ~STATIC_CALL_SITE_FLAGS;
354357
unsigned long key;
355358

0 commit comments

Comments
 (0)