Skip to contentSkip to conversation

drm/amdgpu/display: fix dmub invalid register read

PATCH In review Thomas Lambertz 3 participants 5 messages Mar 23, 2021 – Mar 25, 2021

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

PATCH 1/1 drm/amdgpu/display: fix dmub invalid register read

DMCUB_SCRATCH_0 sometimes contains 0xdeadbeef during initialization. If this is detected, return 0 instead. This prevents wrong bit-flags from being read.

The main impact of this bug is in the status check loop in dmub_srv_wait_for_auto_load. As it is waiting for the device to become ready, returning too early leads to a race condition. It is usually won on first boot, but lost when laptop resumes from sleep, breaking screen brightness control.

This issue was always present, but previously mitigated by the fact that the full register was compared to the wanted value. Currently, only the bottom two bits are tested, which are also set in 0xdeadbeef, thus returning readiness to early.

Fixes 5fe6b98ae00d ("drm/amd/display: Update dmub code")
---
 drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c | 8 +++++++-
 drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c +7 -1
index 8e8e65fa83c0..d6fcae182f68 100644
@@ -323,8 +323,14 @@ uint32_t dmub_dcn20_get_gpint_response(struct dmub_srv *dmub)
 union dmub_fw_boot_status dmub_dcn20_get_fw_boot_status(struct dmub_srv *dmub)
 {
 	union dmub_fw_boot_status status;
+	uint32_t value;
+
+	value = REG_READ(DMCUB_SCRATCH0);
+	if (value == DMCUB_SCRATCH0_INVALID)
+		status.all = 0;
+	else
+		status.all = value;
 
-	status.all = REG_READ(DMCUB_SCRATCH0);
 	return status;
 }
 
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +2 -0
index a62be9c0652e..9557e76cf5d4 100644
@@ -154,6 +154,8 @@ struct dmub_srv_common_regs {
 
 extern const struct dmub_srv_common_regs dmub_srv_dcn20_regs;
 
+#define DMCUB_SCRATCH0_INVALID 0xdeadbeef
+
 /* Hardware functions. */
 
 void dmub_dcn20_init(struct dmub_srv *dmub);

--
2.31.0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#1 lore raw
Quoted 11 lines · Thomas Lambertz

DMCUB_SCRATCH_0 sometimes contains 0xdeadbeef during initialization. If this is detected, return 0 instead. This prevents wrong bit-flags from being read.

The main impact of this bug is in the status check loop in dmub_srv_wait_for_auto_load. As it is waiting for the device to become ready, returning too early leads to a race condition. It is usually won on first boot, but lost when laptop resumes from sleep, breaking screen brightness control.

Quoted 6 lines

This issue was always present, but previously mitigated by the fact that the full register was compared to the wanted value. Currently, only the bottom two bits are tested, which are also set in 0xdeadbeef, thus returning readiness to early.

Fixes 5fe6b98ae00d ("drm/amd/display: Update dmub code")

Harry, Leo, Rodrigo, any ideas?

Alex

Quoted 40 lines
---
 drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c | 8 +++++++-
 drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c +7 -1
index 8e8e65fa83c0..d6fcae182f68 100644
@@ -323,8 +323,14 @@ uint32_t dmub_dcn20_get_gpint_response(struct dmub_srv *dmub)
 union dmub_fw_boot_status dmub_dcn20_get_fw_boot_status(struct dmub_srv *dmub)
 {
        union dmub_fw_boot_status status;
+       uint32_t value;
+
+       value = REG_READ(DMCUB_SCRATCH0);
+       if (value == DMCUB_SCRATCH0_INVALID)
+               status.all = 0;
+       else
+               status.all = value;
 
-       status.all = REG_READ(DMCUB_SCRATCH0);
        return status;
 }
 
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +2 -1
index a62be9c0652e..9557e76cf5d4 100644
@@ -154,6 +154,8 @@ struct dmub_srv_common_regs {
 
 extern const struct dmub_srv_common_regs dmub_srv_dcn20_regs;
 
+#define DMCUB_SCRATCH0_INVALID 0xdeadbeef
+
 /* Hardware functions. */
 
 void dmub_dcn20_init(struct dmub_srv *dmub);
--
Quoted 5 lines

2.31.0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer
#2 lore raw

+Nick, Bhawan

Quoted 12 lines · Alex Deucher
Quoted 11 lines · Thomas Lambertz

DMCUB_SCRATCH_0 sometimes contains 0xdeadbeef during initialization. If this is detected, return 0 instead. This prevents wrong bit-flags from being read.

The main impact of this bug is in the status check loop in dmub_srv_wait_for_auto_load. As it is waiting for the device to become ready, returning too early leads to a race condition. It is usually won on first boot, but lost when laptop resumes from sleep, breaking screen brightness control.

Quoted 9 lines
Quoted 6 lines

This issue was always present, but previously mitigated by the fact that the full register was compared to the wanted value. Currently, only the bottom two bits are tested, which are also set in 0xdeadbeef, thus returning readiness to early.

Fixes 5fe6b98ae00d ("drm/amd/display: Update dmub code")
Bug https://gitlab.freedesktop.org/drm/amd/-/issues/1518>> Harry, Leo, Rodrigo, any ideas?

When I checked with our DMUB experts yesterday they said they'd never expect to see 0xdeadbeef in SCRATCH0.

That said based on Thomas's test it does look like we're getting deadbeef at resume so I'm almost inclined to ACK this patch. It doesn't really do any harm.

Harry

Quoted 40 lines

Alex

Quoted 38 lines
---
  drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c | 8 +++++++-
  drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h | 2 ++
  2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c +7 -1
index 8e8e65fa83c0..d6fcae182f68 100644
@@ -323,8 +323,14 @@ uint32_t dmub_dcn20_get_gpint_response(struct dmub_srv *dmub)
  union dmub_fw_boot_status dmub_dcn20_get_fw_boot_status(struct dmub_srv *dmub)
  {
         union dmub_fw_boot_status status;
+       uint32_t value;
+
+       value = REG_READ(DMCUB_SCRATCH0);
+       if (value == DMCUB_SCRATCH0_INVALID)
+               status.all = 0;
+       else
+               status.all = value;
 
-       status.all = REG_READ(DMCUB_SCRATCH0);
         return status;
  }
 
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +2 -0
index a62be9c0652e..9557e76cf5d4 100644
@@ -154,6 +154,8 @@ struct dmub_srv_common_regs {
 
  extern const struct dmub_srv_common_regs dmub_srv_dcn20_regs;
 
+#define DMCUB_SCRATCH0_INVALID 0xdeadbeef
+
  /* Hardware functions. */
 
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +0 -1
  void dmub_dcn20_init(struct dmub_srv *dmub);
--

2.31.0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx>

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer Reviewed-by
#3 lore raw
Quoted 20 lines · Harry Wentland

+Nick, Bhawan

Quoted 17 lines · Alex Deucher
Quoted 16 lines · Thomas Lambertz

DMCUB_SCRATCH_0 sometimes contains 0xdeadbeef during initialization. If this is detected, return 0 instead. This prevents wrong bit-flags from being read.

The main impact of this bug is in the status check loop in dmub_srv_wait_for_auto_load. As it is waiting for the device to become ready, returning too early leads to a race condition. It is usually won on first boot, but lost when laptop resumes from sleep, breaking screen brightness control.

This issue was always present, but previously mitigated by the fact that the full register was compared to the wanted value. Currently, only the bottom two bits are tested, which are also set in 0xdeadbeef, thus returning readiness to early.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Fixes 5fe6b98ae00d ("drm/amd/display: Update dmub code")
Bug https://gitlab.freedesktop.org/drm/amd/-/issues/1518 Harry, Leo, Rodrigo, any ideas?

When I checked with our DMUB experts yesterday they said they'd never expect to see 0xdeadbeef in SCRATCH0.

That said based on Thomas's test it does look like we're getting deadbeef at resume so I'm almost inclined to ACK this patch. It doesn't really do any harm.

Apparently an older version of the renoir_dmcub (and likely other versions) had a 0xdeadbeef write to SCRATCH0. In order to support these older FW this patch is

I recommend updating to the latest FW from linux-firmware if any other issues are observed.

Harry

Quoted 43 lines

Harry

Quoted 41 lines

Alex

Quoted 39 lines

---
  drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c | 8 +++++++- drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h | 2 ++

  2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c +7 -1
index 8e8e65fa83c0..d6fcae182f68 100644
@@ -323,8 +323,14 @@ uint32_t dmub_dcn20_get_gpint_response(struct 
 dmub_srv *dmub)
   union dmub_fw_boot_status dmub_dcn20_get_fw_boot_status(struct dmub_srv *dmub)
   {
          union dmub_fw_boot_status status;
+       uint32_t value;
+
+       value = REG_READ(DMCUB_SCRATCH0);
+       if (value == DMCUB_SCRATCH0_INVALID)
+               status.all = 0;
+       else
+               status.all = value;
 
-       status.all = REG_READ(DMCUB_SCRATCH0);
          return status;
   }
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +2 -0
index a62be9c0652e..9557e76cf5d4 100644
@@ -154,6 +154,8 @@ struct dmub_srv_common_regs {
 
   extern const struct dmub_srv_common_regs dmub_srv_dcn20_regs;
 
+#define DMCUB_SCRATCH0_INVALID 0xdeadbeef
+
   /* Hardware functions. */
 
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +0 -0
   void dmub_dcn20_init(struct dmub_srv *dmub);
Signature · 5 lines
2.31.0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
Quoted 30 lines · Harry Wentland
Quoted 27 lines · Harry Wentland

+Nick, Bhawan

Quoted 12 lines · Alex Deucher
Quoted 11 lines · Thomas Lambertz

DMCUB_SCRATCH_0 sometimes contains 0xdeadbeef during initialization. If this is detected, return 0 instead. This prevents wrong bit-flags from being read.

The main impact of this bug is in the status check loop in dmub_srv_wait_for_auto_load. As it is waiting for the device to become ready, returning too early leads to a race condition. It is usually won on first boot, but lost when laptop resumes from sleep, breaking screen brightness control.

Quoted 9 lines
Quoted 6 lines

This issue was always present, but previously mitigated by the fact that the full register was compared to the wanted value. Currently, only the bottom two bits are tested, which are also set in 0xdeadbeef, thus returning readiness to early.

Fixes 5fe6b98ae00d ("drm/amd/display: Update dmub code")
Bug https://gitlab.freedesktop.org/drm/amd/-/issues/1518 Harry, Leo, Rodrigo, any ideas?

When I checked with our DMUB experts yesterday they said they'd never expect to see 0xdeadbeef in SCRATCH0.

Quoted 7 lines
Quoted 2 lines

That said based on Thomas's test it does look like we're getting deadbeef at resume so I'm almost inclined to ACK this patch. It doesn't really do any harm.

Apparently an older version of the renoir_dmcub (and likely other versions) had a 0xdeadbeef write to SCRATCH0. In order to support these older FW this patch is

I recommend updating to the latest FW from linux-firmware if any other issues are observed.

Thank you for the quick triage!

I just tried the newest firmware from git, and have some good and some bad news. The 0xdeadbeef issue is fixed, and initialization is way faster on the newer firmware.

But the screen brightness issue has been reintroduced. The cause is a different one, and I am not sure how to debug it further.

To test, I booted the same kernel (v5.12-RC4 with my patch applied) with two versions of linux-firmware. The old one worked, the new one shows the same issue as the old without the patch.

Relevant dmesg parts:

a) NEW, 24/03/2021 (3f026a2)

[    6.350233] [drm] Display Core initialized with v3.2.122!
[    6.350256] DMCUB_SCRATCH0: 0x0
[    6.350359] DMCUB_SCRATCH0: 0x0
[    6.350461] DMCUB_SCRATCH0: 0x0
[    6.350563] DMCUB_SCRATCH0: 0x0
[    6.350666] DMCUB_SCRATCH0: 0x3
[    6.350883] [drm] DMUB hardware initialized: version=0x01020003
.... suspend, resume ....
[   59.709695] DMCUB_SCRATCH0: 0x0
     repeats 6 more times
[   59.710432] DMCUB_SCRATCH0: 0x3
[   59.710438] [drm] DMUB hardware initialized: version=0x01020003

b) OLD, 15/03/2021 (3568f96)

[    7.805468] [drm] Display Core initialized with v3.2.122!
[    7.805496] DMCUB_SCRATCH0: 0x0
[    7.805598] DMCUB_SCRATCH0: 0x0
[    7.805700] DMCUB_SCRATCH0: 0x0
[    7.805801] DMCUB_SCRATCH0: 0x0
[    7.805903] DMCUB_SCRATCH0: 0x1
     repeats 115 more times
[    7.817841] DMCUB_SCRATCH0: 0x1
[    7.817944] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818047] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818149] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818251] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818353] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818454] DMCUB_SCRATCH0: 0x3
[    7.818676] [drm] DMUB hardware initialized: version=0x01000000
.... suspend, resume ....
[   89.818383] DMCUB_SCRATCH0: 0x0
[   89.818493] DMCUB_SCRATCH0: 0x0
[   89.818601] DMCUB_SCRATCH0: 0x0
[   89.818708] DMCUB_SCRATCH0: 0x0
[   89.818811] DMCUB_SCRATCH0: 0x0
[   89.818918] DMCUB_SCRATCH0: 0x0
[   89.819025] DMCUB_SCRATCH0: 0x1
     repeats 112 more times
