All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net,
	graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
	masahiroy@kernel.org, ojeda@kernel.org, pratyush@kernel.org,
	rdunlap@infradead.org, tj@kernel.org
Subject: Re: [PATCHv7 1/7] kho: allow to drive kho from within kernel
Date: Thu, 23 Oct 2025 10:13:49 +0300	[thread overview]
Message-ID: <aPnVrZC4Fz273lLn@kernel.org> (raw)
In-Reply-To: <20251022005719.3670224-2-pasha.tatashin@soleen.com>

On Tue, Oct 21, 2025 at 08:57:13PM -0400, Pasha Tatashin wrote:
> Allow kernel to drive finalize and abort without requiring triggers
> from the userspace.
> 
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> Reviewed-by: Pratyush Yadav <pratyush@kernel.org>

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  include/linux/kexec_handover.h | 15 +++++++
>  kernel/kexec_handover.c        | 75 +++++++++++++++++++++-------------
>  2 files changed, 61 insertions(+), 29 deletions(-)
> 
> diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h
> index 25042c1d8d54..04d0108db98e 100644
> --- a/include/linux/kexec_handover.h
> +++ b/include/linux/kexec_handover.h
> @@ -67,6 +67,10 @@ void kho_memory_init(void);
>  
>  void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys,
>  		  u64 scratch_len);
> +
> +int kho_finalize(void);
> +int kho_abort(void);
> +
>  #else
>  static inline bool kho_is_enabled(void)
>  {
> @@ -139,6 +143,17 @@ static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
>  				phys_addr_t scratch_phys, u64 scratch_len)
>  {
>  }
> +
> +static inline int kho_finalize(void)
> +{
> +	return -EOPNOTSUPP;
> +}
> +
> +static inline int kho_abort(void)
> +{
> +	return -EOPNOTSUPP;
> +}
> +
>  #endif /* CONFIG_KEXEC_HANDOVER */
>  
>  #endif /* LINUX_KEXEC_HANDOVER_H */
> diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
> index de4466b47455..6458f369a346 100644
> --- a/kernel/kexec_handover.c
> +++ b/kernel/kexec_handover.c
> @@ -1087,7 +1087,7 @@ static int kho_out_update_debugfs_fdt(void)
>  	return err;
>  }
>  
> -static int kho_abort(void)
> +static int __kho_abort(void)
>  {
>  	int err;
>  	unsigned long order;
> @@ -1120,7 +1120,27 @@ static int kho_abort(void)
>  	return err;
>  }
>  
> -static int kho_finalize(void)
> +int kho_abort(void)
> +{
> +	int ret = 0;
> +
> +	if (!kho_enable)
> +		return -EOPNOTSUPP;
> +
> +	guard(mutex)(&kho_out.lock);
> +	if (!kho_out.finalized)
> +		return -ENOENT;
> +
> +	ret = __kho_abort();
> +	if (ret)
> +		return ret;
> +
> +	kho_out.finalized = false;
> +
> +	return kho_out_update_debugfs_fdt();
> +}
> +
> +static int __kho_finalize(void)
>  {
>  	int err = 0;
>  	u64 *preserved_mem_map;
> @@ -1163,12 +1183,32 @@ static int kho_finalize(void)
>  abort:
>  	if (err) {
>  		pr_err("Failed to convert KHO state tree: %d\n", err);
> -		kho_abort();
> +		__kho_abort();
>  	}
>  
>  	return err;
>  }
>  
> +int kho_finalize(void)
> +{
> +	int ret;
> +
> +	if (!kho_enable)
> +		return -EOPNOTSUPP;
> +
> +	guard(mutex)(&kho_out.lock);
> +	if (kho_out.finalized)
> +		return -EEXIST;
> +
> +	ret = __kho_finalize();
> +	if (ret)
> +		return ret;
> +
> +	kho_out.finalized = true;
> +
> +	return kho_out_update_debugfs_fdt();
> +}
> +
>  static int kho_out_finalize_get(void *data, u64 *val)
>  {
>  	mutex_lock(&kho_out.lock);
> @@ -1178,35 +1218,12 @@ static int kho_out_finalize_get(void *data, u64 *val)
>  	return 0;
>  }
>  
> -static int kho_out_finalize_set(void *data, u64 _val)
> +static int kho_out_finalize_set(void *data, u64 val)
>  {
> -	int ret = 0;
> -	bool val = !!_val;
> -
> -	mutex_lock(&kho_out.lock);
> -
> -	if (val == kho_out.finalized) {
> -		if (kho_out.finalized)
> -			ret = -EEXIST;
> -		else
> -			ret = -ENOENT;
> -		goto unlock;
> -	}
> -
>  	if (val)
> -		ret = kho_finalize();
> +		return kho_finalize();
>  	else
> -		ret = kho_abort();
> -
> -	if (ret)
> -		goto unlock;
> -
> -	kho_out.finalized = val;
> -	ret = kho_out_update_debugfs_fdt();
> -
> -unlock:
> -	mutex_unlock(&kho_out.lock);
> -	return ret;
> +		return kho_abort();
>  }
>  
>  DEFINE_DEBUGFS_ATTRIBUTE(fops_kho_out_finalize, kho_out_finalize_get,
> -- 
> 2.51.0.915.g61a8936c21-goog
> 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2025-10-23  7:13 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-22  0:57 [PATCHv7 0/7] liveupdate: Rework KHO for in-kernel users Pasha Tatashin
2025-10-22  0:57 ` [PATCHv7 1/7] kho: allow to drive kho from within kernel Pasha Tatashin
2025-10-23  7:13   ` Mike Rapoport [this message]
2025-10-22  0:57 ` [PATCHv7 2/7] kho: make debugfs interface optional Pasha Tatashin
2025-10-22 10:31   ` Pratyush Yadav
2025-10-22  0:57 ` [PATCHv7 3/7] kho: drop notifiers Pasha Tatashin
2025-10-22 11:01   ` Pratyush Yadav
2025-10-24  6:16     ` Mike Rapoport
2025-10-24  9:39       ` Pratyush Yadav
2025-10-24 13:11     ` Pasha Tatashin
2025-10-24 15:50       ` Pratyush Yadav
2025-10-24 15:52         ` Pratyush Yadav
2025-10-24 16:15           ` Pasha Tatashin
2025-10-24 16:32             ` Pratyush Yadav
2025-10-22  0:57 ` [PATCHv7 4/7] kho: add interfaces to unpreserve folios and page ranges Pasha Tatashin
2025-10-22 11:10   ` Pratyush Yadav
2025-10-24 13:18     ` Pasha Tatashin
2025-10-23  7:17   ` Mike Rapoport
2025-10-22  0:57 ` [PATCHv7 5/7] kho: don't unpreserve memory during abort Pasha Tatashin
2025-10-22 11:15   ` Pratyush Yadav
2025-10-23  7:20     ` Mike Rapoport
2025-10-24 13:28       ` Pasha Tatashin
2025-10-24 15:27         ` Pratyush Yadav
2025-10-24 15:33           ` Pasha Tatashin
2025-10-24 15:48             ` Pratyush Yadav
2025-10-22  0:57 ` [PATCHv7 6/7] liveupdate: kho: move to kernel/liveupdate Pasha Tatashin
2025-10-22  0:57 ` [PATCHv7 7/7] liveupdate: kho: move kho debugfs directory to liveupdate Pasha Tatashin
2025-10-23  7:32   ` Mike Rapoport
2025-10-24 13:33     ` Pasha Tatashin

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=aPnVrZC4Fz273lLn@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=graf@amazon.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=masahiroy@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.