On Tue, 18 Jul 2017 15:48:48 -0600
"Theo de Raadt" <[email protected]> wrote:
>> On Tue, Jul 18, 2017 at 08:40:53PM +0200, Theo Buehler wrote:
>> > On Tue, Jul 18, 2017 at 11:10:00AM -0600, Theo de Raadt wrote:
>> > > Possibly.
>> > >
>> > > cc'ing yasuoka who helped me with this method of disk probing.
>> > >
>> > > But anyways, beyond a code review we need someone to SHOW THEIR BOOT
>> > > LOADER
>> > > OUTPUT, so that we can see the hibernate marker letter is missing.
>> >
>> > Using FDE from MBR on my T420, I can confirm Natasha's findings.
>> >
>> > Automatic kernel selection to unhibernate fails, but manually selecting
>> > /bsd.booted works fine.
>> >
>> > I see the exact same thing on reboot and on boot into unhibernate:
>> > (manually transcribed, no & sign)
>> >
>> > Using drive 0, partition 3.
>> > Loading......
>> > probing: pc0 mem[630K 511M 510M 2471M 486M a20=on]
>> > disk: hd0+ sr0*
>> > >> OpenBSD/amd64 BOOT 3.33
>> > Passphrase: _
>>
>> To compare, here my output on suspended boot for a laptop (i386)
>> *without* FDE:
>>
>> Using drive 0, partition 3.
>> Loading......
>> probing: pc0 pci mem[636K 2037M a20=on]
>> disk: hd0+&
>> >> OpenBSD/i386 BOOT 3.31
>> unhibernate detected: switching to /bsd.booted
>> boot>
>> booting hd0a:/bsd.booted: 8122376+....
>> entry point at 0x2000d4
>> ...
>>
>> So here the & is present, and an explicit line is echoed.
>
> I'll explain what is going on here, and what needs to probably be done.
>
> The changes introduced into the bootloader are largely correct. They
> make the right decisions. They just don't make them at the right
> points in time. The IO operations should be moved further forward, to
> after the key operations.
>
> Havinge done it this way, yasuoka and I were able to create a workable
> model, but the operations need to be moved forward.
>
> Someone want to dive in?
The diff is to support selecting bsd.booted for FED.
disk: hd0 sr0*
>> OpenBSD/amd64 BOOTX64 3.33
Passphrase: <--- Enter the passphrase
unhibernate detected: switching to /bsd.booted
boot>
booting sr0a:/bsd.booted: xxxx...
we can't add "&" sign on the "disk" line. Since the bootloader gets
the passpharase after that line.
The boot codes other than BOOTX64.EFI are not tested yet.
Index: sys/arch/amd64/stand/efiboot/efidev.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efidev.c,v
retrieving revision 1.26
diff -u -p -r1.26 efidev.c
--- sys/arch/amd64/stand/efiboot/efidev.c 16 May 2017 02:56:23 -0000
1.26
+++ sys/arch/amd64/stand/efiboot/efidev.c 20 Jul 2017 12:24:24 -0000
@@ -625,6 +625,7 @@ efiopen(struct open_file *f, ...)
if (sr_getdisklabel(bv, &dip->disklabel))
return ERDLAB;
dip->bios_info.flags &= ~BDI_BADLABEL;
+ check_hibernate(dip);
}
bv->sbv_part = part + 'a';
Index: sys/arch/amd64/stand/libsa/biosdev.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/stand/libsa/biosdev.c,v
retrieving revision 1.30
diff -u -p -r1.30 biosdev.c
--- sys/arch/amd64/stand/libsa/biosdev.c 18 Sep 2016 15:13:10 -0000
1.30
+++ sys/arch/amd64/stand/libsa/biosdev.c 20 Jul 2017 12:24:24 -0000
@@ -548,6 +548,7 @@ biosopen(struct open_file *f, ...)
if (sr_getdisklabel(bv, &dip->disklabel))
return ERDLAB;
dip->bios_info.flags &= ~BDI_BADLABEL;
+ check_hibernate(dip);
}
bv->sbv_part = part + 'a';
Index: sys/arch/amd64/stand/libsa/disk.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/stand/libsa/disk.h,v
retrieving revision 1.5
diff -u -p -r1.5 disk.h
--- sys/arch/amd64/stand/libsa/disk.h 2 Sep 2015 01:52:26 -0000 1.5
+++ sys/arch/amd64/stand/libsa/disk.h 20 Jul 2017 12:24:24 -0000
@@ -59,4 +59,6 @@ extern struct disklist_lh disklist;
void dump_diskinfo(void);
+void check_hibernate(struct diskinfo *);
+
#endif /* _DISK_H */
Index: sys/arch/amd64/stand/libsa/diskprobe.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/stand/libsa/diskprobe.c,v
retrieving revision 1.19
diff -u -p -r1.19 diskprobe.c
--- sys/arch/amd64/stand/libsa/diskprobe.c 22 Jun 2017 01:26:28 -0000
1.19
+++ sys/arch/amd64/stand/libsa/diskprobe.c 20 Jul 2017 12:24:24 -0000
@@ -55,7 +55,6 @@
/* Local Prototypes */
static int disksum(int);
-static void check_hibernate(struct diskinfo *);
int bootdev_has_hibernate(void); /* export for loadfile() */
@@ -176,6 +175,8 @@ hardprobe(void)
dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
check_hibernate(dip);
+ if (dip->bios_info.flags & BDI_HIBVALID)
+ printf("&");
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
@@ -232,6 +233,8 @@ efi_hardprobe(void)
dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
check_hibernate(dip);
+ if (dip->bios_info.flags & BDI_HIBVALID)
+ printf("&");
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
@@ -472,7 +475,7 @@ bootdev_has_hibernate(void)
return ((bootdev_dip->bios_info.flags & BDI_HIBVALID)? 1 : 0);
}
-static void
+void
check_hibernate(struct diskinfo *dip)
{
daddr_t sec;
@@ -489,9 +492,6 @@ check_hibernate(struct diskinfo *dip)
(sizeof(union hibernate_info) / DEV_BSIZE);
error = dip->strategy(dip, F_READ, (daddr32_t)sec, sizeof hib, &hib,
NULL);
- if (error == 0 && hib.magic == HIBERNATE_MAGIC) {
- /* Hibernate present */
- dip->bios_info.flags |= BDI_HIBVALID;
- printf("&");
- }
+ if (error == 0 && hib.magic == HIBERNATE_MAGIC)
+ dip->bios_info.flags |= BDI_HIBVALID; /* Hibernate present */
}
Index: sys/arch/i386/stand/libsa/biosdev.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/stand/libsa/biosdev.c,v
retrieving revision 1.95
diff -u -p -r1.95 biosdev.c
--- sys/arch/i386/stand/libsa/biosdev.c 18 Sep 2016 15:13:10 -0000 1.95
+++ sys/arch/i386/stand/libsa/biosdev.c 20 Jul 2017 12:24:25 -0000
@@ -549,6 +549,7 @@ biosopen(struct open_file *f, ...)
if (sr_getdisklabel(bv, &dip->disklabel))
return ERDLAB;
dip->bios_info.flags &= ~BDI_BADLABEL;
+ check_hibernate(dip);
}
bv->sbv_part = part + 'a';
Index: sys/arch/i386/stand/libsa/disk.h
===================================================================
RCS file: /cvs/src/sys/arch/i386/stand/libsa/disk.h,v
retrieving revision 1.6
diff -u -p -r1.6 disk.h
--- sys/arch/i386/stand/libsa/disk.h 2 Sep 2015 04:09:24 -0000 1.6
+++ sys/arch/i386/stand/libsa/disk.h 20 Jul 2017 12:24:25 -0000
@@ -59,4 +59,6 @@ extern struct disklist_lh disklist;
void dump_diskinfo(void);
+void check_hibernate(struct diskinfo *);
+
#endif /* _DISK_H */
Index: sys/arch/i386/stand/libsa/diskprobe.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/stand/libsa/diskprobe.c,v
retrieving revision 1.43
diff -u -p -r1.43 diskprobe.c
--- sys/arch/i386/stand/libsa/diskprobe.c 22 Jun 2017 01:26:28 -0000
1.43
+++ sys/arch/i386/stand/libsa/diskprobe.c 20 Jul 2017 12:24:25 -0000
@@ -55,7 +55,6 @@
/* Local Prototypes */
static int disksum(int);
-static void check_hibernate(struct diskinfo *);
int bootdev_has_hibernate(void); /* export for loadfile() */
@@ -176,6 +175,8 @@ hardprobe(void)
dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
check_hibernate(dip);
+ if (dip->bios_info.flags & BDI_HIBVALID)
+ printf("&");
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
@@ -232,6 +233,8 @@ efi_hardprobe(void)
dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
check_hibernate(dip);
+ if (dip->bios_info.flags & BDI_HIBVALID)
+ printf("&");
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
@@ -472,7 +475,7 @@ bootdev_has_hibernate(void)
return ((bootdev_dip->bios_info.flags & BDI_HIBVALID)? 1 : 0);
}
-static void
+void
check_hibernate(struct diskinfo *dip)
{
daddr_t sec;
@@ -489,9 +492,6 @@ check_hibernate(struct diskinfo *dip)
(sizeof(union hibernate_info) / DEV_BSIZE);
error = dip->strategy(dip, F_READ, (daddr32_t)sec, sizeof hib, &hib,
NULL);
- if (error == 0 && hib.magic == HIBERNATE_MAGIC) {
- /* Hibernate present */
- dip->bios_info.flags |= BDI_HIBVALID;
- printf("&");
- }
+ if (error == 0 && hib.magic == HIBERNATE_MAGIC)
+ dip->bios_info.flags |= BDI_HIBVALID; /* Hibernate present */
}