GPT detection regression in efi.c from commit 27a7c64
Subsystems (2)
The commit, "27a7c64 partitions/efi: account for pmbr size in lba", that was just merged in 3.12-rc caused a regression on my system with a GPT formatted eMMC device. In 3.11, the GPT partition table was detected fine but now a partition table is not detected.
Not being a GPT expert, I did some research and found that the tool used to create the PMBR on my system shares characteristics with what is mentioned in an explanation of Microsoft created PMBRs [1]. In short, the size_in_lba field incorrectly has 0xffffffff even though I have a <2TiB drive (16GiB eMMC).
I get that this is not compliant with UEFI. I bring this up because before this commit the is_pmbr_valid() check was less pedantic. In 3.11 a PMBR formatted this way did not fail the check. For my particular case, I simply dded out LBA 1 and whacked the SizeInLBA field to comply with the spec and this patch and I'm back in business. We're updating the tools that we inherited to prepopulate our boards with a GPT to be compliant. However, I wondered if this would be a problem for all the people with Windows-generated GPTs as noted in [1].
-Matt
[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT
"The partition table contains only a single "GPT Protective" entry which in all cases is set to the maximum 32-bit limitation (even though a drive may have far less than a 2.2 TB capacity). The "GPT Protective MBR Sector" has exactly the same contents for all GPT disk drives created by the Windows 7 (or 8) OS. But, note: This does not follow the UEFI Specification, which states that the "SizeInLBA" should be "set to the size of the disk minus one" if it's not too large to be represented.[1] (GPT drives partitioned under various Linux and Apple® Mac OS systems do follow the UEFI Specification in this regard.)"
Cc'ing Linus.
Quoted 10 lines · Matt Porter
The commit, "27a7c64 partitions/efi: account for pmbr size in lba", that was just merged in 3.12-rc caused a regression on my system with a GPT formatted eMMC device. In 3.11, the GPT partition table was detected fine but now a partition table is not detected.
Not being a GPT expert, I did some research and found that the tool used to create the PMBR on my system shares characteristics with what is mentioned in an explanation of Microsoft created PMBRs [1]. In short, the
size_in_lbafield incorrectly has0xffffffffeven though I have a <2TiB drive (16GiB eMMC).
*sigh*. So Microsoft decided to do its own version of the GPT specs.
Up until now, Linux was incorrectly enforcing pMBR checks: not recognizing valid labels and vice versa, as with the case you are mentioning now. The changes that went in the 3.12 merge window attempt to address those concerns, enforcing the correct checks - which is also how Linux partitioning tools do it (fdisk, parted).
Quoted 9 lines
I get that this is not compliant with UEFI. I bring this up because before this commit the
is_pmbr_valid()check was less pedantic. In 3.11 a PMBR formatted this way did not fail the check. For my particular case, I simply dded out LBA 1 and whacked the SizeInLBA field to comply with the spec and this patch and I'm back in business. We're updating the tools that we inherited to prepopulate our boards with a GPT to be compliant. However, I wondered if this would be a problem for all the people with Windows-generated GPTs as noted in [1].
I guess this comes down to choosing whether or not we want Linux to be more UEFI compliant or not. Should we care if Microsoft decides to go do things out of the official spec? I don't know the policy here. The fact is that *they* should update their partitioning tools and create valid pMBRs. Any way, I'm ok with reverting this commit if deemed necessary.
Thanks,
Davidlohr
Quoted 14 lines
-Matt
[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT
"The partition table contains only a single "GPT Protective" entry which in all cases is set to the maximum 32-bit limitation (even though a drive may have far less than a 2.2 TB capacity). The "GPT Protective MBR Sector" has exactly the same contents for all GPT disk drives created by the Windows 7 (or 8) OS. But, note: This does not follow the UEFI Specification, which states that the "SizeInLBA" should be "set to the size of the disk minus one" if it's not too large to be represented.[1] (GPT drives partitioned under various Linux and Apple® Mac OS systems do follow the UEFI Specification in this regard.)"
Quoted 8 lines · Davidlohr Bueso
Cc'ing Linus.
Quoted 5 lines · Matt Porter
The commit, "27a7c64 partitions/efi: account for pmbr size in lba", that was just merged in 3.12-rc caused a regression on my system with a GPT formatted eMMC device. In 3.11, the GPT partition table was detected fine but now a partition table is not detected.
Quoted 7 lines
Quoted 5 lines
Not being a GPT expert, I did some research and found that the tool used to create the PMBR on my system shares characteristics with what is mentioned in an explanation of Microsoft created PMBRs [1]. In short, the
size_in_lbafield incorrectly has0xffffffffeven though I have a <2TiB drive (16GiB eMMC).*sigh*. So Microsoft decided to do its own version of the GPT specs.
Don't sound so surprised. :)
Quoted 5 lines
Up until now, Linux was incorrectly enforcing pMBR checks: not recognizing valid labels and vice versa, as with the case you are mentioning now. The changes that went in the 3.12 merge window attempt to address those concerns, enforcing the correct checks - which is also how Linux partitioning tools do it (fdisk, parted).
Understood, and we are fixing our own manufacturing tool that was used to prepopulate the eMMC. I definitely prefer to have this correct for my case.
Quoted 9 lines
Quoted 8 lines
I get that this is not compliant with UEFI. I bring this up because before this commit the
is_pmbr_valid()check was less pedantic. In 3.11 a PMBR formatted this way did not fail the check. For my particular case, I simply dded out LBA 1 and whacked the SizeInLBA field to comply with the spec and this patch and I'm back in business. We're updating the tools that we inherited to prepopulate our boards with a GPT to be compliant. However, I wondered if this would be a problem for all the people with Windows-generated GPTs as noted in [1].
Quoted 5 lines
I guess this comes down to choosing whether or not we want Linux to be more UEFI compliant or not. Should we care if Microsoft decides to go do things out of the official spec? I don't know the policy here. The fact is that *they* should update their partitioning tools and create valid pMBRs. Any way, I'm ok with reverting this commit if deemed necessary.
I can't say first-hand that Windows 7/8 does what is claimed in this description as I simply don't have access to any Windows machines here. If it's true, I would have to agree with Linus that meeting reality if more important than meeting the spec.
Hopefully somebody can confirm that Windows does indeed produce these special PMBRs that need to be handled as an exception to the spec.
-Matt
Quoted 1 line · Matt Porter
On 09/13/2013 12:28 PM, Davidlohr Bueso wrote:
[...]
Quoted 16 lines
Quoted 10 lines
Quoted 9 lines
I get that this is not compliant with UEFI. I bring this up because before this commit the
is_pmbr_valid()check was less pedantic. In 3.11 a PMBR formatted this way did not fail the check. For my particular case, I simply dded out LBA 1 and whacked the SizeInLBA field to comply with the spec and this patch and I'm back in business. We're updating the tools that we inherited to prepopulate our boards with a GPT to be compliant. However, I wondered if this would be a problem for all the people with Windows-generated GPTs as noted in [1].Quoted 5 lines
I guess this comes down to choosing whether or not we want Linux to be more UEFI compliant or not. Should we care if Microsoft decides to go do things out of the official spec? I don't know the policy here. The fact is that *they* should update their partitioning tools and create valid pMBRs. Any way, I'm ok with reverting this commit if deemed necessary.
Quoted 4 lines
I can't say first-hand that Windows 7/8 does what is claimed in this description as I simply don't have access to any Windows machines here. If it's true, I would have to agree with Linus that meeting reality if more important than meeting the spec.
Yep, me too.
Quoted 3 lines
Hopefully somebody can confirm that Windows does indeed produce these special PMBRs that need to be handled as an exception to the spec.
I've got a partition with Windows 7 and I can take a look during the weekend. Do you know exactly what tool was used for creating the partition?
Thanks,
Davidlohr
Quoted 25 lines · Matt Porter
Quoted 8 lines · Davidlohr Bueso
Cc'ing Linus.
Quoted 5 lines · Matt Porter
The commit, "27a7c64 partitions/efi: account for pmbr size in lba", that was just merged in 3.12-rc caused a regression on my system with a GPT formatted eMMC device. In 3.11, the GPT partition table was detected fine but now a partition table is not detected.
Quoted 7 lines
Quoted 5 lines
Not being a GPT expert, I did some research and found that the tool used to create the PMBR on my system shares characteristics with what is mentioned in an explanation of Microsoft created PMBRs [1]. In short, the
size_in_lbafield incorrectly has0xffffffffeven though I have a <2TiB drive (16GiB eMMC).*sigh*. So Microsoft decided to do its own version of the GPT specs.
Don't sound so surprised. :)
Quoted 5 lines
Up until now, Linux was incorrectly enforcing pMBR checks: not recognizing valid labels and vice versa, as with the case you are mentioning now. The changes that went in the 3.12 merge window attempt to address those concerns, enforcing the correct checks - which is also how Linux partitioning tools do it (fdisk, parted).
Quoted 3 lines
Understood, and we are fixing our own manufacturing tool that was used to prepopulate the eMMC. I definitely prefer to have this correct for my case.
Come to think of it, we do have a long existing workaround: the force_gpt option. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).
Thanks,
Davidlohr
Quoted 26 lines · Davidlohr Bueso
Quoted 25 lines · Matt Porter
Quoted 8 lines · Davidlohr Bueso
Cc'ing Linus.
Quoted 5 lines · Matt Porter
The commit, "27a7c64 partitions/efi: account for pmbr size in lba", that was just merged in 3.12-rc caused a regression on my system with a GPT formatted eMMC device. In 3.11, the GPT partition table was detected fine but now a partition table is not detected.
Quoted 7 lines
Quoted 5 lines
Not being a GPT expert, I did some research and found that the tool used to create the PMBR on my system shares characteristics with what is mentioned in an explanation of Microsoft created PMBRs [1]. In short, the
size_in_lbafield incorrectly has0xffffffffeven though I have a <2TiB drive (16GiB eMMC).*sigh*. So Microsoft decided to do its own version of the GPT specs.
Don't sound so surprised. :)
Quoted 5 lines
Up until now, Linux was incorrectly enforcing pMBR checks: not recognizing valid labels and vice versa, as with the case you are mentioning now. The changes that went in the 3.12 merge window attempt to address those concerns, enforcing the correct checks - which is also how Linux partitioning tools do it (fdisk, parted).
Quoted 7 lines
Quoted 3 lines
Understood, and we are fixing our own manufacturing tool that was used to prepopulate the eMMC. I definitely prefer to have this correct for my case.
Come to think of it, we do have a long existing workaround: the
force_gptoption. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).
Yes, that's what I used at first after seeing what the problem was. But then I opted to fix my PMBR.
I felt like it was a regression since it required a new option passed on the cmdline.
-Matt
Quoted 27 lines · Davidlohr Bueso
Quoted 1 line · Matt Porter
On 09/13/2013 12:28 PM, Davidlohr Bueso wrote:
[...]
Quoted 16 lines
Quoted 10 lines
Quoted 9 lines
I get that this is not compliant with UEFI. I bring this up because before this commit the
is_pmbr_valid()check was less pedantic. In 3.11 a PMBR formatted this way did not fail the check. For my particular case, I simply dded out LBA 1 and whacked the SizeInLBA field to comply with the spec and this patch and I'm back in business. We're updating the tools that we inherited to prepopulate our boards with a GPT to be compliant. However, I wondered if this would be a problem for all the people with Windows-generated GPTs as noted in [1].Quoted 5 lines
I guess this comes down to choosing whether or not we want Linux to be more UEFI compliant or not. Should we care if Microsoft decides to go do things out of the official spec? I don't know the policy here. The fact is that *they* should update their partitioning tools and create valid pMBRs. Any way, I'm ok with reverting this commit if deemed necessary.
Quoted 4 lines
I can't say first-hand that Windows 7/8 does what is claimed in this description as I simply don't have access to any Windows machines here. If it's true, I would have to agree with Linus that meeting reality if more important than meeting the spec.
Yep, me too.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Hopefully somebody can confirm that Windows does indeed produce these special PMBRs that need to be handled as an exception to the spec.
I've got a partition with Windows 7 and I can take a look during the weekend. Do you know exactly what tool was used for creating the partition?
Just to be clear, we used an internal Broadcom tool that did this Windows-like behavior on our bcm281xx reference board.
In the Windows situation, I really have no idea what tool Windows 7/8 use to partition disks. Based on that article, I'm assuming it's whatever today's version of "FDISK", as shipped on Windows 7/8, is.
Ok, Google claims it is "The Windows 7 Disk Management" tool. I might try to stop at somebody's house this weekend, boot Linux from USB and extract the PMBR from their drive just as another data point.
-Matt
Quoted 9 lines · Matt Porter
Quoted 3 lines
Come to think of it, we do have a long existing workaround: the
force_gptoption. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).Yes, that's what I used at first after seeing what the problem was. But then I opted to fix my PMBR.
I felt like it was a regression since it required a new option passed on the cmdline.
Yep, it is *regression* and I guess Davidlohr is going to fix it asap :-)
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 5 lines · Karel Zak
Quoted 4 lines · Matt Porter
Quoted 3 lines
Come to think of it, we do have a long existing workaround: the
force_gptoption. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).
Quoted 7 lines
Quoted 5 lines
Yes, that's what I used at first after seeing what the problem was. But then I opted to fix my PMBR.
I felt like it was a regression since it required a new option passed on the cmdline.
Yep, it is *regression* and I guess Davidlohr is going to fix it asap :-)
I was doing a git revert, but what would you guys think of keeping the check but making it more flexible? Instead of enforcing the minimum, just make sure that the size_in_lba is either the whole disk or 2 TiB, that should take care of Matt's issue.
block/partitions/efi.c +2 -2
@@ -220,8 +220,8 @@ check_hybrid:* Hybrid MBRs do not necessarily comply with this. */ if (ret ==GPT_MBR_PROTECTIVE ) { -if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != -min ((uint32_t ) total_sectors -1 ,0xFFFFFFFF )) +if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != (uint32_t ) total_sectors -1 || +le32_to_cpu (mbr->partition_record[part].size_in_lba) !=0xFFFFFFFF ) ret =0 ; } done:
Karel, I guess any changes that we do here should apply to fdisk :)
Thanks,
Davidlohr
Quoted 12 lines · Davidlohr Bueso
Quoted 11 lines · Karel Zak
Quoted 9 lines · Matt Porter
Quoted 3 lines
Come to think of it, we do have a long existing workaround: the
force_gptoption. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).Yes, that's what I used at first after seeing what the problem was. But then I opted to fix my PMBR.
I felt like it was a regression since it required a new option passed on the cmdline.
Quoted 6 lines
Quoted 1 line
Yep, it is *regression* and I guess Davidlohr is going to fix it asap :-)
I was doing a git revert, but what would you guys think of keeping the check but making it more flexible? Instead of enforcing the minimum, just make sure that the
size_in_lbais either the whole disk or 2 TiB, that should take care of Matt's issue.
That seems to be the way to go given the departure from the spec.
Quoted 21 lines
block/partitions/efi.c +2
-2@@ -220,8 +220,8 @@ check_hybrid:* Hybrid MBRs do not necessarily comply with this. */ if (ret ==GPT_MBR_PROTECTIVE ) { -if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != -min ((uint32_t ) total_sectors -1 ,0xFFFFFFFF )) +if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != (uint32_t ) total_sectors -1 || +le32_to_cpu (mbr->partition_record[part].size_in_lba) !=0xFFFFFFFF ) ret =0 ; } done:Karel, I guess any changes that we do here should apply to fdisk :)
Thanks,
Davidlohr
Quoted 13 lines · Matt Porter
Quoted 12 lines · Davidlohr Bueso
Quoted 11 lines · Karel Zak
Quoted 9 lines · Matt Porter
Quoted 3 lines
Come to think of it, we do have a long existing workaround: the
force_gptoption. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).Yes, that's what I used at first after seeing what the problem was. But then I opted to fix my PMBR.
I felt like it was a regression since it required a new option passed on the cmdline.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Yep, it is *regression* and I guess Davidlohr is going to fix it asap :-)
I was doing a git revert, but what would you guys think of keeping the check but making it more flexible? Instead of enforcing the minimum, just make sure that the
size_in_lbais either the whole disk or 2 TiB, that should take care of Matt's issue.That seems to be the way to go given the departure from the spec.
Matt, could you please verify that this patch fixes your problem?
Thanks!
8<-------------------------------------------------
From: Davidlohr Bueso <[email protected]>
Subject: [PATCH] partitions/efi: loosen pmbr size in lba check
Matt found that commit 27a7c64 (partitions/efi: account for pmbr size in lba) caused his GPT formatted eMMC device not to boot. The reason is that this commit enforced Linux to always check the lesser of the whole disk or 2Tib for the pMBR size in LBA. While most disk partitioning tools out there create a pMBR with these characteristics, Microsoft does not, as it always sets the entry to the maximum 32-bit limitation - even though a drive may be smaller than that[1].
Loosen this check and only verify that the size is either the whole disk or 0xFFFFFFFF. No tool in its right mind would set it to any value other than these.
[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT
--- block/partitions/efi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/partitions/efi.c +6 -2
@@ -186,6 +186,7 @@ invalid:*/ static int is_pmbr_valid (legacy_mbr *mbr,sector_t total_sectors) { +uint32_t sz =0 ;int i, part =0 , ret =0 ;/* invalid by default */ if (!mbr ||le16_to_cpu (mbr->signature) !=MSDOS_MBR_SIGNATURE )
@@ -216,12 +217,15 @@ check_hybrid:/* * Protective MBRs take up the lesser of the whole disk * or 2 TiB (32bit LBA), ignoring the rest of the disk. +* Some partitioning programs, nonetheless, choose to set +* the size to the maximum 32-bit limitation, disregarding +* the disk size. * * Hybrid MBRs do not necessarily comply with this. */ if (ret ==GPT_MBR_PROTECTIVE ) { -if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != -min ((uint32_t ) total_sectors -1 ,0xFFFFFFFF )) + sz =le32_to_cpu (mbr->partition_record[part].size_in_lba); +if (sz != (uint32_t ) total_sectors -1 || sz !=0xFFFFFFFF ) ret =0 ; } done:
Signature · 1 line
1.7.11.7
Matt Porter
Tested-byQuoted 67 lines · Davidlohr Bueso
Quoted 13 lines · Matt Porter
Quoted 12 lines · Davidlohr Bueso
Quoted 11 lines · Karel Zak
Quoted 9 lines · Matt Porter
Quoted 3 lines
Come to think of it, we do have a long existing workaround: the
force_gptoption. Setting it will bypass any MBR checking (is_pmbr_valid(), specifically).Yes, that's what I used at first after seeing what the problem was. But then I opted to fix my PMBR.
I felt like it was a regression since it required a new option passed on the cmdline.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Yep, it is *regression* and I guess Davidlohr is going to fix it asap :-)
I was doing a git revert, but what would you guys think of keeping the check but making it more flexible? Instead of enforcing the minimum, just make sure that the
size_in_lbais either the whole disk or 2 TiB, that should take care of Matt's issue.That seems to be the way to go given the departure from the spec.
Matt, could you please verify that this patch fixes your problem?
Thanks!
8<-------------------------------------------------
From: Davidlohr Bueso <[email protected]>
Subject: [PATCH] partitions/efi: loosen pmbr size in lba checkMatt found that commit 27a7c64 (partitions/efi: account for pmbr size in lba) caused his GPT formatted eMMC device not to boot. The reason is that this commit enforced Linux to always check the lesser of the whole disk or 2Tib for the pMBR size in LBA. While most disk partitioning tools out there create a pMBR with these characteristics, Microsoft does not, as it always sets the entry to the maximum 32-bit limitation - even though a drive may be smaller than that[1].
Loosen this check and only verify that the size is either the whole disk or
0xFFFFFFFF. No tool in its right mind would set it to any value other than these.[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT
Reported-by Matt Porter <[email protected]>Signed-off-by Davidlohr Bueso <[email protected]>--- block/partitions/efi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)block/partitions/efi.c +2
-0@@ -186,6 +186,7 @@ invalid:*/ static int is_pmbr_valid (legacy_mbr *mbr,sector_t total_sectors) { +uint32_t sz =0 ;int i, part =0 , ret =0 ;/* invalid by default */ if (!mbr ||le16_to_cpu (mbr->signature) !=MSDOS_MBR_SIGNATURE )@@ -216,12 +217,15 @@ check_hybrid:/* * Protective MBRs take up the lesser of the whole disk * or 2 TiB (32bit LBA), ignoring the rest of the disk. +* Some partitioning programs, nonetheless, choose to set
block/partitions/efi.c check_hybrid: · line 228
Quoted 10 lines
block/partitions/efi.c +4
-2+* the size to the maximum 32-bit limitation, disregarding +* the disk size. * * Hybrid MBRs do not necessarily comply with this. */ if (ret ==GPT_MBR_PROTECTIVE ) { -if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != -min ((uint32_t ) total_sectors -1 ,0xFFFFFFFF )) + sz =le32_to_cpu (mbr->partition_record[part].size_in_lba); +if (sz != (uint32_t ) total_sectors -1 || sz !=0xFFFFFFFF )
Almost! You'll want to get that brown paper bag out cause I've worn it for this same type of bug before. Add this fix in and you can have my
block/partitions/efi.c +1 -1
@@ -225,7 +225,7 @@ check_hybrid:*/ if (ret ==GPT_MBR_PROTECTIVE ) { sz =le32_to_cpu (mbr->partition_record[part].size_in_lba); -if (sz != (uint32_t ) total_sectors -1 || sz !=0xFFFFFFFF ) +if (sz != (uint32_t ) total_sectors -1 && sz !=0xFFFFFFFF )
ret = 0;
}done:
Thanks,
Matt
On Fri, 2013-09-13 at 17:36 -0400, Matt Porter wrote:
[...]
Quoted 39 lines
Quoted 18 lines
block/partitions/efi.c +2
-0@@ -186,6 +186,7 @@ invalid:*/ static int is_pmbr_valid (legacy_mbr *mbr,sector_t total_sectors) { +uint32_t sz =0 ;int i, part =0 , ret =0 ;/* invalid by default */ if (!mbr ||le16_to_cpu (mbr->signature) !=MSDOS_MBR_SIGNATURE )@@ -216,12 +217,15 @@ check_hybrid:/* * Protective MBRs take up the lesser of the whole disk * or 2 TiB (32bit LBA), ignoring the rest of the disk. +* Some partitioning programs, nonetheless, choose to set block/partitions/efi.c check_hybrid: · line 228
Quoted 10 lines
block/partitions/efi.c +4
-2+* the size to the maximum 32-bit limitation, disregarding +* the disk size. * * Hybrid MBRs do not necessarily comply with this. */ if (ret ==GPT_MBR_PROTECTIVE ) { -if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != -min ((uint32_t ) total_sectors -1 ,0xFFFFFFFF )) + sz =le32_to_cpu (mbr->partition_record[part].size_in_lba); +if (sz != (uint32_t ) total_sectors -1 || sz !=0xFFFFFFFF )Almost! You'll want to get that brown paper bag out cause I've worn it for this same type of bug before. Add this fix in and you can have my
Tested-by Matt Porter <[email protected]>block/partitions/efi.c +0
-0
block/partitions/efi.c check_hybrid: · line 229
Quoted 6 lines
block/partitions/efi.c +1
-1@@ -225,7 +225,7 @@ check_hybrid:*/ if (ret ==GPT_MBR_PROTECTIVE ) { sz =le32_to_cpu (mbr->partition_record[part].size_in_lba); -if (sz != (uint32_t ) total_sectors -1 || sz !=0xFFFFFFFF ) +if (sz != (uint32_t ) total_sectors -1 && sz !=0xFFFFFFFF ) ret =0 ;
Oh my, yes, sorry about that. I obviously only built-tested this patch. Linus, if you're ok with it, please go ahead and pick this up.
Thanks,
Davidlohr
8<-------------------------------------------------
From: Davidlohr Bueso <[email protected]>
Subject: [PATCH] partitions/efi: loosen pmbr size in lba check
Matt found that commit 27a7c64 (partitions/efi: account for pmbr size in lba) caused his GPT formatted eMMC device not to boot. The reason is that this commit enforced Linux to always check the lesser of the whole disk or 2Tib for the pMBR size in LBA. While most disk partitioning tools out there create a pMBR with these characteristics, Microsoft does not, as it always sets the entry to the maximum 32-bit limitation - even though a drive may be smaller than that[1].
Loosen this check and only verify that the size is either the whole disk or 0xFFFFFFFF. No tool in its right mind would set it to any value other than these.
[1] http://thestarman.pcministry.com/asm/mbr/GPT.htm#GPTPT
--- block/partitions/efi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/partitions/efi.c +6 -2
@@ -186,6 +186,7 @@ invalid:*/ static int is_pmbr_valid (legacy_mbr *mbr,sector_t total_sectors) { +uint32_t sz =0 ;int i, part =0 , ret =0 ;/* invalid by default */ if (!mbr ||le16_to_cpu (mbr->signature) !=MSDOS_MBR_SIGNATURE )
@@ -216,12 +217,15 @@ check_hybrid:/* * Protective MBRs take up the lesser of the whole disk * or 2 TiB (32bit LBA), ignoring the rest of the disk. +* Some partitioning programs, nonetheless, choose to set +* the size to the maximum 32-bit limitation, disregarding +* the disk size. * * Hybrid MBRs do not necessarily comply with this. */ if (ret ==GPT_MBR_PROTECTIVE ) { -if (le32_to_cpu (mbr->partition_record[part].size_in_lba) != -min ((uint32_t ) total_sectors -1 ,0xFFFFFFFF )) + sz =le32_to_cpu (mbr->partition_record[part].size_in_lba); +if (sz != (uint32_t ) total_sectors -1 && sz !=0xFFFFFFFF ) ret =0 ; } done:
Signature · 1 line
1.7.11.7