linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V4] livepatch: non static warnings fix
@ 2019-01-24  1:48 Nicholas Mc Guire
  2019-01-24 17:05 ` Joe Lawrence
  2019-01-25 15:44 ` Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Nicholas Mc Guire @ 2019-01-24  1:48 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Jessica Yu, Jiri Kosina, Miroslav Benes, Petr Mladek,
	live-patching, linux-kernel, Nicholas Mc Guire

Sparse reported warnings about non-static symbols. For the variables
a simple static attribute is fine - for the functions referenced by
livepatch via klp_func the symbol-names must be unmodified in the
symbol table and the patchable code has to be emitted. The resolution
is to attach __used attribute to the shared statically declared functions.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Link: https://lore.kernel.org/lkml/1544965657-26804-1-git-send-email-hofrat@osadl.org/
---

V2: not all static functions shared need to carry the __noclone
    attribute only those that need to be resolved at runtime by
    livepatch - so drop the unnecessary __noclone attributes as
    well as the Note on __noclone as suggested by Joe Lawrence
    <joe.lawrence@redhat.com> - thanks !

V3: fix the wording as proposed by Joe Lawrence
    <joe.lawrence@redhat.com> to address that this is not only
    about how to fix sparse warnings but also to ensure
    traceable/patchable code still being emitted.

V4: fix up the Link to point to the proper page as suggested
    by Joe Lawrence <joe.lawrence@redhat.com>.

Sparse reported the following findings in 5.0-rc3:

  CHECK   samples/livepatch/livepatch-shadow-mod.c
samples/livepatch/livepatch-shadow-mod.c:99:1: warning: symbol 'dummy_list' was not declared. Should it be static?
samples/livepatch/livepatch-shadow-mod.c:100:1: warning: symbol 'dummy_list_mutex' was not declared. Should it be static?
samples/livepatch/livepatch-shadow-mod.c:107:23: warning: symbol 'dummy_alloc' was not declared. Should it be static?
samples/livepatch/livepatch-shadow-mod.c:132:15: warning: symbol 'dummy_free' was not declared. Should it be static?
samples/livepatch/livepatch-shadow-mod.c:140:15: warning: symbol 'dummy_check' was not declared. Should it be static?

  CHECK   samples/livepatch/livepatch-shadow-fix1.c
samples/livepatch/livepatch-shadow-fix1.c:74:14: warning: symbol 'livepatch_fix1_dummy_alloc' was not declared. Should it be static?
samples/livepatch/livepatch-shadow-fix1.c:116:6: warning: symbol 'livepatch_fix1_dummy_free' was not declared. Should it be static?

  CHECK   samples/livepatch/livepatch-shadow-fix2.c
samples/livepatch/livepatch-shadow-fix2.c:53:6: warning: symbol 'livepatch_fix2_dummy_check' was not declared. Should it be static?
samples/livepatch/livepatch-shadow-fix2.c:81:6: warning: symbol 'livepatch_fix2_dummy_free' was not declared. Should it be static?

Patch was compile tested with: x86_64_defconfig + FTRACE=y
FUNCTION_TRACER=y, SAMPLES=y, LIVEPATCH=y SAMPLE_LIVEPATCH=m
(looks sparse, smatch claan, one coccichek warning left - fix later today)

Patch was runtested with:
   insmod samples/livepatch/livepatch-shadow-mod.ko
   insmod samples/livepatch/livepatch-shadow-fix1.ko
   insmod samples/livepatch/livepatch-shadow-fix2.ko
   echo 0 > /sys/kernel/livepatch/livepatch_shadow_fix2/enabled
   echo 0 > /sys/kernel/livepatch/livepatch_shadow_fix1/enabled
   rmmod livepatch-shadow-fix2
   rmmod livepatch-shadow-fix1
   rmmod livepatch-shadow-mod
and dmesg output compared to previous run.

Patch is against 5.0-rc3 (localversion-next is next-20190123)

 samples/livepatch/livepatch-shadow-fix1.c |  4 ++--
 samples/livepatch/livepatch-shadow-fix2.c |  4 ++--
 samples/livepatch/livepatch-shadow-mod.c  | 11 ++++++-----
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c
index a5a5cac..67a73e5 100644
--- a/samples/livepatch/livepatch-shadow-fix1.c
+++ b/samples/livepatch/livepatch-shadow-fix1.c
@@ -71,7 +71,7 @@ static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
 	return 0;
 }
 
-struct dummy *livepatch_fix1_dummy_alloc(void)
+static struct dummy *livepatch_fix1_dummy_alloc(void)
 {
 	struct dummy *d;
 	void *leak;
@@ -113,7 +113,7 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
 			 __func__, d, *shadow_leak);
 }
 
