From nobody Mon Feb 9 16:35:21 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=1654692273; cv=none; d=zohomail.com; s=zohoarc; b=YctyKiJ3WGfz1N19i4bEONDfqZ8noYTsCQGL8pNKrwU7DvGqaEWttGln03plUFFdcY4XjwOsiR5uTnBmFIFAVfZnNvKXAgKWL2O2yP68Feb9TtvZg6/6or/AYDe/RZE8oykHWdPVr3OX4Ay4o/iniMGXsK2MSbKTzmDcJdWFKkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654692273; 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=gzyaExfeAxAI4/QUP0HNV4qRZ8YuhM7wtOwKDPH+LWg=; b=gvdV0KiXNvixjWhVl7VBES/IeGshlEKFUy68kqv1UUtqx6zuncQmABRVcIdzdhcL52iOGUKy5pLaJw4ZplVxVlIXFIJXHHmLf8ihR2GI1SKMRU0++d/FlWyz8RM7PbD21V1tbgaxiMdEOu1rBh9nDiHADUqfgoRd8/TBGSIYC0c= 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 1654692273397702.6605327384958; Wed, 8 Jun 2022 05:44:33 -0700 (PDT) Received: from localhost ([::1]:43896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyv31-0005TI-1u for importer@patchew.org; Wed, 08 Jun 2022 08:44:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyuqt-0000RA-5x for qemu-devel@nongnu.org; Wed, 08 Jun 2022 08:31:59 -0400 Received: from mga05.intel.com ([192.55.52.43]:56947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyuqo-0005ka-1D for qemu-devel@nongnu.org; Wed, 08 Jun 2022 08:31:57 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 05:31:46 -0700 Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by FMSMGA003.fm.intel.com with ESMTP; 08 Jun 2022 05:31:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654691514; x=1686227514; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dBhh34Fn2hj15XF0RFxWzOWwQ/vwct5pqhM//y9VRbY=; b=X9htwzEtvJx3EYL1JTlERvQBUJ3hRn1bAnhkzPy01fMbaY4q1JiaSBCk 4kumdHckyqXttCL/6Px0FgHveKiuMrmaxtmJftnG8ssXsCQl2mOtajemH Lm+ezvdnVG60bED1ZppD7lzZPMws7AcSJpbo3pmeIeeUzYdx6jeyO+h1b PNQUWSWuRT6Vz4NrFfbOSFRZvQmJfVtNNBp/dka4qHE6vr5Xr/BfHiYwS 4hteR7ifirYvgqKnIgzcEmGh0nFl3PpU9KfoF8NE1jSwMAtm6KYokuCM9 LnpbW+zXS7AEJD3fmRurg/r1z3qJg40iTpQmWrn5d1EkKYP9e61ZYtOIB A==; X-IronPort-AV: E=McAfee;i="6400,9594,10371"; a="363210142" X-IronPort-AV: E=Sophos;i="5.91,286,1647327600"; d="scan'208";a="363210142" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,286,1647327600"; d="scan'208";a="670529818" From: Yi Liu To: alex.williamson@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org Cc: david@gibson.dropbear.id.au, thuth@redhat.com, farman@linux.ibm.com, mjrosato@linux.ibm.com, akrowiak@linux.ibm.com, pasic@linux.ibm.com, jjherne@linux.ibm.com, jasowang@redhat.com, kvm@vger.kernel.org, jgg@nvidia.com, nicolinc@nvidia.com, eric.auger@redhat.com, eric.auger.pro@gmail.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, yi.y.sun@intel.com, peterx@redhat.com, shameerali.kolothum.thodi@huawei.com, zhangfei.gao@linaro.org, berrange@redhat.com Subject: [RFC v2 08/15] vfio/ccw: Use vfio_[attach/detach]_device Date: Wed, 8 Jun 2022 05:31:32 -0700 Message-Id: <20220608123139.19356-9-yi.l.liu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220608123139.19356-1-yi.l.liu@intel.com> References: <20220608123139.19356-1-yi.l.liu@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.43; envelope-from=yi.l.liu@intel.com; helo=mga05.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1654692275010100003 Content-Type: text/plain; charset="utf-8" From: Eric Auger Let the vfio-ccw device use vfio_attach_device() and vfio_detach_device(), hence hiding the details of the used IOMMU backend. Also now all the devices have been migrated to use the new vfio_attach_device/vfio_detach_device API, let's turn the legacy functions into static functions, local to container.c. Signed-off-by: Eric Auger Signed-off-by: Yi Liu --- hw/vfio/ccw.c | 118 ++++++++-------------------------- hw/vfio/container.c | 8 +-- include/hw/vfio/vfio-common.h | 4 -- 3 files changed, 32 insertions(+), 98 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 0354737666..6fde7849cc 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -579,27 +579,32 @@ static void vfio_ccw_put_region(VFIOCCWDevice *vcdev) g_free(vcdev->io_region); } =20 -static void vfio_ccw_put_device(VFIOCCWDevice *vcdev) -{ - g_free(vcdev->vdev.name); - vfio_put_base_device(&vcdev->vdev); -} - -static void vfio_ccw_get_device(VFIOGroup *group, VFIOCCWDevice *vcdev, - Error **errp) +static void vfio_ccw_realize(DeviceState *dev, Error **errp) { + CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); + S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); + VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); + S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); + VFIODevice *vbasedev =3D &vcdev->vdev; + Error *err =3D NULL; char *name =3D g_strdup_printf("%x.%x.%04x", vcdev->cdev.hostid.cssid, vcdev->cdev.hostid.ssid, vcdev->cdev.hostid.devid); - VFIODevice *vbasedev; + int ret; =20 - QLIST_FOREACH(vbasedev, &group->device_list, next) { - if (strcmp(vbasedev->name, name) =3D=3D 0) { - error_setg(errp, "vfio: subchannel %s has already been attache= d", - name); - goto out_err; + /* Call the class init function for subchannel. */ + if (cdc->realize) { + cdc->realize(cdev, vcdev->vdev.sysfsdev, &err); + if (err) { + goto out_err_propagate; } } + vbasedev->sysfsdev =3D g_strdup_printf("/sys/bus/css/devices/%s/%s", + name, cdev->mdevid); + vbasedev->ops =3D &vfio_ccw_ops; + vbasedev->type =3D VFIO_DEVICE_TYPE_CCW; + vbasedev->name =3D name; + vbasedev->dev =3D &vcdev->cdev.parent_obj.parent_obj; =20 /* * All vfio-ccw devices are believed to operate in a way compatible wi= th @@ -609,80 +614,18 @@ static void vfio_ccw_get_device(VFIOGroup *group, VFI= OCCWDevice *vcdev, * needs to be set before vfio_get_device() for vfio common to handle * ram_block_discard_disable(). */ - vcdev->vdev.ram_block_discard_allowed =3D true; - - if (vfio_get_device(group, vcdev->cdev.mdevid, &vcdev->vdev, errp)) { - goto out_err; - } - - vcdev->vdev.ops =3D &vfio_ccw_ops; - vcdev->vdev.type =3D VFIO_DEVICE_TYPE_CCW; - vcdev->vdev.name =3D name; - vcdev->vdev.dev =3D &vcdev->cdev.parent_obj.parent_obj; - - return; - -out_err: - g_free(name); -} - -static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, Error **errp) -{ - char *tmp, group_path[PATH_MAX]; - ssize_t len; - int groupid; =20 - tmp =3D g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/%s/iommu_grou= p", - cdev->hostid.cssid, cdev->hostid.ssid, - cdev->hostid.devid, cdev->mdevid); - len =3D readlink(tmp, group_path, sizeof(group_path)); - g_free(tmp); + vbasedev->ram_block_discard_allowed =3D true; =20 - if (len <=3D 0 || len >=3D sizeof(group_path)) { - error_setg(errp, "vfio: no iommu_group found"); - return NULL; - } - - group_path[len] =3D 0; - - if (sscanf(basename(group_path), "%d", &groupid) !=3D 1) { - error_setg(errp, "vfio: failed to read %s", group_path); - return NULL; - } - - return vfio_get_group(groupid, &address_space_memory, errp); -} - -static void vfio_ccw_realize(DeviceState *dev, Error **errp) -{ - VFIOGroup *group; - CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); - S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); - VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); - S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); - Error *err =3D NULL; - - /* Call the class init function for subchannel. */ - if (cdc->realize) { - cdc->realize(cdev, vcdev->vdev.sysfsdev, &err); - if (err) { - goto out_err_propagate; - } - } - - group =3D vfio_ccw_get_group(cdev, &err); - if (!group) { - goto out_group_err; - } - - vfio_ccw_get_device(group, vcdev, &err); - if (err) { - goto out_device_err; + ret =3D vfio_attach_device(vbasedev, &address_space_memory, errp); + if (ret) { + g_free(vbasedev->name); + g_free(vbasedev->sysfsdev); } =20 vfio_ccw_get_region(vcdev, &err); if (err) { - goto out_region_err; + goto out_get_dev_err; } =20 vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err); @@ -714,11 +657,8 @@ out_irq_notifier_err: vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX); out_io_notifier_err: vfio_ccw_put_region(vcdev); -out_region_err: - vfio_ccw_put_device(vcdev); -out_device_err: - vfio_put_group(group); -out_group_err: +out_get_dev_err: + vfio_detach_device(vbasedev); if (cdc->unrealize) { cdc->unrealize(cdev); } @@ -732,14 +672,12 @@ static void vfio_ccw_unrealize(DeviceState *dev) S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); - VFIOGroup *group =3D vcdev->vdev.group; =20 vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX); vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX); vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX); vfio_ccw_put_region(vcdev); - vfio_ccw_put_device(vcdev); - vfio_put_group(group); + vfio_detach_device(&vcdev->vdev); =20 if (cdc->unrealize) { cdc->unrealize(cdev); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 74e6eeba74..fbde5b0d31 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -958,7 +958,7 @@ static void vfio_disconnect_container(VFIOGroup *group) } } =20 -VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp) +static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **er= rp) { VFIOGroup *group; VFIOContainer *bcontainer; @@ -1027,7 +1027,7 @@ free_group_exit: return NULL; } =20 -void vfio_put_group(VFIOGroup *group) +static void vfio_put_group(VFIOGroup *group) { if (!group || !QLIST_EMPTY(&group->device_list)) { return; @@ -1048,8 +1048,8 @@ void vfio_put_group(VFIOGroup *group) } } =20 -int vfio_get_device(VFIOGroup *group, const char *name, - VFIODevice *vbasedev, Error **errp) +static int vfio_get_device(VFIOGroup *group, const char *name, + VFIODevice *vbasedev, Error **errp) { struct vfio_device_info dev_info =3D { .argsz =3D sizeof(dev_info) }; int ret, fd; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 1b68cd8ece..669d761728 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -177,10 +177,6 @@ void vfio_region_unmap(VFIORegion *region); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); -VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp); -void vfio_put_group(VFIOGroup *group); -int vfio_get_device(VFIOGroup *group, const char *name, - VFIODevice *vbasedev, Error **errp); int vfio_attach_device(VFIODevice *vbasedev, AddressSpace *as, Error **err= p); void vfio_detach_device(VFIODevice *vbasedev); =20 --=20 2.27.0