From nobody Wed Feb 11 02:09:09 2026 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=1693392834; cv=none; d=zohomail.com; s=zohoarc; b=EQ2Ez1NUz+3sONp4rY2GgjVXWzmDToxGzXjfs8DG0ketYqXg6HbvlZI2hWmFOny9tUfX9cqcCYjswuN/BX+WBx39zYYork2OGyWNWy3UCsl9M2zOPvug5FGaN7HXNjyo0d4YQ9VbtLuDPBIsOsD36X+htg5ME8MpbIj1uucc4t8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693392834; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HpR5foyMRf/iD32dLjg0q2Tqx4eR2Zg8y6pE5mL7ra8=; b=ZY2pnWPbrrtDTWJzxFFnyt5d1XeDKHf/7TuFfcNcAqBvCJL3JRoKpOY3gMAnDsMVAcoJ+hFNKJBlOp0nzotWNMRBqKBXrbwwzRAWod/nCmLIV5PFaAwz/ai4UMWPpoRkwaUXytrytE27Nc/9Tm+IdBPlDAwXOo6JoeoWgKYn8/M= 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 1693392834019436.816939810339; Wed, 30 Aug 2023 03:53:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbIpF-0004I3-V0; Wed, 30 Aug 2023 06:53:31 -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 1qbIpC-0004Ha-Il for qemu-devel@nongnu.org; Wed, 30 Aug 2023 06:53:26 -0400 Received: from mgamail.intel.com ([192.55.52.93]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbIpA-0007fH-8c for qemu-devel@nongnu.org; Wed, 30 Aug 2023 06:53:26 -0400 Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 03:53:13 -0700 Received: from duan-server-s2600bt.bj.intel.com ([10.240.192.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 03:53:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693392804; x=1724928804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SvlSSQEEskjTcJO2Ju6WBWVkXRHLlMua+97gnXK3DqQ=; b=Ym/rllxaVjDMfhti5w9LCb9uUg4NxUnVEa7fqxtrir3zBac88xjmUJ16 5+ORLFE5OuP4iAUFiON8zsHE39x+5HeQ5WRW07FiqFguB6foJ2D23yFMq uPO/tTdXbfk+04JhdDMTIUytNwv7Mk8ggkRfo4aZ+hjwsRvSiFnO2IJNI lP8QN3RowJV+deikGyyk0Fa4tGfE5frzKuWyzEYMhVy4sFNKQP6n8FHNP ibUvm5NYSpzmVJAa6k4sVoASRwtvILbbegu3/MT95gc8YTWThiIL1qF7K RRfEBCWhVwK2PhF9E0vz9oZ4SyvuGU6NAmpgVqqPJDCIddZ3swnDiXetD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10817"; a="373016540" X-IronPort-AV: E=Sophos;i="6.02,213,1688454000"; d="scan'208";a="373016540" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10817"; a="715866123" X-IronPort-AV: E=Sophos;i="6.02,213,1688454000"; d="scan'208";a="715866123" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 10/22] vfio/platform: Use vfio_[attach/detach]_device Date: Wed, 30 Aug 2023 18:37:42 +0800 Message-Id: <20230830103754.36461-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230830103754.36461-1-zhenzhong.duan@intel.com> References: <20230830103754.36461-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=192.55.52.93; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1693392904344100001 Content-Type: text/plain; charset="utf-8" From: Eric Auger Let the vfio-platform device use vfio_attach_device() and vfio_detach_device(), hence hiding the details of the used IOMMU backend. Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/vfio/platform.c | 43 ++++--------------------------------------- hw/vfio/trace-events | 2 +- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 5af73f9287..5c08c39315 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -529,12 +529,7 @@ static VFIODeviceOps vfio_platform_ops =3D { */ static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp) { - VFIOGroup *group; - VFIODevice *vbasedev_iter; - char *tmp, group_path[PATH_MAX], *group_name; - ssize_t len; struct stat st; - int groupid; int ret; =20 /* @sysfsdev takes precedence over @host */ @@ -557,47 +552,17 @@ static int vfio_base_device_init(VFIODevice *vbasedev= , Error **errp) return -errno; } =20 - tmp =3D g_strdup_printf("%s/iommu_group", vbasedev->sysfsdev); - len =3D readlink(tmp, group_path, sizeof(group_path)); - g_free(tmp); + trace_vfio_platform_base_device_init(vbasedev->name); =20 - if (len < 0 || len >=3D sizeof(group_path)) { - ret =3D len < 0 ? -errno : -ENAMETOOLONG; - error_setg_errno(errp, -ret, "no iommu_group found"); - return ret; - } - - group_path[len] =3D 0; - - group_name =3D basename(group_path); - if (sscanf(group_name, "%d", &groupid) !=3D 1) { - error_setg_errno(errp, errno, "failed to read %s", group_path); - return -errno; - } - - trace_vfio_platform_base_device_init(vbasedev->name, groupid); - - group =3D vfio_get_group(groupid, &address_space_memory, errp); - if (!group) { - return -ENOENT; - } - - QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { - if (strcmp(vbasedev_iter->name, vbasedev->name) =3D=3D 0) { - error_setg(errp, "device is already attached"); - vfio_put_group(group); - return -EBUSY; - } - } - ret =3D vfio_get_device(group, vbasedev->name, vbasedev, errp); + ret =3D vfio_attach_device(vbasedev->name, vbasedev, + &address_space_memory, errp); if (ret) { - vfio_put_group(group); return ret; } =20 ret =3D vfio_populate_device(vbasedev, errp); if (ret) { - vfio_put_group(group); + vfio_detach_device(vbasedev); } =20 return ret; diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 8016d9f0d2..bd32970854 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -124,7 +124,7 @@ vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t s= ize, uint64_t bitmap_size vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 # platform.c -vfio_platform_base_device_init(char *name, int groupid) "%s belongs to gro= up #%d" +vfio_platform_base_device_init(char *name) "%s" vfio_platform_realize(char *name, char *compat) "vfio device %s, compat = =3D %s" vfio_platform_eoi(int pin, int fd) "EOI IRQ pin %d (fd=3D%d)" vfio_platform_intp_mmap_enable(int pin) "IRQ #%d still active, stay in slo= w path" --=20 2.34.1