-void livepatch_fix1_dummy_free(struct dummy *d)
+static void livepatch_fix1_dummy_free(struct dummy *d)
 {
 	void **shadow_leak;
 
diff --git a/samples/livepatch/livepatch-shadow-fix2.c b/samples/livepatch/livepatch-shadow-fix2.c
index 52de947..91c21d5 100644
--- a/samples/livepatch/livepatch-shadow-fix2.c
+++ b/samples/livepatch/livepatch-shadow-fix2.c
@@ -50,7 +50,7 @@ struct dummy {
 	unsigned long jiffies_expire;
 };
 
-bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
+static bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
 {
 	int *shadow_count;
 
@@ -78,7 +78,7 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
 			 __func__, d, *shadow_leak);
 }
 
-void livepatch_fix2_dummy_free(struct dummy *d)
+static void livepatch_fix2_dummy_free(struct dummy *d)
 {
 	void **shadow_leak;
 	int *shadow_count;
diff --git a/samples/livepatch/livepatch-shadow-mod.c b/samples/livepatch/livepatch-shadow-mod.c
index 4aa8a88..4d79c6dc 100644
--- a/samples/livepatch/livepatch-shadow-mod.c
+++ b/samples/livepatch/livepatch-shadow-mod.c
@@ -96,15 +96,15 @@ MODULE_DESCRIPTION("Buggy module for shadow variable demo");
  * Keep a list of all the dummies so we can clean up any residual ones
  * on module exit
  */
-LIST_HEAD(dummy_list);
-DEFINE_MUTEX(dummy_list_mutex);
+static LIST_HEAD(dummy_list);
+static DEFINE_MUTEX(dummy_list_mutex);
 
 struct dummy {
 	struct list_head list;
 	unsigned long jiffies_expire;
 };
 
-noinline struct dummy *dummy_alloc(void)
+static __used noinline struct dummy *dummy_alloc(void)
 {
 	struct dummy *d;
 	void *leak;
@@ -129,7 +129,7 @@ noinline struct dummy *dummy_alloc(void)
 	return d;
 }
 
-noinline void dummy_free(struct dummy *d)
+static __used noinline void dummy_free(struct dummy *d)
 {
 	pr_info("%s: dummy @ %p, expired = %lx\n",
 		__func__, d, d->jiffies_expire);
@@ -137,7 +137,8 @@ noinline void dummy_free(struct dummy *d)
 	kfree(d);
 }
 
-noinline bool dummy_check(struct dummy *d, unsigned long jiffies)
+static __used noinline bool dummy_check(struct dummy *d,
+					   unsigned long jiffies)
 {
 	return time_after(jiffies, d->jiffies_expire);
 }
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] livepatch: non static warnings fix
  2019-01-24  1:48 [PATCH V4] livepatch: non static warnings fix Nicholas Mc Guire
@ 2019-01-24 17:05 ` Joe Lawrence
  2019-01-25 15:44 ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: Joe Lawrence @ 2019-01-24 17:05 UTC (permalink / raw)
  To: Nicholas Mc Guire, Josh Poimboeuf
  Cc: Jessica Yu, Jiri Kosina, Miroslav Benes, Petr Mladek,
	live-patching, linux-kernel

On 1/23/19 8:48 PM, Nicholas Mc Guire wrote:
> Sparse reported warnings about non-static symbols. For the variables
> a simple static attribute is fine - for the functions referenced by
> livepatch via klp_func the symbol-names must be unmodified in the
> symbol table and the patchable code has to be emitted. The resolution
> is to attach __used attribute to the shared statically declared functions.
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
> Acked-by: Miroslav Benes <mbenes@suse.cz>
> Link: https://lore.kernel.org/lkml/1544965657-26804-1-git-send-email-hofrat@osadl.org/

Hi Nicholas, thanks for re-posting this fix, the __used attribute change 
was particularly interesting to learn about.

I think Miroslav requested a re-ordering of these tags, perhaps we could 
do the shuffle when we apply the patch to the tree?

   Link:
   Suggested-by:
   Signed-off-by:
   Acked-by:

With that,

Acked-by: Joe Lawrence <joe.lawrence@redhat.com>


> ---
> 
> V2: not all static functions shared need to carry the __noclone
>      attribute only those that need to be resolved at runtime by
>      livepatch - so drop the unnecessary __noclone attributes as
>      well as the Note on __noclone as suggested by Joe Lawrence
>      <joe.lawrence@redhat.com> - thanks !
> 
> V3: fix the wording as proposed by Joe Lawrence
>      <joe.lawrence@redhat.com> to address that this is not only
>      about how to fix sparse warnings but also to ensure
>      traceable/patchable code still being emitted.
> 
> V4: fix up the Link to point to the proper page as suggested
>      by Joe Lawrence <joe.lawrence@redhat.com>.

Credit to Miroslav for these last two change suggestions.

-- Joe

> Sparse reported the following findings in 5.0-rc3:
> 
>    CHECK   samples/livepatch/livepatch-shadow-mod.c
> samples/livepatch/livepatch-shadow-mod.c:99:1: warning: symbol 'dummy_list' was not declared. Should it be static?
> samples/livepatch/livepatch-shadow-mod.c:100:1: warning: symbol 'dummy_list_mutex' was not declared. Should it be static?
> samples/livepatch/livepatch-shadow-mod.c:107:23: warning: symbol 'dummy_alloc' was not declared. Should it be static?
> samples/livepatch/livepatch-shadow-mod.c:132:15: warning: symbol 'dummy_free' was not declared. Should it be static?
> samples/livepatch/livepatch-shadow-mod.c:140:15: warning: symbol 'dummy_check' was not declared. Should it be static?
> 
>    CHECK   samples/livepatch/livepatch-shadow-fix1.c
> samples/livepatch/livepatch-shadow-fix1.c:74:14: warning: symbol 'livepatch_fix1_dummy_alloc' was not declared. Should it be static?
> samples/livepatch/livepatch-shadow-fix1.c:116:6: warning: symbol 'livepatch_fix1_dummy_free' was not declared. Should it be static?
> 
>    CHECK   samples/livepatch/livepatch-shadow-fix2.c
> samples/livepatch/livepatch-shadow-fix2.c:53:6: warning: symbol 'livepatch_fix2_dummy_check' was not declared. Should it be static?
> samples/livepatch/livepatch-shadow-fix2.c:81:6: warning: symbol 'livepatch_fix2_dummy_free' was not declared. Should it be static?
> 
> Patch was compile tested with: x86_64_defconfig + FTRACE=y
> FUNCTION_TRACER=y, SAMPLES=y, LIVEPATCH=y SAMPLE_LIVEPATCH=m
> (looks sparse, smatch claan, one coccichek warning left - fix later today)
> 
> Patch was runtested with:
>     insmod samples/livepatch/livepatch-shadow-mod.ko
>     insmod samples/livepatch/livepatch-shadow-fix1.ko
>     insmod samples/livepatch/livepatch-shadow-fix2.ko
>     echo 0 > /sys/kernel/livepatch/livepatch_shadow_fix2/enabled
>     echo 0 > /sys/kernel/livepatch/livepatch_shadow_fix1/enabled
>     rmmod livepatch-shadow-fix2
>     rmmod livepatch-shadow-fix1
>     rmmod livepatch-shadow-mod
> and dmesg output compared to previous run.
> 
> Patch is against 5.0-rc3 (localversion-next is next-20190123)
> 
>   samples/livepatch/livepatch-shadow-fix1.c |  4 ++--
>   samples/livepatch/livepatch-shadow-fix2.c |  4 ++--
>   samples/livepatch/livepatch-shadow-mod.c  | 11 ++++++-----
>   3 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c
> index a5a5cac..67a73e5 100644
> --- a/samples/livepatch/livepatch-shadow-fix1.c
> +++ b/samples/livepatch/livepatch-shadow-fix1.c
> @@ -71,7 +71,7 @@ static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
>   	return 0;
>   }
>   
> -struct dummy *livepatch_fix1_dummy_alloc(void)
> +static struct dummy *livepatch_fix1_dummy_alloc(void)
>   {
>   	struct dummy *d;
>   	void *leak;
> @@ -113,7 +113,7 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
>   			 __func__, d, *shadow_leak);
>   }
>   
> -void livepatch_fix1_dummy_free(struct dummy *d)
> +static void livepatch_fix1_dummy_free(struct dummy *d)
>   {
>   	void **shadow_leak;
>   
> diff --git a/samples/livepatch/livepatch-shadow-fix2.c b/samples/livepatch/livepatch-shadow-fix2.c
> index 52de947..91c21d5 100644
> --- a/samples/livepatch/livepatch-shadow-fix2.c
> +++ b/samples/livepatch/livepatch-shadow-fix2.c
> @@ -50,7 +50,7 @@ struct dummy {
>   	unsigned long jiffies_expire;
>   };
>   
> -bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
> +static bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
>   {
>   	int *shadow_count;
>   
> @@ -78,7 +78,7 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
>   			 __func__, d, *shadow_leak);
>   }
>   
> -void livepatch_fix2_dummy_free(struct dummy *d)
> +static void livepatch_fix2_dummy_free(struct dummy *d)
>   {
>   	void **shadow_leak;
>   	int *shadow_count;
> diff --git a/samples/livepatch/livepatch-shadow-mod.c b/samples/livepatch/livepatch-shadow-mod.c
> index 4aa8a88..4d79c6dc 100644
> --- a/samples/livepatch/livepatch-shadow-mod.c
> +++ b/samples/livepatch/livepatch-shadow-mod.c
> @@ -96,15 +96,15 @@ MODULE_DESCRIPTION("Buggy module for shadow variable demo");
>    * Keep a list of all the dummies so we can clean up any residual ones
>    * on module exit
>    */
> -LIST_HEAD(dummy_list);
> -DEFINE_MUTEX(dummy_list_mutex);
> +static LIST_HEAD(dummy_list);
> +static DEFINE_MUTEX(dummy_list_mutex);
>   
>   struct dummy {
>   	struct list_head list;
>   	unsigned long jiffies_expire;
>   };
>   
> -noinline struct dummy *dummy_alloc(void)
> +static __used noinline struct dummy *dummy_alloc(void)
>   {
>   	struct dummy *d;
>   	void *leak;
> @@ -129,7 +129,7 @@ noinline struct dummy *dummy_alloc(void)
>   	return d;
>   }
>   
> -noinline void dummy_free(struct dummy *d)
> +static __used noinline void dummy_free(struct dummy *d)
>   {
>   	pr_info("%s: dummy @ %p, expired = %lx\n",
>   		__func__, d, d->jiffies_expire);
> @@ -137,7 +137,8 @@ noinline void dummy_free(struct dummy *d)
>   	kfree(d);
>   }
>   
> -noinline bool dummy_check(struct dummy *d, unsigned long jiffies)
> +static __used noinline bool dummy_check(struct dummy *d,
> +					   unsigned long jiffies)
>   {
>   	return time_after(jiffies, d->jiffies_expire);
>   }
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] livepatch: non static warnings fix
  2019-01-24  1:48 [PATCH V4] livepatch: non static warnings fix Nicholas Mc Guire
  2019-01-24 17:05 ` Joe Lawrence
