Skip to contentSkip to conversation

crypto/ccp: Fixes for PCI IDE

PATCH In review Alexey Kardashevskiy 3 participants 9 messages Jan 23 – Jan 29

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

cover crypto/ccp: Fixes for PCI IDE

A couple of fixes for bugs discovered recently as we got more of these devices and tested more configurations with multiple devices on same and different bridges.

This is based on sha1
0499add8efd7 Paolo Bonzini Merge tag 'kvm-x86-fixes-6.19-rc1' of htts://github.com/kvm-x86/linux into HEAD

Please comment. Thanks.

Alexey Kardashevskiy (2):
crypto/ccp: Use PCI bridge defaults for IDE crypto/ccp: Allow multiple streams on the same root bridge

 drivers/crypto/ccp/sev-dev-tsm.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/2 crypto/ccp: Use PCI bridge defaults for IDE

The current number of streams in AMD TSM is 1 which is too little, the core uses 255. Also, even if the module parameter is increased, calling pci_ide_set_nr_streams() second time triggers WARN_ON.

Simplify the code by sticking to the PCI core defaults.

Fixes 4be423572da1 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")
---
 drivers/crypto/ccp/sev-dev-tsm.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/crypto/ccp/sev-dev-tsm.c +0 -12
index ea29cd5d0ff9..7407b77c2ef2 100644
@@ -19,12 +19,6 @@
 
 MODULE_IMPORT_NS("PCI_IDE");
 
-#define TIO_DEFAULT_NR_IDE_STREAMS	1
-
-static uint nr_ide_streams = TIO_DEFAULT_NR_IDE_STREAMS;
-module_param_named(ide_nr, nr_ide_streams, uint, 0644);
-MODULE_PARM_DESC(ide_nr, "Set the maximum number of IDE streams per PHB");
-
 #define dev_to_sp(dev)		((struct sp_device *)dev_get_drvdata(dev))
 #define dev_to_psp(dev)		((struct psp_device *)(dev_to_sp(dev)->psp_data))
 #define dev_to_sev(dev)		((struct sev_device *)(dev_to_psp(dev)->sev_data))
