Skip to contentSkip to conversation

x86/efi-bgrt: Switch pr_err() to pr_debug() for invalid BGRT

PATCH In review Matt Fleming 6 participants 13 messages Jun 29, 2015 – Jun 30, 2015 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/efi-bgrt: Switch pr_err() to pr_debug() for invalid BGRT

From: Matt Fleming <[email protected]>

It's totally legitimate, per the ACPI spec, for the firmware to set the BGRT 'status' field to zero to indicate that the BGRT image isn't being displayed, and we shouldn't be printing an error message in that case because it's just noise for users. So swap pr_err() for pr_debug().

However, Josh points that out it still makes sense to test the validity of the upper 7 bits of the 'status' field, since they're marked as "reserved" in the spec and must be zero. If firmware violates this it really *is* an error.

Cc Josh Triplett <[email protected]>
Cc Matthew Garrett <[email protected]>

---

Tom, if you could test out this patch that would be really helpful. I'll take this one through the EFI git repo.

 arch/x86/platform/efi/efi-bgrt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/platform/efi/efi-bgrt.c +7 -2
index d7f997f7c26d..ea48449b2e63 100644
@@ -50,11 +50,16 @@ void __init efi_bgrt_init(void)
 		       bgrt_tab->version);
 		return;
 	}
-	if (bgrt_tab->status != 1) {
-		pr_err("Ignoring BGRT: invalid status %u (expected 1)\n",
+	if (bgrt_tab->status & 0xfe) {
+		pr_err("Ignoring BGRT: reserved status bits are non-zero %u\n",
 		       bgrt_tab->status);
 		return;
 	}
+	if (bgrt_tab->status != 1) {
+		pr_debug("Ignoring BGRT: invalid status %u (expected 1)\n",
+			 bgrt_tab->status);
+		return;
+	}
 	if (bgrt_tab->image_type != 0) {
 		pr_err("Ignoring BGRT: invalid image type %u (expected 0)\n",
 		       bgrt_tab->image_type);
Signature · 1 line
2.1.0
#2 lore raw
In reply to a message not in the archive
Quoted 11 lines · Matt Fleming

From: Matt Fleming <[email protected]>

It's totally legitimate, per the ACPI spec, for the firmware to set the BGRT 'status' field to zero to indicate that the BGRT image isn't being displayed, and we shouldn't be printing an error message in that case because it's just noise for users. So swap pr_err() for pr_debug().

However, Josh points that out it still makes sense to test the validity of the upper 7 bits of the 'status' field, since they're marked as "reserved" in the spec and must be zero. If firmware violates this it really *is* an error.

Sounds to me this should be

	pr_warn(FW_WARN "... );

then, no?

So that it hopefully gets caught at early testing when fw can still be fixed...?

Better yet FW_BUG even...

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#4 lore raw
In reply to a message not in the archive
Quoted 15 lines · Borislav Petkov
Quoted 11 lines · Matt Fleming

From: Matt Fleming <[email protected]>

It's totally legitimate, per the ACPI spec, for the firmware to set the BGRT 'status' field to zero to indicate that the BGRT image isn't being displayed, and we shouldn't be printing an error message in that case because it's just noise for users. So swap pr_err() for pr_debug().

However, Josh points that out it still makes sense to test the validity of the upper 7 bits of the 'status' field, since they're marked as "reserved" in the spec and must be zero. If firmware violates this it really *is* an error.

Sounds to me this should be

Quoted 8 lines
	pr_warn(FW_WARN "... );

then, no?

So that it hopefully gets caught at early testing when fw can still be fixed...?

Better yet FW_BUG even...

Definitely not FW_BUG. The field is reserved *now*; it would be legitimate for a new version of the BGRT spec to define one of those bits for something else.

- Josh Triplett

Reviewed-by
#14 lore raw
In reply to a message not in the archive
Quoted 12 lines · Matt Fleming

From: Matt Fleming <[email protected]>

It's totally legitimate, per the ACPI spec, for the firmware to set the BGRT 'status' field to zero to indicate that the BGRT image isn't being displayed, and we shouldn't be printing an error message in that case because it's just noise for users. So swap pr_err() for pr_debug().

However, Josh points that out it still makes sense to test the validity of the upper 7 bits of the 'status' field, since they're marked as "reserved" in the spec and must be zero. If firmware violates this it really *is* an error.

Quoted 4 lines
Cc Josh Triplett <[email protected]>
Cc Matthew Garrett <[email protected]>

Looks reasonable to me.

Quoted 33 lines

Tom, if you could test out this patch that would be really helpful. I'll take this one through the EFI git repo.

 arch/x86/platform/efi/efi-bgrt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/platform/efi/efi-bgrt.c +7 -2
index d7f997f7c26d..ea48449b2e63 100644
@@ -50,11 +50,16 @@ void __init efi_bgrt_init(void)
 		       bgrt_tab->version);
 		return;
 	}
-	if (bgrt_tab->status != 1) {
-		pr_err("Ignoring BGRT: invalid status %u (expected 1)\n",
+	if (bgrt_tab->status & 0xfe) {
+		pr_err("Ignoring BGRT: reserved status bits are non-zero %u\n",
 		       bgrt_tab->status);
 		return;
 	}
+	if (bgrt_tab->status != 1) {
+		pr_debug("Ignoring BGRT: invalid status %u (expected 1)\n",
+			 bgrt_tab->status);
+		return;
+	}
 	if (bgrt_tab->image_type != 0) {
 		pr_err("Ignoring BGRT: invalid image type %u (expected 0)\n",
 		       bgrt_tab->image_type);
Signature · 1 line
2.1.0
#5 lore raw
In reply to Josh Triplett
Quoted 3 lines · Josh Triplett

Definitely not FW_BUG. The field is reserved *now*; it would be legitimate for a new version of the BGRT spec to define one of those bits for something else.

Which would mean that booting old kernels on new FW which defines those reserved bits would cause that warning to fire erroneously.

So then we probably don't need it at all or we need to check implemented BGRT version of the FW running to know which bits are defined by the spec and which are reserved...

Also, does the spec really say that reserved bits must be zero? Or it doesn't specify their value?

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#7 lore raw
In reply to a message not in the archive
Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Josh Triplett

Definitely not FW_BUG. The field is reserved *now*; it would be legitimate for a new version of the BGRT spec to define one of those bits for something else.

Which would mean that booting old kernels on new FW which defines those reserved bits would cause that warning to fire erroneously.

Not erroneously; those bits could potentially indicate some status condition we don't know about, so we need to assume we can't handle the table if a bit we don't understand is set.

(Specs like this should really do what ext4 does, and define whether a given set of currently undefined bits are optional or mandatory; as in, if you don't understand them, can you proceed or should you stop?)

Quoted 6 lines

So then we probably don't need it at all or we need to check implemented BGRT version of the FW running to know which bits are defined by the spec and which are reserved...

Also, does the spec really say that reserved bits must be zero? Or it doesn't specify their value?

The spec says those bits of the status field are reserved and must be zero.

- Josh Triplett

#8 lore raw
In reply to Borislav Petkov
Quoted 11 lines · Borislav Petkov
Quoted 3 lines · Josh Triplett

Definitely not FW_BUG. The field is reserved *now*; it would be legitimate for a new version of the BGRT spec to define one of those bits for something else.

Which would mean that booting old kernels on new FW which defines those reserved bits would cause that warning to fire erroneously.

So then we probably don't need it at all or we need to check implemented BGRT version of the FW running to know which bits are defined by the spec and which are reserved...

It still makes sense to have the error message because the kernel literally does not know what the firmware is trying to achieve by setting those bits.

But I agree with Josh that for the specific case of "reserved bits", FW_BUG is wrong, because if in some future version of the spec those bits get used, seeing,

"[Firmware Bug]: Ignoring BGRT: reserved bits are non-zero 0x3"

is going to confuse the hell outta any firmware engineers, since it's not the firmware that's buggy, it's just that the kernel lacks support.

This discussion should definitely be summarised in printk.h.

However, other error messages in efi-bgrt.c probably do want to be sprinkled with FW_* if they represent things that should never happen ever.

Quoted 2 lines

Also, does the spec really say that reserved bits must be zero? Or it doesn't specify their value?

" 1-byte status field indicating current status about the table.
Bits[7:1] = Reserved (must be zero)
Bit [0] = Displayed. A one indicates the boot image graphic is displayed. "

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#10 lore raw
In reply to a message not in the archive
Quoted 17 lines · Matt Fleming
Quoted 11 lines · Borislav Petkov
Quoted 3 lines · Josh Triplett

Definitely not FW_BUG. The field is reserved *now*; it would be legitimate for a new version of the BGRT spec to define one of those bits for something else.

Which would mean that booting old kernels on new FW which defines those reserved bits would cause that warning to fire erroneously.

So then we probably don't need it at all or we need to check implemented BGRT version of the FW running to know which bits are defined by the spec and which are reserved...

It still makes sense to have the error message because the kernel literally does not know what the firmware is trying to achieve by setting those bits.

Quoted 8 lines

But I agree with Josh that for the specific case of "reserved bits", FW_BUG is wrong, because if in some future version of the spec those bits get used, seeing,

"[Firmware Bug]: Ignoring BGRT: reserved bits are non-zero 0x3"

is going to confuse the hell outta any firmware engineers, since it's not the firmware that's buggy, it's just that the kernel lacks support.

Right. Same reason we shouldn't use FW_BUG for bgrt_tab->version != 1 or bgrt_tab->image_type != 0 .

Quoted 5 lines

This discussion should definitely be summarised in printk.h.

However, other error messages in efi-bgrt.c probably do want to be sprinkled with FW_* if they represent things that should never happen ever.

I think the length check and null pointer check would fall in that category.

- Josh Triplett

#11 lore raw
In reply to a message not in the archive
Quoted 9 lines · Matt Fleming

It still makes sense to have the error message because the kernel literally does not know what the firmware is trying to achieve by setting those bits.

But I agree with Josh that for the specific case of "reserved bits", FW_BUG is wrong, because if in some future version of the spec those bits get used, seeing,

"[Firmware Bug]: Ignoring BGRT: reserved bits are non-zero 0x3"

I still don't see what that message brings if some kernel complains that some bits are !0 then. Are they valid bits which the kernel doesn't know about or are they erroneously set and reserved. This, IMHO, is confusing because the error message is not correct in all cases.

Thus my suggestion to either check the spec version before looking at the bits or find out in some other way which bits are defined and which are reserved and warn only about the reserved ones which are 1b.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#12 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 9 lines · Matt Fleming

It still makes sense to have the error message because the kernel literally does not know what the firmware is trying to achieve by setting those bits.

But I agree with Josh that for the specific case of "reserved bits", FW_BUG is wrong, because if in some future version of the spec those bits get used, seeing,

"[Firmware Bug]: Ignoring BGRT: reserved bits are non-zero 0x3"

Quoted 8 lines

I still don't see what that message brings if some kernel complains that some bits are !0 then. Are they valid bits which the kernel doesn't know about or are they erroneously set and reserved. This, IMHO, is confusing because the error message is not correct in all cases.

Thus my suggestion to either check the spec version before looking at the bits or find out in some other way which bits are defined and which are reserved and warn only about the reserved ones which are 1b.

The version is already checked *before* the status bits: if the version is not 1, the kernel stops there and ignores the BGRT, before printing a message about status.

- Josh Triplett

#15 lore raw
In reply to a message not in the archive

Hi Matt!

The patch works for me against linux 4.0.6. I no longer see the message in dmesg with the BIOS option set to "Auto". I assume this is expected? It will only be displayed if I build it with a debug flag, right?
https://www.kernel.org/doc/local/pr_debug.txt

Quoted 50 lines · Matt Fleming

From: Matt Fleming <[email protected]>

It's totally legitimate, per the ACPI spec, for the firmware to set the BGRT 'status' field to zero to indicate that the BGRT image isn't being displayed, and we shouldn't be printing an error message in that case because it's just noise for users. So swap pr_err() for pr_debug().

However, Josh points that out it still makes sense to test the validity of the upper 7 bits of the 'status' field, since they're marked as "reserved" in the spec and must be zero. If firmware violates this it really *is* an error.

Cc Josh Triplett <[email protected]>
Cc Matthew Garrett <[email protected]>

---

Tom, if you could test out this patch that would be really helpful. I'll take this one through the EFI git repo.

 arch/x86/platform/efi/efi-bgrt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/platform/efi/efi-bgrt.c +7 -3
index d7f997f7c26d..ea48449b2e63 100644
@@ -50,11 +50,16 @@ void __init efi_bgrt_init(void)
                       bgrt_tab->version);
                return;
        }
-       if (bgrt_tab->status != 1) {
-               pr_err("Ignoring BGRT: invalid status %u (expected 1)\n",
+       if (bgrt_tab->status & 0xfe) {
+               pr_err("Ignoring BGRT: reserved status bits are non-zero %u\n",
                       bgrt_tab->status);
                return;
        }
+       if (bgrt_tab->status != 1) {
+               pr_debug("Ignoring BGRT: invalid status %u (expected 1)\n",
+                        bgrt_tab->status);
+               return;
+       }
        if (bgrt_tab->image_type != 0) {
                pr_err("Ignoring BGRT: invalid image type %u (expected 0)\n",
                       bgrt_tab->image_type);
--

2.1.0

#13 lore raw
In reply to [email protected]
Quoted 17 lines · Josh Triplett
Quoted 16 lines · Borislav Petkov
Quoted 9 lines · Matt Fleming

It still makes sense to have the error message because the kernel literally does not know what the firmware is trying to achieve by setting those bits.

But I agree with Josh that for the specific case of "reserved bits", FW_BUG is wrong, because if in some future version of the spec those bits get used, seeing,

"[Firmware Bug]: Ignoring BGRT: reserved bits are non-zero 0x3"

I still don't see what that message brings if some kernel complains that some bits are !0 then. Are they valid bits which the kernel doesn't know about or are they erroneously set and reserved. This, IMHO, is confusing because the error message is not correct in all cases.

Quoted 7 lines
Quoted 3 lines

Thus my suggestion to either check the spec version before looking at the bits or find out in some other way which bits are defined and which are reserved and warn only about the reserved ones which are 1b.

The version is already checked *before* the status bits: if the version is not 1, the kernel stops there and ignores the BGRT, before printing a message about status.

If we're performing version[1] checks then I think it's fair game to use FW_BUG, since these bits are reserved for that version.

[1] Note the version of the BGRT table is checked, not the ACPI spec version, and it's not clear which would get a bump if new bits were defined for the 'status' field. Historically, new bits have been added to the EFI memory map without bumping the expected "memory descriptor" version - a spec version update was considered to be sufficient (see EFI_MEMORY_RO).

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#16 lore raw
In reply to Tom Yan
Quoted 7 lines · Tom Yan

Hi Matt!

The patch works for me against linux 4.0.6. I no longer see the message in dmesg with the BIOS option set to "Auto". I assume this is expected? It will only be displayed if I build it with a debug flag, right?
https://www.kernel.org/doc/local/pr_debug.txt

Right, that is the expected outcome but it's always good to check that I didn't somehow goof up the patch.

Thanks for testing!

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center