From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32B0FC83F17 for ; Tue, 15 Jul 2025 10:41:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubd5E-0004Jw-Cp; Tue, 15 Jul 2025 06:40:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubd4w-0003w2-Fm; Tue, 15 Jul 2025 06:40:06 -0400 Received: from [185.176.79.56] (helo=frasgout.his.huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubd4s-0005X0-U4; Tue, 15 Jul 2025 06:40:06 -0400 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4bhFwW38Nzz6L586; Tue, 15 Jul 2025 18:36:27 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id E581E140144; Tue, 15 Jul 2025 18:39:56 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 15 Jul 2025 12:39:55 +0200 Date: Tue, 15 Jul 2025 11:39:54 +0100 To: Shameer Kolothum , CC: , , , , , , , , , , , , , , , , Subject: Re: [RFC PATCH v3 12/15] hw/arm/smmuv3-accel: Introduce helpers to batch and issue cache invalidations Message-ID: <20250715113954.0000449e@huawei.com> In-Reply-To: <20250714155941.22176-13-shameerali.kolothum.thodi@huawei.com> References: <20250714155941.22176-1-shameerali.kolothum.thodi@huawei.com> <20250714155941.22176-13-shameerali.kolothum.thodi@huawei.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To frapeml500008.china.huawei.com (7.182.85.71) X-Host-Lookup-Failed: Reverse DNS lookup failed for 185.176.79.56 (deferred) Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org On Mon, 14 Jul 2025 16:59:38 +0100 Shameer Kolothum wrote: > From: Nicolin Chen > > Helpers will batch the commands and issue at once to host SMMUv3. > > Signed-off-by: Nicolin Chen > Signed-off-by: Shameer Kolothum > --- > hw/arm/smmuv3-accel.c | 65 ++++++++++++++++++++++++++++++++++++++++ > hw/arm/smmuv3-accel.h | 16 ++++++++++ > hw/arm/smmuv3-internal.h | 12 ++++++++ > 3 files changed, 93 insertions(+) > > diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c > index 04c665ccf5..1298b4f6d0 100644 > --- a/hw/arm/smmuv3-accel.c > +++ b/hw/arm/smmuv3-accel.c > @@ -168,6 +168,71 @@ smmuv3_accel_install_nested_ste_range(SMMUState *bs, SMMUSIDRange *range) > g_hash_table_foreach(bs->configs, smmuv3_accel_ste_range, range); > } > > +/* Update batch->ncmds to the number of execute cmds */ Not obvious what the return value here means. Maybe a comment? > +bool smmuv3_accel_issue_cmd_batch(SMMUState *bs, SMMUCommandBatch *batch) > +{ > + SMMUv3State *s = ARM_SMMUV3(bs); > + SMMUv3AccelState *s_accel = s->s_accel; > + uint32_t total = batch->ncmds; > + IOMMUFDViommu *viommu_core; > + int ret; > + > + if (!bs->accel) { > + return true; > + } > + > + if (!s_accel->viommu) { > + return true; > + } > + > + viommu_core = &s_accel->viommu->core; > + ret = iommufd_backend_invalidate_cache(viommu_core->iommufd, > + viommu_core->viommu_id, > + IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3, > + sizeof(Cmd), &batch->ncmds, > + batch->cmds, NULL); > + if (!ret || total != batch->ncmds) { > + error_report("%s failed: ret=%d, total=%d, done=%d", > + __func__, ret, total, batch->ncmds); > + return ret; This is reporting an error either way but returning success for the second condition which looks odd. Add a comment if intended. > + } > + > + batch->ncmds = 0; > + return ret; return true; given I think we know it's true if we get here? > +} > + > +/* > + * Note: sdev can be NULL for certain invalidation commands > + * e.g., SMMU_CMD_TLBI_NH_ASID, SMMU_CMD_TLBI_NH_VA etc. > + */ > +void smmuv3_accel_batch_cmd(SMMUState *bs, SMMUDevice *sdev, > + SMMUCommandBatch *batch, Cmd *cmd, > + uint32_t *cons) > +{ > + if (!bs->accel) { > + return; > + } > + > + /* > + * We may end up here for any emulated PCI bridge or root port type > + * devices. The batching of commands only matters for vfio-pci endpoint > + * devices with Guest S1 translation enabled. Hence check that, if > + * sdev is available. > + */ > + if (sdev) { > + SMMUv3AccelDevice *accel_dev; > + accel_dev = container_of(sdev, SMMUv3AccelDevice, sdev); > + > + if (!accel_dev->s1_hwpt) { > + return; > + } > + } > + > + batch->cmds[batch->ncmds] = *cmd; > + batch->cons[batch->ncmds++] = *cons; > + return; Drop this trailing return. > +} From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57B83C83F1D for ; Tue, 15 Jul 2025 10:41:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubd5C-0004Ij-Ca; Tue, 15 Jul 2025 06:40:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubd4w-0003w2-Fm; Tue, 15 Jul 2025 06:40:06 -0400 Received: from [185.176.79.56] (helo=frasgout.his.huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubd4s-0005X0-U4; Tue, 15 Jul 2025 06:40:06 -0400 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4bhFwW38Nzz6L586; Tue, 15 Jul 2025 18:36:27 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id E581E140144; Tue, 15 Jul 2025 18:39:56 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 15 Jul 2025 12:39:55 +0200 Date: Tue, 15 Jul 2025 11:39:54 +0100 To: Shameer Kolothum , CC: , , , , , , , , , , , , , , , , Subject: Re: [RFC PATCH v3 12/15] hw/arm/smmuv3-accel: Introduce helpers to batch and issue cache invalidations Message-ID: <20250715113954.0000449e@huawei.com> In-Reply-To: <20250714155941.22176-13-shameerali.kolothum.thodi@huawei.com> References: <20250714155941.22176-1-shameerali.kolothum.thodi@huawei.com> <20250714155941.22176-13-shameerali.kolothum.thodi@huawei.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To frapeml500008.china.huawei.com (7.182.85.71) X-Host-Lookup-Failed: Reverse DNS lookup failed for 185.176.79.56 (deferred) Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Mon, 14 Jul 2025 16:59:38 +0100 Shameer Kolothum wrote: > From: Nicolin Chen > > Helpers will batch the commands and issue at once to host SMMUv3. > > Signed-off-by: Nicolin Chen > Signed-off-by: Shameer Kolothum > --- > hw/arm/smmuv3-accel.c | 65 ++++++++++++++++++++++++++++++++++++++++ > hw/arm/smmuv3-accel.h | 16 ++++++++++ > hw/arm/smmuv3-internal.h | 12 ++++++++ > 3 files changed, 93 insertions(+) > > diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c > index 04c665ccf5..1298b4f6d0 100644 > --- a/hw/arm/smmuv3-accel.c > +++ b/hw/arm/smmuv3-accel.c > @@ -168,6 +168,71 @@ smmuv3_accel_install_nested_ste_range(SMMUState *bs, SMMUSIDRange *range) > g_hash_table_foreach(bs->configs, smmuv3_accel_ste_range, range); > } > > +/* Update batch->ncmds to the number of execute cmds */ Not obvious what the return value here means. Maybe a comment? > +bool smmuv3_accel_issue_cmd_batch(SMMUState *bs, SMMUCommandBatch *batch) > +{ > + SMMUv3State *s = ARM_SMMUV3(bs); > + SMMUv3AccelState *s_accel = s->s_accel; > + uint32_t total = batch->ncmds; > + IOMMUFDViommu *viommu_core; > + int ret; > + > + if (!bs->accel) { > + return true; > + } > + > + if (!s_accel->viommu) { > + return true; > + } > + > + viommu_core = &s_accel->viommu->core; > + ret = iommufd_backend_invalidate_cache(viommu_core->iommufd, > + viommu_core->viommu_id, > + IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3, > + sizeof(Cmd), &batch->ncmds, > + batch->cmds, NULL); > + if (!ret || total != batch->ncmds) { > + error_report("%s failed: ret=%d, total=%d, done=%d", > + __func__, ret, total, batch->ncmds); > + return ret; This is reporting an error either way but returning success for the second condition which looks odd. Add a comment if intended. > + } > + > + batch->ncmds = 0; > + return ret; return true; given I think we know it's true if we get here? > +} > + > +/* > + * Note: sdev can be NULL for certain invalidation commands > + * e.g., SMMU_CMD_TLBI_NH_ASID, SMMU_CMD_TLBI_NH_VA etc. > + */ > +void smmuv3_accel_batch_cmd(SMMUState *bs, SMMUDevice *sdev, > + SMMUCommandBatch *batch, Cmd *cmd, > + uint32_t *cons) > +{ > + if (!bs->accel) { > + return; > + } > + > + /* > + * We may end up here for any emulated PCI bridge or root port type > + * devices. The batching of commands only matters for vfio-pci endpoint > + * devices with Guest S1 translation enabled. Hence check that, if > + * sdev is available. > + */ > + if (sdev) { > + SMMUv3AccelDevice *accel_dev; > + accel_dev = container_of(sdev, SMMUv3AccelDevice, sdev); > + > + if (!accel_dev->s1_hwpt) { > + return; > + } > + } > + > + batch->cmds[batch->ncmds] = *cmd; > + batch->cons[batch->ncmds++] = *cons; > + return; Drop this trailing return. > +}