@@ -193,7 +187,6 @@ static void streams_teardown(struct pci_ide **ide)
 static int stream_alloc(struct pci_dev *pdev, struct pci_ide **ide,
 			unsigned int tc)
 {
-	struct pci_dev *rp = pcie_find_root_port(pdev);
 	struct pci_ide *ide1;
 
 	if (ide[tc]) {
@@ -201,11 +194,6 @@ static int stream_alloc(struct pci_dev *pdev, struct pci_ide **ide,
 		return -EBUSY;
 	}
 
-	/* FIXME: find a better way */
-	if (nr_ide_streams != TIO_DEFAULT_NR_IDE_STREAMS)
-		pci_notice(pdev, "Enable non-default %d streams", nr_ide_streams);
-	pci_ide_set_nr_streams(to_pci_host_bridge(rp->bus->bridge), nr_ide_streams);
-
 	ide1 = pci_ide_stream_alloc(pdev);
 	if (!ide1)
 		return -EFAULT;
Signature · 1 line
2.52.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH kernel 1/2] crypto/ccp: Use PCI bridge defaults for IDE

Quoted 17 lines · Alexey Kardashevskiy

The current number of streams in AMD TSM is 1 which is too little, the core uses 255. Also, even if the module parameter is increased, calling pci_ide_set_nr_streams() second time triggers WARN_ON.

Simplify the code by sticking to the PCI core defaults.

Fixes 4be423572da1 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")
---
 drivers/crypto/ccp/sev-dev-tsm.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/crypto/ccp/sev-dev-tsm.c +0 -0
index ea29cd5d0ff9..7407b77c2ef2 100644

drivers/crypto/ccp/sev-dev-tsm.c line 27

Quoted 9 lines
drivers/crypto/ccp/sev-dev-tsm.c +0 -6
@@ -19,12 +19,6 @@
 
 MODULE_IMPORT_NS("PCI_IDE");
 
-#define TIO_DEFAULT_NR_IDE_STREAMS	1
-
-static uint nr_ide_streams = TIO_DEFAULT_NR_IDE_STREAMS;
-module_param_named(ide_nr, nr_ide_streams, uint, 0644);
-MODULE_PARM_DESC(ide_nr, "Set the maximum number of IDE streams per PHB");
-

Yes, happy to see any reduction in ABI surface, especially module parameters.

#3 lore raw

PATCH 2/2 crypto/ccp: Allow multiple streams on the same root bridge

In reply to Alexey Kardashevskiy

IDE stream IDs are responsibility of a platform and in some cases TSM allocates the numbers. AMD SEV TIO though leaves it to the host OS. Mistakenly stream ID is hard coded to be the same as a traffic class.

Use the host bridge stream index for a newly allocated stream ID.

Fixes 4be423572da1 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")
---
 drivers/crypto/ccp/sev-dev-tsm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/crypto/ccp/sev-dev-tsm.c +1 -2
index 7407b77c2ef2..40d02adaf3f6 100644
@@ -198,8 +198,7 @@ static int stream_alloc(struct pci_dev *pdev, struct pci_ide **ide,
 	if (!ide1)
 		return -EFAULT;
 
-	/* Blindly assign streamid=0 to TC=0, and so on */
-	ide1->stream_id = tc;
+	ide1->stream_id = ide1->host_bridge_stream;
 
 	ide[tc] = ide1;
 
Signature · 1 line
2.52.0
#4 lore raw

Re: [PATCH kernel 2/2] crypto/ccp: Allow multiple streams on the same root bridge

Quoted 3 lines · Alexey Kardashevskiy

IDE stream IDs are responsibility of a platform and in some cases TSM allocates the numbers. AMD SEV TIO though leaves it to the host OS. Mistakenly stream ID is hard coded to be the same as a traffic class.

I scratched my head at this comment, but now realize that you are saying the existing code used the local @tc, not that the hardware stream ID is in any way related to traffic class, right?

It would help to detail what the end user visible effects of this bug are. The TSM framework does not allow for multiple streams per PF, so I wonder what scenario is being fixed?

Lastly, are you expecting tsm.git#fixes to pick this up? I am assuming that this goes through crypto.git and tsm.git can just stay focused on core fixes.

#5 lore raw

Re: [PATCH kernel 2/2] crypto/ccp: Allow multiple streams on the same root bridge

Quoted 8 lines · On 24/1/26 09:59, [email protected] wrote:
Quoted 3 lines · Alexey Kardashevskiy

IDE stream IDs are responsibility of a platform and in some cases TSM allocates the numbers. AMD SEV TIO though leaves it to the host OS. Mistakenly stream ID is hard coded to be the same as a traffic class.

I scratched my head at this comment, but now realize that you are saying the existing code used the local @tc, not that the hardware stream ID is in any way related to traffic class, right?

When I did that in the first place, I also wanted to try different traffic classes so I just took a shortcut here.

Quoted 3 lines

It would help to detail what the end user visible effects of this bug are. The TSM framework does not allow for multiple streams per PF, so I wonder what scenario is being fixed?

There is no way in the current upstream code to specify this TC so the only visible effect is that 2 devices under the same bridge can work now, previously the second device would fail to allocate a stream.

Quoted 3 lines

Lastly, are you expecting tsm.git#fixes to pick this up? I am assuming that this goes through crypto.git and tsm.git can just stay focused on core fixes.

I was kinda hoping that Tom acks these (as he did) and you could take them. Thanks,

Signature · 1 line
Alexey
#6 lore raw

Re: [PATCH kernel 2/2] crypto/ccp: Allow multiple streams on the same root bridge

Quoted 22 lines · Alexey Kardashevskiy
Quoted 9 lines · On 24/1/26 09:59, [email protected] wrote:
Quoted 4 lines · Alexey Kardashevskiy

IDE stream IDs are responsibility of a platform and in some cases TSM allocates the numbers. AMD SEV TIO though leaves it to the host OS. Mistakenly stream ID is hard coded to be the same as a traffic class.

I scratched my head at this comment, but now realize that you are saying the existing code used the local @tc, not that the hardware stream ID is in any way related to traffic class, right?

When I did that in the first place, I also wanted to try different traffic classes so I just took a shortcut here.

Quoted 3 lines

It would help to detail what the end user visible effects of this bug are. The TSM framework does not allow for multiple streams per PF, so I wonder what scenario is being fixed?

There is no way in the current upstream code to specify this TC so the only visible effect is that 2 devices under the same bridge can work now, previously the second device would fail to allocate a stream.

Quoted 6 lines
Quoted 3 lines

Lastly, are you expecting tsm.git#fixes to pick this up? I am assuming that this goes through crypto.git and tsm.git can just stay focused on core fixes.

I was kinda hoping that Tom acks these (as he did) and you could take them. Thanks,

Ok, so can you refresh the changelog to call out the user visible effects? Something like:

---
With SEV-TIO the low-level TSM driver is responsible for allocating a Stream ID. The Stream ID needs to be unique within each IDE partner port. Fix the Stream ID selection to reuse the host bridge stream resource id which is a pool of 256 ids per host bridge on AMD platforms. Otherwise, only one device per-host bridge can establish Selective Stream IDE.
---

Send a v2, and I will pick it up.

author Acked-by
#7 lore raw

Re: [PATCH kernel 2/2] crypto/ccp: Allow multiple streams on the same root bridge

Quoted 42 lines · On 27/1/26 17:59, [email protected] wrote:
Quoted 22 lines · Alexey Kardashevskiy
Quoted 9 lines · On 24/1/26 09:59, [email protected] wrote:
Quoted 4 lines · Alexey Kardashevskiy

IDE stream IDs are responsibility of a platform and in some cases TSM allocates the numbers. AMD SEV TIO though leaves it to the host OS. Mistakenly stream ID is hard coded to be the same as a traffic class.

I scratched my head at this comment, but now realize that you are saying the existing code used the local @tc, not that the hardware stream ID is in any way related to traffic class, right?

When I did that in the first place, I also wanted to try different traffic classes so I just took a shortcut here.

Quoted 3 lines

It would help to detail what the end user visible effects of this bug are. The TSM framework does not allow for multiple streams per PF, so I wonder what scenario is being fixed?

There is no way in the current upstream code to specify this TC so the only visible effect is that 2 devices under the same bridge can work now, previously the second device would fail to allocate a stream.

Quoted 6 lines
Quoted 3 lines

Lastly, are you expecting tsm.git#fixes to pick this up? I am assuming that this goes through crypto.git and tsm.git can just stay focused on core fixes.

I was kinda hoping that Tom acks these (as he did) and you could take them. Thanks,

Ok, so can you refresh the changelog to call out the user visible effects? Something like:

---
With SEV-TIO the low-level TSM driver is responsible for allocating a Stream ID. The Stream ID needs to be unique within each IDE partner port. Fix the Stream ID selection to reuse the host bridge stream resource id which is a pool of 256 ids per host bridge on AMD platforms. Otherwise, only one device per-host bridge can establish Selective Stream IDE.
---

Quoted 1 line

Send a v2, and I will pick it up.

Please squash it in the v1, if possible.

thanks!

ps sorry missed that on time, I do suck at multitasking :(

Signature · 1 line
Alexey
maintainer Acked-by on the v1 series
#8 lore raw
In reply to Alexey Kardashevskiy
Quoted 10 lines · Alexey Kardashevskiy

A couple of fixes for bugs discovered recently as we got more of these devices and tested more configurations with multiple devices on same and different bridges.

This is based on sha1
0499add8efd7 Paolo Bonzini Merge tag 'kvm-x86-fixes-6.19-rc1' of htts://github.com/kvm-x86/linux into HEAD

Please comment. Thanks.

You might want to send a patch that adds you as a maintainer of the SEV TIO files/support, too.

Quoted 9 lines

Alexey Kardashevskiy (2):
crypto/ccp: Use PCI bridge defaults for IDE crypto/ccp: Allow multiple streams on the same root bridge

 drivers/crypto/ccp/sev-dev-tsm.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)