From: Alex Williamson <alex.williamson@redhat.com>
To: Kirti Wankhede <kwankhede@nvidia.com>
Cc: <pbonzini@redhat.com>, <kraxel@redhat.com>, <cjia@nvidia.com>,
<qemu-devel@nongnu.org>, <kvm@vger.kernel.org>,
<kevin.tian@intel.com>, <jike.song@intel.com>,
<bjsdjshi@linux.vnet.ibm.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v9 01/12] vfio: Mediated device Core driver
Date: Wed, 19 Oct 2016 16:20:30 -0600 [thread overview]
Message-ID: <20161019162030.6e37a6c1@t450s.home> (raw)
In-Reply-To: <ac5bccaa-4647-ce5e-5f07-588bcf166b2c@nvidia.com>
On Thu, 20 Oct 2016 00:46:48 +0530
Kirti Wankhede <kwankhede@nvidia.com> wrote:
> On 10/19/2016 4:46 AM, Alex Williamson wrote:
> > On Tue, 18 Oct 2016 02:52:01 +0530
> > Kirti Wankhede <kwankhede@nvidia.com> wrote:
> >
> ...
> >> +static struct mdev_device *__find_mdev_device(struct parent_device *parent,
> >> + uuid_le uuid)
> >> +{
> >> + struct device *dev;
> >> +
> >> + dev = device_find_child(parent->dev, &uuid, _find_mdev_device);
> >> + if (!dev)
> >> + return NULL;
> >> +
> >> + put_device(dev);
> >> +
> >> + return to_mdev_device(dev);
> >> +}
> >
> > This function is only used by mdev_device_create() for the purpose of
> > checking whether a given uuid for a parent already exists, so the
> > returned device is not actually used. However, at the point where
> > we're using to_mdev_device() here, we don't actually hold a reference to
> > the device, so that function call and any possible use of the returned
> > pointer by the callee is invalid. I would either turn this into a
> > "get" function where the callee has a device reference and needs to do
> > a "put" on it or change this to a "exists" test where true/false is
> > returned and the function cannot be later mis-used to do a device
> > lookup where the reference isn't actually valid.
> >
>
> I'll change it to return 0 if not found and -EEXIST if found.
>
>
> >> +int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
> >> +{
> >> + int ret;
> >> + struct mdev_device *mdev;
> >> + struct parent_device *parent;
> >> + struct mdev_type *type = to_mdev_type(kobj);
> >> +
> >> + parent = mdev_get_parent(type->parent);
> >> + if (!parent)
> >> + return -EINVAL;
> >> +
> >> + /* Check for duplicate */
> >> + mdev = __find_mdev_device(parent, uuid);
> >> + if (mdev) {
> >> + ret = -EEXIST;
> >> + goto create_err;
> >> + }
> >
> > We check here whether the {parent,uuid} already exists, but what
> > prevents us racing with another create call with the same uuid? ie.
> > neither exists at this point. Will device_register() fail if the
> > device name already exists? If so, should we just rely on the error
> > there and skip this duplicate check? If not, we need a mutex to avoid
> > the race.
> >
>
> Yes, device_register() fails if device exists already with below
> warning. Is it ok to dump such warning? I think, this should be fine,
> right? then we can remove duplicate check.
>
> If we want to avoid such warning, we should have duplication check.
We should avoid such warnings, bugs will get filed otherwise. Thanks
for checking. Thanks,
Alex
> [ 610.847958] ------------[ cut here ]------------
> [ 610.855377] WARNING: CPU: 15 PID: 19839 at fs/sysfs/dir.c:31
> sysfs_warn_dup+0x64/0x80
> [ 610.865798] sysfs: cannot create duplicate filename
> '/devices/pci0000:80/0000:80:02.0/0000:83:00.0/0000:84:08.0/0000:85:00.0/83b8f4f2-509f-382f-3c1e-e6bfe0fa1234'
> [ 610.885101] Modules linked in:[ 610.888039] nvidia(POE)
> vfio_iommu_type1 vfio_mdev mdev vfio nfsv4 dns_resolver nfs fscache
> sb_edac edac_core x86_pkg_temp_thermal intel_powerclamp coretemp
> kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul crc32c_intel
> ghash_clmulni_intel aesni_intel glue_helper lrw gf128mul ablk_helper
> cryptd nfsd auth_rpcgss nfs_acl lockd mei_me grace iTCO_wdt
> iTCO_vendor_support mei ipmi_si pcspkr ioatdma i2c_i801 lpc_ich shpchp
> i2c_smbus mfd_core ipmi_msghandler acpi_pad uinput sunrpc xfs libcrc32c
> sd_mod mgag200 drm_kms_helper syscopyarea sysfillrect sysimgblt
> fb_sys_fops ttm drm igb ahci libahci ptp libata pps_core dca
> i2c_algo_bit i2c_core dm_mirror dm_region_hash dm_log dm_mod [last
> unloaded: mdev]
> [ 610.963835] CPU: 15 PID: 19839 Comm: bash Tainted: P OE
> 4.8.0-next-20161013+ #0
> [ 610.973779] Hardware name: Supermicro
> SYS-2027GR-5204A-NC024/X9DRG-HF, BIOS 1.0c 02/28/2013
> [ 610.983769] ffffc90009323ae0 ffffffff813568bf ffffc90009323b30
> 0000000000000000
> [ 610.992867] ffffc90009323b20 ffffffff81085511 0000001f00001000
> ffff8808839ef000
> [ 611.001954] ffff88108b30f900 ffff88109ae368e8 ffff88109ae580b0
> ffff881099cc0818
> [ 611.011055] Call Trace:
> [ 611.015087] [<ffffffff813568bf>] dump_stack+0x63/0x84
> [ 611.021784] [<ffffffff81085511>] __warn+0xd1/0xf0
> [ 611.028115] [<ffffffff8108558f>] warn_slowpath_fmt+0x5f/0x80
> [ 611.035379] [<ffffffff812a4e80>] ? kernfs_path_from_node+0x50/0x60
> [ 611.043148] [<ffffffff812a86c4>] sysfs_warn_dup+0x64/0x80
> [ 611.050109] [<ffffffff812a87ae>] sysfs_create_dir_ns+0x7e/0x90
> [ 611.057481] [<ffffffff81359891>] kobject_add_internal+0xc1/0x340
> [ 611.065018] [<ffffffff81359d45>] kobject_add+0x75/0xd0
> [ 611.071635] [<ffffffff81483829>] device_add+0x119/0x610
> [ 611.078314] [<ffffffff81483d3a>] device_register+0x1a/0x20
> [ 611.085261] [<ffffffffa03c748d>] mdev_device_create+0xdd/0x200 [mdev]
> [ 611.093143] [<ffffffffa03c7768>] create_store+0xa8/0xe0 [mdev]
> [ 611.100385] [<ffffffffa03c76ab>] mdev_type_attr_store+0x1b/0x30 [mdev]
> [ 611.108309] [<ffffffff812a7d8a>] sysfs_kf_write+0x3a/0x50
> [ 611.115096] [<ffffffff812a78bb>] kernfs_fop_write+0x10b/0x190
> [ 611.122231] [<ffffffff81224e97>] __vfs_write+0x37/0x140
> [ 611.128817] [<ffffffff811cea84>] ? handle_mm_fault+0x724/0xd80
> [ 611.135976] [<ffffffff81225da2>] vfs_write+0xb2/0x1b0
> [ 611.142354] [<ffffffff81003510>] ? syscall_trace_enter+0x1d0/0x2b0
> [ 611.149836] [<ffffffff812271f5>] SyS_write+0x55/0xc0
> [ 611.156065] [<ffffffff81003a47>] do_syscall_64+0x67/0x180
> [ 611.162734] [<ffffffff816d41eb>] entry_SYSCALL64_slow_path+0x25/0x25
> [ 611.170345] ---[ end trace b05a73599da2ba3f ]---
> [ 611.175940] ------------[ cut here ]------------
>
>
>
> >> +static ssize_t create_store(struct kobject *kobj, struct device *dev,
> >> + const char *buf, size_t count)
> >> +{
> >> + char *str;
> >> + uuid_le uuid;
> >> + int ret;
> >> +
> >> + if (count < UUID_STRING_LEN)
> >> + return -EINVAL;
> >
> >
> > Can't we also test for something unreasonably large?
> >
>
> Ok. I'll add that check.
>
> >
> >> +
> >> + str = kstrndup(buf, count, GFP_KERNEL);
> >> + if (!str)
> >> + return -ENOMEM;
> >> +
> >> + ret = uuid_le_to_bin(str, &uuid);
> >
> > nit, we can kfree(str) here regardless of the return.
> >
> >> + if (!ret) {
> >> +
> >> + ret = mdev_device_create(kobj, dev, uuid);
> >> + if (ret)
> >> + pr_err("mdev_create: Failed to create mdev device\n");
> >
> > What value does this pr_err add? It doesn't tell us why it failed and
> > the user will already know if failed by the return value of their write.
> >
>
> Ok, will remove it.
>
> >> + else
> >> + ret = count;
> >> + }
> >> +
> >> + kfree(str);
> >> + return ret;
> >> +}
>
> ...
>
> >> +static inline struct mdev_driver *to_mdev_driver(struct device_driver *drv)
> >> +{
> >> + return drv ? container_of(drv, struct mdev_driver, driver) : NULL;
> >> +}
> >> +
> >> +static inline struct mdev_device *to_mdev_device(struct device *dev)
> >> +{
> >> + return dev ? container_of(dev, struct mdev_device, dev) : NULL;
> >
> >
> > Do we really need this NULL dev/drv behavior? I don't see that any of
> > the callers can pass NULL into these. The PCI equivalents don't
> > support this behavior and it doesn't seem they need to. Thanks,
> >
>
> Ok, I'll update that.
>
> Kirti
next prev parent reply other threads:[~2016-10-19 22:20 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-17 21:22 [PATCH v9 00/12] Add Mediated device support Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 01/12] vfio: Mediated device Core driver Kirti Wankhede
2016-10-18 23:16 ` Alex Williamson
2016-10-19 19:16 ` Kirti Wankhede
2016-10-19 22:20 ` Alex Williamson [this message]
2016-10-20 7:23 ` Jike Song
2016-10-20 17:12 ` Alex Williamson
2016-10-21 2:41 ` Jike Song
2016-10-27 5:56 ` Jike Song
2016-10-26 6:52 ` Tian, Kevin
2016-10-26 14:58 ` Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 02/12] vfio: VFIO based driver for Mediated devices Kirti Wankhede
2016-10-26 6:57 ` Tian, Kevin
2016-10-26 15:01 ` Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 03/12] vfio: Rearrange functions to get vfio_group from dev Kirti Wankhede
2016-10-19 17:26 ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 04/12] vfio iommu: Add support for mediated devices Kirti Wankhede
2016-10-19 21:02 ` Alex Williamson
2016-10-20 20:17 ` Kirti Wankhede
2016-10-24 2:32 ` Alex Williamson
2016-10-26 7:19 ` Tian, Kevin
2016-10-26 15:06 ` Kirti Wankhede
2016-10-26 7:53 ` Tian, Kevin
2016-10-26 15:16 ` Alex Williamson
2016-10-26 7:54 ` Tian, Kevin
2016-10-26 15:19 ` Alex Williamson
2016-10-21 7:49 ` Jike Song
2016-10-21 14:36 ` Alex Williamson
2016-10-24 10:35 ` Kirti Wankhede
2016-10-27 7:20 ` [Qemu-devel] " Alexey Kardashevskiy
2016-10-27 12:31 ` Kirti Wankhede
2016-10-27 14:30 ` Alex Williamson
2016-10-27 15:59 ` Kirti Wankhede
2016-10-28 2:18 ` Alexey Kardashevskiy
2016-11-01 14:01 ` Kirti Wankhede
2016-11-02 1:24 ` Alexey Kardashevskiy
2016-11-02 3:29 ` Kirti Wankhede
2016-11-02 4:09 ` Alexey Kardashevskiy
2016-11-02 12:21 ` Jike Song
2016-11-02 12:41 ` Kirti Wankhede
2016-11-02 13:00 ` Jike Song
2016-11-02 13:18 ` Kirti Wankhede
2016-11-02 13:35 ` Jike Song
2016-11-03 4:29 ` Alexey Kardashevskiy
2016-10-17 21:22 ` [PATCH v9 05/12] vfio: Introduce common function to add capabilities Kirti Wankhede
2016-10-20 19:24 ` Alex Williamson
2016-10-24 21:27 ` Kirti Wankhede
2016-10-24 21:39 ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 06/12] vfio_pci: Update vfio_pci to use vfio_info_add_capability() Kirti Wankhede
2016-10-20 19:24 ` Alex Williamson
2016-10-24 21:22 ` Kirti Wankhede
2016-10-24 21:37 ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 07/12] vfio: Introduce vfio_set_irqs_validate_and_prepare() Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 08/12] vfio_pci: Updated to use vfio_set_irqs_validate_and_prepare() Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 09/12] vfio_platform: " Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 10/12] vfio: Add function to get device_api string from vfio_device_info.flags Kirti Wankhede
2016-10-20 19:34 ` Alex Williamson
2016-10-20 20:29 ` Kirti Wankhede
2016-10-20 21:05 ` Alex Williamson
2016-10-20 21:14 ` Kirti Wankhede
2016-10-20 21:22 ` Alex Williamson
2016-10-21 3:00 ` Kirti Wankhede
2016-10-21 3:20 ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 11/12] docs: Add Documentation for Mediated devices Kirti Wankhede
2016-10-25 16:17 ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 12/12] docs: Sample driver to demonstrate how to use Mediated device framework Kirti Wankhede
[not found] ` <20161018025411.GA22572@bjsdjshi@linux.vnet.ibm.com>
2016-10-18 17:17 ` Alex Williamson
2016-10-19 19:19 ` Kirti Wankhede
2016-10-17 21:41 ` [PATCH v9 00/12] Add Mediated device support Alex Williamson
2016-10-24 7:07 ` Jike Song
2016-12-05 17:44 ` Gerd Hoffmann
2016-12-06 2:24 ` Jike Song
2016-12-07 14:40 ` Gerd Hoffmann
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=20161019162030.6e37a6c1@t450s.home \
--to=alex.williamson@redhat.com \
--cc=bjsdjshi@linux.vnet.ibm.com \
--cc=cjia@nvidia.com \
--cc=jike.song@intel.com \
--cc=kevin.tian@intel.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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
all inboxes | Powered by JetHome®