All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: fix the left value check of cmd buffer
@ 2016-12-12 12:28 Huang Rui
       [not found] ` <1481545706-1610-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Huang Rui @ 2016-12-12 12:28 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Chunming Zhou, Alvin Huan,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Huang Rui,
	Ken Wang, Borislav Petkov, Hawking Zhang

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: Huang Rui <ray.huang-5C7GfCeVMHo@public.gmane.org>
---

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(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 019e027..3ef0f42 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -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;
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iommu/amd: fix the left value check of cmd buffer
       [not found] ` <1481545706-1610-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
@ 2017-01-04 14:24   ` Joerg Roedel
  0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2017-01-04 14:24 UTC (permalink / raw)
  To: Huang Rui
  Cc: Chunming Zhou, Alvin Huan,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Ken Wang,
	Borislav Petkov, Hawking Zhang

On Mon, Dec 12, 2016 at 07:28:26AM -0500, Huang Rui wrote:
> 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: Huang Rui <ray.huang-5C7GfCeVMHo@public.gmane.org>

Applied to the fixes branch, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-04 14:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-12 12:28 [PATCH] iommu/amd: fix the left value check of cmd buffer Huang Rui
     [not found] ` <1481545706-1610-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2017-01-04 14:24   ` Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.