Skip to contentSkip to conversation

hw/ide/core.c: fix handling of unsupported commands

PATCH In review Mateusz Albecki 4 participants 9 messages Apr 16, 2023 – Jun 1, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/ide/core.c: fix handling of unsupported commands

The patch was developed during the debug for the UEFI SCT issue reported in
https://bugzilla.tianocore.org/show_bug.cgi?id=4016. After fixing the issue in EDK2 the test was still failing on qemu since qemu wouldn't return abort and instead we would get a command timeout. Additionally qemu also has another bug in that it reports support for storage security commands which it doesn't support(will file a bug).

Tests:
- tested against UEFI SCT test mentioned in bugzilla and it is passing.
- able to read/write files on ahci controller from UEFI.

Mateusz Albecki (1):
hw/ide/core.c: fix handling of unsupported commands

 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/1 hw/ide/core.c: fix handling of unsupported commands

From: Mateusz Albecki <[email protected]>

Current code will not call ide_cmd_done when aborting the unsupported command which will lead to the command timeout on the driver side instead of getting a D2H FIS with ABRT indication. This can lead to problems on the driver side as the spec mandates that device should return a D2H FIS with ABRT bit set in ERR register(from SATA 3.1 section 16.3.3.8.6)

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +1 -0
index 45d14a25e9..d7027bbd4d 100644
@@ -2146,6 +2146,7 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val)
 
     if (!ide_cmd_permitted(s, val)) {
         ide_abort_command(s);
+        ide_cmd_done(s);
         ide_bus_set_irq(s->bus);
         return;
     }
Signature · 1 line
2.40.0
#2 lore raw
Quoted 27 lines · Mateusz Albecki

From: Mateusz Albecki <[email protected]>

Current code will not call ide_cmd_done when aborting the unsupported command which will lead to the command timeout on the driver side instead of getting a D2H FIS with ABRT indication. This can lead to problems on the driver side as the spec mandates that device should return a D2H FIS with ABRT bit set in ERR register(from SATA 3.1 section 16.3.3.8.6)

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +1 -1
index 45d14a25e9..d7027bbd4d 100644
@@ -2146,6 +2146,7 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val)
 
     if (!ide_cmd_permitted(s, val)) {
         ide_abort_command(s);
+        ide_cmd_done(s);
         ide_bus_set_irq(s->bus);
         return;
     }
--
Quoted 2 lines

2.40.0

I recently noticed that Niklas Cassel sent a patch to fix unsupported command handling:
https://lists.gnu.org/archive/html/qemu-devel/2023-04/msg05552.html

I suspect that his approach is the more technically correct one and that calling ide_cmd_done here is a heavy cudgel that may have unintended consequences. Am I mistaken?
Can you check that Niklas's patch solves your issue? I think you're both solving the same problem. I've CC'd him on this patch as well.

--js

#3 lore raw

Certainly seems like my patch is wrong as it will make the abort path execute ide_cmd_done twice. During debug I came to the conclusion that ide_cmd_done is not called at all as I was getting timeouts on the driver side while waiting for D2H FIS. I am still not sure how I was getting this behavior if the problem was actually with setting correct error bits. Even so I think it can be safely assumed that Niklas' change will solve the issue, I will try to verify it in a couple of days and if I see any problem I will come back to you.

Mateusz

Quoted 46 lines · John Snow
Quoted 6 lines · Mateusz Albecki

From: Mateusz Albecki <[email protected]>

Current code will not call ide_cmd_done when aborting the unsupported command which will lead to the command timeout on the driver side instead of getting a D2H FIS with ABRT indication. This can lead to problems on

the

Quoted 21 lines

driver side as the spec mandates that device should return a D2H FIS with ABRT bit set in ERR register(from SATA 3.1 section 16.3.3.8.6)

---
 hw/ide/core.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/core.c +1 -1
index 45d14a25e9..d7027bbd4d 100644
@@ -2146,6 +2146,7 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val)
 
     if (!ide_cmd_permitted(s, val)) {
         ide_abort_command(s);
+        ide_cmd_done(s);
         ide_bus_set_irq(s->bus);
         return;
     }
--
Quoted 2 lines

2.40.0

I recently noticed that Niklas Cassel sent a patch to fix unsupported command handling:
https://lists.gnu.org/archive/html/qemu-devel/2023-04/msg05552.html

I suspect that his approach is the more technically correct one and that calling ide_cmd_done here is a heavy cudgel that may have unintended consequences. Am I mistaken?
Can you check that Niklas's patch solves your issue? I think you're both solving the same problem. I've CC'd him on this patch as well.

--js

