Skip to contentSkip to conversation

kexec: clear kexec_image slot when unloading kexec image

PATCH In review Bhavesh Davda 4 participants 7 messages Apr 3, 2017 – Apr 4, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec: clear kexec_image slot when unloading kexec image

While theoretically this bug can be tickled simply by a sequence of 'kexec -p' to load a kexec crash image followed by two back-to-back 'kexec -p -u' to unload the kexec crash image, I found the following perl script to be useful to reliably reproduce Xen panics as well as verify that the fix works. YMMV.

-snip-
#!/usr/bin/perl -w

use strict;
use warnings;
use threads;

sub threaded_task {
    threads->create(sub { 
        my $thr_id = threads->self->tid;
        print "Starting load thread $thr_id\n";
        system("/sbin/kexec  -p --command-line=\"placeholder root=/dev/mapper/root ro rhbg console=tty0 console=hvc0 earlyprintk=xen nomodeset printk.time=1 irqpoll maxcpus=1 nr_cpus=1 reset_devices cgroup_disable=memory mce=off selinux=0 console=ttyS1,115200n8\" --initrd=/boot/initrd.x86_64kdump.img /boot/vmlinuz.x86_64");
        print "Ending load thread $thr_id\n";
        threads->detach(); #End thread.
    });
    threads->create(sub { 
        my $thr_id = threads->self->tid;
        print "Starting unload thread $thr_id\n";
        system("/sbin/kexec  -p -u");
        print "Ending unload thread $thr_id\n";
        threads->detach(); #End thread.
    });
}

for my $i (0..99)

{
    threaded_task();
}

-snip-

---
When kexec_do_unload calls kexec_swap_images to get the old kexec_image to free, it passes NULL for the new kexec_image pointer. The new slot wasn't being cleared in such a case, leading to a stale pointer being left behind in the kexec_image array and Xen panics in subsequent load/unload operations.

---
 xen/common/kexec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
