iommu/amd: fix the left value check of cmd buffer
PATCH 1/1 iommu/amd: fix the left value check of cmd buffer
The generic command buffer entry is 128 bits (16 bytes), so the offset of tail and head pointer should be 16 bytes aligned and increased with 0x10 per command.
When cmd buf is full, head = (tail + 0x10) % CMD_BUFFER_SIZE.
So when left space of cmd buf should be able to store only two command, we should be issued one COMPLETE_WAIT additionally to wait all older commands completed. Then the left space should be increased after IOMMU fetching from cmd buf.
So left check value should be left <= 0x20 (two commands).
---
Hi Joerg,
The command entry is 128 bits (16 bytes aligned), so the left value shouldn't be 2. I think here, you might check the case when the buf is full, so modify the value as the two commands left. Please review.
Thanks,
Rui
--- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd_iommu.c +1 -1
@@ -1023,7 +1023,7 @@ static int __iommu_queue_command_sync(struct amd_iommu *iommu, next_tail = (tail +sizeof (*cmd)) %CMD_BUFFER_SIZE ; left = (head - next_tail) %CMD_BUFFER_SIZE ; -if (left <=2 ) { +if (left <=0x20 ) {struct iommu_cmd sync_cmd;int ret;
Signature · 1 line
2.1.0
A message that is not in the archive (sent off-list or not yet received): 1481545706-1610-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Joerg Roedel
AppliedQuoted 6 lines · Huang Rui
The generic command buffer entry is 128 bits (16 bytes), so the offset of tail and head pointer should be 16 bytes aligned and increased with
0x10per command.When cmd buf is full, head = (tail +
0x10) %CMD_BUFFER_SIZE.
Quoted 8 lines
So when left space of cmd buf should be able to store only two command, we should be issued one
COMPLETE_WAITadditionally to wait all older commands completed. Then the left space should be increased after IOMMU fetching from cmd buf.So left check value should be left <=
0x20(two commands).Signed-off-by Huang Rui <[email protected]>
Applied to the fixes branch, thanks.