public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
To: Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
Cc: Ingo Molnar <mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"H. Peter Anvin" <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Ard Biesheuvel
	<ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Leif Lindholm
	<leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Matthew Garrett <mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>,
	Matt Fleming
	<matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 1/2] efi: Provide a non-blocking SetVariable() operation
Date: Wed, 1 Oct 2014 17:26:24 +0200	[thread overview]
Message-ID: <20141001152624.GB2843@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <1412165200-32141-2-git-send-email-matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>

On Wed, Oct 01, 2014 at 01:06:39PM +0100, Matt Fleming wrote:
> From: Matt Fleming <matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> 
> There are some circumstances that call for trying to write an EFI
> variable in a non-blocking way. One such scenario is when writing pstore
> data in efi_pstore_write() via the pstore_dump() kdump callback.
> 
> Now that we have an EFI runtime spinlock we need a way of aborting if
> there is contention instead of spinning, since when writing pstore data
> from the kdump callback, the runtime lock may already be held by the CPU
> that's running the callback if we crashed in the middle of an EFI
> variable operation.
> 
> The situation is sufficiently special that a new EFI variable operation
> is warranted.
> 
> Introduce ->set_variable_nonblocking() for this use case. It is an
> optional EFI backend operation, and need only be implemented by those
> backends that usually acquire locks to serialize access to EFI
> variables, as is the case for virt_efi_set_variable() where we now grab
> the EFI runtime spinlock.
> 
> Cc: Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
> Cc: Ingo Molnar <mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Cc: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Matthew Garrett <mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
> Signed-off-by: Matt Fleming <matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/firmware/efi/runtime-wrappers.c | 19 +++++++++++++
>  drivers/firmware/efi/vars.c             | 47 +++++++++++++++++++++++++++++++++
>  include/linux/efi.h                     |  6 +++++
>  3 files changed, 72 insertions(+)
> 
> diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c
> index 9694cba665c4..4349206198b2 100644
> --- a/drivers/firmware/efi/runtime-wrappers.c
> +++ b/drivers/firmware/efi/runtime-wrappers.c
> @@ -200,6 +200,24 @@ static efi_status_t virt_efi_set_variable(efi_char16_t *name,
>  	return status;
>  }
>  
> +static efi_status_t
> +virt_efi_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
> +				  u32 attr, unsigned long data_size,
> +				  void *data)
> +{
> +	unsigned long flags;
> +	efi_status_t status;
> +
> +	if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
> +		return EFI_NOT_READY;
> +
> +	status = efi_call_virt(set_variable, name, vendor, attr, data_size,
> +			       data);
> +	spin_unlock_irqrestore(&efi_runtime_lock, flags);
> +	return status;
> +}

If you want to have this usable from NMI context, you need to convert
efi_runtime_lock to a raw_spinlock_t.

Also, it would probably be a good idea to have some selftest like thing
that actually calls this from NMI context, right?

  parent reply	other threads:[~2014-10-01 15:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-01 12:06 [PATCH 0/2] efi: Remove conditional in_nmi() runtime locking Matt Fleming
2014-10-01 12:06 ` [PATCH 1/2] efi: Provide a non-blocking SetVariable() operation Matt Fleming
     [not found]   ` <1412165200-32141-2-git-send-email-matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2014-10-01 15:26     ` Peter Zijlstra [this message]
     [not found]       ` <20141001152624.GB2843-IIpfhp3q70z/8w/KjCw3T+5/BudmfyzbbVWyRVo5IupeoWH0uzbU5w@public.gmane.org>
2014-10-01 16:11         ` Matt Fleming
2014-10-01 12:06 ` [PATCH 2/2] efi: Delete the in_nmi() conditional runtime locking Matt Fleming

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=20141001152624.GB2843@worktop.programming.kicks-ass.net \
    --to=peterz-wegcikhe2lqwvfeawa7xhq@public.gmane.org \
    --cc=ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
    --cc=leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org \
    --cc=matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox