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 80A65CCFA04 for ; Mon, 3 Nov 2025 16:52:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFxmn-0003Rf-3M; Mon, 03 Nov 2025 11:52:05 -0500 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 1vFxmm-0003RX-BV for qemu-arm@nongnu.org; Mon, 03 Nov 2025 11:52:04 -0500 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 1vFxme-00049A-5j for qemu-arm@nongnu.org; Mon, 03 Nov 2025 11:52:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762188711; 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=x2mzI29oojPvR6WejxEc0b6TlzG6uFGzZY+idHVO0ow=; b=ezT3mRS2kbJtjpnha541zBdKDV6OU1kWhu2BOCdcBnaibfhOJX7nuZw9mT1HReBcQFQXIE cY7P4YpII5cSSX4rgF1nutuDjPI1/x0Wz54yTkRk2h/SJ7Ix1qaXHykSWryzRpk/HzQ30t ptD/SZcGpJMPqyYlqwE+c2lOO9IuS4Q= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-12-0WG2UN6FOZutb17I5ES1XQ-1; Mon, 03 Nov 2025 11:51:48 -0500 X-MC-Unique: 0WG2UN6FOZutb17I5ES1XQ-1 X-Mimecast-MFC-AGG-ID: 0WG2UN6FOZutb17I5ES1XQ_1762188707 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3ef9218daf5so3653089f8f.1 for ; Mon, 03 Nov 2025 08:51:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762188707; x=1762793507; 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-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x2mzI29oojPvR6WejxEc0b6TlzG6uFGzZY+idHVO0ow=; b=i6kpJJwpLU3kGMtxe6QDektTOu80xo8ZyKajRVT/aNH/3fd4Rrwmjqe+bXjqJyUKdV O8XYt0hxru2D3I7O8kEEJWM2ymq833yh97bcLl93eiCLttUq+lSfd44VUCLjOAZ+GNdi VDMMFqDQUCQ+OqtE/6fDnn0ItB8oBw2Dgy/0utMN3SRh3Hi3Bx3zycxHfO6pm3nQ10F1 29YmbaKTr8eIDjeJcAgJVr75Juh2pWpWVZIK31y+1bMoiR1mC3t2jD27T74tPs9vaham INdCLpAlAz7IpkmNft8xX6Ks42qq+rW3hz0jEy0guPCzLLmUneYKnS6zso0YajLP9AcS 6Ltg== X-Forwarded-Encrypted: i=1; AJvYcCXJ7G/1U/cH8GbguA6fK+UO+Jq/8rRdAMH4ISnmafVpwE6u2W5InrFriCPAT2qcFkz+FoFxeQqmcQ==@nongnu.org X-Gm-Message-State: AOJu0YzX6QuKf7IgxGWZAlrqYqBZCrn3zWeb/FWBDL3sLeyUW5a71PgC /dVgRCMOKEHpKNqvSqX9xQnm2GTyXJ0MlDQbQ6RMsGGTwojtj+9TRva11k1eEhR4YbZzclxeQe9 d0Vh2Evr0tgYdN+Wgp0xylCm7C9ubTZPmBTmhJn09niV0xYAbKXy2Ag== X-Gm-Gg: ASbGncvj3uaf38RaUblIL212dlaKBoIwtGqKk3CB2g0Lyy5cE9IGqd16F3WTiL74wM9 H9ux3MFg97YAH7uF8NBan9Ka7zeBG7b2Ngwe6sREm+3gNfR5OnS9Dei7t+CxqkC3BDguoFGdhcF NuRJCWTTF1whTk5AYcJyURJRXTBI3ze+9LJ0Gr2pgP/nnLsRP29rB19rct2AP8CFJnd7kpNwPF3 +S6VZrEXk2xRchYX+bDvdk6eenh4Xi/RfpdODcfhSJlW822IroIEXvItrjYA9Hr5RmngENg12qP vyeNs0ptgi9XkTTiY2HrpptoR1npeJa1VMbNGi75b5Q28tdMu+OlZiBGAbP3FKhyxGs0DppBWQj bKp/yqgPj9E0q7FgA9l4MLf5rtTsa61aZ5wPB+/YskoWfCQ== X-Received: by 2002:a05:6000:2301:b0:429:8d46:fc40 with SMTP id ffacd0b85a97d-429bd682dd2mr12131314f8f.25.1762188707118; Mon, 03 Nov 2025 08:51:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEotaw287g1lb2lhrTcaCRzhvp0/x8klbGbixmmi379YOwWofmKIsnkvzMMjY1Wy/z+zMVZvw== X-Received: by 2002:a05:6000:2301:b0:429:8d46:fc40 with SMTP id ffacd0b85a97d-429bd682dd2mr12131293f8f.25.1762188706691; Mon, 03 Nov 2025 08:51:46 -0800 (PST) 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-429c1406a45sm20960647f8f.47.2025.11.03.08.51.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Nov 2025 08:51:46 -0800 (PST) Message-ID: <51afaf95-20bb-44f9-8595-8e6f699a6b75@redhat.com> Date: Mon, 3 Nov 2025 17:51:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 10/32] hw/arm/smmuv3-accel: Restrict accelerated SMMUv3 to vfio-pci endpoints with iommufd To: Shameer Kolothum , qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, ddutile@redhat.com, berrange@redhat.com, nathanc@nvidia.com, mochs@nvidia.com, smostafa@google.com, wangzhou1@hisilicon.com, jiangkunkun@huawei.com, jonathan.cameron@huawei.com, zhangfei.gao@linaro.org, zhenzhong.duan@intel.com, yi.l.liu@intel.com, kjaju@nvidia.com References: <20251031105005.24618-1-skolothumtho@nvidia.com> <20251031105005.24618-11-skolothumtho@nvidia.com> From: Eric Auger In-Reply-To: <20251031105005.24618-11-skolothumtho@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DiaB6KfO4ETbeCQaKVPS1LajclLK_9huFq1XVqDd2bU_1762188707 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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 10/31/25 11:49 AM, Shameer Kolothum wrote: > Accelerated SMMUv3 is only meaningful when a device can leverage the > host SMMUv3 in nested mode (S1+S2 translation). To keep the model > consistent and correct, this mode is restricted to vfio-pci endpoint > devices using the iommufd backend. > > Non-endpoint emulated devices such as PCIe root ports and bridges are > also permitted so that vfio-pci devices can be attached beneath them. s/beneath them/downstream? > All other device types are unsupported in accelerated mode. > > Implement supports_address_space() callaback to reject all such callback > unsupported devices. > > This restriction also avoids complications with IOTLB invalidations. > Some TLBI commands (e.g. CMD_TLBI_NH_ASID) lack an associated SID, > making it difficult to trace the originating device. Allowing emulated > endpoints would require invalidating both QEMU’s software IOTLB and the > host’s hardware IOTLB, which can significantly degrade performance. > > For vfio-pci devices in nested mode, get_address_space() returns an > address space aliased to system address space so that the VFIO core > can set up the correct stage-2 mappings for guest RAM. > > In summary: > - vfio-pci devices(with iommufd as backend) return an address space > aliased to system address space. > - bridges and root ports return the IOMMU address space. > > Reviewed-by: Jonathan Cameron > Reviewed-by: Nicolin Chen > Signed-off-by: Shameer Kolothum > --- > hw/arm/smmuv3-accel.c | 66 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 65 insertions(+), 1 deletion(-) > > diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c > index f62b6cf2c9..550a0496fe 100644 > --- a/hw/arm/smmuv3-accel.c > +++ b/hw/arm/smmuv3-accel.c > @@ -7,8 +7,13 @@ > */ > > #include "qemu/osdep.h" > +#include "qemu/error-report.h" > > #include "hw/arm/smmuv3.h" > +#include "hw/pci/pci_bridge.h" > +#include "hw/pci-host/gpex.h" > +#include "hw/vfio/pci.h" > + > #include "smmuv3-accel.h" > > /* > @@ -38,6 +43,41 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus, > return accel_dev; > } > > +static bool smmuv3_accel_pdev_allowed(PCIDevice *pdev, bool *vfio_pci) > +{ > + > + if (object_dynamic_cast(OBJECT(pdev), TYPE_PCI_BRIDGE) || > + object_dynamic_cast(OBJECT(pdev), TYPE_PXB_PCIE_DEV) || > + object_dynamic_cast(OBJECT(pdev), TYPE_GPEX_ROOT_DEVICE)) { > + return true; > + } else if ((object_dynamic_cast(OBJECT(pdev), TYPE_VFIO_PCI))) { > + *vfio_pci = true; > + if (object_property_get_link(OBJECT(pdev), "iommufd", NULL)) { > + return true; > + } > + } > + return false; > +} > + > +static bool smmuv3_accel_supports_as(PCIBus *bus, void *opaque, int devfn, > + Error **errp) > +{ > + PCIDevice *pdev = pci_find_device(bus, pci_bus_num(bus), devfn); > + bool vfio_pci = false; > + > + if (pdev && !smmuv3_accel_pdev_allowed(pdev, &vfio_pci)) { > + if (vfio_pci) { > + error_setg(errp, "vfio-pci endpoint devices without an iommufd " > + "backend not allowed when using arm-smmuv3,accel=on"); > + > + } else { > + error_setg(errp, "Emulated endpoint devices are not allowed when " > + "using arm-smmuv3,accel=on"); > + } > + return false; > + } > + return true; > +} > /* > * Find or add an address space for the given PCI device. > * > @@ -48,15 +88,39 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus, > static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus, void *opaque, > int devfn) > { > + PCIDevice *pdev = pci_find_device(bus, pci_bus_num(bus), devfn); > SMMUState *bs = opaque; > SMMUPciBus *sbus = smmu_get_sbus(bs, bus); > SMMUv3AccelDevice *accel_dev = smmuv3_accel_get_dev(bs, sbus, bus, devfn); > SMMUDevice *sdev = &accel_dev->sdev; > + bool vfio_pci = false; > > - return &sdev->as; > + if (pdev && !smmuv3_accel_pdev_allowed(pdev, &vfio_pci)) { > + /* Should never be here: supports_address_space() filters these out */ > + g_assert_not_reached(); > + } > + > + /* > + * In the accelerated mode, a vfio-pci device attached via the iommufd > + * backend must remain in the system address space. Such a device is > + * always translated by its physical SMMU (using either a stage-2-only > + * STE or a nested STE), where the parent stage-2 page table is allocated > + * by the VFIO core to back the system address space. > + * > + * Return the shared_as_sysmem aliased to the global system memory in this > + * case. Sharing address_space_memory also allows devices under different > + * vSMMU instances in the same VM to reuse a single nesting parent HWPT in > + * the VFIO core. > + */ > + if (vfio_pci) { > + return shared_as_sysmem; > + } else { > + return &sdev->as; > + } > } > > static const PCIIOMMUOps smmuv3_accel_ops = { > + .supports_address_space = smmuv3_accel_supports_as, > .get_address_space = smmuv3_accel_find_add_as, > }; > Besides Reviewed-by: Eric Auger Eric