[   89.831007] DMCUB_SCRATCH0: 0x1
[   89.831110] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831218] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831325] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831428] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831535] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831643] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831745] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831853] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831956] DMCUB_SCRATCH0: 0x3
[   89.832299] [drm] DMUB hardware initialized: version=0x01000000

Thomas

Quoted 57 lines

Harry

Quoted 53 lines

Harry

Quoted 40 lines

Alex

Quoted 38 lines

---
  drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c | 8 +++++++- drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h | 2 ++

  2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c +7 -1
index 8e8e65fa83c0..d6fcae182f68 100644
@@ -323,8 +323,14 @@ uint32_t dmub_dcn20_get_gpint_response(struct dmub_srv *dmub)
   union dmub_fw_boot_status dmub_dcn20_get_fw_boot_status(struct dmub_srv *dmub)
   {
          union dmub_fw_boot_status status;
+       uint32_t value;
+
+       value = REG_READ(DMCUB_SCRATCH0);
+       if (value == DMCUB_SCRATCH0_INVALID)
+               status.all = 0;
+       else
+               status.all = value;
 
-       status.all = REG_READ(DMCUB_SCRATCH0);
          return status;
   }
 
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +2 -0
index a62be9c0652e..9557e76cf5d4 100644
@@ -154,6 +154,8 @@ struct dmub_srv_common_regs {
 
   extern const struct dmub_srv_common_regs dmub_srv_dcn20_regs;
 
+#define DMCUB_SCRATCH0_INVALID 0xdeadbeef
+
   /* Hardware functions. */
 
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h +0 -0
   void dmub_dcn20_init(struct dmub_srv *dmub);

--
2.31.0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx