Skip to contentSkip to conversation

iommu/amd: fix the left value check of cmd buffer

PATCH Applied Huang Rui 2 participants 2 messages Dec 12, 2016 – Jan 4, 2017 1 message not in the archive IOMMU

lore
Share & tools
lore

Huang Rui

author
#0 lore raw

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
index 019e027..3ef0f42 100644
@@ -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

Applied
#2 lore raw
Quoted 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 0x10 per 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_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).

Applied to the fixes branch, thanks.