[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/2] AMD/IOMMU: redo awaiting of command completion


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 25 Jun 2021 14:15:01 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HKNAiCAkTEux8snV3/fR8a3Zgbg4iM0MzH/i8v9qTag=; b=Duu4Q1Ir0QVpHQEUocabQ0hQhKbk1NhS+vPAsQdiQOG/wjvc+/0mXN826C97OVMW1ViW5SglOU2GvvQDu01s0jugLr6esbj3h5SyqT4m2IDHtYiy4GcH8ub4ajHvYU9XZ7Uf6ANHfdNL4Be+9BKnfxuErtkXfA2tRlJinu6JoFf6aNReN6jqRn5hof8No5gO0oPo872L9BY/crWWc4QP+hsl6D7ylCO79Pcm609KIcqM6ajC/ji6LaTlHDGtwY21hKuYTkUQeZe1A0+4sX2lMvazvp5I5PaxqBxAl2xUw46rnBZ1qjtmSHalWwejJNYjWP7K78b978woOm6pvLbQsg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d+/Z/PUx3aonao+Bn2BfVUmUDRCPWgFKL/E0TrW1ZNTu6gx4k50kKcjL/rZk5lYZNHkB/UDVogt86pB4tTSKFl4El8N9caSIJqDgFeQT/qHTpEGC6BFwhuGALGWgKu7Trmv+4Y0FnWbYY3yHXVatBQwknfxW38YsDY3Ik8XkxjGgzm3sTH+qe3IvhHxMJoHNA8fzkOmN/KXqEpeKGh5jsDlELw+Kbgz1PuWwCJzL4UGQ+j+gJS0DKtcRvLvE4NNKxrHEhIwHBHOb8vGsRlT4rOJskf7jNgharvSg6N25gaNjyHErNUlL9UWvkraX1lzwEn1y7hY4eFHK+T4e+4YVbg==
  • Authentication-results: citrix.com; dkim=none (message not signed) header.d=none;citrix.com; dmarc=none action=none header.from=suse.com;
  • Cc: Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Fri, 25 Jun 2021 12:15:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The present abuse of the completion interrupt does not only stand in the
way of, down the road, using it for its actual purpose, but also
requires holding the IOMMU lock while waiting for command completion,
limiting parallelism and keeping interrupts off for non-negligible
periods of time. Have the IOMMU do an ordinary memory write instead of
signaling an otherwise disabled interrupt (by just updating a status
register bit).

Since IOMMU_COMP_WAIT_I_FLAG_SHIFT is now unused and
IOMMU_COMP_WAIT_[FS]_FLAG_SHIFT already were, drop all three of them
while at it.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Reviewed-by: Paul Durrant <paul@xxxxxxx>
---
v2: Avoid set_field_in_reg_u32(). Drop now unused
    IOMMU_COMP_WAIT_[FIS]_FLAG_SHIFT.

--- a/xen/drivers/passthrough/amd/iommu-defs.h
+++ b/xen/drivers/passthrough/amd/iommu-defs.h
@@ -178,11 +178,8 @@ struct amd_iommu_dte {
 #define IOMMU_COMP_WAIT_DATA_BUFFER_SIZE       8
 #define IOMMU_COMP_WAIT_DATA_BUFFER_ALIGNMENT  8
 #define IOMMU_COMP_WAIT_S_FLAG_MASK            0x00000001
-#define IOMMU_COMP_WAIT_S_FLAG_SHIFT           0
 #define IOMMU_COMP_WAIT_I_FLAG_MASK            0x00000002
-#define IOMMU_COMP_WAIT_I_FLAG_SHIFT           1
 #define IOMMU_COMP_WAIT_F_FLAG_MASK            0x00000004
-#define IOMMU_COMP_WAIT_F_FLAG_SHIFT           2
 #define IOMMU_COMP_WAIT_ADDR_LOW_MASK          0xFFFFFFF8
 #define IOMMU_COMP_WAIT_ADDR_LOW_SHIFT         3
 #define IOMMU_COMP_WAIT_ADDR_HIGH_MASK         0x000FFFFF
--- a/xen/drivers/passthrough/amd/iommu_cmd.c
+++ b/xen/drivers/passthrough/amd/iommu_cmd.c
@@ -20,6 +20,9 @@
 #include "iommu.h"
 #include "../ats.h"
 
+#define CMD_COMPLETION_INIT 0
+#define CMD_COMPLETION_DONE 1
+
 static void send_iommu_command(struct amd_iommu *iommu,
                                const uint32_t cmd[4])
 {
@@ -49,28 +52,27 @@ static void send_iommu_command(struct am
 static void flush_command_buffer(struct amd_iommu *iommu,
                                  unsigned int timeout_base)
 {
-    uint32_t cmd[4];
+    static DEFINE_PER_CPU(uint64_t, poll_slot);
+    uint64_t *this_poll_slot = &this_cpu(poll_slot);
+    paddr_t addr = virt_to_maddr(this_poll_slot);
+    /* send a COMPLETION_WAIT command to flush command buffer */
+    uint32_t cmd[4] = {
+        addr | MASK_INSR(IOMMU_CONTROL_ENABLED,
+                         IOMMU_COMP_WAIT_S_FLAG_MASK),
+        (addr >> 32) | MASK_INSR(IOMMU_CMD_COMPLETION_WAIT,
+                                 IOMMU_CMD_OPCODE_MASK),
+        CMD_COMPLETION_DONE
+    };
     s_time_t start, timeout;
     static unsigned int __read_mostly threshold = 1;
 
-    /* RW1C 'ComWaitInt' in status register */
-    writel(IOMMU_STATUS_COMP_WAIT_INT,
-           iommu->mmio_base + IOMMU_STATUS_MMIO_OFFSET);
-
-    /* send an empty COMPLETION_WAIT command to flush command buffer */
-    cmd[3] = cmd[2] = 0;
-    set_field_in_reg_u32(IOMMU_CMD_COMPLETION_WAIT, 0,
-                         IOMMU_CMD_OPCODE_MASK,
-                         IOMMU_CMD_OPCODE_SHIFT, &cmd[1]);
-    set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, 0,
-                         IOMMU_COMP_WAIT_I_FLAG_MASK,
-                         IOMMU_COMP_WAIT_I_FLAG_SHIFT, &cmd[0]);
+    ACCESS_ONCE(*this_poll_slot) = CMD_COMPLETION_INIT;
+
     send_iommu_command(iommu, cmd);
 
     start = NOW();
     timeout = start + (timeout_base ?: 100) * MILLISECS(threshold);
-    while ( !(readl(iommu->mmio_base + IOMMU_STATUS_MMIO_OFFSET) &
-              IOMMU_STATUS_COMP_WAIT_INT) )
+    while ( ACCESS_ONCE(*this_poll_slot) != CMD_COMPLETION_DONE )
     {
         if ( timeout && NOW() > timeout )
         {




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.