The vfio-user container will later need to hook into these callbacks;
set up vfio to use them, and optionally pass them through to the
container.
Signed-off-by: John Levon <john.levon@nutanix.com>
---
hw/vfio/listener.c | 28 +++++++++++++++++++++++++++
include/hw/vfio/vfio-container-base.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
index 285ca97a8c..9ffc2deb2d 100644
--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -412,6 +412,32 @@ static bool vfio_get_section_iova_range(VFIOContainerBase *bcontainer,
return true;
}
+static void vfio_listener_begin(MemoryListener *listener)
+{
+ VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
+ listener);
+ void (*listener_begin)(VFIOContainerBase *bcontainer);
+
+ listener_begin = VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin;
+
+ if (listener_begin) {
+ listener_begin(bcontainer);
+ }
+}
+
+static void vfio_listener_commit(MemoryListener *listener)
+{
+ VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
+ listener);
+ void (*listener_commit)(VFIOContainerBase *bcontainer);
+
+ listener_commit = VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin;
+
+ if (listener_commit) {
+ listener_commit(bcontainer);
+ }
+}
+
static void vfio_device_error_append(VFIODevice *vbasedev, Error **errp)
{
/*
@@ -1166,6 +1192,8 @@ static void vfio_listener_log_sync(MemoryListener *listener,
static const MemoryListener vfio_memory_listener = {
.name = "vfio",
+ .begin = vfio_listener_begin,
+ .commit = vfio_listener_commit,
.region_add = vfio_listener_region_add,
.region_del = vfio_listener_region_del,
.log_global_start = vfio_listener_log_global_start,
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index a441932be7..67373e8db0 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -120,6 +120,8 @@ struct VFIOIOMMUClass {
/* basic feature */
bool (*setup)(VFIOContainerBase *bcontainer, Error **errp);
+ void (*listener_begin)(VFIOContainerBase *bcontainer);
+ void (*listener_commit)(VFIOContainerBase *bcontainer);
int (*dma_map)(const VFIOContainerBase *bcontainer,
hwaddr iova, ram_addr_t size,
void *vaddr, bool readonly);
--
2.34.1
On 4/9/25 15:48, John Levon wrote:
> The vfio-user container will later need to hook into these callbacks;
> set up vfio to use them, and optionally pass them through to the
> container.
>
> Signed-off-by: John Levon <john.levon@nutanix.com>
> ---
> hw/vfio/listener.c | 28 +++++++++++++++++++++++++++
> include/hw/vfio/vfio-container-base.h | 2 ++
> 2 files changed, 30 insertions(+)
>
> diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
> index 285ca97a8c..9ffc2deb2d 100644
> --- a/hw/vfio/listener.c
> +++ b/hw/vfio/listener.c
> @@ -412,6 +412,32 @@ static bool vfio_get_section_iova_range(VFIOContainerBase *bcontainer,
> return true;
> }
>
> +static void vfio_listener_begin(MemoryListener *listener)
> +{
> + VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
> + listener);
> + void (*listener_begin)(VFIOContainerBase *bcontainer);
> +
> + listener_begin = VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin;
> +
> + if (listener_begin) {
> + listener_begin(bcontainer);
> + }
> +}
> +
> +static void vfio_listener_commit(MemoryListener *listener)
> +{
> + VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
> + listener);
> + void (*listener_commit)(VFIOContainerBase *bcontainer);
> +
> + listener_commit = VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin;
> +
> + if (listener_commit) {
> + listener_commit(bcontainer);
> + }
> +}
> +
> static void vfio_device_error_append(VFIODevice *vbasedev, Error **errp)
> {
> /*
> @@ -1166,6 +1192,8 @@ static void vfio_listener_log_sync(MemoryListener *listener,
>
> static const MemoryListener vfio_memory_listener = {
> .name = "vfio",
> + .begin = vfio_listener_begin,
> + .commit = vfio_listener_commit,
> .region_add = vfio_listener_region_add,
> .region_del = vfio_listener_region_del,
> .log_global_start = vfio_listener_log_global_start,
> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
> index a441932be7..67373e8db0 100644
> --- a/include/hw/vfio/vfio-container-base.h
> +++ b/include/hw/vfio/vfio-container-base.h
> @@ -120,6 +120,8 @@ struct VFIOIOMMUClass {
>
> /* basic feature */
> bool (*setup)(VFIOContainerBase *bcontainer, Error **errp);
> + void (*listener_begin)(VFIOContainerBase *bcontainer);
> + void (*listener_commit)(VFIOContainerBase *bcontainer);
Please add documentation for the new callbacks.
Thanks,
C.
> int (*dma_map)(const VFIOContainerBase *bcontainer,
> hwaddr iova, ram_addr_t size,
> void *vaddr, bool readonly);
On 4/23/25 15:45, Cédric Le Goater wrote:
> On 4/9/25 15:48, John Levon wrote:
>> The vfio-user container will later need to hook into these callbacks;
>> set up vfio to use them, and optionally pass them through to the
>> container.
>>
>> Signed-off-by: John Levon <john.levon@nutanix.com>
>> ---
>> hw/vfio/listener.c | 28 +++++++++++++++++++++++++++
>> include/hw/vfio/vfio-container-base.h | 2 ++
>> 2 files changed, 30 insertions(+)
>>
>> diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
>> index 285ca97a8c..9ffc2deb2d 100644
>> --- a/hw/vfio/listener.c
>> +++ b/hw/vfio/listener.c
>> @@ -412,6 +412,32 @@ static bool vfio_get_section_iova_range(VFIOContainerBase *bcontainer,
>> return true;
>> }
>> +static void vfio_listener_begin(MemoryListener *listener)
>> +{
>> + VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
>> + listener);
>> + void (*listener_begin)(VFIOContainerBase *bcontainer);
>> +
>> + listener_begin = VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin;
>> +
>> + if (listener_begin) {
>> + listener_begin(bcontainer);
>> + }
>> +}
>> +
>> +static void vfio_listener_commit(MemoryListener *listener)
>> +{
>> + VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
>> + listener);
>> + void (*listener_commit)(VFIOContainerBase *bcontainer);
>> +
>> + listener_commit = VFIO_IOMMU_GET_CLASS(bcontainer)->listener_begin;
>> +
>> + if (listener_commit) {
>> + listener_commit(bcontainer);
>> + }
>> +}
>> +
>> static void vfio_device_error_append(VFIODevice *vbasedev, Error **errp)
>> {
>> /*
>> @@ -1166,6 +1192,8 @@ static void vfio_listener_log_sync(MemoryListener *listener,
>> static const MemoryListener vfio_memory_listener = {
>> .name = "vfio",
>> + .begin = vfio_listener_begin,
>> + .commit = vfio_listener_commit,
>> .region_add = vfio_listener_region_add,
>> .region_del = vfio_listener_region_del,
>> .log_global_start = vfio_listener_log_global_start,
>> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
>> index a441932be7..67373e8db0 100644
>> --- a/include/hw/vfio/vfio-container-base.h
>> +++ b/include/hw/vfio/vfio-container-base.h
>> @@ -120,6 +120,8 @@ struct VFIOIOMMUClass {
>> /* basic feature */
>> bool (*setup)(VFIOContainerBase *bcontainer, Error **errp);
>> + void (*listener_begin)(VFIOContainerBase *bcontainer);
>> + void (*listener_commit)(VFIOContainerBase *bcontainer);
>
> Please add documentation for the new callbacks.
and it is not used in this series yet. So we can keep it for later.
Thanks,
C.
On Thu, Apr 24, 2025 at 06:24:23PM +0200, Cédric Le Goater wrote: > > On 4/9/25 15:48, John Levon wrote: > > > The vfio-user container will later need to hook into these callbacks; > > > set up vfio to use them, and optionally pass them through to the > > > container. > > > + void (*listener_begin)(VFIOContainerBase *bcontainer); > > > + void (*listener_commit)(VFIOContainerBase *bcontainer); > > > > Please add documentation for the new callbacks. > and it is not used in this series yet. So we can keep it for later. Will do, I thought you wanted the general vfio stuff separated out, but can move to the vfio-user specific queue. regards john
On 4/24/25 18:28, John Levon wrote: > On Thu, Apr 24, 2025 at 06:24:23PM +0200, Cédric Le Goater wrote: > >>> On 4/9/25 15:48, John Levon wrote: >>>> The vfio-user container will later need to hook into these callbacks; >>>> set up vfio to use them, and optionally pass them through to the >>>> container. >>>> + void (*listener_begin)(VFIOContainerBase *bcontainer); >>>> + void (*listener_commit)(VFIOContainerBase *bcontainer); >>> >>> Please add documentation for the new callbacks. >> and it is not used in this series yet. So we can keep it for later. > > Will do, I thought you wanted the general vfio stuff separated out, yes. It is best to start with the invasive part. > but can move to the vfio-user specific queue. This is a simple addition which shouldn't conflict with the rest of the changes. So it can come when needed. Thanks, C.
© 2016 - 2025 Red Hat, Inc.