From nobody Wed Feb 11 05:36:55 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=1687470632; cv=none; d=zohomail.com; s=zohoarc; b=Rl76iu/wevys/Uc890yI/vcEhwS3VZIszS+4CT9NsOVzrkcLiLus5wz77XKXs8Q8aaj4luSnd4/+yNMqESUx3B4zLbS8KM1PODN8JbV4kTOF2DcRPelo9B1jYabybXWI3/kHF4bVdpwBPZyoPmmb7lgxHgao6pWshyLYZxEB7yY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687470632; 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=2XsM4/X8GgWe6VN83nLwHow/PhcL0rm5V9PFVUE9tL0=; b=I2LHGJ3wvDHDcUABHm4lu4L1gM1JYFEsYsBQgfDh4w1qHzdGUlCQYfBdbHmWXEQsIjjRqIbVx7gIsVq4Rv1IjZF5QKY7P1XVmMBSJgXsVbjm08/r5uBXH4Wx4UksOrTMY6Ge2RDPFqpy1/Z5lT6caUOjC7GudzJnlQh90A4vMYM= 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 1687470632093598.7034880995924; Thu, 22 Jun 2023 14:50:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCSBY-0003Ex-AH; Thu, 22 Jun 2023 17:49:48 -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 1qCSBW-0003El-SW for qemu-devel@nongnu.org; Thu, 22 Jun 2023 17:49:46 -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 1qCSBV-0007TY-6Z for qemu-devel@nongnu.org; Thu, 22 Jun 2023 17:49:46 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35MIbN5I031279; Thu, 22 Jun 2023 21:49:43 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 3r94ettxm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Jun 2023 21:49:43 +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 35MJgThM008357; Thu, 22 Jun 2023 21:49:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3r9398epj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Jun 2023 21:49:41 +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 35MLn770035791; Thu, 22 Jun 2023 21:49:41 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-8; Thu, 22 Jun 2023 21:49:41 +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=2XsM4/X8GgWe6VN83nLwHow/PhcL0rm5V9PFVUE9tL0=; b=t0Nyj1zx9l7cZHMqvTeHWdO7Mef8jYa/nPbuJFPqDT5gqWwQ7SQ6Z7yPgF/r8hMrcQd7 1cp8D/ncZy6/Jt4g1OcZKlAC4QhHWauCCI8xLRdNBhIGtDqNztQXXbXWnaDM+PkP2Mz9 5ikx1tKgxuTcCnqNhOPl/VnB/Ku8AlGPRYBoN5b+Lmsq1Jvf69wVoiKL4E+cNzedpUm+ VFRgUoCN+nezYExfu2wwsMKa4BBrnxT/eXMGleplA38t0Df+q0PvwsEoxG85jauIGWwd q5mXYOuZ4JmrCWZIDSKphxjgc5jxJiQ6cooOhrp97S+UgiWWhHWJspHJhK7rdf5oyvGZ XA== 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 07/15] vfio/common: Track whether DMA Translation is enabled on the vIOMMU Date: Thu, 22 Jun 2023 22:48:37 +0100 Message-Id: <20230622214845.3980-8-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: egVIolT5eitF4iXJX4JhxLyUc6xTIC-z X-Proofpoint-ORIG-GUID: egVIolT5eitF4iXJX4JhxLyUc6xTIC-z 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: 1687470634133100005 Content-Type: text/plain; charset="utf-8" vfio_get_group() allocates and fills the group/container/space on success which will store the AddressSpace inside the VFIOSpace struct. Use the newly added pci_device_iommu_get_attr() to see if DMA translation is enabled or not. Assume that by default it is enabled. Today, this means only intel-iommu supports it. Signed-off-by: Joao Martins --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/pci.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index eed244f25f34..f41860988d6b 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -70,6 +70,7 @@ typedef struct VFIOMigration { =20 typedef struct VFIOAddressSpace { AddressSpace *as; + bool no_dma_translation; QLIST_HEAD(, VFIOContainer) containers; QLIST_ENTRY(VFIOAddressSpace) list; } VFIOAddressSpace; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 73874a94de12..8a98e6ffc480 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2900,6 +2900,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); VFIODevice *vbasedev =3D &vdev->vbasedev; VFIODevice *vbasedev_iter; + VFIOAddressSpace *space; VFIOGroup *group; char *tmp, *subsys, group_path[PATH_MAX], *group_name; Error *err =3D NULL; @@ -2907,7 +2908,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) struct stat st; int groupid; int i, ret; - bool is_mdev; + bool is_mdev, dma_translation; char uuid[UUID_FMT_LEN]; char *name; =20 @@ -2961,6 +2962,18 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) goto error; } =20 + space =3D group->container->space; + + /* + * Support for toggling DMA translation is optional. + * By default, DMA translation is assumed to be enabled i.e. + * space::no_dma_translation is 0. + */ + dma_translation =3D true; + pci_device_iommu_get_attr(pdev, IOMMU_ATTR_DMA_TRANSLATION, + &dma_translation); + space->no_dma_translation =3D !dma_translation; + QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (strcmp(vbasedev_iter->name, vbasedev->name) =3D=3D 0) { error_setg(errp, "device is already attached"); --=20 2.17.2