New kernels

AmigaOne X5000 platform specific issues related to Linux only.
User avatar
Skateman
Posts: 955
Joined: Thu Aug 10, 2017 9:36 pm
Location: The Netherlands

Re: New kernels

Post by Skateman »

Final kernel 6.4 up and running on my AmigaOne X5000

Image

Big picture https://www.skateman.nl/wp-content/uplo ... -32-21.png

Thanks Christian for al the hard work making this possible!!
AmigaOne X5000 -> 2GHz / 16GB RAM / Radeon RX 570 / Radeon X1950 / M-Audio 5.1 -> AmigaOS / Linux
Amiga 1200 -> Recapped / 68ec020 ACA 1221ec / CF HDD / RetroNET connected to the world
Vampire 4SA - RPi4 Running AmiKitXE Full
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

Skateman wrote: Tue Jun 27, 2023 7:35 pm Final kernel 6.4 up and running on my AmigaOne X5000

Thanks Christian for al the hard work making this possible!!
Thank you for testing the final kernel 6.4.0. :-)
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

The alpha1 of kernel 6.5 can't read the Amiga partition table via the rigid disk block (RDB) correctly anymore so it isn't possible to mount a Linux partition from a disk with an Amiga partition table. The kernel 6.4 doesn't have this issue.

Kernel 6.4.0 final:

parted -l

Code: Select all

Model: ATA ST2000DM001-9YN1 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: amiga
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1057kB  123MB   122MB   affs7        BDH0  hidden
 2      123MB   2274MB  2150MB               DH0   boot
 3      2274MB  691GB   689GB                DH2
 4      691GB   1992GB  1301GB  ext4         dhx   boot
dmesg | grep -i sda

Code: Select all