#4 lore raw
Quoted 2 lines · Mateusz Albecki

Certainly seems like my patch is wrong as it will make the abort path

execute ide_cmd_done twice. During debug I came to the conclusion that ide_cmd_done is not called at all as I was getting timeouts on the driver side while waiting for D2H FIS. I am still not sure how I was getting this behavior if the problem was actually with setting correct error bits. Even so I think it can be safely assumed that Niklas' change will solve the issue, I will try to verify it in a couple of days and if I see any problem I will come back to you.

Quoted 2 lines

Mateusz

Great, thanks :)

I'm waiting to hear back from Niklas, but I'm hoping to take their patches this cycle as I think they look quite good.

Thank you for submitting bug reports and patches :~)

--js

#5 lore raw
Quoted 12 lines · John Snow
Quoted 2 lines · On Mon, May 22, 2023 at 5:16???PM Mateusz Albecki…

Certainly seems like my patch is wrong as it will make the abort path

execute ide_cmd_done twice. During debug I came to the conclusion that ide_cmd_done is not called at all as I was getting timeouts on the driver side while waiting for D2H FIS. I am still not sure how I was getting this behavior if the problem was actually with setting correct error bits. Even so I think it can be safely assumed that Niklas' change will solve the issue, I will try to verify it in a couple of days and if I see any problem I will come back to you.

Quoted 1 line
Quoted 6 lines
Quoted 1 line

Mateusz

Great, thanks :)

I'm waiting to hear back from Niklas, but I'm hoping to take their patches this cycle as I think they look quite good.

Hello John,

Unfortunately, I've noticed an increase in boot time during the initial SeaBIOS part of QEMU with my changes.

Will need to debug to see which change is causing this.

I'm at a conference this week, so it might take until next week until I have time to figure out why this is happening.

So unfortunately, I think we need to hold off with my series for now.

If Mateusz can confirm that
https://lists.gnu.org/archive/html/qemu-devel/2023-04/msg05552.html
solves his issue, and that it does not cause an increased boot time for SeaBIOS, perhaps that patch could be picked up separately.

Kind regards,
Niklas

#6 lore raw
Quoted 30 lines · Niklas Cassel
Quoted 1 line · John Snow

On Mon, May 22, 2023 at 5:16???PM Mateusz Albecki <

[email protected]>

Quoted 6 lines
Quoted 2 lines · wrote:

Certainly seems like my patch is wrong as it will make the abort path

execute ide_cmd_done twice. During debug I came to the conclusion that ide_cmd_done is not called at all as I was getting timeouts on the driver side while waiting for D2H FIS. I am still not sure how I was getting

this

Quoted 1 line

behavior if the problem was actually with setting correct error bits.

Even

Quoted 2 lines

so I think it can be safely assumed that Niklas' change will solve the issue, I will try to verify it in a couple of days and if I see any

problem

Quoted 7 lines

I will come back to you.

Quoted 2 lines

Mateusz

Great, thanks :)

I'm waiting to hear back from Niklas, but I'm hoping to take their

patches

Quoted 1 line

this cycle as I think they look quite good.

Hello John,

Unfortunately, I've noticed an increase in boot time during the initial SeaBIOS part of QEMU with my changes.

Quoted 8 lines

Will need to debug to see which change is causing this.

I'm at a conference this week, so it might take until next week until I have time to figure out why this is happening.

So unfortunately, I think we need to hold off with my series for now.

Shame. Feel free to resend it once you've isolated the problem and I'll try to fast-track it, since it'd be nice to have my more embarrassing mistakes for NCQ fixed :)

(If I become hard to reach, please ping me with a direct, non-patch email so it bubbles up to the top of my inbox.)

((...by the way, what are you working on? What motivates the interest in AHCI/SATA now? Can you say?))

Quoted 10 lines

If Mateusz can confirm that
https://lists.gnu.org/archive/html/qemu-devel/2023-04/msg05552.html
solves his issue, and that it does not cause an increased boot time for SeaBIOS, perhaps that patch could be picked up separately.

Kind regards,
Niklas

#7 lore raw
Quoted 45 lines · John Snow
Quoted 30 lines · Niklas Cassel
Quoted 1 line · John Snow

On Mon, May 22, 2023 at 5:16???PM Mateusz Albecki <

[email protected]>

Quoted 6 lines
Quoted 2 lines · wrote:

Certainly seems like my patch is wrong as it will make the abort path

execute ide_cmd_done twice. During debug I came to the conclusion that ide_cmd_done is not called at all as I was getting timeouts on the driver side while waiting for D2H FIS. I am still not sure how I was getting

this

