Skip to content

Commit

Permalink
vfio/container: Move IBM EEH related functions into spapr_pci_vfio.c
Browse files Browse the repository at this point in the history
With vfio_eeh_as_ok/vfio_eeh_as_op moved and made static,
vfio.h becomes empty and is deleted.

No functional changes intended.

Suggested-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Acked-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
  • Loading branch information
duanzhenzhong authored and legoater committed Nov 6, 2023
1 parent 5fe5193 commit 54876d2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 110 deletions.
100 changes: 99 additions & 1 deletion hw/ppc/spapr_pci_vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,112 @@
*/

#include "qemu/osdep.h"
#include <sys/ioctl.h>
#include <linux/vfio.h>
#include "hw/ppc/spapr.h"
#include "hw/pci-host/spapr.h"
#include "hw/pci/msix.h"
#include "hw/pci/pci_device.h"
#include "hw/vfio/vfio.h"
#include "hw/vfio/vfio-common.h"
#include "qemu/error-report.h"

/*
* Interfaces for IBM EEH (Enhanced Error Handling)
*/
static bool vfio_eeh_container_ok(VFIOContainer *container)
{
/*
* As of 2016-03-04 (linux-4.5) the host kernel EEH/VFIO
* implementation is broken if there are multiple groups in a
* container. The hardware works in units of Partitionable
* Endpoints (== IOMMU groups) and the EEH operations naively
* iterate across all groups in the container, without any logic
* to make sure the groups have their state synchronized. For
* certain operations (ENABLE) that might be ok, until an error
* occurs, but for others (GET_STATE) it's clearly broken.
*/

/*
* XXX Once fixed kernels exist, test for them here
*/

if (QLIST_EMPTY(&container->group_list)) {
return false;
}

if (QLIST_NEXT(QLIST_FIRST(&container->group_list), container_next)) {
return false;
}

return true;
}

static int vfio_eeh_container_op(VFIOContainer *container, uint32_t op)
{
struct vfio_eeh_pe_op pe_op = {
.argsz = sizeof(pe_op),
.op = op,
};
int ret;

if (!vfio_eeh_container_ok(container)) {
error_report("vfio/eeh: EEH_PE_OP 0x%x: "
"kernel requires a container with exactly one group", op);
return -EPERM;
}

ret = ioctl(container->fd, VFIO_EEH_PE_OP, &pe_op);
if (ret < 0) {
error_report("vfio/eeh: EEH_PE_OP 0x%x failed: %m", op);
return -errno;
}

return ret;
}

static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
{
VFIOAddressSpace *space = vfio_get_address_space(as);
VFIOContainer *container = NULL;

if (QLIST_EMPTY(&space->containers)) {
/* No containers to act on */
goto out;
}

container = QLIST_FIRST(&space->containers);

if (QLIST_NEXT(container, next)) {
/*
* We don't yet have logic to synchronize EEH state across
* multiple containers
*/
container = NULL;
goto out;
}

out:
vfio_put_address_space(space);
return container;
}

static bool vfio_eeh_as_ok(AddressSpace *as)
{
VFIOContainer *container = vfio_eeh_as_container(as);

return (container != NULL) && vfio_eeh_container_ok(container);
}

static int vfio_eeh_as_op(AddressSpace *as, uint32_t op)
{
VFIOContainer *container = vfio_eeh_as_container(as);

if (!container) {
return -ENODEV;
}
return vfio_eeh_container_op(container, op);
}

