Skip to contentSkip to conversation

slof/fs/packages/disk-label.fs: improve checking for DOS boot partitions

PATCH In review Kautuk Consul 2 participants 12 messages Mar 28, 2024 – May 27, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 slof/fs/packages/disk-label.fs: improve checking for DOS boot partitions

While testing with a qcow2 with a DOS boot partition it was found that when we set the logical_block_size in the guest XML to >512 then the boot would fail in the following interminable loop:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
</SNIP>

Change the "read-sector" Forth subroutine to throw an exception whenever it fails to read a full block-size length of sector from the disk. Also change the "open" method to initiate CATCH exception handling for the calls to try-partitions/try-files which will also call read-sector which could potentially now throw this new exception.

After making the above changes, it fails properly with the correct error message as follows:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!

E3404: Not a bootable device!

E3407: Load failed

Type 'boot' and press return to continue booting the system. Type 'reset-all' and press return to reboot the system.

Ready!
0 >
</SNIP>

---
 slof/fs/packages/disk-label.fs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
slof/fs/packages/disk-label.fs +9 -3
index 661c6b0..a6fb231 100644
@@ -136,7 +136,8 @@ CONSTANT /gpt-part-entry
 : read-sector ( sector-number -- )
    \ block-size is 0x200 on disks, 0x800 on cdrom drives
    block-size * 0 seek drop      \ seek to sector
-   block block-size read drop    \ read sector
+   block block-size read         \ read sector
+   block-size < IF throw THEN    \ if we read less than the block-size then throw an exception
 ;
 
 : (.part-entry) ( part-entry )
@@ -723,10 +724,15 @@ CREATE GPT-LINUX-PARTITION 10 allot
    THEN
 
    partition IF
