From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39818606A322 for ; Thu, 3 Dec 2026 21:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=S+YM2d1b Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZDzV-0007Ms-Et; Thu, 03 Dec 2026 16:05:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZDzO-0007KG-8A for qemu-arm@nongnu.org; Thu, 03 Dec 2026 16:05:15 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xZDzK-0005qD-H7 for qemu-arm@nongnu.org; Thu, 03 Dec 2026 16:05:12 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4a018493d57so21105e9.0 for ; Thu, 03 Dec 2026 13:05:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796331908; x=1796936708; darn=nongnu.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=HJ2yko7y3s93sxKRIfZW3lHry9VbuokLHr7cDAdU24A=; b=S+YM2d1b+MD/VokyM7zITXV5ijBWFsHpsJxe61YZn61fWQdMbmBMuX481T84DK78o1 29qYXaFV+Qri7vwo5pdNFEx90dRY8gc5Jp9mP7+8iiUXcE/cWq+aka+hEJZRHxLFE6zQ rxLVU9GKIIaMZRpVCtP8ahmn6fQNna5Sf+LbmkmGq2Ompb/mMupUzTTrvLCW+LzApPO0 phQnozhL4/MMnbbz9v/Dtdie6lvXanGkxYfTu6Y8/ZDvPPoJBbieFY1K1RXlDOqnamz8 nCOwpv1M6Ls+xr7A/nA4Rh/naZ/PFWJiWCcsmp7iKP7T3I6+mpMjKzChaKOvEw0IEpNb 5umw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796331908; x=1796936708; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HJ2yko7y3s93sxKRIfZW3lHry9VbuokLHr7cDAdU24A=; b=tkGEvnBs7VhUy/LHu9W22dACBDVIyVrZ2Q8n04j+A/SVi/KurlfGKkP7ISBgXc+k7y TJDwxDpdx2KmO5idrbCRpd+3rPxNjgHFa8sAuUOcsw3ZpcnxFbkMY7K7B6GsuR0h16Ak xIf/N+M8WLy6GDa2mNH3A8sL0iKxrXmPYcXakgWzJ2H8qAACZz1Icpk7PmLCyPB38dFQ fz3hR5MhsjeHZADxx46TxLRbSwtg0A5hyW2yixbStgcUS9YUzqY4SfGpBFIQTn9fMHi2 Rb3gO/qmCC4gOFjGsKv4Z/msSbk40I7QJVdtJXOghB84C7WchtR8MPuvYx74UNE8q/u3 JD+A== X-Forwarded-Encrypted: i=1; AL+hErF1/NGI8bPuWyElg+9mi5veNS31OZyb0QWjaWFjdg7wvvsClafESPYMCVA/IP4VZAM7sCLQkSVODw==@nongnu.org X-Gm-Message-State: APuU4Z9aeJViN0grejmm8pOuvlfZeJVll5tTSOsYqugZohHK1mO5An82 AR9DJceq44ydf+8iFEwca3THATdrM2c76VjmzkgY17+SCkS3b5/4fZixbia8MbTHww== X-Gm-Gg: AZFdTZe39yGncV3ltrtoSNEW39xhcfnmto1rUg1XeG1QvWmNpoUv5vxvT8DAI+hr5bw yn1GZKzSr3SEFy3AH+hBxV88p+xg/upK9DloHBSzsBnqvcGk08B1LU1Di9LabJyiwdziDILlG8n 3BLiW++7XqJj3+lcHuW+YgWhIe8vwGuJPayQz+1LBGRZy5y8PQdS6SMxkQEgT+eKneBh0mCHiLR C/aox0eysAPJcHtwn6S6LazwfoqLcHFAkxJ9BYtsHDgcIJp22RjA3pYoWJM6PgmJ0gsGSVp8Itf hHbrhLpWHzXS7lzF/FgeP/iuHfM+O81dwPZv2fmxM/fauS+sFqyd3zPHiEonKJ1y11bci+spjLY XC3/HH1M+oahxG1bT/WvWZlX0P8STQG8/+35vhyZ5p/Q8XlG5r87QM/IZfep5UY+Hd6jB1AxRNg oD9KO2z6N2yDdx/3dAcSzlvWzTlVJ1wwu3pl/5+EsfY+Q1FwHpIoKhDunyw0jxRYgZ4UEHFzXQ+ hU5mu8D31QwnkHlETPcbuCm2SSE74DzuUAaMQCc8KW5etrVoQkrJh2H5zzwStVl6p4ORzMXf16s RxMIHKRbEAY6ktlLgcyGshxh1IQOpmrVw1j01wScrOF0BrfCFhaJFfewhRokU/YK7CSc2A== X-Received: by 2002:a05:600c:8b34:b0:4bb:a5e1:74a1 with SMTP id 5b1f17b1804b1-4bbead25fb6mr64355e9.1.1796331907934; Thu, 03 Dec 2026 13:05:07 -0800 (PST) Received: from google.com (160.193.189.35.bc.googleusercontent.com. [35.189.193.160]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1738cfb63sm1392007f8f.37.2026.12.03.13.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 13:05:06 -0800 (PST) Date: Thu, 3 Dec 2026 21:05:02 +0000 From: Mostafa Saleh To: Tao Tang Cc: Peter Maydell , Eric Auger , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Chao Liu , Chen Baozi , Jim MacArthur Subject: Re: [PATCH v6 26/35] hw/arm/smmuv3: Determine register bank from MMIO offset Message-ID: References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> <20261114161940.3648277-1-tangtao1634@phytium.com.cn> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261114161940.3648277-1-tangtao1634@phytium.com.cn> Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=smostafa@google.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -144 X-Spam_score: -14.5 X-Spam_bar: -------------- X-Spam_report: (-14.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, FSL_HELO_FAKE=3.099, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sun, Nov 15, 2026 at 12:19:40AM +0800, Tao Tang wrote: > Modify the main MMIO handlers to select the target register bank from the > memory-mapped offset. > > Offsets in the Secure register window select SMMU_SEC_SID_S and are > normalized by subtracting SMMU_SECURE_REG_START. Other offsets select the > Non-secure bank. Pass the selected SEC_SID to the register access helpers, > where the normalized bank-local offset identifies the register. > > Keep bank-specific differences explicit, such as S_IDR5 being unimplemented. > This patch implements Non-secure and Secure bank dispatch and prepares for > later access checks; Realm and Root programming interfaces are not modeled. > > Signed-off-by: Tao Tang > Reviewed-by: Pierrick Bouvier > Reviewed-by: Jim MacArthur > Reviewed-by: Eric Auger > --- > hw/arm/smmuv3.c | 84 ++++++++++++++++++++++++++++++++++++++++--------- > 1 file changed, 70 insertions(+), 14 deletions(-) > > diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c > index 138ca178a1a..54647964c21 100644 > --- a/hw/arm/smmuv3.c > +++ b/hw/arm/smmuv3.c > @@ -1742,10 +1742,25 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > return 0; > } > > +static bool smmuv3_reg_is_raz_wi(hwaddr offset, SMMUSecSID reg_sec_sid) > +{ > + switch (offset) { > + case A_IDR5: > + case A_IIDR: > + case A_STATUSR: > + case A_IDREGS ... A_IDREGS + 0x2f: > + return reg_sec_sid != SMMU_SEC_SID_NS; This check and the next one (reg_sec_sid == SMMU_SEC_SID_S) are the same and can be replaced with the helper smmu_sec_sid_is_secure() > + case A_AIDR: > + return reg_sec_sid == SMMU_SEC_SID_S; > + default: > + return false; > + } > +} > + > static MemTxResult smmu_writell(SMMUv3State *s, hwaddr offset, > - uint64_t data, MemTxAttrs attrs) > + uint64_t data, MemTxAttrs attrs, > + SMMUSecSID reg_sec_sid) > { > - SMMUSecSID reg_sec_sid = SMMU_SEC_SID_NS; > SMMUv3RegBank *bank = smmuv3_bank(s, reg_sec_sid); > > switch (offset) { > @@ -1798,16 +1813,20 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwaddr offset, > } > > static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset, > - uint64_t data, MemTxAttrs attrs) > + uint64_t data, MemTxAttrs attrs, > + SMMUSecSID reg_sec_sid) > { > Error *local_err = NULL; > - SMMUSecSID reg_sec_sid = SMMU_SEC_SID_NS; > SMMUv3RegBank *bank = smmuv3_bank(s, reg_sec_sid); > > switch (offset) { > case A_CR0: > + if (reg_sec_sid == SMMU_SEC_SID_S) { > + data &= ~SMMU_S_CR0_RESERVED; > + } > bank->cr[0] = data; > - bank->cr0ack = data & ~SMMU_CR0_RESERVED; > + bank->cr0ack = data & ~(reg_sec_sid == SMMU_SEC_SID_S ? > + SMMU_S_CR0_RESERVED : SMMU_CR0_RESERVED); > /* in case the command queue has been enabled */ > smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); > if (local_err) { > @@ -1850,7 +1869,9 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset, > if (data & R_GBPA_UPDATE_MASK) { > /* Ignore update bit as write is synchronous. */ > bank->gbpa = data & ~R_GBPA_UPDATE_MASK; > - smmuv3_accel_attach_gbpa_hwpt(s, &local_err); > + if (reg_sec_sid == SMMU_SEC_SID_NS) { > + smmuv3_accel_attach_gbpa_hwpt(s, &local_err); > + } > } > break; > case A_STRTAB_BASE: /* 64b */ > @@ -1991,16 +2012,35 @@ static MemTxResult smmu_write_mmio(void *opaque, hwaddr offset, uint64_t data, > SMMUState *sys = opaque; > SMMUv3State *s = ARM_SMMUV3(sys); > MemTxResult r; > + SMMUSecSID reg_sec_sid = SMMU_SEC_SID_NS; > > /* CONSTRAINED UNPREDICTABLE choice to have page0/1 be exact aliases */ > offset &= ~0x10000; > > + /* > + * Dispatch the Non-secure window directly. After access validation, > + * translate the Secure window to its bank-local register offsets. > + */ > + if (offset >= SMMU_SECURE_REG_START) { > + reg_sec_sid = SMMU_SEC_SID_S; > + offset -= SMMU_SECURE_REG_START; > + } > + > + if (smmuv3_reg_is_raz_wi(offset, reg_sec_sid)) { > + qemu_log_mask(LOG_GUEST_ERROR, > + "%s: write to undefined register: bank=%d " > + "offset=0x%" PRIx64 " (WI)\n", > + __func__, reg_sec_sid, offset); > + trace_smmuv3_write_mmio(offset, data, size, MEMTX_OK); > + return MEMTX_OK; > + } > + > switch (size) { > case 8: > - r = smmu_writell(s, offset, data, attrs); > + r = smmu_writell(s, offset, data, attrs, reg_sec_sid); > break; > case 4: > - r = smmu_writel(s, offset, data, attrs); > + r = smmu_writel(s, offset, data, attrs, reg_sec_sid); > break; > default: > r = MEMTX_ERROR; > @@ -2012,9 +2052,9 @@ static MemTxResult smmu_write_mmio(void *opaque, hwaddr offset, uint64_t data, > } > > static MemTxResult smmu_readll(SMMUv3State *s, hwaddr offset, > - uint64_t *data, MemTxAttrs attrs) > + uint64_t *data, MemTxAttrs attrs, > + SMMUSecSID reg_sec_sid) > { > - SMMUSecSID reg_sec_sid = SMMU_SEC_SID_NS; > SMMUv3RegBank *bank = smmuv3_bank(s, reg_sec_sid); > > switch (offset) { > @@ -2043,9 +2083,9 @@ static MemTxResult smmu_readll(SMMUv3State *s, hwaddr offset, > } > > static MemTxResult smmu_readl(SMMUv3State *s, hwaddr offset, > - uint64_t *data, MemTxAttrs attrs) > + uint64_t *data, MemTxAttrs attrs, > + SMMUSecSID reg_sec_sid) > { > - SMMUSecSID reg_sec_sid = SMMU_SEC_SID_NS; > SMMUv3RegBank *bank = smmuv3_bank(s, reg_sec_sid); > > switch (offset) { > @@ -2135,6 +2175,7 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwaddr offset, > *data = 0; > return MEMTX_OK; > default: > + unhandled: This label is unused. Otherwise, Reviewed-by: Mostafa Saleh Thanks, Mostafa > *data = 0; > qemu_log_mask(LOG_UNIMP, > "%s unhandled 32-bit access at 0x%"PRIx64" (RAZ)\n", > @@ -2149,16 +2190,31 @@ static MemTxResult smmu_read_mmio(void *opaque, hwaddr offset, uint64_t *data, > SMMUState *sys = opaque; > SMMUv3State *s = ARM_SMMUV3(sys); > MemTxResult r; > + SMMUSecSID reg_sec_sid = SMMU_SEC_SID_NS; > > /* CONSTRAINED UNPREDICTABLE choice to have page0/1 be exact aliases */ > offset &= ~0x10000; > + if (offset >= SMMU_SECURE_REG_START) { > + reg_sec_sid = SMMU_SEC_SID_S; > + offset -= SMMU_SECURE_REG_START; > + } > + > + if (smmuv3_reg_is_raz_wi(offset, reg_sec_sid)) { > + *data = 0; > + qemu_log_mask(LOG_GUEST_ERROR, > + "%s: read from undefined register: bank=%d " > + "offset=0x%" PRIx64 " (RAZ)\n", > + __func__, reg_sec_sid, offset); > + trace_smmuv3_read_mmio(offset, *data, size, MEMTX_OK); > + return MEMTX_OK; > + } > > switch (size) { > case 8: > - r = smmu_readll(s, offset, data, attrs); > + r = smmu_readll(s, offset, data, attrs, reg_sec_sid); > break; > case 4: > - r = smmu_readl(s, offset, data, attrs); > + r = smmu_readl(s, offset, data, attrs, reg_sec_sid); > break; > default: > r = MEMTX_ERROR; > -- > 2.34.1 >