xen/common/kexec.c +1 -3
index 940fc7ec94..072cc8e0db 100644
@@ -837,11 +837,9 @@ static int kexec_swap_images(int type, struct kexec_image *new,
     old_slot = base + pos;
     new_slot = base + !pos;
 
+    kexec_image[new_slot] = new;
     if ( new )
-    {
-        kexec_image[new_slot] = new;
         set_bit(new_slot, &kexec_flags);
-    }
     change_bit(bit, &kexec_flags);
 
     clear_bit(old_slot, &kexec_flags);
Signature · 7 lines
2.12.2.575.gb14f27f.dirty


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 55 lines · Bhavesh Davda

While theoretically this bug can be tickled simply by a sequence of 'kexec -p' to load a kexec crash image followed by two back-to-back 'kexec -p -u' to unload the kexec crash image, I found the following perl script to be useful to reliably reproduce Xen panics as well as verify that the fix works. YMMV.

-snip-
#!/usr/bin/perl -w

use strict;
use warnings;
use threads;

sub threaded_task {
    threads->create(sub {
        my $thr_id = threads->self->tid;
        print "Starting load thread $thr_id\n";
        system("/sbin/kexec  -p --command-line=\"placeholder root=/dev/mapper/root ro rhbg console=tty0 console=hvc0 earlyprintk=xen nomodeset printk.time=1 irqpoll maxcpus=1 nr_cpus=1 reset_devices cgroup_disable=memory mce=off selinux=0 console=ttyS1,115200n8\" --initrd=/boot/initrd.x86_64kdump.img /boot/vmlinuz.x86_64");
        print "Ending load thread $thr_id\n";
        threads->detach(); #End thread.
    });
    threads->create(sub {
        my $thr_id = threads->self->tid;
        print "Starting unload thread $thr_id\n";
        system("/sbin/kexec  -p -u");
        print "Ending unload thread $thr_id\n";
        threads->detach(); #End thread.
    });
}

for my $i (0..99)

{
    threaded_task();
}

-snip-

---
When kexec_do_unload calls kexec_swap_images to get the old kexec_image to free, it passes NULL for the new kexec_image pointer. The new slot wasn't being cleared in such a case, leading to a stale pointer being left behind in the kexec_image array and Xen panics in subsequent load/unload operations.

---
 xen/common/kexec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
xen/common/kexec.c +0 -0
index 940fc7ec94..072cc8e0db 100644
@@ -837,11 +837,9 @@ static int kexec_swap_images(int type, struct kexec_image *new,
     old_slot = base + pos;
     new_slot = base + !pos;

xen/common/kexec.c static int kexec_swap_images(int type, struct kexec_image *new, · line 845

Quoted 10 lines
xen/common/kexec.c +1 -3
 
+    kexec_image[new_slot] = new;
     if ( new )
-    {
-        kexec_image[new_slot] = new;
         set_bit(new_slot, &kexec_flags);
-    }
     change_bit(bit, &kexec_flags);
 
     clear_bit(old_slot, &kexec_flags);

Bhavesh, thanks for posting this.

Jan, Andrew, IMO, this is Xen stable material too.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Bhavesh Davda
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 03.04.17 at 19:44, <[email protected]> wrote:

While theoretically this bug can be tickled simply by a sequence of 'kexec -p' to load a kexec crash image followed by two back-to-back 'kexec -p -u' to unload the kexec crash image, I found the following perl script to be useful to reliably reproduce Xen panics as well as verify that the fix works. YMMV.

-snip-
#!/usr/bin/perl -w

use strict;
use warnings;
use threads;

sub threaded_task {
    threads->create(sub { 
        my $thr_id = threads->self->tid;
        print "Starting load thread $thr_id\n";
        system("/sbin/kexec  -p --command-line=\"placeholder 
root=/dev/mapper/root ro rhbg console=tty0 console=hvc0 earlyprintk=xen 
nomodeset printk.time=1 irqpoll maxcpus=1 nr_cpus=1 reset_devices 
cgroup_disable=memory mce=off selinux=0 console=ttyS1,115200n8\" 
--initrd=/boot/initrd.x86_64kdump.img /boot/vmlinuz.x86_64");
        print "Ending load thread $thr_id\n";
        threads->detach(); #End thread.
    });
    threads->create(sub { 
        my $thr_id = threads->self->tid;
        print "Starting unload thread $thr_id\n";
        system("/sbin/kexec  -p -u");
        print "Ending unload thread $thr_id\n";
        threads->detach(); #End thread.
    });
}
Quoted 7 lines

for my $i (0..99)

{
    threaded_task();
}

-snip-

---

Looks like you've mixed up commit message (everything up from this marker) and ...

Quoted 8 lines

When kexec_do_unload calls kexec_swap_images to get the old kexec_image to free, it passes NULL for the new kexec_image pointer. The new slot wasn't being cleared in such a case, leading to a stale pointer being left behind in the kexec_image array and Xen panics in subsequent load/unload operations.

... auxiliary information (after the first --- marker).

Other than that

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 3 lines

Looks like you've mixed up commit message (everything up from this marker) and …

Sorry about that! Since it’s been a while since I posted a git patch to a mailing list, I had to figure out what the canonical format for an e-mail with a patch was, such that I could have a more verbose description of the problem followed by the usual git commit message. In the Documentation directory of the mainline Linux kernel tree I thought this is what they were recommending:

<message-body-start>
You can put a longer, more verbose description of the problem and the patch here. This section is not picked up by the tools committers use to extract the patch out of the e-mail.

- - -
Original git commit message, more concise, which will be used as the commit message in git Signed-off-by:
Reviewed-by:
- - -
diffstat

diff
- -
git version
<message-body-end>

Is that not correct?

Also couldn’t find the right command line options for any of the git helpers like format-patch or send-email to let it do the canonical formatting with the verbose description, so I edited the “git format-patch” generated file to conform with the above format.

Thanks for fixing it up!

- Bhavesh

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 25 lines
Quoted 4 lines
Quoted 1 line · On 04.04.17 at 17:30, <[email protected]> wrote:

Looks like you've mixed up commit message (everything up from this
marker) and …

Sorry about that! Since it’s been a while since I posted a git patch to a mailing list, I had to figure out what the canonical format for an e-mail with a patch was, such that I could have a more verbose description of the problem followed by the usual git commit message. In the Documentation directory of the mainline Linux kernel tree I thought this is what they were recommending:

<message-body-start>
You can put a longer, more verbose description of the problem and the patch here. This section is not picked up by the tools committers use to extract the patch out of the e-mail.

- - -
Original git commit message, more concise, which will be used as the commit message in git
Signed-off-by:
Reviewed-by:
- - -
diffstat

Quoted 6 lines

diff
- -
git version
<message-body-end>

Is that not correct?

That's not how we do things normally. You could have looked at a couple of patches sent by others...

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 4 lines

That's not how we do things normally. You could have looked at a couple of patches sent by others...

Jan

Well, naturally I tried doing that first, but due to the follies of statistical sampling, unfortunately the several patches I looked at on xen-devel didn’t have the more verbose description that’s not part of the commit log, or had a separate cover letter e-mail as [PATCH 00] of a series with the more verbose descriptions.

Like I said though, mea culpa, and I’ll be more careful next time :)

Thanks

- Bhavesh
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#6 lore raw
In reply to Bhavesh Davda
Quoted 8 lines · Bhavesh Davda

When kexec_do_unload calls kexec_swap_images to get the old kexec_image to free, it passes NULL for the new kexec_image pointer. The new slot wasn't being cleared in such a case, leading to a stale pointer being left behind in the kexec_image array and Xen panics in subsequent load/unload operations.

message suitably cropped.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel