From: Alexandra Winter <wintera@linux.ibm.com>
To: Julian Ruess <julianr@linux.ibm.com>,
schnelle@linux.ibm.com, ts@linux.ibm.com, oberpar@linux.ibm.com,
gbayer@linux.ibm.com, Alex Williamson <alex@shazbot.org>,
Jason Gunthorpe <jgg@ziepe.ca>, Yishai Hadas <yishaih@nvidia.com>,
Shameer Kolothum <skolothumtho@nvidia.com>,
Kevin Tian <kevin.tian@intel.com>
Cc: mjrosato@linux.ibm.com, alifm@linux.ibm.com, raspl@linux.ibm.com,
hca@linux.ibm.com, agordeev@linux.ibm.com, gor@linux.ibm.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-s390@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 2/3] vfio/ism: Implement vfio_pci driver for ISM devices
Date: Fri, 27 Feb 2026 16:52:54 +0100 [thread overview]
Message-ID: <5e10827b-e87e-43a6-8783-2e5d23a186e1@linux.ibm.com> (raw)
In-Reply-To: <20260224-vfio_pci_ism-v2-2-f010945373fa@linux.ibm.com>
On 24.02.26 13:34, Julian Ruess wrote:
[...]
> diff --git a/drivers/vfio/pci/ism/main.c b/drivers/vfio/pci/ism/main.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..5f9674f6dd1d44888c4e1e416d05edfd89fd09fe
> --- /dev/null
> +++ b/drivers/vfio/pci/ism/main.c
> @@ -0,0 +1,297 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * vfio-ISM driver for s390
> + *
> + * Copyright IBM Corp.
> + */
> +
> +#include "../vfio_pci_priv.h"
> +
> +#define ISM_VFIO_PCI_OFFSET_SHIFT 48
> +#define ISM_VFIO_PCI_OFFSET_TO_INDEX(off) (off >> ISM_VFIO_PCI_OFFSET_SHIFT)
> +#define ISM_VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << ISM_VFIO_PCI_OFFSET_SHIFT)
> +#define ISM_VFIO_PCI_OFFSET_MASK (((u64)(1) << ISM_VFIO_PCI_OFFSET_SHIFT) - 1)
> +
> +struct ism_vfio_pci_core_device {
> + struct vfio_pci_core_device core_device;
> +};
> +
> +static int ism_pci_open_device(struct vfio_device *core_vdev)
> +{
> + struct ism_vfio_pci_core_device *ivdev;
> + struct vfio_pci_core_device *vdev;
Why do you need 'struct ism_vfio_pci_core_device'?
Unlike other vfio_pci variant drivers your struct only has a single member.
I see it is used below as well, but couldn't you directly use 'struct vfio_pci_core_device'
in all places?
> + int ret;
> +
> + ivdev = container_of(core_vdev, struct ism_vfio_pci_core_device,
> + core_device.vdev);
> + vdev = &ivdev->core_device;
> +
> + ret = vfio_pci_core_enable(vdev);
> + if (ret)
> + return ret;
> +
> + vfio_pci_core_finish_enable(vdev);
> + return 0;
> +}
> +
> +static ssize_t ism_vfio_pci_do_io_r(struct vfio_pci_core_device *vdev,
> + char __user *buf, loff_t off, size_t count,
> + int bar)
> +{
> + struct zpci_dev *zdev = to_zpci(vdev->pdev);
> + ssize_t ret, done = 0;
> + u64 req, length, tmp;
> +
> + while (count) {
> + if (count >= 8 && IS_ALIGNED(off, 8))
> + length = 8;
> + else if (count >= 4 && IS_ALIGNED(off, 4))
> + length = 4;
> + else if (count >= 2 && IS_ALIGNED(off, 2))
> + length = 2;
> + else
> + length = 1;
As you know something like
> + if (count >= 8 && IS_ALIGNED(off, 8)) {
> + length = 8;
} else {
unsigned missing_bytes = 8 - (off % 8);
length = min(count, missing_bytes);
}
would suffice to fullfill the requirements for pcilg to BARs.
But your code works as well.
> + req = ZPCI_CREATE_REQ(READ_ONCE(zdev->fh), bar, length);
> + /* use pcilg to prevent using MIO instructions */
> + ret = __zpci_load(&tmp, req, off);
> + if (ret)
> + return ret;
> + if (copy_to_user(buf, &tmp, length))
> + return -EFAULT;
> + count -= length;
> + done += length;
> + off += length;
> + buf += length;
> + }
> + return done;
> +}
> +
> +static ssize_t ism_vfio_pci_do_io_w(struct vfio_pci_core_device *vdev,
> + char __user *buf, loff_t off, size_t count,
> + int bar)
> +{
> + struct zpci_dev *zdev = to_zpci(vdev->pdev);
> + void *data __free(kfree) = NULL;
> + ssize_t ret;
> + u64 req;
> +
> + if (count > zdev->maxstbl)
> + return -EINVAL;
I think you also need to check for off+count not crossing 4k
> + data = kzalloc(count, GFP_KERNEL);
Where do you free 'data' ?
> + if (!data)
> + return -ENOMEM;
> + if (copy_from_user(data, buf, count))
> + return -EFAULT;
> + req = ZPCI_CREATE_REQ(READ_ONCE(zdev->fh), bar, count);
> + ret = __zpci_store_block(data, req, off);
> + if (ret)
> + return ret;
> + return count;
> +}
> +
next prev parent reply other threads:[~2026-02-27 15:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 12:34 [PATCH v2 0/3] vfio/pci: Introduce " Julian Ruess
2026-02-24 12:34 ` [PATCH v2 1/3] vfio/pci: Rename vfio_config_do_rw() to vfio_pci_config_rw_single() and export it Julian Ruess
2026-02-26 19:36 ` Niklas Schnelle
2026-02-27 20:51 ` Alex Williamson
2026-02-24 12:34 ` [PATCH v2 2/3] vfio/ism: Implement vfio_pci driver for ISM devices Julian Ruess
2026-02-26 21:02 ` Niklas Schnelle
2026-02-27 15:52 ` Alexandra Winter [this message]
2026-03-02 12:18 ` Julian Ruess
2026-03-02 13:23 ` Alexandra Winter
2026-02-27 22:12 ` Alex Williamson
2026-03-02 22:07 ` Farhan Ali
2026-02-24 12:34 ` [PATCH v2 3/3] MAINTAINERS: add VFIO ISM PCI DRIVER section Julian Ruess
2026-02-26 21:04 ` Niklas Schnelle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5e10827b-e87e-43a6-8783-2e5d23a186e1@linux.ibm.com \
--to=wintera@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=alex@shazbot.org \
--cc=alifm@linux.ibm.com \
--cc=gbayer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=jgg@ziepe.ca \
--cc=julianr@linux.ibm.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=oberpar@linux.ibm.com \
--cc=raspl@linux.ibm.com \
--cc=schnelle@linux.ibm.com \
--cc=skolothumtho@nvidia.com \
--cc=ts@linux.ibm.com \
--cc=yishaih@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®