* Re: [PATCH v2 1/3] virtio_pci: use put_device instead of kfree
From: weiping zhang @ 2017-12-15 1:38 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Cornelia Huck, weiping zhang, Greg Kroah-Hartman, virtualization
In-Reply-To: <20171214205538-mutt-send-email-mst@kernel.org>
2017-12-15 3:13 GMT+08:00 Michael S. Tsirkin <mst@redhat.com>:
> On Tue, Dec 12, 2017 at 09:24:02PM +0800, weiping zhang wrote:
>> As mentioned at drivers/base/core.c:
>> /*
>> * NOTE: _Never_ directly free @dev after calling this function, even
>> * if it returned an error! Always use put_device() to give up the
>> * reference initialized in this function instead.
>> */
>> so we don't free vp_dev until vp_dev->vdev.dev.release be called.
>
> seeing as 5739411acbaa63a6c22c91e340fdcdbcc7d82a51 adding these
> annotations went to stable, should this go there too?
>
just let people know the detail reason of using put_device.
>> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>
> OK but this relies on users knowing that register_virtio_device
> calls device_register. I think we want to add a comment
> to register_virtio_device.
>
> Also the cleanup is uglified.
>
> I really think the right thing would be to change device_register making
> it safe to kfree. People have the right to expect register on failure to
> have no effect.
>
> That just might be too hard to implement though.
>
> For now, my suggestion - add a variable.
>
>> ---
>> drivers/virtio/virtio_pci_common.c | 17 +++++++++--------
>> 1 file changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
>> index 1c4797e..91d20f7 100644
>> --- a/drivers/virtio/virtio_pci_common.c
>> +++ b/drivers/virtio/virtio_pci_common.c
>> @@ -551,16 +551,17 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>> pci_set_master(pci_dev);
>>
>> rc = register_virtio_device(&vp_dev->vdev);
>> - if (rc)
>> - goto err_register;
>> + if (rc) {
>> + if (vp_dev->ioaddr)
>> + virtio_pci_legacy_remove(vp_dev);
>> + else
>> + virtio_pci_modern_remove(vp_dev);
>> + pci_disable_device(pci_dev);
>> + put_device(&vp_dev->vdev.dev);
>> + }
>>
>> - return 0;
>> + return rc;
>>
>> -err_register:
>> - if (vp_dev->ioaddr)
>> - virtio_pci_legacy_remove(vp_dev);
>> - else
>> - virtio_pci_modern_remove(vp_dev);
>> err_probe:
>> pci_disable_device(pci_dev);
>> err_enable_device:
>> --
>> 2.9.4
>
> I'd prefer something like the below.
>
> --->
>
> virtio_pci: don't kfree device on register failure
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> ---
>
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index 1c4797e..995ab03 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -513,7 +513,7 @@ static void virtio_pci_release_dev(struct device *_d)
> static int virtio_pci_probe(struct pci_dev *pci_dev,
> const struct pci_device_id *id)
> {
> - struct virtio_pci_device *vp_dev;
> + struct virtio_pci_device *vp_dev, *reg_dev = NULL;
> int rc;
>
> /* allocate our structure and fill it out */
> @@ -551,6 +551,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> pci_set_master(pci_dev);
>
> rc = register_virtio_device(&vp_dev->vdev);
> + /* NOTE: device is considered registered even if register failed. */
> + reg_dev = vp_dev;
> if (rc)
> goto err_register;
>
> @@ -564,7 +566,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> err_probe:
> pci_disable_device(pci_dev);
> err_enable_device:
> - kfree(vp_dev);
> + if (reg_dev)
> + put_device(dev);
> + else
> + kfree(vp_dev);
> return rc;
> }
looks more cleaner and same coding style.
Need I send V3 or apply your patch directly ?
> _______________________________________________
> Virtualization mailing list
> Virtualization@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCH v2 1/3] virtio_pci: use put_device instead of kfree
From: Michael S. Tsirkin @ 2017-12-15 1:48 UTC (permalink / raw)
To: weiping zhang
Cc: Cornelia Huck, weiping zhang, Greg Kroah-Hartman, virtualization
In-Reply-To: <CAA70yB4jyroEGd+rKHMA_AJ93JGTC8Q4qADBs87q3z7x9XwEMQ@mail.gmail.com>
On Fri, Dec 15, 2017 at 09:38:42AM +0800, weiping zhang wrote:
> 2017-12-15 3:13 GMT+08:00 Michael S. Tsirkin <mst@redhat.com>:
> > On Tue, Dec 12, 2017 at 09:24:02PM +0800, weiping zhang wrote:
> >> As mentioned at drivers/base/core.c:
> >> /*
> >> * NOTE: _Never_ directly free @dev after calling this function, even
> >> * if it returned an error! Always use put_device() to give up the
> >> * reference initialized in this function instead.
> >> */
> >> so we don't free vp_dev until vp_dev->vdev.dev.release be called.
> >
> > seeing as 5739411acbaa63a6c22c91e340fdcdbcc7d82a51 adding these
> > annotations went to stable, should this go there too?
> >
> just let people know the detail reason of using put_device.
> >> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> >> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> >
> > OK but this relies on users knowing that register_virtio_device
> > calls device_register. I think we want to add a comment
> > to register_virtio_device.
> >
> > Also the cleanup is uglified.
> >
> > I really think the right thing would be to change device_register making
> > it safe to kfree. People have the right to expect register on failure to
> > have no effect.
> >
> > That just might be too hard to implement though.
> >
> > For now, my suggestion - add a variable.
> >
> >> ---
> >> drivers/virtio/virtio_pci_common.c | 17 +++++++++--------
> >> 1 file changed, 9 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> >> index 1c4797e..91d20f7 100644
> >> --- a/drivers/virtio/virtio_pci_common.c
> >> +++ b/drivers/virtio/virtio_pci_common.c
> >> @@ -551,16 +551,17 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> >> pci_set_master(pci_dev);
> >>
> >> rc = register_virtio_device(&vp_dev->vdev);
> >> - if (rc)
> >> - goto err_register;
> >> + if (rc) {
> >> + if (vp_dev->ioaddr)
> >> + virtio_pci_legacy_remove(vp_dev);
> >> + else
> >> + virtio_pci_modern_remove(vp_dev);
> >> + pci_disable_device(pci_dev);
> >> + put_device(&vp_dev->vdev.dev);
> >> + }
> >>
> >> - return 0;
> >> + return rc;
> >>
> >> -err_register:
> >> - if (vp_dev->ioaddr)
> >> - virtio_pci_legacy_remove(vp_dev);
> >> - else
> >> - virtio_pci_modern_remove(vp_dev);
> >> err_probe:
> >> pci_disable_device(pci_dev);
> >> err_enable_device:
> >> --
> >> 2.9.4
> >
> > I'd prefer something like the below.
> >
> > --->
> >
> > virtio_pci: don't kfree device on register failure
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >
> > ---
> >
> > diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> > index 1c4797e..995ab03 100644
> > --- a/drivers/virtio/virtio_pci_common.c
> > +++ b/drivers/virtio/virtio_pci_common.c
> > @@ -513,7 +513,7 @@ static void virtio_pci_release_dev(struct device *_d)
> > static int virtio_pci_probe(struct pci_dev *pci_dev,
> > const struct pci_device_id *id)
> > {
> > - struct virtio_pci_device *vp_dev;
> > + struct virtio_pci_device *vp_dev, *reg_dev = NULL;
> > int rc;
> >
> > /* allocate our structure and fill it out */
> > @@ -551,6 +551,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> > pci_set_master(pci_dev);
> >
> > rc = register_virtio_device(&vp_dev->vdev);
> > + /* NOTE: device is considered registered even if register failed. */
> > + reg_dev = vp_dev;
> > if (rc)
> > goto err_register;
> >
> > @@ -564,7 +566,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> > err_probe:
> > pci_disable_device(pci_dev);
> > err_enable_device:
> > - kfree(vp_dev);
> > + if (reg_dev)
> > + put_device(dev);
> > + else
> > + kfree(vp_dev);
> > return rc;
> > }
> looks more cleaner and same coding style.
> Need I send V3 or apply your patch directly ?
Pls post v3 updating all patches to this style.
Also just to make sure, none of this is a regression and none
of this causes actual known issues right?
I think it's preferrable to defer to next merge cycle unless this
is a regression.
> > _______________________________________________
> > Virtualization mailing list
> > Virtualization@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCHv2] virtio_mmio: fix devm cleanup
From: weiping zhang @ 2017-12-15 1:48 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Mark Rutland, Cornelia Huck, weiping zhang,
Linux Kernel Mailing List, virtualization
In-Reply-To: <20171214204808-mutt-send-email-mst@kernel.org>
2017-12-15 2:48 GMT+08:00 Michael S. Tsirkin <mst@redhat.com>:
> On Wed, Dec 13, 2017 at 02:34:14PM +0000, Mark Rutland wrote:
>> On Tue, Dec 12, 2017 at 06:02:23PM +0100, Cornelia Huck wrote:
>> > On Tue, 12 Dec 2017 13:45:50 +0000
>> > Mark Rutland <mark.rutland@arm.com> wrote:
>> >
>> > > Recent rework of the virtio_mmio probe/remove paths balanced a
>> > > devm_ioremap() with an iounmap() rather than its devm variant. This ends
>> > > up corrupting the devm datastructures, and results in the following
>> > > boot-time splat on arm64 under QEMU 2.9.0:
>> > >
>> > > [ 3.450397] ------------[ cut here ]------------
>> > > [ 3.453822] Trying to vfree() nonexistent vm area (00000000c05b4844)
>> > > [ 3.460534] WARNING: CPU: 1 PID: 1 at mm/vmalloc.c:1525 __vunmap+0x1b8/0x220
>> > > [ 3.475898] Kernel panic - not syncing: panic_on_warn set ...
>> > > [ 3.475898]
>> > > [ 3.493933] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.15.0-rc3 #1
>> > > [ 3.513109] Hardware name: linux,dummy-virt (DT)
>> > > [ 3.525382] Call trace:
>> > > [ 3.531683] dump_backtrace+0x0/0x368
>> > > [ 3.543921] show_stack+0x20/0x30
>> > > [ 3.547767] dump_stack+0x108/0x164
>> > > [ 3.559584] panic+0x25c/0x51c
>> > > [ 3.569184] __warn+0x29c/0x31c
>> > > [ 3.576023] report_bug+0x1d4/0x290
>> > > [ 3.586069] bug_handler.part.2+0x40/0x100
>> > > [ 3.597820] bug_handler+0x4c/0x88
>> > > [ 3.608400] brk_handler+0x11c/0x218
>> > > [ 3.613430] do_debug_exception+0xe8/0x318
>> > > [ 3.627370] el1_dbg+0x18/0x78
>> > > [ 3.634037] __vunmap+0x1b8/0x220
>> > > [ 3.648747] vunmap+0x6c/0xc0
>> > > [ 3.653864] __iounmap+0x44/0x58
>> > > [ 3.659771] devm_ioremap_release+0x34/0x68
>> > > [ 3.672983] release_nodes+0x404/0x880
>> > > [ 3.683543] devres_release_all+0x6c/0xe8
>> > > [ 3.695692] driver_probe_device+0x250/0x828
>> > > [ 3.706187] __driver_attach+0x190/0x210
>> > > [ 3.717645] bus_for_each_dev+0x14c/0x1f0
>> > > [ 3.728633] driver_attach+0x48/0x78
>> > > [ 3.740249] bus_add_driver+0x26c/0x5b8
>> > > [ 3.752248] driver_register+0x16c/0x398
>> > > [ 3.757211] __platform_driver_register+0xd8/0x128
>> > > [ 3.770860] virtio_mmio_init+0x1c/0x24
>> > > [ 3.782671] do_one_initcall+0xe0/0x398
>> > > [ 3.791890] kernel_init_freeable+0x594/0x660
>> > > [ 3.798514] kernel_init+0x18/0x190
>> > > [ 3.810220] ret_from_fork+0x10/0x18
>> > >
>> > > To fix this, we can simply rip out the explicit cleanup that the devm
>> > > infrastructure will do for us when our probe function returns an error
>> > > code, or when our remove function returns.
>> > >
>> > > We only need to ensure that we call put_device() if a call to
>> > > register_virtio_device() fails in the probe path.
>> > >
>> > > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
>> > > Fixes: 7eb781b1bbb7136f ("virtio_mmio: add cleanup for virtio_mmio_probe")
>> > > Fixes: 25f32223bce5c580 ("virtio_mmio: add cleanup for virtio_mmio_remove")
>> > > Cc: Cornelia Huck <cohuck@redhat.com>
>> > > Cc: Michael S. Tsirkin <mst@redhat.com>
>> > > Cc: weiping zhang <zhangweiping@didichuxing.com>
>> > > Cc: virtualization@lists.linux-foundation.org
>> > > ---
>> > > drivers/virtio/virtio_mmio.c | 43 +++++++++----------------------------------
>> > > 1 file changed, 9 insertions(+), 34 deletions(-)
>> >
>> > In the hope that I have grokked the devm_* interface by now,
>> >
>> > Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>>
>> Thanks!
>>
>> Michael, could you please queue this as a fix for v4.15?
>>
>> This regressed arm64 VMs booting between v4.15-rc1 and v4-15-rc2,
>> impacting our automated regression testing, and I'd very much like to
>> get back to testing pure mainline rather than mainline + local fixes.
>>
>> Thanks,
>> Mark.
>
> Yep, plan to.
> Thanks!
Sorry to bother again,
As we know if we call device_register we should keep vdev alive until
dev.release be called. As discuss with Cornelia before,
> - return register_virtio_device(&vm_dev->vdev);
> + rc = register_virtio_device(&vm_dev->vdev);
> + if (rc)
> + goto put_dev;
> + return 0;
> +put_dev:
> + put_device(&vm_dev->vdev.dev);
> Here you give up the extra reference from device_initialize(), which
> may or may not be the last reference (since you don't know if
> device_add() had already exposed the struct device to other code that
> might have acquired a reference). As the device has an empty release
> function, touching the device structure after that is not a real
> problem, but...
cuase devm_ interface will free vdev if probe fail, even dev.ref count not
dev to 0. So devm_ interface, may be not very suitable for device_register.
______________________________________________
> Virtualization mailing list
> Virtualization@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCH v19 2/7] xbitmap: potential improvement
From: kbuild test robot @ 2017-12-15 3:07 UTC (permalink / raw)
To: Wei Wang
Cc: yang.zhang.wz, kvm, mst, penguin-kernel, liliang.opensource,
qemu-devel, virtualization, linux-mm, aarcange, virtio-dev,
mawilcox, willy, quan.xu, nilal, riel, cornelia.huck, mhocko,
linux-kernel, kbuild-all, amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <1513079759-14169-3-git-send-email-wei.w.wang@intel.com>
[-- Attachment #1: Type: text/plain, Size: 2729 bytes --]
Hi Wei,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.15-rc3 next-20171214]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Wei-Wang/Virtio-balloon-Enhancement/20171215-100525
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
Note: the linux-review/Wei-Wang/Virtio-balloon-Enhancement/20171215-100525 HEAD 607ddba072bf7f9c9cbacedaccad7c42c5c7149c builds fine.
It only hurts bisectibility.
All errors (new ones prefixed by >>):
>> lib/xbitmap.c:80:6: error: conflicting types for 'xb_clear_bit'
void xb_clear_bit(struct xb *xb, unsigned long bit)
^~~~~~~~~~~~
In file included from lib/xbitmap.c:2:0:
include/linux/xbitmap.h:37:5: note: previous declaration of 'xb_clear_bit' was here
int xb_clear_bit(struct xb *xb, unsigned long bit);
^~~~~~~~~~~~
vim +/xb_clear_bit +80 lib/xbitmap.c
71
72 /**
73 * xb_clear_bit - clear a bit in the xbitmap
74 * @xb: the xbitmap tree used to record the bit
75 * @bit: index of the bit to clear
76 *
77 * This function is used to clear a bit in the xbitmap. If all the bits of the
78 * bitmap are 0, the bitmap will be freed.
79 */
> 80 void xb_clear_bit(struct xb *xb, unsigned long bit)
81 {
82 unsigned long index = bit / IDA_BITMAP_BITS;
83 struct radix_tree_root *root = &xb->xbrt;
84 struct radix_tree_node *node;
85 void **slot;
86 struct ida_bitmap *bitmap;
87 unsigned long ebit;
88
89 bit %= IDA_BITMAP_BITS;
90 ebit = bit + 2;
91
92 bitmap = __radix_tree_lookup(root, index, &node, &slot);
93 if (radix_tree_exception(bitmap)) {
94 unsigned long tmp = (unsigned long)bitmap;
95
96 if (ebit >= BITS_PER_LONG)
97 return;
98 tmp &= ~(1UL << ebit);
99 if (tmp == RADIX_TREE_EXCEPTIONAL_ENTRY)
100 __radix_tree_delete(root, node, slot);
101 else
102 rcu_assign_pointer(*slot, (void *)tmp);
103 return;
104 }
105
106 if (!bitmap)
107 return;
108
109 __clear_bit(bit, bitmap->bitmap);
110 if (bitmap_empty(bitmap->bitmap, IDA_BITMAP_BITS)) {
111 kfree(bitmap);
112 __radix_tree_delete(root, node, slot);
113 }
114 }
115 EXPORT_SYMBOL(xb_clear_bit);
116
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6769 bytes --]
[-- Attachment #3: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCH v19 1/7] xbitmap: Introduce xbitmap
From: kbuild test robot @ 2017-12-15 11:05 UTC (permalink / raw)
To: Wei Wang
Cc: yang.zhang.wz, kvm, mst, penguin-kernel, liliang.opensource,
qemu-devel, virtualization, linux-mm, aarcange, virtio-dev,
mawilcox, willy, quan.xu, nilal, riel, cornelia.huck, mhocko,
linux-kernel, kbuild-all, amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <1513079759-14169-2-git-send-email-wei.w.wang@intel.com>
Hi Matthew,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.15-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Wei-Wang/Virtio-balloon-Enhancement/20171215-100525
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__
sparse warnings: (new ones prefixed by >>)
vim +29 lib/xbitmap.c
5
6 /**
7 * xb_set_bit - set a bit in the xbitmap
8 * @xb: the xbitmap tree used to record the bit
9 * @bit: index of the bit to set
10 *
11 * This function is used to set a bit in the xbitmap. If the bitmap that @bit
12 * resides in is not there, the per-cpu ida_bitmap will be taken.
13 *
14 * Returns: 0 on success. %-EAGAIN indicates that @bit was not set.
15 */
16 int xb_set_bit(struct xb *xb, unsigned long bit)
17 {
18 int err;
19 unsigned long index = bit / IDA_BITMAP_BITS;
20 struct radix_tree_root *root = &xb->xbrt;
21 struct radix_tree_node *node;
22 void **slot;
23 struct ida_bitmap *bitmap;
24 unsigned long ebit;
25
26 bit %= IDA_BITMAP_BITS;
27 ebit = bit + 2;
28
> 29 err = __radix_tree_create(root, index, 0, &node, &slot);
30 if (err)
31 return err;
32 bitmap = rcu_dereference_raw(*slot);
33 if (radix_tree_exception(bitmap)) {
34 unsigned long tmp = (unsigned long)bitmap;
35
36 if (ebit < BITS_PER_LONG) {
37 tmp |= 1UL << ebit;
38 rcu_assign_pointer(*slot, (void *)tmp);
39 return 0;
40 }
41 bitmap = this_cpu_xchg(ida_bitmap, NULL);
42 if (!bitmap)
43 return -EAGAIN;
44 memset(bitmap, 0, sizeof(*bitmap));
45 bitmap->bitmap[0] = tmp >> RADIX_TREE_EXCEPTIONAL_SHIFT;
46 rcu_assign_pointer(*slot, bitmap);
47 }
48
49 if (!bitmap) {
50 if (ebit < BITS_PER_LONG) {
51 bitmap = (void *)((1UL << ebit) |
52 RADIX_TREE_EXCEPTIONAL_ENTRY);
> 53 __radix_tree_replace(root, node, slot, bitmap, NULL);
54 return 0;
55 }
56 bitmap = this_cpu_xchg(ida_bitmap, NULL);
57 if (!bitmap)
58 return -EAGAIN;
59 memset(bitmap, 0, sizeof(*bitmap));
60 __radix_tree_replace(root, node, slot, bitmap, NULL);
61 }
62
63 __set_bit(bit, bitmap->bitmap);
64 return 0;
65 }
66 EXPORT_SYMBOL(xb_set_bit);
67
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
^ permalink raw reply
* Re: [PATCH v2 1/3] virtio_pci: use put_device instead of kfree
From: Cornelia Huck @ 2017-12-15 12:21 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Greg Kroah-Hartman, weiping zhang, virtualization
In-Reply-To: <20171214205538-mutt-send-email-mst@kernel.org>
On Thu, 14 Dec 2017 21:13:28 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Tue, Dec 12, 2017 at 09:24:02PM +0800, weiping zhang wrote:
> > As mentioned at drivers/base/core.c:
> > /*
> > * NOTE: _Never_ directly free @dev after calling this function, even
> > * if it returned an error! Always use put_device() to give up the
> > * reference initialized in this function instead.
> > */
> > so we don't free vp_dev until vp_dev->vdev.dev.release be called.
>
> seeing as 5739411acbaa63a6c22c91e340fdcdbcc7d82a51 adding these
> annotations went to stable, should this go there too?
>
> > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> > Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>
> OK but this relies on users knowing that register_virtio_device
> calls device_register. I think we want to add a comment
> to register_virtio_device.
>
> Also the cleanup is uglified.
>
> I really think the right thing would be to change device_register making
> it safe to kfree. People have the right to expect register on failure to
> have no effect.
>
> That just might be too hard to implement though.
Yes. The main problem is that device_register() at some point makes the
structure visible to others, at which point they may obtain a
reference. If that happened, you cannot clean up unless that other
party gave up their reference -- which means your only chance to get
this right is the current put_device() approach.
It *is* problematic if all of that stuff is hidden behind too many
calling layers. If you have the device_initialize() -> device_add()
calling sequence, having to do a put_device() on failure is much more
obvious. But as you usually don't pass in a pure struct device but
something embedding it, the put_device() needs to be done on the
outermost level.
Commenting can help here, as would probably a static checker for that
code pattern.
^ permalink raw reply
* Re: [PATCH v2 1/3] virtio_pci: use put_device instead of kfree
From: Cornelia Huck @ 2017-12-15 12:32 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Greg Kroah-Hartman, weiping zhang, virtualization
In-Reply-To: <20171215034700-mutt-send-email-mst@kernel.org>
On Fri, 15 Dec 2017 03:48:09 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> Also just to make sure, none of this is a regression and none
> of this causes actual known issues right?
>
> I think it's preferrable to defer to next merge cycle unless this
> is a regression.
I noticed this while looking at the cleanup path for
regsiter_virtio_device(), I don't think any actual problems have been
seen in the wild (just a latent bug). Deferring to the next merge
window seems reasonable.
^ permalink raw reply
* Re: [PATCH v19 1/7] xbitmap: Introduce xbitmap
From: Matthew Wilcox @ 2017-12-15 13:24 UTC (permalink / raw)
To: kbuild test robot
Cc: yang.zhang.wz, kvm, mst, penguin-kernel, liliang.opensource,
qemu-devel, virtualization, linux-mm, aarcange, virtio-dev,
mawilcox, quan.xu, nilal, riel, cornelia.huck, mhocko,
linux-kernel, kbuild-all, amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <201712151837.MQq7hdgk%fengguang.wu@intel.com>
On Fri, Dec 15, 2017 at 07:05:07PM +0800, kbuild test robot wrote:
> 21 struct radix_tree_node *node;
> 22 void **slot;
^^^
missing __rcu annotation here.
Wei, could you fold that change into your next round? Thanks!
^ permalink raw reply
* [PULL] vhost: regression fixes
From: Michael S. Tsirkin @ 2017-12-15 18:19 UTC (permalink / raw)
To: Linus Torvalds
Cc: mark.rutland, kvm, mst, netdev, cohuck, linux-kernel,
virtualization, zhangweiping
The following changes since commit 03e9f8a05bce7330bcd9c5cc54c8e42d0fcbf993:
virtio_net: fix return value check in receive_mergeable() (2017-12-07 18:34:52 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git tags/for_linus
for you to fetch changes up to c2e90800aef22e7ea14ea7560ba99993f11d3616:
virtio_mmio: fix devm cleanup (2017-12-14 21:01:40 +0200)
----------------------------------------------------------------
virtio: regression fixes
Fixes two issues in the latest kernel.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
----------------------------------------------------------------
Mark Rutland (1):
virtio_mmio: fix devm cleanup
Michael S. Tsirkin (1):
ptr_ring: fix up after recent ptr_ring changes
drivers/virtio/virtio_mmio.c | 43 +++++++++-------------------------------
tools/virtio/ringtest/ptr_ring.c | 29 +++++++++++++++++++++------
2 files changed, 32 insertions(+), 40 deletions(-)
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Michael S. Tsirkin @ 2017-12-15 18:26 UTC (permalink / raw)
To: Tetsuo Handa
Cc: yang.zhang.wz, kvm, liliang.opensource, qemu-devel,
virtualization, linux-mm, aarcange, virtio-dev, mawilcox, willy,
quan.xu, nilal, riel, cornelia.huck, mhocko, linux-kernel,
amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <201712160121.BEJ26052.HOFFOOQFMLtSVJ@I-love.SAKURA.ne.jp>
On Sat, Dec 16, 2017 at 01:21:52AM +0900, Tetsuo Handa wrote:
> My understanding is that virtio-balloon wants to handle sparsely spreaded
> unsigned long values (which is PATCH 4/7) and wants to find all chunks of
> consecutive "1" bits efficiently. Therefore, I guess that holding the values
> in ascending order at store time is faster than sorting the values at read
> time.
Are you asking why is a bitmap used here, as opposed to a tree? It's
not just store versus read. There's also the issue that memory can get
highly fragmented, if it is, the number of 1s is potentially very high.
A bitmap can use as little as 1 bit per value, it is hard to beat in
this respect.
--
MST
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Matthew Wilcox @ 2017-12-15 18:42 UTC (permalink / raw)
To: Wei Wang
Cc: yang.zhang.wz, kvm, mst, penguin-kernel, liliang.opensource,
qemu-devel, virtualization, linux-mm, aarcange, virtio-dev,
mawilcox, quan.xu, nilal, riel, cornelia.huck, mhocko,
linux-kernel, amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <1513079759-14169-4-git-send-email-wei.w.wang@intel.com>
On Tue, Dec 12, 2017 at 07:55:55PM +0800, Wei Wang wrote:
> +int xb_preload_and_set_bit(struct xb *xb, unsigned long bit, gfp_t gfp);
I'm struggling to understand when one would use this. The xb_ API
requires you to handle your own locking. But specifying GFP flags
here implies you can sleep. So ... um ... there's no locking?
> +void xb_clear_bit_range(struct xb *xb, unsigned long start, unsigned long end);
That's xb_zero() which you deleted with the previous patch ... remember,
keep things as close as possible to the bitmap API.
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Matthew Wilcox @ 2017-12-15 18:49 UTC (permalink / raw)
To: Tetsuo Handa
Cc: yang.zhang.wz, kvm, mst, liliang.opensource, qemu-devel,
virtualization, linux-mm, aarcange, virtio-dev, mawilcox, quan.xu,
nilal, riel, cornelia.huck, mhocko, linux-kernel, amit.shah,
pbonzini, akpm, mgorman
In-Reply-To: <201712160121.BEJ26052.HOFFOOQFMLtSVJ@I-love.SAKURA.ne.jp>
On Sat, Dec 16, 2017 at 01:21:52AM +0900, Tetsuo Handa wrote:
> My understanding is that virtio-balloon wants to handle sparsely spreaded
> unsigned long values (which is PATCH 4/7) and wants to find all chunks of
> consecutive "1" bits efficiently. Therefore, I guess that holding the values
> in ascending order at store time is faster than sorting the values at read
> time. I don't know how to use radix tree API, but I think that B+ tree API
> suits for holding the values in ascending order.
>
> We wait for Wei to post radix tree version combined into one patch and then
> compare performance between radix tree version and B+ tree version (shown
> below)?
Sure. We all benefit from some friendly competition. Even if a
competition between trees might remind one of the Entmoot ;-)
But let's not hold back -- let's figure out some good workloads to use
in our competition. And we should also decide on the API / locking
constraints. And of course we should compete based on not just speed,
but also memory consumption (both as a runtime overhead for a given set
of bits and as code size). If you can replace the IDR, you get to count
that savings against the cost of your implementation.
Here's the API I'm looking at right now. The user need take no lock;
the locking (spinlock) is handled internally to the implementation.
void xbit_init(struct xbitmap *xb);
int xbit_alloc(struct xbitmap *, unsigned long bit, gfp_t);
int xbit_alloc_range(struct xbitmap *, unsigned long start,
unsigned long nbits, gfp_t);
int xbit_set(struct xbitmap *, unsigned long bit, gfp_t);
bool xbit_test(struct xbitmap *, unsigned long bit);
int xbit_clear(struct xbitmap *, unsigned long bit);
int xbit_zero(struct xbitmap *, unsigned long start, unsigned long nbits);
int xbit_fill(struct xbitmap *, unsigned long start, unsigned long nbits,
gfp_t);
unsigned long xbit_find_clear(struct xbitmap *, unsigned long start,
unsigned long max);
unsigned long xbit_find_set(struct xbitmap *, unsigned long start,
unsigned long max);
> static bool set_ulong(struct ulong_list_head *head, const unsigned long value)
> {
> if (!ptr) {
> ptr = kzalloc(sizeof(*ptr), GFP_NOWAIT | __GFP_NOWARN);
> if (!ptr)
> goto out1;
> ptr->bitmap = kzalloc(BITMAP_LEN / 8,
> GFP_NOWAIT | __GFP_NOWARN);
> if (!ptr->bitmap)
> goto out2;
> if (btree_insertl(&head->btree, ~segment, ptr,
> GFP_NOWAIT | __GFP_NOWARN))
> goto out3;
> out3:
> kfree(ptr->bitmap);
> out2:
> kfree(ptr);
> out1:
> return false;
> }
And what is the user supposed to do if this returns false? How do they
make headway? The xb_ API is clear -- you call xb_prealloc and that
ensures forward progress.
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Matthew Wilcox @ 2017-12-15 19:22 UTC (permalink / raw)
To: Tetsuo Handa
Cc: yang.zhang.wz, kvm, mst, liliang.opensource, qemu-devel,
virtualization, linux-mm, aarcange, virtio-dev, mawilcox, quan.xu,
nilal, riel, cornelia.huck, mhocko, linux-kernel, amit.shah,
pbonzini, akpm, mgorman
In-Reply-To: <20171215184915.GB27160@bombadil.infradead.org>
On Fri, Dec 15, 2017 at 10:49:15AM -0800, Matthew Wilcox wrote:
> Here's the API I'm looking at right now. The user need take no lock;
> the locking (spinlock) is handled internally to the implementation.
I looked at the API some more and found some flaws:
- how does xbit_alloc communicate back which bit it allocated?
- What if xbit_find_set() is called on a completely empty array with
a range of 0, ULONG_MAX -- there's no invalid number to return.
- xbit_clear() can't return an error. Neither can xbit_zero().
- Need to add __must_check to various return values to discourage sloppy
programming
So I modify the proposed API we compete with thusly:
bool xbit_test(struct xbitmap *, unsigned long bit);
int __must_check xbit_set(struct xbitmap *, unsigned long bit, gfp_t);
void xbit_clear(struct xbitmap *, unsigned long bit);
int __must_check xbit_alloc(struct xbitmap *, unsigned long *bit, gfp_t);
int __must_check xbit_fill(struct xbitmap *, unsigned long start,
unsigned long nbits, gfp_t);
void xbit_zero(struct xbitmap *, unsigned long start, unsigned long nbits);
int __must_check xbit_alloc_range(struct xbitmap *, unsigned long *bit,
unsigned long nbits, gfp_t);
bool xbit_find_clear(struct xbitmap *, unsigned long *start, unsigned long max);
bool xbit_find_set(struct xbitmap *, unsigned long *start, unsigned long max);
(I'm a little sceptical about the API accepting 'max' for the find
functions and 'nbits' in the fill/zero/alloc_range functions, but I think
that matches how people want to use it, and it matches how bitmap.h works)
^ permalink raw reply
* Re: [PATCH] drm/virtio: Add window server support
From: kbuild test robot @ 2017-12-16 0:50 UTC (permalink / raw)
Cc: Tomeu Vizoso, Michael S. Tsirkin, David Airlie, linux-kernel,
dri-devel, virtualization, kbuild-all
In-Reply-To: <20171214124323.10139-1-tomeu.vizoso@collabora.com>
[-- Attachment #1: Type: text/plain, Size: 2675 bytes --]
Hi Tomeu,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.15-rc3]
[cannot apply to drm/drm-next drm-exynos/exynos-drm/for-next next-20171215]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Tomeu-Vizoso/drm-virtio-Add-window-server-support/20171216-081939
config: i386-randconfig-x016-201750 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
drivers/gpu/drm/virtio/virtgpu_ioctl.c: In function 'winsrv_ioctl_rx':
>> drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (copy_to_user((void *)cmd->data + read_count,
^
drivers/gpu/drm/virtio/virtgpu_ioctl.c: In function 'winsrv_ioctl':
drivers/gpu/drm/virtio/virtgpu_ioctl.c:615:5: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
(const char __user *) winsrv_cmd.data,
^
vim +562 drivers/gpu/drm/virtio/virtgpu_ioctl.c
547
548 static int winsrv_ioctl_rx(struct virtio_gpu_device *vgdev,
549 struct virtio_gpu_winsrv_conn *conn,
550 struct drm_virtgpu_winsrv *cmd)
551 {
552 struct virtio_gpu_winsrv_rx_qentry *qentry, *tmp;
553 struct virtio_gpu_winsrv_rx *virtio_cmd;
554 int available_len = cmd->len;
555 int read_count = 0;
556
557 list_for_each_entry_safe(qentry, tmp, &conn->cmdq, next) {
558 virtio_cmd = qentry->cmd;
559 if (virtio_cmd->len > available_len)
560 return 0;
561
> 562 if (copy_to_user((void *)cmd->data + read_count,
563 virtio_cmd->data,
564 virtio_cmd->len)) {
565 /* return error unless we have some data to return */
566 if (read_count == 0)
567 return -EFAULT;
568 }
569
570 /*
571 * here we could export resource IDs to FDs, but no protocol
572 * as of today requires it
573 */
574
575 available_len -= virtio_cmd->len;
576 read_count += virtio_cmd->len;
577
578 virtio_gpu_queue_winsrv_rx_in(vgdev, virtio_cmd);
579
580 list_del(&qentry->next);
581 kfree(qentry);
582 }
583
584 cmd->len = read_count;
585
586 return 0;
587 }
588
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 23999 bytes --]
[-- Attachment #3: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCH] drm/virtio: Add window server support
From: kbuild test robot @ 2017-12-16 0:58 UTC (permalink / raw)
Cc: Tomeu Vizoso, Michael S. Tsirkin, David Airlie, linux-kernel,
dri-devel, virtualization, kbuild-all
In-Reply-To: <20171214124323.10139-1-tomeu.vizoso@collabora.com>
[-- Attachment #1: Type: text/plain, Size: 4459 bytes --]
Hi Tomeu,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.15-rc3]
[cannot apply to drm/drm-next drm-exynos/exynos-drm/for-next next-20171215]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Tomeu-Vizoso/drm-virtio-Add-window-server-support/20171216-081939
config: i386-randconfig-x002-201750 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
In file included from include/linux/kernel.h:10:0,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from include/uapi/linux/aio_abi.h:31,
from include/linux/syscalls.h:72,
from drivers/gpu/drm/virtio/virtgpu_ioctl.c:29:
drivers/gpu/drm/virtio/virtgpu_ioctl.c: In function 'winsrv_ioctl_rx':
drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (copy_to_user((void *)cmd->data + read_count,
^
include/linux/compiler.h:58:30: note: in definition of macro '__trace_if'
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
^~~~
>> drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:3: note: in expansion of macro 'if'
if (copy_to_user((void *)cmd->data + read_count,
^~
drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (copy_to_user((void *)cmd->data + read_count,
^
include/linux/compiler.h:58:42: note: in definition of macro '__trace_if'
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
^~~~
>> drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:3: note: in expansion of macro 'if'
if (copy_to_user((void *)cmd->data + read_count,
^~
drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
if (copy_to_user((void *)cmd->data + read_count,
^
include/linux/compiler.h:69:16: note: in definition of macro '__trace_if'
______r = !!(cond); \
^~~~
>> drivers/gpu/drm/virtio/virtgpu_ioctl.c:562:3: note: in expansion of macro 'if'
if (copy_to_user((void *)cmd->data + read_count,
^~
drivers/gpu/drm/virtio/virtgpu_ioctl.c: In function 'winsrv_ioctl':
drivers/gpu/drm/virtio/virtgpu_ioctl.c:615:5: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
(const char __user *) winsrv_cmd.data,
^
vim +/if +562 drivers/gpu/drm/virtio/virtgpu_ioctl.c
547
548 static int winsrv_ioctl_rx(struct virtio_gpu_device *vgdev,
549 struct virtio_gpu_winsrv_conn *conn,
550 struct drm_virtgpu_winsrv *cmd)
551 {
552 struct virtio_gpu_winsrv_rx_qentry *qentry, *tmp;
553 struct virtio_gpu_winsrv_rx *virtio_cmd;
554 int available_len = cmd->len;
555 int read_count = 0;
556
557 list_for_each_entry_safe(qentry, tmp, &conn->cmdq, next) {
558 virtio_cmd = qentry->cmd;
559 if (virtio_cmd->len > available_len)
560 return 0;
561
> 562 if (copy_to_user((void *)cmd->data + read_count,
563 virtio_cmd->data,
564 virtio_cmd->len)) {
565 /* return error unless we have some data to return */
566 if (read_count == 0)
567 return -EFAULT;
568 }
569
570 /*
571 * here we could export resource IDs to FDs, but no protocol
572 * as of today requires it
573 */
574
575 available_len -= virtio_cmd->len;
576 read_count += virtio_cmd->len;
577
578 virtio_gpu_queue_winsrv_rx_in(vgdev, virtio_cmd);
579
580 list_del(&qentry->next);
581 kfree(qentry);
582 }
583
584 cmd->len = read_count;
585
586 return 0;
587 }
588
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 27343 bytes --]
[-- Attachment #3: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Matthew Wilcox @ 2017-12-16 5:05 UTC (permalink / raw)
To: Tetsuo Handa
Cc: yang.zhang.wz, kvm, mst, liliang.opensource, qemu-devel,
virtualization, linux-mm, aarcange, virtio-dev, mawilcox, quan.xu,
nilal, riel, cornelia.huck, mhocko, linux-kernel, amit.shah,
pbonzini, akpm, mgorman
In-Reply-To: <201712161331.ABI26579.OtOMFSOLHVFFQJ@I-love.SAKURA.ne.jp>
On Sat, Dec 16, 2017 at 01:31:24PM +0900, Tetsuo Handa wrote:
> Michael S. Tsirkin wrote:
> > On Sat, Dec 16, 2017 at 01:21:52AM +0900, Tetsuo Handa wrote:
> > > My understanding is that virtio-balloon wants to handle sparsely spreaded
> > > unsigned long values (which is PATCH 4/7) and wants to find all chunks of
> > > consecutive "1" bits efficiently. Therefore, I guess that holding the values
> > > in ascending order at store time is faster than sorting the values at read
> > > time.
What makes you think that the radix tree (also xbitmap, also idr) doesn't
sort the values at store time?
> I'm asking whether we really need to invent a new library module (i.e.
> PATCH 1/7 + PATCH 2/7 + PATCH 3/7) for virtio-balloon compared to mine.
>
> What virtio-balloon needs is ability to
>
> (1) record any integer value in [0, ULONG_MAX] range
>
> (2) fetch all recorded values, with consecutive values combined in
> min,max (or start,count) form for efficiently
>
> and I wonder whether we need to invent complete API set which
> Matthew Wilcox and Wei Wang are planning for generic purpose.
The xbitmap absolutely has that ability. And making it generic code
means more people see it, use it, debug it, optimise it. I originally
wrote the implementation for bcache, when Kent was complaining we didn't
have such a thing. His needs weren't as complex as Wei's, which is why
I hadn't implemented everything that Wei needed.
^ permalink raw reply
* Re: [PATCH v19 1/7] xbitmap: Introduce xbitmap
From: Wei Wang @ 2017-12-16 10:10 UTC (permalink / raw)
To: Matthew Wilcox, kbuild test robot
Cc: yang.zhang.wz, kvm, mst, penguin-kernel, liliang.opensource,
qemu-devel, virtualization, linux-mm, aarcange, virtio-dev,
mawilcox, quan.xu, nilal, riel, cornelia.huck, mhocko,
linux-kernel, kbuild-all, amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <20171215132405.GB10348@bombadil.infradead.org>
On 12/15/2017 09:24 PM, Matthew Wilcox wrote:
> On Fri, Dec 15, 2017 at 07:05:07PM +0800, kbuild test robot wrote:
>> 21 struct radix_tree_node *node;
>> 22 void **slot;
> ^^^
> missing __rcu annotation here.
>
> Wei, could you fold that change into your next round? Thanks!
>
Sure, I'll do. Thanks for your time on this patch series.
Best,
Wei
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Wei Wang @ 2017-12-16 10:12 UTC (permalink / raw)
To: Matthew Wilcox
Cc: yang.zhang.wz, kvm, mst, penguin-kernel, liliang.opensource,
qemu-devel, virtualization, linux-mm, aarcange, virtio-dev,
mawilcox, quan.xu, nilal, riel, cornelia.huck, mhocko,
linux-kernel, amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <20171215184256.GA27160@bombadil.infradead.org>
On 12/16/2017 02:42 AM, Matthew Wilcox wrote:
> On Tue, Dec 12, 2017 at 07:55:55PM +0800, Wei Wang wrote:
>> +int xb_preload_and_set_bit(struct xb *xb, unsigned long bit, gfp_t gfp);
> I'm struggling to understand when one would use this. The xb_ API
> requires you to handle your own locking. But specifying GFP flags
> here implies you can sleep. So ... um ... there's no locking?
In the regular use cases, people would do xb_preload() before taking the
lock, and the xb_set/clear within the lock.
In the virtio-balloon usage, we have a large number of bits to set with
the balloon_lock being held (we're not unlocking for each bit), so we
used the above wrapper to do preload and set within the balloon_lock,
and passed in GFP_NOWAIT to avoid sleeping. Probably we can change to
put this wrapper implementation to virtio-balloon, since it would not be
useful for the regular cases.
Best,
Wei
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Wei Wang @ 2017-12-16 10:14 UTC (permalink / raw)
To: Tetsuo Handa
Cc: yang.zhang.wz, kvm, mst, liliang.opensource, qemu-devel,
virtualization, linux-mm, aarcange, virtio-dev, mawilcox, willy,
quan.xu, nilal, riel, cornelia.huck, mhocko, linux-kernel,
amit.shah, pbonzini, akpm, mgorman
In-Reply-To: <201712150129.BFC35949.FFtFOLSOJOQHVM@I-love.SAKURA.ne.jp>
On 12/15/2017 12:29 AM, Tetsuo Handa wrote:
> Wei Wang wrote:
>> I used the example of xb_clear_bit_range(), and xb_find_next_bit() is
>> the same fundamentally. Please let me know if anywhere still looks fuzzy.
> I don't think it is the same for xb_find_next_bit() with set == 0.
>
> + if (radix_tree_exception(bmap)) {
> + unsigned long tmp = (unsigned long)bmap;
> + unsigned long ebit = bit + 2;
> +
> + if (ebit >= BITS_PER_LONG)
> + continue;
> + if (set)
> + ret = find_next_bit(&tmp, BITS_PER_LONG, ebit);
> + else
> + ret = find_next_zero_bit(&tmp, BITS_PER_LONG,
> + ebit);
> + if (ret < BITS_PER_LONG)
> + return ret - 2 + IDA_BITMAP_BITS * index;
>
> What I'm saying is that find_next_zero_bit() will not be called if you do
> "if (ebit >= BITS_PER_LONG) continue;" before calling find_next_zero_bit().
>
> When scanning "0000000000000000000000000000000000000000000000000000000000000001",
> "bit < BITS_PER_LONG - 2" case finds "0" in this word but
> "bit >= BITS_PER_LONG - 2" case finds "0" in next word or segment.
>
> I can't understand why this is correct behavior. It is too much puzzling.
>
OK, I'll post out a version without the exceptional path.
Best,
Wei
^ permalink raw reply
* Re: [PATCH v2 1/3] virtio_pci: use put_device instead of kfree
From: Michael S. Tsirkin @ 2017-12-16 22:13 UTC (permalink / raw)
To: Cornelia Huck; +Cc: Greg Kroah-Hartman, weiping zhang, virtualization
In-Reply-To: <20171215132127.71c33352.cohuck@redhat.com>
On Fri, Dec 15, 2017 at 01:21:27PM +0100, Cornelia Huck wrote:
> On Thu, 14 Dec 2017 21:13:28 +0200
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
>
> > On Tue, Dec 12, 2017 at 09:24:02PM +0800, weiping zhang wrote:
> > > As mentioned at drivers/base/core.c:
> > > /*
> > > * NOTE: _Never_ directly free @dev after calling this function, even
> > > * if it returned an error! Always use put_device() to give up the
> > > * reference initialized in this function instead.
> > > */
> > > so we don't free vp_dev until vp_dev->vdev.dev.release be called.
> >
> > seeing as 5739411acbaa63a6c22c91e340fdcdbcc7d82a51 adding these
> > annotations went to stable, should this go there too?
> >
> > > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> > > Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> >
> > OK but this relies on users knowing that register_virtio_device
> > calls device_register. I think we want to add a comment
> > to register_virtio_device.
> >
> > Also the cleanup is uglified.
> >
> > I really think the right thing would be to change device_register making
> > it safe to kfree. People have the right to expect register on failure to
> > have no effect.
> >
> > That just might be too hard to implement though.
>
> Yes. The main problem is that device_register() at some point makes the
> structure visible to others, at which point they may obtain a
> reference. If that happened, you cannot clean up unless that other
> party gave up their reference -- which means your only chance to get
> this right is the current put_device() approach.
>
> It *is* problematic if all of that stuff is hidden behind too many
> calling layers. If you have the device_initialize() -> device_add()
> calling sequence, having to do a put_device() on failure is much more
> obvious. But as you usually don't pass in a pure struct device but
> something embedding it, the put_device() needs to be done on the
> outermost level.
>
> Commenting can help here, as would probably a static checker for that
> code pattern.
A semantic patch is probably the best we can do here.
--
MST
^ permalink raw reply
* Re: [PATCH v19 3/7] xbitmap: add more operations
From: Wei Wang @ 2017-12-17 5:24 UTC (permalink / raw)
To: Tetsuo Handa, willy
Cc: aarcange, virtio-dev, riel, nilal, kvm, mst, qemu-devel,
amit.shah, liliang.opensource, mawilcox, linux-kernel,
virtualization, linux-mm, yang.zhang.wz, quan.xu, cornelia.huck,
pbonzini, akpm, mhocko, mgorman
In-Reply-To: <201712162028.FEB87079.FOJFMQHVOSLtFO@I-love.SAKURA.ne.jp>
On 12/16/2017 07:28 PM, Tetsuo Handa wrote:
> Wei Wang wrote:
>> On 12/16/2017 02:42 AM, Matthew Wilcox wrote:
>>> On Tue, Dec 12, 2017 at 07:55:55PM +0800, Wei Wang wrote:
>>>> +int xb_preload_and_set_bit(struct xb *xb, unsigned long bit, gfp_t gfp);
>>> I'm struggling to understand when one would use this. The xb_ API
>>> requires you to handle your own locking. But specifying GFP flags
>>> here implies you can sleep. So ... um ... there's no locking?
>> In the regular use cases, people would do xb_preload() before taking the
>> lock, and the xb_set/clear within the lock.
>>
>> In the virtio-balloon usage, we have a large number of bits to set with
>> the balloon_lock being held (we're not unlocking for each bit), so we
>> used the above wrapper to do preload and set within the balloon_lock,
>> and passed in GFP_NOWAIT to avoid sleeping. Probably we can change to
>> put this wrapper implementation to virtio-balloon, since it would not be
>> useful for the regular cases.
> GFP_NOWAIT is chosen in order not to try to OOM-kill something, isn't it?
Yes, I think that's right the issue we are discussing here (also
discussed in the deadlock patch before): Suppose we use a sleep-able
flag GFP_KERNEL, which gets the caller (fill_balloon or leak_balloon)
into sleep with balloon_lock being held, and the memory reclaiming from
GFP_KERNEL would fall into the OOM code path which first invokes the
oom_notify-->leak_balloon to release some balloon memory, which needs to
take the balloon_lock that is being held by the task who is sleeping.
So, using GFP_NOWAIT avoids sleeping to get memory through directly
memory reclaiming, which could fall into that OOM code path that needs
to take the balloon_lock.
> But passing GFP_NOWAIT means that we can handle allocation failure. There is
> no need to use preload approach when we can handle allocation failure.
I think the reason we need xb_preload is because radix tree insertion
needs the memory being preallocated already (it couldn't suffer from
memory failure during the process of inserting, probably because
handling the failure there isn't easy, Matthew may know the backstory of
this)
So, I think we can handle the memory failure with xb_preload, which
stops going into the radix tree APIs, but shouldn't call radix tree APIs
without the related memory preallocated.
Best,
Wei
^ permalink raw reply
* RE: [PATCH v19 3/7] xbitmap: add more operations
From: Wang, Wei W @ 2017-12-17 11:50 UTC (permalink / raw)
To: Tetsuo Handa, willy@infradead.org
Cc: aarcange@redhat.com, virtio-dev@lists.oasis-open.org,
riel@redhat.com, nilal@redhat.com, kvm@vger.kernel.org,
mst@redhat.com, qemu-devel@nongnu.org, amit.shah@redhat.com,
liliang.opensource@gmail.com, mawilcox@microsoft.com,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, linux-mm@kvack.org,
yang.zhang.wz@gmail.com, quan.xu@aliyun.com,
cornelia.huck@de.ibm.com, pbonzini@redhat.com, akpm
In-Reply-To: <201712171921.IBB30790.VOOOFMQHFSLFJt@I-love.SAKURA.ne.jp>
> -----Original Message-----
> From: Tetsuo Handa [mailto:penguin-kernel@I-love.SAKURA.ne.jp]
> Sent: Sunday, December 17, 2017 6:22 PM
> To: Wang, Wei W <wei.w.wang@intel.com>; willy@infradead.org
> Cc: virtio-dev@lists.oasis-open.org; linux-kernel@vger.kernel.org; qemu-
> devel@nongnu.org; virtualization@lists.linux-foundation.org;
> kvm@vger.kernel.org; linux-mm@kvack.org; mst@redhat.com;
> mhocko@kernel.org; akpm@linux-foundation.org; mawilcox@microsoft.com;
> david@redhat.com; cornelia.huck@de.ibm.com;
> mgorman@techsingularity.net; aarcange@redhat.com;
> amit.shah@redhat.com; pbonzini@redhat.com;
> liliang.opensource@gmail.com; yang.zhang.wz@gmail.com;
> quan.xu@aliyun.com; nilal@redhat.com; riel@redhat.com
> Subject: Re: [PATCH v19 3/7] xbitmap: add more operations
>
> Wei Wang wrote:
> > > But passing GFP_NOWAIT means that we can handle allocation failure.
> > > There is no need to use preload approach when we can handle allocation
> failure.
> >
> > I think the reason we need xb_preload is because radix tree insertion
> > needs the memory being preallocated already (it couldn't suffer from
> > memory failure during the process of inserting, probably because
> > handling the failure there isn't easy, Matthew may know the backstory
> > of
> > this)
>
> According to https://lwn.net/Articles/175432/ , I think that preloading is
> needed only when failure to insert an item into a radix tree is a significant
> problem.
> That is, when failure to insert an item into a radix tree is not a problem, I
> think that we don't need to use preloading.
It also mentions that the preload attempts to allocate sufficient memory to *guarantee* that the next radix tree insertion cannot fail.
If we check radix_tree_node_alloc(), the comments there says "this assumes that the caller has performed appropriate preallocation".
So, I think we would get a risk of triggering some issue without preload().
> >
> > So, I think we can handle the memory failure with xb_preload, which
> > stops going into the radix tree APIs, but shouldn't call radix tree
> > APIs without the related memory preallocated.
>
> It seems to me that virtio-ballon case has no problem without using
> preloading.
Why is that?
Best,
Wei
^ permalink raw reply
* [PATCH v3 0/5] proper cleanup if fail to register_virtio_device
From: weiping zhang @ 2017-12-17 13:45 UTC (permalink / raw)
To: cohuck, mst, jasowang; +Cc: virtualization
Hi,
Patch1 add a helper to get virtio_device's status which will be used
later.
Patch2~4: check virtio_device's status is RTIO_CONFIG_S_ACKNOWLEDGE
or not, if so use put_device otherwise use kfree.
Patch5: add comments for virtio_register_device help caller do a
proper cleanup if got failure.
weiping zhang (5):
virtio: add helper virtio_get_status
virtio_pci: don't kfree device on register failure
virtio_vop: don't kfree device on register failure
virtio_remoteproc: don't kfree device on register failure
virtio: add comments for virtio_register_device
drivers/misc/mic/vop/vop_main.c | 17 +++++++++++------
drivers/remoteproc/remoteproc_virtio.c | 10 +++++++++-
drivers/virtio/virtio.c | 19 +++++++++++++++++++
drivers/virtio/virtio_pci_common.c | 5 ++++-
include/linux/virtio_config.h | 2 ++
5 files changed, 45 insertions(+), 8 deletions(-)
--
2.9.4
^ permalink raw reply
* [PATCH v3 1/5] virtio: add helper virtio_get_status
From: weiping zhang @ 2017-12-17 13:45 UTC (permalink / raw)
To: cohuck, mst, jasowang; +Cc: virtualization
In-Reply-To: <cover.1513517240.git.zhangweiping@didichuxing.com>
add helper function to simplify dev->config->get_status().
Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
drivers/virtio/virtio.c | 6 ++++++
include/linux/virtio_config.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index bf7ff39..c5b057bd 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -165,6 +165,12 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status)
}
EXPORT_SYMBOL_GPL(virtio_add_status);
+unsigned int virtio_get_status(struct virtio_device *dev)
+{
+ return dev->config->get_status(dev);
+}
+EXPORT_SYMBOL_GPL(virtio_get_status);
+
int virtio_finalize_features(struct virtio_device *dev)
{
int ret = dev->config->finalize_features(dev);
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 5559a2d..30972c4 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -429,6 +429,8 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
vdev->config->set(vdev, offset, &val, sizeof(val));
}
+unsigned int virtio_get_status(struct virtio_device *dev);
+
/* Conditional config space accessors. */
#define virtio_cread_feature(vdev, fbit, structname, member, ptr) \
({ \
--
2.9.4
^ permalink raw reply related
* [PATCH v3 2/5] virtio_pci: don't kfree device on register failure
From: weiping zhang @ 2017-12-17 13:46 UTC (permalink / raw)
To: cohuck, mst, jasowang; +Cc: virtualization
In-Reply-To: <cover.1513517240.git.zhangweiping@didichuxing.com>
As mentioned at drivers/base/core.c:
/*
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always use put_device() to give up the
* reference initialized in this function instead.
*/
so we don't free vp_dev until vp_dev->vdev.dev.release be called.
Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
drivers/virtio/virtio_pci_common.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 1c4797e..21a2ce0 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -564,7 +564,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
err_probe:
pci_disable_device(pci_dev);
err_enable_device:
- kfree(vp_dev);
+ if (VIRTIO_CONFIG_S_ACKNOWLEDGE & virtio_get_status(&vp_dev->vdev))
+ put_device(&vp_dev->vdev.dev);
+ else
+ kfree(vp_dev);
return rc;
}
--
2.9.4
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox