mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miroslav Benes <mbenes@suse.cz>
To: Petr Mladek <pmladek@suse.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
	 Joe Lawrence <joe.lawrence@redhat.com>,
	Nicolai Stange <nstange@suse.de>,
	 live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [POC 3/7] livepatch: Use per-state callbacks in state API tests
Date: Thu, 25 Jul 2024 13:48:06 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LSU.2.21.2407251343160.21729@pobox.suse.cz> (raw)
In-Reply-To: <20231110170428.6664-4-pmladek@suse.com>

Hi,

On Fri, 10 Nov 2023, Petr Mladek wrote:

> Recent changes in the livepatch core have allowed to connect states,
> shadow variables, and callbacks. Use these new features in
> the state tests.
> 
> Use the shadow variable API to store the original loglevel. It is
> better suited for this purpose than directly accessing the .data
> pointer in state klp_state.
> 
> Another big advantage is that the shadow variable is preserved
> when the current patch is replaced by a new version. As a result,
> there is not need to copy the pointer.
> 
> Finally, the lifetime of the shadow variable is connected with
> the lifetime of the state. It is freed automatically when
> it is not longer supported.
> 
> This results into the following changes in the code:
> 
>   + Rename CONSOLE_LOGLEVEL_STATE -> CONSOLE_LOGLEVEL_FIX_ID
>     because it will be used also the for shadow variable
> 
>   + Remove the extra code for module coming and going states
>     because the new callback are per-state.
> 
>   + Remove callbacks needed to transfer the pointer between
>     states.
> 
>   + Keep the versioning of the state to prevent downgrade.
>     The problem is artificial because no callbacks are
>     needed to transfer or free the shadow variable anymore.
> 
> Signed-off-by: Petr Mladek <pmladek@suse.com>

it is much cleaner now.

[...]

>  static int allocate_loglevel_state(void)
>  {
> -	struct klp_state *loglevel_state;
> +	int *shadow_console_loglevel;
>  
> -	loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE);
> -	if (!loglevel_state)
> -		return -EINVAL;
> +	/* Make sure that the shadow variable does not exist yet. */
> +	shadow_console_loglevel =
> +		klp_shadow_alloc(&console_loglevel, CONSOLE_LOGLEVEL_FIX_ID,
> +				 sizeof(*shadow_console_loglevel), GFP_KERNEL,
> +				 NULL, NULL);
>  
> -	loglevel_state->data = kzalloc(sizeof(console_loglevel), GFP_KERNEL);
> -	if (!loglevel_state->data)
> +	if (!shadow_console_loglevel) {
> +		pr_err("%s: failed to allocated shadow variable for storing original loglevel\n",
> +		       __func__);
>  		return -ENOMEM;
> +	}
>  
>  	pr_info("%s: allocating space to store console_loglevel\n",
>  		__func__);
> +
>  	return 0;
>  }

Would it make sense to set is_shadow to 1 here? I mean you would pass 
klp_state down to allocate_loglevel_state() from setup callback and set 
its is_shadow member here. Because then...
  
>  static void free_loglevel_state(void)
>  {
> -	struct klp_state *loglevel_state;
> +	int *shadow_console_loglevel;
>  
> -	loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE);
> -	if (!loglevel_state)
> +	shadow_console_loglevel =
> +		(int *)klp_shadow_get(&console_loglevel, CONSOLE_LOGLEVEL_FIX_ID);
> +	if (!shadow_console_loglevel)
>  		return;
>  
>  	pr_info("%s: freeing space for the stored console_loglevel\n",
>  		__func__);
> -	kfree(loglevel_state->data);
> +	klp_shadow_free(&console_loglevel, CONSOLE_LOGLEVEL_FIX_ID, NULL);
>  }

would not be needed. And release callback neither.

Or am I wrong?

We can even have both ways implemented to demonstrate different 
approaches...

Miroslav

  reply	other threads:[~2024-07-25 11:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 17:04 [POC 0/7] livepatch: Make livepatch states, callbacks, and shadow variables work together Petr Mladek
2023-11-10 17:04 ` [POC 1/7] livepatch: Add callbacks for introducing and removing states Petr Mladek
2023-11-11  0:54   ` kernel test robot
2023-11-11  3:19   ` kernel test robot
2023-11-10 17:04 ` [POC 2/7] livepatch: Allow to handle lifetime of shadow variables using the livepatch state Petr Mladek
2024-07-25 11:31   ` Miroslav Benes
2024-08-15 13:43     ` Petr Mladek
2023-11-10 17:04 ` [POC 3/7] livepatch: Use per-state callbacks in state API tests Petr Mladek
2024-07-25 11:48   ` Miroslav Benes [this message]
2024-08-16 16:02     ` Petr Mladek
2023-11-10 17:04 ` [POC 4/7] livepatch: Do not use callbacks when testing sysfs interface Petr Mladek
2023-11-10 17:04 ` [POC 5/7] livepatch: Convert klp module callbacks tests into livepatch module tests Petr Mladek
2023-11-11  1:15   ` kernel test robot
2024-07-25 12:22   ` Miroslav Benes
2023-11-10 17:04 ` [POC 6/7] livepatch: Remove the obsolete per-object callbacks Petr Mladek
2023-11-10 17:04 ` [POC 7/7] livepatching: Remove per-state version Petr Mladek
2024-07-25 14:16   ` Miroslav Benes
2024-08-15 14:00     ` Petr Mladek
2023-11-10 21:33 ` [POC 0/7] livepatch: Make livepatch states, callbacks, and shadow variables work together Josh Poimboeuf
2024-07-25 14:19   ` Miroslav Benes
2024-08-15 10:08     ` Petr Mladek
2024-07-25 14:22 ` Miroslav Benes
2024-07-25 14:40   ` Nicolai Stange
     [not found]   ` <66a263d5.170a0220.b2c84.1870SMTPIN_ADDED_BROKEN@mx.google.com>
2024-08-21 15:28     ` Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.21.2407251343160.21729@pobox.suse.cz \
    --to=mbenes@suse.cz \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=nstange@suse.de \
    --cc=pmladek@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®