qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@redhat.com>
To: Alistair Popple <apopple@nvidia.com>, Yi Liu <yi.l.liu@intel.com>
Cc: alex.williamson@redhat.com, cohuck@redhat.com,
	david@gibson.dropbear.id.au, thuth@redhat.com,
	farman@linux.ibm.com, mjrosato@linux.ibm.com,
	akrowiak@linux.ibm.com, pasic@linux.ibm.com,
	jjherne@linux.ibm.com, jasowang@redhat.com, kvm@vger.kernel.org,
	jgg@nvidia.com, nicolinc@nvidia.com, eric.auger.pro@gmail.com,
	kevin.tian@intel.com, chao.p.peng@intel.com, yi.y.sun@intel.com,
	peterx@redhat.com, shameerali.kolothum.thodi@huawei.com,
	zhangfei.gao@linaro.org, berrange@redhat.com,
	qemu-devel@nongnu.org
Subject: Re: [RFC v2 13/15] vfio/iommufd: Implement the iommufd backend
Date: Wed, 5 Oct 2022 11:02:49 +0200	[thread overview]
Message-ID: <33d7599c-0759-baf7-5e98-dacdf8b3ccf5@redhat.com> (raw)
In-Reply-To: <87zgecqdv1.fsf@nvidia.com>

Hi Alister,
On 10/4/22 08:47, Alistair Popple wrote:
> Yi Liu <yi.l.liu@intel.com> writes:
>
> [...]
>
>> +static int vfio_get_devicefd(const char *sysfs_path, Error **errp)
>> +{
>> +    long int ret = -ENOTTY;
>> +    char *path, *vfio_dev_path = NULL, *vfio_path = NULL;
>> +    DIR *dir;
>> +    struct dirent *dent;
>> +    gchar *contents;
>> +    struct stat st;
>> +    gsize length;
>> +    int major, minor;
>> +    dev_t vfio_devt;
>> +
>> +    path = g_strdup_printf("%s/vfio-device", sysfs_path);
>> +    if (stat(path, &st) < 0) {
>> +        error_setg_errno(errp, errno, "no such host device");
>> +        goto out_free_path;
>> +    }
>> +
>> +    dir = opendir(path);
>> +    if (!dir) {
>> +        error_setg_errno(errp, errno, "couldn't open dirrectory %s", path);
>> +        goto out_free_path;
>> +    }
>> +
>> +    while ((dent = readdir(dir))) {
>> +        if (!strncmp(dent->d_name, "vfio", 4)) {
>> +            vfio_dev_path = g_strdup_printf("%s/%s/dev", path, dent->d_name);
>> +            break;
>> +        }
>> +    }
>> +
>> +    if (!vfio_dev_path) {
>> +        error_setg(errp, "failed to find vfio-device/vfioX/dev");
>> +        goto out_free_path;
>> +    }
>> +
>> +    if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) {
>> +        error_setg(errp, "failed to load \"%s\"", vfio_dev_path);
>> +        goto out_free_dev_path;
>> +    }
>> +
>> +    if (sscanf(contents, "%d:%d", &major, &minor) != 2) {
>> +        error_setg(errp, "failed to get major:mino for \"%s\"", vfio_dev_path);
>> +        goto out_free_dev_path;
>> +    }
>> +    g_free(contents);
>> +    vfio_devt = makedev(major, minor);
>> +
>> +    vfio_path = g_strdup_printf("/dev/vfio/devices/%s", dent->d_name);
>> +    ret = open_cdev(vfio_path, vfio_devt);
>> +    if (ret < 0) {
>> +        error_setg(errp, "Failed to open %s", vfio_path);
>> +    }
>> +
>> +    trace_vfio_iommufd_get_devicefd(vfio_path, ret);
>> +    g_free(vfio_path);
>> +
>> +out_free_dev_path:
>> +    g_free(vfio_dev_path);
>> +out_free_path:
>> +    g_free(path);
>> +
>> +    if (*errp) {
>> +        error_prepend(errp, VFIO_MSG_PREFIX, path);
> I ran into this while trying to get things running, so haven't reviewed
> the patch but noticed path is used after it's freed if !!*errp.

thank you for the bug report! We will fix that on the next iteration.

Eric
>
>  - Alistair
>
>> +    }
>> +    return ret;
>> +}



  reply	other threads:[~2022-10-05  9:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 12:31 [RFC v2 00/15] vfio: Adopt iommufd Yi Liu
2022-06-08 12:31 ` [RFC v2 01/15] scripts/update-linux-headers: Add iommufd.h Yi Liu
2022-06-08 12:31 ` [RFC v2 02/15] linux-headers: Import latest vfio.h and iommufd.h Yi Liu
2022-06-08 12:31 ` [RFC v2 03/15] vfio/common: Split common.c into common.c, container.c and as.c Yi Liu
2022-06-08 12:31 ` [RFC v2 04/15] vfio: Add base container Yi Liu
2022-06-08 12:31 ` [RFC v2 05/15] vfio/container: Introduce vfio_[attach/detach]_device Yi Liu
2022-06-08 12:31 ` [RFC v2 06/15] vfio/platform: Use vfio_[attach/detach]_device Yi Liu
2022-06-08 12:31 ` [RFC v2 07/15] vfio/ap: " Yi Liu
2022-06-08 12:31 ` [RFC v2 08/15] vfio/ccw: " Yi Liu
2022-06-08 12:31 ` [RFC v2 09/15] vfio/container-base: Introduce [attach/detach]_device container callbacks Yi Liu
2022-06-08 12:31 ` [RFC v2 10/15] vfio/container-base: Introduce VFIOContainer reset callback Yi Liu
2022-06-08 12:31 ` [RFC v2 11/15] backends/iommufd: Introduce the iommufd object Yi Liu
2022-06-08 12:31 ` [RFC v2 12/15] util/char_dev: Add open_cdev() Yi Liu
2022-06-08 12:31 ` [RFC v2 13/15] vfio/iommufd: Implement the iommufd backend Yi Liu
2022-10-04  6:47   ` Alistair Popple
2022-10-05  9:02     ` Eric Auger [this message]
2022-06-08 12:31 ` [RFC v2 14/15] vfio/iommufd: Add IOAS_COPY_DMA support Yi Liu
2022-06-08 12:31 ` [RFC v2 15/15] vfio/as: Allow the selection of a given iommu backend Yi Liu

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=33d7599c-0759-baf7-5e98-dacdf8b3ccf5@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=apopple@nvidia.com \
    --cc=berrange@redhat.com \
    --cc=chao.p.peng@intel.com \
    --cc=cohuck@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=eric.auger.pro@gmail.com \
    --cc=farman@linux.ibm.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=nicolinc@nvidia.com \
    --cc=pasic@linux.ibm.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=thuth@redhat.com \
    --cc=yi.l.liu@intel.com \
    --cc=yi.y.sun@intel.com \
    --cc=zhangfei.gao@linaro.org \
    /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;
as well as URLs for NNTP newsgroup(s).