From nobody Fri Nov 14 23:31:37 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1759982658; cv=none; d=zohomail.com; s=zohoarc; b=nPpLlMe20JdgfxOBHiklF4eVW/FIa8gTbTmAdvRnNfWbVfxZxJe2oG2KYZ8wTIHRbn43Y0nFpkyha1qQhCDphbaef6mpPNTwpavWS9H1IZ4tINA+nWVazV+jJfdDiiBBEx8D9uK67Er3hHsWBm1QTmyqBHwFjHSo3XDfJ54zxf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759982658; 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=/LbnznsnmxYQYUfdSXhX7lsm9hvMxQzfkEIx50PM+UA=; b=LHMg7yDdWgqyirV+rd7SP9jLGkxy0OUVoY2B3i3Hj/FYLzKVJ3RTt4rqnnG5a3iEWg8KzuLyUzhsxDMnYbBPMfSl29QuwQOKvS5kw+46GicVMsalRbTfHSxybD5gCZzFoykle0qwZ27xWrmBSkqjQxfaqnanVi9fnZeEjtVQO98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1759982658860223.6672013618596; Wed, 8 Oct 2025 21:04:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v6hrQ-0005o2-Cu; Thu, 09 Oct 2025 00:02:36 -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 1v6hrN-0005nX-NY for qemu-devel@nongnu.org; Thu, 09 Oct 2025 00:02:34 -0400 Received: from mgamail.intel.com ([198.175.65.9]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v6hrA-0002at-6W for qemu-devel@nongnu.org; Thu, 09 Oct 2025 00:02:29 -0400 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2025 21:02:15 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2025 21:02:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1759982540; x=1791518540; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=evj+FWN+i7qsqXS7v2uC/zwnpEBYRbN8B5CyZzFZPpE=; b=Of3iehMqD8yZE5aC4YlpeB2I8ZY9f+57I6CfikbzQYjMxfbnJqZN3Mv5 4J6DKAbis3AEZpoJIkTumhPJ31/JTFdFp0tkooJnvW/xIBtX592bo78Xu nEbaYY61YcevtOPGJxlBdx4eQMUku9QcrqrhIh/w67AwsFcoSbxVcbqHi VpOCYp57ZVE8l5qmCnQ8xWn7iKf7HtnJ4t8dw8NFh7eqnyFmSwHUNmn+Z hGfgFEVUBm7pm+efvHpA+fagwiut312KgudfQw1NwL/do7tsQs21wF2zn q9bUHfhga3s/EzbXZyInHwGsX6kPqe5AQ0syZz+G7S3WNTcifTCz43tHB w==; X-CSE-ConnectionGUID: PttsmK2iSXKJbj6ZhKy9Yw== X-CSE-MsgGUID: 6lRjydUhRz+xQ4Ic7oGa/g== X-IronPort-AV: E=McAfee;i="6800,10657,11576"; a="84804130" X-IronPort-AV: E=Sophos;i="6.19,215,1754982000"; d="scan'208";a="84804130" X-CSE-ConnectionGUID: SmsCK5cBRrWfAIDz6N2tuw== X-CSE-MsgGUID: v4yxI6IcSP6snJtCvpi+2g== X-ExtLoop1: 1 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, levon@movementarian.org, Zhenzhong Duan Subject: [PATCH v2 1/3] vfio/container: Support unmap all in one ioctl() Date: Thu, 9 Oct 2025 00:01:32 -0400 Message-ID: <20251009040134.334251-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251009040134.334251-1-zhenzhong.duan@intel.com> References: <20251009040134.334251-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=198.175.65.9; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.442, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1759982660666154100 Content-Type: text/plain; charset="utf-8" VFIO type1 kernel uAPI supports unmapping whole address space in one call since commit c19650995374 ("vfio/type1: implement unmap all"). Use the unmap_all variant whenever it's supported in kernel. Opportunistically pass VFIOLegacyContainer pointer in low level function vfio_legacy_dma_unmap_one(). Co-developed-by: John Levon Signed-off-by: John Levon Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-container-legacy.h | 1 + hw/vfio/container-legacy.c | 38 ++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/hw/vfio/vfio-container-legacy.h b/include/hw/vfio/vfio= -container-legacy.h index 74a72df018..ffd594e80d 100644 --- a/include/hw/vfio/vfio-container-legacy.h +++ b/include/hw/vfio/vfio-container-legacy.h @@ -30,6 +30,7 @@ struct VFIOLegacyContainer { =20 int fd; /* /dev/vfio/vfio, empowered by the attached groups */ unsigned iommu_type; + bool unmap_all_supported; QLIST_HEAD(, VFIOGroup) group_list; VFIOContainerCPR cpr; }; diff --git a/hw/vfio/container-legacy.c b/hw/vfio/container-legacy.c index a3615d7b5d..8e9639603e 100644 --- a/hw/vfio/container-legacy.c +++ b/hw/vfio/container-legacy.c @@ -121,14 +121,14 @@ unmap_exit: return ret; } =20 -static int vfio_legacy_dma_unmap_one(const VFIOContainer *bcontainer, +static int vfio_legacy_dma_unmap_one(const VFIOLegacyContainer *container, hwaddr iova, uint64_t size, - IOMMUTLBEntry *iotlb) + uint32_t flags, IOMMUTLBEntry *iotlb) { - const VFIOLegacyContainer *container =3D VFIO_IOMMU_LEGACY(bcontainer); + const VFIOContainer *bcontainer =3D VFIO_IOMMU(container); struct vfio_iommu_type1_dma_unmap unmap =3D { .argsz =3D sizeof(unmap), - .flags =3D 0, + .flags =3D flags, .iova =3D iova, .size =3D size, }; @@ -170,25 +170,28 @@ static int vfio_legacy_dma_unmap(const VFIOContainer = *bcontainer, hwaddr iova, uint64_t size, IOMMUTLBEntry *iotlb, bool unmap_all) { + const VFIOLegacyContainer *container =3D VFIO_IOMMU_LEGACY(bcontainer); + uint32_t flags =3D 0; int ret; =20 if (unmap_all) { - /* The unmap ioctl doesn't accept a full 64-bit span. */ - Int128 llsize =3D int128_rshift(int128_2_64(), 1); - - ret =3D vfio_legacy_dma_unmap_one(bcontainer, 0, int128_get64(llsi= ze), - iotlb); + if (container->unmap_all_supported) { + flags =3D VFIO_DMA_UNMAP_FLAG_ALL; + } else { + /* The unmap ioctl doesn't accept a full 64-bit span. */ + Int128 llsize =3D int128_rshift(int128_2_64(), 1); + size =3D int128_get64(llsize); + + ret =3D vfio_legacy_dma_unmap_one(container, 0, size, flags, i= otlb); + if (ret) { + return ret; + } =20 - if (ret =3D=3D 0) { - ret =3D vfio_legacy_dma_unmap_one(bcontainer, int128_get64(lls= ize), - int128_get64(llsize), iotlb); + iova =3D size; } - - } else { - ret =3D vfio_legacy_dma_unmap_one(bcontainer, iova, size, iotlb); } =20 - return ret; + return vfio_legacy_dma_unmap_one(container, iova, size, flags, iotlb); } =20 static int vfio_legacy_dma_map(const VFIOContainer *bcontainer, hwaddr iov= a, @@ -519,6 +522,9 @@ static bool vfio_legacy_setup(VFIOContainer *bcontainer= , Error **errp) =20 vfio_get_info_iova_range(info, bcontainer); =20 + ret =3D ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UNMAP_ALL); + container->unmap_all_supported =3D !!ret; + vfio_get_iommu_info_migration(container, info); return true; } --=20 2.47.1