Quoted 1 line

behavior if the problem was actually with setting correct error bits.

Even

Quoted 2 lines

so I think it can be safely assumed that Niklas' change will solve the issue, I will try to verify it in a couple of days and if I see any

problem

Quoted 7 lines

I will come back to you.

Quoted 2 lines

Mateusz

Great, thanks :)

I'm waiting to hear back from Niklas, but I'm hoping to take their

patches

Quoted 1 line

this cycle as I think they look quite good.

Hello John,

Unfortunately, I've noticed an increase in boot time during the initial SeaBIOS part of QEMU with my changes.

Quoted 8 lines

Will need to debug to see which change is causing this.

I'm at a conference this week, so it might take until next week until I have time to figure out why this is happening.

So unfortunately, I think we need to hold off with my series for now.

Shame. Feel free to resend it once you've isolated the problem and I'll try to fast-track it, since it'd be nice to have my more embarrassing mistakes for NCQ fixed :)

Quoted 5 lines

(If I become hard to reach, please ping me with a direct, non-patch email so it bubbles up to the top of my inbox.)

((...by the way, what are you working on? What motivates the interest in AHCI/SATA now? Can you say?))

Hello John,

It is simple, Western Digital is still selling a lot of SATA drives :)

And we used QEMU to verify some of the support for Command Duration Limits in linux:
https://lore.kernel.org/linux-scsi/[email protected]/

Right now, I don't intend to upstream all my hacky patches to QEMU, just the things that might be useful for everyone, e.g. GPL and NCQ error log (and possibly Sense Data Reporting feature set support, and NCQ autosense).

Kind regards,
Niklas

#8 lore raw
Quoted 55 lines · Niklas Cassel
Quoted 8 lines · John Snow
Quoted 6 lines · Niklas Cassel
Quoted 1 line · John Snow

On Mon, May 22, 2023 at 5:16???PM Mateusz Albecki <

[email protected]>

Quoted 3 lines
Quoted 2 lines · wrote:

Certainly seems like my patch is wrong as it will make the abort

path

Quoted 1 line
Quoted 1 line
Quoted 1 line

execute ide_cmd_done twice. During debug I came to the conclusion

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

ide_cmd_done is not called at all as I was getting timeouts on the

driver

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

side while waiting for D2H FIS. I am still not sure how I was getting

this

Quoted 1 line

behavior if the problem was actually with setting correct error bits.

Even

Quoted 1 line

so I think it can be safely assumed that Niklas' change will solve

the

Quoted 19 lines
Quoted 19 lines
Quoted 1 line

issue, I will try to verify it in a couple of days and if I see any

problem

Quoted 7 lines

I will come back to you.

Quoted 2 lines

Mateusz

Great, thanks :)

I'm waiting to hear back from Niklas, but I'm hoping to take their

patches

Quoted 1 line

this cycle as I think they look quite good.

Hello John,

Unfortunately, I've noticed an increase in boot time during the initial SeaBIOS part of QEMU with my changes.

Will need to debug to see which change is causing this.

Quoted 8 lines
Quoted 6 lines

I'm at a conference this week, so it might take until next week until I have time to figure out why this is happening.

So unfortunately, I think we need to hold off with my series for now.

Shame. Feel free to resend it once you've isolated the problem and I'll

try

Quoted 1 line

to fast-track it, since it'd be nice to have my more embarrassing

mistakes

Quoted 5 lines

for NCQ fixed :)

(If I become hard to reach, please ping me with a direct, non-patch email so it bubbles up to the top of my inbox.)

Quoted 7 lines
Quoted 2 lines

((...by the way, what are you working on? What motivates the interest in AHCI/SATA now? Can you say?))

Hello John,

It is simple, Western Digital is still selling a lot of SATA drives :)

Haha! Fair enough. I built my first computer without a single AHCI device in it last year, but you can't say the same for my Synology downstairs in my networking closet :)

Quoted 3 lines

And we used QEMU to verify some of the support for Command Duration Limits in linux:
https://lore.kernel.org/linux-scsi/[email protected]/

Ah-ha, that helps explain it :)

If you find other problems, even if you don't intend to fix them, please file a gitlab issue to document that there's work that needs done.

Quoted 6 lines

Right now, I don't intend to upstream all my hacky patches to QEMU, just the things that might be useful for everyone, e.g. GPL and NCQ error log
(and possibly Sense Data Reporting feature set support, and NCQ autosense).

Got it, thanks! I'll try to set aside time to look over your patches "soon", I'd like then for 8.1. If I go quiet, *please* ping me.

Quoted 4 lines

Kind regards,
Niklas