From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570877; cv=none; d=zohomail.com; s=zohoarc; b=iNQyM5CEpeeKIwsag+AjCs8Ul0MKPDcvn8jclj9/5fHXBBP7AhdnzcJg4KdVCKubiw679zdjM6q6O9u9JzdnPthovuOrxbVX17ud13qq9PucQI8KZqQ9tw/oggmr+ynDRw0kcGaR+oREK59QdxZvpR5O7IX2Q2VIZ/44dTC5lpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570877; 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=lY+v69YkrmKbaWSdpoVXnchedsmJjUQiyoXmziKt2Zw=; b=b8Dn2VTiCnqZwfoq3r1CF26QYscmQRB/uJ5iKhL4/pHzv3J4yEyA+FCF8wAX5cu1hq3Ar0TE+QCDo57TXz2jzACuA+8bJuOAE3n5Cfc1CK78cX43mA3phEXeYqEjVAj7M7iEKTyB3lnc9fDbpSchvoi6rzo8M8IkU6HOYXd9s4w= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570877856840.0281883819907; Fri, 25 Apr 2025 01:47:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EiE-0002hz-J5; Fri, 25 Apr 2025 04:47:14 -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 1u8EiA-0002gr-Hq for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:07 -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 1u8Ei6-0003AW-9B for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:06 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-8OAuMyPgO6a7UUoYviG_ww-1; Fri, 25 Apr 2025 04:46:56 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AE56C180010A; Fri, 25 Apr 2025 08:46:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B6B630001AB; Fri, 25 Apr 2025 08:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570819; 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=lY+v69YkrmKbaWSdpoVXnchedsmJjUQiyoXmziKt2Zw=; b=BAK1vZrqz2T7EaqlLOjJ3YQcBAftYbntrLmdiT3Z8QqBgzyFSQErV1tZ8FAywJCf/7a8cj Iuep3Woe+VuWWS3K6KCmWj7meAK73nYbNuD+DDS0eADsYqHmPj6G8AzqmtGH/ZFKWPWKJh HZL3hQrHH6Ni1FBaEKMWlD7YxeZ22Xg= X-MC-Unique: 8OAuMyPgO6a7UUoYviG_ww-1 X-Mimecast-MFC-AGG-ID: 8OAuMyPgO6a7UUoYviG_ww_1745570815 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Tomita Moeko , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 01/50] vfio/igd: Update IGD passthrough documentation Date: Fri, 25 Apr 2025 10:45:54 +0200 Message-ID: <20250425084644.102196-2-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_SBL_A=0.1 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: 1745570880074019000 From: Tomita Moeko A previous change made the OpRegion and LPC quirks independent of the existing legacy mode, update the documentation accordingly. More related topics, like creating EFI Option ROM of IGD for OVMF, how to solve the VFIO_DMA_MAP Invalid Argument warning, as well as details on IGD memory internals, are also added. Signed-off-by: Tomita Moeko Reviewed-by: Alex Williamson Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250313150339.358621-1-tomitamoek= o@gmail.com Signed-off-by: C=C3=A9dric Le Goater --- docs/igd-assign.txt | 265 ++++++++++++++++++++++++++++++++------------ 1 file changed, 196 insertions(+), 69 deletions(-) diff --git a/docs/igd-assign.txt b/docs/igd-assign.txt index e17bb50789ada12b210897a5574bf89ee64b80fb..3aed7956d5d4fbc763d52c0f6ae= 0288c9a423679 100644 --- a/docs/igd-assign.txt +++ b/docs/igd-assign.txt @@ -1,44 +1,69 @@ Intel Graphics Device (IGD) assignment with vfio-pci =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =20 -IGD has two different modes for assignment using vfio-pci: - -1) Universal Pass-Through (UPT) mode: - - In this mode the IGD device is added as a *secondary* (ie. non-primary) - graphics device in combination with an emulated primary graphics device. - This mode *requires* guest driver support to remove the external - dependencies generally associated with IGD (see below). Those guest - drivers only support this mode for Broadwell and newer IGD, according to - Intel. Additionally, this mode by default, and as officially supported - by Intel, does not support direct video output. The intention is to use - this mode either to provide hardware acceleration to the emulated graph= ics - or to use this mode in combination with guest-based remote access softw= are, - for example VNC (see below for optional output support). This mode - theoretically has no device specific handling dependencies on vfio-pci = or - the VM firmware. - -2) "Legacy" mode: - - In this mode the IGD device is intended to be the primary and exclusive - graphics device in the VM[1], as such QEMU does not facilitate any sort - of remote graphics to the VM in this mode. A connected physical monitor - is the intended output device for IGD. This mode includes several - requirements and restrictions: - - * IGD must be given address 02.0 on the PCI root bus in the VM - * The host kernel must support vfio extensions for IGD (v4.6) - * vfio VGA support very likely needs to be enabled in the host kernel - * The VM firmware must support specific fw_cfg enablers for IGD - * The VM machine type must support a PCI host bridge at 00.0 (standard) - * The VM machine type must provide or allow to be created a special - ISA/LPC bridge device (vfio-pci-igd-lpc-bridge) on the root bus at - PCI address 1f.0. - * The IGD device must have a VGA ROM, either provided via the romfile - option or loaded automatically through vfio (standard). rombar=3D0 - will disable legacy mode support. - * Hotplug of the IGD device is not supported. - * The IGD device must be a SandyBridge or newer model device. +Using vfio-pci, we can passthrough Intel Graphics Device (IGD) to guest, e= ither +serve as primary and exclusive graphics adapter, or used in combination wi= th an +emulated primary graphics device, depending on the config and guest driver +support. However, IGD devices are not "clean" PCI devices, they use extra +memory regions other than BARs. Special handling is required to make them = work +properly, including: + +* OpRegion for accessing Virtual BIOS Table (VBT) that contains display ou= tput + information. +* Data Stolen Memory (DSM) region used as VRAM at early stage (BIOS/UEFI) + +Certain guest software also depends on following conditions to work: +(*-Required by) + +| Condition | Linux | Windows | VBIOS | = EFI GOP | +|---------------------------------------------|-------|---------|-------|-= --------| +| #1 IGD has a valid OpRegion containing VBT | * ^1 | * | * | = * | +| #2 VID/DID of LPC bridge at 00:1f.0 matches | | | * | = * | +| #3 IGD is assigned to BDF 00:02.0 | | | * | = * | +| #4 IGD has VGA controller device class | | | * | = * | +| #5 Host's VGA ranges are mapped to IGD | | | * | = | +| #6 Guest has valid VBIOS or UEFI Option ROM | | | * | = * | + +^1 Though i915 driver is able to mock a OpRegion, it is still recommended = to + use the VBT copied from host OpRegion to prevent incorrect configuratio= n. + +For #1, the "x-igd-opregion=3Don" option exposes a copy of host IGD OpRegi= on to +guest via fw_cfg, where guest firmware can set up guest OpRegion with it. + +For #2, "x-igd-lpc=3Don" option copies the IDs of host LPC bridge and host= bridge +to guest. Currently this is only supported on i440fx machines as there is +already an ICH9 LPC bridge present on q35 machines, overwriting its IDs may +lead to unexpected behavior. + +For #3, "addr=3D2.0" assigns IGD to 00:02.0. + +For #4, the primary display must be set to IGD in host BIOS. + +For #5, "x-vga=3Don" enables guest access to standard VGA IO/MMIO ranges. + +For #6, ROM either provided via the ROM BAR or romfile=3D option is needed= , this +Intel document [1] shows how to dump VBIOS to file. For UEFI Option ROM, s= ee +"Guest firmware" section. + +QEMU also provides a "Legacy" mode that implicitly enables full functional= ity +on IGD, it is automatically enabled when +* Machine type is i440fx +* IGD is assigned to guest BDF 00:02.0 +* ROM BAR or romfile is present + +In "Legacy" mode, QEMU will automatically setup OpRegion, LPC bridge IDs a= nd +VGA range access, which is equivalent to: + x-igd-opregion=3Don,x-igd-lpc=3Don,x-vga=3Don + +By default, "Legacy" mode won't fail, it continues on error. User can set +"x-igd-legacy-mode=3Don" to force enabling legacy mode, this also checks i= f the +conditions above for legacy mode is met, and if any error occurs, QEMU will +fail immediately. Users can also set "x-igd-legacy-mode=3Doff" to disable = legacy +mode. + +In legacy mode, as the guest VGA ranges are assigned to IGD device, all ot= her +graphics devices should be removed, this can be done using "-nographic" or +"-vga none" or "-nodefaults", along with adding the device using vfio-pci. =20 For either mode, depending on the host kernel, the i915 driver in the host may generate faults and errors upon re-binding to an IGD device after it @@ -73,31 +98,39 @@ DVI, or DisplayPort) may be unsupported in some use cas= es. In the author's experience, even DP to VGA adapters can be troublesome while adapters betw= een digital formats work well. =20 -Usage -=3D=3D=3D=3D=3D -The intention is for IGD assignment to be transparent for users and thus f= or -management tools like libvirt. To make use of legacy mode, simply remove = all -other graphics options and use "-nographic" and either "-vga none" or -"-nodefaults", along with adding the device using vfio-pci: =20 - -device vfio-pci,host=3D00:02.0,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x2 +Options +=3D=3D=3D=3D=3D=3D=3D +* x-igd-opregion=3D[on|*off*] + Copy host IGD OpRegion and expose it to guest with fw_cfg + +* x-igd-lpc=3D[on|*off*] + Creates a dummy LPC bridge at 00:1f:0 with host VID/DID (i440fx only) + +* x-igd-legacy-mode=3D[on|off|*auto*] + Enable/Disable legacy mode + +* x-igd-gms=3D[hex, default 0] + Overriding DSM region size in GGC register, 0 means uses host value. + Use this only when the DSM size cannot be changed through the + 'DVMT Pre-Allocated' option in host BIOS. =20 -For UPT mode, retain the default emulated graphics and simply add the vfio= -pci -device making use of any other bus address other than 02.0. libvirt will -default to assigning the device a UPT compatible address while legacy mode -users will need to manually edit the XML if using a tool like virt-manager -where the VM device address is not expressly specified. =20 -An experimental vfio-pci option also exists to enable OpRegion, and thus -external monitor support, for UPT mode. This can be enabled by adding -"x-igd-opregion=3Don" to the vfio-pci device options for the IGD device. = As -with legacy mode, this requires the host to support features introduced in -the v4.6 kernel. If Intel chooses to embrace this support, the option may -be made non-experimental in the future, opening it to libvirt support. +Examples +=3D=3D=3D=3D=3D=3D=3D=3D +* Adding IGD with automatically legacy mode support + -device vfio-pci,host=3D00:02.0,id=3Dhostdev0,addr=3D2.0 =20 -Developer ABI -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Legacy mode IGD support imposes two fw_cfg requirements on the VM firmware: +* Adding IGD with OpRegion and LPC ID hack, but without VGA ranges + (For UEFI guests) + -device vfio-pci,host=3D00:02.0,id=3Dhostdev0,addr=3D2.0,x-igd-legacy-mo= de=3Doff,x-igd-opregion=3Don,x-igd-lpc=3Don,romfile=3Defi_oprom.rom + + +Guest firmware +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Guest firmware is responsible for setting up OpRegion and Base of Data Sto= len +Memory (BDSM) in guest address space. IGD passthrough support imposes two +fw_cfg requirements on the VM firmware: =20 1) "etc/igd-opregion" =20 @@ -117,17 +150,111 @@ Legacy mode IGD support imposes two fw_cfg requireme= nts on the VM firmware: Firmware must allocate a reserved memory below 4GB with required 1MB alignment equal to this size. Additionally the base address of this reserved region must be written to the dword BDSM register in PCI config - space of the IGD device at offset 0x5C. As this support is related to - running the IGD ROM, which has other dependencies on the device appeari= ng - at guest address 00:02.0, it's expected that this fw_cfg file is only - relevant to a single PCI class VGA device with Intel vendor ID, appeari= ng - at PCI bus address 00:02.0. + space of the IGD device at offset 0x5C (or 0xC0 for Gen 11+ devices usi= ng + 64-bit BDSM). As this support is related to running the IGD ROM, which + has other dependencies on the device appearing at guest address 00:02.0, + it's expected that this fw_cfg file is only relevant to a single PCI + class VGA device with Intel vendor ID, appearing at PCI bus address 00:= 02.0. + +Upstream Seabios has OpRegion and BDSM (pre-Gen11 device only) support. +However, the support is not accepted by upstream EDK2/OVMF. A recommended +solution is to create a virtual OpRom with following DXE drivers: + +* IgdAssignmentDxe: Set up OpRegion and BDSM according to fw_cfg (must) +* IntelGopDriver: Closed-source Intel GOP driver +* PlatformGopPolicy: Protocol required by IntelGopDriver + +IntelGopDriver and PlatformGopPolicy is only required when enabling GOP on= IGD. + +The original IgdAssignmentDxe can be found at [3]. A Intel maintained vers= ion +with PlatformGopPolicy for industrial computing is at [4]. There is also an +unofficially maintained version with newer Gen11+ device support at [5]. +You need to build them with EDK2. + +For the IntelGopDriver, Intel never released it to public. You may contact +Intel support to get one as [4] said, if you are an Intel Premier Support +customer, or you can try extracting it from your host firmware using +"UEFI BIOS Updater"[6]. + +Once you got all the required DXE drivers, a Option ROM can be generated w= ith +EfiRom utility in EDK2, using + EfiRom -f 0x8086 -i -o output.rom \ + -e IgdAssignmentDxe.efi PlatformGOPPolicy.efi IntelGopDriver.efi + + +Known issues +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +When using OVMF as guest firmware, you may encounter the following warning: +warning: vfio_container_dma_map(0x55fab36ce610, 0x380010000000, 0x108000, = 0x7fd336000000) =3D -22 (Invalid argument) + +Solution: +Set the host physical address bits to IOMMU address width using + -cpu host,host-phys-bits-limit=3D +Or in libvirt XML with + + '/> + +The IOMMU address width can be determined with + echo $(( ((0x$(cat /sys/devices/virtual/iommu/dmar0/intel-iommu/cap) & 0= x3F0000) >> 16) + 1 )) +Refer https://edk2.groups.io/g/devel/topic/patch_v1/102359124 for more det= ails + + +Memory View +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +IGD has it own address space. To use system RAM as VRAM, a single-level pa= ge +table named Global Graphics Translation Table (GTT) is used for the address +translation. Each page table entry points a 4KB page. Illustration below s= hows +the translation flow on IGD with 64-bit GTT PTEs. + +(PTE_SIZE =3D=3D 8) +-------------+---+ + | Address | V | V: Valid Bit + +-------------+---+ + | ... | | +IGD:0x01ae9010 0xd740| 0x70ffc000 | 1 | Mem:0x42ba3e010^ +-----------------------> 0xd748| 0x42ba3e000 | 1 +------------------> +(addr >> 12) * PTE_SIZE 0xd750| 0x42ba3f000 | 1 | + | ... | | + +-------------+---+ +^ The address may be remapped by IOMMU + +The memory region store GTT is called GTT Stolen Memory (GSM) it is located +right below the Data Stolen Memory (DSM). Accessing this region directly is +not allowed, any access will immediately freeze the whole system. The only= way +to access it is through the second half of MMIO BAR0. + +The Data Stolen Memory is reserved by firmware, and acts as the VRAM in pr= e-OS +environments. In QEMU, guest firmware (Seabios/OVMF) is responsible for +reserving a continuous region and program its base address to BDSM registe= r, +then let VBIOS/GOP driver initializing this region. Illustration below sho= ws +how DSM is mapped. + + IGD Addr Space Host Addr Space Guest Addr S= pace + +-------------+ +-------------+ +-----------= --+ + | | | | | = | + | | | | | = | + | | +-------------+ +-----------= --+ + | | | Data Stolen | | Data Stole= n | + | | | (Guest) | | (Guest) = | + | | +------------>+-------------+<------->+-----------= --+<--Guest BDSM + | | | Passthrough | | EPT | = | Emulated by QEMU +DSMSIZE+-------------+ | with IOMMU | | Mapping | = | Programmed by guest FW + | | | | | | = | + | | | | | | = | + 0+-------------+--+ | | | = | + | +-------------+ | = | + | | Data Stolen | +-----------= --+ + | | (Host) | + +------------>+-------------+<--Host BDSM + Non- | | "real" one in HW + Passthrough | | Programmed by host= FW + +-------------+ =20 Footnotes =3D=3D=3D=3D=3D=3D=3D=3D=3D -[1] Nothing precludes adding additional emulated or assigned graphics devi= ces - as non-primary, other than the combination typically not working. I o= nly - intend to set user expectations, others are welcome to find working - combinations or fix whatever issues prevent this from working in the c= ommon - case. +[1] https://www.intel.com/content/www/us/en/docs/graphics-for-linux/develo= per-reference/1-0/dump-video-bios.html [2] # echo "vfio-pci" > /sys/bus/pci/devices/0000:00:02.0/driver_override +[3] https://web.archive.org/web/20240827012422/https://bugzilla.tianocore.= org/show_bug.cgi?id=3D935 + Tianocore bugzilla was down since Jan 2025 :( +[4] https://eci.intel.com/docs/3.3/components/kvm-hypervisor.html, Patch 0= 001-0004 +[5] https://github.com/tomitamoeko/VfioIgdPkg +[6] https://winraid.level1techs.com/t/tool-guide-news-uefi-bios-updater-ub= u/30357 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570894; cv=none; d=zohomail.com; s=zohoarc; b=h4LmCzd7ieF0A6Q2JgLUqHcR2ybXV4XqhQDPvQi2UnMVINnDIGXW52ttxJvWl717GtKX6lIAd2QasZFEZBE6Ckj9uqZkyBu2dMukRT3GdGUXj5XLlFTtWiQaDsUVeN3xt5uxR/An/Ff2wNmZIrz2u3gOhVq7+/0pj46MxR4AjPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570894; 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=znzbnhlbGLkfVH7d+2fBAjEPlohi/FMDzJbg3Om2RCE=; b=i13eb7sExy28ztTvvc5YBeH1EfX9kRoHe/XqUj4HtW/PBEHNOz/prizSJEHMqHOQ3zaCKUSaBJTSwgHsxYyLlnjafVGgJy8CCJ36+7MCNrZZir+UM+6szHUApN2ps+w+/Zsdgk+rQLNMFSl65uIAyxiILamrjagNc1Y9U5AK7QQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570894678360.43123991016375; Fri, 25 Apr 2025 01:48:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EiQ-0002lO-N1; Fri, 25 Apr 2025 04:47:22 -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 1u8EiB-0002hS-RW for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Ei9-0003BR-4P for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:07 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-WGqepQzdNWmKIsDLy2wRuw-1; Fri, 25 Apr 2025 04:47:00 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 430FA1800EC9; Fri, 25 Apr 2025 08:46:59 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 392E130001A2; Fri, 25 Apr 2025 08:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570824; 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=znzbnhlbGLkfVH7d+2fBAjEPlohi/FMDzJbg3Om2RCE=; b=DdWwGdLwHmSbpy7OFGLI5LCHrzVq7mZ3G5dPUrSi3nadOZ5gU/59Gsr7O2t3bfgw198nLV ZFs2dl4B93jJ1EVnTZrbBJkTgOa0RNhfPe7RZPgFUePIkuWfhoG0CluYvf6Ra02FSFYlaT kHKX44XUno5hSBXR+p8Xi5OPAuw9Uuw= X-MC-Unique: WGqepQzdNWmKIsDLy2wRuw-1 X-Mimecast-MFC-AGG-ID: WGqepQzdNWmKIsDLy2wRuw_1745570819 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Prasad Pandit , Avihai Horon Subject: [PULL 02/50] vfio: Open code vfio_migration_set_error() Date: Fri, 25 Apr 2025 10:45:55 +0200 Message-ID: <20250425084644.102196-3-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570895936019000 VFIO uses migration_file_set_error() in a couple of places where an 'Error **' parameter is not provided. In MemoryListener handlers : vfio_listener_region_add vfio_listener_log_global_stop vfio_listener_log_sync and in callback routines for IOMMU notifiers : vfio_iommu_map_notify vfio_iommu_map_dirty_notify Hopefully, one day, we will be able to extend these callbacks with an 'Error **' parameter and avoid setting the global migration error. Until then, it seems sensible to clearly identify the use cases, which are limited, and open code vfio_migration_set_error(). One other benefit is an improved error reporting when migration is running. While at it, slightly modify error reporting to only report errors when migration is not active and not always as is currently done. Cc: Prasad Pandit Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250324123315.637827-1-clg@redhat= .com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 60 +++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 9b493451c5e9b2b1388b42607984b0b2b1b1bede..5ef14931cd2dea6407999e6ef82= 5c7376f212678 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -145,13 +145,6 @@ bool vfio_viommu_preset(VFIODevice *vbasedev) return vbasedev->bcontainer->space->as !=3D &address_space_memory; } =20 -static void vfio_set_migration_error(int ret) -{ - if (migration_is_running()) { - migration_file_set_error(ret, NULL); - } -} - bool vfio_device_state_is_running(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; @@ -287,9 +280,14 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IO= MMUTLBEntry *iotlb) iova, iova + iotlb->addr_mask); =20 if (iotlb->target_as !=3D &address_space_memory) { - error_report("Wrong target AS \"%s\", only system memory is allowe= d", - iotlb->target_as->name ? iotlb->target_as->name : "no= ne"); - vfio_set_migration_error(-EINVAL); + error_setg(&local_err, + "Wrong target AS \"%s\", only system memory is allowed", + iotlb->target_as->name ? iotlb->target_as->name : "none= "); + if (migration_is_running()) { + migration_file_set_error(-EINVAL, local_err); + } else { + error_report_err(local_err); + } return; } =20 @@ -322,11 +320,16 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, I= OMMUTLBEntry *iotlb) ret =3D vfio_container_dma_unmap(bcontainer, iova, iotlb->addr_mask + 1, iotlb); if (ret) { - error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx") =3D %d (%s)", - bcontainer, iova, - iotlb->addr_mask + 1, ret, strerror(-ret)); - vfio_set_migration_error(ret); + error_setg(&local_err, + "vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") =3D %d (%s)", + bcontainer, iova, + iotlb->addr_mask + 1, ret, strerror(-ret)); + if (migration_is_running()) { + migration_file_set_error(ret, local_err); + } else { + error_report_err(local_err); + } } } out: @@ -1108,8 +1111,11 @@ static void vfio_listener_log_global_stop(MemoryList= ener *listener) if (ret) { error_prepend(&local_err, "vfio: Could not stop dirty page tracking - "); - error_report_err(local_err); - vfio_set_migration_error(ret); + if (migration_is_running()) { + migration_file_set_error(ret, local_err); + } else { + error_report_err(local_err); + } } } =20 @@ -1225,14 +1231,14 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifi= er *n, IOMMUTLBEntry *iotlb) trace_vfio_iommu_map_dirty_notify(iova, iova + iotlb->addr_mask); =20 if (iotlb->target_as !=3D &address_space_memory) { - error_report("Wrong target AS \"%s\", only system memory is allowe= d", - iotlb->target_as->name ? iotlb->target_as->name : "no= ne"); + error_setg(&local_err, + "Wrong target AS \"%s\", only system memory is allowed", + iotlb->target_as->name ? iotlb->target_as->name : "none= "); goto out; } =20 rcu_read_lock(); if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL, &local_er= r)) { - error_report_err(local_err); goto out_unlock; } =20 @@ -1243,7 +1249,6 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) "vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") failed - ", bcontainer, iova, iotlb->addr_mask + 1); - error_report_err(local_err); } =20 out_unlock: @@ -1251,7 +1256,11 @@ out_unlock: =20 out: if (ret) { - vfio_set_migration_error(ret); + if (migration_is_running()) { + migration_file_set_error(ret, local_err); + } else { + error_report_err(local_err); + } } } =20 @@ -1384,8 +1393,11 @@ static void vfio_listener_log_sync(MemoryListener *l= istener, if (vfio_log_sync_needed(bcontainer)) { ret =3D vfio_sync_dirty_bitmap(bcontainer, section, &local_err); if (ret) { - error_report_err(local_err); - vfio_set_migration_error(ret); + if (migration_is_running()) { + migration_file_set_error(ret, local_err); + } else { + error_report_err(local_err); + } } } } --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570912; cv=none; d=zohomail.com; s=zohoarc; b=bIQ6iHpnH9ACXAJqxQTCXFXR07LfFpbI+RxtKY+0Fci+roSeJ3Oo/gEp197ErCYSBxKdLvnVu2VB9bGsgGE+LPetZQd0OuSkCfThwYP8o+uI47rudltQPrxa9EvN+Qa8dCtflMxKxYbWML7+9OBCivGlsqrijhu8iPOnr83Sm/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570912; 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=gBgpznxmwMkdPoCPXXwHNcIYnDpO/rm3Dg3GzUyU6gI=; b=UcdGCHGv/pescPQV25d6FvNAxNSSmf2633E0tualm2c9/ZKWUZI4vkTFbFNu0J5nkd+0ppl5zmVqbuO8dcTL7ulMkHl4NiDQ5qwfSFk5mHSyBnvEQsjGGIbUMGV0+bA6kuOHeZJx1Oo5lpOTygMiDT/xV/jz+py/oB5ng7vDIzI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570912487325.46719792902365; Fri, 25 Apr 2025 01:48:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EiR-0002lh-BB; Fri, 25 Apr 2025 04:47:25 -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 1u8EiF-0002iF-4W for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:14 -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 1u8EiB-0003Bn-RC for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:10 -0400 Received: from mx-prod-mc-01.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-60-Q81m6SFDMya9M0Nh4lqxuA-1; Fri, 25 Apr 2025 04:47:03 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A78319560A1; Fri, 25 Apr 2025 08:47:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0343730001A2; Fri, 25 Apr 2025 08:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570827; 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=gBgpznxmwMkdPoCPXXwHNcIYnDpO/rm3Dg3GzUyU6gI=; b=UTBzSZvsvf6kU8DUl7F+8tQiHWTiVa7+CRTAznJdrF96de6ClT/fHKCLSlE4xGHt+b/RyT nhdhJb9LxyC061uwuVNT6iHz3NpvQCo3tOCLoGx9L23lw8xJBkrMMA3RTF1L56zrDB4LhY Ep4W8qzHtq0XugdqyA+OCxVYK9ll+4U= X-MC-Unique: Q81m6SFDMya9M0Nh4lqxuA-1 X-Mimecast-MFC-AGG-ID: Q81m6SFDMya9M0Nh4lqxuA_1745570822 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Amit Machhiwal , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 03/50] vfio/spapr: Enhance error handling in vfio_spapr_create_window() Date: Fri, 25 Apr 2025 10:45:56 +0200 Message-ID: <20250425084644.102196-4-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570914908019100 From: Amit Machhiwal Introduce an Error ** parameter to vfio_spapr_create_window() to enable structured error reporting. This allows the function to propagate detailed errors back to callers. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Amit Machhiwal Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250408124042.2695955-2-amachhiw@= linux.ibm.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/spapr.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 66a2d2bb0dc1b7370ab89075085db185ecc56c40..3d6354134c3d517b810d28404f3= e2a7eee9b1192 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -230,9 +230,9 @@ static int vfio_spapr_remove_window(VFIOContainer *cont= ainer, return 0; } =20 -static int vfio_spapr_create_window(VFIOContainer *container, +static bool vfio_spapr_create_window(VFIOContainer *container, MemoryRegionSection *section, - hwaddr *pgsize) + hwaddr *pgsize, Error **errp) { int ret =3D 0; VFIOContainerBase *bcontainer =3D &container->bcontainer; @@ -252,11 +252,11 @@ static int vfio_spapr_create_window(VFIOContainer *co= ntainer, pgmask =3D bcontainer->pgsizes & (pagesize | (pagesize - 1)); pagesize =3D pgmask ? (1ULL << (63 - clz64(pgmask))) : 0; if (!pagesize) { - error_report("Host doesn't support page size 0x%"PRIx64 - ", the supported mask is 0x%lx", - memory_region_iommu_get_min_page_size(iommu_mr), - bcontainer->pgsizes); - return -EINVAL; + error_setg_errno(errp, EINVAL, "Host doesn't support page size 0x%= "PRIx64 + ", the supported mask is 0x%lx", + memory_region_iommu_get_min_page_size(iommu_mr), + bcontainer->pgsizes); + return false; } =20 /* @@ -302,17 +302,17 @@ static int vfio_spapr_create_window(VFIOContainer *co= ntainer, } } if (ret) { - error_report("Failed to create a window, ret =3D %d (%m)", ret); - return -errno; + error_setg_errno(errp, errno, "Failed to create a window, ret =3D = %d", ret); + return false; } =20 if (create.start_addr !=3D section->offset_within_address_space) { vfio_spapr_remove_window(container, create.start_addr); =20 - error_report("Host doesn't support DMA window at %"HWADDR_PRIx", m= ust be %"PRIx64, - section->offset_within_address_space, - (uint64_t)create.start_addr); - return -EINVAL; + error_setg_errno(errp, EINVAL, "Host doesn't support DMA window at= %"HWADDR_PRIx + ", must be %"PRIx64, section->offset_within_addre= ss_space, + (uint64_t)create.start_addr); + return false; } trace_vfio_spapr_create_window(create.page_shift, create.levels, @@ -320,7 +320,7 @@ static int vfio_spapr_create_window(VFIOContainer *cont= ainer, create.start_addr); *pgsize =3D pagesize; =20 - return 0; + return true; } =20 static bool @@ -377,9 +377,8 @@ vfio_spapr_container_add_section_window(VFIOContainerBa= se *bcontainer, } } =20 - ret =3D vfio_spapr_create_window(container, section, &pgsize); - if (ret) { - error_setg_errno(errp, -ret, "Failed to create SPAPR window"); + ret =3D vfio_spapr_create_window(container, section, &pgsize, errp); + if (!ret) { return false; } =20 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571067; cv=none; d=zohomail.com; s=zohoarc; b=CmDBxycm641O9bcaRDQBJvLDC1aujhjs70dxF7Ou6EuGNmdhBUYI3qKuDCKQH3HqM33RQsU7WAv9CL5y5PNtEb7FQoeoccpvyvq7bzUE8Kf0is+hFur7/gbs9fuVQCseEO1WO0SDcxYoevMV/2cxavKFkZ5iPd2CKK4IYjebeV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571067; 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=FOjx7Ww77adIq1GqkqZD+JwC0UxWK+D5vsju9/L0IZ0=; b=BAfhwqk7zLkaI/HkhMAePwxOSHG1DywFvabdbH9SJF+Nm1YY/Hsyds6WzoXiiyz0GU10C5qAsFLu2MgtsL5AhNCuxrkVLupdw9V8J2fd1KTOb1JSIfgXk66RommHNAb9w9EMGrQOr61wZFOffODpMo1lV3hoIx/FAtH5LqBwtZ8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571067667353.5556365039432; Fri, 25 Apr 2025 01:51:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EiW-0002mZ-L1; Fri, 25 Apr 2025 04:47:28 -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 1u8EiI-0002iV-8l for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:14 -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 1u8EiD-0003Cx-K9 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:12 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-384-G8_9OlkmP7K3YvJh-q62cA-1; Fri, 25 Apr 2025 04:47:07 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2EB45180087B; Fri, 25 Apr 2025 08:47:06 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C6C7D30001A2; Fri, 25 Apr 2025 08:47:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570829; 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=FOjx7Ww77adIq1GqkqZD+JwC0UxWK+D5vsju9/L0IZ0=; b=bN+abl8QSaC2Vzw3NS1jo9A6ZRTg/gp+0AAOAd6/yTN+LTq3hjUD2ha/FsnzhXDlu/Mb78 ZCHCGncPceSrId3p1oxQwTel0bWC+C56qe+Q6k6j28A5N40YbVBmZOXKE4D2HkD6mmWcow +WlJ3NVz3gLe+2RTuppm8ecNJnlwOwE= X-MC-Unique: G8_9OlkmP7K3YvJh-q62cA-1 X-Mimecast-MFC-AGG-ID: G8_9OlkmP7K3YvJh-q62cA_1745570826 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Amit Machhiwal , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 04/50] vfio/spapr: Fix L2 crash with PCI device passthrough and memory > 128G Date: Fri, 25 Apr 2025 10:45:57 +0200 Message-ID: <20250425084644.102196-5-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571068374019000 From: Amit Machhiwal An L2 KVM guest fails to boot inside a pSeries LPAR when booted with a memory more than 128 GB and PCI device passthrough. The L2 guest also crashes when it is booted with a memory greater than 128 GB and a PCI device is hotplugged later. The issue arises from a conditional check for `levels > 1` in `spapr_tce_create_table()` within L1 KVM. This check is meant to prevent multi-level TCEs, which are not supported by the PowerVM hypervisor. As a result, when QEMU makes a `VFIO_IOMMU_SPAPR_TCE_CREATE` ioctl call with `levels > 1`, it triggers the conditional check and returns `EINVAL`, causing the guest to crash with the following errors: 2025-03-04T06:36:36.133117Z qemu-system-ppc64: Failed to create a window, = ret =3D -1 (Invalid argument) 2025-03-04T06:36:36.133176Z qemu-system-ppc64: Failed to create SPAPR wind= ow: Invalid argument qemu: hardware error: vfio: DMA mapping failed, unable to continue Fix this by checking the supported DDW "levels" returned by the VFIO_IOMMU_SPAPR_TCE_GET_INFO ioctl before attempting the TCE create ioctl in KVM. The patch has been tested on KVM guests with memory configurations of up to 390GB, and 450GB on PowerVM and bare-metal environments respectively. Signed-off-by: Amit Machhiwal Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250408124042.2695955-3-amachhiw@= linux.ibm.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/spapr.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 3d6354134c3d517b810d28404f3e2a7eee9b1192..7e5cb95f6a48ff87a0fddd62f9c= 3c297b790049d 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -26,6 +26,7 @@ typedef struct VFIOSpaprContainer { VFIOContainer container; MemoryListener prereg_listener; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; + unsigned int levels; } VFIOSpaprContainer; =20 OBJECT_DECLARE_SIMPLE_TYPE(VFIOSpaprContainer, VFIO_IOMMU_SPAPR); @@ -236,9 +237,11 @@ static bool vfio_spapr_create_window(VFIOContainer *co= ntainer, { int ret =3D 0; VFIOContainerBase *bcontainer =3D &container->bcontainer; + VFIOSpaprContainer *scontainer =3D container_of(container, VFIOSpaprCo= ntainer, + container); IOMMUMemoryRegion *iommu_mr =3D IOMMU_MEMORY_REGION(section->mr); uint64_t pagesize =3D memory_region_iommu_get_min_page_size(iommu_mr),= pgmask; - unsigned entries, bits_total, bits_per_level, max_levels; + unsigned entries, bits_total, bits_per_level, max_levels, ddw_levels; struct vfio_iommu_spapr_tce_create create =3D { .argsz =3D sizeof(crea= te) }; long rampagesize =3D qemu_minrampagesize(); =20 @@ -291,16 +294,29 @@ static bool vfio_spapr_create_window(VFIOContainer *c= ontainer, */ bits_per_level =3D ctz64(qemu_real_host_page_size()) + 8; create.levels =3D bits_total / bits_per_level; - if (bits_total % bits_per_level) { - ++create.levels; - } - max_levels =3D (64 - create.page_shift) / ctz64(qemu_real_host_page_si= ze()); - for ( ; create.levels <=3D max_levels; ++create.levels) { - ret =3D ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create); - if (!ret) { - break; + + ddw_levels =3D scontainer->levels; + if (ddw_levels > 1) { + if (bits_total % bits_per_level) { + ++create.levels; } + max_levels =3D (64 - create.page_shift) / ctz64(qemu_real_host_pag= e_size()); + for ( ; create.levels <=3D max_levels; ++create.levels) { + ret =3D ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &cre= ate); + if (!ret) { + break; + } + } + } else { /* ddw_levels =3D=3D 1 */ + if (create.levels > ddw_levels) { + error_setg_errno(errp, EINVAL, "Host doesn't support multi-lev= el TCE tables" + ". Use larger IO page size. Supported mask is= 0x%lx", + bcontainer->pgsizes); + return false; + } + ret =3D ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create); } + if (ret) { error_setg_errno(errp, errno, "Failed to create a window, ret =3D = %d", ret); return false; @@ -501,6 +517,8 @@ static bool vfio_spapr_container_setup(VFIOContainerBas= e *bcontainer, goto listener_unregister_exit; } =20 + scontainer->levels =3D info.ddw.levels; + if (v2) { bcontainer->pgsizes =3D info.ddw.pgsizes; /* --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570959; cv=none; d=zohomail.com; s=zohoarc; b=gMWDuYay4UxYdj3KAi0NW0BkqOqaE9hZdKdz/adSV+Wg7PmDIiCUtc5bgjSKzNxgQcXeT75i9v3CkysG9VBcQ1+p/sVmlfzu9SJmxmv/Ro+AfAJ8Al5lTZengN+Ds56D4TRum9pCjEuyXsDdNw0Q9Jne7sl4J39mPaOd2gfXsPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570959; 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=BJOF1w1PeJj5YFAydIBR1pLbDHKnDKjgoMMnTkRLmb4=; b=FpG9Sm8GOtMQcFK1N1ov8stWtP0nTxmu2HsDOSQV/EshKGSzGYcLbIQjm7mOwSbOXJh7uPPTup5RaW0gjqxcHttl2rLB6EDi5sZ5F/43mkDcoSiCkxSjiMeZri4lCru0eG7cQR72+m91XLQDy8tfmjO4F9uEZsusfzZomvno5nI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570959224439.11060680751154; Fri, 25 Apr 2025 01:49:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EiZ-0002nT-GY; Fri, 25 Apr 2025 04:47: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 1u8EiM-0002kb-Tt for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EiK-0003DC-UK for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:18 -0400 Received: from mx-prod-mc-04.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-171-PFH2Y9BZPfOFD7jogej8bw-1; Fri, 25 Apr 2025 04:47:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9BB1B1955DC5; Fri, 25 Apr 2025 08:47:09 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9FC8330001A2; Fri, 25 Apr 2025 08:47:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570836; 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=BJOF1w1PeJj5YFAydIBR1pLbDHKnDKjgoMMnTkRLmb4=; b=DICELZJ+O9MgRUWY+3NHxaYCOGm5USQwaIZvwX38OpcsIElJW9PYg2wFIzPIGHo/H89RhD Q8iCn9QCyq+UMhMIS1Cw2QwMCMHIB5Z7PVx/Esn9R2w8cAWV5nX4v0LzKoG8/eAmLx1WG4 oxJYEWDoTi3hqTwdqhfG2ZflTV6Q/l0= X-MC-Unique: PFH2Y9BZPfOFD7jogej8bw-1 X-Mimecast-MFC-AGG-ID: PFH2Y9BZPfOFD7jogej8bw_1745570829 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Avihai Horon , John Levon Subject: [PULL 05/50] vfio: Move vfio_mig_active() into migration.c Date: Fri, 25 Apr 2025 10:45:58 +0200 Message-ID: <20250425084644.102196-6-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570960934019100 vfio_mig_active() is part of the VFIO migration API. Move the definitions where VFIO migration is implemented. Reviewed-by: Avihai Horon Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-2-clg@redhat= .com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-2-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 16 ---------------- hw/vfio/migration.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 5ef14931cd2dea6407999e6ef825c7376f212678..2ea4e12c902c05fd707f7cb471e= a86a520a93f4f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -65,22 +65,6 @@ int vfio_kvm_device_fd =3D -1; * Device state interfaces */ =20 -bool vfio_mig_active(void) -{ - VFIODevice *vbasedev; - - if (QLIST_EMPTY(&vfio_device_list)) { - return false; - } - - QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { - if (vbasedev->migration_blocker) { - return false; - } - } - return true; -} - static Error *multiple_devices_migration_blocker; =20 /* diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d31= 82dde8f33514b 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1062,6 +1062,22 @@ void vfio_mig_add_bytes_transferred(unsigned long va= l) qatomic_add(&bytes_transferred, val); } =20 +bool vfio_mig_active(void) +{ + VFIODevice *vbasedev; + + if (QLIST_EMPTY(&vfio_device_list)) { + return false; + } + + QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { + if (vbasedev->migration_blocker) { + return false; + } + } + return true; +} + /* * Return true when either migration initialized or blocker registered. * Currently only return false when adding blocker fails which will --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570956; cv=none; d=zohomail.com; s=zohoarc; b=n+XruX7xXIcZBIfMRWgypHVDM/nx5QPx9aYWRBhWffO+7Xcw+59k32CMg+MFzFDRIDi3kzAIGsvPMTJfv0JTGUlidTlFcm8dUgliKWY52BdjZmOQ0HmpRAViT8BZHH61fBTBCYPjB56NHnstIs5l2e1y7dbCzVOsg90IfnKAu3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570956; 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=f+lRuREDYmAb7FRqFmPmzscmAV0dzWDCk1Z9mMPPcq0=; b=O3gyDVCEM/iSxKv9yBWnFRMJZ0bxbE42UD2242T/THnsMVzXqjcAWOsvE7pDJfV6l3BBipk+2qanzveeaRBq0lwqfmi0f/p6SVkxJ+yMhdU+4caxAkqosOn5ybyLURYfWzkYeFC5RFCoQiO122qKbjQAgd9OJxxJMuurcdE510w= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570956190975.6858856073552; Fri, 25 Apr 2025 01:49:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EiY-0002n6-7t; Fri, 25 Apr 2025 04:47:30 -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 1u8EiU-0002mY-67 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EiO-0003DO-C1 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:25 -0400 Received: from mx-prod-mc-03.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-311-W1hyRVRSOfKp2xrlT16HMQ-1; Fri, 25 Apr 2025 04:47:17 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22FE119560AE; Fri, 25 Apr 2025 08:47:16 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BB8C30001A2; Fri, 25 Apr 2025 08:47:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570839; 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=f+lRuREDYmAb7FRqFmPmzscmAV0dzWDCk1Z9mMPPcq0=; b=bbXbrJVwqN+M9UWmmJV7PkBTW7wM5Fgb7HMgltlsVkcwO8KS0WOmD1r/t4iDQvgifkiVhv i81gAGeE8HkYPVvDVuoD3ZW+N5v9pBzT0Wr4WlRiVVqMXaUUkjoUTVbNXTvyNbELjl3KC3 kI18FqxnRoalK78UFhtNeGf46TSfk6o= X-MC-Unique: W1hyRVRSOfKp2xrlT16HMQ-1 X-Mimecast-MFC-AGG-ID: W1hyRVRSOfKp2xrlT16HMQ_1745570836 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Avihai Horon , John Levon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 06/50] vfio: Rename vfio_reset_bytes_transferred() Date: Fri, 25 Apr 2025 10:45:59 +0200 Message-ID: <20250425084644.102196-7-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570958018019000 Enforce a 'vfio_mig_' prefix for the VFIO migration API to better reflect the namespace these routines belong to. Reviewed-by: Avihai Horon Reviewed-by: John Levon Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-3-clg@redhat= .com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-3-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 +- hw/vfio/migration.c | 2 +- migration/target.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f5b3f45a43aefc5e90137bb40de1d50d3abeff11..f58cae9e55c9a2816358160984f= ab18324fba0cf 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -295,7 +295,7 @@ int vfio_block_multiple_devices_migration(VFIODevice *v= basedev, Error **errp); void vfio_unblock_multiple_devices_migration(void); bool vfio_viommu_preset(VFIODevice *vbasedev); int64_t vfio_mig_bytes_transferred(void); -void vfio_reset_bytes_transferred(void); +void vfio_mig_reset_bytes_transferred(void); void vfio_mig_add_bytes_transferred(unsigned long val); bool vfio_device_state_is_running(VFIODevice *vbasedev); bool vfio_device_state_is_precopy(VFIODevice *vbasedev); diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index b5fb0d218808d010d8210612d3182dde8f33514b..8bf65b8e11094b8363692dba308= 4b762362c7dd6 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1052,7 +1052,7 @@ int64_t vfio_mig_bytes_transferred(void) return MIN(qatomic_read(&bytes_transferred), INT64_MAX); } =20 -void vfio_reset_bytes_transferred(void) +void vfio_mig_reset_bytes_transferred(void) { qatomic_set(&bytes_transferred, 0); } diff --git a/migration/target.c b/migration/target.c index a6ffa9a5ce312d1e64157b650827aa726eb4d364..f5d8cfe7c2a3473f4bd3f506814= 5598c60973c58 100644 --- a/migration/target.c +++ b/migration/target.c @@ -25,7 +25,7 @@ void migration_populate_vfio_info(MigrationInfo *info) =20 void migration_reset_vfio_bytes_transferred(void) { - vfio_reset_bytes_transferred(); + vfio_mig_reset_bytes_transferred(); } #else void migration_populate_vfio_info(MigrationInfo *info) --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571031; cv=none; d=zohomail.com; s=zohoarc; b=AsuEajDDVbcQHW5HWrXKBHU7Rck2QVRVSRDz529iHUukvuyLiOToKOsDJUzLJmJzgUebiKiq+otzzWqWJX0EYSgQSzKNYWC3vNrNpzeExEiJvGrSdD4YPFK0AODL7DZaJtZdafbQLIFCEdjZPsWBwoI2RbIOJNzRW/bZluBtqVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571031; 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=EAVkTegx08KSi2/p/LIgIi/c/VdoNv9CjIxpyafvHx4=; b=g2fP8eGvIO/OvPrlDgs14lkbk6BsF7kaUxnxl/+OGJW6okIbjI5Edz3a7oSc3IYv9LpLIVN44ohBAXVK4R6w/B3iouXR2FytuafJzK5YDkQXrcfsbz+QLvz6rtdpyWQoVLr1/PExpB0/xZDW304huL+W2sCqpUKkteCFAuuDZg8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571031902656.1689933010563; Fri, 25 Apr 2025 01:50:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eib-0002pD-Jl; Fri, 25 Apr 2025 04:47:33 -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 1u8EiZ-0002ng-3B for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EiW-0003Dd-Hj for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:30 -0400 Received: from mx-prod-mc-04.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-633--Cl4mEy2PgKlRjqE0OHQ_w-1; Fri, 25 Apr 2025 04:47:21 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4D8EE19560AB; Fri, 25 Apr 2025 08:47:20 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4291130002C3; Fri, 25 Apr 2025 08:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570846; 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=EAVkTegx08KSi2/p/LIgIi/c/VdoNv9CjIxpyafvHx4=; b=NWMaigpNykKV38X5VNvNfmf2yninT8onOZhyEDQyaQA37pKsF4dqaXell43A7tDAdqGo97 88rM3qzgbfKzRQbdO3KT4Bfl7BiwmiGht/ajIDPaIAlYJSPB6bYP6UEf5Wy3u2yN7jwHFI alS/7J0e/rooI+XoIWeIKtXk/nyEEXk= X-MC-Unique: -Cl4mEy2PgKlRjqE0OHQ_w-1 X-Mimecast-MFC-AGG-ID: -Cl4mEy2PgKlRjqE0OHQ_w_1745570840 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Kirti Wankhede , Avihai Horon , Prasad Pandit , John Levon Subject: [PULL 07/50] vfio: Introduce a new header file for external migration services Date: Fri, 25 Apr 2025 10:46:00 +0200 Message-ID: <20250425084644.102196-8-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571034234019100 The migration core subsystem makes use of the VFIO migration API to collect statistics on the number of bytes transferred. These services are declared in "hw/vfio/vfio-common.h" which also contains VFIO internal declarations. Move the migration declarations into a new header file "hw/vfio/vfio-migration.h" to reduce the exposure of VFIO internals. While at it, use a 'vfio_migration_' prefix for these services. To be noted, vfio_migration_add_bytes_transferred() is a VFIO migration internal service which we will be moved in the subsequent patches. Cc: Kirti Wankhede Cc: Avihai Horon Reviewed-by: Prasad Pandit Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-4-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 5 +---- include/hw/vfio/vfio-migration.h | 16 ++++++++++++++++ hw/vfio/migration-multifd.c | 5 +++-- hw/vfio/migration.c | 11 ++++++----- migration/target.c | 8 ++++---- 5 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 include/hw/vfio/vfio-migration.h diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f58cae9e55c9a2816358160984fab18324fba0cf..7a551bb2300f047b98c90a72ea0= b21356ecb668a 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -290,13 +290,10 @@ extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 -bool vfio_mig_active(void); int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **er= rp); void vfio_unblock_multiple_devices_migration(void); bool vfio_viommu_preset(VFIODevice *vbasedev); -int64_t vfio_mig_bytes_transferred(void); -void vfio_mig_reset_bytes_transferred(void); -void vfio_mig_add_bytes_transferred(unsigned long val); +void vfio_migration_add_bytes_transferred(unsigned long val); bool vfio_device_state_is_running(VFIODevice *vbasedev); bool vfio_device_state_is_precopy(VFIODevice *vbasedev); =20 diff --git a/include/hw/vfio/vfio-migration.h b/include/hw/vfio/vfio-migrat= ion.h new file mode 100644 index 0000000000000000000000000000000000000000..0d4ecd33d5d8c214bb77e0652b4= 405b6e43bcafa --- /dev/null +++ b/include/hw/vfio/vfio-migration.h @@ -0,0 +1,16 @@ +/* + * VFIO migration interface + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_VFIO_MIGRATION_H +#define HW_VFIO_VFIO_MIGRATION_H + +bool vfio_migration_active(void); +int64_t vfio_migration_bytes_transferred(void); +void vfio_migration_reset_bytes_transferred(void); + +#endif /* HW_VFIO_VFIO_MIGRATION_H */ diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..09aa57f5f890f37f7e36c857fd8= 13f55b1da2fce 100644 --- a/hw/vfio/migration-multifd.c +++ b/hw/vfio/migration-multifd.c @@ -11,6 +11,7 @@ =20 #include "qemu/osdep.h" #include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-migration.h" #include "migration/misc.h" #include "qapi/error.h" #include "qemu/bswap.h" @@ -575,7 +576,7 @@ vfio_save_complete_precopy_thread_config_state(VFIODevi= ce *vbasedev, return false; } =20 - vfio_mig_add_bytes_transferred(packet_len); + vfio_migration_add_bytes_transferred(packet_len); =20 return true; } @@ -645,7 +646,7 @@ vfio_multifd_save_complete_precopy_thread(SaveLiveCompl= etePrecopyThreadData *d, goto thread_exit; } =20 - vfio_mig_add_bytes_transferred(packet_size); + vfio_migration_add_bytes_transferred(packet_size); } =20 if (!vfio_save_complete_precopy_thread_config_state(vbasedev, diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 8bf65b8e11094b8363692dba3084b762362c7dd6..582d65932a6c590eaecd8bf0b76= 5f27d93896c72 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -17,6 +17,7 @@ =20 #include "system/runstate.h" #include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-migration.h" #include "migration/misc.h" #include "migration/savevm.h" #include "migration/vmstate.h" @@ -373,7 +374,7 @@ static ssize_t vfio_save_block(QEMUFile *f, VFIOMigrati= on *migration) qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE); qemu_put_be64(f, data_size); qemu_put_buffer(f, migration->data_buffer, data_size); - vfio_mig_add_bytes_transferred(data_size); + vfio_migration_add_bytes_transferred(data_size); =20 trace_vfio_save_block(migration->vbasedev->name, data_size); =20 @@ -1047,22 +1048,22 @@ static int vfio_block_migration(VFIODevice *vbasede= v, Error *err, Error **errp) =20 /* ---------------------------------------------------------------------- = */ =20 -int64_t vfio_mig_bytes_transferred(void) +int64_t vfio_migration_bytes_transferred(void) { return MIN(qatomic_read(&bytes_transferred), INT64_MAX); } =20 -void vfio_mig_reset_bytes_transferred(void) +void vfio_migration_reset_bytes_transferred(void) { qatomic_set(&bytes_transferred, 0); } =20 -void vfio_mig_add_bytes_transferred(unsigned long val) +void vfio_migration_add_bytes_transferred(unsigned long val) { qatomic_add(&bytes_transferred, val); } =20 -bool vfio_mig_active(void) +bool vfio_migration_active(void) { VFIODevice *vbasedev; =20 diff --git a/migration/target.c b/migration/target.c index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..12fd399f0c521c5c28535b58f24= feab6845947fd 100644 --- a/migration/target.c +++ b/migration/target.c @@ -11,21 +11,21 @@ #include CONFIG_DEVICES =20 #ifdef CONFIG_VFIO -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-migration.h" #endif =20 #ifdef CONFIG_VFIO void migration_populate_vfio_info(MigrationInfo *info) { - if (vfio_mig_active()) { + if (vfio_migration_active()) { info->vfio =3D g_malloc0(sizeof(*info->vfio)); - info->vfio->transferred =3D vfio_mig_bytes_transferred(); + info->vfio->transferred =3D vfio_migration_bytes_transferred(); } } =20 void migration_reset_vfio_bytes_transferred(void) { - vfio_mig_reset_bytes_transferred(); + vfio_migration_reset_bytes_transferred(); } #else void migration_populate_vfio_info(MigrationInfo *info) --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571209; cv=none; d=zohomail.com; s=zohoarc; b=GlxcCxP3aKB9uy+e55U0lLoN5/lRpqqOUBXbuvx1Aoljw+TXwaUR8BGC0zq9enaDswQmlZbqnvTBKpc4zJ34hCvKMw/RtI8xGTEQcG9K2WAyHae1lEido/26Yip0txOlCyRaHIeexZtVAK7MpQvnyhLLO+r2hd5fDj7sXDp+9gQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571209; 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=5ElvJk4d/udYXi++Bf5ZwZ/ZHHJwQTpXFh+529TpK0U=; b=deGq0UdGv8KSn4S9WsSdtkWoChLJqBlIDil8GCZ9NF1VFsfdVt/YPkuaFhFdlC0OLJFB2LQwZHf1WvzGI1W256whS8tBph1a6md6MwLSa96lnyAaNBfz6faWGl76byNI9XpS681W9GHnWeM89sJf8Su4TsK+fthpNfZznlMg0jc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571208827180.19315957529204; Fri, 25 Apr 2025 01:53:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ein-0002qD-6o; Fri, 25 Apr 2025 04:47:45 -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 1u8EiZ-0002nh-4E for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:31 -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 1u8EiW-0003Dg-Ta for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:30 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-RwDOgm5JNdqnN3L0HPsRog-1; Fri, 25 Apr 2025 04:47:23 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A9406180036F; Fri, 25 Apr 2025 08:47:22 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C8BA430001A2; Fri, 25 Apr 2025 08:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570848; 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=5ElvJk4d/udYXi++Bf5ZwZ/ZHHJwQTpXFh+529TpK0U=; b=EJcR4Ex1I0cCuZNpuXCit9mabY3Z2gb0WkGjVuaDDKQr8N/t0TvAvz2Mdx0OLgxIAhI29B 1Iyw8A2SP5UhmGdIM6/dZIINkfi5gWXNxx6labkAWgJVu8tiV5LZBNjvXuTs2oIUESr05f hjI6luR7X1UxPPftyF7FRzBXBCpLtaw= X-MC-Unique: RwDOgm5JNdqnN3L0HPsRog-1 X-Mimecast-MFC-AGG-ID: RwDOgm5JNdqnN3L0HPsRog_1745570842 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon Subject: [PULL 08/50] vfio: Make vfio_un/block_multiple_devices_migration() static Date: Fri, 25 Apr 2025 10:46:01 +0200 Message-ID: <20250425084644.102196-9-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571211592019100 Both of these routines are only used in file "migration.c". Move them there. Reviewed-by: Joao Martins Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-5-clg@redhat= .com Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-5-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 -- hw/vfio/common.c | 59 ----------------------------------- hw/vfio/migration.c | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 61 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 7a551bb2300f047b98c90a72ea0b21356ecb668a..5f1c0bee9de3b4ed38a63872bca= 7db5bde3815c4 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -290,8 +290,6 @@ extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 -int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **er= rp); -void vfio_unblock_multiple_devices_migration(void); bool vfio_viommu_preset(VFIODevice *vbasedev); void vfio_migration_add_bytes_transferred(unsigned long val); bool vfio_device_state_is_running(VFIODevice *vbasedev); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 2ea4e12c902c05fd707f7cb471ea86a520a93f4f..d65e77b93a15dff8ef244e296ff= 073c906e4af35 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -40,7 +40,6 @@ #include "trace.h" #include "qapi/error.h" #include "migration/misc.h" -#include "migration/blocker.h" #include "migration/qemu-file.h" #include "system/tcg.h" #include "system/tpm.h" @@ -65,64 +64,6 @@ int vfio_kvm_device_fd =3D -1; * Device state interfaces */ =20 -static Error *multiple_devices_migration_blocker; - -/* - * Multiple devices migration is allowed only if all devices support P2P - * migration. Single device migration is allowed regardless of P2P migrati= on - * support. - */ -static bool vfio_multiple_devices_migration_is_supported(void) -{ - VFIODevice *vbasedev; - unsigned int device_num =3D 0; - bool all_support_p2p =3D true; - - QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { - if (vbasedev->migration) { - device_num++; - - if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) { - all_support_p2p =3D false; - } - } - } - - return all_support_p2p || device_num <=3D 1; -} - -int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **er= rp) -{ - if (vfio_multiple_devices_migration_is_supported()) { - return 0; - } - - if (vbasedev->enable_migration =3D=3D ON_OFF_AUTO_ON) { - error_setg(errp, "Multiple VFIO devices migration is supported onl= y if " - "all of them support P2P migration"); - return -EINVAL; - } - - if (multiple_devices_migration_blocker) { - return 0; - } - - error_setg(&multiple_devices_migration_blocker, - "Multiple VFIO devices migration is supported only if all o= f " - "them support P2P migration"); - return migrate_add_blocker_normal(&multiple_devices_migration_blocker, - errp); -} - -void vfio_unblock_multiple_devices_migration(void) -{ - if (!multiple_devices_migration_blocker || - !vfio_multiple_devices_migration_is_supported()) { - return; - } - - migrate_del_blocker(&multiple_devices_migration_blocker); -} =20 bool vfio_viommu_preset(VFIODevice *vbasedev) { diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 582d65932a6c590eaecd8bf0b765f27d93896c72..ace3d8548edfa438a6479df6a61= 7ceb8f495c622 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1022,6 +1022,65 @@ static int vfio_migration_init(VFIODevice *vbasedev) return 0; } =20 +static Error *multiple_devices_migration_blocker; + +/* + * Multiple devices migration is allowed only if all devices support P2P + * migration. Single device migration is allowed regardless of P2P migrati= on + * support. + */ +static bool vfio_multiple_devices_migration_is_supported(void) +{ + VFIODevice *vbasedev; + unsigned int device_num =3D 0; + bool all_support_p2p =3D true; + + QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { + if (vbasedev->migration) { + device_num++; + + if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) { + all_support_p2p =3D false; + } + } + } + + return all_support_p2p || device_num <=3D 1; +} + +static int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Err= or **errp) +{ + if (vfio_multiple_devices_migration_is_supported()) { + return 0; + } + + if (vbasedev->enable_migration =3D=3D ON_OFF_AUTO_ON) { + error_setg(errp, "Multiple VFIO devices migration is supported onl= y if " + "all of them support P2P migration"); + return -EINVAL; + } + + if (multiple_devices_migration_blocker) { + return 0; + } + + error_setg(&multiple_devices_migration_blocker, + "Multiple VFIO devices migration is supported only if all o= f " + "them support P2P migration"); + return migrate_add_blocker_normal(&multiple_devices_migration_blocker, + errp); +} + +static void vfio_unblock_multiple_devices_migration(void) +{ + if (!multiple_devices_migration_blocker || + !vfio_multiple_devices_migration_is_supported()) { + return; + } + + migrate_del_blocker(&multiple_devices_migration_blocker); +} + static void vfio_migration_deinit(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571111; cv=none; d=zohomail.com; s=zohoarc; b=Jj7f7qDazpLw7nIWU7BPtIZ0mQy39K64qpNuzfbAoWkfwiixQY+N/q7axYVmsBMlHJ+E9XRTrz5Oh2eYytPJsHm7Ea5ycnUCEjZWFNxYogg96vJFg+4B7D4qGTg5IsSF6m5eSB0jXSzY341rYUQwpCf+Fs2PUT2Z77v0kD3exbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571111; 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=RuQChiOuSII9qmHfsEBsTXh2AFUvBk5M8cAL20A/sOM=; b=ZcMVN1MURSchNO7s5zDMdHYxQNu8LL1GifXKq88/+jlFN8c65j2KjG8uf/1BOyhOaQg2CADqWFKYl+0DBbmuZfuJa5Ju2hOkZEQL2WXlA4CTJ/I6sYvDAa91mw0fHAfjlXbUBRXp2qJpqc4pcEW8A7ehPWJjS4k8uVApt02PBPI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571111889699.177679383833; Fri, 25 Apr 2025 01:51:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eio-0002rC-Is; Fri, 25 Apr 2025 04:47:46 -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 1u8Eib-0002pb-NQ for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:34 -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 1u8EiZ-0003Dx-SX for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:33 -0400 Received: from mx-prod-mc-05.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-610-KlUlALyqMqG7cOBN1yZz_w-1; Fri, 25 Apr 2025 04:47:26 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4E7311956094; Fri, 25 Apr 2025 08:47:25 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3011630001A2; Fri, 25 Apr 2025 08:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570851; 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=RuQChiOuSII9qmHfsEBsTXh2AFUvBk5M8cAL20A/sOM=; b=hgMEFusWO1R8Q1ty5bKCwbI5GpzNiVSJISF4q7JXDmb65DaWyo9SmGQe4aEBXDkGC1VGDB /s5QISrdTrpzHTaCX0ymZx8VcuCXw2gBAkxMwbiW2mBmtQSIF/G3XQwJbVAGQfzf6AEAVN /6es4vK/Dm4zMzGeRmqOH9u0Q5lvC70= X-MC-Unique: KlUlALyqMqG7cOBN1yZz_w-1 X-Mimecast-MFC-AGG-ID: KlUlALyqMqG7cOBN1yZz_w_1745570845 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Joao Martins Subject: [PULL 09/50] vfio: Make vfio_viommu_preset() static Date: Fri, 25 Apr 2025 10:46:02 +0200 Message-ID: <20250425084644.102196-10-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571112443019000 This routine is only used in file "migration.c". Move it there. Reviewed-by: John Levon Reviewed-by: Joao Martins Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-6-clg@redhat= .com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-6-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 1 - hw/vfio/common.c | 5 ----- hw/vfio/migration.c | 5 +++++ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 5f1c0bee9de3b4ed38a63872bca7db5bde3815c4..8c5692150698b9a4a8eb534bafc= 5623d9cf2d5a5 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -290,7 +290,6 @@ extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 -bool vfio_viommu_preset(VFIODevice *vbasedev); void vfio_migration_add_bytes_transferred(unsigned long val); bool vfio_device_state_is_running(VFIODevice *vbasedev); bool vfio_device_state_is_precopy(VFIODevice *vbasedev); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index d65e77b93a15dff8ef244e296ff073c906e4af35..679076343ac0a736a4f6fe597c2= f851a87381a41 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -65,11 +65,6 @@ int vfio_kvm_device_fd =3D -1; */ =20 =20 -bool vfio_viommu_preset(VFIODevice *vbasedev) -{ - return vbasedev->bcontainer->space->as !=3D &address_space_memory; -} - bool vfio_device_state_is_running(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index ace3d8548edfa438a6479df6a617ceb8f495c622..b5bb0cd09252deb8fdd87879e2a= 6802efa6d94a8 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1138,6 +1138,11 @@ bool vfio_migration_active(void) return true; } =20 +static bool vfio_viommu_preset(VFIODevice *vbasedev) +{ + return vbasedev->bcontainer->space->as !=3D &address_space_memory; +} + /* * Return true when either migration initialized or blocker registered. * Currently only return false when adding blocker fails which will --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571275; cv=none; d=zohomail.com; s=zohoarc; b=n0hTEG/h7pvSC9nuom2iheEcBcEouwgG8FCY+VGjOjTxEdA6Tshz7XxGuxxm4RTB/g13bMvxYzTShivPpImnBzz+OnAfdDIbb3MxhhkPeGH0n3SvV8PU6hKrFhtmB2hHNuARtj2EEgiUyxklqWCY8QFfsco+kY1lG0U8gcdEJcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571275; 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=ND0UEcb7648PvNamrEAMferP+6Blk+X4eOcZopsGZE8=; b=hYV6DADsWBQcMVZozp7mJNDNI4aHaLBDR8ZcU3/o8/lJnsg3mRqeMOnmKtsJUzon6ZOErwQJzlQLLSb/WuEU5C+7g0mtNJ60QZCpCb4NqOFTU+1Ps+YJFdDBszX3c3SNi94Mg0Y+HfHyW2H8ZIHMqjZZKc/2evE+JzbUjcwVbnQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17455712750721.1432394592100081; Fri, 25 Apr 2025 01:54:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eip-0002rT-ME; Fri, 25 Apr 2025 04:47:47 -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 1u8Eik-0002qZ-P8 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:45 -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 1u8Eie-0003EC-Tj for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:40 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-K3A_jVPxNFGKPIwl961-Eg-1; Fri, 25 Apr 2025 04:47:30 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 38CB01800982; Fri, 25 Apr 2025 08:47:29 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4CE3130001A2; Fri, 25 Apr 2025 08:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570856; 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=ND0UEcb7648PvNamrEAMferP+6Blk+X4eOcZopsGZE8=; b=FMWkenXGtkcKBwjl80Vblem4vlcr2H41eTlH8oN/nY7gQLL0XNzHZr7nzOfp2uoi2a5Xk7 f063XWc6GeiZZPu0OnLxxGoiOcP22VXBd0bIx/QZeY0Ngfi1rN4+vPYAQ6hX/cdRYbIcwL y/FaB5mABmsI0gF+l/RtfecSxm4ydlw= X-MC-Unique: K3A_jVPxNFGKPIwl961-Eg-1 X-Mimecast-MFC-AGG-ID: K3A_jVPxNFGKPIwl961-Eg_1745570849 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Kirti Wankhede , Avihai Horon , Prasad Pandit , John Levon Subject: [PULL 10/50] vfio: Introduce a new header file for internal migration services Date: Fri, 25 Apr 2025 10:46:03 +0200 Message-ID: <20250425084644.102196-11-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571277267019000 Gather all VFIO migration related declarations into "vfio-migration-internal.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Cc: Kirti Wankhede Cc: Avihai Horon Reviewed-by: Prasad Pandit Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-7-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-migration-internal.h | 72 +++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 52 +--------------------- hw/vfio/common.c | 1 + hw/vfio/migration-multifd.c | 2 +- hw/vfio/migration.c | 1 + hw/vfio/pci.c | 1 + 6 files changed, 77 insertions(+), 52 deletions(-) create mode 100644 hw/vfio/vfio-migration-internal.h diff --git a/hw/vfio/vfio-migration-internal.h b/hw/vfio/vfio-migration-int= ernal.h new file mode 100644 index 0000000000000000000000000000000000000000..ab6a1bad9b513aa61557905e72e= 5c6b264372276 --- /dev/null +++ b/hw/vfio/vfio-migration-internal.h @@ -0,0 +1,72 @@ +/* + * VFIO migration + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_VFIO_MIGRATION_INTERNAL_H +#define HW_VFIO_VFIO_MIGRATION_INTERNAL_H + +#ifdef CONFIG_LINUX +#include +#endif + +#include "qemu/typedefs.h" +#include "qemu/notify.h" + +/* + * Flags to be used as unique delimiters for VFIO devices in the migration + * stream. These flags are composed as: + * 0xffffffff =3D> MSB 32-bit all 1s + * 0xef10 =3D> Magic ID, represents emulated (virtual) function IO + * 0x0000 =3D> 16-bits reserved for flags + * + * The beginning of state information is marked by _DEV_CONFIG_STATE, + * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a + * certain state information is marked by _END_OF_STATE. + */ +#define VFIO_MIG_FLAG_END_OF_STATE (0xffffffffef100001ULL) +#define VFIO_MIG_FLAG_DEV_CONFIG_STATE (0xffffffffef100002ULL) +#define VFIO_MIG_FLAG_DEV_SETUP_STATE (0xffffffffef100003ULL) +#define VFIO_MIG_FLAG_DEV_DATA_STATE (0xffffffffef100004ULL) +#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL) + +typedef struct VFIODevice VFIODevice; +typedef struct VFIOMultifd VFIOMultifd; + +typedef struct VFIOMigration { + struct VFIODevice *vbasedev; + VMChangeStateEntry *vm_state; + NotifierWithReturn migration_state; + uint32_t device_state; + int data_fd; + void *data_buffer; + size_t data_buffer_size; + uint64_t mig_flags; + uint64_t precopy_init_size; + uint64_t precopy_dirty_size; + bool multifd_transfer; + VFIOMultifd *multifd; + bool initial_data_sent; + + bool event_save_iterate_started; + bool event_precopy_empty_hit; +} VFIOMigration; + +bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp); +void vfio_migration_exit(VFIODevice *vbasedev); +int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp); +int vfio_load_device_config_state(QEMUFile *f, void *opaque); + +#ifdef CONFIG_LINUX +int vfio_migration_set_state(VFIODevice *vbasedev, + enum vfio_device_mig_state new_state, + enum vfio_device_mig_state recover_state, + Error **errp); +#endif + +void vfio_migration_add_bytes_transferred(unsigned long val); + +#endif /* HW_VFIO_VFIO_MIGRATION_INTERNAL_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 8c5692150698b9a4a8eb534bafc5623d9cf2d5a5..05c88753ce93ab9df7863082d93= 8467d21d76967 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -23,7 +23,6 @@ =20 #include "system/memory.h" #include "qemu/queue.h" -#include "qemu/notify.h" #include "ui/console.h" #include "hw/display/ramfb.h" #ifdef CONFIG_LINUX @@ -36,23 +35,6 @@ =20 #define VFIO_MSG_PREFIX "vfio %s: " =20 -/* - * Flags to be used as unique delimiters for VFIO devices in the migration - * stream. These flags are composed as: - * 0xffffffff =3D> MSB 32-bit all 1s - * 0xef10 =3D> Magic ID, represents emulated (virtual) function IO - * 0x0000 =3D> 16-bits reserved for flags - * - * The beginning of state information is marked by _DEV_CONFIG_STATE, - * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a - * certain state information is marked by _END_OF_STATE. - */ -#define VFIO_MIG_FLAG_END_OF_STATE (0xffffffffef100001ULL) -#define VFIO_MIG_FLAG_DEV_CONFIG_STATE (0xffffffffef100002ULL) -#define VFIO_MIG_FLAG_DEV_SETUP_STATE (0xffffffffef100003ULL) -#define VFIO_MIG_FLAG_DEV_DATA_STATE (0xffffffffef100004ULL) -#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL) - enum { VFIO_DEVICE_TYPE_PCI =3D 0, VFIO_DEVICE_TYPE_PLATFORM =3D 1, @@ -78,27 +60,6 @@ typedef struct VFIORegion { uint8_t nr; /* cache the region number for debug */ } VFIORegion; =20 -typedef struct VFIOMultifd VFIOMultifd; - -typedef struct VFIOMigration { - struct VFIODevice *vbasedev; - VMChangeStateEntry *vm_state; - NotifierWithReturn migration_state; - uint32_t device_state; - int data_fd; - void *data_buffer; - size_t data_buffer_size; - uint64_t mig_flags; - uint64_t precopy_init_size; - uint64_t precopy_dirty_size; - bool multifd_transfer; - VFIOMultifd *multifd; - bool initial_data_sent; - - bool event_save_iterate_started; - bool event_precopy_empty_hit; -} VFIOMigration; - struct VFIOGroup; =20 typedef struct VFIOContainer { @@ -136,6 +97,7 @@ typedef struct VFIOIOMMUFDContainer { OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD); =20 typedef struct VFIODeviceOps VFIODeviceOps; +typedef struct VFIOMigration VFIOMigration; =20 typedef struct VFIODevice { QLIST_ENTRY(VFIODevice) next; @@ -290,13 +252,9 @@ extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 -void vfio_migration_add_bytes_transferred(unsigned long val); bool vfio_device_state_is_running(VFIODevice *vbasedev); bool vfio_device_state_is_precopy(VFIODevice *vbasedev); =20 -int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp); -int vfio_load_device_config_state(QEMUFile *f, void *opaque); - #ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); @@ -311,16 +269,8 @@ struct vfio_info_cap_header * vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id); struct vfio_info_cap_header * vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id); - -int vfio_migration_set_state(VFIODevice *vbasedev, - enum vfio_device_mig_state new_state, - enum vfio_device_mig_state recover_state, - Error **errp); #endif =20 -bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp); -void vfio_migration_exit(VFIODevice *vbasedev); - int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); bool vfio_devices_all_dirty_tracking_started( const VFIOContainerBase *bcontainer); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 679076343ac0a736a4f6fe597c2f851a87381a41..bef5414dd7a2b1f005b75816ff4= 6b4f390c630b1 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -43,6 +43,7 @@ #include "migration/qemu-file.h" #include "system/tcg.h" #include "system/tpm.h" +#include "vfio-migration-internal.h" =20 VFIODeviceList vfio_device_list =3D QLIST_HEAD_INITIALIZER(vfio_device_list); diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c index 09aa57f5f890f37f7e36c857fd813f55b1da2fce..a3005226b9ca22ff27d9d49339d= 9828a43713932 100644 --- a/hw/vfio/migration-multifd.c +++ b/hw/vfio/migration-multifd.c @@ -11,7 +11,6 @@ =20 #include "qemu/osdep.h" #include "hw/vfio/vfio-common.h" -#include "hw/vfio/vfio-migration.h" #include "migration/misc.h" #include "qapi/error.h" #include "qemu/bswap.h" @@ -22,6 +21,7 @@ #include "io/channel-buffer.h" #include "migration/qemu-file.h" #include "migration-multifd.h" +#include "vfio-migration-internal.h" #include "trace.h" =20 #define VFIO_DEVICE_STATE_CONFIG_STATE (1) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index b5bb0cd09252deb8fdd87879e2a6802efa6d94a8..54f6ca3e7ce0024ac103535cb19= 78b1941d0bf15 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -31,6 +31,7 @@ #include "pci.h" #include "trace.h" #include "hw/hw.h" +#include "vfio-migration-internal.h" =20 /* * This is an arbitrary size based on migration of mlx5 devices, where typ= ically diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index f87f3ccbe1546ae3ae01b55470fab4feb5262de5..b0aac2f3a0b93ad3af6d8b71c6d= c0f9d390ea475 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -44,6 +44,7 @@ #include "migration/blocker.h" #include "migration/qemu-file.h" #include "system/iommufd.h" +#include "vfio-migration-internal.h" =20 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug" =20 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571242; cv=none; d=zohomail.com; s=zohoarc; b=Ny7tljGWUxyANgy9AnoTcYmOMh18w4eyutSDHVqdbCuE6CFtv8a/Z/CbMODKziN/YxfRe8KzPe5OEoyCrBpZ94ubSz6J8Kyr3v/9DMqVdNOz6fMAiwl2PCfJffOXuJi/h/jV/2TvXmg0RlwM/xmBFovcLr75WbcsHxtqAqR7rVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571242; 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=pFKVfC+mPXFEgEjYEyqCmo1qq98Q48Y9AjnID8hqikE=; b=TyI44RHkXwO7e+CHZMhinpIdw77NKQOLduPSwK/I1Gq3MeEbYgJPmN8BrFX2oPhl+mC/DOP1LFNEMEwbveGzbE3gDa82WfkSrfz+ikoBAGQdmAR+JBvfjVK3GsD15u5h1hQdQwoehVZHaqQzR8S8z4f20aDct7P3UNZ08fRSdCw= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571242071986.7629253930259; Fri, 25 Apr 2025 01:54:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eiq-0002sF-OE; Fri, 25 Apr 2025 04:47:48 -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 1u8Ein-0002qk-98 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Eig-0003EG-Ay for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:41 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-za_iRC0cMlqIzBiTwXFOVw-1; Fri, 25 Apr 2025 04:47:32 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1EAE18001EA; Fri, 25 Apr 2025 08:47:31 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9635D30001A2; Fri, 25 Apr 2025 08:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570857; 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=pFKVfC+mPXFEgEjYEyqCmo1qq98Q48Y9AjnID8hqikE=; b=JmhnpNuX5vHutNDZKlo6MVttHVJGe7BRu9WmS+bYsWRPicmscDGXonVxLR8dV08X/e/3Ud Q5ysSRd98lLh0eQGHbc2xiiiLn6dquCCN1ottPAmVpRJet/I5kC6zWWhD20KMgIyKEKN79 84kvbRN4Fgp00+GCnpoXIvJd6elKLy0= X-MC-Unique: za_iRC0cMlqIzBiTwXFOVw-1 X-Mimecast-MFC-AGG-ID: za_iRC0cMlqIzBiTwXFOVw_1745570851 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Prasad Pandit , John Levon Subject: [PULL 11/50] vfio: Move vfio_device_state_is_running/precopy() into migration.c Date: Fri, 25 Apr 2025 10:46:04 +0200 Message-ID: <20250425084644.102196-12-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571243565019100 These routines are migration related. Move their declaration and implementation under the migration files. Reviewed-by: Prasad Pandit Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-8-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-migration-internal.h | 2 ++ include/hw/vfio/vfio-common.h | 3 --- hw/vfio/common.c | 16 ---------------- hw/vfio/migration.c | 16 ++++++++++++++++ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/hw/vfio/vfio-migration-internal.h b/hw/vfio/vfio-migration-int= ernal.h index ab6a1bad9b513aa61557905e72e5c6b264372276..a8b456b239df8a54ab96daf56b5= f778b3ffbfa5e 100644 --- a/hw/vfio/vfio-migration-internal.h +++ b/hw/vfio/vfio-migration-internal.h @@ -57,6 +57,8 @@ typedef struct VFIOMigration { =20 bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp); void vfio_migration_exit(VFIODevice *vbasedev); +bool vfio_device_state_is_running(VFIODevice *vbasedev); +bool vfio_device_state_is_precopy(VFIODevice *vbasedev); int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp); int vfio_load_device_config_state(QEMUFile *f, void *opaque); =20 diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 05c88753ce93ab9df7863082d938467d21d76967..fa0b74d5eac53cc49e9da97007c= c36ca7b8d8611 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -252,9 +252,6 @@ extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 -bool vfio_device_state_is_running(VFIODevice *vbasedev); -bool vfio_device_state_is_precopy(VFIODevice *vbasedev); - #ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index bef5414dd7a2b1f005b75816ff46b4f390c630b1..8f55e7b212991acb8be63c92432= 7206c8d1727b0 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -66,22 +66,6 @@ int vfio_kvm_device_fd =3D -1; */ =20 =20 -bool vfio_device_state_is_running(VFIODevice *vbasedev) -{ - VFIOMigration *migration =3D vbasedev->migration; - - return migration->device_state =3D=3D VFIO_DEVICE_STATE_RUNNING || - migration->device_state =3D=3D VFIO_DEVICE_STATE_RUNNING_P2P; -} - -bool vfio_device_state_is_precopy(VFIODevice *vbasedev) -{ - VFIOMigration *migration =3D vbasedev->migration; - - return migration->device_state =3D=3D VFIO_DEVICE_STATE_PRE_COPY || - migration->device_state =3D=3D VFIO_DEVICE_STATE_PRE_COPY_P2P; -} - static bool vfio_devices_all_device_dirty_tracking_started( const VFIOContainerBase *bcontainer) { diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 54f6ca3e7ce0024ac103535cb1978b1941d0bf15..4da05263255b9f858539a55d03d= 1b35609a4c697 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1220,3 +1220,19 @@ void vfio_migration_exit(VFIODevice *vbasedev) =20 migrate_del_blocker(&vbasedev->migration_blocker); } + +bool vfio_device_state_is_running(VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + + return migration->device_state =3D=3D VFIO_DEVICE_STATE_RUNNING || + migration->device_state =3D=3D VFIO_DEVICE_STATE_RUNNING_P2P; +} + +bool vfio_device_state_is_precopy(VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + + return migration->device_state =3D=3D VFIO_DEVICE_STATE_PRE_COPY || + migration->device_state =3D=3D VFIO_DEVICE_STATE_PRE_COPY_P2P; +} --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571112; cv=none; d=zohomail.com; s=zohoarc; b=IbNHvPEtGnZc5/gkwBK4P75+DdB/tkXTn8ALlxfVHK2PKNesMowKZ/pTq07+SH+pdAcx84T501mYSwWCmw3m22OsgQ/uY9N1MN6yKttxprMBRYwJFNAYxynJBNVDDzBNPUeub1Fwj5mmbuCk0keLzHFykIPCn4CUNjiBFk7m4yo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571112; 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=ku80WnsyoY1yoKJVZbi1RE32bDtPSkPy28YgWR2YXGE=; b=E/JIzr6FlTZzOmxlxXVZnshdyZRdJRbMxiY9MdjMttbBDPEn9WpdE6Gg2hwzpKbOiSIQF23XnhLDeOglCwk4neK5UJrVkBWzcEmS7H76PugMP9fjssQW6CMYtS4RPWBwiiL1kDcIn9Sk2zDstJMXaZvV4r/hHjn+Xj8O86ZwWGE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571112586552.3467256991862; Fri, 25 Apr 2025 01:51:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eis-0002sv-LF; Fri, 25 Apr 2025 04:47:50 -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 1u8Eip-0002rU-IX for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Eil-0003EL-6K for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:46 -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-441-UJ2lJQuFPaCkK0J4QNFL5g-1; Fri, 25 Apr 2025 04:47:35 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 180431956087; Fri, 25 Apr 2025 08:47:34 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3A0E930001A2; Fri, 25 Apr 2025 08:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570860; 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=ku80WnsyoY1yoKJVZbi1RE32bDtPSkPy28YgWR2YXGE=; b=MwITkoqgmQDd99EnPId/mCR2ctfhvAOmb4jYnVXeHERYCjEdx0Q4meRtYPfYvJgC4Rw0ET F9jbJmIgHkDdLnsK1bjRfpRwwCjYO40aSo0quH9fM9BPWkZ/G/w6xOtDm2DQnAZYf6y0gQ vMwy4aERtKJBbcFU1I7WiY5XxEgmxic= X-MC-Unique: UJ2lJQuFPaCkK0J4QNFL5g-1 X-Mimecast-MFC-AGG-ID: UJ2lJQuFPaCkK0J4QNFL5g_1745570854 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 12/50] vfio: Introduce a new header file for VFIOdisplay declarations Date: Fri, 25 Apr 2025 10:46:05 +0200 Message-ID: <20250425084644.102196-13-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571114498019000 Gather all VFIOdisplay related declarations into "vfio-display.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-8-clg@redhat= .com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-9-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 1 + hw/vfio/vfio-display.h | 41 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 28 ------------------------ hw/vfio/display.c | 2 +- 4 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 hw/vfio/vfio-display.h diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 6c59300248f279f56cff46874085992eeb3f82f9..62fd5f49978845ba24613ada972= e625e629c5080 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -20,6 +20,7 @@ #include "qemu/timer.h" #include "qom/object.h" #include "system/kvm.h" +#include "vfio-display.h" =20 #define PCI_ANY_ID (~0) =20 diff --git a/hw/vfio/vfio-display.h b/hw/vfio/vfio-display.h new file mode 100644 index 0000000000000000000000000000000000000000..99b8cb67ef7558d3eefe3105a83= 1e3fcb30afc4d --- /dev/null +++ b/hw/vfio/vfio-display.h @@ -0,0 +1,41 @@ +/* + * VFIO display + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_VFIO_DISPLAY_H +#define HW_VFIO_VFIO_DISPLAY_H + +#include "ui/console.h" +#include "hw/display/ramfb.h" + +typedef struct VFIODMABuf { + QemuDmaBuf *buf; + uint32_t pos_x, pos_y, pos_updates; + uint32_t hot_x, hot_y, hot_updates; + int dmabuf_id; + QTAILQ_ENTRY(VFIODMABuf) next; +} VFIODMABuf; + +typedef struct VFIODisplay { + QemuConsole *con; + RAMFBState *ramfb; + struct vfio_region_info *edid_info; + struct vfio_region_gfx_edid *edid_regs; + uint8_t *edid_blob; + QEMUTimer *edid_link_timer; + struct { + VFIORegion buffer; + DisplaySurface *surface; + } region; + struct { + QTAILQ_HEAD(, VFIODMABuf) bufs; + VFIODMABuf *primary; + VFIODMABuf *cursor; + } dmabuf; +} VFIODisplay; + +#endif /* HW_VFIO_VFIO_DISPLAY_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index fa0b74d5eac53cc49e9da97007cc36ca7b8d8611..528eafadf9f2886d567584c45cc= 3fc749ef8ddd7 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -23,8 +23,6 @@ =20 #include "system/memory.h" #include "qemu/queue.h" -#include "ui/console.h" -#include "hw/display/ramfb.h" #ifdef CONFIG_LINUX #include #endif @@ -182,32 +180,6 @@ typedef struct VFIOGroup { #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" =20 -typedef struct VFIODMABuf { - QemuDmaBuf *buf; - uint32_t pos_x, pos_y, pos_updates; - uint32_t hot_x, hot_y, hot_updates; - int dmabuf_id; - QTAILQ_ENTRY(VFIODMABuf) next; -} VFIODMABuf; - -typedef struct VFIODisplay { - QemuConsole *con; - RAMFBState *ramfb; - struct vfio_region_info *edid_info; - struct vfio_region_gfx_edid *edid_regs; - uint8_t *edid_blob; - QEMUTimer *edid_link_timer; - struct { - VFIORegion buffer; - DisplaySurface *surface; - } region; - struct { - QTAILQ_HEAD(, VFIODMABuf) bufs; - VFIODMABuf *primary; - VFIODMABuf *cursor; - } dmabuf; -} VFIODisplay; - VFIOAddressSpace *vfio_get_address_space(AddressSpace *as); void vfio_put_address_space(VFIOAddressSpace *space); void vfio_address_space_insert(VFIOAddressSpace *space, diff --git a/hw/vfio/display.c b/hw/vfio/display.c index 4fdcef505da59477e52df14ff9e611797bac162c..70cfd685bd049aadf97b73d0608= 6a0e44eb3f9cb 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -16,9 +16,9 @@ =20 #include "qemu/error-report.h" #include "hw/display/edid.h" -#include "ui/console.h" #include "qapi/error.h" #include "pci.h" +#include "vfio-display.h" #include "trace.h" =20 #ifndef DRM_PLANE_TYPE_PRIMARY --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571027; cv=none; d=zohomail.com; s=zohoarc; b=T9amjPrUvgCZ+tfXUgVDyphPncNz0fvd17nv+4Xwmsx/3JRS5ArJrPUWh5zTDgJxs/ioalsppg+VmSymnJcWlLRJGPHjLxmPQ8khrAZT0+Mio7rE9T+OPODerH5p0ZLWV4ryhj39WamKQImhHfUm7g6HHEicJ5WSz+IHr9eluts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571027; 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=8cxLXqQWGxONyUm7QCDXODzWCXomUnP/zkxG1RLXQw0=; b=LiUrmsVEiioKIISc38WpBcMqj0bNoHcYZpWbE6oAoTaV7gReAXNvuU0fU8UspJDP1ON0gmLE9CtKisz6LbTeRnvTgFMRH3kzMOYmqLL0e8+81HGNqZFWSEyhMx0UzvCR6ooQD5SVwTRBsR1GIfGswcFpmv2wA4R1+6F+hQGIy9Q= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174557102762275.40164814499758; Fri, 25 Apr 2025 01:50:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eir-0002sW-JF; Fri, 25 Apr 2025 04:47: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 1u8Eip-0002rV-I6 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Eim-0003EQ-Fe for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:46 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-491-Z8SBxffyOLKKa2Zsql1lAQ-1; Fri, 25 Apr 2025 04:47:37 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85D1F1800877; Fri, 25 Apr 2025 08:47:36 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 93BAE30001A2; Fri, 25 Apr 2025 08:47:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570861; 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=8cxLXqQWGxONyUm7QCDXODzWCXomUnP/zkxG1RLXQw0=; b=drNVJDjGa/L5btoe9ftvVymWvDRtCc8RxIybVoZGIywd/6Cj8fXRnqZrIgZelsdsJ8mOmg mIlVV2rKWHAGPASJIO6s5irBOvnIYrWA/2bj8XIqAy6s1+Y1Xtbk5TEbTNigi+nc/KbfG3 CFG4qwrUXuvgf2ZbugxolCllVLegcbQ= X-MC-Unique: Z8SBxffyOLKKa2Zsql1lAQ-1 X-Mimecast-MFC-AGG-ID: Z8SBxffyOLKKa2Zsql1lAQ_1745570856 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 13/50] vfio: Move VFIOHostDMAWindow definition into spapr.c Date: Fri, 25 Apr 2025 10:46:06 +0200 Message-ID: <20250425084644.102196-14-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571028191019000 VFIOHostDMAWindow is only used in file "spapr.c". Move it there. Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-9-clg@redhat= .com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-10-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 7 ------- hw/vfio/spapr.c | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 528eafadf9f2886d567584c45cc3fc749ef8ddd7..83b1f7be805998c00f02d5b264a= 4171b51c1d55c 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -69,13 +69,6 @@ typedef struct VFIOContainer { =20 OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY); =20 -typedef struct VFIOHostDMAWindow { - hwaddr min_iova; - hwaddr max_iova; - uint64_t iova_pgsizes; - QLIST_ENTRY(VFIOHostDMAWindow) hostwin_next; -} VFIOHostDMAWindow; - typedef struct IOMMUFDBackend IOMMUFDBackend; =20 typedef struct VFIOIOASHwpt { diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 7e5cb95f6a48ff87a0fddd62f9c3c297b790049d..f21955a3442b956bdcb2964b004= 2a12e2ac8a03d 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -22,6 +22,13 @@ #include "qapi/error.h" #include "trace.h" =20 +typedef struct VFIOHostDMAWindow { + hwaddr min_iova; + hwaddr max_iova; + uint64_t iova_pgsizes; + QLIST_ENTRY(VFIOHostDMAWindow) hostwin_next; +} VFIOHostDMAWindow; + typedef struct VFIOSpaprContainer { VFIOContainer container; MemoryListener prereg_listener; --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571370; cv=none; d=zohomail.com; s=zohoarc; b=f8jQ55ejzaDQgjMprRc1KDdVEs/BGOil3Fdr63p+UdkeTLNqCf9sLOT9Y05k7bhmWr1EJTpc4zGnf5Af422KgayBwp9ToQBoYxEYIkIgbEmz9sEC58qBIPufnu0N3QOQ4lX1qOAgpjxmWSzL/Ka7k42t7XozRFl3u7VUoprHL6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571370; 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=XZSS12jJn3Ab8jgyon0Rq7AsqZv904HgNZr+YuZoE5Q=; b=Lp0XyBypXhqF0ESwHLp5IHPab0lRKTKSQlBbZxUSzfcccFXgqkDgmP2975oV7nKFtKw4nZ6Voa4SYAqQyHNX39PtskwUyThj2f2g/BsnXs/PLV8qBDS1J4vHVbNaYa05jiixJ13clJBMgjoFTAhrHTGWsTweS091Rap71K8J7Ic= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571370084822.1908656067047; Fri, 25 Apr 2025 01:56:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eit-0002tP-Lv; Fri, 25 Apr 2025 04:47:51 -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 1u8Eiq-0002sG-MZ for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:48 -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 1u8Ein-0003Ea-2y for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:48 -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-344-2g8EwTomMpC3CG5La_52vw-1; Fri, 25 Apr 2025 04:47:41 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 E09F01956095; Fri, 25 Apr 2025 08:47:39 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0CD8A30001AB; Fri, 25 Apr 2025 08:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570862; 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=XZSS12jJn3Ab8jgyon0Rq7AsqZv904HgNZr+YuZoE5Q=; b=S+o26oePHvc9zkO0KXrQHaSeXKzPe7tVTxQJ4xF/VgoEqxrgH69wGG8IeIYSta6rdmcVUF rMMPJwZRpJoy/3E2v+78fB5OTG4KXllb2sn151333sspgqNkYXmTTyUMdI69dNbX7L3Pij F4eLt6N4bXDbDg3g8uzYp78jQPOfn9U= X-MC-Unique: 2g8EwTomMpC3CG5La_52vw-1 X-Mimecast-MFC-AGG-ID: 2g8EwTomMpC3CG5La_52vw_1745570860 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , Yi Liu , John Levon , Zhenzhong Duan Subject: [PULL 14/50] vfio: Introduce a new header file for VFIOIOMMUFD declarations Date: Fri, 25 Apr 2025 10:46:07 +0200 Message-ID: <20250425084644.102196-15-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571371389019000 Gather all VFIOIOMMUFD related declarations introduced by commits 5ee3dc7af785 ("vfio/iommufd: Implement the iommufd backend") and 5b1e96e65403 ("vfio/iommufd: Introduce auto domain creation") into "vfio-iommufd.h". This to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Cc: Joao Martins Cc: Yi Liu Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-10-clg@redha= t.com Reviewed-by: Joao Martins Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-11-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-iommufd.h | 34 ++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 21 +++------------------ hw/vfio/iommufd.c | 1 + 3 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 hw/vfio/vfio-iommufd.h diff --git a/hw/vfio/vfio-iommufd.h b/hw/vfio/vfio-iommufd.h new file mode 100644 index 0000000000000000000000000000000000000000..07ea0f43049645a5f3782048117= fd9bf22083053 --- /dev/null +++ b/hw/vfio/vfio-iommufd.h @@ -0,0 +1,34 @@ +/* + * VFIO iommufd + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_VFIO_IOMMUFD_H +#define HW_VFIO_VFIO_IOMMUFD_H + +#include "hw/vfio/vfio-container-base.h" + +typedef struct VFIODevice VFIODevice; + +typedef struct VFIOIOASHwpt { + uint32_t hwpt_id; + uint32_t hwpt_flags; + QLIST_HEAD(, VFIODevice) device_list; + QLIST_ENTRY(VFIOIOASHwpt) next; +} VFIOIOASHwpt; + +typedef struct IOMMUFDBackend IOMMUFDBackend; + +typedef struct VFIOIOMMUFDContainer { + VFIOContainerBase bcontainer; + IOMMUFDBackend *be; + uint32_t ioas_id; + QLIST_HEAD(, VFIOIOASHwpt) hwpt_list; +} VFIOIOMMUFDContainer; + +OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD); + +#endif /* HW_VFIO_VFIO_IOMMUFD_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 83b1f7be805998c00f02d5b264a4171b51c1d55c..9ec90fbac007f39d222cc42c25c= ca96be4e4421b 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -69,27 +69,12 @@ typedef struct VFIOContainer { =20 OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY); =20 -typedef struct IOMMUFDBackend IOMMUFDBackend; - -typedef struct VFIOIOASHwpt { - uint32_t hwpt_id; - uint32_t hwpt_flags; - 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; - -OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD); - typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIOMigration VFIOMigration; =20 +typedef struct IOMMUFDBackend IOMMUFDBackend; +typedef struct VFIOIOASHwpt VFIOIOASHwpt; + typedef struct VFIODevice { QLIST_ENTRY(VFIODevice) next; QLIST_ENTRY(VFIODevice) container_next; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..7196c4080125674ec58b1ebf02d= ad84b4387c355 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 "vfio-iommufd.h" =20 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr io= va, ram_addr_t size, void *vaddr, bool readonly) --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571169; cv=none; d=zohomail.com; s=zohoarc; b=E2G7b/TglVYde5kIIDwttKdizvob/TLfDZJ/1xPHrIuUopbZ+oR8jzDK43L/8eRng2p1arkkUCD3VqxQJMEy0pecenUiuYNWrZMuGuLgeBefmLck/TVc9NOzi4fL34q10b3Ijwbz1tmFjXVzRVjDLST/IzArA/gGuBYWRUE2sBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571169; 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=xWgRWlLQMC2r71ndq/oCQcCpGwUhQV+NcXbs5vRXN/8=; b=JS5XIQlskPzCwWIyutYIZEyV0Iz4KQyOiHH8KdS260YC2oNpU33mfRjsoxXpTqTYnPww1qjQj05DU6/u4ZaWjRPpWt9MOZVHmDjGVQGFsWANWXzFMyPwHcFY/8y9Rv8AhlQwzpY2Gdg0FTAoGp19XyaxIqho1k9naLe/Z1UL+Mk= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174557116968422.989303019314093; Fri, 25 Apr 2025 01:52:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eiw-0002uL-DT; Fri, 25 Apr 2025 04:47:54 -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 1u8Eiu-0002u2-O1 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Eiq-0003F1-Uk for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:52 -0400 Received: from mx-prod-mc-04.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-575-4UJxiGsVNvC21VSN_HbiJA-1; Fri, 25 Apr 2025 04:47:44 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9C2D71955DCC; Fri, 25 Apr 2025 08:47:43 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6B01030001A2; Fri, 25 Apr 2025 08:47:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570867; 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=xWgRWlLQMC2r71ndq/oCQcCpGwUhQV+NcXbs5vRXN/8=; b=DebfhpeNum/NEw7UapIoaMrVaZtzmIkTi+SuzUI8l1LlzArfGOE++giro0mJpmRqYdeUcE NhSp87wpS1YhenSJJeBKHXVmRRmGdHcODsTkP0v8yhmaNPuD47AXm63ol/MOBHPS/csvl6 AKLVj0CtNjrvrEOqe9xwUGArixFLytw= X-MC-Unique: 4UJxiGsVNvC21VSN_HbiJA-1 X-Mimecast-MFC-AGG-ID: 4UJxiGsVNvC21VSN_HbiJA_1745570863 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Eric Auger , Zhenzhong Duan Subject: [PULL 15/50] vfio: Introduce new files for VFIORegion definitions and declarations Date: Fri, 25 Apr 2025 10:46:08 +0200 Message-ID: <20250425084644.102196-16-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571171569019100 Gather all VFIORegion related declarations and definitions into their own files to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". They were introduced for 'vfio-platform' support in commits db0da029a185 ("vfio: Generalize region support") and a664477db8da ("hw/vfio/pci: Introduce VFIORegion"). To be noted that the 'vfio-platform' devices have been deprecated and will be removed in QEMU 10.2. Until then, make the declarations available externally for 'sysbus-fdt.c'. Cc: Eric Auger Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-12-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 1 + hw/vfio/vfio-display.h | 1 + include/hw/vfio/vfio-common.h | 32 +-- include/hw/vfio/vfio-platform.h | 2 + include/hw/vfio/vfio-region.h | 47 ++++ hw/core/sysbus-fdt.c | 1 + hw/vfio/helpers.c | 363 ----------------------------- hw/vfio/platform.c | 1 + hw/vfio/region.c | 394 ++++++++++++++++++++++++++++++++ hw/vfio/meson.build | 1 + hw/vfio/trace-events | 16 +- 11 files changed, 458 insertions(+), 401 deletions(-) create mode 100644 include/hw/vfio/vfio-region.h create mode 100644 hw/vfio/region.c diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 62fd5f49978845ba24613ada972e625e629c5080..801ea445b8c9f7b11fb209146aa= 54349fe29ccf4 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -15,6 +15,7 @@ #include "system/memory.h" #include "hw/pci/pci_device.h" #include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-region.h" #include "qemu/event_notifier.h" #include "qemu/queue.h" #include "qemu/timer.h" diff --git a/hw/vfio/vfio-display.h b/hw/vfio/vfio-display.h index 99b8cb67ef7558d3eefe3105a831e3fcb30afc4d..2606c34b396a88cec3e8f884adb= 158e48e8105f1 100644 --- a/hw/vfio/vfio-display.h +++ b/hw/vfio/vfio-display.h @@ -11,6 +11,7 @@ =20 #include "ui/console.h" #include "hw/display/ramfb.h" +#include "hw/vfio/vfio-region.h" =20 typedef struct VFIODMABuf { QemuDmaBuf *buf; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 9ec90fbac007f39d222cc42c25cca96be4e4421b..b37203374178045f2b534bf6d89= 90f9dbea1fca7 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -39,25 +39,6 @@ enum { VFIO_DEVICE_TYPE_CCW =3D 2, VFIO_DEVICE_TYPE_AP =3D 3, }; - -typedef struct VFIOMmap { - MemoryRegion mem; - void *mmap; - off_t offset; - size_t size; -} VFIOMmap; - -typedef struct VFIORegion { - struct VFIODevice *vbasedev; - off_t fd_offset; /* offset of region within device fd */ - MemoryRegion *mem; /* slow, read/write access */ - size_t size; - uint32_t flags; /* VFIO region flags (rd/wr/mmap) */ - uint32_t nr_mmaps; - VFIOMmap *mmaps; - uint8_t nr; /* cache the region number for debug */ -} VFIORegion; - struct VFIOGroup; =20 typedef struct VFIOContainer { @@ -168,17 +149,7 @@ void vfio_unmask_single_irqindex(VFIODevice *vbasedev,= int index); void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index); bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, int action, int fd, Error **errp); -void vfio_region_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size); -uint64_t vfio_region_read(void *opaque, - hwaddr addr, unsigned size); -int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, - int index, const char *name); -int vfio_region_mmap(VFIORegion *region); -void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled); -void vfio_region_unmap(VFIORegion *region); -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); @@ -194,7 +165,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp); bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); =20 -extern const MemoryRegionOps vfio_region_ops; typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList; typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; extern VFIOGroupList vfio_group_list; diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platfor= m.h index c414c3dffcc840a2f40a1b252d0f7b4e309c78d4..3191545717da51abc41d10cd364= 6cd047b4a676c 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -47,6 +47,8 @@ typedef struct VFIOINTp { /* function type for user side eventfd handler */ typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp); =20 +typedef struct VFIORegion VFIORegion; + struct VFIOPlatformDevice { SysBusDevice sbdev; VFIODevice vbasedev; /* not a QOM object */ diff --git a/include/hw/vfio/vfio-region.h b/include/hw/vfio/vfio-region.h new file mode 100644 index 0000000000000000000000000000000000000000..cbffb269628cc89fbbdb060ce3c= e6e45bd701bad --- /dev/null +++ b/include/hw/vfio/vfio-region.h @@ -0,0 +1,47 @@ +/* + * VFIO region + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_REGION_H +#define HW_VFIO_REGION_H + +#include "system/memory.h" + +typedef struct VFIOMmap { + MemoryRegion mem; + void *mmap; + off_t offset; + size_t size; +} VFIOMmap; + +typedef struct VFIODevice VFIODevice; + +typedef struct VFIORegion { + struct VFIODevice *vbasedev; + off_t fd_offset; /* offset of region within device fd */ + MemoryRegion *mem; /* slow, read/write access */ + size_t size; + uint32_t flags; /* VFIO region flags (rd/wr/mmap) */ + uint32_t nr_mmaps; + VFIOMmap *mmaps; + uint8_t nr; /* cache the region number for debug */ +} VFIORegion; + + +void vfio_region_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size); +uint64_t vfio_region_read(void *opaque, + hwaddr addr, unsigned size); +int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, + int index, const char *name); +int vfio_region_mmap(VFIORegion *region); +void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled); +void vfio_region_unmap(VFIORegion *region); +void vfio_region_exit(VFIORegion *region); +void vfio_region_finalize(VFIORegion *region); + +#endif /* HW_VFIO_REGION_H */ diff --git a/hw/core/sysbus-fdt.c b/hw/core/sysbus-fdt.c index e85066b905637b1ca34b5965f383df341f3a4eb7..c339a27875cbee8131b064674aa= 09adf4b9efa25 100644 --- a/hw/core/sysbus-fdt.c +++ b/hw/core/sysbus-fdt.c @@ -35,6 +35,7 @@ #include "hw/vfio/vfio-platform.h" #include "hw/vfio/vfio-calxeda-xgmac.h" #include "hw/vfio/vfio-amd-xgbe.h" +#include "hw/vfio/vfio-region.h" #include "hw/display/ramfb.h" #include "hw/uefi/var-service-api.h" #include "hw/arm/fdt.h" diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 4b255d4f3a9e81f55df00c68fc71da769fd5bd04..89403943a7a219e491b6812d50b= 27b7f1fd7b4a4 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -147,118 +147,6 @@ bool vfio_set_irq_signaling(VFIODevice *vbasedev, int= index, int subindex, return false; } =20 -/* - * IO Port/MMIO - Beware of the endians, VFIO is always little endian - */ -void vfio_region_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) -{ - VFIORegion *region =3D opaque; - VFIODevice *vbasedev =3D region->vbasedev; - union { - uint8_t byte; - uint16_t word; - uint32_t dword; - uint64_t qword; - } buf; - - switch (size) { - case 1: - buf.byte =3D data; - break; - case 2: - buf.word =3D cpu_to_le16(data); - break; - case 4: - buf.dword =3D cpu_to_le32(data); - break; - case 8: - buf.qword =3D cpu_to_le64(data); - break; - default: - hw_error("vfio: unsupported write size, %u bytes", size); - break; - } - - if (pwrite(vbasedev->fd, &buf, size, region->fd_offset + addr) !=3D si= ze) { - error_report("%s(%s:region%d+0x%"HWADDR_PRIx", 0x%"PRIx64 - ",%d) failed: %m", - __func__, vbasedev->name, region->nr, - addr, data, size); - } - - trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size); - - /* - * A read or write to a BAR always signals an INTx EOI. This will - * do nothing if not pending (including not in INTx mode). We assume - * that a BAR access is in response to an interrupt and that BAR - * accesses will service the interrupt. Unfortunately, we don't know - * which access will service the interrupt, so we're potentially - * getting quite a few host interrupts per guest interrupt. - */ - vbasedev->ops->vfio_eoi(vbasedev); -} - -uint64_t vfio_region_read(void *opaque, - hwaddr addr, unsigned size) -{ - VFIORegion *region =3D opaque; - VFIODevice *vbasedev =3D region->vbasedev; - union { - uint8_t byte; - uint16_t word; - uint32_t dword; - uint64_t qword; - } buf; - uint64_t data =3D 0; - - if (pread(vbasedev->fd, &buf, size, region->fd_offset + addr) !=3D siz= e) { - error_report("%s(%s:region%d+0x%"HWADDR_PRIx", %d) failed: %m", - __func__, vbasedev->name, region->nr, - addr, size); - return (uint64_t)-1; - } - switch (size) { - case 1: - data =3D buf.byte; - break; - case 2: - data =3D le16_to_cpu(buf.word); - break; - case 4: - data =3D le32_to_cpu(buf.dword); - break; - case 8: - data =3D le64_to_cpu(buf.qword); - break; - default: - hw_error("vfio: unsupported read size, %u bytes", size); - break; - } - - trace_vfio_region_read(vbasedev->name, region->nr, addr, size, data); - - /* Same as write above */ - vbasedev->ops->vfio_eoi(vbasedev); - - return data; -} - -const MemoryRegionOps vfio_region_ops =3D { - .read =3D vfio_region_read, - .write =3D vfio_region_write, - .endianness =3D DEVICE_LITTLE_ENDIAN, - .valid =3D { - .min_access_size =3D 1, - .max_access_size =3D 8, - }, - .impl =3D { - .min_access_size =3D 1, - .max_access_size =3D 8, - }, -}; - int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size) { vbmap->pages =3D REAL_HOST_PAGE_ALIGN(size) / qemu_real_host_page_size= (); @@ -306,257 +194,6 @@ vfio_get_device_info_cap(struct vfio_device_info *inf= o, uint16_t id) return vfio_get_cap((void *)info, info->cap_offset, id); } =20 -static int vfio_setup_region_sparse_mmaps(VFIORegion *region, - struct vfio_region_info *info) -{ - struct vfio_info_cap_header *hdr; - struct vfio_region_info_cap_sparse_mmap *sparse; - int i, j; - - hdr =3D vfio_get_region_info_cap(info, VFIO_REGION_INFO_CAP_SPARSE_MMA= P); - if (!hdr) { - return -ENODEV; - } - - sparse =3D container_of(hdr, struct vfio_region_info_cap_sparse_mmap, = header); - - trace_vfio_region_sparse_mmap_header(region->vbasedev->name, - region->nr, sparse->nr_areas); - - region->mmaps =3D g_new0(VFIOMmap, sparse->nr_areas); - - for (i =3D 0, j =3D 0; i < sparse->nr_areas; i++) { - if (sparse->areas[i].size) { - trace_vfio_region_sparse_mmap_entry(i, sparse->areas[i].offset, - sparse->areas[i].offset + - sparse->areas[i].size - 1); - region->mmaps[j].offset =3D sparse->areas[i].offset; - region->mmaps[j].size =3D sparse->areas[i].size; - j++; - } - } - - region->nr_mmaps =3D j; - region->mmaps =3D g_realloc(region->mmaps, j * sizeof(VFIOMmap)); - - return 0; -} - -int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, - int index, const char *name) -{ - g_autofree struct vfio_region_info *info =3D NULL; - int ret; - - ret =3D vfio_get_region_info(vbasedev, index, &info); - if (ret) { - return ret; - } - - region->vbasedev =3D vbasedev; - region->flags =3D info->flags; - region->size =3D info->size; - region->fd_offset =3D info->offset; - region->nr =3D index; - - if (region->size) { - region->mem =3D g_new0(MemoryRegion, 1); - memory_region_init_io(region->mem, obj, &vfio_region_ops, - region, name, region->size); - - if (!vbasedev->no_mmap && - region->flags & VFIO_REGION_INFO_FLAG_MMAP) { - - ret =3D vfio_setup_region_sparse_mmaps(region, info); - - if (ret) { - region->nr_mmaps =3D 1; - region->mmaps =3D g_new0(VFIOMmap, region->nr_mmaps); - region->mmaps[0].offset =3D 0; - region->mmaps[0].size =3D region->size; - } - } - } - - trace_vfio_region_setup(vbasedev->name, index, name, - region->flags, region->fd_offset, region->size= ); - return 0; -} - -static void vfio_subregion_unmap(VFIORegion *region, int index) -{ - trace_vfio_region_unmap(memory_region_name(®ion->mmaps[index].mem), - region->mmaps[index].offset, - region->mmaps[index].offset + - region->mmaps[index].size - 1); - memory_region_del_subregion(region->mem, ®ion->mmaps[index].mem); - munmap(region->mmaps[index].mmap, region->mmaps[index].size); - object_unparent(OBJECT(®ion->mmaps[index].mem)); - region->mmaps[index].mmap =3D NULL; -} - -int vfio_region_mmap(VFIORegion *region) -{ - int i, ret, prot =3D 0; - char *name; - - if (!region->mem) { - return 0; - } - - prot |=3D region->flags & VFIO_REGION_INFO_FLAG_READ ? PROT_READ : 0; - prot |=3D region->flags & VFIO_REGION_INFO_FLAG_WRITE ? PROT_WRITE : 0; - - for (i =3D 0; i < region->nr_mmaps; i++) { - size_t align =3D MIN(1ULL << ctz64(region->mmaps[i].size), 1 * GiB= ); - void *map_base, *map_align; - - /* - * Align the mmap for more efficient mapping in the kernel. Ideal= ly - * we'd know the PMD and PUD mapping sizes to use as discrete alig= nment - * intervals, but we don't. As of Linux v6.12, the largest PUD si= ze - * supporting huge pfnmap is 1GiB (ARCH_SUPPORTS_PUD_PFNMAP is onl= y set - * on x86_64). Align by power-of-two size, capped at 1GiB. - * - * NB. qemu_memalign() and friends actually allocate memory, where= as - * the region size here can exceed host memory, therefore we manua= lly - * create an oversized anonymous mapping and clean it up for align= ment. - */ - map_base =3D mmap(0, region->mmaps[i].size + align, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (map_base =3D=3D MAP_FAILED) { - ret =3D -errno; - goto no_mmap; - } - - map_align =3D (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)ali= gn); - munmap(map_base, map_align - map_base); - munmap(map_align + region->mmaps[i].size, - align - (map_align - map_base)); - - region->mmaps[i].mmap =3D mmap(map_align, region->mmaps[i].size, p= rot, - MAP_SHARED | MAP_FIXED, - region->vbasedev->fd, - region->fd_offset + - region->mmaps[i].offset); - if (region->mmaps[i].mmap =3D=3D MAP_FAILED) { - ret =3D -errno; - goto no_mmap; - } - - name =3D g_strdup_printf("%s mmaps[%d]", - memory_region_name(region->mem), i); - memory_region_init_ram_device_ptr(®ion->mmaps[i].mem, - memory_region_owner(region->mem), - name, region->mmaps[i].size, - region->mmaps[i].mmap); - g_free(name); - memory_region_add_subregion(region->mem, region->mmaps[i].offset, - ®ion->mmaps[i].mem); - - trace_vfio_region_mmap(memory_region_name(®ion->mmaps[i].mem), - region->mmaps[i].offset, - region->mmaps[i].offset + - region->mmaps[i].size - 1); - } - - return 0; - -no_mmap: - trace_vfio_region_mmap_fault(memory_region_name(region->mem), i, - region->fd_offset + region->mmaps[i].offs= et, - region->fd_offset + region->mmaps[i].offs= et + - region->mmaps[i].size - 1, ret); - - region->mmaps[i].mmap =3D NULL; - - for (i--; i >=3D 0; i--) { - vfio_subregion_unmap(region, i); - } - - return ret; -} - -void vfio_region_unmap(VFIORegion *region) -{ - int i; - - if (!region->mem) { - return; - } - - for (i =3D 0; i < region->nr_mmaps; i++) { - if (region->mmaps[i].mmap) { - vfio_subregion_unmap(region, i); - } - } -} - -void vfio_region_exit(VFIORegion *region) -{ - int i; - - if (!region->mem) { - return; - } - - for (i =3D 0; i < region->nr_mmaps; i++) { - if (region->mmaps[i].mmap) { - memory_region_del_subregion(region->mem, ®ion->mmaps[i].mem= ); - } - } - - trace_vfio_region_exit(region->vbasedev->name, region->nr); -} - -void vfio_region_finalize(VFIORegion *region) -{ - int i; - - if (!region->mem) { - return; - } - - for (i =3D 0; i < region->nr_mmaps; i++) { - if (region->mmaps[i].mmap) { - munmap(region->mmaps[i].mmap, region->mmaps[i].size); - object_unparent(OBJECT(®ion->mmaps[i].mem)); - } - } - - object_unparent(OBJECT(region->mem)); - - g_free(region->mem); - g_free(region->mmaps); - - trace_vfio_region_finalize(region->vbasedev->name, region->nr); - - region->mem =3D NULL; - region->mmaps =3D NULL; - region->nr_mmaps =3D 0; - region->size =3D 0; - region->flags =3D 0; - region->nr =3D 0; -} - -void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled) -{ - int i; - - if (!region->mem) { - return; - } - - for (i =3D 0; i < region->nr_mmaps; i++) { - if (region->mmaps[i].mmap) { - memory_region_set_enabled(®ion->mmaps[i].mem, enabled); - } - } - - trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), - enabled); -} - int vfio_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info) { diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index f273ae9a51a179b8d8851ec2170f441a21a427fc..ca6528cc568db4f4666fea70896= a39b650642679 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -37,6 +37,7 @@ #include "hw/platform-bus.h" #include "hw/qdev-properties.h" #include "system/kvm.h" +#include "hw/vfio/vfio-region.h" =20 /* * Functions used whatever the injection method diff --git a/hw/vfio/region.c b/hw/vfio/region.c new file mode 100644 index 0000000000000000000000000000000000000000..08cd69e7047ab950151832864a1= 4af7af774ff3b --- /dev/null +++ b/hw/vfio/region.c @@ -0,0 +1,394 @@ +/* + * VFIO regions + * + * Copyright Red Hat, Inc. 2012 + * + * Authors: + * Alex Williamson + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Based on qemu-kvm device-assignment: + * Adapted for KVM by Qumranet. + * Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com) + * Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com) + * Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com) + * Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com) + * Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com) + */ + +#include "qemu/osdep.h" +#include + +#include "hw/vfio/vfio-common.h" +#include "hw/vfio/pci.h" +#include "hw/hw.h" +#include "trace.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/units.h" +#include "monitor/monitor.h" + +/* + * IO Port/MMIO - Beware of the endians, VFIO is always little endian + */ +void vfio_region_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + VFIORegion *region =3D opaque; + VFIODevice *vbasedev =3D region->vbasedev; + union { + uint8_t byte; + uint16_t word; + uint32_t dword; + uint64_t qword; + } buf; + + switch (size) { + case 1: + buf.byte =3D data; + break; + case 2: + buf.word =3D cpu_to_le16(data); + break; + case 4: + buf.dword =3D cpu_to_le32(data); + break; + case 8: + buf.qword =3D cpu_to_le64(data); + break; + default: + hw_error("vfio: unsupported write size, %u bytes", size); + break; + } + + if (pwrite(vbasedev->fd, &buf, size, region->fd_offset + addr) !=3D si= ze) { + error_report("%s(%s:region%d+0x%"HWADDR_PRIx", 0x%"PRIx64 + ",%d) failed: %m", + __func__, vbasedev->name, region->nr, + addr, data, size); + } + + trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size); + + /* + * A read or write to a BAR always signals an INTx EOI. This will + * do nothing if not pending (including not in INTx mode). We assume + * that a BAR access is in response to an interrupt and that BAR + * accesses will service the interrupt. Unfortunately, we don't know + * which access will service the interrupt, so we're potentially + * getting quite a few host interrupts per guest interrupt. + */ + vbasedev->ops->vfio_eoi(vbasedev); +} + +uint64_t vfio_region_read(void *opaque, + hwaddr addr, unsigned size) +{ + VFIORegion *region =3D opaque; + VFIODevice *vbasedev =3D region->vbasedev; + union { + uint8_t byte; + uint16_t word; + uint32_t dword; + uint64_t qword; + } buf; + uint64_t data =3D 0; + + if (pread(vbasedev->fd, &buf, size, region->fd_offset + addr) !=3D siz= e) { + error_report("%s(%s:region%d+0x%"HWADDR_PRIx", %d) failed: %m", + __func__, vbasedev->name, region->nr, + addr, size); + return (uint64_t)-1; + } + switch (size) { + case 1: + data =3D buf.byte; + break; + case 2: + data =3D le16_to_cpu(buf.word); + break; + case 4: + data =3D le32_to_cpu(buf.dword); + break; + case 8: + data =3D le64_to_cpu(buf.qword); + break; + default: + hw_error("vfio: unsupported read size, %u bytes", size); + break; + } + + trace_vfio_region_read(vbasedev->name, region->nr, addr, size, data); + + /* Same as write above */ + vbasedev->ops->vfio_eoi(vbasedev); + + return data; +} + +static const MemoryRegionOps vfio_region_ops =3D { + .read =3D vfio_region_read, + .write =3D vfio_region_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, +}; + +static int vfio_setup_region_sparse_mmaps(VFIORegion *region, + struct vfio_region_info *info) +{ + struct vfio_info_cap_header *hdr; + struct vfio_region_info_cap_sparse_mmap *sparse; + int i, j; + + hdr =3D vfio_get_region_info_cap(info, VFIO_REGION_INFO_CAP_SPARSE_MMA= P); + if (!hdr) { + return -ENODEV; + } + + sparse =3D container_of(hdr, struct vfio_region_info_cap_sparse_mmap, = header); + + trace_vfio_region_sparse_mmap_header(region->vbasedev->name, + region->nr, sparse->nr_areas); + + region->mmaps =3D g_new0(VFIOMmap, sparse->nr_areas); + + for (i =3D 0, j =3D 0; i < sparse->nr_areas; i++) { + if (sparse->areas[i].size) { + trace_vfio_region_sparse_mmap_entry(i, sparse->areas[i].offset, + sparse->areas[i].offset + + sparse->areas[i].size - 1); + region->mmaps[j].offset =3D sparse->areas[i].offset; + region->mmaps[j].size =3D sparse->areas[i].size; + j++; + } + } + + region->nr_mmaps =3D j; + region->mmaps =3D g_realloc(region->mmaps, j * sizeof(VFIOMmap)); + + return 0; +} + +int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, + int index, const char *name) +{ + g_autofree struct vfio_region_info *info =3D NULL; + int ret; + + ret =3D vfio_get_region_info(vbasedev, index, &info); + if (ret) { + return ret; + } + + region->vbasedev =3D vbasedev; + region->flags =3D info->flags; + region->size =3D info->size; + region->fd_offset =3D info->offset; + region->nr =3D index; + + if (region->size) { + region->mem =3D g_new0(MemoryRegion, 1); + memory_region_init_io(region->mem, obj, &vfio_region_ops, + region, name, region->size); + + if (!vbasedev->no_mmap && + region->flags & VFIO_REGION_INFO_FLAG_MMAP) { + + ret =3D vfio_setup_region_sparse_mmaps(region, info); + + if (ret) { + region->nr_mmaps =3D 1; + region->mmaps =3D g_new0(VFIOMmap, region->nr_mmaps); + region->mmaps[0].offset =3D 0; + region->mmaps[0].size =3D region->size; + } + } + } + + trace_vfio_region_setup(vbasedev->name, index, name, + region->flags, region->fd_offset, region->size= ); + return 0; +} + +static void vfio_subregion_unmap(VFIORegion *region, int index) +{ + trace_vfio_region_unmap(memory_region_name(®ion->mmaps[index].mem), + region->mmaps[index].offset, + region->mmaps[index].offset + + region->mmaps[index].size - 1); + memory_region_del_subregion(region->mem, ®ion->mmaps[index].mem); + munmap(region->mmaps[index].mmap, region->mmaps[index].size); + object_unparent(OBJECT(®ion->mmaps[index].mem)); + region->mmaps[index].mmap =3D NULL; +} + +int vfio_region_mmap(VFIORegion *region) +{ + int i, ret, prot =3D 0; + char *name; + + if (!region->mem) { + return 0; + } + + prot |=3D region->flags & VFIO_REGION_INFO_FLAG_READ ? PROT_READ : 0; + prot |=3D region->flags & VFIO_REGION_INFO_FLAG_WRITE ? PROT_WRITE : 0; + + for (i =3D 0; i < region->nr_mmaps; i++) { + size_t align =3D MIN(1ULL << ctz64(region->mmaps[i].size), 1 * GiB= ); + void *map_base, *map_align; + + /* + * Align the mmap for more efficient mapping in the kernel. Ideal= ly + * we'd know the PMD and PUD mapping sizes to use as discrete alig= nment + * intervals, but we don't. As of Linux v6.12, the largest PUD si= ze + * supporting huge pfnmap is 1GiB (ARCH_SUPPORTS_PUD_PFNMAP is onl= y set + * on x86_64). Align by power-of-two size, capped at 1GiB. + * + * NB. qemu_memalign() and friends actually allocate memory, where= as + * the region size here can exceed host memory, therefore we manua= lly + * create an oversized anonymous mapping and clean it up for align= ment. + */ + map_base =3D mmap(0, region->mmaps[i].size + align, PROT_NONE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (map_base =3D=3D MAP_FAILED) { + ret =3D -errno; + goto no_mmap; + } + + map_align =3D (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)ali= gn); + munmap(map_base, map_align - map_base); + munmap(map_align + region->mmaps[i].size, + align - (map_align - map_base)); + + region->mmaps[i].mmap =3D mmap(map_align, region->mmaps[i].size, p= rot, + MAP_SHARED | MAP_FIXED, + region->vbasedev->fd, + region->fd_offset + + region->mmaps[i].offset); + if (region->mmaps[i].mmap =3D=3D MAP_FAILED) { + ret =3D -errno; + goto no_mmap; + } + + name =3D g_strdup_printf("%s mmaps[%d]", + memory_region_name(region->mem), i); + memory_region_init_ram_device_ptr(®ion->mmaps[i].mem, + memory_region_owner(region->mem), + name, region->mmaps[i].size, + region->mmaps[i].mmap); + g_free(name); + memory_region_add_subregion(region->mem, region->mmaps[i].offset, + ®ion->mmaps[i].mem); + + trace_vfio_region_mmap(memory_region_name(®ion->mmaps[i].mem), + region->mmaps[i].offset, + region->mmaps[i].offset + + region->mmaps[i].size - 1); + } + + return 0; + +no_mmap: + trace_vfio_region_mmap_fault(memory_region_name(region->mem), i, + region->fd_offset + region->mmaps[i].offs= et, + region->fd_offset + region->mmaps[i].offs= et + + region->mmaps[i].size - 1, ret); + + region->mmaps[i].mmap =3D NULL; + + for (i--; i >=3D 0; i--) { + vfio_subregion_unmap(region, i); + } + + return ret; +} + +void vfio_region_unmap(VFIORegion *region) +{ + int i; + + if (!region->mem) { + return; + } + + for (i =3D 0; i < region->nr_mmaps; i++) { + if (region->mmaps[i].mmap) { + vfio_subregion_unmap(region, i); + } + } +} + +void vfio_region_exit(VFIORegion *region) +{ + int i; + + if (!region->mem) { + return; + } + + for (i =3D 0; i < region->nr_mmaps; i++) { + if (region->mmaps[i].mmap) { + memory_region_del_subregion(region->mem, ®ion->mmaps[i].mem= ); + } + } + + trace_vfio_region_exit(region->vbasedev->name, region->nr); +} + +void vfio_region_finalize(VFIORegion *region) +{ + int i; + + if (!region->mem) { + return; + } + + for (i =3D 0; i < region->nr_mmaps; i++) { + if (region->mmaps[i].mmap) { + munmap(region->mmaps[i].mmap, region->mmaps[i].size); + object_unparent(OBJECT(®ion->mmaps[i].mem)); + } + } + + object_unparent(OBJECT(region->mem)); + + g_free(region->mem); + g_free(region->mmaps); + + trace_vfio_region_finalize(region->vbasedev->name, region->nr); + + region->mem =3D NULL; + region->mmaps =3D NULL; + region->nr_mmaps =3D 0; + region->size =3D 0; + region->flags =3D 0; + region->nr =3D 0; +} + +void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled) +{ + int i; + + if (!region->mem) { + return; + } + + for (i =3D 0; i < region->nr_mmaps; i++) { + if (region->mmaps[i].mmap) { + memory_region_set_enabled(®ion->mmaps[i].mem, enabled); + } + } + + trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), + enabled); +} diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index a8939c838657b09c38f93ad69d541df5aea30a6f..07010c7c9e01a39ae3449c54d20= 27a2cdd0a7a4d 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -23,6 +23,7 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files( 'migration.c', 'migration-multifd.c', 'cpr.c', + 'region.c', )) system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files( 'iommufd.c', diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 9347e3a5f6607ec6907f9b426da9ab90553292cf..81f4130100c48012c15b5b48584= 46149a7eaf5b6 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -90,8 +90,6 @@ vfio_pci_igd_host_bridge_enabled(const char *name) "%s" vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s" =20 # common.c -vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" -vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint= 64_t data) " (%s:region%d+0x%"PRIx64", %d) =3D 0x%"PRIx64 vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_e= nd) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64 vfio_listener_region_skip(const char *name, uint64_t start, uint64_t end) = "SKIPPING %s 0x%"PRIx64" - 0x%"PRIx64 vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to = liobn fd %d" @@ -107,6 +105,15 @@ vfio_disconnect_container(int fd) "close container->fd= =3D%d" vfio_put_group(int fd) "close group->fd=3D%d" vfio_get_device(const char * name, unsigned int flags, unsigned int num_re= gions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u" vfio_put_base_device(int fd) "close vdev->fd=3D%d" +vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%08x" +vfio_legacy_dma_unmap_overflow_workaround(void) "" +vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 +vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 +vfio_reset_handler(void) "" + +# region.c +vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" +vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint= 64_t data) " (%s:region%d+0x%"PRIx64", %d) =3D 0x%"PRIx64 vfio_region_setup(const char *dev, int index, const char *name, unsigned l= ong flags, unsigned long offset, unsigned long size) "Device %s, region %d = \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx" vfio_region_mmap_fault(const char *name, int index, unsigned long offset, = unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault= : %d" vfio_region_mmap(const char *name, unsigned long offset, unsigned long end= ) "Region %s [0x%lx - 0x%lx]" @@ -116,11 +123,6 @@ vfio_region_mmaps_set_enabled(const char *name, bool e= nabled) "Region %s mmaps e vfio_region_unmap(const char *name, unsigned long offset, unsigned long en= d) "Region %s unmap [0x%lx - 0x%lx]" vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) = "Device %s region %d: %d sparse mmap entries" vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long en= d) "sparse entry %d [0x%lx - 0x%lx]" -vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%08x" -vfio_legacy_dma_unmap_overflow_workaround(void) "" -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 -vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 -vfio_reset_handler(void) "" =20 # platform.c vfio_platform_realize(char *name, char *compat) "vfio device %s, compat = =3D %s" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571205; cv=none; d=zohomail.com; s=zohoarc; b=gbK41zlZipaDKjq8a7gdw4fjKCjv+wQXFQCL0nf+IWHujaGnOaLwTDVy18igoZxCuH2gjohKZGs5H/DGxYwt+a7IWJU7yVRKQzhnVJdpKRB/FOw+2U/yxIXl8SRJpo9h9Sgt++zJewf68A+Joz5VeAsINj5M2yxPmwfm1SoAZe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571205; 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=CPnHVBcgsWTqT+InYSFw9LQgKVoq4/hzYKs3O4CxH8I=; b=MtXqa7suqcXc45nHAKqRQ8im+5g+mgm9cgMmgQNPxLKd+gnL1V10K09ETGn1OFehaC23SHjZyMEWZwOKRKC5WPbtEvTBCb/R0C+6CxdxldwuGibVbN3tE38u2mchDi8OL2GaNm/12Hpr8QpqsBl1P0N3qfnPnm88JeGJeVanqq0= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571205682482.31976178617526; Fri, 25 Apr 2025 01:53:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eiw-0002uT-Oe; Fri, 25 Apr 2025 04:47:54 -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 1u8Eiv-0002uC-Id for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Eit-0003FH-5Q for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:53 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-Q6kfkM_5P9u4RVOMmh4-vg-1; Fri, 25 Apr 2025 04:47:47 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 08FBF1800264; Fri, 25 Apr 2025 08:47:47 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C2A530001A2; Fri, 25 Apr 2025 08:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570869; 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=CPnHVBcgsWTqT+InYSFw9LQgKVoq4/hzYKs3O4CxH8I=; b=Nf6cJ5F5PMn/hthlEnU2JvFUxlY47k2IgxJ/j2AaUo8OSAFkr8twDN9wwhT+ZhxozhEbt9 tXzrCyIQ3oIjYoTgHnzhu0scLqKUByDCBEsxdeuMBuf4iP322eJNZbL9vgaiFU4m1H1mCZ DHSTTwPw4n/A7QNjB9dfusXb5GshSNY= X-MC-Unique: Q6kfkM_5P9u4RVOMmh4-vg-1 X-Mimecast-MFC-AGG-ID: Q6kfkM_5P9u4RVOMmh4-vg_1745570867 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , John Levon Subject: [PULL 16/50] vfio: Introduce a new header file for VFIOcontainer declarations Date: Fri, 25 Apr 2025 10:46:09 +0200 Message-ID: <20250425084644.102196-17-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571207537019100 Gather all VFIOcontainer related declarations into "hw/vfio/vfio-container.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". These declarations were initially introduced in commit 65501a745dba ("vfio: vfio-pci device assignment driver"). They are made available externally for PPC and s390x. Reviewed-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-12-clg@redha= t.com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-13-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 19 ----------------- include/hw/vfio/vfio-container.h | 36 ++++++++++++++++++++++++++++++++ hw/ppc/spapr_pci_vfio.c | 1 + hw/s390x/s390-pci-vfio.c | 2 +- hw/vfio/container.c | 1 + hw/vfio/spapr.c | 1 + 6 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 include/hw/vfio/vfio-container.h diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b37203374178045f2b534bf6d8990f9dbea1fca7..bcdbc9de57dd11c2c93252b983e= c4e4190a82fe5 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -39,16 +39,6 @@ enum { VFIO_DEVICE_TYPE_CCW =3D 2, VFIO_DEVICE_TYPE_AP =3D 3, }; -struct VFIOGroup; - -typedef struct VFIOContainer { - VFIOContainerBase bcontainer; - int fd; /* /dev/vfio/vfio, empowered by the attached groups */ - unsigned iommu_type; - QLIST_HEAD(, VFIOGroup) group_list; -} VFIOContainer; - -OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY); =20 typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIOMigration VFIOMigration; @@ -125,15 +115,6 @@ struct VFIODeviceOps { int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 -typedef struct VFIOGroup { - int fd; - int groupid; - VFIOContainer *container; - QLIST_HEAD(, VFIODevice) device_list; - QLIST_ENTRY(VFIOGroup) next; - QLIST_ENTRY(VFIOGroup) container_next; - bool ram_block_discard_allowed; -} VFIOGroup; =20 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-contai= ner.h new file mode 100644 index 0000000000000000000000000000000000000000..afc498da49fd4aa7625e47a0749= f2c524049296d --- /dev/null +++ b/include/hw/vfio/vfio-container.h @@ -0,0 +1,36 @@ +/* + * VFIO container + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_CONTAINER_H +#define HW_VFIO_CONTAINER_H + +#include "hw/vfio/vfio-container-base.h" + +typedef struct VFIOContainer VFIOContainer; +typedef struct VFIODevice VFIODevice; + +typedef struct VFIOGroup { + int fd; + int groupid; + VFIOContainer *container; + QLIST_HEAD(, VFIODevice) device_list; + QLIST_ENTRY(VFIOGroup) next; + QLIST_ENTRY(VFIOGroup) container_next; + bool ram_block_discard_allowed; +} VFIOGroup; + +typedef struct VFIOContainer { + VFIOContainerBase bcontainer; + int fd; /* /dev/vfio/vfio, empowered by the attached groups */ + unsigned iommu_type; + QLIST_HEAD(, VFIOGroup) group_list; +} VFIOContainer; + +OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY); + +#endif /* HW_VFIO_CONTAINER_H */ diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c index 76b2a3487b5d6f21528e9c301341eb27bc8fec1d..1722a5bfa3983d42baac558f224= 10e36eed375f5 100644 --- a/hw/ppc/spapr_pci_vfio.c +++ b/hw/ppc/spapr_pci_vfio.c @@ -25,6 +25,7 @@ #include "hw/pci/msix.h" #include "hw/pci/pci_device.h" #include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-container.h" #include "qemu/error-report.h" #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */ =20 diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index db152a625253a0f4047353000ff3bafca1f09938..748a51fd8cc478604340b7c812e= 0da356836b807 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -20,7 +20,7 @@ #include "hw/s390x/s390-pci-clp.h" #include "hw/s390x/s390-pci-vfio.h" #include "hw/vfio/pci.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-container.h" =20 /* * Get the current DMA available count from vfio. Returns true if vfio is diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 812d5edbcf911911fa896ba3603b91a817ffec6b..bda1942662d1da24c3a47db0f4a= 389a2a0fbec7e 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -32,6 +32,7 @@ #include "trace.h" #include "qapi/error.h" #include "pci.h" +#include "hw/vfio/vfio-container.h" =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index f21955a3442b956bdcb2964b0042a12e2ac8a03d..31e4dddc9e2707b18ebaf3e744d= 85009e635f172 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -16,6 +16,7 @@ #include "system/address-spaces.h" =20 #include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-container.h" #include "hw/hw.h" #include "system/ram_addr.h" #include "qemu/error-report.h" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570995; cv=none; d=zohomail.com; s=zohoarc; b=b8IIUdyH4t4iZHKrlJ2e8uMMctkTbeO0Z57XtAFPIGFXVOL5mYeOZIbi19UsU93uUrg8IUDpEiiM39lAnFNL8kYME0mriXA6SBQ9/OCyneVUdF2MS9oCfYJV025G0S9JFRrHHfDqVeGRNVLZIaTJfnxKYcMoDsf/AQHlPjB2QW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570995; 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=N1kju0YE1jFBrB2+SQ2vQoITxBXZYdxdIEJVgGH5MOk=; b=HTCu1+WHuiHc7Xps6ogpyWWfeDTlffJonMRfAkE5p8ArAHupB6Q5MwRUfhCYk9zSpA2X42OdMTpCe3geZLEzD9T7Uq3OWupxeJNUKyZ+ulOiNKxjZwe89VKEMFwM/7GFvEnkBMy69JqmWaZA/EKeyMbvC4XEUMc1WUGGO69VpI0= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570995674523.5579673165441; Fri, 25 Apr 2025 01:49:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EjF-00032K-Uq; Fri, 25 Apr 2025 04:48:14 -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 1u8Ej2-00031D-Ei for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:00 -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 1u8Ej0-0003Fi-8Y for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:47:59 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-_bMWX7s3PLSSIR7JTtShCQ-1; Fri, 25 Apr 2025 04:47:54 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0DB891800873; Fri, 25 Apr 2025 08:47:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BB6D30001A2; Fri, 25 Apr 2025 08:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570877; 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=N1kju0YE1jFBrB2+SQ2vQoITxBXZYdxdIEJVgGH5MOk=; b=fFt0JBzoXJ+Kb4TViwKRY9kltMwH7Xkgpa3SVFF2kp6Ty0bGgsyHtwNuy91pIWxKVgcbOt S8V0CsZCWdIlmnL+Sf1jOePdlLTC4aBNVo20mt9Q0JuCYdxVEcGn0Mh9PT2ZmNs9mwUH35 v2gJXhuWsCDX5aT01PKOCpMMfWl8o6M= X-MC-Unique: _bMWX7s3PLSSIR7JTtShCQ-1 X-Mimecast-MFC-AGG-ID: _bMWX7s3PLSSIR7JTtShCQ_1745570873 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 17/50] vfio: Make vfio_group_list static Date: Fri, 25 Apr 2025 10:46:10 +0200 Message-ID: <20250425084644.102196-18-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570997009019100 vfio_group_list is only used in file "container.c". Reviewed-by: John Levon Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-13-clg@redha= t.com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-14-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 -- hw/vfio/container.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index bcdbc9de57dd11c2c93252b983ec4e4190a82fe5..d8063494757cf61a3019c321f5c= 1174099ccd74f 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -146,9 +146,7 @@ int vfio_kvm_device_del_fd(int fd, Error **errp); bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); =20 -typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList; typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; -extern VFIOGroupList vfio_group_list; extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index bda1942662d1da24c3a47db0f4a389a2a0fbec7e..8a216b24b5dea630f3488ace73e= cf04a7e7cf735 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -34,7 +34,8 @@ #include "pci.h" #include "hw/vfio/vfio-container.h" =20 -VFIOGroupList vfio_group_list =3D +typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList; +static VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); =20 static int vfio_ram_block_discard_disable(VFIOContainer *container, bool s= tate) --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570945; cv=none; d=zohomail.com; s=zohoarc; b=FrZBcBhlG7Hj3zx4wwCpMooBV4z0yjnrXmpuJ9I9sRx7OM3io4nLlG8ej9XQPy2NIWKNV4pZWKSTrpHjZSP36B8YkTXMvz5pcHmY7tiAEDmqkMQzztQktgWnJ5mwoQiDEhC51xbQC5eNMjeYaXbKu1WBVkZfu+n5lIUo0erbkAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570945; 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=DacpOlReGEeq2ISvos3fl4juD/QOyme+IbWkl7yQqLY=; b=mm86DVLuKUda8IL5jNBaSzdR7Lt2950Rhf5jLyBGMpsPoMyA+yL2nWdGV5jFbx9pKufKvH7IDpSWWQooqJM7qOSi8WmxQ7S/LdX8x/QeY+PNVdvy2y5V7qg3tbwH3Ag8//ys7HdlTUAuxzhcEwDe/uedGl53NABLcAqygK0/S6o= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570945422978.1966321485987; Fri, 25 Apr 2025 01:49:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EjS-0003Zt-RY; Fri, 25 Apr 2025 04:48:26 -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 1u8Ej4-00032O-8D for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:06 -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 1u8Ej2-0003Fn-6f for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:01 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648--vx3gb8yNyaR9KPQHVyrjw-1; Fri, 25 Apr 2025 04:47:56 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6E60B180036E; Fri, 25 Apr 2025 08:47:55 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 89F1B30001A2; Fri, 25 Apr 2025 08:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570879; 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=DacpOlReGEeq2ISvos3fl4juD/QOyme+IbWkl7yQqLY=; b=h7ioygcMLs0JFqMzfTqxM004E9Mn0tHrCoFqVsppnDJyh500WqVOqAoTL3lxOe06NSj4QL Iko4qQCqrY650F6tGEne9HXCxzQSdB4V8cdy1+ljI5LHnRaizSgwqAB+/hiw9d7aQrBOfp ybNB+79NSctSkEeP8L78xWKkCPMQ2oo= X-MC-Unique: -vx3gb8yNyaR9KPQHVyrjw-1 X-Mimecast-MFC-AGG-ID: -vx3gb8yNyaR9KPQHVyrjw_1745570875 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 18/50] vfio: Move VFIOAddressSpace helpers into container-base.c Date: Fri, 25 Apr 2025 10:46:11 +0200 Message-ID: <20250425084644.102196-19-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570947067019100 VFIOAddressSpace is a common object used by VFIOContainerBase which is declared in "hw/vfio/vfio-container-base.h". Move the VFIOAddressSpace related services into "container-base.c". While at it, rename : vfio_get_address_space -> vfio_address_space_get vfio_put_address_space -> vfio_address_space_put to better reflect the namespace these routines belong to. Reviewed-by: John Levon Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-15-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 5 --- include/hw/vfio/vfio-container-base.h | 6 ++++ hw/ppc/spapr_pci_vfio.c | 5 ++- hw/vfio/common.c | 47 ------------------------- hw/vfio/container-base.c | 50 +++++++++++++++++++++++++++ hw/vfio/container.c | 6 ++-- hw/vfio/iommufd.c | 6 ++-- 7 files changed, 64 insertions(+), 61 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index d8063494757cf61a3019c321f5c1174099ccd74f..7d78eb85daf09e39a9c48fd879e= c703950a58dd0 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -120,11 +120,6 @@ struct VFIODeviceOps { #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" =20 -VFIOAddressSpace *vfio_get_address_space(AddressSpace *as); -void vfio_put_address_space(VFIOAddressSpace *space); -void vfio_address_space_insert(VFIOAddressSpace *space, - VFIOContainerBase *bcontainer); - void vfio_disable_irqindex(VFIODevice *vbasedev, int index); void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index); void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 6aca02fb3d214abf7ec1ec152b725c8e601455a0..e0c458d487b8b6fc7ec7fb17bae= 84b4a937e6e2c 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -71,6 +71,11 @@ typedef struct VFIORamDiscardListener { QLIST_ENTRY(VFIORamDiscardListener) next; } VFIORamDiscardListener; =20 +VFIOAddressSpace *vfio_address_space_get(AddressSpace *as); +void vfio_address_space_put(VFIOAddressSpace *space); +void vfio_address_space_insert(VFIOAddressSpace *space, + VFIOContainerBase *bcontainer); + int vfio_container_dma_map(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); @@ -163,4 +168,5 @@ struct VFIOIOMMUClass { MemoryRegionSection *section); void (*release)(VFIOContainerBase *bcontainer); }; + #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */ diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c index 1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc219= 5bf68418e5206 100644 --- a/hw/ppc/spapr_pci_vfio.c +++ b/hw/ppc/spapr_pci_vfio.c @@ -24,7 +24,6 @@ #include "hw/pci-host/spapr.h" #include "hw/pci/msix.h" #include "hw/pci/pci_device.h" -#include "hw/vfio/vfio-common.h" #include "hw/vfio/vfio-container.h" #include "qemu/error-report.h" #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */ @@ -86,7 +85,7 @@ static int vfio_eeh_container_op(VFIOContainer *container= , uint32_t op) =20 static VFIOContainer *vfio_eeh_as_container(AddressSpace *as) { - VFIOAddressSpace *space =3D vfio_get_address_space(as); + VFIOAddressSpace *space =3D vfio_address_space_get(as); VFIOContainerBase *bcontainer =3D NULL; =20 if (QLIST_EMPTY(&space->containers)) { @@ -106,7 +105,7 @@ static VFIOContainer *vfio_eeh_as_container(AddressSpac= e *as) } =20 out: - vfio_put_address_space(space); + vfio_address_space_put(space); return container_of(bcontainer, VFIOContainer, bcontainer); } =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8f55e7b212991acb8be63c924327206c8d1727b0..c099d4d24d044263ca3570ec9cf= bd5ca4bcd1e23 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -47,8 +47,6 @@ =20 VFIODeviceList vfio_device_list =3D QLIST_HEAD_INITIALIZER(vfio_device_list); -static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =3D - QLIST_HEAD_INITIALIZER(vfio_address_spaces); =20 #ifdef CONFIG_KVM /* @@ -1392,51 +1390,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp) return 0; } =20 -VFIOAddressSpace *vfio_get_address_space(AddressSpace *as) -{ - VFIOAddressSpace *space; - - QLIST_FOREACH(space, &vfio_address_spaces, list) { - if (space->as =3D=3D as) { - return space; - } - } - - /* No suitable VFIOAddressSpace, create a new one */ - space =3D g_malloc0(sizeof(*space)); - space->as =3D as; - QLIST_INIT(&space->containers); - - if (QLIST_EMPTY(&vfio_address_spaces)) { - qemu_register_reset(vfio_reset_handler, NULL); - } - - QLIST_INSERT_HEAD(&vfio_address_spaces, space, list); - - return space; -} - -void vfio_put_address_space(VFIOAddressSpace *space) -{ - if (!QLIST_EMPTY(&space->containers)) { - return; - } - - QLIST_REMOVE(space, list); - g_free(space); - - if (QLIST_EMPTY(&vfio_address_spaces)) { - qemu_unregister_reset(vfio_reset_handler, NULL); - } -} - -void vfio_address_space_insert(VFIOAddressSpace *space, - VFIOContainerBase *bcontainer) -{ - QLIST_INSERT_HEAD(&space->containers, bcontainer, next); - bcontainer->space =3D space; -} - struct vfio_device_info *vfio_get_device_info(int fd) { struct vfio_device_info *info; diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 749a3fd29dd6fc9143f14edf7e4ac6238315fcce..2c2d8329e3cf0f21386cb0896dd= 366c8d0ccdb60 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -14,6 +14,56 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "hw/vfio/vfio-container-base.h" +#include "hw/vfio/vfio-common.h" /* vfio_reset_handler */ +#include "system/reset.h" + +static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =3D + QLIST_HEAD_INITIALIZER(vfio_address_spaces); + +VFIOAddressSpace *vfio_address_space_get(AddressSpace *as) +{ + VFIOAddressSpace *space; + + QLIST_FOREACH(space, &vfio_address_spaces, list) { + if (space->as =3D=3D as) { + return space; + } + } + + /* No suitable VFIOAddressSpace, create a new one */ + space =3D g_malloc0(sizeof(*space)); + space->as =3D as; + QLIST_INIT(&space->containers); + + if (QLIST_EMPTY(&vfio_address_spaces)) { + qemu_register_reset(vfio_reset_handler, NULL); + } + + QLIST_INSERT_HEAD(&vfio_address_spaces, space, list); + + return space; +} + +void vfio_address_space_put(VFIOAddressSpace *space) +{ + if (!QLIST_EMPTY(&space->containers)) { + return; + } + + QLIST_REMOVE(space, list); + g_free(space); + + if (QLIST_EMPTY(&vfio_address_spaces)) { + qemu_unregister_reset(vfio_reset_handler, NULL); + } +} + +void vfio_address_space_insert(VFIOAddressSpace *space, + VFIOContainerBase *bcontainer) +{ + QLIST_INSERT_HEAD(&space->containers, bcontainer, next); + bcontainer->space =3D space; +} =20 int vfio_container_dma_map(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 8a216b24b5dea630f3488ace73ecf04a7e7cf735..cc8cc0f2726be43dfccaf609ee7= 7aa17a493cd2d 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -546,7 +546,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, VFIOAddressSpace *space; VFIOIOMMUClass *vioc; =20 - space =3D vfio_get_address_space(as); + space =3D vfio_address_space_get(as); =20 /* * VFIO is currently incompatible with discarding of RAM insofar as the @@ -675,7 +675,7 @@ close_fd_exit: close(fd); =20 put_space_exit: - vfio_put_address_space(space); + vfio_address_space_put(space); =20 return false; } @@ -714,7 +714,7 @@ static void vfio_disconnect_container(VFIOGroup *group) close(container->fd); object_unref(container); =20 - vfio_put_address_space(space); + vfio_address_space_put(space); } } =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 7196c4080125674ec58b1ebf02dad84b4387c355..a520d40afc00d79ae8617fd3c40= 433e228583b5a 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -486,7 +486,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, goto err_connect_bind; } =20 - space =3D vfio_get_address_space(as); + space =3D vfio_address_space_get(as); =20 /* * The HostIOMMUDevice data from legacy backend is static and doesn't = need @@ -606,7 +606,7 @@ err_discard_disable: err_attach_container: iommufd_cdev_container_destroy(container); err_alloc_ioas: - vfio_put_address_space(space); + vfio_address_space_put(space); iommufd_cdev_unbind_and_disconnect(vbasedev); err_connect_bind: close(vbasedev->fd); @@ -631,7 +631,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) vfio_cpr_unregister_container(bcontainer); iommufd_cdev_detach_container(vbasedev, container); iommufd_cdev_container_destroy(container); - vfio_put_address_space(space); + vfio_address_space_put(space); =20 iommufd_cdev_unbind_and_disconnect(vbasedev); close(vbasedev->fd); --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571265; cv=none; d=zohomail.com; s=zohoarc; b=KHLSUOUR+wglqvat5DB5C5Dvv47cz0nm7Q4vu8iJ/H/kdX0ICFNou1KsTW1RiWPq5jMePuV0gPdm41k0k1tUbYe639j2zRAo8TJKc0wPy66COyuupdYKoFlO0e7Wz0HG/17BAHC0NU032h5wiA7z5uDMtLXG5HSm1OKrJ7vMfeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571265; 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=qwXGBMaMW0/8GTydkZjueSaZzmNjSIL+S+ixpPp105Q=; b=HftlBVgN2mgZqoqYcE0WISfwaXojFbs5nAsdfLMeh5mzQQfWh4o3xAx/2ox9rBjdGRQyTQHYN9Ffn7y5poLY95fvmN+nTJAU1MjSi03Ylf2or672Zx51bRoF+GvVCUpZ3JYKm7sCbUelFLngepOSoBmlgIedQLjxPtMkR1AA1Sg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571265548737.5260414215664; Fri, 25 Apr 2025 01:54:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eja-00040S-RR; Fri, 25 Apr 2025 04:48:34 -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 1u8Ej5-00032Y-7v for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:06 -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 1u8Ej3-0003G2-DR for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:02 -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-244-8Fa3axnGMBqP1tT6ByyKdA-1; Fri, 25 Apr 2025 04:47:59 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 F1D921956086; Fri, 25 Apr 2025 08:47:57 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E992430001AB; Fri, 25 Apr 2025 08:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570880; 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=qwXGBMaMW0/8GTydkZjueSaZzmNjSIL+S+ixpPp105Q=; b=Ld9IX7tXX4R2UsVXPUIUtxZq6zwsMSW8zyLYWYbAbjPWchd+Le5UGVvWGY2wnsrbXLyQP/ 9lAOGNqUCwUsB1JCb2lM6NkC2HiVDNjuUKMqXdOUK32AGJSsrnmrD+1b4pSU11gZ70Et8F LRDNWDy2IMhquVS1j6zUIjXe2odVKyY= X-MC-Unique: 8Fa3axnGMBqP1tT6ByyKdA-1 X-Mimecast-MFC-AGG-ID: 8Fa3axnGMBqP1tT6ByyKdA_1745570878 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , John Levon Subject: [PULL 19/50] vfio: Move Host IOMMU type declarations into their respective files Date: Fri, 25 Apr 2025 10:46:12 +0200 Message-ID: <20250425084644.102196-20-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571266977019000 These definitions don't have any use outside of their respective submodules. There is no need to expose them externally. Keep them private. Reviewed-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-15-clg@redha= t.com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-16-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 5 ----- hw/vfio/container.c | 2 ++ hw/vfio/iommufd.c | 3 +++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 7d78eb85daf09e39a9c48fd879ec703950a58dd0..bb11b8215a889500bdf019166cf= d2622431432a4 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -115,11 +115,6 @@ struct VFIODeviceOps { int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 - -#define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" -#define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ - TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" - void vfio_disable_irqindex(VFIODevice *vbasedev, int index); void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index); void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index cc8cc0f2726be43dfccaf609ee77aa17a493cd2d..6ef53ee187052002be0bd20af8f= 05b41cc2424b3 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -34,6 +34,8 @@ #include "pci.h" #include "hw/vfio/vfio-container.h" =20 +#define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" + typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList; static VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index a520d40afc00d79ae8617fd3c40433e228583b5a..2ec15bc2692e2eb90299e5a1c09= ab6b738c69cf0 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -27,6 +27,9 @@ #include "pci.h" #include "vfio-iommufd.h" =20 +#define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ + TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" + static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr io= va, ram_addr_t size, void *vaddr, bool readonly) { --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571244; cv=none; d=zohomail.com; s=zohoarc; b=KKcrvYMovfl2+N3W9QmOb+Zm937Qy4NzWoi4b1R5hMyJuND847xUXSujTPCut0ydeUjelzsqRnUXHjSMqreJ+HBCgVaCv1E+8w81g//HTE8V7r5XL+0GDRj21DVgdIbXVGoi4FVrAQQU2Q4O57yD7yWOHcE8Io/SXHR/Mo1kX0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571244; 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=BWX9TpPpPcwU2SDAsZBVZrpVJxO44kGgrgcQiQERT58=; b=LmL4mOOvK5gzGhjdKl6zJ6E3nKxt3h6uvOQtJ5XtB2KYMnMmcVQ3rS80Z6qV10WEqAJVQR4sGJ7Hnk/v3B6btdcgR24cOnPDdh1C+UFS7bGDL85w1j6DR6VCwSyp+LUe1DqR2ewg51URpf+oLNHvJQQBuOWAo/yrbPbY02LNc+M= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571244610967.8265886149213; Fri, 25 Apr 2025 01:54:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejg-0004Nd-87; Fri, 25 Apr 2025 04:48: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 1u8EjG-0003RZ-Tq for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EjA-0003GU-SW for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:14 -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-225-3hAdNj10O_yrOW36LbmXRg-1; Fri, 25 Apr 2025 04:48:01 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 73D491956086; Fri, 25 Apr 2025 08:48:00 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5063B30001A2; Fri, 25 Apr 2025 08:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570886; 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=BWX9TpPpPcwU2SDAsZBVZrpVJxO44kGgrgcQiQERT58=; b=AY4YORCjj75bxmcJVVWsxFYfiLXakVSwU40R6iiw5S9rf/8Ls8Q17aH5UBNMS8PyZHTozP BBYFPll2TqxOVF/h188F2p/3g4fV5Ne1nBsVZl5Ef6HRawpjFWXJhkExJ/hrOsJh4bVVW8 LcWR9havffgzbzD1iFuXjJOchnArqg0= X-MC-Unique: 3hAdNj10O_yrOW36LbmXRg-1 X-Mimecast-MFC-AGG-ID: 3hAdNj10O_yrOW36LbmXRg_1745570880 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 20/50] vfio: Introduce a new header file for helper services Date: Fri, 25 Apr 2025 10:46:13 +0200 Message-ID: <20250425084644.102196-21-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571244976019000 Gather all helper routine declarations into "vfio-helpers.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-16-clg@redha= t.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-17-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-helpers.h | 26 ++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 7 ------- hw/s390x/s390-pci-vfio.c | 1 + hw/vfio/common.c | 1 + hw/vfio/container.c | 1 + hw/vfio/helpers.c | 1 + hw/vfio/pci.c | 1 + hw/vfio/region.c | 1 + 8 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 hw/vfio/vfio-helpers.h diff --git a/hw/vfio/vfio-helpers.h b/hw/vfio/vfio-helpers.h new file mode 100644 index 0000000000000000000000000000000000000000..d7e4dcba512a2a842c4a9d75e2d= 834bdf97c8f31 --- /dev/null +++ b/hw/vfio/vfio-helpers.h @@ -0,0 +1,26 @@ +/* + * VFIO helpers + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_VFIO_HELPERS_H +#define HW_VFIO_VFIO_HELPERS_H + +#ifdef CONFIG_LINUX +#include + +struct vfio_info_cap_header * +vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id); +struct vfio_info_cap_header * +vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id); +struct vfio_info_cap_header * +vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id); + +#endif + +int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); + +#endif /* HW_VFIO_VFIO_HELPERS_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index bb11b8215a889500bdf019166cfd2622431432a4..8e465111d26ff612148fcd1af9a= 39a4e4de5184e 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -147,17 +147,10 @@ int vfio_get_region_info(VFIODevice *vbasedev, int in= dex, int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo); bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe); -struct vfio_info_cap_header * -vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id); bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, unsigned int *avail); -struct vfio_info_cap_header * -vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id); -struct vfio_info_cap_header * -vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id); #endif =20 -int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); bool vfio_devices_all_dirty_tracking_started( const VFIOContainerBase *bcontainer); bool diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index 748a51fd8cc478604340b7c812e0da356836b807..aaf91319b4e3cfacf3ca3a91e71= d9d6d2fbda13f 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -21,6 +21,7 @@ #include "hw/s390x/s390-pci-vfio.h" #include "hw/vfio/pci.h" #include "hw/vfio/vfio-container.h" +#include "hw/vfio/vfio-helpers.h" =20 /* * Get the current DMA available count from vfio. Returns true if vfio is diff --git a/hw/vfio/common.c b/hw/vfio/common.c index c099d4d24d044263ca3570ec9cfbd5ca4bcd1e23..18e5aacbd1b5e8033221df99999= 739cd58c883b0 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -44,6 +44,7 @@ #include "system/tcg.h" #include "system/tpm.h" #include "vfio-migration-internal.h" +#include "vfio-helpers.h" =20 VFIODeviceList vfio_device_list =3D QLIST_HEAD_INITIALIZER(vfio_device_list); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 6ef53ee187052002be0bd20af8f05b41cc2424b3..b2d72f5036c5182e4b2d48b8cf5= 7260d906e0bb5 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -33,6 +33,7 @@ #include "qapi/error.h" #include "pci.h" #include "hw/vfio/vfio-container.h" +#include "vfio-helpers.h" =20 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" =20 diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 89403943a7a219e491b6812d50b27b7f1fd7b4a4..054ee6e31ebd080cc10516b9fc5= a0373725b63d8 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -30,6 +30,7 @@ #include "qemu/error-report.h" #include "qemu/units.h" #include "monitor/monitor.h" +#include "vfio-helpers.h" =20 /* * Common VFIO interrupt disable diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index b0aac2f3a0b93ad3af6d8b71c6dc0f9d390ea475..bade3b80d7d98125cf84e13f0d3= 4009b6c46992e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -45,6 +45,7 @@ #include "migration/qemu-file.h" #include "system/iommufd.h" #include "vfio-migration-internal.h" +#include "vfio-helpers.h" =20 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug" =20 diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 08cd69e7047ab950151832864a14af7af774ff3b..9049143abffa28bed333d110d1e= 01d68ad7f83be 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -29,6 +29,7 @@ #include "qemu/error-report.h" #include "qemu/units.h" #include "monitor/monitor.h" +#include "vfio-helpers.h" =20 /* * IO Port/MMIO - Beware of the endians, VFIO is always little endian --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571349; cv=none; d=zohomail.com; s=zohoarc; b=QDFhYBYmXT6lA5h3u+GsVCyaO4XQ6KmByymdhRFK1ZCJVczpMJS2mplwWf9wcr/FoSq5JmJR3MfwvCnBOXSUtfDRIAeN9ceE9cPQOM90b/fPFptU1HMYiPPD7EHRXDmgJUER/cDR8OlvrLhK2UsRuJaB8ENIam5/ASGAZtpcoXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571349; 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=qOKPEmVG3cL7qwvWrWnc6oMtBMiJ4La+cPHLDKNEb0k=; b=lKCg6QHMHTRlQQKS9HPQ2TQ3wvKFQPzsjoOyuEq2S+RFCoK5BlMEISDN0Ztw/cdJsw7zM2pZCjTGxkm91NYh5FoPg3OxlqjUHXyEren19DkuBnA1ri88Wv2PZbuj5ofOeVfeEcSeeBoFTCtkns0co2YsB8wGUj43jI1drbE8UJQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571349272610.0016374147633; Fri, 25 Apr 2025 01:55:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EjP-0003Ya-UD; Fri, 25 Apr 2025 04:48:24 -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 1u8EjH-0003Ri-Et for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:17 -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 1u8EjE-0003Ga-5B for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:15 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-82-RnHDP8ldMymMgB6_78qpDA-1; Fri, 25 Apr 2025 04:48:03 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0BCF1800876; Fri, 25 Apr 2025 08:48:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0ADC230001A2; Fri, 25 Apr 2025 08:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570887; 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=qOKPEmVG3cL7qwvWrWnc6oMtBMiJ4La+cPHLDKNEb0k=; b=WFCF1UvOr2Kd2xDRbFJVaLM8bt5WCjsHDoRKBnPHgGtOSMVr0ZLpc/mWDHowWdD4tVpxbp 6vQZCH8QGQbcqMQxIwwtvXqXjtzinNlaTbGL45myuJfq+K4kAZT1LutXd5InsT2bnnNKs/ NfZFCaJIJuq/1WGueBtgQ9+JWRVy+Io= X-MC-Unique: RnHDP8ldMymMgB6_78qpDA-1 X-Mimecast-MFC-AGG-ID: RnHDP8ldMymMgB6_78qpDA_1745570883 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 21/50] vfio: Move vfio_get_info_dma_avail() into helpers.c Date: Fri, 25 Apr 2025 10:46:14 +0200 Message-ID: <20250425084644.102196-22-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571351300019000 vfio_get_info_dma_avail() is a low level routine similar to the other routines extracting capabilities from 'struct vfio_iommu_type1_info'. It belongs to file "helpers.c". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-17-clg@redha= t.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-18-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-helpers.h | 5 ++++- include/hw/vfio/vfio-common.h | 2 -- hw/vfio/container.c | 31 ------------------------------- hw/vfio/helpers.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/hw/vfio/vfio-helpers.h b/hw/vfio/vfio-helpers.h index d7e4dcba512a2a842c4a9d75e2d834bdf97c8f31..9af43878b8b90c0247221543423= a5aca8be2eef5 100644 --- a/hw/vfio/vfio-helpers.h +++ b/hw/vfio/vfio-helpers.h @@ -18,7 +18,10 @@ struct vfio_info_cap_header * vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id); struct vfio_info_cap_header * vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id); - +struct vfio_info_cap_header * +vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t= id); +bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, + unsigned int *avail); #endif =20 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 8e465111d26ff612148fcd1af9a39a4e4de5184e..be2558f7e4e1e577caf69ee9879= 8e490e80be96b 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -147,8 +147,6 @@ int vfio_get_region_info(VFIODevice *vbasedev, int inde= x, int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo); bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe); -bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, - unsigned int *avail); #endif =20 bool vfio_devices_all_dirty_tracking_started( diff --git a/hw/vfio/container.c b/hw/vfio/container.c index b2d72f5036c5182e4b2d48b8cf57260d906e0bb5..3fdd5dac379bd43fdd8f606e020= 29c1f44bdb69a 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -278,37 +278,6 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOCo= ntainerBase *bcontainer, return ret; } =20 -static struct vfio_info_cap_header * -vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t= id) -{ - if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) { - return NULL; - } - - return vfio_get_cap((void *)info, info->cap_offset, id); -} - -bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, - unsigned int *avail) -{ - struct vfio_info_cap_header *hdr; - struct vfio_iommu_type1_info_dma_avail *cap; - - /* If the capability cannot be found, assume no DMA limiting */ - hdr =3D vfio_get_iommu_type1_info_cap(info, - VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL); - if (!hdr) { - return false; - } - - if (avail !=3D NULL) { - cap =3D (void *) hdr; - *avail =3D cap->avail; - } - - return true; -} - static bool vfio_get_info_iova_range(struct vfio_iommu_type1_info *info, VFIOContainerBase *bcontainer) { diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 054ee6e31ebd080cc10516b9fc5a0373725b63d8..1a584ba5f007995a16d2364faeb= 72cb2b22de4e9 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -222,6 +222,37 @@ retry: return 0; } =20 +struct vfio_info_cap_header * +vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t= id) +{ + if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) { + return NULL; + } + + return vfio_get_cap((void *)info, info->cap_offset, id); +} + +bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, + unsigned int *avail) +{ + struct vfio_info_cap_header *hdr; + struct vfio_iommu_type1_info_dma_avail *cap; + + /* If the capability cannot be found, assume no DMA limiting */ + hdr =3D vfio_get_iommu_type1_info_cap(info, + VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL); + if (!hdr) { + return false; + } + + if (avail !=3D NULL) { + cap =3D (void *) hdr; + *avail =3D cap->avail; + } + + return true; +} + int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo) { --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570941; cv=none; d=zohomail.com; s=zohoarc; b=kW059r6rTLj1JiuZLzvZwLiqmJ3gOiM+t05/TOceeIw89breudcnuE0gIvteivdgFfb97bVrSOxt5rDnlejbHmudUPak+Z77PNTs9Hlld5MuhLFvo3gdyton65oQpAmGyN9AlBJLa6WSVTUB6m3dphcJwwv7U1pDXssJOkoubEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570941; 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=s30yRNqQjluROqGY+qZrtxBuCfrpV+9NHGTuq8+0ywE=; b=LhX0rcx3r1Vw2fRk+hfmwe7n79iyT2RD27MvNP1opHyycewGNLxxs5gudBysF58zNDrBdhIoZ6p9BEJKIx1F+NSpQ8qAW/As7TH0c5ZgwsuvN/JxsGGy6VW4HAtsmoUbeNaOM8LjhmnBapYE38y/yuhJJ2RWYkVjVRWyjeNdpG4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570941208351.67158194253045; Fri, 25 Apr 2025 01:49:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EjY-0003vb-PS; Fri, 25 Apr 2025 04:48:33 -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 1u8EjI-0003SF-KE for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:17 -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 1u8EjE-0003Gh-FU for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:16 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-z41OSc6xMUKUg0l1n6CXEg-1; Fri, 25 Apr 2025 04:48:06 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B466A1800876; Fri, 25 Apr 2025 08:48:05 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67A3130001A2; Fri, 25 Apr 2025 08:48:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570891; 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=s30yRNqQjluROqGY+qZrtxBuCfrpV+9NHGTuq8+0ywE=; b=BaoUTIijxnKGu8Tu8eokvaWVx6Loo/HWciRcfkFIgKjDPy3/nxPCUmWgDn4Y0mO7iiVF6O DuYQV1KJun3ugbkGqZx0T+TZGyL1ua0e4ArvDkfuKoAjhjuuejajbuPdVqpF6dpAO0u51G LruJdS0pATR2sz3xgdOb0UfdxWKDCgY= X-MC-Unique: z41OSc6xMUKUg0l1n6CXEg-1 X-Mimecast-MFC-AGG-ID: z41OSc6xMUKUg0l1n6CXEg_1745570885 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , John Levon Subject: [PULL 22/50] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Date: Fri, 25 Apr 2025 10:46:15 +0200 Message-ID: <20250425084644.102196-23-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570943048019100 vfio_kvm_device_add/del_fd() are low level routines. Move them with the other helpers. Reviewed-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-18-clg@redha= t.com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-19-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-helpers.h | 3 ++ include/hw/vfio/vfio-common.h | 3 -- hw/vfio/common.c | 58 ---------------------------------- hw/vfio/helpers.c | 59 +++++++++++++++++++++++++++++++++++ hw/vfio/iommufd.c | 1 + hw/vfio/meson.build | 2 +- 6 files changed, 64 insertions(+), 62 deletions(-) diff --git a/hw/vfio/vfio-helpers.h b/hw/vfio/vfio-helpers.h index 9af43878b8b90c0247221543423a5aca8be2eef5..5d91e33d27be1bdd8eb9b3ce74c= 39a4ac1991adc 100644 --- a/hw/vfio/vfio-helpers.h +++ b/hw/vfio/vfio-helpers.h @@ -26,4 +26,7 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info= *info, =20 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); =20 +int vfio_kvm_device_add_fd(int fd, Error **errp); +int vfio_kvm_device_del_fd(int fd, Error **errp); + #endif /* HW_VFIO_VFIO_HELPERS_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index be2558f7e4e1e577caf69ee98798e490e80be96b..442ec287d799538e1d3669a6c47= 0960cce5459a0 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -130,9 +130,6 @@ bool vfio_attach_device(char *name, VFIODevice *vbasede= v, void vfio_detach_device(VFIODevice *vbasedev); VFIODevice *vfio_get_vfio_device(Object *obj); =20 -int vfio_kvm_device_add_fd(int fd, Error **errp); -int vfio_kvm_device_del_fd(int fd, Error **errp); - bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 18e5aacbd1b5e8033221df99999739cd58c883b0..2b3af051cc46118799b882a9a8e= 3ae96e556952b 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1333,64 +1333,6 @@ void vfio_reset_handler(void *opaque) } } =20 -int vfio_kvm_device_add_fd(int fd, Error **errp) -{ -#ifdef CONFIG_KVM - struct kvm_device_attr attr =3D { - .group =3D KVM_DEV_VFIO_FILE, - .attr =3D KVM_DEV_VFIO_FILE_ADD, - .addr =3D (uint64_t)(unsigned long)&fd, - }; - - if (!kvm_enabled()) { - return 0; - } - - if (vfio_kvm_device_fd < 0) { - struct kvm_create_device cd =3D { - .type =3D KVM_DEV_TYPE_VFIO, - }; - - if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) { - error_setg_errno(errp, errno, "Failed to create KVM VFIO devic= e"); - return -errno; - } - - vfio_kvm_device_fd =3D cd.fd; - } - - if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { - error_setg_errno(errp, errno, "Failed to add fd %d to KVM VFIO dev= ice", - fd); - return -errno; - } -#endif - return 0; -} - -int vfio_kvm_device_del_fd(int fd, Error **errp) -{ -#ifdef CONFIG_KVM - struct kvm_device_attr attr =3D { - .group =3D KVM_DEV_VFIO_FILE, - .attr =3D KVM_DEV_VFIO_FILE_DEL, - .addr =3D (uint64_t)(unsigned long)&fd, - }; - - if (vfio_kvm_device_fd < 0) { - error_setg(errp, "KVM VFIO device isn't created yet"); - return -EINVAL; - } - - if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { - error_setg_errno(errp, errno, - "Failed to remove fd %d from KVM VFIO device", fd= ); - return -errno; - } -#endif - return 0; -} - struct vfio_device_info *vfio_get_device_info(int fd) { struct vfio_device_info *info; diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 1a584ba5f007995a16d2364faeb72cb2b22de4e9..e6b75baa805241b4df28769338b= 15a6fe9b99501 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -22,6 +22,7 @@ #include "qemu/osdep.h" #include =20 +#include "system/kvm.h" #include "hw/vfio/vfio-common.h" #include "hw/vfio/pci.h" #include "hw/hw.h" @@ -253,6 +254,64 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_i= nfo *info, return true; } =20 +int vfio_kvm_device_add_fd(int fd, Error **errp) +{ +#ifdef CONFIG_KVM + struct kvm_device_attr attr =3D { + .group =3D KVM_DEV_VFIO_FILE, + .attr =3D KVM_DEV_VFIO_FILE_ADD, + .addr =3D (uint64_t)(unsigned long)&fd, + }; + + if (!kvm_enabled()) { + return 0; + } + + if (vfio_kvm_device_fd < 0) { + struct kvm_create_device cd =3D { + .type =3D KVM_DEV_TYPE_VFIO, + }; + + if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) { + error_setg_errno(errp, errno, "Failed to create KVM VFIO devic= e"); + return -errno; + } + + vfio_kvm_device_fd =3D cd.fd; + } + + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_setg_errno(errp, errno, "Failed to add fd %d to KVM VFIO dev= ice", + fd); + return -errno; + } +#endif + return 0; +} + +int vfio_kvm_device_del_fd(int fd, Error **errp) +{ +#ifdef CONFIG_KVM + struct kvm_device_attr attr =3D { + .group =3D KVM_DEV_VFIO_FILE, + .attr =3D KVM_DEV_VFIO_FILE_DEL, + .addr =3D (uint64_t)(unsigned long)&fd, + }; + + if (vfio_kvm_device_fd < 0) { + error_setg(errp, "KVM VFIO device isn't created yet"); + return -EINVAL; + } + + if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) { + error_setg_errno(errp, errno, + "Failed to remove fd %d from KVM VFIO device", fd= ); + return -errno; + } +#endif + return 0; +} + int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo) { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 2ec15bc2692e2eb90299e5a1c09ab6b738c69cf0..85b5a8146ac401af6be8109c28e= a4c7a39e84521 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -26,6 +26,7 @@ #include "qemu/chardev_open.h" #include "pci.h" #include "vfio-iommufd.h" +#include "vfio-helpers.h" =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 07010c7c9e01a39ae3449c54d2027a2cdd0a7a4d..21795b3d19e5db0c93993c0cb4a= 951a70d260f10 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -2,6 +2,7 @@ vfio_ss =3D ss.source_set() vfio_ss.add(files( 'common.c', 'container.c', + 'helpers.c', )) vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c')) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( @@ -18,7 +19,6 @@ specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss) system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c')) system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c')) system_ss.add(when: 'CONFIG_VFIO', if_true: files( - 'helpers.c', 'container-base.c', 'migration.c', 'migration-multifd.c', --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571005; cv=none; d=zohomail.com; s=zohoarc; b=O+U8cFfpEh81Ko4d2803d1VYazmYk/ZdcUBzheevV/H3zNFe9NcpyUevnDbDsdbyIV/g0TblXL+UmTPQG1lxB/9tuXVibCHZhYEiqbu81JKWt2X8vSV+yU07H4xw1D8/c1BzFfYWjX36Zmn32VZJV3NSqXsV1Qmn75jRav/khn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571005; 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=pQVWhSfaqWAu3DCFHgrvYVX+zy0oRE6ifscy5BtoQ4w=; b=dweNeGRpHH4mH4OFgPIEJ8azue+o7NwYN5SuEz69+i2qKrlB2aozqycj+wuvOM2sJB30gm8xqEdVi0u7J2WAcBcc7J8jHNZSLZI9uSemeiUsh9lNfdLc2I5DJMa1Gn7LqvNrhU7SWrwvKwHzX4QB7P77zjUS0avb79QKnxru6ec= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571005055989.3533426041517; Fri, 25 Apr 2025 01:50:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EjV-0003gV-9h; Fri, 25 Apr 2025 04:48:29 -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 1u8EjI-0003SD-GK for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EjF-0003Gl-AB for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:16 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-KXVbt05CN9qTUkzfyq6g8Q-1; Fri, 25 Apr 2025 04:48:09 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A5EC180034E; Fri, 25 Apr 2025 08:48:08 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3B68130001A2; Fri, 25 Apr 2025 08:48:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570892; 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=pQVWhSfaqWAu3DCFHgrvYVX+zy0oRE6ifscy5BtoQ4w=; b=Og3aStNlcqur4P/ASJaYqCymF5NX3Os6yHJPLuadG2EIklgiJW3fnXmkPXUQmLA2Lw4U2C reaBb/Kuif9In+ag4MyiKx9ME2QT9D8JJ/gHom0hwzMVRnoUwecwf5JFNTL2QJMVbar8tE yzbBpUhkoGJkJ2tRWVTKmLyOsQVgfOA= X-MC-Unique: KXVbt05CN9qTUkzfyq6g8Q-1 X-Mimecast-MFC-AGG-ID: KXVbt05CN9qTUkzfyq6g8Q_1745570888 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , John Levon Subject: [PULL 23/50] vfio: Move vfio_get_device_info() to helpers.c Date: Fri, 25 Apr 2025 10:46:16 +0200 Message-ID: <20250425084644.102196-24-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571007059019100 vfio_get_device_info() is a low level routine. Move it with the other helpers. Reviewed-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-19-clg@redha= t.com Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-20-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-helpers.h | 1 + include/hw/vfio/vfio-common.h | 1 - hw/vfio/common.c | 24 ------------------------ hw/vfio/helpers.c | 24 ++++++++++++++++++++++++ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/hw/vfio/vfio-helpers.h b/hw/vfio/vfio-helpers.h index 5d91e33d27be1bdd8eb9b3ce74c39a4ac1991adc..dbcb68bbb0e12607f5ccf15f114= 530966c2cbcb2 100644 --- a/hw/vfio/vfio-helpers.h +++ b/hw/vfio/vfio-helpers.h @@ -25,6 +25,7 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info= *info, #endif =20 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); +struct vfio_device_info *vfio_get_device_info(int fd); =20 int vfio_kvm_device_add_fd(int fd, Error **errp); int vfio_kvm_device_del_fd(int fd, Error **errp); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 442ec287d799538e1d3669a6c470960cce5459a0..dca7a6a4b3dcc583eb430b8cf93= 80a007623ec26 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -122,7 +122,6 @@ bool vfio_set_irq_signaling(VFIODevice *vbasedev, int i= ndex, int subindex, int action, int fd, Error **errp); =20 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_device_hiod_realize(VFIODevice *vbasedev, Error **errp); bool vfio_attach_device(char *name, VFIODevice *vbasedev, diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 2b3af051cc46118799b882a9a8e3ae96e556952b..f80c0ef229c867070593f6a6f53= e7ea1a701cf41 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1333,30 +1333,6 @@ void vfio_reset_handler(void *opaque) } } =20 -struct vfio_device_info *vfio_get_device_info(int fd) -{ - struct vfio_device_info *info; - uint32_t argsz =3D sizeof(*info); - - info =3D g_malloc0(argsz); - -retry: - info->argsz =3D argsz; - - if (ioctl(fd, VFIO_DEVICE_GET_INFO, info)) { - g_free(info); - return NULL; - } - - if (info->argsz > argsz) { - argsz =3D info->argsz; - info =3D g_realloc(info, argsz); - goto retry; - } - - return info; -} - bool vfio_attach_device(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp) { diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index e6b75baa805241b4df28769338b15a6fe9b99501..b7f75b47af3a5d066eb51890383= 1214df6c3755a 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -312,6 +312,30 @@ int vfio_kvm_device_del_fd(int fd, Error **errp) return 0; } =20 +struct vfio_device_info *vfio_get_device_info(int fd) +{ + struct vfio_device_info *info; + uint32_t argsz =3D sizeof(*info); + + info =3D g_malloc0(argsz); + +retry: + info->argsz =3D argsz; + + if (ioctl(fd, VFIO_DEVICE_GET_INFO, info)) { + g_free(info); + return NULL; + } + + if (info->argsz > argsz) { + argsz =3D info->argsz; + info =3D g_realloc(info, argsz); + goto retry; + } + + return info; +} + int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo) { --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571199; cv=none; d=zohomail.com; s=zohoarc; b=F/PjOFPm2rmwEpge6l+U/EgbtUpZOUKPZwX9M9RCC1SLAAWbCdf9MPl1z+rjwCw79nV180gimBOlGlBMD29aCaxC+yZJ0Od3zbZRmEhY5Ie9sDFGttq5MpDIfcbGqSR/ZIegMQWuuOwgZWZDNFh190hkjA4ycHGCKR6Yy1hjWO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571199; 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=ldKF2ZKRRoEoBZv/t7E9dil8wBlS9ODxbRN+2cUIEhY=; b=nDyFhHXcOPUBvzaqnZAYrFaDHFjSRR+LvlvOMHcopRNXapFDg+ZQ2ISBzJhudXBBYAxwDAA7yXVM7OdsGD+wbTVLYC2uuOpdiwp7pV2xVHC86EA5BhwlEX7epnPxVFMYsxMmXbmUtsfGrGC+Rx6ZWYj8OjfCHLpNafvFTj2I7oE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571199479819.9420943822686; Fri, 25 Apr 2025 01:53:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EjX-0003lI-Kj; Fri, 25 Apr 2025 04:48:32 -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 1u8EjK-0003Sh-A4 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:19 -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 1u8EjH-0003Gz-Dr for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:18 -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-658-QkGlAkdDPsqOHB3Ye-6umA-1; Fri, 25 Apr 2025 04:48:12 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 28A6A195608A; Fri, 25 Apr 2025 08:48:11 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 961B430001A2; Fri, 25 Apr 2025 08:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570894; 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=ldKF2ZKRRoEoBZv/t7E9dil8wBlS9ODxbRN+2cUIEhY=; b=hmVQPoYFL1RhheY2Ns9esJQSS7XF26nsC4/nmTpeoTeyxX2L1ViIgrWIrmZKu+6b7A07I8 8Q/Dwj7pnCq8PW0HoEkTFyHSXst6MHQSjgy7IwAqpUosPC37yCtXbN40sWK0IiRCEmyh+D dNNP8Fg7xCGqPV+tDcEnOI5ItrWRb20= X-MC-Unique: QkGlAkdDPsqOHB3Ye-6umA-1 X-Mimecast-MFC-AGG-ID: QkGlAkdDPsqOHB3Ye-6umA_1745570891 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , John Levon Subject: [PULL 24/50] vfio: Introduce a new file for VFIODevice definitions Date: Fri, 25 Apr 2025 10:46:17 +0200 Message-ID: <20250425084644.102196-25-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571200882019000 Move all VFIODevice related routines of "helpers.c" into a new "device.c" file. Reviewed-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-21-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/device.c | 330 +++++++++++++++++++++++++++++++++++++++++++ hw/vfio/helpers.c | 303 --------------------------------------- hw/vfio/meson.build | 1 + hw/vfio/trace-events | 4 +- 4 files changed, 334 insertions(+), 304 deletions(-) create mode 100644 hw/vfio/device.c diff --git a/hw/vfio/device.c b/hw/vfio/device.c new file mode 100644 index 0000000000000000000000000000000000000000..21c6824430c49170b8d1b9a69ff= 51272f48096a4 --- /dev/null +++ b/hw/vfio/device.c @@ -0,0 +1,330 @@ +/* + * VFIO device + * + * Copyright Red Hat, Inc. 2012 + * + * Authors: + * Alex Williamson + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Based on qemu-kvm device-assignment: + * Adapted for KVM by Qumranet. + * Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com) + * Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com) + * Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com) + * Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com) + * Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com) + */ + +#include "qemu/osdep.h" +#include + +#include "hw/vfio/vfio-common.h" +#include "hw/vfio/pci.h" +#include "hw/hw.h" +#include "trace.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/units.h" +#include "monitor/monitor.h" +#include "vfio-helpers.h" + +/* + * Common VFIO interrupt disable + */ +void vfio_disable_irqindex(VFIODevice *vbasedev, int index) +{ + struct vfio_irq_set irq_set =3D { + .argsz =3D sizeof(irq_set), + .flags =3D VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER, + .index =3D index, + .start =3D 0, + .count =3D 0, + }; + + ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); +} + +void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index) +{ + struct vfio_irq_set irq_set =3D { + .argsz =3D sizeof(irq_set), + .flags =3D VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK, + .index =3D index, + .start =3D 0, + .count =3D 1, + }; + + ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); +} + +void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index) +{ + struct vfio_irq_set irq_set =3D { + .argsz =3D sizeof(irq_set), + .flags =3D VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_MASK, + .index =3D index, + .start =3D 0, + .count =3D 1, + }; + + ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); +} + +static inline const char *action_to_str(int action) +{ + switch (action) { + case VFIO_IRQ_SET_ACTION_MASK: + return "MASK"; + case VFIO_IRQ_SET_ACTION_UNMASK: + return "UNMASK"; + case VFIO_IRQ_SET_ACTION_TRIGGER: + return "TRIGGER"; + default: + return "UNKNOWN ACTION"; + } +} + +static const char *index_to_str(VFIODevice *vbasedev, int index) +{ + if (vbasedev->type !=3D VFIO_DEVICE_TYPE_PCI) { + return NULL; + } + + switch (index) { + case VFIO_PCI_INTX_IRQ_INDEX: + return "INTX"; + case VFIO_PCI_MSI_IRQ_INDEX: + return "MSI"; + case VFIO_PCI_MSIX_IRQ_INDEX: + return "MSIX"; + case VFIO_PCI_ERR_IRQ_INDEX: + return "ERR"; + case VFIO_PCI_REQ_IRQ_INDEX: + return "REQ"; + default: + return NULL; + } +} + +bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, + int action, int fd, Error **errp) +{ + ERRP_GUARD(); + g_autofree struct vfio_irq_set *irq_set =3D NULL; + int argsz; + const char *name; + int32_t *pfd; + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | action; + irq_set->index =3D index; + irq_set->start =3D subindex; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + *pfd =3D fd; + + if (!ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { + return true; + } + + error_setg_errno(errp, errno, "VFIO_DEVICE_SET_IRQS failure"); + + name =3D index_to_str(vbasedev, index); + if (name) { + error_prepend(errp, "%s-%d: ", name, subindex); + } else { + error_prepend(errp, "index %d-%d: ", index, subindex); + } + error_prepend(errp, + "Failed to %s %s eventfd signaling for interrupt ", + fd < 0 ? "tear down" : "set up", action_to_str(action)); + return false; +} + +int vfio_get_region_info(VFIODevice *vbasedev, int index, + struct vfio_region_info **info) +{ + size_t argsz =3D sizeof(struct vfio_region_info); + + *info =3D g_malloc0(argsz); + + (*info)->index =3D index; +retry: + (*info)->argsz =3D argsz; + + if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, *info)) { + g_free(*info); + *info =3D NULL; + return -errno; + } + + if ((*info)->argsz > argsz) { + argsz =3D (*info)->argsz; + *info =3D g_realloc(*info, argsz); + + goto retry; + } + + return 0; +} + +int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, + uint32_t subtype, struct vfio_region_info **i= nfo) +{ + int i; + + for (i =3D 0; i < vbasedev->num_regions; i++) { + struct vfio_info_cap_header *hdr; + struct vfio_region_info_cap_type *cap_type; + + if (vfio_get_region_info(vbasedev, i, info)) { + continue; + } + + hdr =3D vfio_get_region_info_cap(*info, VFIO_REGION_INFO_CAP_TYPE); + if (!hdr) { + g_free(*info); + continue; + } + + cap_type =3D container_of(hdr, struct vfio_region_info_cap_type, h= eader); + + trace_vfio_get_dev_region(vbasedev->name, i, + cap_type->type, cap_type->subtype); + + if (cap_type->type =3D=3D type && cap_type->subtype =3D=3D subtype= ) { + return 0; + } + + g_free(*info); + } + + *info =3D NULL; + return -ENODEV; +} + +bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe) +{ + g_autofree struct vfio_region_info *info =3D NULL; + bool ret =3D false; + + if (!vfio_get_region_info(vbasedev, region, &info)) { + if (vfio_get_region_info_cap(info, cap_type)) { + ret =3D true; + } + } + + return ret; +} + +bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp) +{ + ERRP_GUARD(); + struct stat st; + + if (vbasedev->fd < 0) { + if (stat(vbasedev->sysfsdev, &st) < 0) { + error_setg_errno(errp, errno, "no such host device"); + error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev); + return false; + } + /* User may specify a name, e.g: VFIO platform device */ + if (!vbasedev->name) { + vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); + } + } else { + if (!vbasedev->iommufd) { + error_setg(errp, "Use FD passing only with iommufd backend"); + return false; + } + /* + * Give a name with fd so any function printing out vbasedev->name + * will not break. + */ + if (!vbasedev->name) { + vbasedev->name =3D g_strdup_printf("VFIO_FD%d", vbasedev->fd); + } + } + + return true; +} + +void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) +{ + ERRP_GUARD(); + int fd =3D monitor_fd_param(monitor_cur(), str, errp); + + if (fd < 0) { + error_prepend(errp, "Could not parse remote object fd %s:", str); + return; + } + vbasedev->fd =3D fd; +} + +void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, + DeviceState *dev, bool ram_discard) +{ + vbasedev->type =3D type; + vbasedev->ops =3D ops; + vbasedev->dev =3D dev; + vbasedev->fd =3D -1; + + vbasedev->ram_block_discard_allowed =3D ram_discard; +} + +int vfio_device_get_aw_bits(VFIODevice *vdev) +{ + /* + * iova_ranges is a sorted list. For old kernels that support + * VFIO but not support query of iova ranges, iova_ranges is NULL, + * in this case HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX(64) is returned. + */ + GList *l =3D g_list_last(vdev->bcontainer->iova_ranges); + + if (l) { + Range *range =3D l->data; + return range_get_last_bit(range) + 1; + } + + 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); +} + +bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp) +{ + HostIOMMUDevice *hiod =3D vbasedev->hiod; + + if (!hiod) { + return true; + } + + return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp= ); +} + +VFIODevice *vfio_get_vfio_device(Object *obj) +{ + if (object_dynamic_cast(obj, TYPE_VFIO_PCI)) { + return &VFIO_PCI(obj)->vbasedev; + } else { + return NULL; + } +} diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index b7f75b47af3a5d066eb518903831214df6c3755a..7ddc9797ef7659035d927e40a3b= 99a8f74dca2de 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -24,131 +24,10 @@ =20 #include "system/kvm.h" #include "hw/vfio/vfio-common.h" -#include "hw/vfio/pci.h" #include "hw/hw.h" -#include "trace.h" #include "qapi/error.h" -#include "qemu/error-report.h" -#include "qemu/units.h" -#include "monitor/monitor.h" #include "vfio-helpers.h" =20 -/* - * Common VFIO interrupt disable - */ -void vfio_disable_irqindex(VFIODevice *vbasedev, int index) -{ - struct vfio_irq_set irq_set =3D { - .argsz =3D sizeof(irq_set), - .flags =3D VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER, - .index =3D index, - .start =3D 0, - .count =3D 0, - }; - - ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); -} - -void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index) -{ - struct vfio_irq_set irq_set =3D { - .argsz =3D sizeof(irq_set), - .flags =3D VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK, - .index =3D index, - .start =3D 0, - .count =3D 1, - }; - - ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); -} - -void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index) -{ - struct vfio_irq_set irq_set =3D { - .argsz =3D sizeof(irq_set), - .flags =3D VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_MASK, - .index =3D index, - .start =3D 0, - .count =3D 1, - }; - - ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); -} - -static inline const char *action_to_str(int action) -{ - switch (action) { - case VFIO_IRQ_SET_ACTION_MASK: - return "MASK"; - case VFIO_IRQ_SET_ACTION_UNMASK: - return "UNMASK"; - case VFIO_IRQ_SET_ACTION_TRIGGER: - return "TRIGGER"; - default: - return "UNKNOWN ACTION"; - } -} - -static const char *index_to_str(VFIODevice *vbasedev, int index) -{ - if (vbasedev->type !=3D VFIO_DEVICE_TYPE_PCI) { - return NULL; - } - - switch (index) { - case VFIO_PCI_INTX_IRQ_INDEX: - return "INTX"; - case VFIO_PCI_MSI_IRQ_INDEX: - return "MSI"; - case VFIO_PCI_MSIX_IRQ_INDEX: - return "MSIX"; - case VFIO_PCI_ERR_IRQ_INDEX: - return "ERR"; - case VFIO_PCI_REQ_IRQ_INDEX: - return "REQ"; - default: - return NULL; - } -} - -bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, - int action, int fd, Error **errp) -{ - ERRP_GUARD(); - g_autofree struct vfio_irq_set *irq_set =3D NULL; - int argsz; - const char *name; - int32_t *pfd; - - argsz =3D sizeof(*irq_set) + sizeof(*pfd); - - irq_set =3D g_malloc0(argsz); - irq_set->argsz =3D argsz; - irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | action; - irq_set->index =3D index; - irq_set->start =3D subindex; - irq_set->count =3D 1; - pfd =3D (int32_t *)&irq_set->data; - *pfd =3D fd; - - if (!ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { - return true; - } - - error_setg_errno(errp, errno, "VFIO_DEVICE_SET_IRQS failure"); - - name =3D index_to_str(vbasedev, index); - if (name) { - error_prepend(errp, "%s-%d: ", name, subindex); - } else { - error_prepend(errp, "index %d-%d: ", index, subindex); - } - error_prepend(errp, - "Failed to %s %s eventfd signaling for interrupt ", - fd < 0 ? "tear down" : "set up", action_to_str(action)); - return false; -} - int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size) { vbmap->pages =3D REAL_HOST_PAGE_ALIGN(size) / qemu_real_host_page_size= (); @@ -196,33 +75,6 @@ vfio_get_device_info_cap(struct vfio_device_info *info,= uint16_t id) return vfio_get_cap((void *)info, info->cap_offset, id); } =20 -int vfio_get_region_info(VFIODevice *vbasedev, int index, - struct vfio_region_info **info) -{ - size_t argsz =3D sizeof(struct vfio_region_info); - - *info =3D g_malloc0(argsz); - - (*info)->index =3D index; -retry: - (*info)->argsz =3D argsz; - - if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, *info)) { - g_free(*info); - *info =3D NULL; - return -errno; - } - - if ((*info)->argsz > argsz) { - argsz =3D (*info)->argsz; - *info =3D g_realloc(*info, argsz); - - goto retry; - } - - return 0; -} - struct vfio_info_cap_header * vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t= id) { @@ -335,158 +187,3 @@ retry: =20 return info; } - -int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, - uint32_t subtype, struct vfio_region_info **i= nfo) -{ - int i; - - for (i =3D 0; i < vbasedev->num_regions; i++) { - struct vfio_info_cap_header *hdr; - struct vfio_region_info_cap_type *cap_type; - - if (vfio_get_region_info(vbasedev, i, info)) { - continue; - } - - hdr =3D vfio_get_region_info_cap(*info, VFIO_REGION_INFO_CAP_TYPE); - if (!hdr) { - g_free(*info); - continue; - } - - cap_type =3D container_of(hdr, struct vfio_region_info_cap_type, h= eader); - - trace_vfio_get_dev_region(vbasedev->name, i, - cap_type->type, cap_type->subtype); - - if (cap_type->type =3D=3D type && cap_type->subtype =3D=3D subtype= ) { - return 0; - } - - g_free(*info); - } - - *info =3D NULL; - return -ENODEV; -} - -bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe) -{ - g_autofree struct vfio_region_info *info =3D NULL; - bool ret =3D false; - - if (!vfio_get_region_info(vbasedev, region, &info)) { - if (vfio_get_region_info_cap(info, cap_type)) { - ret =3D true; - } - } - - return ret; -} - -bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp) -{ - ERRP_GUARD(); - struct stat st; - - if (vbasedev->fd < 0) { - if (stat(vbasedev->sysfsdev, &st) < 0) { - error_setg_errno(errp, errno, "no such host device"); - error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev); - return false; - } - /* User may specify a name, e.g: VFIO platform device */ - if (!vbasedev->name) { - vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); - } - } else { - if (!vbasedev->iommufd) { - error_setg(errp, "Use FD passing only with iommufd backend"); - return false; - } - /* - * Give a name with fd so any function printing out vbasedev->name - * will not break. - */ - if (!vbasedev->name) { - vbasedev->name =3D g_strdup_printf("VFIO_FD%d", vbasedev->fd); - } - } - - return true; -} - -void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) -{ - ERRP_GUARD(); - int fd =3D monitor_fd_param(monitor_cur(), str, errp); - - if (fd < 0) { - error_prepend(errp, "Could not parse remote object fd %s:", str); - return; - } - vbasedev->fd =3D fd; -} - -void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, - DeviceState *dev, bool ram_discard) -{ - vbasedev->type =3D type; - vbasedev->ops =3D ops; - vbasedev->dev =3D dev; - vbasedev->fd =3D -1; - - vbasedev->ram_block_discard_allowed =3D ram_discard; -} - -int vfio_device_get_aw_bits(VFIODevice *vdev) -{ - /* - * iova_ranges is a sorted list. For old kernels that support - * VFIO but not support query of iova ranges, iova_ranges is NULL, - * in this case HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX(64) is returned. - */ - GList *l =3D g_list_last(vdev->bcontainer->iova_ranges); - - if (l) { - Range *range =3D l->data; - return range_get_last_bit(range) + 1; - } - - 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); -} - -bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp) -{ - HostIOMMUDevice *hiod =3D vbasedev->hiod; - - if (!hiod) { - return true; - } - - return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp= ); -} - -VFIODevice *vfio_get_vfio_device(Object *obj) -{ - if (object_dynamic_cast(obj, TYPE_VFIO_PCI)) { - return &VFIO_PCI(obj)->vbasedev; - } else { - return NULL; - } -} diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 21795b3d19e5db0c93993c0cb4a951a70d260f10..60caa366175edee6bc69c0febeb= aef84e752e346 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -20,6 +20,7 @@ system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('= calxeda-xgmac.c')) system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c')) system_ss.add(when: 'CONFIG_VFIO', if_true: files( 'container-base.c', + 'device.c', 'migration.c', 'migration-multifd.c', 'cpr.c', diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 81f4130100c48012c15b5b4858446149a7eaf5b6..590d9674cf7bc47171516082aba= f398dda72b86d 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -105,7 +105,6 @@ vfio_disconnect_container(int fd) "close container->fd= =3D%d" vfio_put_group(int fd) "close group->fd=3D%d" vfio_get_device(const char * name, unsigned int flags, unsigned int num_re= gions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u" vfio_put_base_device(int fd) "close vdev->fd=3D%d" -vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%08x" vfio_legacy_dma_unmap_overflow_workaround(void) "" vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 @@ -194,3 +193,6 @@ iommufd_cdev_fail_attach_existing_container(const char = *msg) " %s" iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=3D%d] new IOM= MUFD container with ioasid=3D%d" iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int num_regi= ons, int flags) " %s (%d) num_irqs=3D%d num_regions=3D%d flags=3D%d" iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int = function, int dev_id) "\t%04x:%02x:%02x.%x devid %d" + +# device.c +vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%08x" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745570985; cv=none; d=zohomail.com; s=zohoarc; b=FgwmWNjwt7lAcJJpWZ0ai9tgWvtFbJ/Apt6g0UPE26p7oh2xiOh2Lu9JF6NV8p+tyAJciPHPzSmYy0Q/8EWH/R/C1gbKgzur4AFhhi37gsijJyyh04Glsw0OVgsHhswYFpAylMnTM2E/atdQ6/bPMmGO6CX/KAHKUAWIpFT2WaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745570985; 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=MJvgmNFEoYpPlarzHxNwwFp3mPzZ439qDYCDrXnxmVg=; b=luHG2ad1yp/BXufjhusZZXewv/Ck3VERYBCMM8dUkONvYZtf3sDXFU8cEXKeqVuAxQkYZ1Klg1BlGdPzCSDSjeLp4ozgGp85qezbMLIjQnVPMAaM3exQ7634CbYoZvFLrUNjjKaIl/hm/c3QwLWpQUNMSIPmqX2SGvbPaSCVdMM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745570985041783.0124772985936; Fri, 25 Apr 2025 01:49:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejd-00044N-Q3; Fri, 25 Apr 2025 04:48:38 -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 1u8EjM-0003W6-98 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:21 -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 1u8EjK-0003HV-8H for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:19 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-PVfAltzcPsmolGv-00RHpA-1; Fri, 25 Apr 2025 04:48:14 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F9F4180036E; Fri, 25 Apr 2025 08:48:13 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8121830001A2; Fri, 25 Apr 2025 08:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570897; 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=MJvgmNFEoYpPlarzHxNwwFp3mPzZ439qDYCDrXnxmVg=; b=iNl+eaCNh4bqzI1fZtNRmWwVGw0owEVfV/6AJs+n7qdIxFCO3dImoVS9GEbexXfeo9oYqL gfjN2k+rmCoCO1PGrDPA2QeSY5ZMJv5h/Wq0YDoemDSOqyUVAsooJ6gj/1cHlASHYtyAXA rNiYzGfZHbLai646pbwnaHsH/23QrRY= X-MC-Unique: PVfAltzcPsmolGv-00RHpA-1 X-Mimecast-MFC-AGG-ID: PVfAltzcPsmolGv-00RHpA_1745570893 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Steve Sistare Subject: [PULL 25/50] vfio: Introduce new files for CPR definitions and declarations Date: Fri, 25 Apr 2025 10:46:18 +0200 Message-ID: <20250425084644.102196-26-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745570986238019000 Gather all CPR related declarations into "vfio-cpr.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". These were introduced in commit d9fa4223b30a ("vfio: register container for cpr"). Order file list in meson.build while at it. Cc: Steve Sistare Reviewed-by: Steve Sistare Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-22-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-cpr.h | 15 +++++++++++++++ include/hw/vfio/vfio-common.h | 3 --- hw/vfio/container.c | 1 + hw/vfio/cpr.c | 1 + hw/vfio/iommufd.c | 1 + hw/vfio/meson.build | 2 +- 6 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 hw/vfio/vfio-cpr.h diff --git a/hw/vfio/vfio-cpr.h b/hw/vfio/vfio-cpr.h new file mode 100644 index 0000000000000000000000000000000000000000..134b83a62461cbe9409bbe42057= fb4134d84dcd1 --- /dev/null +++ b/hw/vfio/vfio-cpr.h @@ -0,0 +1,15 @@ +/* + * VFIO CPR + * + * Copyright (c) 2025 Oracle and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_CPR_H +#define HW_VFIO_CPR_H + +bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); +void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); + +#endif /* HW_VFIO_CPR_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index dca7a6a4b3dcc583eb430b8cf9380a007623ec26..2065c2f9e409b27a4c8f7e0d0d3= 340c6636c5fa2 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -129,9 +129,6 @@ bool vfio_attach_device(char *name, VFIODevice *vbasede= v, void vfio_detach_device(VFIODevice *vbasedev); VFIODevice *vfio_get_vfio_device(Object *obj); =20 -bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); -void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); - typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 3fdd5dac379bd43fdd8f606e02029c1f44bdb69a..c55fe8e4bede9d7e228af247224= 2efb48bc7d037 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -34,6 +34,7 @@ #include "pci.h" #include "hw/vfio/vfio-container.h" #include "vfio-helpers.h" +#include "vfio-cpr.h" =20 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" =20 diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 3d1c8d290a5e6b6d67e244931a9ef8c194a0b574..696987006b853227e76caedb3c7= f4e4be31cfa06 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -10,6 +10,7 @@ #include "migration/misc.h" #include "qapi/error.h" #include "system/runstate.h" +#include "vfio-cpr.h" =20 static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e, Error **errp) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 85b5a8146ac401af6be8109c28ea4c7a39e84521..a5bd189a86d70bd11ecb80384ac= 145a51979322b 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -27,6 +27,7 @@ #include "pci.h" #include "vfio-iommufd.h" #include "vfio-helpers.h" +#include "vfio-cpr.h" =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 60caa366175edee6bc69c0febebaef84e752e346..1f89bd28c13dea55bcfff476ce9= 9d51b453d8533 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -20,10 +20,10 @@ system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files= ('calxeda-xgmac.c')) system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c')) system_ss.add(when: 'CONFIG_VFIO', if_true: files( 'container-base.c', + 'cpr.c', 'device.c', 'migration.c', 'migration-multifd.c', - 'cpr.c', 'region.c', )) system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files( --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571191; cv=none; d=zohomail.com; s=zohoarc; b=S6FC6YSglhkeb2Z9msv2CnAHklwVdOGEFPGJtfDAAZA5XWx2geZaZaJ75OmR/Z7Z4PmxKTab4gi7g9lbobR5+94Jd54d3nklY/9qN4+iw4wxr3lTpkD2AGewpZB5AzNb46PyLP1a+lhSYkbytRy5PxLFsvePEOVBm0/nyxOcefY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571191; 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=TLZSUJBhoIXxYbxQyf5Khkubcy7Pz4EtiVYqPi92EZ0=; b=VDPKI10cKUZGzJoX+QwXvK3QvJcUoniGCl3nFxqYAAspRNi10QSjD7wGSAEG1BDlefDe9Aht+NIYGM/D+6F1RzAuZc+zB4vz0y5s+Perye8aDOjkLvjHI3nyQeEfSwXg3RWREjVyp5Cdm9+HKwIJ89ioCTQkDs0VD2wHf8OlMvI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571191986320.556661218695; Fri, 25 Apr 2025 01:53:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Eji-0004d2-Oq; Fri, 25 Apr 2025 04:48:43 -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 1u8EjS-0003c5-NS for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EjQ-0003I2-Gb for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:26 -0400 Received: from mx-prod-mc-01.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-411-Qr8QTlLgPkSQBa4cGonTMg-1; Fri, 25 Apr 2025 04:48:18 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D713B1956094; Fri, 25 Apr 2025 08:48:17 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B68C630001A2; Fri, 25 Apr 2025 08:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570902; 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=TLZSUJBhoIXxYbxQyf5Khkubcy7Pz4EtiVYqPi92EZ0=; b=NMG6L7OzWUeto4D38u0PFOT6vtU0Ftht2i2T09SPSwsF+zcZj0quLrVmhWIjA5USzmCDFt SWUBNZmIjD3gJoq1Zb5gIeeJ5wzxex9KY2dGgUdXUO2+2on47UrWfKJpYbcFi/vHf6pE1H jjf7v2RPPtKpjL+nbFP1f9OI8iar8QY= X-MC-Unique: Qr8QTlLgPkSQBa4cGonTMg-1 X-Mimecast-MFC-AGG-ID: Qr8QTlLgPkSQBa4cGonTMg_1745570898 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 26/50] vfio: Move vfio_kvm_device_fd() into helpers.c Date: Fri, 25 Apr 2025 10:46:19 +0200 Message-ID: <20250425084644.102196-27-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571192703019000 The vfio_kvm_device_add/del_fd() routines opening the VFIO pseudo device are defined in "helpers.c". Move 'vfio_kvm_device_fd' definition there and its declaration into "vfio-helpers.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-22-clg@redha= t.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-23-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-helpers.h | 2 ++ include/hw/vfio/vfio-common.h | 1 - hw/vfio/common.c | 11 ----------- hw/vfio/helpers.c | 11 +++++++++++ hw/vfio/spapr.c | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/vfio/vfio-helpers.h b/hw/vfio/vfio-helpers.h index dbcb68bbb0e12607f5ccf15f114530966c2cbcb2..54a327ffbc04a2df364fdd78bd9= 7fe7e2065b38c 100644 --- a/hw/vfio/vfio-helpers.h +++ b/hw/vfio/vfio-helpers.h @@ -12,6 +12,8 @@ #ifdef CONFIG_LINUX #include =20 +extern int vfio_kvm_device_fd; + struct vfio_info_cap_header * vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id); struct vfio_info_cap_header * diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 2065c2f9e409b27a4c8f7e0d0d3340c6636c5fa2..06178cf2828bdeb5e4881b6b3e2= f67708a6df218 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -132,7 +132,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj); typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; extern VFIODeviceList vfio_device_list; extern const MemoryListener vfio_memory_listener; -extern int vfio_kvm_device_fd; =20 #ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index, diff --git a/hw/vfio/common.c b/hw/vfio/common.c index f80c0ef229c867070593f6a6f53e7ea1a701cf41..84a9a37d9d26cf24b7ea9e07ac0= 40c0dc283a5ba 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -49,17 +49,6 @@ VFIODeviceList vfio_device_list =3D QLIST_HEAD_INITIALIZER(vfio_device_list); =20 -#ifdef CONFIG_KVM -/* - * We have a single VFIO pseudo device per KVM VM. Once created it lives - * for the life of the VM. Closing the file descriptor only drops our - * reference to it and the device's reference to kvm. Therefore once - * initialized, this file descriptor is only released on QEMU exit and - * we'll re-use it should another vfio device be attached before then. - */ -int vfio_kvm_device_fd =3D -1; -#endif - /* * Device state interfaces */ diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 7ddc9797ef7659035d927e40a3b99a8f74dca2de..48bd61d5280967dffa509dcbaee= ee7a1ba01335a 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -106,6 +106,17 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_i= nfo *info, return true; } =20 +#ifdef CONFIG_KVM +/* + * We have a single VFIO pseudo device per KVM VM. Once created it lives + * for the life of the VM. Closing the file descriptor only drops our + * reference to it and the device's reference to kvm. Therefore once + * initialized, this file descriptor is only released on QEMU exit and + * we'll re-use it should another vfio device be attached before then. + */ +int vfio_kvm_device_fd =3D -1; +#endif + int vfio_kvm_device_add_fd(int fd, Error **errp) { #ifdef CONFIG_KVM diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 31e4dddc9e2707b18ebaf3e744d85009e635f172..95ccbad4181ec826c8ff7490b6e= 023a78710f297 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -15,13 +15,13 @@ #include "system/hostmem.h" #include "system/address-spaces.h" =20 -#include "hw/vfio/vfio-common.h" #include "hw/vfio/vfio-container.h" #include "hw/hw.h" #include "system/ram_addr.h" #include "qemu/error-report.h" #include "qapi/error.h" #include "trace.h" +#include "vfio-helpers.h" =20 typedef struct VFIOHostDMAWindow { hwaddr min_iova; --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571024; cv=none; d=zohomail.com; s=zohoarc; b=MWx9onMAt8CGKQXmlv7nCigfmu7hEYq8ltr6w0+8xpBqKZwo/dmu9UX4omYLC/QBvauOhXNDOJZCq/zj8NTSkk0V4Y+oMl4DBFv8pTvF61bRa6Y/gei1MdkXnvZ8coBPnB2kG+tjfEIZv1S+TDVbK2fr5n+ita06w53vEnK++Sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571024; 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=BQ6Iko316aU9dgLUgWTvTp05t9T/xV/1GFOCXAOahLw=; b=LpSKWm4eKbPP3rWyG9XJ18Li6+dI06Zt9KddHSe4QGI9O31tPhjR2cpFKUL2Sn+LyUipWl7VyLmUPA3WJaq8+eO/g/m8LzB7WqKxrePB3SYq052S7mMk0+8GwloU6z1qcv0hE22oLXrKjrpq5Ziz4KNzYtnDBwmkVB/8P52cFZg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571024272984.6500687756641; Fri, 25 Apr 2025 01:50:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejh-0004VP-Pg; Fri, 25 Apr 2025 04:48:41 -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 1u8EjU-0003ha-8J for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EjR-0003IE-S5 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:27 -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-13-Y3gwWnsEPjyZr-ZhRMhOPA-1; Fri, 25 Apr 2025 04:48:22 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 3866219560A2; Fri, 25 Apr 2025 08:48:21 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3450E30001A2; Fri, 25 Apr 2025 08:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570904; 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=BQ6Iko316aU9dgLUgWTvTp05t9T/xV/1GFOCXAOahLw=; b=eOI7tYA76vIbOUXVUcEKOXHo7EdhEAzZcuAbtkq9/9PSanzZawFt+hOv9yueHLUPhE+arQ l4S7WXuBBsLV7X6eGahoV2wJnGCxjow+sJNFwDMcRV+ezCy5usTQashUUXKMDvgSREkz3P kGh3K28orj+PMFIC/x5Rth7ku+gV5Pk= X-MC-Unique: Y3gwWnsEPjyZr-ZhRMhOPA-1 X-Mimecast-MFC-AGG-ID: Y3gwWnsEPjyZr-ZhRMhOPA_1745570901 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 27/50] vfio: Move vfio_device_list into device.c Date: Fri, 25 Apr 2025 10:46:20 +0200 Message-ID: <20250425084644.102196-28-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571025098019100 'vfio_device_list' is VFIODevice related. Move its definitions into "device.c". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-23-clg@redha= t.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-24-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 3 --- hw/vfio/device.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 84a9a37d9d26cf24b7ea9e07ac040c0dc283a5ba..4e7d8e83ac72050f874e56143a9= a4bc4527b0bda 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -46,9 +46,6 @@ #include "vfio-migration-internal.h" #include "vfio-helpers.h" =20 -VFIODeviceList vfio_device_list =3D - QLIST_HEAD_INITIALIZER(vfio_device_list); - /* * Device state interfaces */ diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 21c6824430c49170b8d1b9a69ff51272f48096a4..25fdba10a882e35392f26a10750= 9f80e4b1c880a 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -31,6 +31,9 @@ #include "monitor/monitor.h" #include "vfio-helpers.h" =20 +VFIODeviceList vfio_device_list =3D + QLIST_HEAD_INITIALIZER(vfio_device_list); + /* * Common VFIO interrupt disable */ --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571053; cv=none; d=zohomail.com; s=zohoarc; b=NeaO6Dg73rPdrdOtrHd5WbazvF7pO88BCoNWOrsCojyvq+oeyCpNPW4iQWzM47g8Z5c2pzqFm3UCOBoJmeBoC7Ug3siccosTEbaHkVR1jcwLtxRFEzYor6KaQHAkSp+N+IBIXqLMtveaxkEsnGlikJFnGZUhmvJAwG0uCLRXMlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571053; 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=saVfaofs99sOvnyICh6ln/o6vjtI9t3VHofWTVv66AY=; b=I5T7o1jy6edEE9sRfFkqCWhteSQFSwURJXVkJEYlZNLy9RMTMng6om6iRs3K4xRs0nNo9PDLk8ilcY2Xwg4UsNstUP6CkjksfRsc+4SReHWOUt+l4baCdvWltH04pc5+kD0xoJCLgyPF4fSZnNl74J/aK/rSt0wlq6+UnEIWShY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571053884448.51565773737593; Fri, 25 Apr 2025 01:50:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejk-0004k2-D3; Fri, 25 Apr 2025 04:48: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 1u8EjV-0003jn-Fp for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EjT-0003IS-EA for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:29 -0400 Received: from mx-prod-mc-04.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-133-YwO7L9KnNIWGtEpOJrO2ig-1; Fri, 25 Apr 2025 04:48:24 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 78CAD1955DC5; Fri, 25 Apr 2025 08:48:23 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 95CFD30001A2; Fri, 25 Apr 2025 08:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570906; 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=saVfaofs99sOvnyICh6ln/o6vjtI9t3VHofWTVv66AY=; b=KiC5wh+LC+yDnfnwiqmtUp6V8h+H7QP918KD/oUrFRs4lEZSGrbzStJ/umw+OpIgH12569 Uak3gadaw6qeGT3uBZMSl9c8i3MduCU2XlkU/GaPL8RaZHqNmuEGnvh2tk3Ib01ny78+XG aXTXo/ZtPLW6YMTIqDJiVRP5Cd3y58o= X-MC-Unique: YwO7L9KnNIWGtEpOJrO2ig-1 X-Mimecast-MFC-AGG-ID: YwO7L9KnNIWGtEpOJrO2ig_1745570903 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 28/50] vfio: Move vfio_de/attach_device() into device.c Date: Fri, 25 Apr 2025 10:46:21 +0200 Message-ID: <20250425084644.102196-29-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571057146019100 These routines are VFIODevice related. Move their definitions into "device.c". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-24-clg@redha= t.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-25-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 37 ------------------------------------- hw/vfio/device.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 4e7d8e83ac72050f874e56143a9a4bc4527b0bda..a85ed364090f6676cbbc9b513f6= afbf26b5a894b 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1318,40 +1318,3 @@ void vfio_reset_handler(void *opaque) } } } - -bool vfio_attach_device(char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp) -{ - const VFIOIOMMUClass *ops =3D - VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); - HostIOMMUDevice *hiod =3D NULL; - - if (vbasedev->iommufd) { - ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMM= UFD)); - } - - assert(ops); - - - if (!vbasedev->mdev) { - hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); - vbasedev->hiod =3D hiod; - } - - if (!ops->attach_device(name, vbasedev, as, errp)) { - object_unref(hiod); - vbasedev->hiod =3D NULL; - return false; - } - - return true; -} - -void vfio_detach_device(VFIODevice *vbasedev) -{ - if (!vbasedev->bcontainer) { - return; - } - object_unref(vbasedev->hiod); - VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev); -} diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 25fdba10a882e35392f26a107509f80e4b1c880a..179c9fb8decc42dcd8d1b4fe10e= 7acaa2a6f2c7c 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -331,3 +331,40 @@ VFIODevice *vfio_get_vfio_device(Object *obj) return NULL; } } + +bool vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) +{ + const VFIOIOMMUClass *ops =3D + VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); + HostIOMMUDevice *hiod =3D NULL; + + if (vbasedev->iommufd) { + ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMM= UFD)); + } + + assert(ops); + + + if (!vbasedev->mdev) { + hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); + vbasedev->hiod =3D hiod; + } + + if (!ops->attach_device(name, vbasedev, as, errp)) { + object_unref(hiod); + vbasedev->hiod =3D NULL; + return false; + } + + return true; +} + +void vfio_detach_device(VFIODevice *vbasedev) +{ + if (!vbasedev->bcontainer) { + return; + } + object_unref(vbasedev->hiod); + VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev); +} --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571333; cv=none; d=zohomail.com; s=zohoarc; b=Y+n4TfsLugYYujjR85B/wVLnQXk6HnSJiJ+vC+CIxyBG3ymltCzorYCF+YkFwc8ub5HP4M0j7KQFM+kxyyRDi8laMgnr0nuVfRhDpVhJR7VJDvaiEeQm9+CWJ7KRCDI4FT2AfuQD8roVwb6giE9k5A5KhgYZB4EANpVHdcXlDGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571333; 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=JuyI2BP2Uw5ICAcdUFrJFyVDVLPFvBreXiY90oKENKo=; b=bbtq5wulMYWYsU5BXLojLX52Yy53IS/Fis3+P14AnMJgvZOuBp0ivNndFneQRRUsDjjbMXvoODQc3mdX/AYxNW9Qu1uJjjwl+JSDCNi1aEGpD5cGEEiOXR6stBh5yRqVqA2XYX5PS5Vp93sVgu6qykURvn6QnaAguDC8NOpNmfI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571333242245.13200395205251; Fri, 25 Apr 2025 01:55:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejf-0004JU-FW; Fri, 25 Apr 2025 04:48: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 1u8EjX-0003ss-CL for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:31 -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 1u8EjU-0003Im-Ue for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:30 -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-86-8IJjDR2-NxC7JaPsctzZ8g-1; Fri, 25 Apr 2025 04:48:26 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 F21631956089; Fri, 25 Apr 2025 08:48:25 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0017630001A2; Fri, 25 Apr 2025 08:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570908; 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=JuyI2BP2Uw5ICAcdUFrJFyVDVLPFvBreXiY90oKENKo=; b=I07MxPa4xT/130dKtOQceYSHnnNAihfsIxlHq4Q7tLgCaZMaU5ClIGLQnS3WBrlwb56vKI n+OlEENFlrvLYk1QQikTHIyA0FPs8JRynfNvuu5Sosir9Yatp5iNTb/GJ+gMRPmrXXuyeC GsEO6F9gS86ykbeipK+vl9V5yjqfuug= X-MC-Unique: 8IJjDR2-NxC7JaPsctzZ8g-1 X-Mimecast-MFC-AGG-ID: 8IJjDR2-NxC7JaPsctzZ8g_1745570906 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , John Levon Subject: [PULL 29/50] vfio: Move vfio_reset_handler() into device.c Date: Fri, 25 Apr 2025 10:46:22 +0200 Message-ID: <20250425084644.102196-30-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571335276019000 Pass-through devices of a VM are not necessarily in the same group and all groups/address_spaces need to be scanned when the machine is reset. Commit f16f39c3fc97 ("Implement PCI hot reset") introduced a VM reset handler for this purpose. Move it under device.c Also reintroduce the comment which explained the context and was lost along the way. Reviewed-by: Zhenzhong Duan Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-26-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 18 ------------------ hw/vfio/device.c | 35 +++++++++++++++++++++++++++++++++++ hw/vfio/trace-events | 2 +- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index a85ed364090f6676cbbc9b513f6afbf26b5a894b..45ac8b7d8bdda391b1f8e047049= 08f2c0ef47aa8 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1300,21 +1300,3 @@ const MemoryListener vfio_memory_listener =3D { .log_global_stop =3D vfio_listener_log_global_stop, .log_sync =3D vfio_listener_log_sync, }; - -void vfio_reset_handler(void *opaque) -{ - VFIODevice *vbasedev; - - trace_vfio_reset_handler(); - QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { - if (vbasedev->dev->realized) { - vbasedev->ops->vfio_compute_needs_reset(vbasedev); - } - } - - QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { - if (vbasedev->dev->realized && vbasedev->needs_reset) { - vbasedev->ops->vfio_hot_reset_multi(vbasedev); - } - } -} diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 179c9fb8decc42dcd8d1b4fe10e7acaa2a6f2c7c..e122c797c206c285ef26c3a56d8= 41d8c3be8b58b 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -34,6 +34,41 @@ VFIODeviceList vfio_device_list =3D QLIST_HEAD_INITIALIZER(vfio_device_list); =20 +/* + * We want to differentiate hot reset of multiple in-use devices vs + * hot reset of a single in-use device. VFIO_DEVICE_RESET will already + * handle the case of doing hot resets when there is only a single + * device per bus. The in-use here refers to how many VFIODevices are + * affected. A hot reset that affects multiple devices, but only a + * single in-use device, means that we can call it from our bus + * ->reset() callback since the extent is effectively a single + * device. This allows us to make use of it in the hotplug path. When + * there are multiple in-use devices, we can only trigger the hot + * reset during a system reset and thus from our reset handler. We + * separate _one vs _multi here so that we don't overlap and do a + * double reset on the system reset path where both our reset handler + * and ->reset() callback are used. Calling _one() will only do a hot + * reset for the one in-use devices case, calling _multi() will do + * nothing if a _one() would have been sufficient. + */ +void vfio_reset_handler(void *opaque) +{ + VFIODevice *vbasedev; + + trace_vfio_reset_handler(); + QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { + if (vbasedev->dev->realized) { + vbasedev->ops->vfio_compute_needs_reset(vbasedev); + } + } + + QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { + if (vbasedev->dev->realized && vbasedev->needs_reset) { + vbasedev->ops->vfio_hot_reset_multi(vbasedev); + } + } +} + /* * Common VFIO interrupt disable */ diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 590d9674cf7bc47171516082abaf398dda72b86d..9fee7df8764978723f79dc60d3d= c796777278858 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -108,7 +108,6 @@ vfio_put_base_device(int fd) "close vdev->fd=3D%d" vfio_legacy_dma_unmap_overflow_workaround(void) "" vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 -vfio_reset_handler(void) "" =20 # region.c vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" @@ -196,3 +195,4 @@ iommufd_cdev_pci_hot_reset_dep_devices(int domain, int = bus, int slot, int functi =20 # device.c vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%08x" +vfio_reset_handler(void) "" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571354; cv=none; d=zohomail.com; s=zohoarc; b=YoYamyI/bLFZrYgAtXhxhEWi6i8DUqhYqcz45aGochhtYtxAIa/RVN1B/1oztLNoKLbm5AhhpjANk3EappJGWG0MZI0avofgJlQHMR4bcWy5DGoZZ7vqjmIQMK0/CtBT2KYyb0/vgktX7Jd4su1GYbxYkOKFFK31GCScLxdnAcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571354; 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=NZKksoeGPtA0x0TVLG+fslSMScBsvNvXl+GKLyJ6Rgg=; b=Cz7pkLWtdXx2FNOMnOQ5Mwdox7YbbDseBb9ODFi8ckIlqP1PbMjJRIi5hlSV2sEf+HQUOIWyLNkbq8qtjjxN671RwbnRUocVqJIgbfQZt1ry04wkTQbdSw7jAZ9vsZNafYGVjzE7e/YnWwMezegpKxOMpjAdbWLR9Eaaz55VdBE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571354357691.8991819706796; Fri, 25 Apr 2025 01:55:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejr-0005K0-Pi; Fri, 25 Apr 2025 04:48:52 -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 1u8Ejj-0004kH-RN for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:44 -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 1u8Ejg-0003JH-Vh for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:43 -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-562-Al44SyVGNLGATDeVJBWqhw-1; Fri, 25 Apr 2025 04:48:31 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 0217E1956087; Fri, 25 Apr 2025 08:48:29 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BF7030001A2; Fri, 25 Apr 2025 08:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570920; 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=NZKksoeGPtA0x0TVLG+fslSMScBsvNvXl+GKLyJ6Rgg=; b=dYMyt/aySPIN69tVI3Zk8JWQG25S++Bei2+5zLJJFBWZWoOImid7VUacPUFTkegtw+IBJT jojZpKCPebkPr8FjrqtKK/V7EP6SYRgPJXFIoWgzUVBsHBM76rdDhD2kAQutZixTj0tX0i 0xMbodVdL+Y7Izit1tlj9a5lJgfiMY4= X-MC-Unique: Al44SyVGNLGATDeVJBWqhw-1 X-Mimecast-MFC-AGG-ID: Al44SyVGNLGATDeVJBWqhw_1745570909 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , Avihai Horon Subject: [PULL 30/50] vfio: Move dirty tracking related services into container-base.c Date: Fri, 25 Apr 2025 10:46:23 +0200 Message-ID: <20250425084644.102196-31-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571355726019100 Routines of common.c : vfio_devices_all_dirty_tracking_started vfio_devices_all_device_dirty_tracking vfio_devices_query_dirty_bitmap vfio_get_dirty_bitmap are all related to dirty page tracking directly at the container level or at the container device level. Naming is a bit confusing. We will propose new names in the following changes. Reviewed-by: Joao Martins Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-27-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 9 -- include/hw/vfio/vfio-container-base.h | 7 ++ hw/vfio/common.c | 130 ------------------------ hw/vfio/container-base.c | 138 ++++++++++++++++++++++++++ hw/vfio/meson.build | 2 +- hw/vfio/trace-events | 4 +- 6 files changed, 149 insertions(+), 141 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 06178cf2828bdeb5e4881b6b3e2f67708a6df218..0dfae24b72906fa01c5003d1858= d4dc101a5012e 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -141,15 +141,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uin= t32_t type, bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe); #endif =20 -bool vfio_devices_all_dirty_tracking_started( - const VFIOContainerBase *bcontainer); -bool -vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer= ); -int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp); -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr, Error **errp= ); - /* Returns 0 on success, or a negative errno. */ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp); void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index e0c458d487b8b6fc7ec7fb17bae84b4a937e6e2c..41ca27b3f0b72929d851f2cef48= 12c7a8003f916 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -91,6 +91,13 @@ int vfio_container_set_dirty_page_tracking(VFIOContainer= Base *bcontainer, bool start, Error **errp); int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp); +bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcon= tainer); +bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer); +int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, + VFIOBitmap *vbmap, hwaddr iova, hwaddr= size, + Error **errp); +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, + uint64_t size, ram_addr_t ram_addr, Error **errp= ); =20 GList *vfio_container_get_iova_ranges(const VFIOContainerBase *bcontainer); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 45ac8b7d8bdda391b1f8e04704908f2c0ef47aa8..ed49ef88a865521e16584844721= b6ffa09427f18 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -51,27 +51,6 @@ */ =20 =20 -static bool vfio_devices_all_device_dirty_tracking_started( - const VFIOContainerBase *bcontainer) -{ - VFIODevice *vbasedev; - - QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { - if (!vbasedev->dirty_tracking) { - return false; - } - } - - return true; -} - -bool vfio_devices_all_dirty_tracking_started( - const VFIOContainerBase *bcontainer) -{ - return vfio_devices_all_device_dirty_tracking_started(bcontainer) || - bcontainer->dirty_pages_started; -} - static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer) { VFIODevice *vbasedev; @@ -96,22 +75,6 @@ static bool vfio_log_sync_needed(const VFIOContainerBase= *bcontainer) return true; } =20 -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer) -{ - VFIODevice *vbasedev; - - 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; - } - } - - return true; -} - static bool vfio_listener_skipped_section(MemoryRegionSection *section) { return (!memory_region_is_ram(section->mr) && @@ -1009,99 +972,6 @@ static void vfio_listener_log_global_stop(MemoryListe= ner *listener) } } =20 -static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iov= a, - hwaddr size, void *bitmap) -{ - uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) + - sizeof(struct vfio_device_feature_dma_logging_repo= rt), - sizeof(uint64_t))] =3D {}; - struct vfio_device_feature *feature =3D (struct vfio_device_feature *)= buf; - struct vfio_device_feature_dma_logging_report *report =3D - (struct vfio_device_feature_dma_logging_report *)feature->data; - - report->iova =3D iova; - report->length =3D size; - report->page_size =3D qemu_real_host_page_size(); - report->bitmap =3D (uintptr_t)bitmap; - - feature->argsz =3D sizeof(buf); - feature->flags =3D VFIO_DEVICE_FEATURE_GET | - VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT; - - if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { - return -errno; - } - - return 0; -} - -int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp) -{ - VFIODevice *vbasedev; - int ret; - - QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { - ret =3D vfio_device_dma_logging_report(vbasedev, iova, size, - vbmap->bitmap); - if (ret) { - error_setg_errno(errp, -ret, - "%s: Failed to get DMA logging report, iova: " - "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx, - vbasedev->name, iova, size); - - return ret; - } - } - - return 0; -} - -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr, Error **errp) -{ - bool all_device_dirty_tracking =3D - vfio_devices_all_device_dirty_tracking(bcontainer); - uint64_t dirty_pages; - VFIOBitmap vbmap; - int ret; - - if (!bcontainer->dirty_pages_supported && !all_device_dirty_tracking) { - cpu_physical_memory_set_dirty_range(ram_addr, size, - tcg_enabled() ? DIRTY_CLIENTS_= ALL : - DIRTY_CLIENTS_NOCODE); - return 0; - } - - ret =3D vfio_bitmap_alloc(&vbmap, size); - if (ret) { - error_setg_errno(errp, -ret, - "Failed to allocate dirty tracking bitmap"); - return ret; - } - - if (all_device_dirty_tracking) { - ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size, - errp); - } else { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size, - errp); - } - - if (ret) { - goto out; - } - - dirty_pages =3D cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, r= am_addr, - vbmap.pages); - - trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pa= ges); -out: - g_free(vbmap.bitmap); - - return ret; -} - typedef struct { IOMMUNotifier n; VFIOGuestIOMMU *giommu; diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 2c2d8329e3cf0f21386cb0896dd366c8d0ccdb60..f9cf317018b7ad8bfc2e013ce59= c75a100eda7de 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -10,12 +10,20 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 +#include +#include + #include "qemu/osdep.h" +#include "system/tcg.h" +#include "system/ram_addr.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "hw/vfio/vfio-container-base.h" #include "hw/vfio/vfio-common.h" /* vfio_reset_handler */ #include "system/reset.h" +#include "vfio-helpers.h" + +#include "trace.h" =20 static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =3D QLIST_HEAD_INITIALIZER(vfio_address_spaces); @@ -143,6 +151,136 @@ int vfio_container_query_dirty_bitmap(const VFIOConta= inerBase *bcontainer, errp); } =20 +static bool vfio_devices_all_device_dirty_tracking_started( + const VFIOContainerBase *bcontainer) +{ + VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { + if (!vbasedev->dirty_tracking) { + return false; + } + } + + return true; +} + +bool vfio_devices_all_dirty_tracking_started( + const VFIOContainerBase *bcontainer) +{ + return vfio_devices_all_device_dirty_tracking_started(bcontainer) || + bcontainer->dirty_pages_started; +} + +bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer) +{ + VFIODevice *vbasedev; + + 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; + } + } + + return true; +} + +static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iov= a, + hwaddr size, void *bitmap) +{ + uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) + + sizeof(struct vfio_device_feature_dma_logging_repo= rt), + sizeof(uint64_t))] =3D {}; + struct vfio_device_feature *feature =3D (struct vfio_device_feature *)= buf; + struct vfio_device_feature_dma_logging_report *report =3D + (struct vfio_device_feature_dma_logging_report *)feature->data; + + report->iova =3D iova; + report->length =3D size; + report->page_size =3D qemu_real_host_page_size(); + report->bitmap =3D (uintptr_t)bitmap; + + feature->argsz =3D sizeof(buf); + feature->flags =3D VFIO_DEVICE_FEATURE_GET | + VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT; + + if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { + return -errno; + } + + return 0; +} + +int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp) +{ + VFIODevice *vbasedev; + int ret; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { + ret =3D vfio_device_dma_logging_report(vbasedev, iova, size, + vbmap->bitmap); + if (ret) { + error_setg_errno(errp, -ret, + "%s: Failed to get DMA logging report, iova: " + "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx, + vbasedev->name, iova, size); + + return ret; + } + } + + return 0; +} + +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, + uint64_t size, ram_addr_t ram_addr, Error **errp) +{ + bool all_device_dirty_tracking =3D + vfio_devices_all_device_dirty_tracking(bcontainer); + uint64_t dirty_pages; + VFIOBitmap vbmap; + int ret; + + if (!bcontainer->dirty_pages_supported && !all_device_dirty_tracking) { + cpu_physical_memory_set_dirty_range(ram_addr, size, + tcg_enabled() ? DIRTY_CLIENTS_= ALL : + DIRTY_CLIENTS_NOCODE); + return 0; + } + + ret =3D vfio_bitmap_alloc(&vbmap, size); + if (ret) { + error_setg_errno(errp, -ret, + "Failed to allocate dirty tracking bitmap"); + return ret; + } + + if (all_device_dirty_tracking) { + ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size, + errp); + } else { + ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size, + errp); + } + + if (ret) { + goto out; + } + + dirty_pages =3D cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, r= am_addr, + vbmap.pages); + + trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pa= ges); +out: + g_free(vbmap.bitmap); + + return ret; +} + static gpointer copy_iova_range(gconstpointer src, gpointer data) { Range *source =3D (Range *)src; diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 1f89bd28c13dea55bcfff476ce99d51b453d8533..9c8a989db2d4578e97d864c5fd8= bcba125eab66a 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -1,6 +1,7 @@ vfio_ss =3D ss.source_set() vfio_ss.add(files( 'common.c', + 'container-base.c', 'container.c', 'helpers.c', )) @@ -19,7 +20,6 @@ specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss) system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c')) system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c')) system_ss.add(when: 'CONFIG_VFIO', if_true: files( - 'container-base.c', 'cpr.c', 'device.c', 'migration.c', diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 9fee7df8764978723f79dc60d3dc796777278858..d4cd09cb0f93485fe06984346f6= ac927603c5745 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -106,9 +106,11 @@ vfio_put_group(int fd) "close group->fd=3D%d" vfio_get_device(const char * name, unsigned int flags, unsigned int num_re= gions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u" vfio_put_base_device(int fd) "close vdev->fd=3D%d" vfio_legacy_dma_unmap_overflow_workaround(void) "" -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 +# container-base.c +vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 + # region.c vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint= 64_t data) " (%s:region%d+0x%"PRIx64", %d) =3D 0x%"PRIx64 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571348; cv=none; d=zohomail.com; s=zohoarc; b=bpNibHlkuVnl4p3++dnb+rA8A2FmxSvFD9WFFR1jqrd0amw3RRzSsJ5RsDpQsrQnu5C3Avp46L/jZl+awNU4av6Jiy3ojRSH7fhzwIMIo4Byl1cgNZI7BCMmjGGw5ehLrEmFnViZW/SQoVU35B9F8a2BXAzZSgrCL5dBJMNl/T0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571348; 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=5M0MOKrseCJLtuDZyx3PGAWzZBOxN8p94ydnQYQ8DJ4=; b=nrva6sJKFeVYYrTqOXyrzy4hBYF/TZkM1oU3ijAiTjDbMW+Jf/bGmeD4SwtUSRCXItXSkrgkBcCIA96ghuqpezbqCwLgBjP8xoWxTcT2A0HlaCG1RYEA0PsxQaN5cxCLDKNMXR9XxLyl1cM3VtnpfS0kJwxIA5DGnX6kt7UQh7M= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571348627447.21616459849076; Fri, 25 Apr 2025 01:55:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejm-0004vS-4p; Fri, 25 Apr 2025 04:48:46 -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 1u8Ejh-0004YY-Gx for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48: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 1u8Ejf-0003JB-5m for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:41 -0400 Received: from mx-prod-mc-01.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-128-GVUFIgGGOTabQRI5P3KLNA-1; Fri, 25 Apr 2025 04:48:33 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BD2CA195608C; Fri, 25 Apr 2025 08:48:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D07630001A2; Fri, 25 Apr 2025 08:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570917; 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=5M0MOKrseCJLtuDZyx3PGAWzZBOxN8p94ydnQYQ8DJ4=; b=TwKRvyhK/c5QnsHuh3Mhl5NFtrxHOh72aoQaIGeKglVe4uMbgPcaWb5k67L8EowHOw7Jr/ 5JcYcXnk3x7gUy5+6pdgKs8lJnP5b/PrJ8CV2r4mdzacB5TIA2fytQ3mGTGqUNn/pVi/6x ydfR5Qid30inwAK9xV708Su2qqzIkXw= X-MC-Unique: GVUFIgGGOTabQRI5P3KLNA-1 X-Mimecast-MFC-AGG-ID: GVUFIgGGOTabQRI5P3KLNA_1745570912 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon , Avihai Horon Subject: [PULL 31/50] vfio: Make vfio_devices_query_dirty_bitmap() static Date: Fri, 25 Apr 2025 10:46:24 +0200 Message-ID: <20250425084644.102196-32-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571349749019100 vfio_devices_query_dirty_bitmap() is only used in "container-base.c". Also, rename to vfio_container_devices_query_dirty_bitmap() to reflect with the prefix 'vfio_container_devices_' that it simply loops over the container's device list. Reviewed-by: Joao Martins Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-28-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 3 --- hw/vfio/container-base.c | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 41ca27b3f0b72929d851f2cef4812c7a8003f916..60975194a3bdb911b06d5816bcf= e4bdd9c946445 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -93,9 +93,6 @@ int vfio_container_query_dirty_bitmap(const VFIOContainer= Base *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp); bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcon= tainer); bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer); -int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr= size, - Error **errp); int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, uint64_t size, ram_addr_t ram_addr, Error **errp= ); =20 diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index f9cf317018b7ad8bfc2e013ce59c75a100eda7de..eb7ab8461e34d4a47e810bd607d= cde4e77314959 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -214,7 +214,7 @@ static int vfio_device_dma_logging_report(VFIODevice *v= basedev, hwaddr iova, return 0; } =20 -int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, +static int vfio_container_devices_query_dirty_bitmap(const VFIOContainerBa= se *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp) { VFIODevice *vbasedev; @@ -260,8 +260,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcon= tainer, uint64_t iova, } =20 if (all_device_dirty_tracking) { - ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size, - errp); + ret =3D vfio_container_devices_query_dirty_bitmap(bcontainer, &vbm= ap, iova, size, + errp); } else { ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size, errp); --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571357; cv=none; d=zohomail.com; s=zohoarc; b=YILPGT2nmA33oBdEvHt9R7F3oN3aSHXCOfI3Lu+95AdimDBdK6kqxNWtDKTvewK7h1maagTs+HmVdiqRWngQPD+Dilz9iAMIW7OZl56rMAjP2jnpaGow/UOVFwhpuil9uhgc78NBfaVPIvFC7qQfzJA3ajKytGYvLa5yBc0aw08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571357; 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=JgcXIo0J1CjwfiJNfxR0gjhTwNBc70YEky+ixZ0qS4M=; b=gh9pCl99o6e9/IDs8/PCHNmUDArbflw/Q2QKtlCxQYQ1YEMKpmcAYvp7k2jZL8nPa13DEOKRtuHYKSBiKFmuk5S4rhOlqD7t1j0COBEcU1MPRHK18fzDqihjpqslJF5R828bOGmk0ppfBgrEpiZRnRb5sSpVDeIN6E2utgGkUX8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571357492355.37588057452615; Fri, 25 Apr 2025 01:55:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejq-0005FU-HQ; Fri, 25 Apr 2025 04:48:50 -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 1u8Ejm-0004xQ-3g for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Ejj-0003JU-Ua for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:45 -0400 Received: from mx-prod-mc-05.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-615-pFyBi_DVMi6oZ854GVguvA-1; Fri, 25 Apr 2025 04:48:36 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 730F8195609D; Fri, 25 Apr 2025 08:48:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2B0DC30001A2; Fri, 25 Apr 2025 08:48:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570922; 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=JgcXIo0J1CjwfiJNfxR0gjhTwNBc70YEky+ixZ0qS4M=; b=aj4aUY6Im8FBB8Xmp3c94oGS/ihu6iZtz25QyNzxDGmEnSz2NqK2oPx+awGDF9xIEJTIMa i3PdypelAerW639HZ4pg7hMlYuBx8KiM3RhvXIK7IVtRwn+dTDaGkS7/lsdRp6NLHuHXHd p5M4mVYNBUVAHTdvZ9RaSXA0t0ug0D0= X-MC-Unique: pFyBi_DVMi6oZ854GVguvA-1 X-Mimecast-MFC-AGG-ID: pFyBi_DVMi6oZ854GVguvA_1745570915 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon , Avihai Horon Subject: [PULL 32/50] vfio: Make vfio_container_query_dirty_bitmap() static Date: Fri, 25 Apr 2025 10:46:25 +0200 Message-ID: <20250425084644.102196-33-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571359790019100 vfio_container_query_dirty_bitmap() is only used in "container-base.c". Also, rename to vfio_container_iommu_query_dirty_bitmap() to reflect it is using the VFIO IOMMU backend device ->query_dirty_bitmap() handler. Reviewed-by: Joao Martins Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-29-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 2 -- hw/vfio/container-base.c | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 60975194a3bdb911b06d5816bcfe4bdd9c946445..69fb698bc19a693de92d3610974= 13557e3cc2b62 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -89,8 +89,6 @@ void vfio_container_del_section_window(VFIOContainerBase = *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp); -int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp); bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcon= tainer); bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer); int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index eb7ab8461e34d4a47e810bd607dcde4e77314959..3c8039d52aa1838ca942a7ac29e= bbd61fa074e67 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -141,16 +141,6 @@ int vfio_container_set_dirty_page_tracking(VFIOContain= erBase *bcontainer, return ret; } =20 -int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp) -{ - VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); - - g_assert(vioc->query_dirty_bitmap); - return vioc->query_dirty_bitmap(bcontainer, vbmap, iova, size, - errp); -} - static bool vfio_devices_all_device_dirty_tracking_started( const VFIOContainerBase *bcontainer) { @@ -214,6 +204,16 @@ static int vfio_device_dma_logging_report(VFIODevice *= vbasedev, hwaddr iova, return 0; } =20 +static int vfio_container_iommu_query_dirty_bitmap(const VFIOContainerBase= *bcontainer, + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp) +{ + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + + g_assert(vioc->query_dirty_bitmap); + return vioc->query_dirty_bitmap(bcontainer, vbmap, iova, size, + errp); +} + static int vfio_container_devices_query_dirty_bitmap(const VFIOContainerBa= se *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp) { @@ -263,8 +263,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcon= tainer, uint64_t iova, ret =3D vfio_container_devices_query_dirty_bitmap(bcontainer, &vbm= ap, iova, size, errp); } else { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size, - errp); + ret =3D vfio_container_iommu_query_dirty_bitmap(bcontainer, &vbmap= , iova, size, + errp); } =20 if (ret) { --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571242; cv=none; d=zohomail.com; s=zohoarc; b=iKGU+/GxWK7aZAeYA+uI8sUIxYbgLV1QqF0/Ih392qwY/vWpMZwzWRP/3DJ3cPHsvJ52LHInYU0AGtYZJDrs/j90jPgxfTAY1qjInXockW+1N9tyNxvFDWrTs1IFbKULLRumYAcgHkVHF0q+W9q0XW/zKBaLOfMPUao+FhUTwDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571242; 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=8prw8ArUl08z4p7fMvLq1bYbVkoyHkBoERWS4TBqkVk=; b=ZKXOG3Pm1radeQqkasuCZN1MfjAa62Ro3yhy7YGpYQp+imeNxWVMPyXGuX5A/ghMAEbHmL12hlpsPvAmbvo/rt6AqMW4tYnK+yibH4hEc89wVt52JixHYdZI/s5Jm3MpOq8YWv4GxG+l9mVQQ4DSJmoGO8B7sNgQDhQJpd881sU= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571242962770.7067796135584; Fri, 25 Apr 2025 01:54:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejv-0005Za-HX; Fri, 25 Apr 2025 04:48:55 -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 1u8Ejo-00059Z-9J for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:48 -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 1u8Ejm-0003Ji-AH for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:47 -0400 Received: from mx-prod-mc-04.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-516-Wcxcg3mEOGCoGcl-NLjkJw-1; Fri, 25 Apr 2025 04:48:39 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 629FA1954B0D; Fri, 25 Apr 2025 08:48:38 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C08730001A2; Fri, 25 Apr 2025 08:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570925; 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=8prw8ArUl08z4p7fMvLq1bYbVkoyHkBoERWS4TBqkVk=; b=JLTljBd81ZHmJSBVxRhS33wgp2yvD44ngUIvtf3t1dq3f2FKtGnaB65sc88xKIayWw++Gz yDrCvkcNVdXlFip4gnbg34fPpI6HRc2zeu7pE5zGfAbvbBvbzYnXkTNwlBxdbDhNHltA+w iNBcaJ69sN1z61Hojp9uzsc3IpvKiOw= X-MC-Unique: Wcxcg3mEOGCoGcl-NLjkJw-1 X-Mimecast-MFC-AGG-ID: Wcxcg3mEOGCoGcl-NLjkJw_1745570918 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon , Avihai Horon Subject: [PULL 33/50] vfio: Rename vfio_devices_all_dirty_tracking_started() Date: Fri, 25 Apr 2025 10:46:26 +0200 Message-ID: <20250425084644.102196-34-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571244926019000 Also rename vfio_devices_all_device_dirty_tracking_started() while at it and use the prefix 'vfio_container_devices_' for routines simply looping over the container's device list. Reviewed-by: Joao Martins Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-30-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 3 ++- hw/vfio/common.c | 2 +- hw/vfio/container-base.c | 6 +++--- hw/vfio/container.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 69fb698bc19a693de92d361097413557e3cc2b62..9b33e71f59bba1f3cbe10c30717= 2422ca4e4c2ce 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -89,7 +89,8 @@ void vfio_container_del_section_window(VFIOContainerBase = *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp); -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcon= tainer); +bool vfio_container_dirty_tracking_is_started( + const VFIOContainerBase *bcontainer); bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer); int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, uint64_t size, ram_addr_t ram_addr, Error **errp= ); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ed49ef88a865521e16584844721b6ffa09427f18..89b7a71385abfff888c5208a6b4= c588b4217716a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -55,7 +55,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase = *bcontainer) { VFIODevice *vbasedev; =20 - if (!vfio_devices_all_dirty_tracking_started(bcontainer)) { + if (!vfio_container_dirty_tracking_is_started(bcontainer)) { return false; } =20 diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 3c8039d52aa1838ca942a7ac29ebbd61fa074e67..1beba37a7739d76630c3e7db16a= 8d04926cb1aee 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -141,7 +141,7 @@ int vfio_container_set_dirty_page_tracking(VFIOContaine= rBase *bcontainer, return ret; } =20 -static bool vfio_devices_all_device_dirty_tracking_started( +static bool vfio_container_devices_dirty_tracking_is_started( const VFIOContainerBase *bcontainer) { VFIODevice *vbasedev; @@ -155,10 +155,10 @@ static bool vfio_devices_all_device_dirty_tracking_st= arted( return true; } =20 -bool vfio_devices_all_dirty_tracking_started( +bool vfio_container_dirty_tracking_is_started( const VFIOContainerBase *bcontainer) { - return vfio_devices_all_device_dirty_tracking_started(bcontainer) || + return vfio_container_devices_dirty_tracking_is_started(bcontainer) || bcontainer->dirty_pages_started; } =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index c55fe8e4bede9d7e228af2472242efb48bc7d037..e8cd9271365e4b2f55fac9ec402= c292607f7fc1d 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -137,7 +137,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, int ret; Error *local_err =3D NULL; =20 - if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) { + if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { if (!vfio_devices_all_device_dirty_tracking(bcontainer) && bcontainer->dirty_pages_supported) { return vfio_dma_unmap_bitmap(container, iova, size, iotlb); --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571013; cv=none; d=zohomail.com; s=zohoarc; b=WCbfx7L/WQGRQOilv7/1Znh6uY7LNLPE2Xvdiz48FDyCq5dfoUki5RnUtSFkIDv1J9WFskeuGy91QkUk67Gs29KKsowqyjo8S5q/wqfMt/U8mGil1JVgm64Tvm3u6jMjvQCJBXItp2NdKZNuPK3P/AryYlSOEMG0nFt/ShuS0tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571013; 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=BeEHvgTujRyP2uqhL8UIZGBsnNlIiYNTWTNvyxVvK90=; b=Z5B3i6TyzO2mgI7rWjUg8Lp2cEP2D5tahCyEIHoOIqBddJOXccZt26p4gEuxLaP47EhAbK+LA08szpBvqLP25MhkMPlX1U0LSnGZLBUphyts9Xy2iWlnn0E1JvWL0k++OqE26BoFfHxghYQ4oq2aEvLq82gm5EYpfDmKL2jnUfA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571013193160.1547846176071; Fri, 25 Apr 2025 01:50:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ejy-0005lm-0i; Fri, 25 Apr 2025 04:48:58 -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 1u8Ejo-00059t-EJ for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:48 -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 1u8Ejm-0003Jk-HK for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:48 -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-346-qQYZm39iNPmxT23JwRPCaA-1; Fri, 25 Apr 2025 04:48:43 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 42D8B1956089; Fri, 25 Apr 2025 08:48:42 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E302230002C7; Fri, 25 Apr 2025 08:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570925; 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=BeEHvgTujRyP2uqhL8UIZGBsnNlIiYNTWTNvyxVvK90=; b=TYLukyJ3o+DEqYS8KMlvI24fWHaMeaKd/mKdclDOboArDc3aM1IZV8MM19NHeQwdEEP349 5PJF0VTW0bu0VrZnA14tbBjxI1P64v8x+iJeohnZW0Pqofmw503JC2LIzNtn5ykGGcNBwI I6hiPPGNx78ov4UC16FiOw9WdMGFRS0= X-MC-Unique: qQYZm39iNPmxT23JwRPCaA-1 X-Mimecast-MFC-AGG-ID: qQYZm39iNPmxT23JwRPCaA_1745570922 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Avihai Horon Subject: [PULL 34/50] vfio: Rename vfio_devices_all_device_dirty_tracking() Date: Fri, 25 Apr 2025 10:46:27 +0200 Message-ID: <20250425084644.102196-35-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571014212019000 Use the prefix 'vfio_container_devices_' to reflect the routine simply loops over the container's device list. Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-31-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 3 ++- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 5 +++-- hw/vfio/container.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 9b33e71f59bba1f3cbe10c307172422ca4e4c2ce..395ace02e488519aba77ca40173= 7f0b319d9a512 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -91,7 +91,8 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerB= ase *bcontainer, bool start, Error **errp); bool vfio_container_dirty_tracking_is_started( const VFIOContainerBase *bcontainer); -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer); +bool vfio_container_devices_dirty_tracking_is_supported( + const VFIOContainerBase *bcontainer); int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, uint64_t size, ram_addr_t ram_addr, Error **errp= ); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 89b7a71385abfff888c5208a6b4c588b4217716a..5a7327979d2cc83221384577398= aa1276578ac26 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -935,7 +935,7 @@ static bool vfio_listener_log_global_start(MemoryListen= er *listener, listener); bool ret; =20 - if (vfio_devices_all_device_dirty_tracking(bcontainer)) { + if (vfio_container_devices_dirty_tracking_is_supported(bcontainer)) { ret =3D vfio_devices_dma_logging_start(bcontainer, errp); } else { ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, e= rrp) =3D=3D 0; @@ -954,7 +954,7 @@ static void vfio_listener_log_global_stop(MemoryListene= r *listener) Error *local_err =3D NULL; int ret =3D 0; =20 - if (vfio_devices_all_device_dirty_tracking(bcontainer)) { + if (vfio_container_devices_dirty_tracking_is_supported(bcontainer)) { vfio_devices_dma_logging_stop(bcontainer); } else { ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 1beba37a7739d76630c3e7db16a8d04926cb1aee..2627908e3fdbf1a43b86293a3f3= 79baf88cef5ef 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -162,7 +162,8 @@ bool vfio_container_dirty_tracking_is_started( bcontainer->dirty_pages_started; } =20 -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer) +bool vfio_container_devices_dirty_tracking_is_supported( + const VFIOContainerBase *bcontainer) { VFIODevice *vbasedev; =20 @@ -240,7 +241,7 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcon= tainer, uint64_t iova, uint64_t size, ram_addr_t ram_addr, Error **errp) { bool all_device_dirty_tracking =3D - vfio_devices_all_device_dirty_tracking(bcontainer); + vfio_container_devices_dirty_tracking_is_supported(bcontainer); uint64_t dirty_pages; VFIOBitmap vbmap; int ret; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index e8cd9271365e4b2f55fac9ec402c292607f7fc1d..8e4a2cae037edd6d454582c8ebe= b14b210463fc2 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -138,7 +138,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, Error *local_err =3D NULL; =20 if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) { - if (!vfio_devices_all_device_dirty_tracking(bcontainer) && + if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer= ) && bcontainer->dirty_pages_supported) { return vfio_dma_unmap_bitmap(container, iova, size, iotlb); } --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571095; cv=none; d=zohomail.com; s=zohoarc; b=RAPp2cMWR7l+mEGugWUM02iOvcvcklOn17l2CtbupLzH7AP2mzy5eRnbuMK2mas2lUBjyOSRUEw7df+QIJpibqV2rJ8JL5Dri9WE7vaHYnbGAzArLgcj9i692SzstItSBQYhMtVJGg8OdUUDgOIOcnYNVkSrpGa0TIRfPrhjtDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571095; 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=+o/6tEuhi2SdAmf5N+1lreZzueKTagEYyygJPcPUi/4=; b=K0Nm27+Eu+YRWRptvnuOM5fafDNUJd1w23Xc04XvdcstrlqI3B6PupAOCXjiwPTsJ0uvcfFvCF/dFIyRpNrCQsd3jFBQzLiuMuIyB3bOKMAWVl3F0l7PwXkClfzi3sRzLPHUkXFA3qK0lENP8oQQKADwQ0275kpKmXCoMXcVAnY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571095667769.4759415819234; Fri, 25 Apr 2025 01:51:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ek2-00066L-1I; Fri, 25 Apr 2025 04:49:02 -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 1u8Ejy-0005rt-Kq for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Eju-0003KJ-NV for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:58 -0400 Received: from mx-prod-mc-03.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-433-CPwPDBS0OSKkQEeSH4LeDQ-1; Fri, 25 Apr 2025 04:48:46 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCAEF1955D99; Fri, 25 Apr 2025 08:48:45 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D526230002C3; Fri, 25 Apr 2025 08:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570932; 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=+o/6tEuhi2SdAmf5N+1lreZzueKTagEYyygJPcPUi/4=; b=OqKrArtMxD23zxYbAs8lcrv+uKh7tOULP8TjJwEMzAmu6J3tzVlBlU9BRsntxEvYWjP1Sp +1URbS01zjhQh6mo7E1HLcafz9gtEHLGWUSqtrcz5tAtq9OmCUtgHwknzkX9IbPt6LsKs2 Mbgw6kVeuIHFgoJiPe8eokYdPirJGd8= X-MC-Unique: CPwPDBS0OSKkQEeSH4LeDQ-1 X-Mimecast-MFC-AGG-ID: CPwPDBS0OSKkQEeSH4LeDQ_1745570925 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon , Avihai Horon Subject: [PULL 35/50] vfio: Rename vfio_get_dirty_bitmap() Date: Fri, 25 Apr 2025 10:46:28 +0200 Message-ID: <20250425084644.102196-36-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571096545019000 Rename to vfio_container_query_dirty_bitmap() to be consistent with the VFIO container routine naming scheme. Reviewed-by: Joao Martins Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-32-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 4 ++-- hw/vfio/common.c | 6 +++--- hw/vfio/container-base.c | 5 +++-- hw/vfio/container.c | 2 +- hw/vfio/trace-events | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 395ace02e488519aba77ca401737f0b319d9a512..af63373c92359ec53eb1669edfd= 4deb5a5177c20 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -93,8 +93,8 @@ bool vfio_container_dirty_tracking_is_started( const VFIOContainerBase *bcontainer); bool vfio_container_devices_dirty_tracking_is_supported( const VFIOContainerBase *bcontainer); -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr, Error **errp= ); +int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, + uint64_t iova, uint64_t size, ram_addr_t ram_addr, Error **errp); =20 GList *vfio_container_get_iova_ranges(const VFIOContainerBase *bcontainer); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 5a7327979d2cc83221384577398aa1276578ac26..bde1bb3c1344818a3958f619a8c= 2a3dd755c5a84 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1002,7 +1002,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) goto out_unlock; } =20 - ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1, + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, iotlb->add= r_mask + 1, translated_addr, &local_err); if (ret) { error_prepend(&local_err, @@ -1039,7 +1039,7 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRe= gionSection *section, * Sync the whole mapped region (spanning multiple individual mappings) * in one go. */ - ret =3D vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr, + ret =3D vfio_container_query_dirty_bitmap(vrdl->bcontainer, iova, size= , ram_addr, &local_err); if (ret) { error_report_err(local_err); @@ -1133,7 +1133,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *= bcontainer, ram_addr =3D memory_region_get_ram_addr(section->mr) + section->offset_within_region; =20 - return vfio_get_dirty_bitmap(bcontainer, + return vfio_container_query_dirty_bitmap(bcontainer, REAL_HOST_PAGE_ALIGN(section->offset_within_address_spa= ce), int128_get64(section->size), ram_addr, er= rp); } diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 2627908e3fdbf1a43b86293a3f379baf88cef5ef..fb86bc41bf81f38549c56663861= 516d99056b53e 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -237,7 +237,7 @@ static int vfio_container_devices_query_dirty_bitmap(co= nst VFIOContainerBase *bc return 0; } =20 -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, +int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,= uint64_t iova, uint64_t size, ram_addr_t ram_addr, Error **errp) { bool all_device_dirty_tracking =3D @@ -275,7 +275,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcon= tainer, uint64_t iova, dirty_pages =3D cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, r= am_addr, vbmap.pages); =20 - trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pa= ges); + trace_vfio_container_query_dirty_bitmap(iova, size, vbmap.size, ram_ad= dr, + dirty_pages); out: g_free(vbmap.bitmap); =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 8e4a2cae037edd6d454582c8ebeb14b210463fc2..bb3990aece90681e7cf8be69a84= ac7299fa7a50d 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -169,7 +169,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, } =20 if (need_dirty_sync) { - ret =3D vfio_get_dirty_bitmap(bcontainer, iova, size, + ret =3D vfio_container_query_dirty_bitmap(bcontainer, iova, size, iotlb->translated_addr, &local_err); if (ret) { error_report_err(local_err); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index d4cd09cb0f93485fe06984346f6ac927603c5745..aa0ba695fa38f7767bf506ec604= 046101186e7d4 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -109,7 +109,7 @@ vfio_legacy_dma_unmap_overflow_workaround(void) "" vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 # container-base.c -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, = uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size=3D 0x%"PRIx6= 4" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages=3D%"PRIu64 +vfio_container_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t b= itmap_size, uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size= =3D 0x%"PRIx64" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages= =3D%"PRIu64 =20 # region.c vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571086; cv=none; d=zohomail.com; s=zohoarc; b=UoKTp1HFNa8DzorwtwClznoFCHxUXvgFFyA4qN4Sm3/vUT3QRHedC1d9N7TUgQc0OirwpQSnyTww4fQ8I7Qyf3775eFvjmsUXzO15HyUzBG/EWG6jjBzslB5haNKjexvGfFX5HfRxb57jn/76evKro4LVFNaRbNKbbu9z0I5/Dw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571086; 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=WQXMmk+ekWsC9mIdFCwL/hcLiHUaeraCByoCPKMZc9M=; b=N6rjFy0ODjLW/ZyeoItUIQhmRO/Uvujm52ZA0Wn/b4Sj0MulkjNfWf+04tkNw2Rw4VwMhWpyTH5IwE3e9uhKnFIIsVNMwarE3pvQAr1ZKsi/ssez5rCTLVmhrl9vGvh3oEQdLQcxJjveSYHzEpQr+Hp0zsUNqSdWTzv5Gv1fJ8M= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571086298922.711303091843; Fri, 25 Apr 2025 01:51:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ek6-0006Q4-CR; Fri, 25 Apr 2025 04:49:06 -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 1u8Ek0-00063g-DX for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:00 -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 1u8Ejy-0003KZ-8O for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:59 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-IfBuz6A7OjC8Cs-nLRPPUg-1; Fri, 25 Apr 2025 04:48:50 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A3881801A11; Fri, 25 Apr 2025 08:48:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 64B2530002C3; Fri, 25 Apr 2025 08:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570937; 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=WQXMmk+ekWsC9mIdFCwL/hcLiHUaeraCByoCPKMZc9M=; b=LHCqBQTyScKTbsuAHEFMbCLFCWCsRqjcyD0aFdVJmSHFSQZ7Dvel2uvLZdPHqPPem+txG6 Z8DDgwmuLN7rsUQ/2CKon7k8dYOZ6U/8FnS2FAdrgvvc7ki/a6FXXV5uCZGim4UdoxbXEK SaWcpqnEKKNWp6Yh/zBsbgbtcDMcBss= X-MC-Unique: IfBuz6A7OjC8Cs-nLRPPUg-1 X-Mimecast-MFC-AGG-ID: IfBuz6A7OjC8Cs-nLRPPUg_1745570929 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon , Avihai Horon Subject: [PULL 36/50] vfio: Introduce new files for VFIO MemoryListener Date: Fri, 25 Apr 2025 10:46:29 +0200 Message-ID: <20250425084644.102196-37-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571089253019100 File "common.c" has been emptied of most of its definitions by the previous changes and the only definitions left are related to the VFIO MemoryListener handlers. Rename it to "listener.c" and introduce its associated "vfio-listener.h" header file for the declarations. Cleanup a little the includes while at it. Reviewed-by: Joao Martins Reviewed-by: John Levon Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-33-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-listener.h | 14 ++++++++++++++ include/hw/vfio/vfio-common.h | 1 - hw/vfio/container.c | 1 + hw/vfio/iommufd.c | 1 + hw/vfio/{common.c =3D> listener.c} | 0 hw/vfio/meson.build | 2 +- hw/vfio/trace-events | 2 +- 7 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 hw/vfio/vfio-listener.h rename hw/vfio/{common.c =3D> listener.c} (100%) diff --git a/hw/vfio/vfio-listener.h b/hw/vfio/vfio-listener.h new file mode 100644 index 0000000000000000000000000000000000000000..93af6747b28955f038454a335b3= 61787f8364a3a --- /dev/null +++ b/hw/vfio/vfio-listener.h @@ -0,0 +1,14 @@ +/* + * VFIO MemoryListener services + * + * Copyright Red Hat, Inc. 2025 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VFIO_VFIO_LISTENER_H +#define HW_VFIO_VFIO_LISTENER_H + +extern const MemoryListener vfio_memory_listener; + +#endif /* HW_VFIO_VFIO_LISTENER_H */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 0dfae24b72906fa01c5003d1858d4dc101a5012e..92381c6160925613dfc1d1de678= 479f70976c796 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -131,7 +131,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj); =20 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; extern VFIODeviceList vfio_device_list; -extern const MemoryListener vfio_memory_listener; =20 #ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index bb3990aece90681e7cf8be69a84ac7299fa7a50d..ff540e1c598b2b6390bdd9e2665= 5a905c8388669 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -35,6 +35,7 @@ #include "hw/vfio/vfio-container.h" #include "vfio-helpers.h" #include "vfio-cpr.h" +#include "vfio-listener.h" =20 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index a5bd189a86d70bd11ecb80384ac145a51979322b..7488d21215b6eee78c9c51cfb22= 7d9c8c59c4978 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -28,6 +28,7 @@ #include "vfio-iommufd.h" #include "vfio-helpers.h" #include "vfio-cpr.h" +#include "vfio-listener.h" =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" diff --git a/hw/vfio/common.c b/hw/vfio/listener.c similarity index 100% rename from hw/vfio/common.c rename to hw/vfio/listener.c diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 9c8a989db2d4578e97d864c5fd8bcba125eab66a..bccb05098ce18968caaa4d5d8de= c3df0852d0398 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -1,6 +1,6 @@ vfio_ss =3D ss.source_set() vfio_ss.add(files( - 'common.c', + 'listener.c', 'container-base.c', 'container.c', 'helpers.c', diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index aa0ba695fa38f7767bf506ec604046101186e7d4..ddb1bcc24a9cdc405713ca04d4e= cc3d4a923ec42 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -89,7 +89,7 @@ vfio_pci_igd_bdsm_enabled(const char *name, int size) "%s= %dMB" vfio_pci_igd_host_bridge_enabled(const char *name) "%s" vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s" =20 -# common.c +# listener.c vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_e= nd) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64 vfio_listener_region_skip(const char *name, uint64_t start, uint64_t end) = "SKIPPING %s 0x%"PRIx64" - 0x%"PRIx64 vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to = liobn fd %d" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571163; cv=none; d=zohomail.com; s=zohoarc; b=iCq1gQue139STPGfBwFDPOVvmudQBsxKMsC2OQFz7nqVnUvRXaqOGBVz8RPOHuxrht0e8Xtt3LqupqQNoZuc7UQRIZDkSvd4Ffyfda8O6JJJ3o2mgn4X+jIOMgmLQe65tSo1onk+v0bOUh195l6/zPAXoemF3k03E7iPEMLKtFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571163; 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=59l+mO+aqKmxGigOlfk5JEvgGu6pumdocPPdkevSbLE=; b=GwPuRjG35kUffyPvdZ8jyRB0HdLY7wykh0E1XOXD0Z1dEIxc8+Avs1+caQKWZjjzIVg65MLs4/GcMeW9yZsnExo0KglmC8y4npkPp0tf8O92uIizFd0+sICzelZbiTBJh+mODWjfMU2fRXC7d34rg0dNjUo0BDoVHcvbWeQ3C2I= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571163368736.6040707265417; Fri, 25 Apr 2025 01:52:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ek2-0006AF-A0; Fri, 25 Apr 2025 04:49:02 -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 1u8Ejz-0005wl-Fz for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Ejx-0003KR-Jd for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:48:59 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-e5VVw6HoMQWYYGK0zCjEfg-1; Fri, 25 Apr 2025 04:48:52 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B12AD180098B; Fri, 25 Apr 2025 08:48:51 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6E0530001AB; Fri, 25 Apr 2025 08:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570936; 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=59l+mO+aqKmxGigOlfk5JEvgGu6pumdocPPdkevSbLE=; b=OL4zFaoKEgvYgo5sQ4T4rupc6hKOadOYORkWkD0y6OwJ8N4Oall1FVprvfxNAKyenYCzYI 9dsUY860pICpzHGCzPCigGpRCoFsYNe6fQmD4Ic/Yu/yUVmjjMitWdy7gzSthy2OrH86w/ RE8GxNo/h0AO//OVpSkVB+OMo12TvLs= X-MC-Unique: e5VVw6HoMQWYYGK0zCjEfg-1 X-Mimecast-MFC-AGG-ID: e5VVw6HoMQWYYGK0zCjEfg_1745570931 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Avihai Horon Subject: [PULL 37/50] vfio: Rename RAM discard related services Date: Fri, 25 Apr 2025 10:46:30 +0200 Message-ID: <20250425084644.102196-38-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571164546019000 Rename some routines to better reflect the namespace they belong to. Reviewed-by: Avihai Horon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-34-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/listener.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index bde1bb3c1344818a3958f619a8c2a3dd755c5a84..70bdeb3ce743088306f0941d63e= 51bddb242a697 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -242,7 +242,7 @@ static int vfio_ram_discard_notify_populate(RamDiscardL= istener *rdl, return 0; } =20 -static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontain= er, +static void vfio_ram_discard_register_listener(VFIOContainerBase *bcontain= er, MemoryRegionSection *sectio= n) { RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(secti= on->mr); @@ -317,7 +317,7 @@ static void vfio_register_ram_discard_listener(VFIOCont= ainerBase *bcontainer, } } =20 -static void vfio_unregister_ram_discard_listener(VFIOContainerBase *bconta= iner, +static void vfio_ram_discard_unregister_listener(VFIOContainerBase *bconta= iner, MemoryRegionSection *sect= ion) { RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(secti= on->mr); @@ -504,7 +504,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, * about changes. */ if (memory_region_has_ram_discard_manager(section->mr)) { - vfio_register_ram_discard_listener(bcontainer, section); + vfio_ram_discard_register_listener(bcontainer, section); return; } =20 @@ -627,7 +627,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, pgmask =3D (1ULL << ctz64(bcontainer->pgsizes)) - 1; try_unmap =3D !((iova & pgmask) || (int128_get64(llsize) & pgmask)= ); } else if (memory_region_has_ram_discard_manager(section->mr)) { - vfio_unregister_ram_discard_listener(bcontainer, section); + vfio_ram_discard_unregister_listener(bcontainer, section); /* Unregistering will trigger an unmap. */ try_unmap =3D false; } @@ -1024,7 +1024,7 @@ out: } } =20 -static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section, +static int vfio_ram_discard_query_dirty_bitmap(MemoryRegionSection *sectio= n, void *opaque) { const hwaddr size =3D int128_get64(section->size); @@ -1071,7 +1071,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOConta= inerBase *bcontainer, * which correspond to populated parts. Replay all populated parts. */ return ram_discard_manager_replay_populated(rdm, section, - vfio_ram_discard_get_dirty_b= itmap, + vfio_ram_discard_query_dir= ty_bitmap, &vrdl); } =20 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571033; cv=none; d=zohomail.com; s=zohoarc; b=Krab9bDcvll7YiV+Z5I6i7CzhIAC479Jrtts2AaeAWCrHBISuTQamfTRxJ8MSGpEKLGDAuX2mScyFfz+uBTQMWew06YOGWXbAj77vVBBF4SA4xv/pEy8/zIo88KGEzTSaScW6w/n77O9ZG3drZ+m0RvQyUoJk5vxp+SMlmWrO9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571033; 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=Dm7vGpZP5EoeI30V0/xpiSTroCenQJrmqRZLViECxjc=; b=Bw5DFqHtxWO6hVdBDetNhN3CalO38pnQLN3pU0DgKwqooXzlJd+CX989DEns2zwPgC5TsTjf2U/hpMCsAG55kku4i3HHe4YDjE1lb6QEG3nNeUP28Jd2ie4k3I2a2PE5aaKy0u1TtuXxnWCvLaPy27jlqGENdsjgX7eNL24wrN8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571033088643.059124185415; Fri, 25 Apr 2025 01:50:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EkF-0006Ym-28; Fri, 25 Apr 2025 04:49:17 -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 1u8Ek2-0006D5-KD for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:02 -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 1u8Ek0-0003Kt-AM for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:02 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-03q7kRizMYeWtN6HRuTAfw-1; Fri, 25 Apr 2025 04:48:55 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 839BB180099F; Fri, 25 Apr 2025 08:48:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3BEE130001AB; Fri, 25 Apr 2025 08:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570939; 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=Dm7vGpZP5EoeI30V0/xpiSTroCenQJrmqRZLViECxjc=; b=G3/08KC7uuOFIbhMrqNrbYpDO6Fw5E8QsobM6DkaD4zIklRPAwhBkopTEvj5SyjWVZ1M2J ELrFcIJod/xDwuqZws6w0oWFNBSDMLkwHtu8TgNAZg6c6mNryKSkjE+D6elmewI2JjPnPf dDyQz9v5WdWHc21XDoW/WBOiHYBo/S0= X-MC-Unique: 03q7kRizMYeWtN6HRuTAfw-1 X-Mimecast-MFC-AGG-ID: 03q7kRizMYeWtN6HRuTAfw_1745570934 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins , John Levon Subject: [PULL 38/50] vfio: Introduce vfio_listener_un/register() routines Date: Fri, 25 Apr 2025 10:46:31 +0200 Message-ID: <20250425084644.102196-39-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571035145019100 This hides the MemoryListener implementation and makes the code common to both IOMMU backends, legacy and IOMMUFD. Reviewed-by: Joao Martins Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-35-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-listener.h | 3 ++- hw/vfio/container.c | 11 +++-------- hw/vfio/iommufd.c | 9 ++------- hw/vfio/listener.c | 22 +++++++++++++++++++++- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/hw/vfio/vfio-listener.h b/hw/vfio/vfio-listener.h index 93af6747b28955f038454a335b361787f8364a3a..eb69ddd374fa20683007cfc4e9a= 7bf6fe707f27d 100644 --- a/hw/vfio/vfio-listener.h +++ b/hw/vfio/vfio-listener.h @@ -9,6 +9,7 @@ #ifndef HW_VFIO_VFIO_LISTENER_H #define HW_VFIO_VFIO_LISTENER_H =20 -extern const MemoryListener vfio_memory_listener; +bool vfio_listener_register(VFIOContainerBase *bcontainer, Error **errp); +void vfio_listener_unregister(VFIOContainerBase *bcontainer); =20 #endif /* HW_VFIO_VFIO_LISTENER_H */ diff --git a/hw/vfio/container.c b/hw/vfio/container.c index ff540e1c598b2b6390bdd9e26655a905c8388669..e4fcb1ad8bee80136fedcdc07cd= 68d56b5eeae04 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -616,12 +616,7 @@ static bool vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_next); =20 - bcontainer->listener =3D vfio_memory_listener; - memory_listener_register(&bcontainer->listener, bcontainer->space->as); - - if (bcontainer->error) { - error_propagate_prepend(errp, bcontainer->error, - "memory listener initialization failed: "); + if (!vfio_listener_register(bcontainer, errp)) { goto listener_release_exit; } =20 @@ -631,7 +626,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, listener_release_exit: QLIST_REMOVE(group, container_next); vfio_kvm_device_del_group(group); - memory_listener_unregister(&bcontainer->listener); + vfio_listener_unregister(bcontainer); if (vioc->release) { vioc->release(bcontainer); } @@ -669,7 +664,7 @@ static void vfio_disconnect_container(VFIOGroup *group) * group. */ if (QLIST_EMPTY(&container->group_list)) { - memory_listener_unregister(&bcontainer->listener); + vfio_listener_unregister(bcontainer); if (vioc->release) { vioc->release(bcontainer); } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 7488d21215b6eee78c9c51cfb227d9c8c59c4978..e47720247d6acfd6ea0e5a2e2a2= eecabfa62dce3 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -410,7 +410,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDC= ontainer *container) if (!QLIST_EMPTY(&bcontainer->device_list)) { return; } - memory_listener_unregister(&bcontainer->listener); + vfio_listener_unregister(bcontainer); iommufd_backend_free_id(container->be, container->ioas_id); object_unref(container); } @@ -562,12 +562,7 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, bcontainer->pgsizes =3D qemu_real_host_page_size(); } =20 - bcontainer->listener =3D vfio_memory_listener; - memory_listener_register(&bcontainer->listener, bcontainer->space->as); - - if (bcontainer->error) { - error_propagate_prepend(errp, bcontainer->error, - "memory listener initialization failed: "); + if (!vfio_listener_register(bcontainer, errp)) { goto err_listener_register; } =20 diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 70bdeb3ce743088306f0941d63e51bddb242a697..d19674503c5dfc6b61671db316a= 186d18ae6f865 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -45,6 +45,7 @@ #include "system/tpm.h" #include "vfio-migration-internal.h" #include "vfio-helpers.h" +#include "vfio-listener.h" =20 /* * Device state interfaces @@ -1162,7 +1163,7 @@ static void vfio_listener_log_sync(MemoryListener *li= stener, } } =20 -const MemoryListener vfio_memory_listener =3D { +static const MemoryListener vfio_memory_listener =3D { .name =3D "vfio", .region_add =3D vfio_listener_region_add, .region_del =3D vfio_listener_region_del, @@ -1170,3 +1171,22 @@ const MemoryListener vfio_memory_listener =3D { .log_global_stop =3D vfio_listener_log_global_stop, .log_sync =3D vfio_listener_log_sync, }; + +bool vfio_listener_register(VFIOContainerBase *bcontainer, Error **errp) +{ + bcontainer->listener =3D vfio_memory_listener; + memory_listener_register(&bcontainer->listener, bcontainer->space->as); + + if (bcontainer->error) { + error_propagate_prepend(errp, bcontainer->error, + "memory listener initialization failed: "); + return false; + } + + return true; +} + +void vfio_listener_unregister(VFIOContainerBase *bcontainer) +{ + memory_listener_unregister(&bcontainer->listener); +} --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571060; cv=none; d=zohomail.com; s=zohoarc; b=Z74SvyYUMxZnnP/oUZR5d4qvJwHRSgCAJQv+LTRThqoaOoDlB9DF0Aul4AvhdNJii9rboWjN2CoB/QD8MFXx2039ZiDZpLASJCLUNyOPZsgwV/1IO743bswwxiyVqKqsFnlngc2QNrMG7jrqRv+A/EbL0YiTC0ADtGCCeuAi5cM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571060; 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=IIz689r5PFmYy+Qt7ydR21v1FHIGWz8plMYyRi3FtWw=; b=Bft0QdbJMUKwuNghEJhlmjZuejZeTT1KL7wjrK2JahlN9Zq/i9X7HKW9W6P1sY2Ijm3Y3ynQjR0ZvT3LWtHdxBCfsN1J5axi/0hO5l/HcB18ryxvEwupTH7jyQGmgKdBjML3FI/LHSXdRRFHp9qY7HlZUjMWVnRoVLCf8WtPSlA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571060610418.1475150103703; Fri, 25 Apr 2025 01:51:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EkR-0006wx-FY; Fri, 25 Apr 2025 04:49:28 -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 1u8Ek5-0006Na-0w for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:05 -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 1u8Ek2-0003L2-BB for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:04 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-TtdTBxSZOTGwuBms_ZjWbA-1; Fri, 25 Apr 2025 04:48:57 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC2911800ECB; Fri, 25 Apr 2025 08:48:56 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C38C30001AB; Fri, 25 Apr 2025 08:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570941; 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=IIz689r5PFmYy+Qt7ydR21v1FHIGWz8plMYyRi3FtWw=; b=DjQAqBMrERFTc4CGHNse4Cqc9GnGfFCPPVG+PiGw2gfOF40cupMe6WVRlWPE5wXMDI1zig BfdSpcoHeD5cEn1FQlnNicN31Txyn7UGmXJ4KbNhEAO3xpDTVXB+SW+o+bPqWvKtnZN1OF nNXDqTlTNy1vx6oP1TSSmEfWGBASHtw= X-MC-Unique: TtdTBxSZOTGwuBms_ZjWbA-1 X-Mimecast-MFC-AGG-ID: TtdTBxSZOTGwuBms_ZjWbA_1745570936 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan Subject: [PULL 39/50] vfio: Rename vfio-common.h to vfio-device.h Date: Fri, 25 Apr 2025 10:46:32 +0200 Message-ID: <20250425084644.102196-40-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571062661019000 "hw/vfio/vfio-common.h" has been emptied of most of its declarations by the previous changes and the only declarations left are related to VFIODevice. Rename it to "hw/vfio/vfio-device.h" and make the necessary adjustments. Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-36-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration-multifd.h | 2 +- hw/vfio/pci.h | 2 +- include/hw/s390x/vfio-ccw.h | 2 +- include/hw/vfio/{vfio-common.h =3D> vfio-device.h} | 2 +- include/hw/vfio/vfio-platform.h | 2 +- backends/iommufd.c | 2 +- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/container-base.c | 2 +- hw/vfio/container.c | 2 +- hw/vfio/cpr.c | 2 +- hw/vfio/device.c | 2 +- hw/vfio/helpers.c | 2 +- hw/vfio/iommufd.c | 2 +- hw/vfio/listener.c | 2 +- hw/vfio/migration-multifd.c | 2 +- hw/vfio/migration.c | 2 +- hw/vfio/region.c | 4 ++-- 18 files changed, 19 insertions(+), 19 deletions(-) rename include/hw/vfio/{vfio-common.h =3D> vfio-device.h} (98%) diff --git a/hw/vfio/migration-multifd.h b/hw/vfio/migration-multifd.h index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea= 57840915ffc2a 100644 --- a/hw/vfio/migration-multifd.h +++ b/hw/vfio/migration-multifd.h @@ -12,7 +12,7 @@ #ifndef HW_VFIO_MIGRATION_MULTIFD_H #define HW_VFIO_MIGRATION_MULTIFD_H =20 -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" =20 bool vfio_multifd_setup(VFIODevice *vbasedev, bool alloc_multifd, Error **= errp); void vfio_multifd_cleanup(VFIODevice *vbasedev); diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 801ea445b8c9f7b11fb209146aa54349fe29ccf4..f835b1dbc2b1e8aab820924900e= 1eb6c36613d16 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -14,7 +14,7 @@ =20 #include "system/memory.h" #include "hw/pci/pci_device.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-region.h" #include "qemu/event_notifier.h" #include "qemu/queue.h" diff --git a/include/hw/s390x/vfio-ccw.h b/include/hw/s390x/vfio-ccw.h index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82= bd3462ace35f5 100644 --- a/include/hw/s390x/vfio-ccw.h +++ b/include/hw/s390x/vfio-ccw.h @@ -14,7 +14,7 @@ #ifndef HW_VFIO_CCW_H #define HW_VFIO_CCW_H =20 -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "hw/s390x/s390-ccw.h" #include "hw/s390x/ccw-device.h" #include "qom/object.h" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-device.h similarity index 98% rename from include/hw/vfio/vfio-common.h rename to include/hw/vfio/vfio-device.h index 92381c6160925613dfc1d1de678479f70976c796..cfbe254e31545818733c1b7f4f5= 607091fc4d871 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-device.h @@ -1,5 +1,5 @@ /* - * common header for vfio based device assignment support + * VFIO Device interface * * Copyright Red Hat, Inc. 2012 * diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platfor= m.h index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e= 3cfca435ed8ed 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -17,7 +17,7 @@ #define HW_VFIO_VFIO_PLATFORM_H =20 #include "hw/sysbus.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "qemu/event_notifier.h" #include "qemu/queue.h" #include "qom/object.h" diff --git a/backends/iommufd.c b/backends/iommufd.c index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196= cfd2079560430 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -18,7 +18,7 @@ #include "qemu/error-report.h" #include "monitor/monitor.h" #include "trace.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include #include =20 diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index d6575d7c44c30e4b6731751f91c0685ceb26d85b..9e2251437e639af64be4040bc82= b34430b492640 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -15,7 +15,7 @@ #include #include #include "qapi/error.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "system/iommufd.h" #include "hw/s390x/ap-device.h" #include "qemu/error-report.h" diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 29e804e1222293e20fbbdfe29889eb796191b25b..d0713ca4c76b31b3fe03b558c31= 0f0455d40b97c 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -21,7 +21,7 @@ #include =20 #include "qapi/error.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "system/iommufd.h" #include "hw/s390x/s390-ccw.h" #include "hw/s390x/vfio-ccw.h" diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index fb86bc41bf81f38549c56663861516d99056b53e..c037bafe2162d864c42e059d763= 0d579fde0d251 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -19,7 +19,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "hw/vfio/vfio-container-base.h" -#include "hw/vfio/vfio-common.h" /* vfio_reset_handler */ +#include "hw/vfio/vfio-device.h" /* vfio_reset_handler */ #include "system/reset.h" #include "vfio-helpers.h" =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index e4fcb1ad8bee80136fedcdc07cd68d56b5eeae04..ef1404607253cd5279c89af5d31= add3c88b01aed 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -22,7 +22,7 @@ #include #include =20 -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "system/address-spaces.h" #include "system/memory.h" #include "system/ram_addr.h" diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 696987006b853227e76caedb3c7f4e4be31cfa06..3214184f97421a17b4d981facdc= adde3a1fcec9a 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -6,7 +6,7 @@ */ =20 #include "qemu/osdep.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "migration/misc.h" #include "qapi/error.h" #include "system/runstate.h" diff --git a/hw/vfio/device.c b/hw/vfio/device.c index e122c797c206c285ef26c3a56d841d8c3be8b58b..543750c3b13b53dbd6705d08ac8= cead0ebe49ed7 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -21,7 +21,7 @@ #include "qemu/osdep.h" #include =20 -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "hw/vfio/pci.h" #include "hw/hw.h" #include "trace.h" diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 48bd61d5280967dffa509dcbaeeee7a1ba01335a..d0dbab1d17132743ea5f5ed0f25= 701436be11945 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -23,7 +23,7 @@ #include =20 #include "system/kvm.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "hw/hw.h" #include "qapi/error.h" #include "vfio-helpers.h" diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index e47720247d6acfd6ea0e5a2e2a2eecabfa62dce3..48db10542269111804643713270= 199657145accc 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -15,7 +15,7 @@ #include #include =20 -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "qemu/error-report.h" #include "trace.h" #include "qapi/error.h" diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index d19674503c5dfc6b61671db316a186d18ae6f865..6f77e18a7a2f9437d50976eeb98= 47f99bfe4a739 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -25,7 +25,7 @@ #endif #include =20 -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "hw/vfio/pci.h" #include "system/address-spaces.h" #include "system/memory.h" diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c index a3005226b9ca22ff27d9d49339d9828a43713932..850a319488786d1b66e40789ae5= 4a0c73ac9137a 100644 --- a/hw/vfio/migration-multifd.c +++ b/hw/vfio/migration-multifd.c @@ -10,7 +10,7 @@ */ =20 #include "qemu/osdep.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "migration/misc.h" #include "qapi/error.h" #include "qemu/bswap.h" diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 4da05263255b9f858539a55d03d1b35609a4c697..1dceab1b192e6430a01ae8813a3= 02d37a0c3e21d 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -16,7 +16,7 @@ #include =20 #include "system/runstate.h" -#include "hw/vfio/vfio-common.h" +#include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-migration.h" #include "migration/misc.h" #include "migration/savevm.h" diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 9049143abffa28bed333d110d1e01d68ad7f83be..010b5241e15c2063051fd780c33= 5fef80f214dc1 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -21,8 +21,8 @@ #include "qemu/osdep.h" #include =20 -#include "hw/vfio/vfio-common.h" -#include "hw/vfio/pci.h" +#include "hw/vfio/vfio-region.h" +#include "hw/vfio/vfio-device.h" #include "hw/hw.h" #include "trace.h" #include "qapi/error.h" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571103; cv=none; d=zohomail.com; s=zohoarc; b=AmRiBh4cg3vfrppUkhOTLh/QYvLEkM+lQQ5tD0nM6XUFcm8/yiqgo51nZ2yUHf6oDAW89d2hecHCwgAjbtGFHMlTMccq28o10X2sWNpf2P5RZc35a/RuDG+CdJ/Mk20KAEwHYGdQ5S+gusYxxfNxKkutPyl9+5nvJFyuUwXOdI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571103; 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=kUwkpq/oOJqsHPwwOGUOK0QFXwLEV2fES2hOO8oECMA=; b=lROvvXEHTJwl+pIAoSBafm0WqH5UB3hRZ51qDbuSMYWULkWy74RyPoS/wU1xfs42W0daO5pLLKUak6OT9uj833QOik2BL+af1C/yx9JbRkAvsrvZbCfZj2JzB+IWNX9AL1sGixLbDXAV9uvC4BTtXGBddDgIk7KhvR/bl+WtYlk= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571103012826.9962151034682; Fri, 25 Apr 2025 01:51:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ekj-0007SX-C2; Fri, 25 Apr 2025 04:49:46 -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 1u8Ek7-0006Wf-DF for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Ek3-0003LD-Gl for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:06 -0400 Received: from mx-prod-mc-05.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-73-a5e8-8L5NpmDzktg5diqag-1; Fri, 25 Apr 2025 04:49:00 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9DD619560B1; Fri, 25 Apr 2025 08:48:59 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B72D30001A2; Fri, 25 Apr 2025 08:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570942; 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=kUwkpq/oOJqsHPwwOGUOK0QFXwLEV2fES2hOO8oECMA=; b=a7GxHpCYkOhOgnoMmWC5eaiDQW5YLo2E0Ak+mcAheneS5cgorQTBoozoCazSDpNb9o6SLP qkJ/LEqTDyH5LRlQUJZFj1mHmo2zx6vT644SvCWqlYqNVxud6WILeeNyrjw1tds/2D3j0W 7+SD29RL9HCzNjKzNpEV/doIVKuw2Uc= X-MC-Unique: a5e8-8L5NpmDzktg5diqag-1 X-Mimecast-MFC-AGG-ID: a5e8-8L5NpmDzktg5diqag_1745570940 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan Subject: [PULL 40/50] vfio: Rename VFIODevice related services Date: Fri, 25 Apr 2025 10:46:33 +0200 Message-ID: <20250425084644.102196-41-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571104430019000 Rename these routines : vfio_disable_irqindex -> vfio_device_irq_disable vfio_unmask_single_irqindex -> vfio_device_irq_unmask vfio_mask_single_irqindex -> vfio_device_irq_mask vfio_set_irq_signaling -> vfio_device_irq_set_signaling vfio_attach_device -> vfio_device_attach vfio_detach_device -> vfio_device_detach vfio_get_region_info -> vfio_device_get_region_info vfio_get_dev_region_info -> vfio_device_get_region_info_type vfio_has_region_cap -> vfio_device_has_region_cap vfio_reset_handler -> vfio_device_reset_hander to better reflect the namespace they belong to. Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-37-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 26 +++++++------- hw/vfio/ap.c | 12 +++---- hw/vfio/ccw.c | 28 +++++++-------- hw/vfio/container-base.c | 6 ++-- hw/vfio/container.c | 6 ++-- hw/vfio/device.c | 36 +++++++++---------- hw/vfio/display.c | 8 ++--- hw/vfio/igd.c | 10 +++--- hw/vfio/pci.c | 68 +++++++++++++++++------------------ hw/vfio/platform.c | 14 ++++---- hw/vfio/region.c | 2 +- hw/vfio/trace-events | 8 ++--- 12 files changed, 112 insertions(+), 112 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index cfbe254e31545818733c1b7f4f5607091fc4d871..696ed87f01038bf29df26046fa9= b75051971ede3 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -115,29 +115,29 @@ struct VFIODeviceOps { int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 -void vfio_disable_irqindex(VFIODevice *vbasedev, int index); -void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index); -void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index); -bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, - int action, int fd, Error **errp); +void vfio_device_irq_disable(VFIODevice *vbasedev, int index); +void vfio_device_irq_unmask(VFIODevice *vbasedev, int index); +void vfio_device_irq_mask(VFIODevice *vbasedev, int index); +bool vfio_device_irq_set_signaling(VFIODevice *vbasedev, int index, int su= bindex, + int action, int fd, Error **errp); =20 -void vfio_reset_handler(void *opaque); +void vfio_device_reset_handler(void *opaque); bool vfio_device_is_mdev(VFIODevice *vbasedev); bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp); -bool vfio_attach_device(char *name, VFIODevice *vbasedev, +bool vfio_device_attach(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); -void vfio_detach_device(VFIODevice *vbasedev); +void vfio_device_detach(VFIODevice *vbasedev); VFIODevice *vfio_get_vfio_device(Object *obj); =20 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; extern VFIODeviceList vfio_device_list; =20 #ifdef CONFIG_LINUX -int vfio_get_region_info(VFIODevice *vbasedev, int index, - struct vfio_region_info **info); -int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, - uint32_t subtype, struct vfio_region_info **i= nfo); -bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe); +int vfio_device_get_region_info(VFIODevice *vbasedev, int index, + struct vfio_region_info **info); +int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type, + uint32_t subtype, struct vfio_region_= info **info); +bool vfio_device_has_region_cap(VFIODevice *vbasedev, int region, uint16_t= cap_type); #endif =20 /* Returns 0 on success, or a negative errno. */ diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 9e2251437e639af64be4040bc82b34430b492640..be2e2927c24a6a9a029d18b00c0= 266abf5b61e98 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -117,8 +117,8 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice = *vapdev, fd =3D event_notifier_get_fd(notifier); qemu_set_fd_handler(fd, fd_read, NULL, vapdev); =20 - if (!vfio_set_irq_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER,= fd, - errp)) { + if (!vfio_device_irq_set_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_T= RIGGER, fd, + errp)) { qemu_set_fd_handler(fd, NULL, NULL, vapdev); event_notifier_cleanup(notifier); } @@ -141,8 +141,8 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevic= e *vapdev, return; } =20 - if (!vfio_set_irq_signaling(&vapdev->vdev, irq, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_device_irq_set_signaling(&vapdev->vdev, irq, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &e= rr)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vapdev->vdev.name); } =20 @@ -162,7 +162,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **e= rrp) return; } =20 - if (!vfio_attach_device(vbasedev->name, vbasedev, + if (!vfio_device_attach(vbasedev->name, vbasedev, &address_space_memory, errp)) { goto error; } @@ -187,7 +187,7 @@ static void vfio_ap_unrealize(DeviceState *dev) VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); =20 vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX); - vfio_detach_device(&vapdev->vdev); + vfio_device_detach(&vapdev->vdev); g_free(vapdev->vdev.name); } =20 diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index d0713ca4c76b31b3fe03b558c310f0455d40b97c..3a91efce81d981e66d8267a5446= 5dcb484c96944 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -426,8 +426,8 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, fd =3D event_notifier_get_fd(notifier); qemu_set_fd_handler(fd, fd_read, NULL, vcdev); =20 - if (!vfio_set_irq_signaling(vdev, irq, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { + if (!vfio_device_irq_set_signaling(vdev, irq, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, er= rp)) { qemu_set_fd_handler(fd, NULL, NULL, vcdev); event_notifier_cleanup(notifier); } @@ -456,8 +456,8 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDev= ice *vcdev, return; } =20 - if (!vfio_set_irq_signaling(&vcdev->vdev, irq, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_device_irq_set_signaling(&vcdev->vdev, irq, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &e= rr)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name); } =20 @@ -488,7 +488,7 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, E= rror **errp) return false; } =20 - ret =3D vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info= ); + ret =3D vfio_device_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX= , &info); if (ret) { error_setg_errno(errp, -ret, "vfio: Error getting config info"); return false; @@ -505,8 +505,8 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, E= rror **errp) g_free(info); =20 /* check for the optional async command region */ - ret =3D vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW, - VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD, &inf= o); + ret =3D vfio_device_get_region_info_type(vdev, VFIO_REGION_TYPE_CCW, + VFIO_REGION_SUBTYPE_CCW_ASYNC_C= MD, &info); if (!ret) { vcdev->async_cmd_region_size =3D info->size; if (sizeof(*vcdev->async_cmd_region) !=3D vcdev->async_cmd_region_= size) { @@ -518,8 +518,8 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, E= rror **errp) g_free(info); } =20 - ret =3D vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW, - VFIO_REGION_SUBTYPE_CCW_SCHIB, &info); + ret =3D vfio_device_get_region_info_type(vdev, VFIO_REGION_TYPE_CCW, + VFIO_REGION_SUBTYPE_CCW_SCHIB, = &info); if (!ret) { vcdev->schib_region_size =3D info->size; if (sizeof(*vcdev->schib_region) !=3D vcdev->schib_region_size) { @@ -531,8 +531,8 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, E= rror **errp) g_free(info); } =20 - ret =3D vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW, - VFIO_REGION_SUBTYPE_CCW_CRW, &info); + ret =3D vfio_device_get_region_info_type(vdev, VFIO_REGION_TYPE_CCW, + VFIO_REGION_SUBTYPE_CCW_CRW, &i= nfo); =20 if (!ret) { vcdev->crw_region_size =3D info->size; @@ -583,7 +583,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) goto out_unrealize; } =20 - if (!vfio_attach_device(cdev->mdevid, vbasedev, + if (!vfio_device_attach(cdev->mdevid, vbasedev, &address_space_memory, errp)) { goto out_attach_dev_err; } @@ -620,7 +620,7 @@ out_irq_notifier_err: out_io_notifier_err: vfio_ccw_put_region(vcdev); out_region_err: - vfio_detach_device(vbasedev); + vfio_device_detach(vbasedev); out_attach_dev_err: g_free(vbasedev->name); out_unrealize: @@ -639,7 +639,7 @@ static void vfio_ccw_unrealize(DeviceState *dev) 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_detach_device(&vcdev->vdev); + vfio_device_detach(&vcdev->vdev); g_free(vcdev->vdev.name); =20 if (cdc->unrealize) { diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index c037bafe2162d864c42e059d7630d579fde0d251..09340fd97a074c9a3b56c686e7a= 750530bed619f 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -19,7 +19,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "hw/vfio/vfio-container-base.h" -#include "hw/vfio/vfio-device.h" /* vfio_reset_handler */ +#include "hw/vfio/vfio-device.h" /* vfio_device_reset_handler */ #include "system/reset.h" #include "vfio-helpers.h" =20 @@ -44,7 +44,7 @@ VFIOAddressSpace *vfio_address_space_get(AddressSpace *as) QLIST_INIT(&space->containers); =20 if (QLIST_EMPTY(&vfio_address_spaces)) { - qemu_register_reset(vfio_reset_handler, NULL); + qemu_register_reset(vfio_device_reset_handler, NULL); } =20 QLIST_INSERT_HEAD(&vfio_address_spaces, space, list); @@ -62,7 +62,7 @@ void vfio_address_space_put(VFIOAddressSpace *space) g_free(space); =20 if (QLIST_EMPTY(&vfio_address_spaces)) { - qemu_unregister_reset(vfio_reset_handler, NULL); + qemu_unregister_reset(vfio_device_reset_handler, NULL); } } =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index ef1404607253cd5279c89af5d31add3c88b01aed..149ea26aff5960a40b50ff64762= d52d01b11be5c 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -865,7 +865,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Er= ror **errp) } =20 /* - * vfio_attach_device: attach a device to a security context + * vfio_device_attach: attach a device to a security context * @name and @vbasedev->name are likely to be different depending * on the type of the device, hence the need for passing @name */ @@ -881,7 +881,7 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, return false; } =20 - trace_vfio_attach_device(vbasedev->name, groupid); + trace_vfio_device_attach(vbasedev->name, groupid); =20 if (!vfio_device_hiod_realize(vbasedev, errp)) { return false; @@ -919,7 +919,7 @@ static void vfio_legacy_detach_device(VFIODevice *vbase= dev) QLIST_REMOVE(vbasedev, global_next); QLIST_REMOVE(vbasedev, container_next); vbasedev->bcontainer =3D NULL; - trace_vfio_detach_device(vbasedev->name, group->groupid); + trace_vfio_device_detach(vbasedev->name, group->groupid); vfio_put_base_device(vbasedev); vfio_put_group(group); } diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 543750c3b13b53dbd6705d08ac8cead0ebe49ed7..4de6948cf472806ed639f629cc3= d980f51021f2c 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -51,11 +51,11 @@ VFIODeviceList vfio_device_list =3D * reset for the one in-use devices case, calling _multi() will do * nothing if a _one() would have been sufficient. */ -void vfio_reset_handler(void *opaque) +void vfio_device_reset_handler(void *opaque) { VFIODevice *vbasedev; =20 - trace_vfio_reset_handler(); + trace_vfio_device_reset_handler(); QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) { if (vbasedev->dev->realized) { vbasedev->ops->vfio_compute_needs_reset(vbasedev); @@ -72,7 +72,7 @@ void vfio_reset_handler(void *opaque) /* * Common VFIO interrupt disable */ -void vfio_disable_irqindex(VFIODevice *vbasedev, int index) +void vfio_device_irq_disable(VFIODevice *vbasedev, int index) { struct vfio_irq_set irq_set =3D { .argsz =3D sizeof(irq_set), @@ -85,7 +85,7 @@ void vfio_disable_irqindex(VFIODevice *vbasedev, int inde= x) ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); } =20 -void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index) +void vfio_device_irq_unmask(VFIODevice *vbasedev, int index) { struct vfio_irq_set irq_set =3D { .argsz =3D sizeof(irq_set), @@ -98,7 +98,7 @@ void vfio_unmask_single_irqindex(VFIODevice *vbasedev, in= t index) ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); } =20 -void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index) +void vfio_device_irq_mask(VFIODevice *vbasedev, int index) { struct vfio_irq_set irq_set =3D { .argsz =3D sizeof(irq_set), @@ -147,8 +147,8 @@ static const char *index_to_str(VFIODevice *vbasedev, i= nt index) } } =20 -bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, - int action, int fd, Error **errp) +bool vfio_device_irq_set_signaling(VFIODevice *vbasedev, int index, int su= bindex, + int action, int fd, Error **errp) { ERRP_GUARD(); g_autofree struct vfio_irq_set *irq_set =3D NULL; @@ -185,8 +185,8 @@ bool vfio_set_irq_signaling(VFIODevice *vbasedev, int i= ndex, int subindex, return false; } =20 -int vfio_get_region_info(VFIODevice *vbasedev, int index, - struct vfio_region_info **info) +int vfio_device_get_region_info(VFIODevice *vbasedev, int index, + struct vfio_region_info **info) { size_t argsz =3D sizeof(struct vfio_region_info); =20 @@ -212,8 +212,8 @@ retry: return 0; } =20 -int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, - uint32_t subtype, struct vfio_region_info **i= nfo) +int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type, + uint32_t subtype, struct vfio_region_= info **info) { int i; =20 @@ -221,7 +221,7 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint= 32_t type, struct vfio_info_cap_header *hdr; struct vfio_region_info_cap_type *cap_type; =20 - if (vfio_get_region_info(vbasedev, i, info)) { + if (vfio_device_get_region_info(vbasedev, i, info)) { continue; } =20 @@ -233,8 +233,8 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint= 32_t type, =20 cap_type =3D container_of(hdr, struct vfio_region_info_cap_type, h= eader); =20 - trace_vfio_get_dev_region(vbasedev->name, i, - cap_type->type, cap_type->subtype); + trace_vfio_device_get_region_info_type(vbasedev->name, i, + cap_type->type, cap_type->s= ubtype); =20 if (cap_type->type =3D=3D type && cap_type->subtype =3D=3D subtype= ) { return 0; @@ -247,12 +247,12 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, ui= nt32_t type, return -ENODEV; } =20 -bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe) +bool vfio_device_has_region_cap(VFIODevice *vbasedev, int region, uint16_t= cap_type) { g_autofree struct vfio_region_info *info =3D NULL; bool ret =3D false; =20 - if (!vfio_get_region_info(vbasedev, region, &info)) { + if (!vfio_device_get_region_info(vbasedev, region, &info)) { if (vfio_get_region_info_cap(info, cap_type)) { ret =3D true; } @@ -367,7 +367,7 @@ VFIODevice *vfio_get_vfio_device(Object *obj) } } =20 -bool vfio_attach_device(char *name, VFIODevice *vbasedev, +bool vfio_device_attach(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp) { const VFIOIOMMUClass *ops =3D @@ -395,7 +395,7 @@ bool vfio_attach_device(char *name, VFIODevice *vbasede= v, return true; } =20 -void vfio_detach_device(VFIODevice *vbasedev) +void vfio_device_detach(VFIODevice *vbasedev) { if (!vbasedev->bcontainer) { return; diff --git a/hw/vfio/display.c b/hw/vfio/display.c index 70cfd685bd049aadf97b73d06086a0e44eb3f9cb..f3e6581f15b7033f79723e25e20= 97574af1feeb8 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -129,10 +129,10 @@ static bool vfio_display_edid_init(VFIOPCIDevice *vde= v, Error **errp) int fd =3D vdev->vbasedev.fd; int ret; =20 - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_GFX, - VFIO_REGION_SUBTYPE_GFX_EDID, - &dpy->edid_info); + ret =3D vfio_device_get_region_info_type(&vdev->vbasedev, + VFIO_REGION_TYPE_GFX, + VFIO_REGION_SUBTYPE_GFX_EDID, + &dpy->edid_info); if (ret) { /* Failed to get GFX edid info, allow to go through without edid. = */ return true; diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 265fffc2aa52d032ba619b1c3759ecebad438033..6678e0e5cd8c1e3bf489e185086= ee703d657d4bd 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -200,7 +200,7 @@ static bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *= vdev, Error **errp) return false; } =20 - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, + ret =3D vfio_device_get_region_info_type(&vdev->vbasedev, VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion); if (ret) { @@ -385,7 +385,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice= *vdev, Error **errp) * Check whether we have all the vfio device specific regions to * support LPC quirk (added in Linux v4.6). */ - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, + ret =3D vfio_device_get_region_info_type(&vdev->vbasedev, VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc); if (ret) { @@ -393,7 +393,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice= *vdev, Error **errp) return false; } =20 - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, + ret =3D vfio_device_get_region_info_type(&vdev->vbasedev, VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); if (ret) { @@ -542,8 +542,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vd= ev, Error **errp) * there's no ROM, there's no point in setting up this quirk. * NB. We only seem to get BIOS ROMs, so UEFI VM would need CSM su= pport. */ - ret =3D vfio_get_region_info(&vdev->vbasedev, - VFIO_PCI_ROM_REGION_INDEX, &rom); + ret =3D vfio_device_get_region_info(&vdev->vbasedev, + VFIO_PCI_ROM_REGION_INDEX, &rom); if ((ret || !rom->size) && !vdev->pdev.romfile) { error_setg(&err, "Device has no ROM"); goto error; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index bade3b80d7d98125cf84e13f0d34009b6c46992e..6fa7217db8dce10749c8cf35658= 376562fff8d42 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -115,7 +115,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev) =20 vdev->intx.pending =3D false; pci_irq_deassert(&vdev->pdev); - vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX); } =20 static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) @@ -131,7 +131,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) =20 /* Get to a known interrupt state */ qemu_set_fd_handler(irq_fd, NULL, NULL, vdev); - vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; pci_irq_deassert(&vdev->pdev); =20 @@ -149,15 +149,15 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev,= Error **errp) goto fail_irqfd; } =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, = 0, - VFIO_IRQ_SET_ACTION_UNMASK, - event_notifier_get_fd(&vdev->intx.unmask), - errp)) { + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_= INDEX, 0, + VFIO_IRQ_SET_ACTION_UNMASK, + event_notifier_get_fd(&vdev->intx.u= nmask), + errp)) { goto fail_vfio; } =20 /* Let'em rip */ - vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); =20 vdev->intx.kvm_accel =3D true; =20 @@ -172,7 +172,7 @@ fail_irqfd: event_notifier_cleanup(&vdev->intx.unmask); fail: qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev); - vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); return false; #else return true; @@ -190,7 +190,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) * Get to a known state, hardware masked, QEMU ready to accept new * interrupts, QEMU IRQ de-asserted. */ - vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; pci_irq_deassert(&vdev->pdev); =20 @@ -210,7 +210,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) vdev->intx.kvm_accel =3D false; =20 /* If we've missed an event, let it re-fire through QEMU */ - vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); =20 trace_vfio_intx_disable_kvm(vdev->vbasedev.name); #endif @@ -299,7 +299,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) fd =3D event_notifier_get_fd(&vdev->intx.interrupt); qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev); =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, = 0, + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_= INDEX, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->intx.interrupt); @@ -322,7 +322,7 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev) =20 timer_del(vdev->intx.mmap_timer); vfio_intx_disable_kvm(vdev); - vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; pci_irq_deassert(&vdev->pdev); vfio_mmap_set_enabled(vdev, true); @@ -578,7 +578,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, =20 if (!vdev->defer_kvm_irq_routing) { if (vdev->msix->noresize && resizing) { - vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX= ); + vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_IND= EX); ret =3D vfio_enable_vectors(vdev, true); if (ret) { error_report("vfio: failed to enable vectors, %d", ret); @@ -593,7 +593,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, fd =3D event_notifier_get_fd(&vector->interrupt); } =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX, nr, VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { @@ -638,7 +638,7 @@ static void vfio_msix_vector_release(PCIDevice *pdev, u= nsigned int nr) int32_t fd =3D event_notifier_get_fd(&vector->interrupt); Error *err =3D NULL; =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_IND= EX, + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_= IRQ_INDEX, nr, VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); @@ -835,7 +835,7 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev) * Always clear MSI-X IRQ index. A PF device could have enabled * MSI-X with no vectors. See vfio_msix_enable(). */ - vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX); + vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX); =20 vfio_msi_disable_common(vdev); if (!vfio_intx_enable(vdev, &err)) { @@ -852,7 +852,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev) { Error *err =3D NULL; =20 - vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSI_IRQ_INDEX); + vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_MSI_IRQ_INDEX); vfio_msi_disable_common(vdev); vfio_intx_enable(vdev, &err); if (err) { @@ -886,8 +886,8 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) off_t off =3D 0; ssize_t bytes; =20 - if (vfio_get_region_info(&vdev->vbasedev, - VFIO_PCI_ROM_REGION_INDEX, ®_info)) { + if (vfio_device_get_region_info(&vdev->vbasedev, + VFIO_PCI_ROM_REGION_INDEX, ®_info))= { error_report("vfio: Error getting ROM info: %m"); return; } @@ -1380,8 +1380,8 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevice = *vdev) * If the host driver allows mapping of a MSIX data, we are going to * do map the entire BAR and emulate MSIX table on top of that. */ - if (vfio_has_region_cap(&vdev->vbasedev, region->nr, - VFIO_REGION_INFO_CAP_MSIX_MAPPABLE)) { + if (vfio_device_has_region_cap(&vdev->vbasedev, region->nr, + VFIO_REGION_INFO_CAP_MSIX_MAPPABLE)) { return; } =20 @@ -2673,7 +2673,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) g_autofree struct vfio_region_info *reg_info =3D NULL; int ret; =20 - ret =3D vfio_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDEX, ®= _info); + ret =3D vfio_device_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDE= X, ®_info); if (ret) { error_setg_errno(errp, -ret, "failed getting region info for VGA region index = %d", @@ -2771,8 +2771,8 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) QLIST_INIT(&vdev->bars[i].quirks); } =20 - ret =3D vfio_get_region_info(vbasedev, - VFIO_PCI_CONFIG_REGION_INDEX, ®_info); + ret =3D vfio_device_get_region_info(vbasedev, + VFIO_PCI_CONFIG_REGION_INDEX, ®_i= nfo); if (ret) { error_setg_errno(errp, -ret, "failed to get config info"); return false; @@ -2816,7 +2816,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) =20 static void vfio_pci_put_device(VFIOPCIDevice *vdev) { - vfio_detach_device(&vdev->vbasedev); + vfio_device_detach(&vdev->vbasedev); =20 g_free(vdev->vbasedev.name); g_free(vdev->msix); @@ -2868,8 +2868,8 @@ static void vfio_register_err_notifier(VFIOPCIDevice = *vdev) fd =3D event_notifier_get_fd(&vdev->err_notifier); qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev); =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_I= NDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->err_notifier); @@ -2885,8 +2885,8 @@ static void vfio_unregister_err_notifier(VFIOPCIDevic= e *vdev) return; } =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_I= NDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } qemu_set_fd_handler(event_notifier_get_fd(&vdev->err_notifier), @@ -2933,8 +2933,8 @@ static void vfio_register_req_notifier(VFIOPCIDevice = *vdev) fd =3D event_notifier_get_fd(&vdev->req_notifier); qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev); =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_I= NDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->req_notifier); @@ -2951,8 +2951,8 @@ static void vfio_unregister_req_notifier(VFIOPCIDevic= e *vdev) return; } =20 - if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_I= NDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } qemu_set_fd_handler(event_notifier_get_fd(&vdev->req_notifier), @@ -3015,7 +3015,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) name =3D g_strdup(vbasedev->name); } =20 - if (!vfio_attach_device(name, vbasedev, + if (!vfio_device_attach(name, vbasedev, pci_device_iommu_address_space(pdev), errp)) { goto error; } diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index ca6528cc568db4f4666fea70896a39b650642679..49cd9816c3d8fc3c8e50032b307= e9fe1b312240c 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -119,8 +119,8 @@ static int vfio_set_trigger_eventfd(VFIOINTp *intp, =20 qemu_set_fd_handler(fd, (IOHandler *)handler, NULL, intp); =20 - if (!vfio_set_irq_signaling(vbasedev, intp->pin, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { + if (!vfio_device_irq_set_signaling(vbasedev, intp->pin, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name); qemu_set_fd_handler(fd, NULL, NULL, NULL); return -EINVAL; @@ -301,7 +301,7 @@ static void vfio_platform_eoi(VFIODevice *vbasedev) =20 if (vfio_irq_is_automasked(intp)) { /* unmasks the physical level-sensitive IRQ */ - vfio_unmask_single_irqindex(vbasedev, intp->pin); + vfio_device_irq_unmask(vbasedev, intp->pin); } =20 /* a single IRQ can be active at a time */ @@ -357,8 +357,8 @@ static int vfio_set_resample_eventfd(VFIOINTp *intp) Error *err =3D NULL; =20 qemu_set_fd_handler(fd, NULL, NULL, NULL); - if (!vfio_set_irq_signaling(vbasedev, intp->pin, 0, - VFIO_IRQ_SET_ACTION_UNMASK, fd, &err)) { + if (!vfio_device_irq_set_signaling(vbasedev, intp->pin, 0, + VFIO_IRQ_SET_ACTION_UNMASK, fd, &er= r)) { error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name); return -EINVAL; } @@ -546,7 +546,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev,= Error **errp) return false; } =20 - if (!vfio_attach_device(vbasedev->name, vbasedev, + if (!vfio_device_attach(vbasedev->name, vbasedev, &address_space_memory, errp)) { return false; } @@ -555,7 +555,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev,= Error **errp) return true; } =20 - vfio_detach_device(vbasedev); + vfio_device_detach(vbasedev); return false; } =20 diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 010b5241e15c2063051fd780c335fef80f214dc1..04bf9eb0987c0ac460e0a1c3ba5= abdf4a87f7499 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -185,7 +185,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, g_autofree struct vfio_region_info *info =3D NULL; int ret; =20 - ret =3D vfio_get_region_info(vbasedev, index, &info); + ret =3D vfio_device_get_region_info(vbasedev, index, &info); if (ret) { return ret; } diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index ddb1bcc24a9cdc405713ca04d4ecc3d4a923ec42..8843560576935232a68a31d43e0= 0be520e0284be 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -37,8 +37,6 @@ vfio_pci_hot_reset_dep_devices(int domain, int bus, int s= lot, int function, int vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot re= set: %s" vfio_populate_device_config(const char *name, unsigned long size, unsigned= long offset, unsigned long flags) "Device '%s' config: size: 0x%lx, offset= : 0x%lx, flags: 0x%lx" vfio_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DEVICE= _GET_IRQ_INFO failure: %s" -vfio_attach_device(const char *name, int group_id) " (%s) group %d" -vfio_detach_device(const char *name, int group_id) " (%s) group %d" vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d" vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) = "%s 0x%x@0x%x" vfio_pci_reset(const char *name) " (%s)" @@ -196,5 +194,7 @@ iommufd_cdev_device_info(char *name, int devfd, int num= _irqs, int num_regions, i iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int = function, int dev_id) "\t%04x:%02x:%02x.%x devid %d" =20 # device.c -vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%08x" -vfio_reset_handler(void) "" +vfio_device_get_region_info_type(const char *name, int index, uint32_t typ= e, uint32_t subtype) "%s index %d, %08x/%08x" +vfio_device_reset_handler(void) "" +vfio_device_attach(const char *name, int group_id) " (%s) group %d" +vfio_device_detach(const char *name, int group_id) " (%s) group %d" --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571210; cv=none; d=zohomail.com; s=zohoarc; b=W+JpXjaVdsC4oph5+PjxDPy833XF2uHj+9ghll5TJBayAuYI0DQw8OPjY/yz6TKUfpSvR8M9g7PQjxD60HZ4QmJcQWqyroylf1RG/cVHi95bKi8kAKOv/iLdgENlUnHI0iH7/U7UJ7a1o0jDa64C+GngHR9A8xr7cwrbJAoKz8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571210; 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=BvJlNORlneKHi5ob12fe7KJ2GeRtlkxIJ2qq72rjAto=; b=ghxMEy/R+lItUg9rN1zb1Js5g6dU1udryHKoByniiKm4N0k2VpTs4nRYY8isCvU2WvClPigcyXrx/XHD/IqFsX7UaUNsEKAVeG+X8nr60OngtI6CSPA2He6pPTJmwZq9y8xnNfwU0g3hzAS2CyVPbu2RDCQ7FrPXzO2xoBLyk0A= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571210184978.5816233636975; Fri, 25 Apr 2025 01:53:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8ElH-0008Bh-Hv; Fri, 25 Apr 2025 04:50:20 -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 1u8EkD-0006cF-Ds for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:14 -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 1u8EkB-0003Ls-9U for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:13 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-_fpXt7L8MTy6rRupX9B3YQ-1; Fri, 25 Apr 2025 04:49:05 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D52151801A04; Fri, 25 Apr 2025 08:49:03 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6195E30001AB; Fri, 25 Apr 2025 08:49:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570950; 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=BvJlNORlneKHi5ob12fe7KJ2GeRtlkxIJ2qq72rjAto=; b=aNyzK25KLHAAJL3jmBMB8nJNBM8GIEJNsv9eAPAcvoMMi5d5fwSMxZIBz0eUO8UwwnX1r/ LNUli9kXEwHCejN/wTHOqmDF12gYPB+SMkQu6zKdk6ZC9b09dkS82qz/wKPdZkVpa4jlqW zCyjBVZVxE1elQ73kdmQEUlOFkjvHTg= X-MC-Unique: _fpXt7L8MTy6rRupX9B3YQ-1 X-Mimecast-MFC-AGG-ID: _fpXt7L8MTy6rRupX9B3YQ_1745570943 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon , Zhenzhong Duan Subject: [PULL 41/50] vfio: Rename VFIOContainer related services Date: Fri, 25 Apr 2025 10:46:34 +0200 Message-ID: <20250425084644.102196-42-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571211074019000 Rename these routines : vfio_put_group -> vfio_group_put vfio_get_group -> vfio_group_get vfio_kvm_device_del_group -> vfio_group_del_kvm_device vfio_kvm_device_add_group -> vfio_group_add_kvm_device vfio_get_device -> vfio_device_get vfio_put_base_device -> vfio_device_put vfio_device_groupid -> vfio_device_get_groupid vfio_connect_container -> vfio_container_connect vfio_disconnect_container -> vfio_container_disconnect to better reflect the namespace they belong to. Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-30-clg@redha= t.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-38-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 52 ++++++++++++++++++++++---------------------- hw/vfio/trace-events | 12 +++++----- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 149ea26aff5960a40b50ff64762d52d01b11be5c..717774760393fd01df968cee97d= de132936581ad 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -306,7 +306,7 @@ static bool vfio_get_info_iova_range(struct vfio_iommu_= type1_info *info, return true; } =20 -static void vfio_kvm_device_add_group(VFIOGroup *group) +static void vfio_group_add_kvm_device(VFIOGroup *group) { Error *err =3D NULL; =20 @@ -315,7 +315,7 @@ static void vfio_kvm_device_add_group(VFIOGroup *group) } } =20 -static void vfio_kvm_device_del_group(VFIOGroup *group) +static void vfio_group_del_kvm_device(VFIOGroup *group) { Error *err =3D NULL; =20 @@ -511,7 +511,7 @@ static bool vfio_legacy_setup(VFIOContainerBase *bconta= iner, Error **errp) return true; } =20 -static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as, +static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as, Error **errp) { VFIOContainer *container; @@ -569,7 +569,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, } group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_nex= t); - vfio_kvm_device_add_group(group); + vfio_group_add_kvm_device(group); return true; } } @@ -609,7 +609,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, goto enable_discards_exit; } =20 - vfio_kvm_device_add_group(group); + vfio_group_add_kvm_device(group); =20 vfio_address_space_insert(space, bcontainer); =20 @@ -625,7 +625,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, return true; listener_release_exit: QLIST_REMOVE(group, container_next); - vfio_kvm_device_del_group(group); + vfio_group_del_kvm_device(group); vfio_listener_unregister(bcontainer); if (vioc->release) { vioc->release(bcontainer); @@ -649,7 +649,7 @@ put_space_exit: return false; } =20 -static void vfio_disconnect_container(VFIOGroup *group) +static void vfio_container_disconnect(VFIOGroup *group) { VFIOContainer *container =3D group->container; VFIOContainerBase *bcontainer =3D &container->bcontainer; @@ -678,7 +678,7 @@ static void vfio_disconnect_container(VFIOGroup *group) if (QLIST_EMPTY(&container->group_list)) { VFIOAddressSpace *space =3D bcontainer->space; =20 - trace_vfio_disconnect_container(container->fd); + trace_vfio_container_disconnect(container->fd); vfio_cpr_unregister_container(bcontainer); close(container->fd); object_unref(container); @@ -687,7 +687,7 @@ static void vfio_disconnect_container(VFIOGroup *group) } } =20 -static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **er= rp) +static VFIOGroup *vfio_group_get(int groupid, AddressSpace *as, Error **er= rp) { ERRP_GUARD(); VFIOGroup *group; @@ -731,7 +731,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSp= ace *as, Error **errp) group->groupid =3D groupid; QLIST_INIT(&group->device_list); =20 - if (!vfio_connect_container(group, as, errp)) { + if (!vfio_container_connect(group, as, errp)) { error_prepend(errp, "failed to setup container for group %d: ", groupid); goto close_fd_exit; @@ -750,7 +750,7 @@ free_group_exit: return NULL; } =20 -static void vfio_put_group(VFIOGroup *group) +static void vfio_group_put(VFIOGroup *group) { if (!group || !QLIST_EMPTY(&group->device_list)) { return; @@ -759,15 +759,15 @@ static void vfio_put_group(VFIOGroup *group) if (!group->ram_block_discard_allowed) { vfio_ram_block_discard_disable(group->container, false); } - vfio_kvm_device_del_group(group); - vfio_disconnect_container(group); + vfio_group_del_kvm_device(group); + vfio_container_disconnect(group); QLIST_REMOVE(group, next); - trace_vfio_put_group(group->fd); + trace_vfio_group_put(group->fd); close(group->fd); g_free(group); } =20 -static bool vfio_get_device(VFIOGroup *group, const char *name, +static bool vfio_device_get(VFIOGroup *group, const char *name, VFIODevice *vbasedev, Error **errp) { g_autofree struct vfio_device_info *info =3D NULL; @@ -819,25 +819,25 @@ static bool vfio_get_device(VFIOGroup *group, const c= har *name, vbasedev->num_regions =3D info->num_regions; vbasedev->flags =3D info->flags; =20 - trace_vfio_get_device(name, info->flags, info->num_regions, info->num_= irqs); + trace_vfio_device_get(name, info->flags, info->num_regions, info->num_= irqs); =20 vbasedev->reset_works =3D !!(info->flags & VFIO_DEVICE_FLAGS_RESET); =20 return true; } =20 -static void vfio_put_base_device(VFIODevice *vbasedev) +static void vfio_device_put(VFIODevice *vbasedev) { if (!vbasedev->group) { return; } QLIST_REMOVE(vbasedev, next); vbasedev->group =3D NULL; - trace_vfio_put_base_device(vbasedev->fd); + trace_vfio_device_put(vbasedev->fd); close(vbasedev->fd); } =20 -static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) +static int vfio_device_get_groupid(VFIODevice *vbasedev, Error **errp) { char *tmp, group_path[PATH_MAX]; g_autofree char *group_name =3D NULL; @@ -872,7 +872,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Er= ror **errp) static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbased= ev, AddressSpace *as, Error **errp) { - int groupid =3D vfio_device_groupid(vbasedev, errp); + int groupid =3D vfio_device_get_groupid(vbasedev, errp); VFIODevice *vbasedev_iter; VFIOGroup *group; VFIOContainerBase *bcontainer; @@ -887,7 +887,7 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, return false; } =20 - group =3D vfio_get_group(groupid, as, errp); + group =3D vfio_group_get(groupid, as, errp); if (!group) { return false; } @@ -895,12 +895,12 @@ static bool vfio_legacy_attach_device(const char *nam= e, VFIODevice *vbasedev, 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); + vfio_group_put(group); return false; } } - if (!vfio_get_device(group, name, vbasedev, errp)) { - vfio_put_group(group); + if (!vfio_device_get(group, name, vbasedev, errp)) { + vfio_group_put(group); return false; } =20 @@ -920,8 +920,8 @@ static void vfio_legacy_detach_device(VFIODevice *vbase= dev) QLIST_REMOVE(vbasedev, container_next); vbasedev->bcontainer =3D NULL; trace_vfio_device_detach(vbasedev->name, group->groupid); - vfio_put_base_device(vbasedev); - vfio_put_group(group); + vfio_device_put(vbasedev); + vfio_group_put(group); } =20 static int vfio_legacy_pci_hot_reset(VFIODevice *vbasedev, bool single) diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 8843560576935232a68a31d43e00be520e0284be..e90ec9bff8d5fa51afde7b55fb7= 36a8d51fef1b0 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -99,16 +99,18 @@ vfio_listener_region_add_no_dma_map(const char *name, u= int64_t iova, uint64_t si vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRI= x64" - 0x%"PRIx64 vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t m= in, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"= - 0x%"PRIx64"]" vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t m= ax32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr= _ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], = pci64:[0x%"PRIx64" - 0x%"PRIx64"]" -vfio_disconnect_container(int fd) "close container->fd=3D%d" -vfio_put_group(int fd) "close group->fd=3D%d" -vfio_get_device(const char * name, unsigned int flags, unsigned int num_re= gions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u" -vfio_put_base_device(int fd) "close vdev->fd=3D%d" -vfio_legacy_dma_unmap_overflow_workaround(void) "" vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu= dirty @ 0x%"PRIx64" - 0x%"PRIx64 =20 # container-base.c vfio_container_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t b= itmap_size, uint64_t start, uint64_t dirty_pages) "iova=3D0x%"PRIx64" size= =3D 0x%"PRIx64" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64" dirty_pages= =3D%"PRIu64 =20 +# container.c +vfio_container_disconnect(int fd) "close container->fd=3D%d" +vfio_group_put(int fd) "close group->fd=3D%d" +vfio_device_get(const char * name, unsigned int flags, unsigned int num_re= gions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u" +vfio_device_put(int fd) "close vdev->fd=3D%d" +vfio_legacy_dma_unmap_overflow_workaround(void) "" + # region.c vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint= 64_t data) " (%s:region%d+0x%"PRIx64", %d) =3D 0x%"PRIx64 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571299; cv=none; d=zohomail.com; s=zohoarc; b=BJPxZWbUp/303gpckWuTU7OpHI9uOTijl0AMT5lSZ/aQl7AAoWp9tmCNznVdgeHNRqOsafYoVgO9+XJgOwQcTHguEuI9Z5s0+RqVc2T0t9iuCaseYsxQ2bjTohgSn92d0pt9NJ79HUQem6zKbNzBG005bQOA0NlGfUxXULEe4Ww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571299; 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=1f/kohsPKe3cF4asAdnNPaEea5S2iDigFAmeraVY5lI=; b=HM76WQ201aeQT3DFcUHPiOG+rO+bWGBoziH8bkUvf9bL+gg1hQeVZcZPbcTYAgm5z+BWf4iC5KNBPQEfuflrnK7Ib6xCmgfBg08eOmvFIhcaToG04qLuUp1v/vGNH6XTgOnHUEyx3JjrL2TGSAh8YLWCVwIx6JZ19qKokpJ/HlA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571299907348.23612224807937; Fri, 25 Apr 2025 01:54:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ekp-0007XB-Ag; Fri, 25 Apr 2025 04:49:52 -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 1u8EkB-0006ar-Gu for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Ek9-0003Lk-S9 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:11 -0400 Received: from mx-prod-mc-01.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-655-B385vqz8PD627Yq2h7I77w-1; Fri, 25 Apr 2025 04:49:07 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3635119560A7; Fri, 25 Apr 2025 08:49:06 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5BDC830001A2; Fri, 25 Apr 2025 08:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570948; 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=1f/kohsPKe3cF4asAdnNPaEea5S2iDigFAmeraVY5lI=; b=dYK4uupVM+gj4hnRCVjvUSLF9Ke76svHpgSDy/TdhYFhCZXHFX8inh0TK7JWcbdo6nrS8i u3r5rl2ZDHV+f5Mi50NxAnRSm5Ci6eECXoeBt1v0y8zfo+aGo2Rz1rO/11KtydY8d03YOl Bi8rYIAnTo7cYS/ete6Ec5pcx2EkUdc= X-MC-Unique: B385vqz8PD627Yq2h7I77w-1 X-Mimecast-MFC-AGG-ID: B385vqz8PD627Yq2h7I77w_1745570946 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 42/50] MAINTAINERS: Add a maintainer for util/vfio-helpers.c Date: Fri, 25 Apr 2025 10:46:35 +0200 Message-ID: <20250425084644.102196-43-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571301854019100 The NVMe Block device driver makes use of a reduced VFIO library managing the host interface. These routines are VFIO related and do not have a maintainer. Move util/vfio-helpers.c under VFIO jurisdiction. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20250422162954.210706-1-clg@redhat= .com Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 661a47db5acc18addd16c2433ba3b623b45a5de8..a316907e76f9fe4357ecc0e9646= aa3a000008c15 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2197,6 +2197,7 @@ M: Alex Williamson M: C=C3=A9dric Le Goater S: Supported F: hw/vfio/* +F: util/vfio-helpers.c F: include/hw/vfio/ F: docs/devel/migration/vfio.rst F: qapi/vfio.json --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571320; cv=none; d=zohomail.com; s=zohoarc; b=QE6c8xH4exHZJB/e8G0y8xyAEYj6TLtlui3RIHxYQYQPcY1gFAmSAjLcBkcV+GgKwkKtOZn2y5ZLrq9eFEzE6IzM/GjczMqViDyq0kcOor/K+gn9UfsDPD1PH78uQq0l1HSkAnWs0i6tucoJ1QzZePPsXEAMJxvhMrykgV/nkEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571320; 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=P+Pk0pEVpcphFt3MWViW47vqavSRO+1rXqbAxFBRldQ=; b=CBlZ3BQrRvLHUjRXobKwcNaJhHXGuxDd9WxQcvfUDVP8r5oV6jGzRp3bdkFyXQwUnRhPRmnFo4USnbIemZGYVWw7p3VU2SWgyQH86W+Q/lH5jMzuD7MnxcagwHvha0+EHjK0AiCBIRgIhFs7yfy+/YvEgczuqf9hAPCtX65OiV4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571320073907.721023412072; Fri, 25 Apr 2025 01:55:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8ElV-0000t1-Qy; Fri, 25 Apr 2025 04:50:37 -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 1u8EkD-0006cG-JV for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:14 -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 1u8EkB-0003M2-T0 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:13 -0400 Received: from mx-prod-mc-01.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-74-lkaO_CEiO_K_7cd0h-amBA-1; Fri, 25 Apr 2025 04:49:09 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ABAD519560A7; Fri, 25 Apr 2025 08:49:08 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B81A330001A2; Fri, 25 Apr 2025 08:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570951; 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=P+Pk0pEVpcphFt3MWViW47vqavSRO+1rXqbAxFBRldQ=; b=ND6fb0ZQmKutT0yaNb4q9UjMK4V4LK1rdFydfwo5HzaNiFEcBHqENM6lDvF55zgm71Abm0 Otta8dJHuzAiT2LPvgGAywscAfxGA8WgbpLafDelWDd6/35kZ9t1sFAUl9lzoRMYOCPGJw 3SeK4NgIxIYR8lrXBAqjNRXGantl6t8= X-MC-Unique: lkaO_CEiO_K_7cd0h-amBA-1 X-Mimecast-MFC-AGG-ID: lkaO_CEiO_K_7cd0h-amBA_1745570948 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Joao Martins Subject: [PULL 43/50] vfio/iommufd: Make a separate call to get IOMMU capabilities Date: Fri, 25 Apr 2025 10:46:36 +0200 Message-ID: <20250425084644.102196-44-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571323674019100 From: Zhenzhong Duan Currently we depend on .realize() calling iommufd_backend_get_device_info() to get IOMMU capabilities and check for dirty page tracking support. By make a extra separate call, this dependency is removed. This happens only during device attach, it's not a hot path. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-2-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 48db10542269111804643713270199657145accc..2253778b3ae0738f0a48dca77f0= b68180b7d1f71 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -287,7 +287,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, { ERRP_GUARD(); IOMMUFDBackend *iommufd =3D vbasedev->iommufd; - uint32_t flags =3D 0; + uint32_t type, flags =3D 0; + uint64_t hw_caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; int ret; @@ -324,7 +325,12 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, * vfio_migration_realize() may decide to use VF dirty tracking * instead. */ - if (vbasedev->hiod->caps.hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) { + if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devi= d, + &type, NULL, 0, &hw_caps, errp)) { + return false; + } + + if (hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) { flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; } =20 --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571364; cv=none; d=zohomail.com; s=zohoarc; b=cT2wgc9PYAHByuo0Mf+s8vdHVfCWu/RZ7KWXcydqdlTeFYnM6qPTvxUUkn6d79PRm9vYAZQwc58bE5hayK3s088CkMVyoiAK2QlkyA6G3yjTNGHWzS+HVtDjtMG7q1/5mUnQumxY4M7MNXClWzwsFJSF+1v1zUafIHuASpYQT6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571364; 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=EWDzgC69mysZy0cadpTCRqedDgSpvxf5w+EQapY63hg=; b=Ew5749N4DxzAyQyEnC9BRgCPo8G5zr7Uo/vj0yAqJm2KXNf7XCi4bLdmryH8k/92xenh/Rbl05CIruT2Ux1rRuBgDFmszUgzvxaCVKWRBSlnyd71DgInKLI0euJIMRQp+4bNQDTvujqYsQVGYv8w5xaUhMq8TpgUU5E9M3uMV/g= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571364387164.42982106991758; Fri, 25 Apr 2025 01:56:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ekq-0007dE-Qd; Fri, 25 Apr 2025 04:49:54 -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 1u8EkI-0006tB-T9 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EkG-0003MV-U4 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:18 -0400 Received: from mx-prod-mc-01.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-633-oqI7bhEtM1ya1YyH9cQQUA-1; Fri, 25 Apr 2025 04:49:12 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 88875195608C; Fri, 25 Apr 2025 08:49:11 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 33BFA30001A2; Fri, 25 Apr 2025 08:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570956; 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=EWDzgC69mysZy0cadpTCRqedDgSpvxf5w+EQapY63hg=; b=bGqi35rU0mF/31rxAFCrs5DSwKth4IlaQjulusoKfQiaGeU5WqI6nCNlKw74MqiSvkMILV 1WF2F0WjBiDGfZGP63YICE7fg065zXJW88mYkhpv03/ckjE2NEMjISG6/kOKBcVhEN0LMA F0aK8VdGXeglRSdZFtBx4DBtAKgx9Wo= X-MC-Unique: oqI7bhEtM1ya1YyH9cQQUA-1 X-Mimecast-MFC-AGG-ID: oqI7bhEtM1ya1YyH9cQQUA_1745570951 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Donald Dutile , Joao Martins Subject: [PULL 44/50] vfio/iommufd: Move realize() after attachment Date: Fri, 25 Apr 2025 10:46:37 +0200 Message-ID: <20250425084644.102196-45-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571365373019000 From: Zhenzhong Duan Previously device attaching depends on realize() getting host IOMMU capabilities to check dirty tracking support. Now we have a separate call to ioctl(IOMMU_GET_HW_INFO) to get host IOMMU capabilities and check that for dirty tracking support, there is no dependency any more, move realize() call after attachment succeed. Suggested-by: C=C3=A9dric Le Goater Suggested-by: Donald Dutile Signed-off-by: Zhenzhong Duan Reviewed-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-3-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 2253778b3ae0738f0a48dca77f0b68180b7d1f71..f273dc87127075e4ff2f3781a49= 757dfb628da27 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -500,17 +500,6 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, =20 space =3D vfio_address_space_get(as); =20 - /* - * The HostIOMMUDevice data from legacy backend is static and doesn't = need - * any information from the (type1-iommu) backend to be initialized. In - * contrast however, the IOMMUFD HostIOMMUDevice data requires the iom= mufd - * FD to be connected and having a devid to be able to successfully ca= ll - * iommufd_backend_get_device_info(). - */ - if (!vfio_device_hiod_realize(vbasedev, errp)) { - goto err_alloc_ioas; - } - /* try to attach to an existing container in this space */ QLIST_FOREACH(bcontainer, &space->containers, next) { container =3D container_of(bcontainer, VFIOIOMMUFDContainer, bcont= ainer); @@ -585,6 +574,10 @@ found_container: goto err_listener_register; } =20 + if (!vfio_device_hiod_realize(vbasedev, errp)) { + goto err_hiod_realize; + } + /* * TODO: examine RAM_BLOCK_DISCARD stuff, should we do group level * for discarding incompatibility check as well? @@ -606,6 +599,8 @@ found_container: vbasedev->num_regions, vbasedev->flags); return true; =20 +err_hiod_realize: + vfio_cpr_unregister_container(bcontainer); err_listener_register: iommufd_cdev_ram_block_discard_disable(false); err_discard_disable: --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571334; cv=none; d=zohomail.com; s=zohoarc; b=VjoAG+c2d5cf8hPCAgqkHmjcShSlzt2Xs0WyLrDbD7AnuBelyZNwCcqb7o7XSjQ4lu8fOgzSjTpSMd2cyWqC2pIOFSLOhUzquUMAwnf/xuU2MDV7mbohOtr9U2WTM27JWIyV/y40z/KS/cltrRsq1uDm0RLfBcNuEqzJHMn7nb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571334; 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=VFAwmtqUTv3QoXjuA0B+bmPamh40DSZXEv1qN59o1zY=; b=EkGg1gkykjCSZ1TblyTADiaRA8jAw1qFJogp8sIeh3+3HfaIv2A1YB5XlZwLz1uxnYu2XLmXMsY/jFvX27mKLNLZ7ioPzwzRTnYO/vjhvQIQn3Y82e9ysdm6lAtafQpp1ZrN6x2HE+xVGAAHtPi2ZNkz8uQcg1On0X7GaYdRGhw= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571334047898.9520223942526; Fri, 25 Apr 2025 01:55:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8ElV-0000to-Qd; Fri, 25 Apr 2025 04:50:37 -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 1u8EkM-0006zi-Pv for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EkK-0003Mu-4g for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:22 -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-447-F2WYfzbWP1GAyYJIWUh-ig-1; Fri, 25 Apr 2025 04:49:15 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 249461956089; Fri, 25 Apr 2025 08:49:14 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1013330001A2; Fri, 25 Apr 2025 08:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570959; 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=VFAwmtqUTv3QoXjuA0B+bmPamh40DSZXEv1qN59o1zY=; b=Y77BJciigK8EfXFFtwtRgOe7EPon+VFDY6f49ONTSvl0VgTaRna788pKxqguheJ5N1toNM UbtkbGHTuARdDGRq9DMkkWmWE5DVpXqxFjRhHNTZ0bY0uDA5jA0BMAWjLIA/XL17ZmsUNe 2c16KHS932rITC4g3/TYenXwspTa1go= X-MC-Unique: F2WYfzbWP1GAyYJIWUh-ig-1 X-Mimecast-MFC-AGG-ID: F2WYfzbWP1GAyYJIWUh-ig_1745570954 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Donald Dutile Subject: [PULL 45/50] vfio/container: Move realize() after attachment Date: Fri, 25 Apr 2025 10:46:38 +0200 Message-ID: <20250425084644.102196-46-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571335222019000 From: Zhenzhong Duan To match the change for IOMMUFD backend, move realize() after attachment for legacy backend too. Suggested-by: C=C3=A9dric Le Goater Suggested-by: Donald Dutile Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-4-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 717774760393fd01df968cee97dde132936581ad..652a6197ceaff96399f16f4727e= a3188eafec4dc 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -883,10 +883,6 @@ static bool vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, =20 trace_vfio_device_attach(vbasedev->name, groupid); =20 - if (!vfio_device_hiod_realize(vbasedev, errp)) { - return false; - } - group =3D vfio_group_get(groupid, as, errp); if (!group) { return false; @@ -895,13 +891,15 @@ static bool vfio_legacy_attach_device(const char *nam= e, VFIODevice *vbasedev, 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_group_put(group); - return false; + goto group_put_exit; } } if (!vfio_device_get(group, name, vbasedev, errp)) { - vfio_group_put(group); - return false; + goto group_put_exit; + } + + if (!vfio_device_hiod_realize(vbasedev, errp)) { + goto device_put_exit; } =20 bcontainer =3D &group->container->bcontainer; @@ -910,6 +908,12 @@ static bool vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); =20 return true; + +device_put_exit: + vfio_device_put(vbasedev); +group_put_exit: + vfio_group_put(group); + return false; } =20 static void vfio_legacy_detach_device(VFIODevice *vbasedev) --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571217; cv=none; d=zohomail.com; s=zohoarc; b=cvOxQ7TPpeMH5Y8q1foQOxwq0ZrGPkLT4UDQ5Fu1HsEazPLy5FPlzBooU2vvXd+DUJoDSvSM+I2WxtWOwnI/dtHLbidCMwUjDBm7dyvXjXRBzbfHH+Puupb4ZkfTk2PEaQSzvQL53GlOrqCMIKY2wLeEUHMtY4pejT2jpjLlKGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571217; 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=aMOAoBVc7BaKcWu6OylWK+5uEVey7Rp74m+rA7vNbGk=; b=KDto8wdlrYf56XdTlvFzMlqZHhXqfLmU4PNY9iNzxFnYRDQbv/KwyHygQPqxTJ6JAi3ERwWR/jOsEixR6aw2I0qYu9Q6oZoLEo6k0mLLPfs6IpgbDeAIC/WD11SAmWkLWx5xhr0Nh11xu/jelied+wwafZgwS0UFZr/efCoOgQQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571217694500.472275655698; Fri, 25 Apr 2025 01:53:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Ell-0001XE-Rd; Fri, 25 Apr 2025 04:50:50 -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 1u8EkO-000708-HI for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:26 -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 1u8EkL-0003N2-Sx for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:24 -0400 Received: from mx-prod-mc-04.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-638-imI24BznNFKg4D4Ua8GZjg-1; Fri, 25 Apr 2025 04:49:17 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 528021955DC5; Fri, 25 Apr 2025 08:49:16 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A00BE30001A2; Fri, 25 Apr 2025 08:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570961; 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=aMOAoBVc7BaKcWu6OylWK+5uEVey7Rp74m+rA7vNbGk=; b=YcaorBuXIgQY3SRyjIEO1l0w3WK9PuDIU6s5nMsBdefHZTkik1BkOy1bF2Dgl4hb+RGOnT 6U7UB5O8WhzpAbIjEzj9FCobPY9U76s5N4+LLczaPI27styStNia7IQYVnweDXphYKNQwm rVRmWglsw0/Wxrnrku0aAr3zru9puLI= X-MC-Unique: imI24BznNFKg4D4Ua8GZjg-1 X-Mimecast-MFC-AGG-ID: imI24BznNFKg4D4Ua8GZjg_1745570956 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 46/50] vfio: Cleanup host IOMMU device creation Date: Fri, 25 Apr 2025 10:46:39 +0200 Message-ID: <20250425084644.102196-47-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571219568019100 From: Zhenzhong Duan realize() is now moved after attachment, do the same for hiod creation. Introduce a new function vfio_device_hiod_create_and_realize() to do them all in one go. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-5-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 3 ++- hw/vfio/container.c | 5 ++++- hw/vfio/device.c | 33 ++++++++++++++------------------- hw/vfio/iommufd.c | 4 +++- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 696ed87f01038bf29df26046fa9b75051971ede3..81c95bb51eeead0e8c4d126c2d0= 561e235632946 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -123,7 +123,8 @@ bool vfio_device_irq_set_signaling(VFIODevice *vbasedev= , int index, int subindex =20 void vfio_device_reset_handler(void *opaque); bool vfio_device_is_mdev(VFIODevice *vbasedev); -bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp); +bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev, + const char *typename, Error **err= p); bool vfio_device_attach(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void vfio_device_detach(VFIODevice *vbasedev); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 652a6197ceaff96399f16f4727ea3188eafec4dc..78f70e63d6fcef09a7c12cbd015= 26701073e6952 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -898,7 +898,9 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, goto group_put_exit; } =20 - if (!vfio_device_hiod_realize(vbasedev, errp)) { + if (!vfio_device_hiod_create_and_realize(vbasedev, + TYPE_HOST_IOMMU_DEVICE_LEGACY= _VFIO, + errp)) { goto device_put_exit; } =20 @@ -924,6 +926,7 @@ static void vfio_legacy_detach_device(VFIODevice *vbase= dev) QLIST_REMOVE(vbasedev, container_next); vbasedev->bcontainer =3D NULL; trace_vfio_device_detach(vbasedev->name, group->groupid); + object_unref(vbasedev->hiod); vfio_device_put(vbasedev); vfio_group_put(group); } diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 4de6948cf472806ed639f629cc3d980f51021f2c..d625a7c4dbbf4ac222541283c40= 34e840da02b08 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -347,15 +347,24 @@ bool vfio_device_is_mdev(VFIODevice *vbasedev) return subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); } =20 -bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp) +bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev, + const char *typename, Error **err= p) { - HostIOMMUDevice *hiod =3D vbasedev->hiod; + HostIOMMUDevice *hiod; =20 - if (!hiod) { + if (vbasedev->mdev) { return true; } =20 - return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp= ); + hiod =3D HOST_IOMMU_DEVICE(object_new(typename)); + + if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp))= { + object_unref(hiod); + return false; + } + + vbasedev->hiod =3D hiod; + return true; } =20 VFIODevice *vfio_get_vfio_device(Object *obj) @@ -372,7 +381,6 @@ bool vfio_device_attach(char *name, VFIODevice *vbasede= v, { const VFIOIOMMUClass *ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); - HostIOMMUDevice *hiod =3D NULL; =20 if (vbasedev->iommufd) { ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMM= UFD)); @@ -380,19 +388,7 @@ bool vfio_device_attach(char *name, VFIODevice *vbased= ev, =20 assert(ops); =20 - - if (!vbasedev->mdev) { - hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); - vbasedev->hiod =3D hiod; - } - - if (!ops->attach_device(name, vbasedev, as, errp)) { - object_unref(hiod); - vbasedev->hiod =3D NULL; - return false; - } - - return true; + return ops->attach_device(name, vbasedev, as, errp); } =20 void vfio_device_detach(VFIODevice *vbasedev) @@ -400,6 +396,5 @@ void vfio_device_detach(VFIODevice *vbasedev) if (!vbasedev->bcontainer) { return; } - object_unref(vbasedev->hiod); VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev); } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f273dc87127075e4ff2f3781a49757dfb628da27..8a010a51ea3882ef62fd1906b97= ed3b77c5e57ef 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -574,7 +574,8 @@ found_container: goto err_listener_register; } =20 - if (!vfio_device_hiod_realize(vbasedev, errp)) { + if (!vfio_device_hiod_create_and_realize(vbasedev, + TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, errp)) { goto err_hiod_realize; } =20 @@ -630,6 +631,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) iommufd_cdev_ram_block_discard_disable(false); } =20 + object_unref(vbasedev->hiod); vfio_cpr_unregister_container(bcontainer); iommufd_cdev_detach_container(vbasedev, container); iommufd_cdev_container_destroy(container); --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571099; cv=none; d=zohomail.com; s=zohoarc; b=MjKR6jGK4o6reIfMcXM+BSZerngrFwveWZHM8131w921mPl4E5E4OHf1K/V7lOXU/YNhhwVIhdmphanPP020uy1WzBeAi1JOJZV9GbBcDKO7K2CZ+FpFUSpxqbYYq7n+4jfKPIA0iPnk0KdQFwdPG/xaM5cEYwpvcQnaW7DDzE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571099; 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=YB4bT7X5Ei4XBUUch0D+TK6fEAPbX+If5u9eieOsydE=; b=QKmfs0OGDIchr14XZS8/pJCAug4qVy1Mo6EKAOAvW8IW6rO08hF0DMgMvz+V34Nb9ffvAtfRez2fTShy8WnE8DqCw9KLUUSS4B5ke2S5KnqpGUo8l9f4iQ82HUAEnjCZtfPFUBf75OSaBU0Z+wiM7/2/ukB1VKyiMwfjm8HhBYg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571099220121.9600620918452; Fri, 25 Apr 2025 01:51:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8ElI-0008E8-L8; Fri, 25 Apr 2025 04:50:22 -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 1u8EkT-00073b-Nw for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:30 -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 1u8EkQ-0003Na-Vw for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:28 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-BT-cSXBINsy5GYsoY2QcLA-1; Fri, 25 Apr 2025 04:49:20 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5B2861800263; Fri, 25 Apr 2025 08:49:19 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF19330001A2; Fri, 25 Apr 2025 08:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570966; 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=YB4bT7X5Ei4XBUUch0D+TK6fEAPbX+If5u9eieOsydE=; b=Dvg51CubbXfLQ+5lgTZODcMuS8MkuZGQG6kTnJL6pLQ/NRxKXnTGkjKRp+tHhkMgXnVYZW BX3T5z4+LcHdkI+T0CTfGX7bFPJBEC4SrJdf81OgeNM6isjRkvFrjb0hx7EORgUeiydjRj 2zDI6Z+FVxeOhaHkQlrAXrKzPhJ4tdY= X-MC-Unique: BT-cSXBINsy5GYsoY2QcLA-1 X-Mimecast-MFC-AGG-ID: BT-cSXBINsy5GYsoY2QcLA_1745570959 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 47/50] vfio: Remove hiod_typename property Date: Fri, 25 Apr 2025 10:46:40 +0200 Message-ID: <20250425084644.102196-48-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571101224019100 From: Zhenzhong Duan Because we handle host IOMMU device creation in each container backend, we know which type name to use, so hiod_typename property is useless now, just remove it. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-6-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 3 --- hw/vfio/container.c | 2 -- hw/vfio/iommufd.c | 2 -- 3 files changed, 7 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index af63373c92359ec53eb1669edfd4deb5a5177c20..5527e027220ac05f82d2a9beaf8= b921e26597271 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -115,9 +115,6 @@ OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, = VFIO_IOMMU) struct VFIOIOMMUClass { ObjectClass parent_class; =20 - /* Properties */ - const char *hiod_typename; - /* basic feature */ bool (*setup)(VFIOContainerBase *bcontainer, Error **errp); int (*dma_map)(const VFIOContainerBase *bcontainer, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 78f70e63d6fcef09a7c12cbd01526701073e6952..29170f063465e2c428a760a0816= 03543c46f1ca3 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1103,8 +1103,6 @@ static void vfio_iommu_legacy_class_init(ObjectClass = *klass, void *data) { VFIOIOMMUClass *vioc =3D VFIO_IOMMU_CLASS(klass); =20 - vioc->hiod_typename =3D TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO; - vioc->setup =3D vfio_legacy_setup; vioc->dma_map =3D vfio_legacy_dma_map; vioc->dma_unmap =3D vfio_legacy_dma_unmap; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 8a010a51ea3882ef62fd1906b97ed3b77c5e57ef..f24054a6a5467e3b3436f106bf7= 64c7de8019b0c 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -795,8 +795,6 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *= klass, void *data) { VFIOIOMMUClass *vioc =3D VFIO_IOMMU_CLASS(klass); =20 - vioc->hiod_typename =3D TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO; - vioc->dma_map =3D iommufd_cdev_map; vioc->dma_unmap =3D iommufd_cdev_unmap; vioc->attach_device =3D iommufd_cdev_attach; --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571318; cv=none; d=zohomail.com; s=zohoarc; b=GWco4hXB8G/uWBBRZGKi+F35VjPsI6aBFHXUUQEM8OTJVcgSxJOHsVwFx2hSefSdvCJu5iZUFV3Lge6wEP6Nx4kEtVet48mZFC8LfSW8QJvzX2lcyox9d2XZ6mgYSmkO9dTTbLtDStz8emY8BCSN+jv/64orxOc5L4OOxAGz028= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571318; 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=X+aoCmiHdt5aSTQt6vuKxlPA0N2D0f+F6ijAi7/To8Y=; b=Ipv1tKtrdW9kZxFBatw2o1r9NCrxSNVKNm/jQQXHXgKFq2hAYqe1yk/QgNbwhTjxAZ0+oDcubiW2q4FaO/swCxoyVdl6rWWEPCe70B21W5cUvhSXKxC9H2SkZpE6PK5WeAV90+njacnB3CQUi8H9v/Pu00qqSd0REsF74EtT1rA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174557131822532.83168034170512; Fri, 25 Apr 2025 01:55:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8ElA-00084A-Nj; Fri, 25 Apr 2025 04:50:16 -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 1u8EkV-00077t-Ku for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EkT-0003Nq-Ul for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:31 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-ceS8g4ydPjC0-VDgJUJmLw-1; Fri, 25 Apr 2025 04:49:25 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC759180034E; Fri, 25 Apr 2025 08:49:24 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 036CC30001A2; Fri, 25 Apr 2025 08:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570969; 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=X+aoCmiHdt5aSTQt6vuKxlPA0N2D0f+F6ijAi7/To8Y=; b=Tb5hhDA/445upQEf2MSlH+RZXqTOrapsWW3eOrDGr6KTSwy3ghhEIUQE74hxuH25ynnWpq iux4Er7ZlWNIg7Wy5sJcFZ/SEjvh0ctElnDHtQr4CXZlvERWHiQsrR4H6EkFrLaxLGCdCa LvNbLwaMT0mo/yfsFVB6obRXjbsoaKk= X-MC-Unique: ceS8g4ydPjC0-VDgJUJmLw-1 X-Mimecast-MFC-AGG-ID: ceS8g4ydPjC0-VDgJUJmLw_1745570964 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 48/50] vfio: Register/unregister container for CPR only once for each container Date: Fri, 25 Apr 2025 10:46:41 +0200 Message-ID: <20250425084644.102196-49-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571319258019000 From: Zhenzhong Duan vfio_cpr_register_container and vfio_cpr_unregister_container are container scoped function. Calling them for each device attaching/detaching would corrupt CPR reboot notifier list, i.e., when two VFIO devices are attached to same container and have same notifier registered twice. Fixes: d9fa4223b30a ("vfio: register container for cpr") Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250424063355.3855174-1-zhenzhong= .duan@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f24054a6a5467e3b3436f106bf764c7de8019b0c..b2f72dc8c3687190f2c9d0f1d0a= 8bc80200930c3 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -416,6 +416,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDC= ontainer *container) if (!QLIST_EMPTY(&bcontainer->device_list)) { return; } + vfio_cpr_unregister_container(bcontainer); vfio_listener_unregister(bcontainer); iommufd_backend_free_id(container->be, container->ioas_id); object_unref(container); @@ -561,6 +562,10 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, goto err_listener_register; } =20 + if (!vfio_cpr_register_container(bcontainer, errp)) { + goto err_listener_register; + } + bcontainer->initialized =3D true; =20 found_container: @@ -570,13 +575,9 @@ found_container: goto err_listener_register; } =20 - if (!vfio_cpr_register_container(bcontainer, errp)) { - goto err_listener_register; - } - if (!vfio_device_hiod_create_and_realize(vbasedev, TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, errp)) { - goto err_hiod_realize; + goto err_listener_register; } =20 /* @@ -600,8 +601,6 @@ found_container: vbasedev->num_regions, vbasedev->flags); return true; =20 -err_hiod_realize: - vfio_cpr_unregister_container(bcontainer); err_listener_register: iommufd_cdev_ram_block_discard_disable(false); err_discard_disable: @@ -632,7 +631,6 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) } =20 object_unref(vbasedev->hiod); - vfio_cpr_unregister_container(bcontainer); iommufd_cdev_detach_container(vbasedev, container); iommufd_cdev_container_destroy(container); vfio_address_space_put(space); --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571362; cv=none; d=zohomail.com; s=zohoarc; b=UUu2voogBvFdT9MbPVG4UzKeNjWUZQPpmstJVVUP6WWfTa9Saic9EUG5b+a0H1h6d2S4W3Fm7XT4Dqn/fflFl1conES6Qaayb8xer8ZzTwI7sHoTUMpt1530NpPFKe0obM3u+xLccguVvp7LHABkX8VGy/x/weqHsC4CyPE0UM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571362; 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=sUfayGizHFTZJ8FEKZBTc5dxaP91Tf+qYs6ihVk2DQk=; b=Gm++XyWkIz2QFBM6MT0vQbCyKnSBQdvn5d/lyptv8HnYJypA1UN/8UMr7VELy0UNlEpC7YqPJxlbVDl/JL40gH4o9U8gUkpYq4BY2ZR2Pdv8sS+jvbPgMXvwiIKuOsHBV4PwW2eDyRGUKyC96cNUYGjH8U1poPkZkRP+dCSfUj4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571362919470.70190047157666; Fri, 25 Apr 2025 01:56:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8Els-000219-2K; Fri, 25 Apr 2025 04:50:56 -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 1u8Eka-0007KO-Kn for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8EkY-0003OH-QQ for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:36 -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-453-FIVecOgyNTeThqqUrv4b_g-1; Fri, 25 Apr 2025 04:49:32 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 519FC195608C; Fri, 25 Apr 2025 08:49:31 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D5F230001A2; Fri, 25 Apr 2025 08:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570974; 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=sUfayGizHFTZJ8FEKZBTc5dxaP91Tf+qYs6ihVk2DQk=; b=doRwVfS+qGDUuo2C7HxMJziA3xILmcwfzPTJu9q6AIBvNAOxtAXvsm0oJgo6TKszElTCJ5 wPB8VZEPN59lBFDNPjXB10k34tWGDuGd8s3GElM+O0PthFHNH+bzXgJbbqibWuFnW0uyid 1P/D2aIkT7lzLuHuBzw1678TgzznjbM= X-MC-Unique: FIVecOgyNTeThqqUrv4b_g-1 X-Mimecast-MFC-AGG-ID: FIVecOgyNTeThqqUrv4b_g_1745570971 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 49/50] vfio: refactor out vfio_interrupt_setup() Date: Fri, 25 Apr 2025 10:46:42 +0200 Message-ID: <20250425084644.102196-50-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571363396019000 From: John Levon Refactor the interrupt setup code out of vfio_realize() for readability. Signed-off-by: John Levon Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250409134814.478903-2-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 55 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6fa7217db8dce10749c8cf35658376562fff8d42..27cc6426a54080dfaf5b9a50e4e= 57567bdeb9063 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2962,6 +2962,38 @@ static void vfio_unregister_req_notifier(VFIOPCIDevi= ce *vdev) vdev->req_enabled =3D false; } =20 +static bool vfio_interrupt_setup(VFIOPCIDevice *vdev, Error **errp) +{ + PCIDevice *pdev =3D &vdev->pdev; + + /* QEMU emulates all of MSI & MSIX */ + if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { + memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff, + MSIX_CAP_LENGTH); + } + + if (pdev->cap_present & QEMU_PCI_CAP_MSI) { + memset(vdev->emulated_config_bits + pdev->msi_cap, 0xff, + vdev->msi_cap_size); + } + + if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) { + vdev->intx.mmap_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, + vfio_intx_mmap_enable, vdev); + pci_device_set_intx_routing_notifier(&vdev->pdev, + vfio_intx_routing_notifier); + vdev->irqchip_change_notifier.notify =3D vfio_irqchip_change; + kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier); + if (!vfio_intx_enable(vdev, errp)) { + timer_free(vdev->intx.mmap_timer); + pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); + kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notif= ier); + return false; + } + } + return true; +} + static void vfio_realize(PCIDevice *pdev, Error **errp) { ERRP_GUARD(); @@ -3141,27 +3173,8 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_bar_quirk_setup(vdev, i); } =20 - /* QEMU emulates all of MSI & MSIX */ - if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { - memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff, - MSIX_CAP_LENGTH); - } - - if (pdev->cap_present & QEMU_PCI_CAP_MSI) { - memset(vdev->emulated_config_bits + pdev->msi_cap, 0xff, - vdev->msi_cap_size); - } - - if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) { - vdev->intx.mmap_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, - vfio_intx_mmap_enable, v= dev); - pci_device_set_intx_routing_notifier(&vdev->pdev, - vfio_intx_routing_notifier); - vdev->irqchip_change_notifier.notify =3D vfio_irqchip_change; - kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier); - if (!vfio_intx_enable(vdev, errp)) { - goto out_deregister; - } + if (!vfio_interrupt_setup(vdev, errp)) { + goto out_unset_idev; } =20 if (vdev->display !=3D ON_OFF_AUTO_OFF) { --=20 2.49.0 From nobody Sat Nov 15 23:38:10 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745571258; cv=none; d=zohomail.com; s=zohoarc; b=eL+s5e+mAXvnotecMLLJU+lLNL8I2oHro402GHdTpL1t4FoKQP528uux99WuzNRKQt99IAEHjte9I+3MpLUvIlX504aNriAdhLOFx+orocUB9UzQj7mFnq3epGlrt431xwJEgNim6P+HCbk6/yFJ56UuDKnIGtrydmc6JUgzq9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745571258; 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=nwQ7525kQm3xWKABt9b1aTs7VzJeYwXUVZDlkEh38yY=; b=QPH9F+8WLiVIdYrxqGE7OrcLCIZx9mVjfz0yo7HNfYGD0lVYmSxkl7P9lGyh/mI7H12ZnV3QzwVMVuIjpRdw3vMQRasDl5Sn082EIfJn9xkpExbmvjWA45jiHZhwDCMf+Oc9zPz3BTAASZhT4U7DuFtP7bpxqZR4ncEyobiXKyQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745571258803901.8747894623533; Fri, 25 Apr 2025 01:54:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8ElO-0000LU-VA; Fri, 25 Apr 2025 04:50:27 -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 1u8Ekg-0007SV-3d for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8Ekd-0003Ov-GU for qemu-devel@nongnu.org; Fri, 25 Apr 2025 04:49:41 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-13-2h5xC0EyOLWx74A4Btz_dw-1; Fri, 25 Apr 2025 04:49:35 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4B8441800264; Fri, 25 Apr 2025 08:49:34 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.65]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CD77530001A2; Fri, 25 Apr 2025 08:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745570978; 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=nwQ7525kQm3xWKABt9b1aTs7VzJeYwXUVZDlkEh38yY=; b=cr+MEgok3+H+8N0hFNsDNoIWTgaKjVpvzuxDWfiseug49YEST/TKSvmNF+TlLWreoi/hab OKXN4LfAxysMxeSoSWAnb0KEv3b2DrqJ6m478M+1vzuBkypsIEdt8Ef+aNNK0pf/WqTgY0 4K4fUA8UUIKDSRh+0wP3dZcaMja94go= X-MC-Unique: 2h5xC0EyOLWx74A4Btz_dw-1 X-Mimecast-MFC-AGG-ID: 2h5xC0EyOLWx74A4Btz_dw_1745570974 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 50/50] vfio: refactor out vfio_pci_config_setup() Date: Fri, 25 Apr 2025 10:46:43 +0200 Message-ID: <20250425084644.102196-51-clg@redhat.com> In-Reply-To: <20250425084644.102196-1-clg@redhat.com> References: <20250425084644.102196-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.4.1 on 10.30.177.4 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.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.84, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745571261678019100 From: John Levon Refactor the PCI config setup code out of vfio_realize() for readability. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250409134814.478903-3-john.levon= @nutanix.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 176 +++++++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 82 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 27cc6426a54080dfaf5b9a50e4e57567bdeb9063..4a9484dfbe85085386ef90613ac= d7461dffc4903 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2962,6 +2962,99 @@ static void vfio_unregister_req_notifier(VFIOPCIDevi= ce *vdev) vdev->req_enabled =3D false; } =20 +static bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp) +{ + PCIDevice *pdev =3D &vdev->pdev; + VFIODevice *vbasedev =3D &vdev->vbasedev; + + /* vfio emulates a lot for us, but some bits need extra love */ + vdev->emulated_config_bits =3D g_malloc0(vdev->config_size); + + /* QEMU can choose to expose the ROM or not */ + memset(vdev->emulated_config_bits + PCI_ROM_ADDRESS, 0xff, 4); + /* QEMU can also add or extend BARs */ + memset(vdev->emulated_config_bits + PCI_BASE_ADDRESS_0, 0xff, 6 * 4); + + /* + * The PCI spec reserves vendor ID 0xffff as an invalid value. The + * device ID is managed by the vendor and need only be a 16-bit value. + * Allow any 16-bit value for subsystem so they can be hidden or chang= ed. + */ + if (vdev->vendor_id !=3D PCI_ANY_ID) { + if (vdev->vendor_id >=3D 0xffff) { + error_setg(errp, "invalid PCI vendor ID provided"); + return false; + } + vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0); + trace_vfio_pci_emulated_vendor_id(vbasedev->name, vdev->vendor_id); + } else { + vdev->vendor_id =3D pci_get_word(pdev->config + PCI_VENDOR_ID); + } + + if (vdev->device_id !=3D PCI_ANY_ID) { + if (vdev->device_id > 0xffff) { + error_setg(errp, "invalid PCI device ID provided"); + return false; + } + vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0); + trace_vfio_pci_emulated_device_id(vbasedev->name, vdev->device_id); + } else { + vdev->device_id =3D pci_get_word(pdev->config + PCI_DEVICE_ID); + } + + if (vdev->sub_vendor_id !=3D PCI_ANY_ID) { + if (vdev->sub_vendor_id > 0xffff) { + error_setg(errp, "invalid PCI subsystem vendor ID provided"); + return false; + } + vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID, + vdev->sub_vendor_id, ~0); + trace_vfio_pci_emulated_sub_vendor_id(vbasedev->name, + vdev->sub_vendor_id); + } + + if (vdev->sub_device_id !=3D PCI_ANY_ID) { + if (vdev->sub_device_id > 0xffff) { + error_setg(errp, "invalid PCI subsystem device ID provided"); + return false; + } + vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id= , ~0); + trace_vfio_pci_emulated_sub_device_id(vbasedev->name, + vdev->sub_device_id); + } + + /* QEMU can change multi-function devices to single function, or rever= se */ + vdev->emulated_config_bits[PCI_HEADER_TYPE] =3D + PCI_HEADER_TYPE_MULTI_FUNCTI= ON; + + /* Restore or clear multifunction, this is always controlled by QEMU */ + if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { + vdev->pdev.config[PCI_HEADER_TYPE] |=3D PCI_HEADER_TYPE_MULTI_FUNC= TION; + } else { + vdev->pdev.config[PCI_HEADER_TYPE] &=3D ~PCI_HEADER_TYPE_MULTI_FUN= CTION; + } + + /* + * Clear host resource mapping info. If we choose not to register a + * BAR, such as might be the case with the option ROM, we can get + * confusing, unwritable, residual addresses from the host here. + */ + memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24); + memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4); + + vfio_pci_size_rom(vdev); + + vfio_bars_prepare(vdev); + + if (!vfio_msix_early_setup(vdev, errp)) { + return false; + } + + vfio_bars_register(vdev); + + return true; +} + static bool vfio_interrupt_setup(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; @@ -3066,91 +3159,10 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) goto error; } =20 - /* vfio emulates a lot for us, but some bits need extra love */ - vdev->emulated_config_bits =3D g_malloc0(vdev->config_size); - - /* QEMU can choose to expose the ROM or not */ - memset(vdev->emulated_config_bits + PCI_ROM_ADDRESS, 0xff, 4); - /* QEMU can also add or extend BARs */ - memset(vdev->emulated_config_bits + PCI_BASE_ADDRESS_0, 0xff, 6 * 4); - - /* - * The PCI spec reserves vendor ID 0xffff as an invalid value. The - * device ID is managed by the vendor and need only be a 16-bit value. - * Allow any 16-bit value for subsystem so they can be hidden or chang= ed. - */ - if (vdev->vendor_id !=3D PCI_ANY_ID) { - if (vdev->vendor_id >=3D 0xffff) { - error_setg(errp, "invalid PCI vendor ID provided"); - goto error; - } - vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0); - trace_vfio_pci_emulated_vendor_id(vbasedev->name, vdev->vendor_id); - } else { - vdev->vendor_id =3D pci_get_word(pdev->config + PCI_VENDOR_ID); - } - - if (vdev->device_id !=3D PCI_ANY_ID) { - if (vdev->device_id > 0xffff) { - error_setg(errp, "invalid PCI device ID provided"); - goto error; - } - vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0); - trace_vfio_pci_emulated_device_id(vbasedev->name, vdev->device_id); - } else { - vdev->device_id =3D pci_get_word(pdev->config + PCI_DEVICE_ID); - } - - if (vdev->sub_vendor_id !=3D PCI_ANY_ID) { - if (vdev->sub_vendor_id > 0xffff) { - error_setg(errp, "invalid PCI subsystem vendor ID provided"); - goto error; - } - vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID, - vdev->sub_vendor_id, ~0); - trace_vfio_pci_emulated_sub_vendor_id(vbasedev->name, - vdev->sub_vendor_id); - } - - if (vdev->sub_device_id !=3D PCI_ANY_ID) { - if (vdev->sub_device_id > 0xffff) { - error_setg(errp, "invalid PCI subsystem device ID provided"); - goto error; - } - vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id= , ~0); - trace_vfio_pci_emulated_sub_device_id(vbasedev->name, - vdev->sub_device_id); - } - - /* QEMU can change multi-function devices to single function, or rever= se */ - vdev->emulated_config_bits[PCI_HEADER_TYPE] =3D - PCI_HEADER_TYPE_MULTI_FUNCTI= ON; - - /* Restore or clear multifunction, this is always controlled by QEMU */ - if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { - vdev->pdev.config[PCI_HEADER_TYPE] |=3D PCI_HEADER_TYPE_MULTI_FUNC= TION; - } else { - vdev->pdev.config[PCI_HEADER_TYPE] &=3D ~PCI_HEADER_TYPE_MULTI_FUN= CTION; - } - - /* - * Clear host resource mapping info. If we choose not to register a - * BAR, such as might be the case with the option ROM, we can get - * confusing, unwritable, residual addresses from the host here. - */ - memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24); - memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4); - - vfio_pci_size_rom(vdev); - - vfio_bars_prepare(vdev); - - if (!vfio_msix_early_setup(vdev, errp)) { + if (!vfio_pci_config_setup(vdev, errp)) { goto error; } =20 - vfio_bars_register(vdev); - if (!vbasedev->mdev && !pci_device_set_iommu_device(pdev, vbasedev->hiod, errp)) { error_prepend(errp, "Failed to set vIOMMU: "); --=20 2.49.0