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 lists1p.gnu.org (lists1p.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 9E1A5CD5BB1 for ; Thu, 21 May 2026 13:27:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ3Qx-0006lz-3G; Thu, 21 May 2026 09:27:31 -0400 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 1wQ3Qv-0006jr-EZ for qemu-arm@nongnu.org; Thu, 21 May 2026 09:27:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ3Qs-0003QI-W9 for qemu-arm@nongnu.org; Thu, 21 May 2026 09:27:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779370046; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IBU0RmhVsjEI/ftPAq3yUSYkLVBipJIEzUT12Oo1K4Q=; b=aPPlG22Ky5t/BNkNoPA6gd1TBbnOfDhgFbCSKCU1A17a2+QgI47t/+Ua5Q7cJNQ8ue/vew hXsnJMlzi85lRLQMvEuPiK2DD78spHfJgPxndlpZDPZra0rPY3C6rd3Wzy+cNRXlTUREa/ sS5fh99raeQGv9pYmO7PF5LHPjqdiCY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-o0ehuAvtNBegjaBqRNnuJA-1; Thu, 21 May 2026 09:27:23 -0400 X-MC-Unique: o0ehuAvtNBegjaBqRNnuJA-1 X-Mimecast-MFC-AGG-ID: o0ehuAvtNBegjaBqRNnuJA_1779370042 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48d127eb013so28260195e9.1 for ; Thu, 21 May 2026 06:27:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779370041; x=1779974841; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IBU0RmhVsjEI/ftPAq3yUSYkLVBipJIEzUT12Oo1K4Q=; b=lRij/sDKYZC7Rcudy3F/UhuWutPT8m+jbyeKBnb1XjIYBnZ1aWWpQ9f/yAYcwpaT0F zgy4nR1qjKRUEv+HrmkT+Q8yz47TEodz1ESOmUU2gcy5o26s0IwC65K1W6O6U/FryrkM blh0qbmSsalRkKONfP7MZ8Viz1XtthiIm3YwfXZZH2GC71y8rEHOBRvCHwbNku21WoC2 9V9X78F10HlDVuVOLPu5u/ZyWOwFMCSPC57AMn/KCpj6BqWKqyRVG733bmoOJfskmtrB N4L4f6n5XGx3jW5uq1wZTNQ4fvWNXjtt9cxY+zRl3z8zfKJbTwEhxO9uYBnzxoejFUD9 zYcw== X-Forwarded-Encrypted: i=1; AFNElJ+N5uV0QGwhOKbQqfl2iIHK3gy8lDw6pmwXbyC7xvfSsxf0E41OaY3uXiFB0uH26usm36IINZ4nlw==@nongnu.org X-Gm-Message-State: AOJu0YwgLepCMwCVU58RPCZy8kJYauz7Cv14md7EJcPXOFpm2UWcgjNd x3783Ti8QS8ZAQOKdR61C2WwUffVqGdgW0BU4jCwbB0F5xhcjfWv7YOafnWa1NsS5T03Yigekbf qznjsqwoP2Hj9mlYl6nWZa+fWNQFd3SmVVEPxivNqNP611qgyfNYBqg== X-Gm-Gg: Acq92OGFA1tyKfKhGqckM5YMi7b1iYdow+Z07kcohotAXB4pcmwXSoVmdJBoPrKTzlo 1MT7c3Hc1dIYQuy+wqg8hZ7kHclutaj5t2Fu8oe0WCurLJuyp9zUDhPGgvEMfbYNpmOazPzkCNf YJrAvu+9I9+TtmhBHvHP88CcZ0GkdufSniw/p0crORsLV0Z/CJlKEfuIWH0AZijujTkc84MI1pA MJaM1+wIKBJKp7YQaue+hCgr5fwHzPxTCeY7/WcRRwlG4V3V3t6qOWyg2Q5ThvE+3+3O+I1N9Ra s9jV5Ss01HU7kb74QY0ndV6vCtjWxjVNV7yDQQh4VrrI+fvE/ATCncPn3r0LWPPppjZzqvrBCSu 9e6kXVrGkyGLK6C2s4WiYnJY2kPqUIXf4afciZzB2rGILWL4AHS7XZ78e19UImybFqpEuhA== X-Received: by 2002:a05:600c:c098:b0:490:3d2e:b67d with SMTP id 5b1f17b1804b1-4903d2eb78emr15456245e9.30.1779370041489; Thu, 21 May 2026 06:27:21 -0700 (PDT) X-Received: by 2002:a05:600c:c098:b0:490:3d2e:b67d with SMTP id 5b1f17b1804b1-4903d2eb78emr15455645e9.30.1779370040976; Thu, 21 May 2026 06:27:20 -0700 (PDT) Received: from ?IPV6:2a01:e0a:f0e:9070:527b:9dff:feef:3874? ([2a01:e0a:f0e:9070:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eaa7cdcc3sm3189524f8f.8.2026.05.21.06.27.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 06:27:20 -0700 (PDT) Message-ID: <69ec35de-1f7c-40ae-9ea5-3727c047c590@redhat.com> Date: Thu, 21 May 2026 15:27:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 19/32] hw/arm/tegra241-cmdqv: Allocate HW VCMDQs once configured To: Shameer Kolothum Thodi , "qemu-arm@nongnu.org" , "qemu-devel@nongnu.org" Cc: "peter.maydell@linaro.org" , "clg@redhat.com" , "alex@shazbot.org" , Nicolin Chen , Nathan Chen , Matt Ochs , Jiandi An , Jason Gunthorpe , "zhenzhong.duan@intel.com" , Krishnakant Jaju , "phrdina@redhat.com" References: <20260519103727.899332-1-skolothumtho@nvidia.com> <20260519103727.899332-20-skolothumtho@nvidia.com> <166c5efb-0fa3-49f6-a1e7-faec85a6ec44@redhat.com> From: Eric Auger In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: aFuwTrnd090ElzcurYRC2jkKk3MsGgihoKNborwH4xU_1779370042 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: eric.auger@redhat.com Errors-To: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org On 5/21/26 2:26 PM, Shameer Kolothum Thodi wrote: > >> -----Original Message----- >> From: Eric Auger >> Sent: 21 May 2026 10:30 >> To: Shameer Kolothum Thodi ; qemu- >> arm@nongnu.org; qemu-devel@nongnu.org >> Cc: peter.maydell@linaro.org; clg@redhat.com; alex@shazbot.org; Nicolin >> Chen ; Nathan Chen ; Matt >> Ochs ; Jiandi An ; Jason Gunthorpe >> ; zhenzhong.duan@intel.com; Krishnakant Jaju >> ; phrdina@redhat.com >> Subject: Re: [PATCH v5 19/32] hw/arm/tegra241-cmdqv: Allocate HW >> VCMDQs once configured >> >> External email: Use caution opening links or attachments >> >> >> Hi, >> >> On 5/19/26 12:36 PM, Shameer Kolothum wrote: >>> From: Nicolin Chen >>> >>> Add support for allocating IOMMUFD hardware queues when the guest >>> programs the VCMDQ BASE registers. >> You should add the fact that >> >> iommufd_backend_alloc_hw_queue() requires the GPA of the VCMDQ. This >> explains why you need to those operations once the GPA has been populated. > Ok. > >>> VCMDQ_EN lives in VCMDQ_CONFIG, which is on the VINTF Page0 region >>> that a later patch maps directly into the guest — so QEMU won't trap >>> its writes. Allocate the hardware queue instead once all of these >>> are set: a RAM-backed BASE, CMDQ_ALLOC_MAP.ALLOC, and CMDQV / >> VINTF >>> enabled. Each precondition write retries the allocation, so the >>> guest may program them in any order. >>> If a hardware queue was previously allocated for the same VCMDQ, >>> free it before reallocation. >>> >>> Writes with invalid addresses are ignored. >>> >>> All allocated VCMDQs are freed when CMDQV or VINTF is disabled, or >>> when the ALLOC bit is cleared. >>> >>> Signed-off-by: Nicolin Chen >>> Co-developed-by: Shameer Kolothum >>> Signed-off-by: Shameer Kolothum >>> --- >>> hw/arm/tegra241-cmdqv.h | 11 ++++ >>> hw/arm/tegra241-cmdqv.c | 138 >> ++++++++++++++++++++++++++++++++++++++-- >>> 2 files changed, 143 insertions(+), 6 deletions(-) >>> >>> diff --git a/hw/arm/tegra241-cmdqv.h b/hw/arm/tegra241-cmdqv.h >>> index f0b031b4dc..7a8cb2ebc7 100644 >>> --- a/hw/arm/tegra241-cmdqv.h >>> +++ b/hw/arm/tegra241-cmdqv.h >>> @@ -45,6 +45,7 @@ typedef struct Tegra241CMDQV { >>> MemoryRegion mmio_cmdqv; >>> qemu_irq irq; >>> IOMMUFDVeventq *veventq; >>> + IOMMUFDHWqueue *vcmdq[TEGRA241_CMDQV_MAX_CMDQ]; >>> void *vintf_page0; >>> >>> /* CMDQ-V Config page register cache */ >>> @@ -361,6 +362,16 @@ >> SMMU_CMDQV_VI_VCMDQi_CONS_INDX_BASE_DRAM_L_(1) >>> SMMU_CMDQV_VI_VCMDQi_CONS_INDX_BASE_DRAM_H_(0) >>> SMMU_CMDQV_VI_VCMDQi_CONS_INDX_BASE_DRAM_H_(1) >>> >>> +static inline bool tegra241_cmdqv_enabled(Tegra241CMDQV *cmdqv) >>> +{ >>> + return cmdqv->status & R_STATUS_CMDQV_ENABLED_MASK; >>> +} >>> + >>> +static inline bool tegra241_vintf_enabled(Tegra241CMDQV *cmdqv) >>> +{ >>> + return cmdqv->vintf_status & R_VINTF0_STATUS_ENABLE_OK_MASK; >>> +} >>> + >>> const SMMUv3AccelCmdqvOps *tegra241_cmdqv_get_ops(void); >>> >>> #endif /* HW_ARM_TEGRA241_CMDQV_H */ >>> diff --git a/hw/arm/tegra241-cmdqv.c b/hw/arm/tegra241-cmdqv.c >>> index 4d9f094b2a..f4968520f3 100644 >>> --- a/hw/arm/tegra241-cmdqv.c >>> +++ b/hw/arm/tegra241-cmdqv.c >>> @@ -18,6 +18,95 @@ >>> #include "tegra241-cmdqv.h" >>> #include "trace.h" >>> >>> +static void tegra241_cmdqv_free_vcmdq(Tegra241CMDQV *cmdqv, int >> index) >>> +{ >>> + IOMMUFDViommu *viommu = cmdqv->s_accel->viommu; >>> + IOMMUFDHWqueue *vcmdq = cmdqv->vcmdq[index]; >>> + >>> + if (!vcmdq) { >>> + return; >>> + } >>> + iommufd_backend_free_id(viommu->iommufd, vcmdq->hw_queue_id); >>> + g_free(vcmdq); >>> + cmdqv->vcmdq[index] = NULL; >>> +} >>> + >>> +static void tegra241_cmdqv_free_all_vcmdq(Tegra241CMDQV *cmdqv) >>> +{ >>> + /* uapi/linux/iommufd.h: hw_queue destroy must be in descending >> @index. */ >>> + for (int i = (TEGRA241_CMDQV_MAX_CMDQ - 1); i >= 0; i--) { >>> + tegra241_cmdqv_free_vcmdq(cmdqv, i); >>> + } >>> +} >>> + >>> +/* >>> + * Allocate a host HW VCMDQ from the current cached BASE / size for >> @index. >>> + * >>> + * Setup is a no-op (returns true) when any of the following preconditions >>> + * isn't met yet: >>> + * - BASE not prgrammed yet. >>> + * - VCMDQ is not mapped to a VINTF (CMDQ_ALLOC_MAP.ALLOC == 0) >>> + * - BASE / size don't resolve to a RAM region >>> + * - CMDQV global enable or VINTF enable is not yet asserted >>> + */ >>> +static bool tegra241_cmdqv_setup_vcmdq(Tegra241CMDQV *cmdqv, int >> index, >>> + Error **errp) >>> +{ >>> + SMMUv3AccelState *accel = cmdqv->s_accel; >>> + uint64_t base_mask = (uint64_t)R_VCMDQ0_BASE_L_ADDR_MASK | >>> + (uint64_t)R_VCMDQ0_BASE_H_ADDR_MASK << 32; >>> + uint64_t addr = cmdqv->vcmdq_base[index] & base_mask; >>> + uint64_t log2 = cmdqv->vcmdq_base[index] & >> R_VCMDQ0_BASE_L_LOG2SIZE_MASK; >>> + uint64_t size = 1ULL << (log2 + 4); >>> + IOMMUFDViommu *viommu = accel->viommu; >>> + IOMMUFDHWqueue *hw_queue; >>> + uint32_t hw_queue_id; >>> + >>> + /* BASE not programmed yet. */ >>> + if (!cmdqv->vcmdq_base[index]) { >>> + return true; >>> + } >>> + >>> + /* VCMDQ not yet mapped to a VINTF. */ >>> + if (!(cmdqv->cmdq_alloc_map[index] & >> R_CMDQ_ALLOC_MAP_0_ALLOC_MASK)) { >>> + return true; >>> + } >>> + >>> + /* Ignore any invalid address. This may come as part of reset etc. */ >>> + if (!address_space_range_is_ram(&address_space_memory, addr, size)) { >> why do you need to test the whole range and not only the start address > That was to make it more defensive based on v4 discussion here: > https://lore.kernel.org/qemu-devel/aft%2FDTFLqQnufzWl@nvidia.com/ > > Please let me know if there is a better way. Well it is unclear to me. You want to make sure the GPA was fully set through the H and L regs. To me that's enough. As far as I understand Nicolin's reply, the kernel checks the rest. But please sync with Jason or Nicolin Eric > >>> + return true; >>> + } >>> + >>> + if (!tegra241_cmdqv_enabled(cmdqv) || >> !tegra241_vintf_enabled(cmdqv)) { >>> + return true; >>> + } >>> + >>> + tegra241_cmdqv_free_vcmdq(cmdqv, index); >>> + >>> + if (!iommufd_backend_alloc_hw_queue(viommu->iommufd, viommu- >>> viommu_id, >>> + IOMMU_HW_QUEUE_TYPE_TEGRA241_CMDQV, >>> + index, addr, size, &hw_queue_id, >>> + errp)) { >>> + return false; >>> + } >>> + hw_queue = g_new(IOMMUFDHWqueue, 1); >>> + hw_queue->hw_queue_id = hw_queue_id; >>> + hw_queue->viommu = viommu; >>> + cmdqv->vcmdq[index] = hw_queue; >>> + >>> + return true; >>> +} >>> + >>> +static void tegra241_cmdqv_setup_all_vcmdq(Tegra241CMDQV *cmdqv, >>> + Error **errp) >>> +{ >>> + for (int i = 0; i < TEGRA241_CMDQV_MAX_CMDQ; i++) { >>> + if (!tegra241_cmdqv_setup_vcmdq(cmdqv, i, errp)) { >> if case of failure,what is the functional consequence. Can you comment >> on this in the commit msg or here. > Today QEMU only logs the error: > > qemu-system-aarch64: IOMMU_HW_QUEUE_ALLOC failed: error -22 > > The guest visible behaviour then depends on whether VINTF0 Page 0 was > mapped into guest memory before this failure: > > Case 1: setup_vcmdq() succeeds for vcmdq0, fails for vcmdq1: > > - VINTF0 Page 0 was mapped to the guest after vcmdq0's success. > - Guest writes VCMDQ1_CONFIG go directly to HW. > - Guest reads VCMDQ1_STATUS directly from HW: > > ... > tegra241_cmdqv: VINTF0: VCMDQ1/LVCMDQ1: failed to enable, STATUS=0x00000000 > tegra241_cmdqv: VINTF0: VCMDQ1/LVCMDQ1: GERRORN=0x0, GERROR=0x0, CONS=0x0 > ... > > Case 2: setup_vcmdq() fails for vcmdq0: > > - VINTF0 Page 0 is not mapped to the guest. > - Guest writes VCMDQ0_CONFIG. Trapped by QEMU. > - Guest reads VCMDQ0_STATUS. Trapped by QEMU. > - Both served from the register cache. The cache currently doesn't > reflect the failure, so the guest thinks the queue is enabled and > proceeds to issue commands, eventually: > > arm-smmu-v3 arm-smmu-v3.0.auto: CMD_SYNC timeout at 0x00000002 [hwprod 0x00000002, hwcons 0x00000000] > arm-smmu-v3 arm-smmu-v3.0.auto: CMD_SYNC timeout at 0x00000004 [hwprod 0x00000004, hwcons 0x00000000] > > Case 2 needs fixing. I'll fix the register cache on the error path > for v6 and document it. OK ;-) Thanks Eric > > Thanks, > Shameer