From nobody Wed Feb 11 05:36:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1687470652; cv=none; d=zohomail.com; s=zohoarc; b=LL9TRmBJIkiEk73y+BGNmhWCWBSIL4luKi9ADErC0pePhmMRlsQgPLDHxORymIiU+WabsKb5T7zKZxlwnGBNg4JKDjyHt0jKFmGFuhoVYokVLubMT5tvT0Xj6jVYLYOKqK1OYzw4uJch9nkoMCcAu1Zky3obeU8M8EI9GOLC4Hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687470652; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SoXbQf/Kl+K/f9RW8RzgtC5CWtwRb6pbFr87bE/fgwE=; b=jjNzXjUWvpGEI82xVQc4xQ+rfhydZrJSqVbSuijFWCY9LTO1VdpfULDlMzJ8gyiUfB06Pxx8mnFfKebR+ZWA4Zu8WpHwTP0iOAkoXPaemxG0ZCzdpwzmaeIT9w72bz6R8HNfkP2WnoC1Bhj0MyHCYgM07pnqppCT6qgZiZvTzVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687470652062505.38102567040437; Thu, 22 Jun 2023 14:50:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCSBU-0003EM-Gu; Thu, 22 Jun 2023 17:49:44 -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 1qCSBS-0003Cg-HX for qemu-devel@nongnu.org; Thu, 22 Jun 2023 17:49:42 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCSBQ-0007SX-VJ for qemu-devel@nongnu.org; Thu, 22 Jun 2023 17:49:42 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35MJo5IW021572; Thu, 22 Jun 2023 21:49:39 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3r93m3txus-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Jun 2023 21:49:38 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 35MKQVLL008308; Thu, 22 Jun 2023 21:49:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3r9398epgq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Jun 2023 21:49:37 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35MLn76w035791; Thu, 22 Jun 2023 21:49:37 GMT Received: from joaomart-mac.uk.oracle.com (dhcp-10-175-180-251.vpn.oracle.com [10.175.180.251]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3r9398ep1g-7; Thu, 22 Jun 2023 21:49:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=SoXbQf/Kl+K/f9RW8RzgtC5CWtwRb6pbFr87bE/fgwE=; b=3eBV1M4NaqNrywQAiJb5zYd+ugc8N4DIQN9I2tYVYrMaML1fL9XCjotSazYpVv8Jx+pI nP0njVqoDkoRqKy0hVNx3F1iLpcSeB5pLt1uu6aAwskXtBO3n3D0TkwIfkoLkU+R5qsY HJtP2qDzpe0CRK5ubL5melHSJcuwdFV6HNd/6EBp2ee/tcNKPt0XJX1RFTIiY0ntoSCI DADEEDY/lO0ErglhKzJRJ2+MB3LDhbsrFS3QBoZ2J/myzLB2wCG+wZF6J2vg1xqeUFWL ablw57HVR5WAw3CPAI8uEP8olkoT7liU5B/i8BUozuVByEbk9hb2sKSYoLPAd2pYasWR Kw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Alex Williamson , Cedric Le Goater , Paolo Bonzini , Peter Xu , David Hildenbrand , Philippe Mathieu-Daude , "Michael S. Tsirkin" , Marcel Apfelbaum , Jason Wang , Richard Henderson , Eduardo Habkost , Avihai Horon , Jason Gunthorpe , Joao Martins Subject: [PATCH v4 06/15] intel-iommu: Implement get_attr() method Date: Thu, 22 Jun 2023 22:48:36 +0100 Message-Id: <20230622214845.3980-7-joao.m.martins@oracle.com> In-Reply-To: <20230622214845.3980-1-joao.m.martins@oracle.com> References: <20230622214845.3980-1-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-22_16,2023-06-22_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306220186 X-Proofpoint-GUID: MPrgm5I5Q8AIfZDO3JVgW19cWfA7HW0c X-Proofpoint-ORIG-GUID: MPrgm5I5Q8AIfZDO3JVgW19cWfA7HW0c Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1687470654287100003 Content-Type: text/plain; charset="utf-8" Implement IOMMU MR get_attr() method and use the dma_translation property to report the IOMMU_ATTR_DMA_TRANSLATION attribute. Additionally add the necessary get_iommu_attr into the PCIIOMMUOps to support pci_device_iommu_get_attr(). The callback in there acts as a IOMMU-specific address space walker which will call get_attr in the IOMMUMemoryRegion backing the device to fetch the desired attribute. Signed-off-by: Avihai Horon Signed-off-by: Joao Martins --- hw/i386/intel_iommu.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 1606d1b952d0..ed2a46e008df 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3861,6 +3861,29 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iomm= u_mr, IOMMUNotifier *n) return; } =20 +static int vtd_iommu_get_attr(IOMMUMemoryRegion *iommu_mr, + enum IOMMUMemoryRegionAttr attr, void *data) +{ + VTDAddressSpace *vtd_as =3D container_of(iommu_mr, VTDAddressSpace, io= mmu); + IntelIOMMUState *s =3D vtd_as->iommu_state; + int ret =3D 0; + + switch (attr) { + case IOMMU_ATTR_DMA_TRANSLATION: + { + bool *enabled =3D (bool *)(uintptr_t) data; + + *enabled =3D s->dma_translation; + break; + } + default: + ret =3D -EINVAL; + break; + } + + return ret; +} + /* Do the initialization. It will also be called when reset, so pay * attention when adding new initialization stuff. */ @@ -4032,8 +4055,24 @@ static AddressSpace *vtd_host_dma_iommu(PCIBus *bus,= void *opaque, int devfn) return &vtd_as->as; } =20 +static int vtd_get_iommu_attr(PCIBus *bus, void *opaque, int32_t devfn, + enum IOMMUMemoryRegionAttr attr, void *data) +{ + IntelIOMMUState *s =3D opaque; + VTDAddressSpace *vtd_as; + + assert(0 <=3D devfn && devfn < PCI_DEVFN_MAX); + + vtd_as =3D vtd_find_add_as(s, bus, devfn, PCI_NO_PASID); + if (!vtd_as) + return -EINVAL; + + return memory_region_iommu_get_attr(&vtd_as->iommu, attr, data); +} + static PCIIOMMUOps vtd_iommu_ops =3D { .get_address_space =3D vtd_host_dma_iommu, + .get_iommu_attr =3D vtd_get_iommu_attr, }; =20 static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) @@ -4197,6 +4236,7 @@ static void vtd_iommu_memory_region_class_init(Object= Class *klass, imrc->translate =3D vtd_iommu_translate; imrc->notify_flag_changed =3D vtd_iommu_notify_flag_changed; imrc->replay =3D vtd_iommu_replay; + imrc->get_attr =3D vtd_iommu_get_attr; } =20 static const TypeInfo vtd_iommu_memory_region_info =3D { --=20 2.17.2