From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784966; cv=none; d=zohomail.com; s=zohoarc; b=aKm4QnAzHEkcT7k+D3mwv3IDTXHmG9hFSImIySm9cJuComWybnCWEm6eWUgKFA9TtjT8uWWpD4B7qJyJ3eoiJAIrD3r5UF+tRWSQjNbrMuUnRBusLxdqKnh7FgMKLwEnoXtGmDtuDrbjCpK0iLQJGC+FWVdymt9jc9sxwS6RTWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784966; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YjjFfcqjRtgmHhj9Eg+zpRZFG+1Mm3L/QLMYuy0OMY4=; b=RMI62Q5lLi7ArtM+eu49mvdDBm6xiY8yUz3YFtXKrWp/dqpQqsKAtngslL+T/WT4MEArUXO872ZeaWpeZLP3mdPqGgYK5cjexXCIXFg8KSlyNVjbGk2D0AFcSbhVWAr9IZdaoTKol5Aj47XWcceHGFVvHFWs3YFmVBeqbWlB46Q= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784966959936.8475883844593; Fri, 12 Jul 2024 04:49:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEke-0005c2-88; Fri, 12 Jul 2024 07:47: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 1sSEkH-0005R1-ED for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:27 -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 1sSEkF-0007cG-HH for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:25 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1CCf3021960; Fri, 12 Jul 2024 11:47:17 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt30a1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:17 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CBMAQP022638; Fri, 12 Jul 2024 11:47:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq09-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:16 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCU008041; Fri, 12 Jul 2024 11:47:15 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-2; Fri, 12 Jul 2024 11:47:15 +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-11-20; bh=Y jjFfcqjRtgmHhj9Eg+zpRZFG+1Mm3L/QLMYuy0OMY4=; b=kmyYSYNoIKAyUADh6 gKwhlx0E5rb25ttTrqvWkGrDD8C2S+w+xXfXfXT16Us6RZ2bepXxCU2m0qXhxrd0 8OqduqAuquhGyCTzF9HazKJJQ6pn5qXwHbs9K9IgPcWiYQrX98eOLQu3UIi8GBtw 8dBUwssJtKtMS4z/u3vVxEqjJCJAXOAdkuw9hw4zNkqpcwskofgK3fhFobdjxum1 RR1y9jUGrWwGVXpSAuxbALqUuHG4Ulkix/YAujUcUoVFT9xLbwnhMlJnFAoVzK4w UilGHYNWceDnyMm6x5oB5EOzyGU2Kp+rVeOWHqumnj6Ul9lVROmIQ+A4HSQyP8ZP yTHzw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 01/12] vfio/pci: Extract mdev check into an helper Date: Fri, 12 Jul 2024 12:46:53 +0100 Message-Id: <20240712114704.8708-2-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: WJRmkkI9-9sxudRMDafjwItU4aH9cr8- X-Proofpoint-ORIG-GUID: WJRmkkI9-9sxudRMDafjwItU4aH9cr8- 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784967484116600 Content-Type: text/plain; charset="utf-8" In preparation to skip initialization of the HostIOMMUDevice for mdev, extract the checks that validate if a device is an mdev into helpers. A vfio_set_mdev() is created, and subsystems consult VFIODevice::mdev to check if it's mdev or not. Signed-off-by: Joao Martins --- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/helpers.c | 18 ++++++++++++++++++ hw/vfio/pci.c | 9 ++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index e8ddf92bb185..7419466bca92 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -116,6 +116,7 @@ typedef struct VFIODevice { DeviceState *dev; int fd; int type; + bool mdev; bool reset_works; bool needs_reset; bool no_mmap; @@ -231,6 +232,7 @@ void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); struct vfio_device_info *vfio_get_device_info(int fd); +void vfio_set_mdev(VFIODevice *vbasedev); bool vfio_attach_device(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void vfio_detach_device(VFIODevice *vbasedev); diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index b14edd46edc9..bace0e788a09 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -675,3 +675,21 @@ int vfio_device_get_aw_bits(VFIODevice *vdev) =20 return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX; } + +void vfio_set_mdev(VFIODevice *vbasedev) +{ + g_autofree char *tmp =3D NULL; + char *subsys; + bool is_mdev; + + if (!vbasedev->sysfsdev) { + return; + } + + tmp =3D g_strdup_printf("%s/subsystem", vbasedev->sysfsdev); + subsys =3D realpath(tmp, NULL); + is_mdev =3D subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); + free(subsys); + + vbasedev->mdev =3D is_mdev; +} diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e03d9f3ba546..585f23a18406 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2963,12 +2963,10 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) ERRP_GUARD(); VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); VFIODevice *vbasedev =3D &vdev->vbasedev; - char *subsys; int i, ret; bool is_mdev; char uuid[UUID_STR_LEN]; g_autofree char *name =3D NULL; - g_autofree char *tmp =3D NULL; =20 if (vbasedev->fd < 0 && !vbasedev->sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || @@ -2997,11 +2995,8 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) * stays in sync with the active working set of the guest driver. Pre= vent * the x-balloon-allowed option unless this is minimally an mdev devic= e. */ - tmp =3D g_strdup_printf("%s/subsystem", vbasedev->sysfsdev); - subsys =3D realpath(tmp, NULL); - is_mdev =3D subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); - free(subsys); - + vfio_set_mdev(vbasedev); + is_mdev =3D vbasedev->mdev; trace_vfio_mdev(vbasedev->name, is_mdev); =20 if (vbasedev->ram_block_discard_allowed && !is_mdev) { --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784908; cv=none; d=zohomail.com; s=zohoarc; b=GMQzYCTQI+DFaHTcecaQDmAk7vUF4ERlk+aMLQHxYeSyWVcgSr96lt+fJ99u+zdfHebVUCJ/6wZonhOZeE3kNuWtGNr7RPslV/9OkNkSDImv9aSojMWK3m2t/aeK+Klrr13EF8YCXnlpDwP1xKMCUAgMVJDiDp3ABEn3dZRVMt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784908; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ka3prPYoEe/KSHCLuHyyuvQyvjBT8EDPgFMoR5YBJF8=; b=S5Hvcn8BaYl7YJSdMF3JbmOcTHB84SwGd3W5rfknYotf/eAIUUS07sC7kMBq78+iPHf9m7EKFFAfJoZsSeJ8c3OweUTksSbOESzAvNtPqoW2ujQbJ/KrXj8F9xmVpYPYq4ePS1RlE+ZO971WRe/oVkPzY4Vipt99r0YbQPMQJDo= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784908049489.0139730599674; Fri, 12 Jul 2024 04:48:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkg-0005mj-SL; Fri, 12 Jul 2024 07:47:51 -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 1sSEkK-0005Uc-8t for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:30 -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 1sSEkF-0007cF-HH for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:28 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BcTH018652; Fri, 12 Jul 2024 11:47:20 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkckm7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:19 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CB2Gvt022045; Fri, 12 Jul 2024 11:47:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:18 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCW008041; Fri, 12 Jul 2024 11:47:18 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-3; Fri, 12 Jul 2024 11:47:18 +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-11-20; bh=K a3prPYoEe/KSHCLuHyyuvQyvjBT8EDPgFMoR5YBJF8=; b=IOEQuxaK9Gd9mMsuO m4ARxgH2a1Z+U70Ni9X0gaGUXrYZfR+YDXX2CIWTUHNu0aAaYM3eX3p2kIkNPKDH tcaiOse+FMwGJTeI+tIV8jdDJxkjlcb2ESoOAtxrPwIQo7aC/kxT1DtKdnn65Ojt A636ppuBj0bt4i93Y482ontwTs+bDlbcTSs51Ipz10gHQzmjy4Agk6RtpkXZmiln xCf1SnQBDY3Nwx2BHhMcXTQAy3EbnS26Qm0abUz57MagJz0nJUCpueX9QQLbXoie A2xiJtW84sjKbYjnuPyKEMkkmoTV9bPZ8t64bPJUG4M65TcYo9JzyA+liRAlJIsL 8Pkgw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 02/12] vfio/iommufd: Don't initialize nor set a HOST_IOMMU_DEVICE with mdev Date: Fri, 12 Jul 2024 12:46:54 +0100 Message-Id: <20240712114704.8708-3-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-ORIG-GUID: 4h5CV6SrapTsSFzDeNIZXIbLFVzZK-LJ X-Proofpoint-GUID: 4h5CV6SrapTsSFzDeNIZXIbLFVzZK-LJ 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784909327116600 Content-Type: text/plain; charset="utf-8" mdevs aren't "physical" devices and when asking for backing IOMMU info, it fails the entire provisioning of the guest. Fix that by skipping HostIOMMUDevice initialization in the presence of mdevs, and skip setting an iommu device when it is known to be an mdev. Cc: Zhenzhong Duan Fixes: 930589520128 ("vfio/iommufd: Implement HostIOMMUDeviceClass::realize= () handler") Signed-off-by: Joao Martins Reviewed-by: Eric Auger Reviewed-by: Zhenzhong Duan --- hw/vfio/common.c | 4 ++++ hw/vfio/pci.c | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7cdb969fd396..b0beed44116e 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1556,6 +1556,10 @@ bool vfio_attach_device(char *name, VFIODevice *vbas= edev, return false; } =20 + if (vbasedev->mdev) { + return true; + } + hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp))= { object_unref(hiod); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 585f23a18406..3fc72e898a25 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3116,7 +3116,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 vfio_bars_register(vdev); =20 - if (!pci_device_set_iommu_device(pdev, vbasedev->hiod, errp)) { + if (!is_mdev && !pci_device_set_iommu_device(pdev, vbasedev->hiod, err= p)) { error_prepend(errp, "Failed to set iommu_device: "); goto out_teardown; } @@ -3239,7 +3239,9 @@ out_deregister: timer_free(vdev->intx.mmap_timer); } out_unset_idev: - pci_device_unset_iommu_device(pdev); + if (!is_mdev) { + pci_device_unset_iommu_device(pdev); + } out_teardown: vfio_teardown_msi(vdev); vfio_bars_exit(vdev); @@ -3284,7 +3286,9 @@ static void vfio_exitfn(PCIDevice *pdev) vfio_pci_disable_rp_atomics(vdev); vfio_bars_exit(vdev); vfio_migration_exit(vbasedev); - pci_device_unset_iommu_device(pdev); + if (!vbasedev->mdev) { + pci_device_unset_iommu_device(pdev); + } } =20 static void vfio_pci_reset(DeviceState *dev) --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784972; cv=none; d=zohomail.com; s=zohoarc; b=LRwFeyPeDDz0xpaBRNVQ9PTDdNupgMe0jC8PsK50VVMJNdTjfBln4tWyq2NHw0cuUxG2pFCfptAWUMqdBPYclwjV1kcE9ZxWCpCakrKl969UEG2o2ko/bI9u7u05yWywgaJVJiUjG/62MZD1jlst61JTEJg09rrhhpJ9MAwLIJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784972; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0nau4lpgSQgPGvf1jMzHDGQRzh3s7fsu4Hvn+m67NL0=; b=GGeEq8wkvauVhfQADBg2OBvuVWssYHBo6PUTG2Py+GYSu20deQMwMSUaCU88g1E0XLOgfN3f5O5iDtp4PX1/0dMOMLhPrcO/GIZNkMqgn8Z1sMiylxUjzdCFG9na92S6l7DnKpEC0AONNYl+vtspMOn1M3W2U67HJiKZFkRfztU= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784972008663.5294733673707; Fri, 12 Jul 2024 04:49:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEke-0005aS-6z; Fri, 12 Jul 2024 07:47: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 1sSEkI-0005T3-RR for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:29 -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 1sSEkH-0007cN-7n for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:26 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BZ7I020939; Fri, 12 Jul 2024 11:47:23 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt30ab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:22 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CBRkux022734; Fri, 12 Jul 2024 11:47:21 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq24-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:21 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCY008041; Fri, 12 Jul 2024 11:47:20 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-4; Fri, 12 Jul 2024 11:47:20 +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-11-20; bh=0 nau4lpgSQgPGvf1jMzHDGQRzh3s7fsu4Hvn+m67NL0=; b=fZ/g00bVoaeJaU4SS mgja4EOh1Gc/Ajac+3FHc74wkR9UsQoMD2iiD45DTA6V9VsdkncvcqgcSIbD2YYw wVEh2bxO7MnmviZ3buPHyftNpuy6Hd556TTx3ErQYCCLzqkkE5jHWOCpknOOquyX B5Lbhy0PqLQbYVJ9QtysErNdzdP0uzmBrmFrjqQGi159YMX/6lLujn32VgXkBzbi cPxz0sILAgA13SdhAXBrF9X8UHOJczyIQPH/UNp46l1J9oA0ENN01GMlbn2J3t8c hOF7y24ngaa32tb+AYzPHXp31pcTW2k1YmUsGT/ikLBn9LIuxspFz7bEfvxg5alE ZyrFA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 03/12] backends/iommufd: Extend iommufd_backend_get_device_info() to fetch HW capabilities Date: Fri, 12 Jul 2024 12:46:55 +0100 Message-Id: <20240712114704.8708-4-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=749 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: am_zYRWOPwJZa7X09zcF3jspd6z-Fgy_ X-Proofpoint-ORIG-GUID: am_zYRWOPwJZa7X09zcF3jspd6z-Fgy_ 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784973473116600 Content-Type: text/plain; charset="utf-8" The helper will be able to fetch vendor agnostic IOMMU capabilities supported both by hardware and software. Right now it is only iommu dirty tracking. Signed-off-by: Joao Martins Reviewed-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- include/sysemu/iommufd.h | 2 +- backends/iommufd.c | 4 +++- hw/vfio/iommufd.c | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 9edfec604595..57d502a1c79a 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -49,7 +49,7 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_= t ioas_id, hwaddr iova, ram_addr_t size); bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, uint32_t *type, void *data, uint32_t = len, - Error **errp); + uint64_t *caps, Error **errp); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 84fefbc9ee7a..2b3d51af26d2 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -210,7 +210,7 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint3= 2_t ioas_id, =20 bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, uint32_t *type, void *data, uint32_t = len, - Error **errp) + uint64_t *caps, Error **errp) { struct iommu_hw_info info =3D { .size =3D sizeof(info), @@ -226,6 +226,8 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be= , uint32_t devid, =20 g_assert(type); *type =3D info.out_data_type; + g_assert(caps); + *caps =3D info.out_capabilities; =20 return true; } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index c2f158e60386..604eaa4d9a5d 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -628,11 +628,13 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice= *hiod, void *opaque, union { struct iommu_hw_info_vtd vtd; } data; + uint64_t hw_caps; =20 hiod->agent =3D opaque; =20 if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, - &type, &data, sizeof(data), errp)= ) { + &type, &data, sizeof(data), + &hw_caps, errp)) { return false; } =20 --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784885; cv=none; d=zohomail.com; s=zohoarc; b=V7qUKY4w973k3UtJJbgRLKX0jpz+bScXyAnP53clpve0J8I8q12KTReqyzYDiqYT7JKhdjcEYc3HhWDSbwDau4sASaWsonMHjKzwqEOFr4EcQqoWb7G+ZLW2AOS0aaocNmkzBPot8PUVW4Nr7Qfr5pYB9ts3KJN+8u3ZWX34g3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784885; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O5LjBIVIE/EHS1v7F4/+Il1DS58gauA/FvnCRuzVzJk=; b=lAf8MHMW10PPzxWjNgAbk/q0W2e/dXrR6S8oSParX6sxbZUjExPWX5HmTjtNJOVvIIjseTVFIbGHsvLkXToN8QyWDMjr04fptGHX1P4JqOZFaXYWmyxaY0wLDBBaL0P+U87yfglvyWDESBGWdew3BVquD6+YSKlPYL72OMZYazU= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784885099207.14471587979756; Fri, 12 Jul 2024 04:48:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkg-0005mO-Rj; Fri, 12 Jul 2024 07:47:50 -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 1sSEkK-0005Ue-P6 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:30 -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 1sSEkJ-0007e4-8f for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:28 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C9o9nr002390; Fri, 12 Jul 2024 11:47:25 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wybuth0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:25 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CAFTj4022608; Fri, 12 Jul 2024 11:47:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:24 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCa008041; Fri, 12 Jul 2024 11:47:23 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-5; Fri, 12 Jul 2024 11:47:23 +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-11-20; bh=O 5LjBIVIE/EHS1v7F4/+Il1DS58gauA/FvnCRuzVzJk=; b=Ng4C8x8uAs1GP2fZU wJ7UE3TjG9cZBWiltB+0SffpXVgEjR1Llb9lxk3Qr0Saas/3dkyOhTI3cKjCZsTo Gom857EFbJdvdrR4IaFIGVunyRClGyh8BXI3dErkuOCCVvSz22X4u+k/mu5gv4OL aaDiNxQzK++pk6RjResoi6clKL0I/oyXpxbqZFe5+xVEsSpybeXDMfaYy0wKZ7RA XtF4QWZvFYLD9D7WzbRZhk4Lw8DzvkaSg8Ju6ImxDhQXNICYDOyJboMENkmYkZFU sM7ecA1IiAeZa/jXAohQhgY8Ikr95HjudeodlTgeuk8B9tZ0Yj1iloCcaBpS+FnY pYcAg== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 04/12] vfio/iommufd: Return errno in iommufd_cdev_attach_ioas_hwpt() Date: Fri, 12 Jul 2024 12:46:56 +0100 Message-Id: <20240712114704.8708-5-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=931 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: iM7983zwZG44jCYkgxdqWNH0BHEmTu9c X-Proofpoint-ORIG-GUID: iM7983zwZG44jCYkgxdqWNH0BHEmTu9c 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784887347116600 Content-Type: text/plain; charset="utf-8" In preparation to implement auto domains have the attach function return the errno it got during domain attach instead of a bool. -EINVAL is tracked to track domain incompatibilities, and decide whether to create a new IOMMU domain. Signed-off-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Reviewed-by: Zhenzhong Duan --- hw/vfio/iommufd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 604eaa4d9a5d..077dea8f1b64 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -172,7 +172,7 @@ out: return ret; } =20 -static bool iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t i= d, +static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t id, Error **errp) { int iommufd =3D vbasedev->iommufd->fd; @@ -187,12 +187,12 @@ static bool iommufd_cdev_attach_ioas_hwpt(VFIODevice = *vbasedev, uint32_t id, error_setg_errno(errp, errno, "[iommufd=3D%d] error attach %s (%d) to id=3D%d", iommufd, vbasedev->name, vbasedev->fd, id); - return false; + return -errno; } =20 trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, vbasedev->fd, id); - return true; + return 0; } =20 static bool iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **er= rp) @@ -216,7 +216,7 @@ static bool iommufd_cdev_attach_container(VFIODevice *v= basedev, VFIOIOMMUFDContainer *container, Error **errp) { - return iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, err= p); + return !iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, er= rp); } =20 static void iommufd_cdev_detach_container(VFIODevice *vbasedev, --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784975; cv=none; d=zohomail.com; s=zohoarc; b=ajTgeD0CIlGkmJIB91q/AwinCL3Ywz2KKWhdIeC0q2FTgHWmXssTMGddP0LakCxL1WGsnB+vXMmGdrPyI4Ou0YaKdW+eIP/V0H9L7ddaRy7ckDLlbMquDDSIqe/0BMNlAQ4gZmXlVp5kkyw8xkMI9p4CBwch+7DERAB12HT/9KQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784975; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kB250HDOc+wA6wR2DjyODzSHiGa427f6S1xVrev3Dyk=; b=B7GprXNfLxJUxd/yJsmEfe4ZLzASagGZycFD6D0MDjR9HP/F5lH6vASy2is7+An9euWsamWM6fKQ65yWDcP6y1Jbmb48GPN5aD2mw20GvXCyT7pOksUWCUq82tm88S5/nQixvqNAXDgeporC7seCBXXttnhgPLSrbD2F9m5Bb0U= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784975617803.4171662183182; Fri, 12 Jul 2024 04:49:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEke-0005aV-6t; Fri, 12 Jul 2024 07:47: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 1sSEkS-0005Xu-TA for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:39 -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 1sSEkN-0007eP-JT for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:36 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BVX8002398; Fri, 12 Jul 2024 11:47:28 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wybuth2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:27 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CB6u6A022041; Fri, 12 Jul 2024 11:47:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:26 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCc008041; Fri, 12 Jul 2024 11:47:26 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-6; Fri, 12 Jul 2024 11:47:26 +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-11-20; bh=k B250HDOc+wA6wR2DjyODzSHiGa427f6S1xVrev3Dyk=; b=lOOIr8XagAIXXXRRm E0Ckeh6BzKCcjoJulGGQyf41kR9OLXvY+2Iy6cmOFJH2+E8LnF7p4eJAaci8V3fk ez7cPjHA9en4u6NOmUtRM2geWSifney8X7+E/VcKqV1P+OVPL9R7v1yVCOEskXaK kD0eDb8gv25W71EDNT8JjdWm0mvmGBjIMJkHLFnkDiOUTq3Gn2uO+aBUCwQEvE6A ypKAJQVR9re/+SowqP5le+Ymrd3rtgkLEDF4jxdsJWs57r2hn/p2JR8cmvliXliS J6GI2EKlOyD/MskW57LWoGpNQL+OSJW9f8lCVovC2n6PozffTkhIF4k7/hg5bP8B zzyvw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 05/12] vfio/iommufd: Introduce auto domain creation Date: Fri, 12 Jul 2024 12:46:57 +0100 Message-Id: <20240712114704.8708-6-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=867 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: aOjonmZG0pXIktffvcoItsiZ4-Hgcr8P X-Proofpoint-ORIG-GUID: aOjonmZG0pXIktffvcoItsiZ4-Hgcr8P 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=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: 1720784977526116600 Content-Type: text/plain; charset="utf-8" There's generally two modes of operation for IOMMUFD: * The simple user API which intends to perform relatively simple things with IOMMUs e.g. DPDK. It generally creates an IOAS and attach to VFIO and mainly performs IOAS_MAP and UNMAP. * The native IOMMUFD API where you have fine grained control of the IOMMU domain and model it accordingly. This is where most new feature are being steered to. For dirty tracking 2) is required, as it needs to ensure that the stage-2/parent IOMMU domain will only attach devices that support dirty tracking (so far it is all homogeneous in x86, likely not the case for smmuv3). Such invariant on dirty tracking provides a useful guarantee to VMMs that will refuse incompatible device attachments for IOMMU domains. Dirty tracking insurance is enforced via HWPT_ALLOC, which is responsible for creating an IOMMU domain. This is contrast to the 'simple API' where the IOMMU domain is created by IOMMUFD automatically when it attaches to VFIO (usually referred as autodomains) but it has the needed handling for mdevs. To support dirty tracking with the advanced IOMMUFD API, it needs similar logic, where IOMMU domains are created and devices attached to compatible domains. Essentially mimmicing kernel iommufd_device_auto_get_domain(). With mdevs given there's no IOMMU domain it falls back to IOAS attach. The auto domain logic allows different IOMMU domains to be created when DMA dirty tracking is not desired (and VF can provide it), and others where it is. Here is not used in this way here given how VFIODevice migration state is initialized after the device attachment. But such mixed mode of IOMMU dirty tracking + device dirty tracking is an improvement that can be added on. Keep the 'all of nothing' of type1 approach that we have been using so far between container vs device dirty tracking. Signed-off-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 9 ++++ include/sysemu/iommufd.h | 5 +++ backends/iommufd.c | 30 +++++++++++++ hw/vfio/iommufd.c | 82 +++++++++++++++++++++++++++++++++++ backends/trace-events | 1 + 5 files changed, 127 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 7419466bca92..2dd468ce3c02 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -95,10 +95,17 @@ typedef struct VFIOHostDMAWindow { =20 typedef struct IOMMUFDBackend IOMMUFDBackend; =20 +typedef struct VFIOIOASHwpt { + uint32_t hwpt_id; + QLIST_HEAD(, VFIODevice) device_list; + QLIST_ENTRY(VFIOIOASHwpt) next; +} VFIOIOASHwpt; + typedef struct VFIOIOMMUFDContainer { VFIOContainerBase bcontainer; IOMMUFDBackend *be; uint32_t ioas_id; + QLIST_HEAD(, VFIOIOASHwpt) hwpt_list; } VFIOIOMMUFDContainer; =20 OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD); @@ -135,6 +142,8 @@ typedef struct VFIODevice { HostIOMMUDevice *hiod; int devid; IOMMUFDBackend *iommufd; + VFIOIOASHwpt *hwpt; + QLIST_ENTRY(VFIODevice) hwpt_next; } VFIODevice; =20 struct VFIODeviceOps { diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 57d502a1c79a..e917e7591d05 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -50,6 +50,11 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32= _t ioas_id, bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, uint32_t *type, void *data, uint32_t = len, uint64_t *caps, Error **errp); +bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id, + uint32_t pt_id, uint32_t flags, + uint32_t data_type, uint32_t data_len, + void *data_ptr, uint32_t *out_hwpt, + Error **errp); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 2b3d51af26d2..5d3dfa917415 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -208,6 +208,36 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint= 32_t ioas_id, return ret; } =20 +bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id, + uint32_t pt_id, uint32_t flags, + uint32_t data_type, uint32_t data_len, + void *data_ptr, uint32_t *out_hwpt, + Error **errp) +{ + int ret, fd =3D be->fd; + struct iommu_hwpt_alloc alloc_hwpt =3D { + .size =3D sizeof(struct iommu_hwpt_alloc), + .flags =3D flags, + .dev_id =3D dev_id, + .pt_id =3D pt_id, + .data_type =3D data_type, + .data_len =3D data_len, + .data_uptr =3D (uint64_t)data_ptr, + }; + + ret =3D ioctl(fd, IOMMU_HWPT_ALLOC, &alloc_hwpt); + trace_iommufd_backend_alloc_hwpt(fd, dev_id, pt_id, flags, data_type, + data_len, (uint64_t)data_ptr, + alloc_hwpt.out_hwpt_id, ret); + if (ret) { + error_setg_errno(errp, errno, "Failed to allocate hwpt"); + return false; + } + + *out_hwpt =3D alloc_hwpt.out_hwpt_id; + return true; +} + bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, uint32_t *type, void *data, uint32_t = len, uint64_t *caps, Error **errp) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 077dea8f1b64..325c7598d5a1 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -212,10 +212,86 @@ static bool iommufd_cdev_detach_ioas_hwpt(VFIODevice = *vbasedev, Error **errp) return true; } =20 +static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, + VFIOIOMMUFDContainer *container, + Error **errp) +{ + IOMMUFDBackend *iommufd =3D vbasedev->iommufd; + uint32_t flags =3D 0; + VFIOIOASHwpt *hwpt; + uint32_t hwpt_id; + int ret; + + /* Try to find a domain */ + QLIST_FOREACH(hwpt, &container->hwpt_list, next) { + ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, err= p); + if (ret) { + /* -EINVAL means the domain is incompatible with the device. */ + if (ret =3D=3D -EINVAL) { + /* + * It is an expected failure and it just means we will try + * another domain, or create one if no existing compatible + * domain is found. Hence why the error is discarded below. + */ + error_free(*errp); + *errp =3D NULL; + continue; + } + + return false; + } else { + vbasedev->hwpt =3D hwpt; + QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); + return true; + } + } + + if (!iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid, + container->ioas_id, flags, + IOMMU_HWPT_DATA_NONE, 0, NULL, + &hwpt_id, errp)) { + return false; + } + + hwpt =3D g_malloc0(sizeof(*hwpt)); + hwpt->hwpt_id =3D hwpt_id; + QLIST_INIT(&hwpt->device_list); + + ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp); + if (ret) { + iommufd_backend_free_id(container->be, hwpt->hwpt_id); + g_free(hwpt); + return false; + } + + vbasedev->hwpt =3D hwpt; + QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); + QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next); + return true; +} + +static void iommufd_cdev_autodomains_put(VFIODevice *vbasedev, + VFIOIOMMUFDContainer *container) +{ + VFIOIOASHwpt *hwpt =3D vbasedev->hwpt; + + QLIST_REMOVE(vbasedev, hwpt_next); + if (QLIST_EMPTY(&hwpt->device_list)) { + QLIST_REMOVE(hwpt, next); + iommufd_backend_free_id(container->be, hwpt->hwpt_id); + g_free(hwpt); + } +} + static bool iommufd_cdev_attach_container(VFIODevice *vbasedev, VFIOIOMMUFDContainer *container, Error **errp) { + /* mdevs aren't physical devices and will fail with auto domains */ + if (!vbasedev->mdev) { + return iommufd_cdev_autodomains_get(vbasedev, container, errp); + } + return !iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, er= rp); } =20 @@ -224,6 +300,11 @@ static void iommufd_cdev_detach_container(VFIODevice *= vbasedev, { Error *err =3D NULL; =20 + if (vbasedev->hwpt) { + iommufd_cdev_autodomains_put(vbasedev, container); + return; + } + if (!iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { error_report_err(err); } @@ -354,6 +435,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, container =3D VFIO_IOMMU_IOMMUFD(object_new(TYPE_VFIO_IOMMU_IOMMUFD)); container->be =3D vbasedev->iommufd; container->ioas_id =3D ioas_id; + QLIST_INIT(&container->hwpt_list); =20 bcontainer =3D &container->bcontainer; vfio_address_space_insert(space, bcontainer); diff --git a/backends/trace-events b/backends/trace-events index 211e6f374adc..4d8ac02fe7d6 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -14,4 +14,5 @@ iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint6= 4_t iova, uint64_t size iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t i= ova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=3D%d ioas= =3D%d iova=3D0x%"PRIx64" size=3D0x%"PRIx64" (%d)" iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint6= 4_t size, int ret) " iommufd=3D%d ioas=3D%d iova=3D0x%"PRIx64" size=3D0x%"P= RIx64" (%d)" iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=3D%d ioas= =3D%d" +iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, u= int32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_= t out_hwpt_id, int ret) " iommufd=3D%d dev_id=3D%u pt_id=3D%u flags=3D0x%x = hwpt_type=3D%u len=3D%u data_ptr=3D0x%"PRIx64" out_hwpt=3D%u (%d)" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784948; cv=none; d=zohomail.com; s=zohoarc; b=BXz/dBXHUlEgRgt40IjxFWR2rUfEh3rOVRMPycDoRpyfkIJuEeOyr8/5R9jgnrhFGlaxesjkSbfSea8RvWSHJqvlOSZ7vH24ohy9czDCCm8Wrtu8LD6bTEcgdokTfal6Hda7rPdB3aWoX6VtTEi4YD5p41W4/4LEYaWCyeyr5Rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784948; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5rzZgaurg3uuiaZ3o8czx3hGgHHFONmGGwlQtj3jByE=; b=GQlI12HuRAhhP/8rGTpYbN0Yq4QHjxITfxJfUyu/j4qBqwgEFuXlq7T5jWVO6Dp5KyhDIvYGf6CfDSU984IKxIUIStiUg3iZASZ2GzllYrFwDsoEtkZmbQeYbSdIrI91r2A0+GUEPDinf4Zr3mc2MZByUqKPj1U2Z73fG0j2UEU= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784948508952.8069960457983; Fri, 12 Jul 2024 04:49:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkq-0006Mw-7n; Fri, 12 Jul 2024 07:48:00 -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 1sSEkR-0005XV-Bc for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:35 -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 1sSEkP-0007eW-FV for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:34 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BY8R020921; Fri, 12 Jul 2024 11:47:30 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt30ah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:30 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CA6MoJ022627; Fri, 12 Jul 2024 11:47:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq5p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:29 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCe008041; Fri, 12 Jul 2024 11:47:29 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-7; Fri, 12 Jul 2024 11:47:28 +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-11-20; bh=5 rzZgaurg3uuiaZ3o8czx3hGgHHFONmGGwlQtj3jByE=; b=hlb0TfRgXMiwS2EsN Cchq+687hhokU8ov+B/8U0wReaZNGTAP5b1ELNFPt+MC/lZYGSjwKujcapMUR1Xv ZOYU4yojKeTsJSeApA1sikKW2geGp5n8JybQLrRAhVJ1X6NRsWYz4K0B31umlL4W 83VGe56D0ge2UZkEfo+sD5wm7+DSycQRcZ0fMnvZ0CxR5bjqr1VZcatOy3ekF6cp 9u4lXG+XnDU0SwROToGCYtiGQiswqhBhyg/iXy1AZ/HjxsYcWkt705CnFISoJk1b vNyeiPilFPccE3ARfK/VD/2YKwOGEoOLRZXkP6Dxh8nBBlZsd2h3NRE73iW92qID Xxt+Q== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 06/12] vfio/{iommufd,container}: Remove caps::aw_bits Date: Fri, 12 Jul 2024 12:46:58 +0100 Message-Id: <20240712114704.8708-7-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=951 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: ILbVIHpq5fYhkAY5lM2u1HWxf4XJAqLm X-Proofpoint-ORIG-GUID: ILbVIHpq5fYhkAY5lM2u1HWxf4XJAqLm 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784949425116600 Content-Type: text/plain; charset="utf-8" In preparation to moving HostIOMMUDevice realize() being able to called early during attach_device(), remove properties that rely on container being initialized. This means removing caps::aw_bits which requires the bcontainer::iova_ranges to be inititalized after device is actually attached. Instead defer that to .get_cap() and call vfio_device_get_aw_bits() directly. Suggested-by: Zhenzhong Duan Signed-off-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater --- include/sysemu/host_iommu_device.h | 1 - backends/iommufd.c | 3 ++- hw/vfio/container.c | 5 +---- hw/vfio/iommufd.c | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index ee6c813c8b22..20e77cf54568 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -24,7 +24,6 @@ */ typedef struct HostIOMMUDeviceCaps { uint32_t type; - uint8_t aw_bits; } HostIOMMUDeviceCaps; =20 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" diff --git a/backends/iommufd.c b/backends/iommufd.c index 5d3dfa917415..41a9dec3b2c5 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -18,6 +18,7 @@ #include "qemu/error-report.h" #include "monitor/monitor.h" #include "trace.h" +#include "hw/vfio/vfio-common.h" #include #include =20 @@ -270,7 +271,7 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, = int cap, Error **errp) case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE: return caps->type; case HOST_IOMMU_DEVICE_CAP_AW_BITS: - return caps->aw_bits; + return vfio_device_get_aw_bits(hiod->agent); default: error_setg(errp, "%s: unsupported capability %x", hiod->name, cap); return -EINVAL; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 88ede913d6f7..c27f448ba26e 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1144,7 +1144,6 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice = *hiod, void *opaque, VFIODevice *vdev =3D opaque; =20 hiod->name =3D g_strdup(vdev->name); - hiod->caps.aw_bits =3D vfio_device_get_aw_bits(vdev); hiod->agent =3D opaque; =20 return true; @@ -1153,11 +1152,9 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice= *hiod, void *opaque, static int hiod_legacy_vfio_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp) { - HostIOMMUDeviceCaps *caps =3D &hiod->caps; - switch (cap) { case HOST_IOMMU_DEVICE_CAP_AW_BITS: - return caps->aw_bits; + return vfio_device_get_aw_bits(hiod->agent); default: error_setg(errp, "%s: unsupported capability %x", hiod->name, cap); return -EINVAL; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 325c7598d5a1..873c919e319c 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -722,7 +722,6 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *= hiod, void *opaque, =20 hiod->name =3D g_strdup(vdev->name); caps->type =3D type; - caps->aw_bits =3D vfio_device_get_aw_bits(vdev); =20 return true; } --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1720784985; cv=none; d=zohomail.com; s=zohoarc; b=TnaP5rh92xWYkS1CGZbxkYJk06/jDEb3YJTdjoRevQDAG/9ePfK3sljb6vSikn2uicoN4uj3xBRJ1A2ChaH+kMnCv1v3K9mzxUSRB6QYYCnUsU4vswG1WDbFXmoDk2ZXWn+R/Q3EbY5lv85De15PYRbk+ZDURWMdKiyqDNxRgY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784985; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=XfT1W7GX/5K7SqPB1l3VjJYEXfu3NPoeRozKhr2EtAU=; b=NJaUm+DXCryQsqc4NrRMfQUcN2KXCAR9rxF32DBwDppIhjGyXGCCWB2m8Uu0toU8BSSj7r3m5IYEjs6AOGAo8D1akZ54PKEqufW0sZxpyTmHocrFOGFUZr3kUHUM6Mo88BfJTHt55tQQMzsmviYq95/mCr87VqpZnyDOsySalrc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1720784984970961.9059758271081; Fri, 12 Jul 2024 04:49:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEko-0006GZ-IY; Fri, 12 Jul 2024 07:47:58 -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 1sSEkV-0005YK-Cn for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:44 -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 1sSEkS-0007eg-3l for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:38 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C9mTWI018637; Fri, 12 Jul 2024 11:47:33 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkckm89-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:33 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CAYOU9022020; Fri, 12 Jul 2024 11:47:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq6k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:32 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCg008041; Fri, 12 Jul 2024 11:47:31 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-8; Fri, 12 Jul 2024 11:47:31 +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-type:content-transfer-encoding; s= corp-2023-11-20; bh=XfT1W7GX/5K7SqPB1l3VjJYEXfu3NPoeRozKhr2EtAU=; b= L9+xp3WeSX244tB8EYKrfjQbP3x8bH5oFNWDafkRfL+OJPq4Vmx/L8QC0J56mkX1 n0WaDfXgS36eh/rRMUePIlzsFYf1udK+9n1C4Wg1lIoCSk7Vx1x7O0RFqzftUVp0 na972SC0/RQ66vbR7PbYOWThuc+PQchblnk5NdOC26ZmhOiDLgGoHBagi0/6w0tp nA5koR1NphXUgT6qqyw+zwm3GXnhwzUfUuaSuyA1yJZIwBv7JdHG4pBAAVG5Qafd 2UjHAAGn2fIK+JM/Vtv2mlMc4O7OXfsdA+hk8TN/Y1oy3JrP1wGtVy61bJwmlMgm Wjl58ryFkuyyWYQPw+yZ9w== To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 07/12] vfio/{iommufd, container}: Initialize HostIOMMUDeviceCaps during attach_device() Date: Fri, 12 Jul 2024 12:46:59 +0100 Message-Id: <20240712114704.8708-8-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-1-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-ORIG-GUID: hBUvswmuHey_5MiS-ejp6VIsy9JD1Nfz X-Proofpoint-GUID: hBUvswmuHey_5MiS-ejp6VIsy9JD1Nfz 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Joao Martins From: Joao Martins via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1720784985556116600 Fetch IOMMU hw raw caps behind the device and thus move the HostIOMMUDevice::realize() to be done during the attach of the device. It allows it to cache the information obtained from IOMMU_GET_HW_INFO from iommufd early on. However, while legacy HostIOMMUDevice caps always return true and doesn't have dependency on other things, the IOMMUFD backend requires the iommufd FD to be connected and having a devid to be able to query capabilities. Hence when exactly is HostIOMMUDevice initialized inside backend ::attach_device() implementation is backend specific. This is in preparation to fetch parse hw capabilities and understand if dirty tracking is supported by device backing IOMMU without necessarily duplicating the amount of calls we do to IOMMU_GET_HW_INFO. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Joao Martins --- include/sysemu/host_iommu_device.h | 1 + hw/vfio/common.c | 16 ++++++---------- hw/vfio/container.c | 6 ++++++ hw/vfio/iommufd.c | 7 +++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index 20e77cf54568..b1e5f4b8ac3e 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -24,6 +24,7 @@ */ typedef struct HostIOMMUDeviceCaps { uint32_t type; + uint64_t hw_caps; } HostIOMMUDeviceCaps; =20 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b0beed44116e..cc14f0e3fe24 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1544,7 +1544,7 @@ bool vfio_attach_device(char *name, VFIODevice *vbase= dev, { const VFIOIOMMUClass *ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); - HostIOMMUDevice *hiod; + HostIOMMUDevice *hiod =3D NULL; =20 if (vbasedev->iommufd) { ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMM= UFD)); @@ -1552,21 +1552,17 @@ bool vfio_attach_device(char *name, VFIODevice *vba= sedev, =20 assert(ops); =20 - if (!ops->attach_device(name, vbasedev, as, errp)) { - return false; - } =20 - if (vbasedev->mdev) { - return true; + if (!vbasedev->mdev) { + hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); + vbasedev->hiod =3D hiod; } =20 - hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); - if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp))= { + if (!ops->attach_device(name, vbasedev, as, errp)) { object_unref(hiod); - ops->detach_device(vbasedev); + vbasedev->hiod =3D NULL; return false; } - vbasedev->hiod =3D hiod; =20 return true; } diff --git a/hw/vfio/container.c b/hw/vfio/container.c index c27f448ba26e..29da261bbf3e 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -907,6 +907,7 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, AddressSpace *as, Error **errp) { int groupid =3D vfio_device_groupid(vbasedev, errp); + HostIOMMUDevice *hiod =3D vbasedev->hiod; VFIODevice *vbasedev_iter; VFIOGroup *group; VFIOContainerBase *bcontainer; @@ -917,6 +918,11 @@ static bool vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, =20 trace_vfio_attach_device(vbasedev->name, groupid); =20 + if (hiod && + !HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp))= { + return false; + } + group =3D vfio_get_group(groupid, as, errp); if (!group) { return false; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 873c919e319c..d34dc88231ec 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -384,6 +384,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, Error *err =3D NULL; const VFIOIOMMUClass *iommufd_vioc =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD)); + HostIOMMUDevice *hiod =3D vbasedev->hiod; =20 if (vbasedev->fd < 0) { devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); @@ -401,6 +402,11 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, =20 space =3D vfio_get_address_space(as); =20 + if (hiod && + !HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp))= { + return false; + } + /* try to attach to an existing container in this space */ QLIST_FOREACH(bcontainer, &space->containers, next) { container =3D container_of(bcontainer, VFIOIOMMUFDContainer, bcont= ainer); @@ -722,6 +728,7 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *= hiod, void *opaque, =20 hiod->name =3D g_strdup(vdev->name); caps->type =3D type; + caps->hw_caps =3D hw_caps; =20 return true; } --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784928; cv=none; d=zohomail.com; s=zohoarc; b=ENAXV30WglG5jgkNk2mj6hhm5W4gzglkPCPIPqGuk6EidEjLvIyJ8UIYprfLk++x3SFKET1HfTwT0r7EDGMEXng16fwkqHssabM9wd6Z2fnrkuj+6iZhgHmnjS3TmVmZqaF/pxEDdtgxMnwJ/g8qQ8zhkg1Qm5eP6NFmCysX/ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784928; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PaYmX+yn5KPsFmi4XTB1nAQuBi/DtSh0BCtwzQmnuas=; b=X5DxQxM4uZ0h4qi7drt/UQWYD5z1g/2kH3e0IkkgmntAaf7MxGIQcBuE8f54aVtQD0LWM8ZUkKV5DnXYdzkKmn5H5OWjtaROChWgtsfGKoNfOpxG62QDnReWhql177Dz1xSfjkOYY7YFXavx48kqBr8tqhQ1sWJ61ZsoAx5Zb2w= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784928358314.7393147809654; Fri, 12 Jul 2024 04:48:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkl-00066e-VM; Fri, 12 Jul 2024 07:47:55 -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 1sSEkc-0005ZR-3B for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47: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 1sSEkV-0007oF-52 for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:43 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1Brt3018742; Fri, 12 Jul 2024 11:47:36 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkckm8c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:35 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CAFTj9022608; Fri, 12 Jul 2024 11:47:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:34 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCi008041; Fri, 12 Jul 2024 11:47:34 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-9; Fri, 12 Jul 2024 11:47:34 +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-11-20; bh=P aYmX+yn5KPsFmi4XTB1nAQuBi/DtSh0BCtwzQmnuas=; b=QaWOizty1g0iw1aF9 zWBM4E8mVOn7G8M2FVUomZOfSeatE78qaEItbjZpxWUNHNAU7NtPZs4ZjKfH6USJ HVGhAarjzwK5R6H/rpmPXijZL3BbzTGAMfHgmK74J5vwgLfC6r9lRGTfMIMxp8c5 wg3eAyHrnxPGqdHqjqFZ30iCRRUZyQNpHzanFETTIyVuYI06CUB0W+Yt++HAtT9r cttWBsZczg3781wLMY2cJ0YbAYHIGZjaT4Lw9SeheUU5eaDWdgu47RpjpI0FBOMO aMxRjfryMKaFRZ9aheMCW1/wolLGBA47oRkNAHNrQyzIC1ai0Nmoumf1QsgUUvRV pV0wA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 08/12] vfio/iommufd: Probe and request hwpt dirty tracking capability Date: Fri, 12 Jul 2024 12:47:00 +0100 Message-Id: <20240712114704.8708-9-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-ORIG-GUID: bKfSXWAYz6Ey-Q9F6UTOUh6clR4lcBbp X-Proofpoint-GUID: bKfSXWAYz6Ey-Q9F6UTOUh6clR4lcBbp 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784929351116600 Content-Type: text/plain; charset="utf-8" Probe hardware dirty tracking support by querying device hw capabilities via IOMMUFD_GET_HW_INFO. In preparation to using the dirty tracking UAPI, request dirty tracking in = the HWPT flags when the IOMMU supports dirty tracking. The auto domain logic allows different IOMMU domains to be created when DMA dirty tracking is not desired (and VF can provide it) while others doesn't = have it and want the IOMMU capability. This is not used in this way here given h= ow VFIODevice migration capability checking takes place *after* the device attachment. Signed-off-by: Joao Martins --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/iommufd.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 2dd468ce3c02..760f31d84ac8 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -97,6 +97,7 @@ typedef struct IOMMUFDBackend IOMMUFDBackend; =20 typedef struct VFIOIOASHwpt { uint32_t hwpt_id; + uint32_t hwpt_flags; QLIST_HEAD(, VFIODevice) device_list; QLIST_ENTRY(VFIOIOASHwpt) next; } VFIOIOASHwpt; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index d34dc88231ec..edc8f97d8f3d 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -246,6 +246,15 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, } } =20 + /* + * This is quite early and VFIODevice isn't yet fully initialized, + * thus rely on IOMMU hardware capabilities as to whether IOMMU dirty + * tracking is going to be needed. + */ + if (vbasedev->hiod->caps.hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) { + flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + } + if (!iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid, container->ioas_id, flags, IOMMU_HWPT_DATA_NONE, 0, NULL, @@ -255,6 +264,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, =20 hwpt =3D g_malloc0(sizeof(*hwpt)); hwpt->hwpt_id =3D hwpt_id; + hwpt->hwpt_flags =3D flags; QLIST_INIT(&hwpt->device_list); =20 ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp); @@ -267,6 +277,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, vbasedev->hwpt =3D hwpt; QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next); + container->bcontainer.dirty_pages_supported |=3D + (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING); return true; } =20 --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720785027; cv=none; d=zohomail.com; s=zohoarc; b=IA1GZeJk1j0qADo0oMlS82EowIqLuQSjZlrFIx2AIyvu0O8y4bApmwnhroQ09uxRl5rGXPa5RMi7NJl0fE9tOVmTmt+vkxyBcEVoJlLiz92Nc0s/+husQif743Xgy2UKIVymA77fjwWR4e4vKIHMrv8uqq0bAZ5MCWXHBMV8hrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720785027; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EuP+9tx4Z2mEPUkxDDMNgGgs5n4zxPOhxuAcR4g1PNg=; b=QIqb5xpC/8DKfr3ium+feBUhHJK+kRguHLL5hWlxAcUAqBvpNR0oltvYvOATnFxBmxCP34by+Z+1lnuZKa40zq11RZssL33eby5a1O7ZGZQVPAu+VSQ/eogM6CBnhDfNwS7mfH9AytGxAI5ohYRHKWHnCwDYLsYkZ33myZhOj+g= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720785027835439.6499720474126; Fri, 12 Jul 2024 04:50:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkn-00069j-5B; Fri, 12 Jul 2024 07:47:57 -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 1sSEkd-0005aI-1M for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:48 -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 1sSEkZ-0007qX-Hr for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:46 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BY8T020921; Fri, 12 Jul 2024 11:47:39 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt30au-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CBVCmh022685; Fri, 12 Jul 2024 11:47:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:37 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCk008041; Fri, 12 Jul 2024 11:47:37 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-10; Fri, 12 Jul 2024 11:47:36 +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-11-20; bh=E uP+9tx4Z2mEPUkxDDMNgGgs5n4zxPOhxuAcR4g1PNg=; b=MC2h4KyQOnNyqcqE+ QQyLdLQ9dZX4HrcSAdKr3g0fin7X+6HaahWHmHijZyem6JuCpTKjl5OMc1B48DKo Nqha8tsgV3wBsr6AyWRRZ3a03auu+6i++TeLuCV9bmk9EzlOGjwJZCWvxMhOv3pk 4d9W3oKyWSGOlMNWhdhsUAQVgXyMKpdf2F8qZIKLB98cbGhzCIebHY+r+J4PUKYF +y+NOiEjtVP9+gyWn73CbBaWYQRAkXAAmclKZ/lx4O+X85LLgVcN051h014zMuFG lj66sILUUmhSeW0ucQI1kDbi46IJZ8oOqizEpaM8/3El/En+X9TeDmM7X6s85az0 x81UA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 09/12] vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support Date: Fri, 12 Jul 2024 12:47:01 +0100 Message-Id: <20240712114704.8708-10-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: 6XW-QbcQGThaYXj5oN6jvqLmDTd1WBFb X-Proofpoint-ORIG-GUID: 6XW-QbcQGThaYXj5oN6jvqLmDTd1WBFb 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720785029733116600 Content-Type: text/plain; charset="utf-8" ioctl(iommufd, IOMMU_HWPT_SET_DIRTY_TRACKING, arg) is the UAPI that enables or disables dirty page tracking. It is used if the hwpt has been created with dirty tracking supported domain (stored in hwpt::flags) and it is called on the whole list of iommu domains it is are tracking. On failure it rolls it back. The checking of hwpt::flags is introduced here as a second user and thus consolidate such check into a helper function iommufd_hwpt_dirty_tracking(). Signed-off-by: Joao Martins --- include/sysemu/iommufd.h | 3 +++ backends/iommufd.c | 23 +++++++++++++++++++++++ hw/vfio/iommufd.c | 39 ++++++++++++++++++++++++++++++++++++++- backends/trace-events | 1 + 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index e917e7591d05..7416d9219703 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -55,6 +55,9 @@ bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint3= 2_t dev_id, uint32_t data_type, uint32_t data_len, void *data_ptr, uint32_t *out_hwpt, Error **errp); +bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_= id, + bool start, Error **errp); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" + #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 41a9dec3b2c5..239f0976e0ad 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -239,6 +239,29 @@ bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, ui= nt32_t dev_id, return true; } =20 +bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, + uint32_t hwpt_id, bool start, + Error **errp) +{ + int ret; + struct iommu_hwpt_set_dirty_tracking set_dirty =3D { + .size =3D sizeof(set_dirty), + .hwpt_id =3D hwpt_id, + .flags =3D !start ? 0 : IOMMU_HWPT_DIRTY_TRACKING_ENABLE, + }; + + ret =3D ioctl(be->fd, IOMMU_HWPT_SET_DIRTY_TRACKING, &set_dirty); + trace_iommufd_backend_set_dirty(be->fd, hwpt_id, start, ret ? errno : = 0); + if (ret) { + error_setg_errno(errp, errno, + "IOMMU_HWPT_SET_DIRTY_TRACKING(hwpt_id %u) failed= ", + hwpt_id); + return false; + } + + return true; +} + bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, uint32_t *type, void *data, uint32_t = len, uint64_t *caps, Error **errp) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index edc8f97d8f3d..da678315faeb 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -110,6 +110,42 @@ static void iommufd_cdev_unbind_and_disconnect(VFIODev= ice *vbasedev) iommufd_backend_disconnect(vbasedev->iommufd); } =20 +static bool iommufd_hwpt_dirty_tracking(VFIOIOASHwpt *hwpt) +{ + return hwpt->hwpt_flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING; +} + +static int iommufd_set_dirty_page_tracking(const VFIOContainerBase *bconta= iner, + bool start, Error **errp) +{ + const VFIOIOMMUFDContainer *container =3D + container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer); + VFIOIOASHwpt *hwpt; + + QLIST_FOREACH(hwpt, &container->hwpt_list, next) { + if (!iommufd_hwpt_dirty_tracking(hwpt)) { + continue; + } + + if (!iommufd_backend_set_dirty_tracking(container->be, + hwpt->hwpt_id, start, errp= )) { + goto err; + } + } + + return 0; + +err: + QLIST_FOREACH(hwpt, &container->hwpt_list, next) { + if (!iommufd_hwpt_dirty_tracking(hwpt)) { + continue; + } + iommufd_backend_set_dirty_tracking(container->be, + hwpt->hwpt_id, !start, NULL); + } + return -EINVAL; +} + static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) { ERRP_GUARD(); @@ -278,7 +314,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next); container->bcontainer.dirty_pages_supported |=3D - (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING); + iommufd_hwpt_dirty_tracking(hwpt); return true; } =20 @@ -717,6 +753,7 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *= klass, void *data) vioc->attach_device =3D iommufd_cdev_attach; vioc->detach_device =3D iommufd_cdev_detach; vioc->pci_hot_reset =3D iommufd_cdev_pci_hot_reset; + vioc->set_dirty_page_tracking =3D iommufd_set_dirty_page_tracking; }; =20 static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, diff --git a/backends/trace-events b/backends/trace-events index 4d8ac02fe7d6..28aca3b859d4 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -16,3 +16,4 @@ iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uin= t64_t iova, uint64_t si iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=3D%d ioas= =3D%d" iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, u= int32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_= t out_hwpt_id, int ret) " iommufd=3D%d dev_id=3D%u pt_id=3D%u flags=3D0x%x = hwpt_type=3D%u len=3D%u data_ptr=3D0x%"PRIx64" out_hwpt=3D%u (%d)" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" +iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int r= et) " iommufd=3D%d hwpt=3D%u enable=3D%d (%d)" --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784940; cv=none; d=zohomail.com; s=zohoarc; b=YCr7R3WPBOVpfCe68UGRIFUNc5YLoFmk1dB8Bk2dnyKwkMiHH+8w92p8DWjfmGzt4eer0GrLFhH48BPAYavuCupszEgSOHztggXgCCtvBSXdo7sVnpjrLkRhnY8Z+F+KMjCgQl7ZYXQROhcldgEx5aq41KceGOcEpnROU1UVbKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784940; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S6fQMnCtnXxuVyEmu+fxuqWG1QuQN9WhUDqA8cjsF7Q=; b=I8LvFmMBUa9M9ueL9UMHgKdf6OPUKTB/W5azx3fU6TatsWML9b37x0ItD9saq2bGOHS1DsV1TH3IpJo8kEeZszRBq8nT6YSFAoMtQpjFp9fyPfaWEtpqkFUsQlkBSHe6G67QYsx0j2u73eU1+08cR/v2w4y5556Rw/zfyzkk8bo= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784940489384.64710968736233; Fri, 12 Jul 2024 04:49:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkl-00066b-VE; Fri, 12 Jul 2024 07:47:55 -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 1sSEkd-0005aH-1I for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:48 -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 1sSEka-0007rX-Rw for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:46 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BuLT021119; Fri, 12 Jul 2024 11:47:41 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt30aw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:41 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46C9ZjoU022757; Fri, 12 Jul 2024 11:47:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pq9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:40 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCm008041; Fri, 12 Jul 2024 11:47:39 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-11; Fri, 12 Jul 2024 11:47:39 +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-11-20; bh=S 6fQMnCtnXxuVyEmu+fxuqWG1QuQN9WhUDqA8cjsF7Q=; b=Voas6QlCJgzH0fQ4s EgkfxadAOxV7wuzUvUrjjj+yapdOUjfPgLEXkcTdrGl0QbeRjCRVKWuvAxZiCtsT CODu1QDpt6XeBHxnvirFVJuzfBuR0hz2SlNRlwXge2SiGbBIDm12RSVct5s4Si+2 fETd8VkUB9C+YJaUSfZ8HipBw86fR5r0yR67fjyaxoLygCAKj5eDBgp8gfXT+zrj vpxXbOpn0nXqcCxhFzp5iZr1MWXLinWogqrOrCXQqbSFYLy0XlIfNvM7c0+1wuTy eXtJl9od0bArWy7WzIoDrj916/bQdP6pPhLkozynGRS22IzUFGZOuRyYRi7uFHkt YQdIA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 10/12] vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support Date: Fri, 12 Jul 2024 12:47:02 +0100 Message-Id: <20240712114704.8708-11-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: HoAGbah5AF4iSuLiRbRZU7d-n64ClPPw X-Proofpoint-ORIG-GUID: HoAGbah5AF4iSuLiRbRZU7d-n64ClPPw 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784941429116600 Content-Type: text/plain; charset="utf-8" ioctl(iommufd, IOMMU_HWPT_GET_DIRTY_BITMAP, arg) is the UAPI that fetches the bitmap that tells what was dirty in an IOVA range. A single bitmap is allocated and used across all the hwpts sharing an IOAS which is then used in log_sync() to set Qemu global bitmaps. Signed-off-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- include/sysemu/iommufd.h | 4 ++++ backends/iommufd.c | 29 +++++++++++++++++++++++++++++ hw/vfio/iommufd.c | 27 +++++++++++++++++++++++++++ backends/trace-events | 1 + 4 files changed, 61 insertions(+) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 7416d9219703..869ca8b7ef59 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -57,6 +57,10 @@ bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint= 32_t dev_id, Error **errp); bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_= id, bool start, Error **errp); +bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id, + uint64_t iova, ram_addr_t size, + uint64_t page_size, uint64_t *data, + Error **errp); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" =20 diff --git a/backends/iommufd.c b/backends/iommufd.c index 239f0976e0ad..46be719cae71 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -262,6 +262,35 @@ bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend= *be, return true; } =20 +bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, + uint32_t hwpt_id, + uint64_t iova, ram_addr_t size, + uint64_t page_size, uint64_t *data, + Error **errp) +{ + int ret; + struct iommu_hwpt_get_dirty_bitmap get_dirty_bitmap =3D { + .size =3D sizeof(get_dirty_bitmap), + .hwpt_id =3D hwpt_id, + .iova =3D iova, + .length =3D size, + .page_size =3D page_size, + .data =3D (uintptr_t)data, + }; + + ret =3D ioctl(be->fd, IOMMU_HWPT_GET_DIRTY_BITMAP, &get_dirty_bitmap); + trace_iommufd_backend_get_dirty_bitmap(be->fd, hwpt_id, iova, size, + page_size, ret ? errno : 0); + if (ret) { + error_setg_errno(errp, errno, + "IOMMU_HWPT_GET_DIRTY_BITMAP (iova: 0x%"HWADDR_PR= Ix + " size: 0x%"HWADDR_PRIx") failed", iova, size); + return false; + } + + return true; +} + bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, uint32_t *type, void *data, uint32_t = len, uint64_t *caps, Error **errp) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index da678315faeb..1fd1558fa0c0 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -25,6 +25,7 @@ #include "qemu/cutils.h" #include "qemu/chardev_open.h" #include "pci.h" +#include "exec/ram_addr.h" =20 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr io= va, ram_addr_t size, void *vaddr, bool readonly) @@ -146,6 +147,31 @@ err: return -EINVAL; } =20 +static int iommufd_query_dirty_bitmap(const VFIOContainerBase *bcontainer, + VFIOBitmap *vbmap, hwaddr iova, + hwaddr size, Error **errp) +{ + VFIOIOMMUFDContainer *container =3D container_of(bcontainer, + VFIOIOMMUFDContainer, + bcontainer); + unsigned long page_size =3D qemu_real_host_page_size(); + VFIOIOASHwpt *hwpt; + + QLIST_FOREACH(hwpt, &container->hwpt_list, next) { + if (!iommufd_hwpt_dirty_tracking(hwpt)) { + continue; + } + + if (!iommufd_backend_get_dirty_bitmap(container->be, hwpt->hwpt_id, + iova, size, page_size, + vbmap->bitmap, errp)) { + return -EINVAL; + } + } + + return 0; +} + static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) { ERRP_GUARD(); @@ -754,6 +780,7 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *= klass, void *data) vioc->detach_device =3D iommufd_cdev_detach; vioc->pci_hot_reset =3D iommufd_cdev_pci_hot_reset; vioc->set_dirty_page_tracking =3D iommufd_set_dirty_page_tracking; + vioc->query_dirty_bitmap =3D iommufd_query_dirty_bitmap; }; =20 static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, diff --git a/backends/trace-events b/backends/trace-events index 28aca3b859d4..40811a316215 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -17,3 +17,4 @@ iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " = iommufd=3D%d ioas=3D%d" iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, u= int32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_= t out_hwpt_id, int ret) " iommufd=3D%d dev_id=3D%u pt_id=3D%u flags=3D0x%x = hwpt_type=3D%u len=3D%u data_ptr=3D0x%"PRIx64" out_hwpt=3D%u (%d)" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int r= et) " iommufd=3D%d hwpt=3D%u enable=3D%d (%d)" +iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t i= ova, uint64_t size, uint64_t page_size, int ret) " iommufd=3D%d hwpt=3D%u i= ova=3D0x%"PRIx64" size=3D0x%"PRIx64" page_size=3D0x%"PRIx64" (%d)" --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720785008; cv=none; d=zohomail.com; s=zohoarc; b=EGZyi2ClZ9NFUyqgJywI/VSZ0pbF2jVZfBXm1aDoBCTJgI323cjF6u1IAC+80S2oRTAKszUTltLg4toLL2rlOw+AaKLTr4fCQ7JAUmn5RjFT4tekUwhl/UIGmL2C+RqVweHxRhV5GA2aN0ReNHe7Hu8roUOX1Cf8kMKCP3OKEvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720785008; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=F9qEY422bL/t8pTSoUsLhV9ChrXPulROskOlqOD/lAQ=; b=MtzoyvhwQbRQTXB6pIciaSrjupViZZ+zJVbjLXpgNWTnLjxtTfrOi1hxUYOXSOQzsRIrJYxeByqMAnT7tz6ia7HTpGEAfF3eiXNTiGIkXA5WYfbYd5JsuDHayqLdVNTD0jxR3qXIHDA3QLnIr5QH3QVtlxao3ecWa/eq/iI3JTM= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720785008360925.8974179715476; Fri, 12 Jul 2024 04:50:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEkp-0006IO-4d; Fri, 12 Jul 2024 07:47:59 -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 1sSEke-0005dD-Cz for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:48 -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 1sSEkc-0007ro-Ox for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:48 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CBhSQa016077; Fri, 12 Jul 2024 11:47:44 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wknuq6r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:44 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CB9scu022104; Fri, 12 Jul 2024 11:47:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pqan-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:43 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCo008041; Fri, 12 Jul 2024 11:47:42 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-12; Fri, 12 Jul 2024 11:47:42 +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-11-20; bh=F 9qEY422bL/t8pTSoUsLhV9ChrXPulROskOlqOD/lAQ=; b=k4D+W686jTKgJpAnF bdd4Mio3Bsn9v6Od+fACOnib1hU0BWO591ClnZ9MHJ2C7krqBt8HrgdEiKDTvcXg MuOKSrT1Qhwsm0pVyOz8EcxMZaPvrtZBFTdDLBs3hSlvaiv7E5x4PpVz1B/yb7zn VO4zYVuwYv2ltudIvhi8mJbLRbE+ZZTmvEtqlyHGTGmaHhK2vLDUtB3Tagps6c12 PVfkj61OfDtMz6caKGfY+tofVRADNfCzMFhK4igHB/3iBg8a97xvW5V40+2kpKvk Xrv1AhmMpBKzBfVQxWrpOP3lNwoydCSb+7Lqwmmfbvmz5coSskeLEcKnYxck4m4o QOd6A== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 11/12] vfio/migration: Don't block migration device dirty tracking is unsupported Date: Fri, 12 Jul 2024 12:47:03 +0100 Message-Id: <20240712114704.8708-12-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=801 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: Ch8nmwXqntVhXG834lVTThQfRORlh-4N X-Proofpoint-ORIG-GUID: Ch8nmwXqntVhXG834lVTThQfRORlh-4N 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720785009613116600 Content-Type: text/plain; charset="utf-8" By default VFIO migration is set to auto, which will support live migration if the migration capability is set *and* also dirty page tracking is supported. For testing purposes one can force enable without dirty page tracking via enable-migration=3Don, but that option is generally left for testing purposes. So starting with IOMMU dirty tracking it can use to acomodate the lack of VF dirty page tracking allowing us to minimize the VF requirements for migration and thus enabling migration by default for those too. Signed-off-by: Joao Martins --- hw/vfio/migration.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 34d4be2ce1b1..ce3d1b6e9a25 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1036,7 +1036,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Err= or **errp) return !vfio_block_migration(vbasedev, err, errp); } =20 - if (!vbasedev->dirty_pages_supported) { + if (!vbasedev->dirty_pages_supported && + !vbasedev->bcontainer->dirty_pages_supported) { if (vbasedev->enable_migration =3D=3D ON_OFF_AUTO_AUTO) { error_setg(&err, "%s: VFIO device doesn't support device dirty track= ing", --=20 2.17.2 From nobody Sun Nov 24 19:05:55 2024 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=reject dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1720784974; cv=none; d=zohomail.com; s=zohoarc; b=YG5UqwH9GhMG4l/fphkVMuLkC0+qnOjl/XUsJ+mpqfMmDeBJy9fOq5I0w6/S8+gQBCk7giHCjTYBN7cao2MELRoYcwHQoKBp3thkGAKzsFDoRNsQ6YF7s7oWxaCuqJnlcFI+DM+XSmGsNEl/rLvPo6RJQlv94GdW22WzUKtU3xE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720784974; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WRoDhdlVzy9B2opOIDS3AcTB0O/W51Ruwc1+9204k1M=; b=NQWNYXshz9tajfK9Z3QLdutvr1J6iQFV0q9t2gLJ7WE0LXrzZlF6FyYfqQWiZ7XigzX1ns/8r/ddnzEq2lQv+YA2OF3Fq2AKHg/XMxTJCh8zokMZQ3gSoJHQMiTz8iNNppvNktIm3Mneuu/IcuLvLglMNC0OLWR26pzLXSFGxmY= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720784974733591.8904852605318; Fri, 12 Jul 2024 04:49:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSEko-0006Gv-Mo; Fri, 12 Jul 2024 07:47:58 -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 1sSEkl-00066X-SM for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:55 -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 1sSEkk-0007zd-6z for qemu-devel@nongnu.org; Fri, 12 Jul 2024 07:47:55 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46C1BY8U020921; Fri, 12 Jul 2024 11:47:47 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt30b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:47 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46CBMAQh022638; Fri, 12 Jul 2024 11:47:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3pqc9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 11:47:46 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 46CBlCCq008041; Fri, 12 Jul 2024 11:47:45 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-0-59.vpn.oracle.com [10.175.0.59]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 409vv3ppxv-13; Fri, 12 Jul 2024 11:47:45 +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-11-20; bh=W RoDhdlVzy9B2opOIDS3AcTB0O/W51Ruwc1+9204k1M=; b=bedHL7TLMhYHl/wzi MQ8gIlrllxOctpKS8bnT2wRyOKUZXKm5Z8QOEI0hJsXU1fbBE1x45G1RJiBYMSYU ywKo8dVgZVJ95/Sy0+pUOCSN4Q4D4DYmiNB9Atia6zwKFMv9XxfgKz0SWmpKZpZh P53ElPZMwxvY11LUVUN+tPv7C7qGwHKezXTionoPLpqidIMm8FX026AfyiKKHNNf +DcpymGZSC1Wyc45+CupA1a6Ea6QxM23XIB9LdXULZ7en0sfK0Fp8XZpcRPt+keB wdLN8J3vcp7YUHhUROC2fYWpi/GM8mG7H+FZ2OJV9o+wOO1b03YR64ukqYZCfPXH /0WMw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Yi Liu , Eric Auger , Zhenzhong Duan , Alex Williamson , Cedric Le Goater , Jason Gunthorpe , Avihai Horon , Joao Martins Subject: [PATCH v4 12/12] vfio/common: Allow disabling device dirty page tracking Date: Fri, 12 Jul 2024 12:47:04 +0100 Message-Id: <20240712114704.8708-13-joao.m.martins@oracle.com> In-Reply-To: <20240712114704.8708-1-joao.m.martins@oracle.com> References: <20240712114704.8708-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.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_08,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=989 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120080 X-Proofpoint-GUID: ukL3BwipKXXPxQVkJv7RQAkgrGmj0Gqv X-Proofpoint-ORIG-GUID: ukL3BwipKXXPxQVkJv7RQAkgrGmj0Gqv 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , 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: 1720784975504116600 Content-Type: text/plain; charset="utf-8" The property 'x-pre-copy-dirty-page-tracking' allows disabling the whole tracking of VF pre-copy phase of dirty page tracking, though it means that it will only be used at the start of the switchover phase. Add an option that disables the VF dirty page tracking, and fall back into container-based dirty page tracking. This also allows to use IOMMU dirty tracking even on VFs with their own dirty tracker scheme. Signed-off-by: Joao Martins --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 3 +++ hw/vfio/migration.c | 3 ++- hw/vfio/pci.c | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 760f31d84ac8..0ed4ebfb4696 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -138,6 +138,7 @@ typedef struct VFIODevice { VFIOMigration *migration; Error *migration_blocker; OnOffAuto pre_copy_dirty_page_tracking; + OnOffAuto device_dirty_page_tracking; bool dirty_pages_supported; bool dirty_tracking; HostIOMMUDevice *hiod; diff --git a/hw/vfio/common.c b/hw/vfio/common.c index cc14f0e3fe24..070a4a2df020 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -199,6 +199,9 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOC= ontainerBase *bcontainer) VFIODevice *vbasedev; =20 QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { + if (vbasedev->device_dirty_page_tracking =3D=3D ON_OFF_AUTO_OFF) { + return false; + } if (!vbasedev->dirty_pages_supported) { return false; } diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index ce3d1b6e9a25..9b41db367629 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1036,7 +1036,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Err= or **errp) return !vfio_block_migration(vbasedev, err, errp); } =20 - if (!vbasedev->dirty_pages_supported && + if ((!vbasedev->dirty_pages_supported || + vbasedev->device_dirty_page_tracking =3D=3D ON_OFF_AUTO_OFF) && !vbasedev->bcontainer->dirty_pages_supported) { if (vbasedev->enable_migration =3D=3D ON_OFF_AUTO_AUTO) { error_setg(&err, diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 3fc72e898a25..5794d72bd3ab 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3361,6 +3361,9 @@ static Property vfio_pci_dev_properties[] =3D { DEFINE_PROP_ON_OFF_AUTO("x-pre-copy-dirty-page-tracking", VFIOPCIDevic= e, vbasedev.pre_copy_dirty_page_tracking, ON_OFF_AUTO_ON), + DEFINE_PROP_ON_OFF_AUTO("x-device-dirty-page-tracking", VFIOPCIDevice, + vbasedev.device_dirty_page_tracking, + ON_OFF_AUTO_ON), DEFINE_PROP_ON_OFF_AUTO("display", VFIOPCIDevice, display, ON_OFF_AUTO_OFF), DEFINE_PROP_UINT32("xres", VFIOPCIDevice, display_xres, 0), --=20 2.17.2