mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: "Matt Fleming" <matt@console-pimps.org>, "Joey Lee" <JLee@suse.com>
Cc: "Zach Bobroff" <zacharyb@ami.com>,
	"Matt Fleming" <matt.fleming@intel.com>,
	"Matthew Garrett" <mjg59@srcf.ucam.org>,
	<linux-efi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH] x86, efi: retry ExitBootServices() on failure
Date: Mon, 17 Jun 2013 10:46:28 +0100	[thread overview]
Message-ID: <51BEF71402000078000DEC12@nat28.tlf.novell.com> (raw)
In-Reply-To: <20130617092107.GA5440@console-pimps.org>

>>> On 17.06.13 at 11:21, Matt Fleming <matt@console-pimps.org> wrote:
> On Fri, 14 Jun, at 12:00:33AM, joeyli wrote:
>> > From: Zach Bobroff <zacharyb@ami.com>
>> > --- a/arch/x86/boot/compressed/eboot.c
>> > +++ b/arch/x86/boot/compressed/eboot.c
>> > @@ -1037,18 +1037,20 @@ static efi_status_t exit_boot(struct boot_params *boot_params,
>> >  	efi_memory_desc_t *mem_map;
>> >  	efi_status_t status;
>> >  	__u32 desc_version;
>> > +	bool called_exit = false;
>> >  	u8 nr_entries;
>> >  	int i;
>> >  
>> >  	size = sizeof(*mem_map) * 32;
>> >  
>> >  again:
>> > -	size += sizeof(*mem_map);
>> > +	size += sizeof(*mem_map) * 2;
>> >  	_size = size;
>> >  	status = low_alloc(size, 1, (unsigned long *)&mem_map);
>> 
>> Can we know why increased the size of double *mem_map is big enough?
>> Does there have any real guarantee to be sufficient?
>  
> It's not guaranteed to be sufficient, it's simply a best guess. If we
> haven't allocated enough memory to store the memory map we should loop
> around to the 'again' label anyway. It's just an optimisation, right
> Zach?

If that were the case, the code change wouldn't be necessary at
all, i.e. the increment could remain to be a single array element
steps.

>> And, why would doubling the increment be necessary here, but not in
>> __get_map()?
>  
> Again, we'll grow the map if it isn't large enough.

But in single element steps only. The question though was why
doubling the step was necessary (and sufficient) there, but isn't
also necessary here.

To me, all this looks like it is being done on phenomenological basis,
taking a particular build of a particular firmware implementation as
the reference. Imo we shouldn't change the code in this way. This
also applies to the fact that the step is being doubled rather than
e.g. tripled: With it ending up a "again" anyway (see below), what's
the point of avoiding one more of the iterations?

Generic considerations would result in the increment being at least
3 * element size; twice the element size assumes that the allocator
would behave in certain ways (like returning the head or tail part of
a larger piece of memory).

>> >  	if (status != EFI_SUCCESS)
>> >  		return status;
>> >  
>> > +get_map:
>> 
>> The get_map label is being placed such that the size doesn't
>> get adjusted anymore, yet it is supposed to deal with an allocation
>> having happened during ExitBootServices(), which could have
>> grown the map.
>> 
>> Why doesn't direct goto 'again' label?
>  
> It makes more sense to query GetMemoryMap() directly first to get the
> required size of the memory map. Then we jump to 'again' and allocate
> the correct size.

Ah, okay, I didn't pay attention to this indirectly ending up at
"again".

>> >  	status = efi_call_phys5(sys_table->boottime->get_memory_map, &size,
>> >  				mem_map, &key, &desc_size, &desc_version);
>> >  	if (status == EFI_BUFFER_TOO_SMALL) {
>> > @@ -1074,8 +1076,20 @@ again:
>> >  	/* Might as well exit boot services now */
>> >  	status = efi_call_phys2(sys_table->boottime->exit_boot_services,
>> >  				handle, key);
>> > -	if (status != EFI_SUCCESS)
>> > -		goto free_mem_map;
>> > +	if (status != EFI_SUCCESS) {
>> > +		/*
>> > +		 * ExitBootServices() will fail if any of the event
>> > +		 * handlers change the memory map. In which case, we
>> > +		 * must be prepared to retry, but only once so that
>> > +		 * we're guaranteed to exit on repeated failures instead
>> > +		 * of spinning forever.
>> > +		 */
>> > +		if (called_exit)
>> > +			goto free_mem_map;
>> > +
>> > +		called_exit = true;
>> 
>> Why a single retry is having reasonable guarantees to work when the
>> original one failed (nothing prevents an event handler to do another
>> allocation the next time through).
>> 
>> Why not retry 3, 4, 5 or even unlimited times?
>  
> There has to be an upper limit on the number of retries. It seems fair
> to retry once but any more than that and it's more likely that there's a
> serious problem and we should bail.

I agree that there ought to be an upper limit. But a single retry here
again looks like a tailored solution to a particular observed (mis-)
behavior, rather than something resulting from general considerations.

Jan

  reply	other threads:[~2013-06-17  9:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-11  6:52 Matt Fleming
2013-06-11  7:22 ` Matt Fleming
2013-06-13 16:00 ` joeyli
2013-06-17  9:21   ` Matt Fleming
2013-06-17  9:46     ` Jan Beulich [this message]
2013-06-17 10:17       ` Matt Fleming
2013-06-17 10:41         ` joeyli
2013-06-17 11:02         ` Jan Beulich
2013-06-17 12:30           ` Matt Fleming
2013-06-18  0:18             ` Zachary Bobroff
2013-06-18  2:47               ` joeyli
2013-06-18  4:20                 ` Zachary Bobroff
2013-06-18  7:34                   ` joeyli
2013-06-18 13:03               ` Jan Beulich
2013-06-18 22:12                 ` Zachary Bobroff
2013-06-19  8:43                   ` matt
2013-06-19  8:53                     ` H. Peter Anvin
2013-06-20 18:04                       ` Zachary Bobroff
2013-06-26 13:12                         ` matt
  -- strict thread matches above, loose matches on Subject: below --
2013-05-22 14:15 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=51BEF71402000078000DEC12@nat28.tlf.novell.com \
    --to=jbeulich@suse.com \
    --cc=JLee@suse.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.fleming@intel.com \
    --cc=matt@console-pimps.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=stable@vger.kernel.org \
    --cc=zacharyb@ami.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®