-       try-partitions
+       ['] try-partitions
    ELSE
-       try-files
+       ['] try-files
    THEN
+
+   \ Catch any exception that might happen due to read-sector failing to read
+   \ block-size number of bytes from any sector of the disk.
+   CATCH IF false THEN
+
    dup 0= IF debug-disk-label? IF ." not found." cr THEN close THEN \ free memory again
 ;
 
Signature · 1 line
2.31.1
#1 lore raw

First, sorry I am late into the discussion. Comments below.

Quoted 3 lines · Kautuk Consul

While testing with a qcow2 with a DOS boot partition it was found that when we set the logical_block_size in the guest XML to >512 then the boot would fail in the following interminable loop:

Why would anyone tweak this? And when you do, what happens inside the SLOF, does it keep using 512?

Quoted 21 lines

<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device! </SNIP>

Quoted 2 lines

Change the "read-sector" Forth subroutine to throw an exception whenever it fails to read a full block-size length of sector from the disk.

Why not throwing an exception from the "beyond end" message point?
Or fail to open a device if SLOF does not like the block size? I forgot the internals :(

Quoted 35 lines

Also change the "open" method to initiate CATCH exception handling for the calls to try-partitions/try-files which will also call read-sector which could potentially now throw this new exception.

After making the above changes, it fails properly with the correct error message as follows:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!

E3404: Not a bootable device!

E3407: Load failed

Type 'boot' and press return to continue booting the system. Type 'reset-all' and press return to reboot the system.

Ready!
0 >
</SNIP>

---
slof/fs/packages/disk-label.fs | 12 +++++++++---

1 file changed, 9 insertions(+), 3 deletions(-)
slof/fs/packages/disk-label.fs +0 -0
index 661c6b0..a6fb231 100644

slof/fs/packages/disk-label.fs CONSTANT /gpt-part-entry · line 140

Quoted 6 lines
slof/fs/packages/disk-label.fs +2 -1
@@ -136,7 +136,8 @@ CONSTANT /gpt-part-entry
 : read-sector ( sector-number -- )
    \ block-size is 0x200 on disks, 0x800 on cdrom drives
    block-size * 0 seek drop      \ seek to sector
-   block block-size read drop    \ read sector
+   block block-size read         \ read sector
+   block-size < IF throw THEN    \ if we read less than the block-size then throw an exception

When it fails, is the number of bytes ever non zero? Thanks,

Quoted 25 lines
slof/fs/packages/disk-label.fs +7 -2
 ;
 
 : (.part-entry) ( part-entry )
@@ -723,10 +724,15 @@ CREATE GPT-LINUX-PARTITION 10 allot
    THEN
 
    partition IF
-       try-partitions
+       ['] try-partitions
    ELSE
-       try-files
+       ['] try-files
    THEN
+
+   \ Catch any exception that might happen due to read-sector failing to read
+   \ block-size number of bytes from any sector of the disk.
+   CATCH IF false THEN
+
    dup 0= IF debug-disk-label? IF ." not found." cr THEN close THEN \ free memory again
 ;
 
Signature · 1 line
2.31.1
#2 lore raw
Quoted 9 lines · Alexey Kardashevskiy

First, sorry I am late into the discussion. Comments below.

Quoted 3 lines · Kautuk Consul

While testing with a qcow2 with a DOS boot partition it was found that when we set the logical_block_size in the guest XML to >512 then the boot would fail in the following interminable loop:

Why would anyone tweak this? And when you do, what happens inside the SLOF, does it keep using 512?

Well, we had an image with DOS boot partition and we tested it with logical_block_size = 1024 and got this infinite loop.
In SLOF the block-size becomes what we configure in the logical_block_size parameter. This same issue doesn't arise with GPT.

Quoted 22 lines
Quoted 22 lines

<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device! </SNIP>

Quoted 5 lines
Quoted 2 lines

Change the "read-sector" Forth subroutine to throw an exception whenever it fails to read a full block-size length of sector from the disk.

Why not throwing an exception from the "beyond end" message point?
Or fail to open a device if SLOF does not like the block size? I forgot the internals :(

This loop is interminable and this "Access beyond end of device!" message continues forever.
SLOF doesn't have any option other than to use the block-size that was set in the logical_block_size parameter. It doesn't have any preference as the code is very generic for both DOS as well as GPT.

Quoted 31 lines
Quoted 31 lines

Also change the "open" method to initiate CATCH exception handling for the calls to try-partitions/try-files which will also call read-sector which could potentially now throw this new exception.

After making the above changes, it fails properly with the correct error message as follows:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!

E3404: Not a bootable device!

E3407: Load failed

Type 'boot' and press return to continue booting the system. Type 'reset-all' and press return to reboot the system.

Ready!
0 >
</SNIP>

---
slof/fs/packages/disk-label.fs | 12 +++++++++---

1 file changed, 9 insertions(+), 3 deletions(-)
Quoted 13 lines

slof/fs/packages/disk-label.fs CONSTANT /gpt-part-entry · line 140

Quoted 11 lines
slof/fs/packages/disk-label.fs +2 -1
index 661c6b0..a6fb231 100644
@@ -136,7 +136,8 @@ CONSTANT /gpt-part-entry
 : read-sector ( sector-number -- )
    \ block-size is 0x200 on disks, 0x800 on cdrom drives
    block-size * 0 seek drop      \ seek to sector
-   block block-size read drop    \ read sector
+   block block-size read         \ read sector
+   block-size < IF throw THEN    \ if we read less than the block-size then throw an exception

When it fails, is the number of bytes ever non zero? Thanks,

No, it doesn't reach 0. It is lesser than the block-size. For example if we set the logcial_block_size to 1024, the block-size is that much. if we are reading the last sector which is physically only 512 bytes long then we read that 512 bytes which is lesser than 1024, which should be regarded as an error.

Quoted 7 lines
Quoted 7 lines
slof/fs/packages/disk-label.fs +0 -0
 ;
 
 : (.part-entry) ( part-entry )
@@ -723,10 +724,15 @@ CREATE GPT-LINUX-PARTITION 10 allot
    THEN
 
Quoted 11 lines

slof/fs/packages/disk-label.fs CREATE GPT-LINUX-PARTITION 10 allot · line 734

Quoted 11 lines
slof/fs/packages/disk-label.fs +6 -2
    partition IF
-       try-partitions
+       ['] try-partitions
    ELSE
-       try-files
+       ['] try-files
    THEN
+
+   \ Catch any exception that might happen due to read-sector failing to read
+   \ block-size number of bytes from any sector of the disk.
+   CATCH IF false THEN

Segher/Alexey, can we keep this CATCH block or should I remove it ?

Quoted 8 lines
Quoted 8 lines
slof/fs/packages/disk-label.fs +1 -0
+
    dup 0= IF debug-disk-label? IF ." not found." cr THEN close THEN \ free memory again
 ;
 
Signature · 1 line
2.31.1
#3 lore raw
Quoted 4 lines · Kautuk Consul
Quoted 3 lines · Alexey Kardashevskiy

First, sorry I am late into the discussion. Comments below.

Quoted 8 lines
Quoted 6 lines · Kautuk Consul
Quoted 3 lines

While testing with a qcow2 with a DOS boot partition it was found that when we set the logical_block_size in the guest XML to >512 then the boot would fail in the following interminable loop:

Why would anyone tweak this? And when you do, what happens inside the SLOF, does it keep using 512?

Well, we had an image with DOS boot partition and we tested it with logical_block_size = 1024 and got this infinite loop.

This does not really answer to "why" ;)

Quoted 2 lines

In SLOF the block-size becomes what we configure in the logical_block_size parameter. This same issue doesn't arise with GPT.

How is GPT different in this regard?

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device! </SNIP>

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Change the "read-sector" Forth subroutine to throw an exception whenever it fails to read a full block-size length of sector from the disk.

Why not throwing an exception from the "beyond end" message point?
Or fail to open a device if SLOF does not like the block size? I forgot the internals :(

This loop is interminable and this "Access beyond end of device!" message continues forever.

Where is that loop exactly? Put CATCH in there.

Quoted 47 lines

SLOF doesn't have any option other than to use the block-size that was set in the logical_block_size parameter. It doesn't have any preference as the code is very generic for both DOS as well as GPT.

Quoted 31 lines
Quoted 31 lines

Also change the "open" method to initiate CATCH exception handling for the calls to try-partitions/try-files which will also call read-sector which could potentially now throw this new exception.

After making the above changes, it fails properly with the correct error message as follows:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!

E3404: Not a bootable device!

E3407: Load failed

Type 'boot' and press return to continue booting the system. Type 'reset-all' and press return to reboot the system.

Ready!
0 >
</SNIP>

---
slof/fs/packages/disk-label.fs | 12 +++++++++---

1 file changed, 9 insertions(+), 3 deletions(-)
Quoted 13 lines

slof/fs/packages/disk-label.fs CONSTANT /gpt-part-entry · line 140

Quoted 11 lines
slof/fs/packages/disk-label.fs +2 -1
index 661c6b0..a6fb231 100644
@@ -136,7 +136,8 @@ CONSTANT /gpt-part-entry
 : read-sector ( sector-number -- )
    \ block-size is 0x200 on disks, 0x800 on cdrom drives
    block-size * 0 seek drop      \ seek to sector
-   block block-size read drop    \ read sector
+   block block-size read         \ read sector
+   block-size < IF throw THEN    \ if we read less than the block-size then throw an exception

When it fails, is the number of bytes ever non zero? Thanks,

Quoted 5 lines

No, it doesn't reach 0. It is lesser than the block-size. For example if we set the logcial_block_size to 1024, the block-size is that much. if we are reading the last sector which is physically only 512 bytes long then we read that 512 bytes which is lesser than 1024, which should be regarded as an error.

Ah so it only happens when there is an odd number of 512 sectors so reading the last one with block-size==1024 only reads a half => failure, is that right?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
slof/fs/packages/disk-label.fs +0 -0
 ;
 
 : (.part-entry) ( part-entry )
@@ -723,10 +724,15 @@ CREATE GPT-LINUX-PARTITION 10 allot
    THEN
 
Quoted 12 lines
Quoted 11 lines

slof/fs/packages/disk-label.fs CREATE GPT-LINUX-PARTITION 10 allot · line 734

Quoted 11 lines
slof/fs/packages/disk-label.fs +6 -2
    partition IF
-       try-partitions
+       ['] try-partitions
    ELSE
-       try-files
+       ['] try-files
    THEN
+
+   \ Catch any exception that might happen due to read-sector failing to read
+   \ block-size number of bytes from any sector of the disk.
+   CATCH IF false THEN

Segher/Alexey, can we keep this CATCH block or should I remove it ?

imho the original bug should be handled more gracefully. Seeing exceptions in the code just triggers exceptions in my small brain :) Thanks,

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
slof/fs/packages/disk-label.fs +1 -0
+
    dup 0= IF debug-disk-label? IF ." not found." cr THEN close THEN \ free memory again
 ;
 
Signature · 1 line
2.31.1
#4 lore raw

Hi,

Quoted 12 lines · Alexey Kardashevskiy
Quoted 9 lines · Kautuk Consul
Quoted 8 lines · Alexey Kardashevskiy

First, sorry I am late into the discussion. Comments below.

Quoted 3 lines · Kautuk Consul

While testing with a qcow2 with a DOS boot partition it was found that when we set the logical_block_size in the guest XML to >512 then the boot would fail in the following interminable loop:

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Why would anyone tweak this? And when you do, what happens inside the SLOF, does it keep using 512?

Well, we had an image with DOS boot partition and we tested it with logical_block_size = 1024 and got this infinite loop.

This does not really answer to "why" ;)

Well, my point is that it is tweakable in virsh/qemu and maybe we should be handling this error in configuration in SLOF properly ? There shouldn't be the possibility of an interminable loop in the software anywhere, right ? :-)

Quoted 5 lines
Quoted 3 lines

In SLOF the block-size becomes what we configure in the logical_block_size parameter. This same issue doesn't arise with GPT.

How is GPT different in this regard?

In GPT the sector number 1 contains the GPT headers, not sector 0 as in the case of DOS boot partition. So if the block-size is incorrect, the GPT magic number itself isn't found and the "E3404: Not a bootable device!" error is immediately thrown.

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines

<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device! </SNIP>

Change the "read-sector" Forth subroutine to throw an exception whenever it fails to read a full block-size length of sector from the disk.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Why not throwing an exception from the "beyond end" message point?
Or fail to open a device if SLOF does not like the block size? I forgot the internals :(

This loop is interminable and this "Access beyond end of device!" message continues forever.

Where is that loop exactly? Put CATCH in there.

That loop is in count-dos-logical-partitions. The reason why I didn't put a CATCH in there is because there is already another CATCH statement in do-load in slof/fs/boot.fs which covers this throw. For the other path that doesn't have a CATCH I have inserted a CATCH in the open subroutine in disk-label.fs.

Quoted 48 lines
Quoted 48 lines

SLOF doesn't have any option other than to use the block-size that was set in the logical_block_size parameter. It doesn't have any preference as the code is very generic for both DOS as well as GPT.

Quoted 44 lines
Quoted 36 lines

Also change the "open" method to initiate CATCH exception handling for the calls to try-partitions/try-files which will also call read-sector which could potentially now throw this new exception.

After making the above changes, it fails properly with the correct error message as follows:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!

E3404: Not a bootable device!

E3407: Load failed

Type 'boot' and press return to continue booting the system. Type 'reset-all' and press return to reboot the system.

Ready!
0 >
</SNIP>

---
slof/fs/packages/disk-label.fs | 12 +++++++++---

1 file changed, 9 insertions(+), 3 deletions(-)
slof/fs/packages/disk-label.fs +0 -0
index 661c6b0..a6fb231 100644

slof/fs/packages/disk-label.fs CONSTANT /gpt-part-entry · line 140

Quoted 6 lines
slof/fs/packages/disk-label.fs +2 -1
@@ -136,7 +136,8 @@ CONSTANT /gpt-part-entry
 : read-sector ( sector-number -- )
    \ block-size is 0x200 on disks, 0x800 on cdrom drives
    block-size * 0 seek drop      \ seek to sector
-   block block-size read drop    \ read sector
+   block block-size read         \ read sector
+   block-size < IF throw THEN    \ if we read less than the block-size then throw an exception

When it fails, is the number of bytes ever non zero? Thanks,

Quoted 7 lines
Quoted 5 lines

No, it doesn't reach 0. It is lesser than the block-size. For example if we set the logcial_block_size to 1024, the block-size is that much. if we are reading the last sector which is physically only 512 bytes long then we read that 512 bytes which is lesser than 1024, which should be regarded as an error.

Ah so it only happens when there is an odd number of 512 sectors so reading the last one with block-size==1024 only reads a half => failure, is that right?

Yes. Or, block-size if set to 2048 or 4096 will also show the same problem.

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
slof/fs/packages/disk-label.fs +0 -0
 ;
 
 : (.part-entry) ( part-entry )
@@ -723,10 +724,15 @@ CREATE GPT-LINUX-PARTITION 10 allot
    THEN
 
Quoted 12 lines
Quoted 11 lines

slof/fs/packages/disk-label.fs CREATE GPT-LINUX-PARTITION 10 allot · line 734

Quoted 11 lines
slof/fs/packages/disk-label.fs +6 -2
    partition IF
-       try-partitions
+       ['] try-partitions
    ELSE
-       try-files
+       ['] try-files
    THEN
+
+   \ Catch any exception that might happen due to read-sector failing to read
+   \ block-size number of bytes from any sector of the disk.
+   CATCH IF false THEN

Segher/Alexey, can we keep this CATCH block or should I remove it ?

Quoted 1 line

imho the original bug should be handled more gracefully. Seeing exceptions in the code just triggers exceptions in my small brain :) Thanks,

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
slof/fs/packages/disk-label.fs +1 -0
+
    dup 0= IF debug-disk-label? IF ." not found." cr THEN close THEN \ free memory again
 ;
 
Signature · 1 line
2.31.1
#5 lore raw

Hi,

Quoted 156 lines · Kautuk Consul

Hi,

Quoted 12 lines · Alexey Kardashevskiy
Quoted 9 lines · Kautuk Consul
Quoted 8 lines · Alexey Kardashevskiy

First, sorry I am late into the discussion. Comments below.

Quoted 3 lines · Kautuk Consul

While testing with a qcow2 with a DOS boot partition it was found that when we set the logical_block_size in the guest XML to >512 then the boot would fail in the following interminable loop:

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Why would anyone tweak this? And when you do, what happens inside the SLOF, does it keep using 512?

Well, we had an image with DOS boot partition and we tested it with logical_block_size = 1024 and got this infinite loop.

This does not really answer to "why" ;)

Well, my point is that it is tweakable in virsh/qemu and maybe we should be handling this error in configuration in SLOF properly ? There shouldn't be the possibility of an interminable loop in the software anywhere, right ? :-)

Quoted 5 lines
Quoted 3 lines

In SLOF the block-size becomes what we configure in the logical_block_size parameter. This same issue doesn't arise with GPT.

How is GPT different in this regard?

In GPT the sector number 1 contains the GPT headers, not sector 0 as in the case of DOS boot partition. So if the block-size is incorrect, the GPT magic number itself isn't found and the "E3404: Not a bootable device!" error is immediately thrown.

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines

<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device! </SNIP>

Change the "read-sector" Forth subroutine to throw an exception whenever it fails to read a full block-size length of sector from the disk.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Why not throwing an exception from the "beyond end" message point?
Or fail to open a device if SLOF does not like the block size? I forgot the internals :(

This loop is interminable and this "Access beyond end of device!" message continues forever.

Where is that loop exactly? Put CATCH in there.

That loop is in count-dos-logical-partitions. The reason why I didn't put a CATCH in there is because there is already another CATCH statement in do-load in slof/fs/boot.fs which covers this throw. For the other path that doesn't have a CATCH I have inserted a CATCH in the open subroutine in disk-label.fs.

Quoted 48 lines
Quoted 48 lines

SLOF doesn't have any option other than to use the block-size that was set in the logical_block_size parameter. It doesn't have any preference as the code is very generic for both DOS as well as GPT.

Quoted 44 lines
Quoted 36 lines

Also change the "open" method to initiate CATCH exception handling for the calls to try-partitions/try-files which will also call read-sector which could potentially now throw this new exception.

After making the above changes, it fails properly with the correct error message as follows:
<SNIP>
Trying to load: from: /pci@800000020000000/scsi@3 ...
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!
virtioblk_transfer: Access beyond end of device!

E3404: Not a bootable device!

E3407: Load failed

Type 'boot' and press return to continue booting the system. Type 'reset-all' and press return to reboot the system.

Ready!
0 >
</SNIP>

---
slof/fs/packages/disk-label.fs | 12 +++++++++---

1 file changed, 9 insertions(+), 3 deletions(-)
slof/fs/packages/disk-label.fs +0 -0
index 661c6b0..a6fb231 100644

slof/fs/packages/disk-label.fs CONSTANT /gpt-part-entry · line 140

Quoted 6 lines
slof/fs/packages/disk-label.fs +2 -1
@@ -136,7 +136,8 @@ CONSTANT /gpt-part-entry
 : read-sector ( sector-number -- )
    \ block-size is 0x200 on disks, 0x800 on cdrom drives
    block-size * 0 seek drop      \ seek to sector
-   block block-size read drop    \ read sector
+   block block-size read         \ read sector
+   block-size < IF throw THEN    \ if we read less than the block-size then throw an exception

When it fails, is the number of bytes ever non zero? Thanks,

Quoted 7 lines
Quoted 5 lines

No, it doesn't reach 0. It is lesser than the block-size. For example if we set the logcial_block_size to 1024, the block-size is that much. if we are reading the last sector which is physically only 512 bytes long then we read that 512 bytes which is lesser than 1024, which should be regarded as an error.

Ah so it only happens when there is an odd number of 512 sectors so reading the last one with block-size==1024 only reads a half => failure, is that right?

Yes. Or, block-size if set to 2048 or 4096 will also show the same problem.

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
slof/fs/packages/disk-label.fs +0 -0
 ;
 
 : (.part-entry) ( part-entry )
@@ -723,10 +724,15 @@ CREATE GPT-LINUX-PARTITION 10 allot
    THEN
 
Quoted 12 lines
Quoted 11 lines

slof/fs/packages/disk-label.fs CREATE GPT-LINUX-PARTITION 10 allot · line 734

Quoted 11 lines
slof/fs/packages/disk-label.fs +6 -2
    partition IF
-       try-partitions
+       ['] try-partitions
    ELSE
-       try-files
+       ['] try-files
    THEN
+
+   \ Catch any exception that might happen due to read-sector failing to read
+   \ block-size number of bytes from any sector of the disk.
+   CATCH IF false THEN

Segher/Alexey, can we keep this CATCH block or should I remove it ?

Quoted 1 line

imho the original bug should be handled more gracefully. Seeing exceptions in the code just triggers exceptions in my small brain :) Thanks,

Quoted 8 lines

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

#6 lore raw

Hi,

Quoted 7 lines · Kautuk Consul
Quoted 1 line

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

Any ideas on how to proceed ?

Quoted 4 lines

_______________________________________________
SLOF mailing list
[email protected]
https://lists.ozlabs.org/listinfo/slof

#7 lore raw
In reply to Kautuk Consul

Hi Alexey/Segher,

Quoted 8 lines
Quoted 8 lines

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Quoted 6 lines

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

Any ideas on how we proceed with this now ?

Quoted 4 lines

_______________________________________________
SLOF mailing list
[email protected]
https://lists.ozlabs.org/listinfo/slof

#8 lore raw

Hi Alexey/Segher,

Quoted 8 lines
Quoted 8 lines

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Quoted 6 lines

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

Any ideas on how we proceed with this now ?

#9 lore raw
Quoted 9 lines · Kautuk Consul

Hi Alexey/Segher,

Quoted 8 lines
Quoted 8 lines

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Quoted 8 lines
Quoted 6 lines

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

Any ideas on how we proceed with this now ?

Ufff, I dropped the ball again :-/

Sorry but if read-sector cannot read a sector because of misconfiguration (not because some underlying hardware error) - this tells me that this should be handled when we open the block device which we knows the size of in sectors and if it is not an integer - barf there. Or it is not possible? In general, when you tweak libvirt xml like this - there are plenty of ways to break SLOF, this one is not worth of another exception throwing imho. Thanks,

#10 lore raw

Hi,

Quoted 19 lines · Alexey Kardashevskiy
Quoted 16 lines · Kautuk Consul

Hi Alexey/Segher,

Quoted 14 lines
Quoted 8 lines

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

Quoted 6 lines
Quoted 1 line

Any ideas on how we proceed with this now ?

Ufff, I dropped the ball again :-/

Sorry but if read-sector cannot read a sector because of misconfiguration (not because some underlying hardware error) - this tells me that this should be handled when we open the block device which we knows the size of in sectors and if it is not an integer - barf there. Or it is not possible? In general, when you tweak libvirt xml like this - there are plenty of ways to break SLOF, this one is not worth of another exception throwing imho. Thanks,

Sure, no issues. Just thought to send in this patch as we encountered this problem. Will abandon this email chain now. Thanks again! :-)

#11 lore raw
Quoted 25 lines · Kautuk Consul

Hi,

Quoted 22 lines · Alexey Kardashevskiy
Quoted 17 lines · Kautuk Consul

Hi Alexey/Segher,

Quoted 8 lines
Quoted 8 lines

:-). But this is the only other path that doesn't have a CATCH like the do-load subroutine in slof/fs/boot.fs. According to Segher there shouldn't ever be a problem with throw because if nothing else the outer-most interpreter loop's CATCH will catch the exception. But I thought to cover this throw in read-sector more locally in places near to this functionality. Because the outermost FORTH SLOF interpreter loop is not really so related to reading a sector in disk-label.fs.

Quoted 6 lines

Alexey/Segher, so what should be the next steps ?
Do you find my explanation above okay or should I simply remove these CATCH blocks ? Putting a CATCH block in count-dos-logical-partitions is out of the question as there is already a CATCH in do-load in slof/fs/boot.fs. This CATCH block in the open subroutine is actually to prevent the exception to be caught at some non-local place in the code.

Any ideas on how we proceed with this now ?

Quoted 6 lines
Quoted 3 lines

Ufff, I dropped the ball again :-/

Sorry but if read-sector cannot read a sector because of misconfiguration (not because some underlying hardware error) - this tells me that this should be handled when we open the block device which we knows the size of in sectors and if it is not an integer - barf there. Or it is not possible? In general, when you tweak libvirt xml like this - there are plenty of ways to break SLOF, this one is not worth of another exception throwing imho. Thanks,

Sure, no issues. Just thought to send in this patch as we encountered this problem. Will abandon this email chain now. Thanks again! :-)

btw I was wondering what if you passed 513 as sector size, for example, have you tried? ;)