@ 2019-01-25 15:44 ` Jiri Kosina
  2019-01-27 10:08   ` Nicholas Mc Guire
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Kosina @ 2019-01-25 15:44 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Josh Poimboeuf, Jessica Yu, Miroslav Benes, Petr Mladek,
	live-patching, linux-kernel

On Thu, 24 Jan 2019, Nicholas Mc Guire wrote:

> Sparse reported warnings about non-static symbols. For the variables
> a simple static attribute is fine - for the functions referenced by
> livepatch via klp_func the symbol-names must be unmodified in the
> symbol table and the patchable code has to be emitted. The resolution
> is to attach __used attribute to the shared statically declared functions.
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
> Acked-by: Miroslav Benes <mbenes@suse.cz>
> Link: https://lore.kernel.org/lkml/1544965657-26804-1-git-send-email-hofrat@osadl.org/

I've reordered the tags :) and applied. Thanks,

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] livepatch: non static warnings fix
  2019-01-25 15:44 ` Jiri Kosina
@ 2019-01-27 10:08   ` Nicholas Mc Guire
  0 siblings, 0 replies; 4+ messages in thread
From: Nicholas Mc Guire @ 2019-01-27 10:08 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Nicholas Mc Guire, Josh Poimboeuf, Jessica Yu, Miroslav Benes,
	Petr Mladek, live-patching, linux-kernel

On Fri, Jan 25, 2019 at 04:44:18PM +0100, Jiri Kosina wrote:
> On Thu, 24 Jan 2019, Nicholas Mc Guire wrote:
> 
> > Sparse reported warnings about non-static symbols. For the variables
> > a simple static attribute is fine - for the functions referenced by
> > livepatch via klp_func the symbol-names must be unmodified in the
> > symbol table and the patchable code has to be emitted. The resolution
> > is to attach __used attribute to the shared statically declared functions.
> > 
> > Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> > Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
> > Acked-by: Miroslav Benes <mbenes@suse.cz>
> > Link: https://lore.kernel.org/lkml/1544965657-26804-1-git-send-email-hofrat@osadl.org/
> 
> I've reordered the tags :) and applied. Thanks,
>

thx for your patience - I´ll try getting this streight a bit faster next time

thx!
hofrat 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-27 10:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-24  1:48 [PATCH V4] livepatch: non static warnings fix Nicholas Mc Guire
2019-01-24 17:05 ` Joe Lawrence
2019-01-25 15:44 ` Jiri Kosina
2019-01-27 10:08   ` Nicholas Mc Guire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).