Report CERROR_ILL for CMD_ATC_INV when SMMU_IDR0.ATS is zero, before
checking the target SID or whether the issuing interface is enabled.

When ATS is advertised, ignore the command if SMMUEN is clear in the
issuing command queue's register bank, as required by IHI 0070G.b,
section 4.5.1. Use the queue's sec_sid for this check while retaining
the Non-secure target for both Non-secure and Secure command queues.

Fixes: dadd1a0809b1 ("hw/arm/smmuv3: Queue helpers")
Fixes: f7f5013a55a3 ("hw/arm/smmuv3-accel: Add support for ATS")
Signed-off-by: Tao Tang <[email protected]>
---
 hw/arm/smmuv3.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 98e45e33082..716520d5eb8 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1669,9 +1669,20 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error 
**errp, SMMUSecSID sec_sid)
             break;
         case SMMU_CMD_ATC_INV:
         {
-            SMMUDevice *sdev = smmu_find_sdev(bs, CMD_SID(&cmd));
+            SMMUDevice *sdev;
 
-            if (!sdev || !smmuv3_ats_enabled(s)) {
+            if (!smmuv3_ats_enabled(s)) {
+                cmd_error = SMMU_CERROR_ILL;
+                break;
+            }
+
+            /* Check SMMUEN for the issuing command queue's security state. */
+            if (!smmu_enabled(s, sec_sid)) {
+                break;
+            }
+
+            sdev = smmu_find_sdev(bs, CMD_SID(&cmd));
+            if (!sdev) {
                 trace_smmuv3_unhandled_cmd(type);
                 break;
             }
-- 
2.34.1


Reply via email to