[    0.000000] Kernel command line: root=/dev/sda4
[    3.987717] sd 0:0:0:0: [sda] 3907029168 512-byte logical blocks: (2.00 TB/1.82 TiB)
[    4.031349] sd 0:0:0:0: [sda] 4096-byte physical blocks
[    4.123773] sd 0:0:0:0: [sda] Write Protect is off
[    4.168682] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    4.279304] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    4.463508] sd 0:0:0:0: [sda] Preferred minimum I/O size 4096 bytes
[    4.519477]  sda: RDSK (512) sda1 (DOS^G)(res 2 spb 2) sda2 (SFS^B)(res 2 spb 1) sda3 (SFS^B)(res 2 spb 2) sda4 ((res 2 spb 1)
[    4.720896] sda: p4 size 18446744071956107760 extends beyond EOD, 
[    4.922550]  sda: RDSK (512) sda1 (DOS^G)(res 2 spb 2) sda2 (SFS^B)(res 2 spb 1) sda3 (SFS^B)(res 2 spb 2) sda4 ((res 2 spb 1)
[    4.948655] sda: p4 size 18446744071956107760 extends beyond EOD, truncated
[    4.998956] sd 0:0:0:0: [sda] Attached SCSI disk
[    8.394695] EXT4-fs (sda4): mounted filesystem 93cb7dd2-ce1b-4bf5-ba47-818cf8e8c9f4 ro with ordered data mode. Quota mode: none.
[   18.578020] EXT4-fs (sda4): re-mounted 93cb7dd2-ce1b-4bf5-ba47-818cf8e8c9f4 ro. Quota mode: none.
[   23.159524] EXT4-fs (sda4): re-mounted 93cb7dd2-ce1b-4bf5-ba47-818cf8e8c9f4 r/w. Quota mode: none.
Kernel 6.5-alpha1:

dmesg | grep -i sda

Code: Select all

[    4.208905] sd 0:0:0:0: [sda] 3907029168 512-byte logical blocks: (2.00 TB/1.82 TiB)
[    4.253995] sd 0:0:0:0: [sda] 4096-byte physical blocks
[    4.254826] sd 0:0:0:0: [sda] Write Protect is off
[    4.300069] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    4.486476] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    4.580507] sd 0:0:0:0: [sda] Preferred minimum I/O size 4096 bytes
[    4.712624] Dev sda: unable to read partition block 4294967295
[    4.761532]  sda: RDSK (512) sda1 (DOS^G)(res 2 spb 2) sda2 (SFS^B)(res 2 spb 1) sda3 (SFS^B)(res 2 spb 2) sda4 ((res 2 spb 1) unable to read partition table
[    4.761892] sda: partition table beyond EOD, 
[    4.861681] Dev sda: unable to read partition block 4294967295
[    4.912094]  sda: RDSK (512) sda1 (DOS^G)(res 2 spb 2) sda2 (SFS^B)(res 2 spb 1) sda3 (SFS^B)(res 2 spb 2) sda4 ((res 2 spb 1) unable to read partition table
[    4.963387] sda: partition table beyond EOD, 
[    5.014769] sd 0:0:0:0: [sda] Attached SCSI disk
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

I think, I have the problematic commit.
- fix overflows in the Amiga partition handling code (Michael Schmitz <[email protected]>)

...

block: add overflow checks for Amiga partition support
block: fix signed int overflow in Amiga partition support
Commit: Block updates

Code: a/block/partitions/amiga.c
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

I created a patch for reverting the commit.

Code: Select all

diff -rupN a/block/partitions/amiga.c b/block/partitions/amiga.c > revert_amiga.c.patch
revert_amiga.c.patch:

Code: Select all

--- a/block/partitions/amiga.c	2023-06-29 04:29:22.947100347 +0200
+++ b/block/partitions/amiga.c	2023-06-26 01:29:58.000000000 +0200
@@ -11,18 +11,10 @@
 #define pr_fmt(fmt) fmt
 
 #include <linux/types.h>
-#include <linux/mm_types.h>
-#include <linux/overflow.h>
 #include <linux/affs_hardblocks.h>
 
 #include "check.h"
 
-/* magic offsets in partition DosEnvVec */
-#define NR_HD	3
-#define NR_SECT	5
-#define LO_CYL	9
-#define HI_CYL	10
-
 static __inline__ u32
 checksum_block(__be32 *m, int size)
 {
@@ -39,12 +31,8 @@ int amiga_partition(struct parsed_partit
 	unsigned char *data;
 	struct RigidDiskBlock *rdb;
 	struct PartitionBlock *pb;
-	u64 start_sect, nr_sects;
-	sector_t blk, end_sect;
-	u32 cylblk;		/* rdb_CylBlocks = nr_heads*sect_per_track */
-	u32 nr_hd, nr_sect, lo_cyl, hi_cyl;
-	int part, res = 0;
-	unsigned int blksize = 1;	/* Multiplier for disk block size */
+	int start_sect, nr_sects, blk, part, res = 0;
+	int blksize = 1;	/* Multiplier for disk block size */
 	int slot = 1;
 
 	for (blk = 0; ; blk++, put_dev_sector(sect)) {
@@ -52,7 +40,7 @@ int amiga_partition(struct parsed_partit
 			goto rdb_done;
 		data = read_part_sector(state, blk, &sect);
 		if (!data) {
-			pr_err("Dev %s: unable to read RDB block %llu\n",
+			pr_err("Dev %s: unable to read RDB block %d\n",
 			       state->disk->disk_name, blk);
 			res = -1;
 			goto rdb_done;
@@ -69,12 +57,12 @@ int amiga_partition(struct parsed_partit
 		*(__be32 *)(data+0xdc) = 0;
 		if (checksum_block((__be32 *)data,
 				be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) {
-			pr_err("Trashed word at 0xd0 in block %llu ignored in checksum calculation\n",
+			pr_err("Trashed word at 0xd0 in block %d ignored in checksum calculation\n",
 			       blk);
 			break;
 		}
 
-		pr_err("Dev %s: RDB in block %llu has bad checksum\n",
+		pr_err("Dev %s: RDB in block %d has bad checksum\n",
 		       state->disk->disk_name, blk);
 	}
 
@@ -91,15 +79,10 @@ int amiga_partition(struct parsed_partit
 	blk = be32_to_cpu(rdb->rdb_PartitionList);
 	put_dev_sector(sect);
 	for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
-		/* Read in terms partition table understands */
-		if (check_mul_overflow(blk, (sector_t) blksize, &blk)) {
-			pr_err("Dev %s: overflow calculating partition block %llu! Skipping partitions %u and beyond\n",
-				state->disk->disk_name, blk, part);
-			break;
-		}
+		blk *= blksize;	/* Read in terms partition table understands */
 		data = read_part_sector(state, blk, &sect);
 		if (!data) {
-			pr_err("Dev %s: unable to read partition block %llu\n",
+			pr_err("Dev %s: unable to read partition block %d\n",
 			       state->disk->disk_name, blk);
 			res = -1;
 			goto rdb_done;
@@ -111,70 +94,19 @@ int amiga_partition(struct parsed_partit
 		if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
 			continue;
 
-		/* RDB gives us more than enough rope to hang ourselves with,
-		 * many times over (2^128 bytes if all fields max out).
-		 * Some careful checks are in order, so check for potential
-		 * overflows.
-		 * We are multiplying four 32 bit numbers to one sector_t!
-		 */
-
-		nr_hd   = be32_to_cpu(pb->pb_Environment[NR_HD]);
-		nr_sect = be32_to_cpu(pb->pb_Environment[NR_SECT]);
-
-		/* CylBlocks is total number of blocks per cylinder */
-		if (check_mul_overflow(nr_hd, nr_sect, &cylblk)) {
-			pr_err("Dev %s: heads*sects %u overflows u32, skipping partition!\n",
-				state->disk->disk_name, cylblk);
-			continue;
-		}
-
-		/* check for consistency with RDB defined CylBlocks */
-		if (cylblk > be32_to_cpu(rdb->rdb_CylBlocks)) {
-			pr_warn("Dev %s: cylblk %u > rdb_CylBlocks %u!\n",
-				state->disk->disk_name, cylblk,
-				be32_to_cpu(rdb->rdb_CylBlocks));
-		}
-
-		/* RDB allows for variable logical block size -
-		 * normalize to 512 byte blocks and check result.
-		 */
-
-		if (check_mul_overflow(cylblk, blksize, &cylblk)) {
-			pr_err("Dev %s: partition %u bytes per cyl. overflows u32, skipping partition!\n",
-				state->disk->disk_name, part);
-			continue;
-		}
-
-		/* Calculate partition start and end. Limit of 32 bit on cylblk
-		 * guarantees no overflow occurs if LBD support is enabled.
-		 */
-
-		lo_cyl = be32_to_cpu(pb->pb_Environment[LO_CYL]);
-		start_sect = ((u64) lo_cyl * cylblk);
-
-		hi_cyl = be32_to_cpu(pb->pb_Environment[HI_CYL]);
-		nr_sects = (((u64) hi_cyl - lo_cyl + 1) * cylblk);
+		/* Tell Kernel about it */
 
+		nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
+			    be32_to_cpu(pb->pb_Environment[9])) *
+			   be32_to_cpu(pb->pb_Environment[3]) *
+			   be32_to_cpu(pb->pb_Environment[5]) *
+			   blksize;
 		if (!nr_sects)
 			continue;
-
-		/* Warn user if partition end overflows u32 (AmigaDOS limit) */
-
-		if ((start_sect + nr_sects) > UINT_MAX) {
-			pr_warn("Dev %s: partition %u (%llu-%llu) needs 64 bit device support!\n",
-				state->disk->disk_name, part,
-				start_sect, start_sect + nr_sects);
-		}
-
-		if (check_add_overflow(start_sect, nr_sects, &end_sect)) {
-			pr_err("Dev %s: partition %u (%llu-%llu) needs LBD device support, skipping partition!\n",
-				state->disk->disk_name, part,
-				start_sect, end_sect);
-			continue;
-		}
-
-		/* Tell Kernel about it */
-
+		start_sect = be32_to_cpu(pb->pb_Environment[9]) *
+			     be32_to_cpu(pb->pb_Environment[3]) *
+			     be32_to_cpu(pb->pb_Environment[5]) *
+			     blksize;
 		put_partition(state,slot++,start_sect,nr_sects);
 		{
 			/* Be even more informative to aid mounting */
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

Hi All,

The two week long merge window for 6.5 has been started and here is the first alpha for testing.

New:
Download: linux-image-6.5-alpha1-X1000_X5000.tar.gz

Download of patched kernels because of the issue with accessing of partitions on disks with an Amiga partition table: linux-image-6.5-alpha1-X1000_X5000_with_patched_amiga.c.tar.gz

Image

Please test the alpha1.

Thanks,
Christian
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

Michael Schmitz wrote: Hi Christian,

[ added Martin Steigerwald in CC ]

thanks for your bug report (and of course, for testing the patch in the
first instance)!

Haven't see this one in any of my tests. I wonder whether your
partitioning software used that value of 4294967295 (32 bit unsigned int
max.) as marker for the end of the partition list, instead of NULL? It's
clearly beyond the end of your disk, so cannot be a legitimate partition
block address. (The parted dump above (showing only four partitions)
appears to support that notion.)

Could you please create a dump of the RDB (first 4 MB of the disk ought
to be enough) and send that?

That's the 32 bit overflow that the patch series was meant to correct.
Parsing the partition table ends before looking at the next partition
block in the list, so we never hit the bug you've seen above.

By reverting my patch, you just reintroduce the old bug, which could
result in mis-parsing the partition table in a way that is not detected
by inane values of partition sizes as above, and as far as I recall this
bug was reported because it did cause data corruption. Do I have that
correct, Martin? Do you still have a copy of the problematic RDB from
the old bug report around?

Could you please check this (whitespace-damaged) patch?

block/partitions - Amiga partition overflow fix bugfix

Making 'blk' sector_t (i.e. 64 bit if LBD support is active)
fails the 'blk>0' test in the partition block loop if a
value of (signed int) -1 is used to mark the end of the
partition block list.

Explicitly cast 'blk' to signed int to catch this.

Signed-off-by: Michael Schmitz <schmitzmic at gmail.com>
amiga.c_v1.patch:

Code: Select all

diff --git a/block/partitions/amiga.c b/block/partitions/amiga.c
index ed222b9c901b..506921095412 100644
--- a/block/partitions/amiga.c
+++ b/block/partitions/amiga.c
@@ -90,7 +90,7 @@ int amiga_partition(struct parsed_partitions *state)
         }
         blk = be32_to_cpu(rdb->rdb_PartitionList);
         put_dev_sector(sect);
-       for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
+       for (part = 1; (s32) blk>0 && part<=16; part++, 
put_dev_sector(sect)) {
                 /* Read in terms partition table understands */
                 if (check_mul_overflow(blk, (sector_t) blksize, &blk)) {
                         pr_err("Dev %s: overflow calculating partition 
block %llu! Skipping partitions %u and beyond\n",
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

Update amiga.c_v1.patch:

Code: Select all

--- a/block/partitions/amiga.c	2023-07-01 06:32:03.106124319 +0200
+++ b/block/partitions/amiga.c	2023-07-01 06:36:59.425257149 +0200
@@ -90,7 +90,7 @@ int amiga_partition(struct parsed_partit
 	}
 	blk = be32_to_cpu(rdb->rdb_PartitionList);
 	put_dev_sector(sect);
-	for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
+	for (part = 1; (s32) blk>0 && part<=16; part++, put_dev_sector(sect)) {	
 		/* Read in terms partition table understands */
 		if (check_mul_overflow(blk, (sector_t) blksize, &blk)) {
 			pr_err("Dev %s: overflow calculating partition block %llu! Skipping partitions %u and beyond\n",
User avatar
xeno74
Posts: 10712
Joined: Fri Mar 23, 2012 7:58 am
Contact:

Re: New kernels

Post by xeno74 »

xeno74 wrote: Sat Jul 01, 2023 6:41 am Update amiga.c_v1.patch:

Code: Select all

--- a/block/partitions/amiga.c	2023-07-01 06:32:03.106124319 +0200
+++ b/block/partitions/amiga.c	2023-07-01 06:36:59.425257149 +0200
@@ -90,7 +90,7 @@ int amiga_partition(struct parsed_partit
 	}
 	blk = be32_to_cpu(rdb->rdb_PartitionList);
 	put_dev_sector(sect);
-	for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
+	for (part = 1; (s32) blk>0 && part<=16; part++, put_dev_sector(sect)) {	
 		/* Read in terms partition table understands */
 		if (check_mul_overflow(blk, (sector_t) blksize, &blk)) {
 			pr_err("Dev %s: overflow calculating partition block %llu! Skipping partitions %u and beyond\n",
I patched the kernel source code with this patch today but unfortunately the kernel has reported a bad geometry. (EXT4-fs (sda4): bad geometry: block count ...)

dmesg | grep -i sda

Code: Select all

[    4.025449] sd 0:0:0:0: [sda] 3907029168 512-byte logical blocks: (2.00 TB/1.82 TiB)
[    4.071978] sd 0:0:0:0: [sda] 4096-byte physical blocks
[    4.119333] sd 0:0:0:0: [sda] Write Protect is off
[    4.165958] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    4.212921] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    4.259469] sd 0:0:0:0: [sda] Preferred minimum I/O size 4096 bytes
[    4.502519]  sda: RDSK (512) sda1 (DOS^G)(res 2 spb 2) sda2 (SFS^B)(res 2 spb 1) sda3 (SFS^B)(res 2 spb 2) sda4 ((res 2 spb 1)
[    4.551981] sd 0:0:0:0: [sda] Attached SCSI disk
[   82.421727] EXT4-fs (sda4): bad geometry: block count 319655862 exceeds size of device (317690430 blocks)
Post Reply