From nobody Thu Sep 19 00:18:51 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1721743282; cv=none; d=zohomail.com; s=zohoarc; b=hlpN8Sc7CPz9xtRx0flTSVYJOxS5cQr15lqgMqSwirei9IaDU0zpgZLdgcjTi8nioOPJYnccZk2XEcNUOUs29r1iOtoruTtfKXd9FGBFZ3tqqwwVaPt25tnZM5XDBAzFymKgnaDTiZneIBAq9xeR0J3BRbu/6CinA97LETV9PK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721743282; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RIzxcHlTUnXXEN3gGBhKdomiNcQkqsc1CXw0al+SQeM=; b=m2v4FtAyKz8i5LrGCr/XQVaL9tc9UqM2FdTkIFG31Kna70LdMS/KooKWgTkznoPP5aaEVorqWShtipOF79BXgIXlj4lQC4VbW1dzPSp8ZCuC8xrQ8GOi2B5IJQ4yRe+iZmLTp3neVRHKgWd9qbtZr2EcAEcRR+SyhYU/goXTJls= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721743282159931.5103573834174; Tue, 23 Jul 2024 07:01:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWG4K-00083s-LD; Tue, 23 Jul 2024 10:00:44 -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 1sWG4G-0007uv-8V for qemu-devel@nongnu.org; Tue, 23 Jul 2024 10:00:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWG4E-0003eR-E1 for qemu-devel@nongnu.org; Tue, 23 Jul 2024 10:00:39 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-01gOCSz7N5e9t3a5E6yegA-1; Tue, 23 Jul 2024 10:00:29 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 883061944A8B; Tue, 23 Jul 2024 14:00:28 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.91]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BFA6195605A; Tue, 23 Jul 2024 14:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721743236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RIzxcHlTUnXXEN3gGBhKdomiNcQkqsc1CXw0al+SQeM=; b=c6x41URjxSV61GyyIUrd0GINUMw0Ch0PD6KCFRz7mXYCyuTXbzj4Hs4Ef385GgNQoEW7JA cFCOpZBwFtHx1vEL68ag5CZWk9R9gHxIS8FTGF2JvXFBOooF6ifG3j4TWNvyU/4ijCnWFN MfDr83ZD6vBV+Gn6npRWWKBPBev+SkM= X-MC-Unique: 01gOCSz7N5e9t3a5E6yegA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Joao Martins , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , Eric Auger Subject: [PULL 02/16] vfio/pci: Extract mdev check into an helper Date: Tue, 23 Jul 2024 16:00:05 +0200 Message-ID: <20240723140019.387786-3-clg@redhat.com> In-Reply-To: <20240723140019.387786-1-clg@redhat.com> References: <20240723140019.387786-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.133, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @redhat.com) X-ZM-MESSAGEID: 1721743284205116600 From: Joao Martins In preparation to skip initialization of the HostIOMMUDevice for mdev, extract the checks that validate if a device is an mdev into helpers. A vfio_device_is_mdev() is created, and subsystems consult VFIODevice::mdev to check if it's mdev or not. Signed-off-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Zhenzhong Duan Reviewed-by: Eric Auger --- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/helpers.c | 14 ++++++++++++++ hw/vfio/pci.c | 12 +++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index e8ddf92bb18547f0d3b811b3d757cbae7fec8b8d..98acae8c1c975390c6cd0fdc02a= 1282f64ea2987 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -116,6 +116,7 @@ typedef struct VFIODevice { DeviceState *dev; int fd; int type; + bool mdev; bool reset_works; bool needs_reset; bool no_mmap; @@ -231,6 +232,7 @@ void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); struct vfio_device_info *vfio_get_device_info(int fd); +bool vfio_device_is_mdev(VFIODevice *vbasedev); bool vfio_attach_device(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void vfio_detach_device(VFIODevice *vbasedev); diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index b14edd46edc9069bb148359a1b419253ff4e5ef0..7e23e9080c9d2860dea51ca5ef5= fbc840d42a32d 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -675,3 +675,17 @@ int vfio_device_get_aw_bits(VFIODevice *vdev) =20 return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX; } + +bool vfio_device_is_mdev(VFIODevice *vbasedev) +{ + g_autofree char *subsys =3D NULL; + g_autofree char *tmp =3D NULL; + + if (!vbasedev->sysfsdev) { + return false; + } + + tmp =3D g_strdup_printf("%s/subsystem", vbasedev->sysfsdev); + subsys =3D realpath(tmp, NULL); + return subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); +} diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e03d9f3ba5461f55f6351d937aba5d522a9128ec..b34e91468a533ab4d550bf2392e= 940b867f7b34c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2963,12 +2963,9 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) ERRP_GUARD(); VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); VFIODevice *vbasedev =3D &vdev->vbasedev; - char *subsys; int i, ret; - bool is_mdev; char uuid[UUID_STR_LEN]; g_autofree char *name =3D NULL; - g_autofree char *tmp =3D NULL; =20 if (vbasedev->fd < 0 && !vbasedev->sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || @@ -2997,14 +2994,11 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) * stays in sync with the active working set of the guest driver. Pre= vent * the x-balloon-allowed option unless this is minimally an mdev devic= e. */ - tmp =3D g_strdup_printf("%s/subsystem", vbasedev->sysfsdev); - subsys =3D realpath(tmp, NULL); - is_mdev =3D subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); - free(subsys); + vbasedev->mdev =3D vfio_device_is_mdev(vbasedev); =20 - trace_vfio_mdev(vbasedev->name, is_mdev); + trace_vfio_mdev(vbasedev->name, vbasedev->mdev); =20 - if (vbasedev->ram_block_discard_allowed && !is_mdev) { + if (vbasedev->ram_block_discard_allowed && !vbasedev->mdev) { error_setg(errp, "x-balloon-allowed only potentially compatible " "with mdev devices"); goto error; --=20 2.45.2