bool spapr_phb_eeh_available(SpaprPhbState *sphb)
{
return vfio_eeh_as_ok(&sphb->iommu_as);
Expand Down
1 change: 0 additions & 1 deletion hw/vfio/ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <linux/vfio.h>
#include <sys/ioctl.h>
#include "qapi/error.h"
#include "hw/vfio/vfio.h"
#include "hw/vfio/vfio-common.h"
#include "hw/s390x/ap-device.h"
#include "qemu/error-report.h"
Expand Down
1 change: 0 additions & 1 deletion hw/vfio/ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <sys/ioctl.h>

#include "qapi/error.h"
#include "hw/vfio/vfio.h"
#include "hw/vfio/vfio-common.h"
#include "hw/s390x/s390-ccw.h"
#include "hw/s390x/vfio-ccw.h"
Expand Down
1 change: 0 additions & 1 deletion hw/vfio/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <linux/vfio.h>

#include "hw/vfio/vfio-common.h"
#include "hw/vfio/vfio.h"
#include "hw/vfio/pci.h"
#include "exec/address-spaces.h"
#include "exec/memory.h"
Expand Down
98 changes: 0 additions & 98 deletions hw/vfio/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <linux/vfio.h>

#include "hw/vfio/vfio-common.h"
#include "hw/vfio/vfio.h"
#include "exec/address-spaces.h"
#include "exec/memory.h"
#include "exec/ram_addr.h"
Expand Down Expand Up @@ -1011,103 +1010,6 @@ static void vfio_put_base_device(VFIODevice *vbasedev)
close(vbasedev->fd);
}

/*
* Interfaces for IBM EEH (Enhanced Error Handling)
*/
static bool vfio_eeh_container_ok(VFIOContainer *container)
{
/*
* As of 2016-03-04 (linux-4.5) the host kernel EEH/VFIO
* implementation is broken if there are multiple groups in a
* container. The hardware works in units of Partitionable
* Endpoints (== IOMMU groups) and the EEH operations naively
* iterate across all groups in the container, without any logic
* to make sure the groups have their state synchronized. For
* certain operations (ENABLE) that might be ok, until an error
* occurs, but for others (GET_STATE) it's clearly broken.
*/

/*
* XXX Once fixed kernels exist, test for them here
*/

if (QLIST_EMPTY(&container->group_list)) {
return false;
}

if (QLIST_NEXT(QLIST_FIRST(&container->group_list), container_next)) {
return false;
}

return true;
}

static int vfio_eeh_container_op(VFIOContainer *container, uint32_t op)
{
struct vfio_eeh_pe_op pe_op = {
.argsz = sizeof(pe_op),
.op = op,
};
int ret;

if (!vfio_eeh_container_ok(container)) {
error_report("vfio/eeh: EEH_PE_OP 0x%x: "
"kernel requires a container with exactly one group", op);
return -EPERM;
}

ret = ioctl(container->fd, VFIO_EEH_PE_OP, &pe_op);
if (ret < 0) {
error_report("vfio/eeh: EEH_PE_OP 0x%x failed: %m", op);
return -errno;
}

return ret;
}

static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
{
VFIOAddressSpace *space = vfio_get_address_space(as);
VFIOContainer *container = NULL;

if (QLIST_EMPTY(&space->containers)) {
/* No containers to act on */
goto out;
}

container = QLIST_FIRST(&space->containers);

if (QLIST_NEXT(container, next)) {
/*
* We don't yet have logic to synchronize EEH state across
* multiple containers
*/
container = NULL;
goto out;
}

out:
vfio_put_address_space(space);
return container;
}

bool vfio_eeh_as_ok(AddressSpace *as)
{
VFIOContainer *container = vfio_eeh_as_container(as);

return (container != NULL) && vfio_eeh_container_ok(container);
}

int vfio_eeh_as_op(AddressSpace *as, uint32_t op)
{
VFIOContainer *container = vfio_eeh_as_container(as);

if (!container) {
return -ENODEV;
}
return vfio_eeh_container_op(container, op);
}

static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp)
{
char *tmp, group_path[PATH_MAX], *group_name;
Expand Down
1 change: 0 additions & 1 deletion hw/vfio/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <sys/ioctl.h>

#include "hw/vfio/vfio-common.h"
#include "hw/vfio/vfio.h"
#include "hw/hw.h"
#include "trace.h"
#include "qapi/error.h"
Expand Down
7 changes: 0 additions & 7 deletions include/hw/vfio/vfio.h

This file was deleted.

0 comments on commit 54876d2

Please sign in to comment.