kvm-ppc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kautuk Consul <kconsul@linux.ibm.com>
To: Segher Boessenkool <segher@kernel.crashing.org>,
	aik@ozlabs.ru, Thomas Huth <thuth@redhat.com>
Cc: slof@lists.ozlabs.org, kvm-ppc@vger.kernel.org,
	Kautuk Consul <kconsul@linux.ibm.com>
Subject: [PATCH v4] slof/fs/packages/disk-label.fs: improve checking for DOS boot partitions
Date: Thu, 28 Mar 2024 02:00:09 -0400	[thread overview]
Message-ID: <20240328060009.650859-1-kconsul@linux.ibm.com> (raw)

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>

Signed-off-by: Kautuk Consul <kconsul@linux.ibm.com>
---
 slof/fs/packages/disk-label.fs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index 661c6b0..a6fb231 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -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
 ;
 
-- 
2.31.1


             reply	other threads:[~2024-03-28  6:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28  6:00 Kautuk Consul [this message]
2024-04-04  0:35 ` [PATCH v4] slof/fs/packages/disk-label.fs: improve checking for DOS boot partitions Alexey Kardashevskiy
2024-04-04  7:18   ` Kautuk Consul
2024-04-05  3:46     ` Alexey Kardashevskiy
2024-04-05  8:16       ` Kautuk Consul
2024-04-16  4:33         ` [SLOF] " Kautuk Consul
2024-04-25  7:14           ` Kautuk Consul
2024-05-03 10:08           ` Kautuk Consul
2024-05-14  9:08             ` Kautuk Consul
2024-05-20  9:03               ` Alexey Kardashevskiy
2024-05-22  8:55                 ` Kautuk Consul
2024-05-27 12:38                   ` Alexey Kardashevskiy

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=20240328060009.650859-1-kconsul@linux.ibm.com \
    --to=kconsul@linux.ibm.com \
    --cc=aik@ozlabs.ru \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=segher@kernel.crashing.org \
    --cc=slof@lists.ozlabs.org \
    --cc=thuth@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).