From nobody Sun Nov 24 18:35:07 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=1720449311; cv=none; d=zohomail.com; s=zohoarc; b=JK2CYHhSjgP3WgzcoVJME/EzBrTUvq7SFxgeiXsxFkKDIipncf3AWGTdeVqntDYE/Q5PRxtuM/pwXl09XkTUTuC1O+OEyYNwluAUQ+1hhMi+B7MESxslMnke3yme+XSeLeTU2sYbyWLVuycLvrwOV2qyC0VDx9zpTKPdS4H06X8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449311; 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=I3o+Y3tPTDDhYqxDwGJca8lPCovvHqZ6UeePhw50hUk=; b=Zk3+FsfnnBv7RGFs1M53HQU8HuGx7WbSfmSJHXvvRkY6L9aeuxKqB8y2hN9e8iDTznmiRuLnFv4NTofhAd7wX8YLrNokx0lH7nomUOMt/bCwAyvLMbWqZY3afBkRlBgQwU6JTaNUM139mDcqrVuGOu5EfYaGVRqNLSNusta48M0= 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 1720449311497722.4530025994687; Mon, 8 Jul 2024 07:35:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpRv-0003ck-Ej; Mon, 08 Jul 2024 10:34:39 -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 1sQpRs-0003Sq-UV for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:37 -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 1sQpRq-0002Sf-SF for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:36 -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 4687fSJj000593; Mon, 8 Jul 2024 14:34:31 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkcas6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:31 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468D8MPC007177; Mon, 8 Jul 2024 14:34:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r6rb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:31 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZ5037381; Mon, 8 Jul 2024 14:34:30 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-2; Mon, 08 Jul 2024 14:34:30 +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=I 3o+Y3tPTDDhYqxDwGJca8lPCovvHqZ6UeePhw50hUk=; b=EhafbAVseaxrLbega 5cBGAbzghb/IJsNxjXiqwy/5VJoQj8dtHp2jaDOyqGQkgjBtv7bapk1EKjAKa2xZ 3GjR2+qqJhofQzSqzI8xKwPJLwe4pTmFwsYEBUWjw80K9rBM1nvVED7TW8tVSoxK vpjylhqNYONSSEd1Qre0buM5Q7ikFf4hE9CkxuYi0xsAJbY+sDCgx8o6c8Ag1V8v ZS46jTKqPZBEZjsBdNsXRm/YbhULBmisys2GdzBU/2wRzQytqcbdeoJ14PyastNg /byHh9oAyV9QJk9B6Z/n3mNwzwMQUYecxW95vzpB2imTaVQaVDpr6jksnY3ZWZhN ocZNw== 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 v3 01/10] vfio/iommufd: Don't fail to realize on IOMMU_GET_HW_INFO failure Date: Mon, 8 Jul 2024 15:34:11 +0100 Message-Id: <20240708143420.16953-2-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=824 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-ORIG-GUID: fEVxUn7o1_-aHk7FTJgBBWixuUiUYYVu X-Proofpoint-GUID: fEVxUn7o1_-aHk7FTJgBBWixuUiUYYVu 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: 1720449313195100007 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 filling caps info when IOMMU_GET_HW_INFO succeeds plus discarding the error we would get into iommufd_backend_get_device_info(). Cc: Zhenzhong Duan =20 Fixes: 930589520128 ("vfio/iommufd: Implement HostIOMMUDeviceClass::realize= () handler") Signed-off-by: Joao Martins --- hw/vfio/iommufd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index c2f158e60386..a4d23f488b01 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -631,15 +631,13 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice= *hiod, void *opaque, =20 hiod->agent =3D opaque; =20 - if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, - &type, &data, sizeof(data), errp)= ) { - return false; + if (iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, + &type, &data, sizeof(data), NULL)= ) { + hiod->name =3D g_strdup(vdev->name); + caps->type =3D type; + caps->aw_bits =3D vfio_device_get_aw_bits(vdev); } =20 - hiod->name =3D g_strdup(vdev->name); - caps->type =3D type; - caps->aw_bits =3D vfio_device_get_aw_bits(vdev); - return true; } =20 --=20 2.17.2 From nobody Sun Nov 24 18:35:07 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=1720449319; cv=none; d=zohomail.com; s=zohoarc; b=MWGls+mrnxQWkW2UPznzygG2+BQG91wrr7xUA1gWhSXHqXBZc28t9gM+L8IfWgOfIXEIDjvrGGj8hEMevGLUEezjQ7EEkFCrQznAuuPboenoDH93+2uNPrtRwVQnvplVSgTeM9gsQmKiGEZl2Crv5p6xi7DVvySUIQMO3mLRhbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449319; 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=DjsII+DNYKco05c74h+Jixdr9avjNbNwMO03qwOWNPU=; b=KRTFr2shNEgB9orVXxuASvoimSciXfeIkcg+F3vgg/mvIKlqqf0Hyqa/lm0L6F7WbBlLmDJMjlZl33BfWeWHPgFb6S0n45g2fdTahH7dl1KDA2OeJCaGkX2p0uHquPP+CafGv0eHIyCBgdwG2zulvi6nMZOllANQxX0OMxANMdQ= 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 1720449319703122.18167180636271; Mon, 8 Jul 2024 07:35:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpRw-0003fa-7c; Mon, 08 Jul 2024 10:34:40 -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 1sQpRt-0003VW-Jx for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:37 -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 1sQpRr-0002T1-QR for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:37 -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 4687fWid018091; Mon, 8 Jul 2024 14:34:34 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emst65v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:33 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DJVi9007488; Mon, 8 Jul 2024 14:34:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r6sk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:33 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZ7037381; Mon, 8 Jul 2024 14:34:32 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-3; Mon, 08 Jul 2024 14:34:32 +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=D jsII+DNYKco05c74h+Jixdr9avjNbNwMO03qwOWNPU=; b=G9dVd04LpQvGHLald M/xvrC2o9YKiFA5kGgVoFtrl70tqnov1xIHtPrUNLYLNwajKai9H4c/PNJ6J5R2m Txx+ArNhgvW3pgql/SbQC/j3PCDxeqlSHBNV0K39eN67fJRRjaRJezSblMzSE0Gj Xtqx6DKE26x6uGXnilokbOH37XopR+Mh/bifpnaDSsT6Tfd8Sqx4WgGdL9KsUfHM RTjRoF/gW5vQ7BjH/yqTHghMLl29qizU14Rktt6Bg8mf+xtw/8cv0DW9nm+bR0XV h3C6jknop1rTVJBrTTm1F/msbPNyjesOvomJhQ9Ycqbn3eagUahqkJnAl3H7ZZ9m zZFeQ== 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 v3 02/10] backends/iommufd: Extend iommufd_backend_get_device_info() to fetch HW capabilities Date: Mon, 8 Jul 2024 15:34:12 +0100 Message-Id: <20240708143420.16953-3-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=585 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-GUID: dDmXGX5jOYsCGIk3HUQRFiIJxwczqk1I X-Proofpoint-ORIG-GUID: dDmXGX5jOYsCGIk3HUQRFiIJxwczqk1I 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: 1720449321235100005 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 --- 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 a4d23f488b01..9cee71659b1c 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), NULL)= ) { + &type, &data, sizeof(data), + &hw_caps, NULL)) { hiod->name =3D g_strdup(vdev->name); caps->type =3D type; caps->aw_bits =3D vfio_device_get_aw_bits(vdev); --=20 2.17.2 From nobody Sun Nov 24 18:35:07 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=1720449310; cv=none; d=zohomail.com; s=zohoarc; b=HYZGQnGLapgbY3YFdHBe3MY7TKuZwsXOoaAfS0SxvAhrY4tudPbOBWcnr4qg5nE7J79VV9u6fY7i9Ux+rdPEQAC70xn5kky2uNkyiYxp5D4UaAb0apNS1IYcrcEaUc5tWOmLthgGZqu6CJ6TAra7j/l3CzjXS3qowDvrPpEVjC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449310; 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=x3j0+sR/TAD6m8XQ92iblNU4/A1p/wrxZ1UPJ/XqQ7U=; b=Uor3famyP+ICtTKsYAh1hMuVV4XQ4VNhaY6FlOZ4DEWsgWa5fVrD5+bNLPXWosYaOSgPDG/9KXXsfMaqvod4cu9GFdX8UmbsjLQETjDrde8XwjwSAwNKuNgH0YXA5vGlyGQJ6loQOiGDM2Kfd/l0c0LR/8uGFlmRGMUTyDy6Dj4= 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 1720449310854577.2623289203707; Mon, 8 Jul 2024 07:35:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpRy-0003qJ-0I; Mon, 08 Jul 2024 10:34:42 -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 1sQpRv-0003dL-Ds for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34: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 1sQpRu-0002Uw-0h for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:39 -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 4687fdY5017452; Mon, 8 Jul 2024 14:34:36 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wknjsrg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:35 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DIo26007172; Mon, 8 Jul 2024 14:34:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r6tf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:35 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZ9037381; Mon, 8 Jul 2024 14:34:34 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-4; Mon, 08 Jul 2024 14:34: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=x 3j0+sR/TAD6m8XQ92iblNU4/A1p/wrxZ1UPJ/XqQ7U=; b=oCHLkwh76FURm7pkR E6Lq0bRH9072f04Vw0jm2sowdO18m2KT63+z/yAM7jyfnM2Ah58bWu1c1JGR/w65 gRM1+LVMiYXU915PdAiaDnR74l1mYKpleR81ZgSrR6N0nAj0KHyZeDwIrW2tFa2D GJXcPMwvvvVWXK1KNSFWD2yrpxjtApTaLje0TjsY/JQAocD/llgQZuq856Oal/zo dsYaZGr+CpmuPDKaqDzL25Azn/BqxF/02hrWpBhx1h7Du/ZamDO2/0Mgg/9OWwyF lsMmafEGK8tjnZZpUfzemUkopt9xQl78V1x5L5nbiXsN59IwvLAuHizddPo3io0i 7WWbA== 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 v3 03/10] vfio/iommufd: Return errno in iommufd_cdev_attach_ioas_hwpt() Date: Mon, 8 Jul 2024 15:34:13 +0100 Message-Id: <20240708143420.16953-4-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=892 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-GUID: bYwBZkItY7kcA10f4jMNK5kdqeE9y3z7 X-Proofpoint-ORIG-GUID: bYwBZkItY7kcA10f4jMNK5kdqeE9y3z7 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: 1720449311192100001 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 --- 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 9cee71659b1c..5a5993b17c2e 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 18:35:07 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=1720449327; cv=none; d=zohomail.com; s=zohoarc; b=gEEQr62/jNORWktWTnkJ0GtAFfGpuNGNKYGL3opBqnjccALK2LLAaCJi0gVDTjkTnfzDew9w6aOmGzovkGzcsiDlkXPIW6fXTSKajpjAT4qV+rrCwv65uFPnFob/oM8rQuN5AGT76X4qw6bxtxVtL6SgkZI+OkIi4SGjPMReKjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449327; 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=02PXHCLRPKa9WgJgT5mUZoFmZ9VeggVdNrBfZfFWkmQ=; b=h59qz2Fadp6k+3eKIjaaKSJrh/p+h+trUW1kQkvVEh8sdP0LVM5IXkv9k6/ZgF6kUrx1k2gxWbpNDaGcwvJqoA1bb0pqVwg2wOfZ4JpaBaUs0B3A+fOoivy6+a/SidSP0lcfzLbZeTRWYVibsmS/+G5cyMZf3ieyKAcUnwzx4zM= 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 1720449327600806.1698630645852; Mon, 8 Jul 2024 07:35:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpS5-0004Fg-LO; Mon, 08 Jul 2024 10:34:49 -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 1sQpRz-0003yB-F6 for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:43 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQpRx-0002Ve-1Q for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:43 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4687fWWn004199; Mon, 8 Jul 2024 14:34:39 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wt8as6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:38 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DSCu0007764; Mon, 8 Jul 2024 14:34:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r6uu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:37 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZB037381; Mon, 8 Jul 2024 14:34:36 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-5; Mon, 08 Jul 2024 14:34: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=0 2PXHCLRPKa9WgJgT5mUZoFmZ9VeggVdNrBfZfFWkmQ=; b=nduGaVk1fj4ndrL8c pSGVQRWAnmbIND/jFUY6qgQlcYQ4R1kjrSbw/gFgF38/pxRqoQWnsyb5WPIBJuh7 ylHXsVr5FqCmSCPvl3aPYkyS0Ur6CV6/FxhJr4ATxgXsupW9PQmycny9KFitGeZB tqjFMnLQTn7bvS065cnmiB6nc/Hv9NQkwzpQ6sxPZsvn/UtV+PwJnvSrGfxhSHfu NRvVdPDAnz2dpxJ6WdMkq6po9n+Hgw2o/+n7UEp2TeEEHLDQFL8h8EdvyUryku5o Dj5bLUy46UnxXa08zOgBwCwZ20mc6hEaelnC9rcNkX2MYzUDDaSI2gHXeOvJjQ7d zqE+A== 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 v3 04/10] vfio/iommufd: Introduce auto domain creation Date: Mon, 8 Jul 2024 15:34:14 +0100 Message-Id: <20240708143420.16953-5-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=888 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-GUID: Y3F6SMoBJgXxiB-4f10f4q2RX2BNjSbi X-Proofpoint-ORIG-GUID: Y3F6SMoBJgXxiB-4f10f4q2RX2BNjSbi 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.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=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: 1720449329317100003 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(). If this fails (i.e. mdevs) it falls back to IOAS attach (which again is always the case for mdevs). 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' approach that we have been using so far between container vs device dirty tracking. Signed-off-by: Joao Martins --- include/hw/vfio/vfio-common.h | 9 ++++ include/sysemu/iommufd.h | 4 ++ backends/iommufd.c | 29 +++++++++++ hw/vfio/iommufd.c | 91 +++++++++++++++++++++++++++++++++++ backends/trace-events | 1 + 5 files changed, 134 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index e8ddf92bb185..82c5a4aaa61e 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); @@ -134,6 +141,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..35a8cec9780f 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -50,6 +50,10 @@ 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); +int 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); =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..f5f73eaf4a1a 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -208,6 +208,35 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint= 32_t ioas_id, return ret; } =20 +int 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) +{ + 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) { + ret =3D -errno; + error_report("IOMMU_HWPT_ALLOC failed: %m"); + } else { + *out_hwpt =3D alloc_hwpt.out_hwpt_id; + } + return ret; +} + 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 5a5993b17c2e..2ca9a32cc7b6 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -212,10 +212,95 @@ 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, NUL= L); + if (ret) { + /* -EINVAL means the domain is incompatible with the device. */ + if (ret =3D=3D -EINVAL) { + continue; + } + + return false; + } else { + vbasedev->hwpt =3D hwpt; + QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); + return true; + } + } + + ret =3D iommufd_backend_alloc_hwpt(iommufd, + vbasedev->devid, + container->ioas_id, flags, + IOMMU_HWPT_DATA_NONE, 0, NULL, &hwpt_= id); + if (ret) { + /* + * When there's no domains allocated we can still attempt a hardwa= re + * pagetable allocation for an mdev, which ends up returning -ENOE= NT + * This is benign and meant to fallback into IOAS attach, hence do= n't + * set 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) { + if (iommufd_cdev_autodomains_get(vbasedev, container, errp)) { + return true; + } + + /* + * iommufd_cdev_autodomains_get() may have an expected failure (-ENOEN= T) + * for mdevs as they aren't real physical devices. @errp is only set + * when real failures happened i.e. failing to attach to a newly creat= ed + * hardware pagetable. These are fatal and should fail the attachment. + */ + if (*errp) { + return false; + } + return !iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, er= rp); } =20 @@ -224,6 +309,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 +444,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 18:35:07 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=1720449333; cv=none; d=zohomail.com; s=zohoarc; b=DwP2eX9oYIvClTBodLxjCMwmS4KTLrthLE8RSLNY4FollV79Cpwc231QK17RBVM5x5+u6Uxk0Ng41McrOVPK6Umxwl3Sf8SDV0RnfgPviULWvIR+e8mEkpnZtcF0rsohk5Rl6XWSFsquZXkPy36KqO/KCX616ik/1No2KhErW7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449333; 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=omqdz6LORkl10HF1VrY2ibkkdtQlMHKO6ZlqBDCrQ0I=; b=bucIaUHEg5eaRdC3UgYiI5b1vJ5FbgTLZcSHGxg1rxqZMrlm/vd2cr/RK8nnm8mMJSTfGPl5G45jdIbdaDpP1XZo5D5uyt2POTpVGncFFG8AyfXhMrK80CaumiHGHOSjruH3MoZQ3/GmZ4kU71aK5Fy/FGFWLwKIOmkvk0MasO0= 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 1720449333323744.7498081314862; Mon, 8 Jul 2024 07:35:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpSC-0004s6-W6; Mon, 08 Jul 2024 10:34: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 1sQpRz-00041n-V5 for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:45 -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 1sQpRy-0002W3-5M for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34: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 4687fTnO000623; Mon, 8 Jul 2024 14:34:40 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkcas77-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:39 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DAx3n007229; Mon, 8 Jul 2024 14:34:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r6wc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:39 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZD037381; Mon, 8 Jul 2024 14:34:38 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-6; Mon, 08 Jul 2024 14:34:38 +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 mqdz6LORkl10HF1VrY2ibkkdtQlMHKO6ZlqBDCrQ0I=; b=dMrf+hnMDFUoNX3Om eDWppRsAPVkZDjU9SpJHIjwKwV9PoaHEPIDqgcg6gJgboypVp3KUz5VXMyIfdfSj gZzRMppkHXvo8qN3r9WUnoDp+2gQFf+6lupbRDwNIXO3zwIadP4j+Jpspovefv5w yPD3XR7pwlz0lMhOXlxHQstjG9YEHntKN8g/HqAZu37+fIqzEzeGky8bBZ9qV5K+ AhtpidFB2ykqNBbjXMzrzl6e9O7XZynXbw9YkZE4IjJRQCYg0Tz97xa9oGBcUPrB uzWpCV2Y5LFlmRSpfVHM0n0Ssjw/sCR0UYN8uIP8Y1BnxwxM0JXbWxCYIXwJkDTO i0hwQ== 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 v3 05/10] vfio/iommufd: Probe and request hwpt dirty tracking capability Date: Mon, 8 Jul 2024 15:34:15 +0100 Message-Id: <20240708143420.16953-6-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-ORIG-GUID: _HyqfmvQ3PIn2gxoSWlybGAuMma1mNBs X-Proofpoint-GUID: _HyqfmvQ3PIn2gxoSWlybGAuMma1mNBs 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: 1720449335340100003 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. But such granularity is a nice property that can be implemented later on. Signed-off-by: Joao Martins Suggested-by: C=C3=A9dric Le Goater devid, &type, + NULL, 0, &caps, NULL)) { + return false; + } + + return caps & IOMMU_HW_CAP_DIRTY_TRACKING; +} + static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, VFIOIOMMUFDContainer *container, Error **errp) @@ -239,6 +253,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 (iommufd_device_dirty_tracking(iommufd, vbasedev)) { + flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + } + ret =3D iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid, container->ioas_id, flags, @@ -255,6 +278,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 +291,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 18:35:07 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=1720449379; cv=none; d=zohomail.com; s=zohoarc; b=gf9HLuuCBAoMj8uUzvsHzFoU8koPdgRBA6Sn3n9vtrMHsRHxXkXLzYioIQA4hcoV/tUiXx5px5Ox+f1uHW2+pCS9+L18O5/BUe0h/kTBAQfH9XGh0pKpbCmPKUJsL3NqahaGiMnhMjufOKRDDiW04h8H0nBWPPIJHduGMrwvddk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449379; 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=sloJ7Sz8fnPO2dBz/IcKyOKnkH8S3tYg9nD2Ncf3WwY=; b=J1GtWCJ2QGAAOc7R6txzYg2dIu8WGoQln87ULh4VaQlqtwxrKTbH1j34ojz7YCfxMK/WrKZNmW9B/jwvfZZYewzvlPsJ1xaRe+vNOcUZH3/yBjvbztNTjm7lc8AlnHch+YZTfz04TKT0PKPNW+L0sheu2Zqm+ayPEvqWm+AcVUk= 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 1720449379191270.1597106482237; Mon, 8 Jul 2024 07:36:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpSD-0004vS-16; Mon, 08 Jul 2024 10:34: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 1sQpS3-0004LJ-Lw for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:49 -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 1sQpS0-0002Wm-MB for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34: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 4687fWsL018069; Mon, 8 Jul 2024 14:34:42 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emst66e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:42 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DL06L007830; Mon, 8 Jul 2024 14:34:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r6xx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:41 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZF037381; Mon, 8 Jul 2024 14:34:40 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-7; Mon, 08 Jul 2024 14:34:40 +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 loJ7Sz8fnPO2dBz/IcKyOKnkH8S3tYg9nD2Ncf3WwY=; b=XEtEBbVREdmuVjpv3 mm4x7XlyifYh0TyUbEHQbDzGySK9eH4CaX0oIifi+vRmdtTEtKrlIY86uxHvIBR4 0ss1kF6BIkyrVhxM8BN64FJVMl/M8V4UsLkUi2PTKz0Yb0d1YuloJNS7ovQ71iJb M+UK/OEmqSf1qzc5ZxWtMWbhvoUOQPsNnXDDvAfz9NxmihW1foMXqthg4JrQiJ0Y VZR19mkMyENZZI8JiZD/rNnpB4QgQgmK8xb+eFYGTVLnHsaFu3yHQgd4z6Bv5h+P 0BoQEHXntlWEV0cHCXe/uZzc97lU10gunCzXzmJs94RIRvRs0547O8zU+a1YKBBN 1TLtg== 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 v3 06/10] vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support Date: Mon, 8 Jul 2024 15:34:16 +0100 Message-Id: <20240708143420.16953-7-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-GUID: b8YQJzRFw0yB3K0BLsqGnvKZ4vzCMGVC X-Proofpoint-ORIG-GUID: b8YQJzRFw0yB3K0BLsqGnvKZ4vzCMGVC 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: 1720449379511100001 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 | 20 ++++++++++++++++++ hw/vfio/iommufd.c | 45 +++++++++++++++++++++++++++++++++++++++- backends/trace-events | 1 + 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 35a8cec9780f..1470377f55ba 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -54,6 +54,9 @@ int 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); +int iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_i= d, + bool start); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" + #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index f5f73eaf4a1a..69daabc27473 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -237,6 +237,26 @@ int iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uin= t32_t dev_id, return ret; } =20 +int iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_i= d, + bool start) +{ + 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); + if (ret) { + ret =3D -errno; + error_report("IOMMU_HWPT_SET_DIRTY_TRACKING failed: %s", + strerror(errno)); + } + return ret; +} + 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 1b5b46d28ed6..158a98cb3b12 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -110,6 +110,48 @@ 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); + int ret; + VFIOIOASHwpt *hwpt; + + QLIST_FOREACH(hwpt, &container->hwpt_list, next) { + if (!iommufd_hwpt_dirty_tracking(hwpt)) { + continue; + } + + ret =3D iommufd_backend_set_dirty_tracking(container->be, + hwpt->hwpt_id, start); + if (ret) { + ret =3D -errno; + error_setg_errno(errp, errno, + "Failed to start dirty tracking on hwpt_id %u= ", + hwpt->hwpt_id); + 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); + } + return ret; +} + static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) { ERRP_GUARD(); @@ -292,7 +334,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 @@ -734,6 +776,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 18:35:07 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=1720449379; cv=none; d=zohomail.com; s=zohoarc; b=TmMcL+586ywiV2w8OL0CWajNUIoulLOuwevZGCXv7ZPDCLmUMDa/dflKaco9xpS9+2ALpRBMXSX/il5hpTb8hP9n9pq2je53z/gok1dyAu3qp1PTrKA5ZBVjj+45HT3a029FXi39lqXVP6luwZmSFGIADGAQ7R/8BaiqhTWtfQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449379; 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=f1bRBqPzVSgljRFlFIl90pFkjgfs7i2Bi3J1zvMFLCg=; b=npLhpN62c4bYJoppIMifv7pb7KNQ/Cq1SvVrq1bfNDX+G4pO82vYIN7d627M6xYq9kwsXWRJY4c3pCYeD0TT5opNHfwclaq13aEuIeM63tMePbQ6qyomAj85rbUi83Iq8SB7+vzYJFBcTJyDoyUFFUBmQNoOUyMQjI2LzTyGcJc= 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 1720449379721885.0319887928355; Mon, 8 Jul 2024 07:36:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpSD-00055H-Qk; Mon, 08 Jul 2024 10:34: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 1sQpS7-0004cM-Ea for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:53 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQpS3-0002X1-EY for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:49 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4687fTfM004389; Mon, 8 Jul 2024 14:34:45 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406xfsjsky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:44 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DOSFK008768; Mon, 8 Jul 2024 14:34:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r715-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:43 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZH037381; Mon, 8 Jul 2024 14:34:42 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-8; Mon, 08 Jul 2024 14:34: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 1bRBqPzVSgljRFlFIl90pFkjgfs7i2Bi3J1zvMFLCg=; b=lEFRsp+/+9oito433 N9j0RZEGkR2bR8WA/JC4tVA9czSbPuJd6LXFm0w5PFLkl01SGKz3grMoJ3zRA7yC GaOPdiQgNfsvwoeLHKRlWcIEs0ODS0SbvfOD84djHbW1OO1wv5lVEQypN/LH652Z cioT7VLlSXMzIGv9P8ZT+kTmz51vkr/DM0wEFqcKnF/xwwidWd2cwJp6xSsopRKW HFexgq0qhgXmBdtPyPI0MT+6FbYSFgWcke0wR0KtCrExZ80ZVIpZaRqoaf/TaYB8 hrTVH3NGzXCRVdE8jfdcBFtfvzS/h0NH0ixKrcoKvNKCaDBiMopz9vykdHCGG0/r MqCIA== 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 v3 07/10] vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support Date: Mon, 8 Jul 2024 15:34:17 +0100 Message-Id: <20240708143420.16953-8-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=987 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-ORIG-GUID: SztYO9LI5O9lS_QbPm-tt_YdM2n2SPIf X-Proofpoint-GUID: SztYO9LI5O9lS_QbPm-tt_YdM2n2SPIf 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.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=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: 1720449381549100007 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 --- include/sysemu/iommufd.h | 3 +++ backends/iommufd.c | 26 ++++++++++++++++++++++++++ hw/vfio/iommufd.c | 34 ++++++++++++++++++++++++++++++++++ backends/trace-events | 1 + 4 files changed, 64 insertions(+) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 1470377f55ba..223f1ea14e84 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -56,6 +56,9 @@ int iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32= _t dev_id, void *data_ptr, uint32_t *out_hwpt); int iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_i= d, bool start); +int 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); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" =20 diff --git a/backends/iommufd.c b/backends/iommufd.c index 69daabc27473..b2d3bbd7c31b 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -257,6 +257,32 @@ int iommufd_backend_set_dirty_tracking(IOMMUFDBackend = *be, uint32_t hwpt_id, return ret; } =20 +int 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) +{ + 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); + if (ret) { + error_report("IOMMU_HWPT_GET_DIRTY_BITMAP (iova: 0x%"PRIx64 + " size: 0x%"PRIx64") failed: %s", iova, + size, strerror(errno)); + } + + return !ret ? 0 : -errno; +} + 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 158a98cb3b12..9fad47baed9e 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) @@ -152,6 +153,38 @@ err: return ret; } =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); + int ret; + VFIOIOASHwpt *hwpt; + unsigned long page_size; + + page_size =3D qemu_real_host_page_size(); + QLIST_FOREACH(hwpt, &container->hwpt_list, next) { + if (!iommufd_hwpt_dirty_tracking(hwpt)) { + continue; + } + + ret =3D iommufd_backend_get_dirty_bitmap(container->be, hwpt->hwpt= _id, + iova, size, page_size, + vbmap->bitmap); + if (ret) { + error_setg_errno(errp, ret, + "Failed to get dirty bitmap report, hwpt_id %= u, iova: " + "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx, + hwpt->hwpt_id, iova, size); + return ret; + } + } + + return 0; +} + static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) { ERRP_GUARD(); @@ -777,6 +810,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 18:35:07 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=1720449319; cv=none; d=zohomail.com; s=zohoarc; b=CYZxwhDnOrhEDSS8l4ivJFJxAMubLer8RyeBme3jH4uP7CeFho1NjSsP1Po1svcTMtnvoQkEqFBL0Sh4gmIgt/44QfmD1FwrcrhfUvherXgSy/dk2UOWx7VHyJ4uiJ4yvcOz/wgfu5Y+pUMWjN+/Yr2HGbSjRblkzgpudQ3vkWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449319; 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=VZFYf2w9uH843EDbavDX3kXTkQ2ntOH2OQJYTwoWxPY=; b=m63wtXqKIa9VEwyuHiAkjEb2E/IsoGGHYZJrc+R/il6NcjTLE4me1F6B8wvKQskLdyxjnMHDH7SHqG1yZxRbztrkzQHOQ4u4KOL4c7cb4MPifUwYLMqibUeZEDBbhF5yWTE/ENrUX3KGLLSdMjnBY1zP40c72ubT6ZfJ7a16jOQ= 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 1720449319800775.8188994391644; Mon, 8 Jul 2024 07:35:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpSF-0005Hb-KX; Mon, 08 Jul 2024 10:34: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 1sQpS7-0004cJ-EB for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:53 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQpS5-0002XM-B1 for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:51 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4687fUAp004411; Mon, 8 Jul 2024 14:34:47 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406xfsjsm0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:47 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DM5TM007590; Mon, 8 Jul 2024 14:34:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r73j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:45 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZJ037381; Mon, 8 Jul 2024 14:34:45 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-9; Mon, 08 Jul 2024 14:34: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=V ZFYf2w9uH843EDbavDX3kXTkQ2ntOH2OQJYTwoWxPY=; b=gS8DVRPTuiz8/dCj7 n5CgSqr07yQIBbNXamLfFEdB6QSlT2KYvYwKEnvDiqfEHYHY8Ya8wSwPw4mufgqi BbGv7eUMGcwqxpCj6rW/sxqgzBnJiv1dZauQ9j93EeR0G2hH5M1OJlD6U8/3SpA1 hUigspf3JRo7IES3nFWwTkHVcpLZ2PEB0bXV8SUNLU0Pri04WHVob4ZMPR1PDj81 qPcBpYrpPN2huElsYZUzC8ytp1bdE/x0TrvqVMeJynMLioBrpJsvxa/+8vKSm+28 /K51phNjVfPSU7bVJWrcD9MMrQ8ce1kN5YQm2pDcvcL7WHd8jl3uLNtGUVSk70OI f3DJA== 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 v3 08/10] vfio/iommufd: Parse hw_caps and store dirty tracking support Date: Mon, 8 Jul 2024 15:34:18 +0100 Message-Id: <20240708143420.16953-9-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=951 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-ORIG-GUID: JvqJKc-6J1A_vl2dZOV5RUwK0a4O7RjT X-Proofpoint-GUID: JvqJKc-6J1A_vl2dZOV5RUwK0a4O7RjT 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.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=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: 1720449321242100006 Content-Type: text/plain; charset="utf-8" Fetch capabilities from IOMMU device and add a capability to host-iommu-device to reflect whether backing IOMMU has dirty tracking. This is in preparation to relax the migration eligibility when device doesn't have dirty tracking. Signed-off-by: Joao Martins --- include/sysemu/host_iommu_device.h | 2 ++ backends/iommufd.c | 2 ++ hw/vfio/iommufd.c | 1 + 3 files changed, 5 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index ee6c813c8b22..d38a31693482 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -25,6 +25,7 @@ typedef struct HostIOMMUDeviceCaps { uint32_t type; uint8_t aw_bits; + bool dirty_tracking; } HostIOMMUDeviceCaps; =20 #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" @@ -97,6 +98,7 @@ struct HostIOMMUDeviceClass { */ #define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 #define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 +#define HOST_IOMMU_DEVICE_CAP_DIRTY_TRACKING 2 =20 #define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64 #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index b2d3bbd7c31b..9400d51004f0 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -314,6 +314,8 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, = int cap, Error **errp) switch (cap) { case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE: return caps->type; + case HOST_IOMMU_DEVICE_CAP_DIRTY_TRACKING: + return caps->dirty_tracking; case HOST_IOMMU_DEVICE_CAP_AW_BITS: return caps->aw_bits; default: diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 9fad47baed9e..2678801f1cad 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -832,6 +832,7 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *= hiod, void *opaque, hiod->name =3D g_strdup(vdev->name); caps->type =3D type; caps->aw_bits =3D vfio_device_get_aw_bits(vdev); + caps->dirty_tracking =3D (hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING); } =20 return true; --=20 2.17.2 From nobody Sun Nov 24 18:35:07 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=1720449349; cv=none; d=zohomail.com; s=zohoarc; b=Qza5tFIUDdTR50I3Mw1tI1mxn5v9oHP9SoAewSlwlxR4zlKrwQXzAG+tW4tCEVBKaUBXoRriC4NFZR13Kk9NuNTM5LFwMvJfGsaDq5pJEk7pplY/dfWr4u4AGpe9tEcy5q4plumBOvLk+UndHhSFzjeYE4Da6cFjrKt5BBZ4J5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449349; 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=h6QCvrXNXbMo96ylbAuUbody2amhcysKXy86lcrhEOE=; b=FIJblbE5YZCr61xn1KOgKYDb38HoqQ9i33Yk1Yb3UTo6VyyZGL+nKf+ag1EVLeGQ1IloMv1F1gYu3pxLR0nDSnFHQPrVl6baymQzV0O3rKnzwxzeUo2Hnxgs9mCE9ydpW2PvL0o3HDzNpqLBU5pJPRl5pv1/JhJr+bRzpEbeWnE= 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 1720449349786838.0112964124422; Mon, 8 Jul 2024 07:35:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpSF-0005Iq-Qs; Mon, 08 Jul 2024 10:34: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 1sQpS8-0004iw-Vc for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:54 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQpS7-0002XU-Dm for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:52 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4687fWc8004202; Mon, 8 Jul 2024 14:34:49 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wt8as74-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:49 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DF53V007576; Mon, 8 Jul 2024 14:34:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r751-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:47 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZL037381; Mon, 8 Jul 2024 14:34:47 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-10; Mon, 08 Jul 2024 14:34:47 +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=h 6QCvrXNXbMo96ylbAuUbody2amhcysKXy86lcrhEOE=; b=S3sKXGhx0/IKiu6Xd UvrtSW41wR/HChUsuT9GTgzwamTgomGW2hHe9DPdJWNZcHA3VO7OogfFPPH8gJvp ZFP63LOPt8odd07yYVAWxerDGxYNciWNwypmO/4+clFT1+6gs7Kxo97iRd8wgkc7 9QXnXi7li7ti1y1i4U+tV+OvXwmwV2yK5pirWHR0HViwB4/rN3B4hVU+m3x3uzPm omgldXlT1/Po4Gn8A8pAJ5/Au3+S6eAHbBSYVVC9/oqS1X0KEB/oaVwIeb4b2EHl jVtnqqPzlNG2czlrz02ds2/pVs2VYtlJdT5/rHhYImqkXTIcnMNNXkoRZUsBfgXd 3vJPA== 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 v3 09/10] vfio/migration: Don't block migration device dirty tracking is unsupported Date: Mon, 8 Jul 2024 15:34:19 +0100 Message-Id: <20240708143420.16953-10-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=885 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-GUID: j2Ekyn-hqIH0sCttE1hBhLfbraXQYpNq X-Proofpoint-ORIG-GUID: j2Ekyn-hqIH0sCttE1hBhLfbraXQYpNq 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.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=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: 1720449351384100003 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. Signed-off-by: Joao Martins --- hw/vfio/migration.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 34d4be2ce1b1..89195928666f 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1012,6 +1012,7 @@ void vfio_reset_bytes_transferred(void) */ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp) { + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(vbasedev->= hiod); Error *err =3D NULL; int ret; =20 @@ -1036,7 +1037,10 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Er= ror **errp) return !vfio_block_migration(vbasedev, err, errp); } =20 - if (!vbasedev->dirty_pages_supported) { + if (!vbasedev->dirty_pages_supported && + (vbasedev->iommufd && + !hiodc->get_cap(vbasedev->hiod, + HOST_IOMMU_DEVICE_CAP_DIRTY_TRACKING, NULL))) { 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 18:35:07 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=1720449367; cv=none; d=zohomail.com; s=zohoarc; b=PKZskv1XaxXdXmDQNpL5XmqSMTyu6EoqlTl5ooU02/y/VTDfXDRpZwAvSKNa8h13mOBBWCT7QTHmknjvByqPLjpoxDVowM/DVH586TshenyUeqzngztLr6yUhPNZEcrszHuhPsj6jQlAhoQpfB9Mk3hICx8StoT9eXLIydCBNNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720449367; 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=Yc3OnvUrU3PWhiR2Avzv9BTvcSxWo6/reCBxayOrcSg=; b=i5ac5WMK78zIxp1nlU8/9Wsr0D/tAk5RlA8OaoBIH+WzDVFSpHBsZFCgQEmgNYschwynaihzhzECsP0HvPZmobfMU6q8pzU0D8g7YuMamgb0got79Y+g0p/n8oF5uCXOMVnxd7IIswQ3QO9wM88HF3unElusZOTnNjMlQMY7m9c= 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 1720449367870375.8725432539909; Mon, 8 Jul 2024 07:36:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQpSH-0005P9-Oz; Mon, 08 Jul 2024 10:35:01 -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 1sQpSB-0004sh-8I for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:56 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQpS9-0002Y2-GA for qemu-devel@nongnu.org; Mon, 08 Jul 2024 10:34:54 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4687fTPe013142; Mon, 8 Jul 2024 14:34:51 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wgptt73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:51 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 468DOSFQ008768; Mon, 8 Jul 2024 14:34:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 407tu1r76c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Jul 2024 14:34:50 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 468EXkZN037381; Mon, 8 Jul 2024 14:34:49 GMT Received: from joaomart-mac.nl.oracle.com (dhcp-10-175-56-128.vpn.oracle.com [10.175.56.128]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 407tu1r6ms-11; Mon, 08 Jul 2024 14:34:49 +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 c3OnvUrU3PWhiR2Avzv9BTvcSxWo6/reCBxayOrcSg=; b=SzvJVd8qBc1B50xlL lnwkmmYm+UxTzypRnaxxJ2ZTqfrkGTPb00Xy9U2Cv1cTm2C71eIEFSScwjfOYXRa eXegOJaV7NrMHbE+Q3zXxd6/er9cnOVovF8rZ7aO8IZTh5uPlfWXuxMRaz+xiRzh dWsi3mqT9RdjMsnk0Xu5wMChXKmAJVv/dfbCcOjiup+ElawgV6d3EYg0Nc5+C6MQ oDYMx6pDSL1AMOVahLawRFURNXcMnD4AwYQ5PIeF64KrSprjcevI+zE+1lsFWiZU 9MrAECB0JoAc15R1/MLDbxd0MVngYUSqiWKKlKbeqc3IiZBxvCtktenSzmIyxKrU NOJPA== 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 v3 10/10] vfio/common: Allow disabling device dirty page tracking Date: Mon, 8 Jul 2024 15:34:20 +0100 Message-Id: <20240708143420.16953-11-joao.m.martins@oracle.com> In-Reply-To: <20240708143420.16953-1-joao.m.martins@oracle.com> References: <20240708143420.16953-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-08_09,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=971 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407080109 X-Proofpoint-ORIG-GUID: -8JAGnEatpol7mdoBZdPmK6HJVJ4t7nK X-Proofpoint-GUID: -8JAGnEatpol7mdoBZdPmK6HJVJ4t7nK 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.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=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: 1720449369465100003 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 7ce925cfab19..9db3fd31cfae 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -137,6 +137,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 7cdb969fd396..eaa33d9ee037 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 89195928666f..35d67332db20 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1037,7 +1037,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->iommufd && !hiodc->get_cap(vbasedev->hiod, HOST_IOMMU_DEVICE_CAP_DIRTY_TRACKING, NULL))) { diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e03d9f3ba546..22819b2036b3 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3362,6 +3362,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