Commit bb38d577 authored by Huang Rui's avatar Huang Rui Committed by Ben Hutchings

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

commit 432abf68 upstream.

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).
Signed-off-by: default avatarHuang Rui <ray.huang@amd.com>
Fixes: ac0ea6e9 ('x86/amd-iommu: Improve handling of full command buffer')
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 0c06b1c5
......@@ -1044,7 +1044,7 @@ static int iommu_queue_command_sync(struct amd_iommu *iommu,
next_tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size;
left = (head - next_tail) % iommu->cmd_buf_size;
if (left <= 2) {
if (left <= 0x20) {
struct iommu_cmd sync_cmd;
volatile u64 sem = 0;
int ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment