* [PATCH v2 0/2] mfd: viperboard: cleanups and fix for cache line sharing
@ 2014-09-22 19:39 Octavian Purdila
2014-09-22 19:39 ` [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
2014-09-22 19:39 ` [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check Octavian Purdila
0 siblings, 2 replies; 13+ messages in thread
From: Octavian Purdila @ 2014-09-22 19:39 UTC (permalink / raw)
To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila
Changes since v1:
* split cache sharing fix and cleanups into separate patches
Octavian Purdila (2):
mfd: viperboard: allocate I/O buffer separately
mfd: viperboard: remove redundant OOM message and NULL pointer check
drivers/mfd/viperboard.c | 16 ++++++++++------
include/linux/mfd/viperboard.h | 2 +-
2 files changed, 11 insertions(+), 7 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-22 19:39 [PATCH v2 0/2] mfd: viperboard: cleanups and fix for cache line sharing Octavian Purdila
@ 2014-09-22 19:39 ` Octavian Purdila
2014-09-23 7:35 ` Johan Hovold
` (2 more replies)
2014-09-22 19:39 ` [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check Octavian Purdila
1 sibling, 3 replies; 13+ messages in thread
From: Octavian Purdila @ 2014-09-22 19:39 UTC (permalink / raw)
To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila
Currently the I/O buffer is allocated part of the device status
structure, potentially sharing the same cache line with other members
in this structure.
Allocate the buffer separately, to avoid the I/O operations corrupting
the device status structure due to cache line sharing.
Compiled tested only as I don't have access to hardware.
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
drivers/mfd/viperboard.c | 8 ++++++++
include/linux/mfd/viperboard.h | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index e00f534..5f62f4e 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
return -ENOMEM;
}
+ vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
+ if (vb->buf == NULL) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
mutex_init(&vb->lock);
vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));
@@ -105,6 +111,7 @@ static int vprbrd_probe(struct usb_interface *interface,
error:
if (vb) {
usb_put_dev(vb->usb_dev);
+ kfree(vb->buf);
kfree(vb);
}
@@ -118,6 +125,7 @@ static void vprbrd_disconnect(struct usb_interface *interface)
mfd_remove_devices(&interface->dev);
usb_set_intfdata(interface, NULL);
usb_put_dev(vb->usb_dev);
+ kfree(vb->buf);
kfree(vb);
dev_dbg(&interface->dev, "disconnected\n");
diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
index 1934528..af928d0 100644
--- a/include/linux/mfd/viperboard.h
+++ b/include/linux/mfd/viperboard.h
@@ -103,7 +103,7 @@ struct vprbrd_i2c_addr_msg {
struct vprbrd {
struct usb_device *usb_dev; /* the usb device for this device */
struct mutex lock;
- u8 buf[sizeof(struct vprbrd_i2c_write_msg)];
+ u8 *buf;
struct platform_device pdev;
};
--
1.9.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check
2014-09-22 19:39 [PATCH v2 0/2] mfd: viperboard: cleanups and fix for cache line sharing Octavian Purdila
2014-09-22 19:39 ` [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
@ 2014-09-22 19:39 ` Octavian Purdila
2014-09-24 10:13 ` Lee Jones
1 sibling, 1 reply; 13+ messages in thread
From: Octavian Purdila @ 2014-09-22 19:39 UTC (permalink / raw)
To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
drivers/mfd/viperboard.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index 5f62f4e..d27c131 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -59,10 +59,8 @@ static int vprbrd_probe(struct usb_interface *interface,
/* allocate memory for our device state and initialize it */
vb = kzalloc(sizeof(*vb), GFP_KERNEL);
- if (vb == NULL) {
- dev_err(&interface->dev, "Out of memory\n");
+ if (vb == NULL)
return -ENOMEM;
- }
vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
if (vb->buf == NULL) {
@@ -109,11 +107,9 @@ static int vprbrd_probe(struct usb_interface *interface,
return 0;
error:
- if (vb) {
- usb_put_dev(vb->usb_dev);
- kfree(vb->buf);
- kfree(vb);
- }
+ usb_put_dev(vb->usb_dev);
+ kfree(vb->buf);
+ kfree(vb);
return ret;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-22 19:39 ` [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
@ 2014-09-23 7:35 ` Johan Hovold
2014-09-23 7:38 ` Johan Hovold
2014-09-23 7:47 ` Johan Hovold
2014-09-24 10:12 ` Lee Jones
2 siblings, 1 reply; 13+ messages in thread
From: Johan Hovold @ 2014-09-23 7:35 UTC (permalink / raw)
To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan
On Mon, Sep 22, 2014 at 10:39:18PM +0300, Octavian Purdila wrote:
> Currently the I/O buffer is allocated part of the device status
> structure, potentially sharing the same cache line with other members
> in this structure.
>
> Allocate the buffer separately, to avoid the I/O operations corrupting
> the device status structure due to cache line sharing.
>
> Compiled tested only as I don't have access to hardware.
>
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> ---
> drivers/mfd/viperboard.c | 8 ++++++++
> include/linux/mfd/viperboard.h | 2 +-
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index e00f534..5f62f4e 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> return -ENOMEM;
> }
>
> + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> + if (vb->buf == NULL) {
> + ret = -ENOMEM;
> + goto error;
This will cause a kref imbalance as you have a usb_put_dev in error,
but haven't done the get yet.
> + }
> +
> mutex_init(&vb->lock);
>
> vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));
Here's the get.
Johan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-23 7:35 ` Johan Hovold
@ 2014-09-23 7:38 ` Johan Hovold
0 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2014-09-23 7:38 UTC (permalink / raw)
To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan
On Tue, Sep 23, 2014 at 09:35:41AM +0200, Johan Hovold wrote:
> On Mon, Sep 22, 2014 at 10:39:18PM +0300, Octavian Purdila wrote:
> > Currently the I/O buffer is allocated part of the device status
> > structure, potentially sharing the same cache line with other members
> > in this structure.
> >
> > Allocate the buffer separately, to avoid the I/O operations corrupting
> > the device status structure due to cache line sharing.
> >
> > Compiled tested only as I don't have access to hardware.
> >
> > Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> > ---
> > drivers/mfd/viperboard.c | 8 ++++++++
> > include/linux/mfd/viperboard.h | 2 +-
> > 2 files changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> > index e00f534..5f62f4e 100644
> > --- a/drivers/mfd/viperboard.c
> > +++ b/drivers/mfd/viperboard.c
> > @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> > return -ENOMEM;
> > }
> >
> > + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> > + if (vb->buf == NULL) {
> > + ret = -ENOMEM;
> > + goto error;
>
> This will cause a kref imbalance as you have a usb_put_dev in error,
> but haven't done the get yet.
Nevermind. This isn't problem as the usb device is null.
Haven't had my morning coffee yet. ;)
Johan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-22 19:39 ` [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
2014-09-23 7:35 ` Johan Hovold
@ 2014-09-23 7:47 ` Johan Hovold
2014-09-24 10:12 ` Lee Jones
2 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2014-09-23 7:47 UTC (permalink / raw)
To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan
On Mon, Sep 22, 2014 at 10:39:18PM +0300, Octavian Purdila wrote:
> Currently the I/O buffer is allocated part of the device status
> structure, potentially sharing the same cache line with other members
> in this structure.
>
> Allocate the buffer separately, to avoid the I/O operations corrupting
> the device status structure due to cache line sharing.
>
> Compiled tested only as I don't have access to hardware.
>
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
Reviewed-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/mfd/viperboard.c | 8 ++++++++
> include/linux/mfd/viperboard.h | 2 +-
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index e00f534..5f62f4e 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> return -ENOMEM;
> }
>
> + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> + if (vb->buf == NULL) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> mutex_init(&vb->lock);
>
> vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));
> @@ -105,6 +111,7 @@ static int vprbrd_probe(struct usb_interface *interface,
> error:
> if (vb) {
> usb_put_dev(vb->usb_dev);
> + kfree(vb->buf);
> kfree(vb);
> }
>
> @@ -118,6 +125,7 @@ static void vprbrd_disconnect(struct usb_interface *interface)
> mfd_remove_devices(&interface->dev);
> usb_set_intfdata(interface, NULL);
> usb_put_dev(vb->usb_dev);
> + kfree(vb->buf);
> kfree(vb);
>
> dev_dbg(&interface->dev, "disconnected\n");
> diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
> index 1934528..af928d0 100644
> --- a/include/linux/mfd/viperboard.h
> +++ b/include/linux/mfd/viperboard.h
> @@ -103,7 +103,7 @@ struct vprbrd_i2c_addr_msg {
> struct vprbrd {
> struct usb_device *usb_dev; /* the usb device for this device */
> struct mutex lock;
> - u8 buf[sizeof(struct vprbrd_i2c_write_msg)];
> + u8 *buf;
> struct platform_device pdev;
> };
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-22 19:39 ` [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
2014-09-23 7:35 ` Johan Hovold
2014-09-23 7:47 ` Johan Hovold
@ 2014-09-24 10:12 ` Lee Jones
2014-09-24 10:28 ` Johan Hovold
2 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2014-09-24 10:12 UTC (permalink / raw)
To: Octavian Purdila; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila
On Mon, 22 Sep 2014, Octavian Purdila wrote:
> Currently the I/O buffer is allocated part of the device status
> structure, potentially sharing the same cache line with other members
> in this structure.
>
> Allocate the buffer separately, to avoid the I/O operations corrupting
> the device status structure due to cache line sharing.
>
> Compiled tested only as I don't have access to hardware.
>
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> ---
> drivers/mfd/viperboard.c | 8 ++++++++
> include/linux/mfd/viperboard.h | 2 +-
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index e00f534..5f62f4e 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> return -ENOMEM;
> }
>
> + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
Can you obtain the 'struct device' first then use managed resources
(devm_*)?
> + if (vb->buf == NULL) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> mutex_init(&vb->lock);
>
> vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));
> @@ -105,6 +111,7 @@ static int vprbrd_probe(struct usb_interface *interface,
> error:
> if (vb) {
> usb_put_dev(vb->usb_dev);
> + kfree(vb->buf);
Then you don't need this.
> kfree(vb);
> }
>
> @@ -118,6 +125,7 @@ static void vprbrd_disconnect(struct usb_interface *interface)
> mfd_remove_devices(&interface->dev);
> usb_set_intfdata(interface, NULL);
> usb_put_dev(vb->usb_dev);
> + kfree(vb->buf);
Or this.
> kfree(vb);
>
> dev_dbg(&interface->dev, "disconnected\n");
> diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
> index 1934528..af928d0 100644
> --- a/include/linux/mfd/viperboard.h
> +++ b/include/linux/mfd/viperboard.h
> @@ -103,7 +103,7 @@ struct vprbrd_i2c_addr_msg {
> struct vprbrd {
> struct usb_device *usb_dev; /* the usb device for this device */
> struct mutex lock;
> - u8 buf[sizeof(struct vprbrd_i2c_write_msg)];
> + u8 *buf;
> struct platform_device pdev;
> };
>
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check
2014-09-22 19:39 ` [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check Octavian Purdila
@ 2014-09-24 10:13 ` Lee Jones
0 siblings, 0 replies; 13+ messages in thread
From: Lee Jones @ 2014-09-24 10:13 UTC (permalink / raw)
To: Octavian Purdila; +Cc: sameo, linux-kernel, linux-usb, johan
On Mon, 22 Sep 2014, Octavian Purdila wrote:
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> ---
> drivers/mfd/viperboard.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
Looks fine, but won't apply without patch 1.
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index 5f62f4e..d27c131 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -59,10 +59,8 @@ static int vprbrd_probe(struct usb_interface *interface,
>
> /* allocate memory for our device state and initialize it */
> vb = kzalloc(sizeof(*vb), GFP_KERNEL);
> - if (vb == NULL) {
> - dev_err(&interface->dev, "Out of memory\n");
> + if (vb == NULL)
> return -ENOMEM;
> - }
>
> vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> if (vb->buf == NULL) {
> @@ -109,11 +107,9 @@ static int vprbrd_probe(struct usb_interface *interface,
> return 0;
>
> error:
> - if (vb) {
> - usb_put_dev(vb->usb_dev);
> - kfree(vb->buf);
> - kfree(vb);
> - }
> + usb_put_dev(vb->usb_dev);
> + kfree(vb->buf);
> + kfree(vb);
>
> return ret;
> }
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-24 10:12 ` Lee Jones
@ 2014-09-24 10:28 ` Johan Hovold
2014-09-24 12:00 ` Lee Jones
0 siblings, 1 reply; 13+ messages in thread
From: Johan Hovold @ 2014-09-24 10:28 UTC (permalink / raw)
To: Lee Jones; +Cc: Octavian Purdila, linux-kernel, linux-usb, johan
On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
> On Mon, 22 Sep 2014, Octavian Purdila wrote:
>
> > Currently the I/O buffer is allocated part of the device status
> > structure, potentially sharing the same cache line with other members
> > in this structure.
> >
> > Allocate the buffer separately, to avoid the I/O operations corrupting
> > the device status structure due to cache line sharing.
> >
> > Compiled tested only as I don't have access to hardware.
> >
> > Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> > ---
> > drivers/mfd/viperboard.c | 8 ++++++++
> > include/linux/mfd/viperboard.h | 2 +-
> > 2 files changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> > index e00f534..5f62f4e 100644
> > --- a/drivers/mfd/viperboard.c
> > +++ b/drivers/mfd/viperboard.c
> > @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> > return -ENOMEM;
> > }
> >
> > + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
>
> Can you obtain the 'struct device' first then use managed resources
> (devm_*)?
I think any devres conversion should be done in a follow-up patch and
not be included in the fix (e.g. in order to facilitate backporting). We
also don't want to mix allocation schemes.
Johan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-24 10:28 ` Johan Hovold
@ 2014-09-24 12:00 ` Lee Jones
2014-09-24 12:26 ` Johan Hovold
0 siblings, 1 reply; 13+ messages in thread
From: Lee Jones @ 2014-09-24 12:00 UTC (permalink / raw)
To: Johan Hovold; +Cc: Octavian Purdila, linux-kernel, linux-usb
On Wed, 24 Sep 2014, Johan Hovold wrote:
> On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
> > On Mon, 22 Sep 2014, Octavian Purdila wrote:
> >
> > > Currently the I/O buffer is allocated part of the device status
> > > structure, potentially sharing the same cache line with other members
> > > in this structure.
> > >
> > > Allocate the buffer separately, to avoid the I/O operations corrupting
> > > the device status structure due to cache line sharing.
> > >
> > > Compiled tested only as I don't have access to hardware.
> > >
> > > Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> > > ---
> > > drivers/mfd/viperboard.c | 8 ++++++++
> > > include/linux/mfd/viperboard.h | 2 +-
> > > 2 files changed, 9 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> > > index e00f534..5f62f4e 100644
> > > --- a/drivers/mfd/viperboard.c
> > > +++ b/drivers/mfd/viperboard.c
> > > @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> > > return -ENOMEM;
> > > }
> > >
> > > + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> >
> > Can you obtain the 'struct device' first then use managed resources
> > (devm_*)?
>
> I think any devres conversion should be done in a follow-up patch and
> not be included in the fix (e.g. in order to facilitate backporting). We
> also don't want to mix allocation schemes.
I agree, but equally I'm not keen on accepting this patch as I believe
it could be done better.
Please submit two patches, one converting to shared resources and this
being the subsequent one, fixed up to do the right thing.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-24 12:00 ` Lee Jones
@ 2014-09-24 12:26 ` Johan Hovold
2014-09-24 12:34 ` Octavian Purdila
0 siblings, 1 reply; 13+ messages in thread
From: Johan Hovold @ 2014-09-24 12:26 UTC (permalink / raw)
To: Lee Jones; +Cc: Johan Hovold, Octavian Purdila, linux-kernel, linux-usb
On Wed, Sep 24, 2014 at 01:00:02PM +0100, Lee Jones wrote:
> On Wed, 24 Sep 2014, Johan Hovold wrote:
>
> > On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
> > > On Mon, 22 Sep 2014, Octavian Purdila wrote:
> > >
> > > > Currently the I/O buffer is allocated part of the device status
> > > > structure, potentially sharing the same cache line with other members
> > > > in this structure.
> > > >
> > > > Allocate the buffer separately, to avoid the I/O operations corrupting
> > > > the device status structure due to cache line sharing.
> > > >
> > > > Compiled tested only as I don't have access to hardware.
> > > >
> > > > Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
> > > > ---
> > > > drivers/mfd/viperboard.c | 8 ++++++++
> > > > include/linux/mfd/viperboard.h | 2 +-
> > > > 2 files changed, 9 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> > > > index e00f534..5f62f4e 100644
> > > > --- a/drivers/mfd/viperboard.c
> > > > +++ b/drivers/mfd/viperboard.c
> > > > @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
> > > > return -ENOMEM;
> > > > }
> > > >
> > > > + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> > >
> > > Can you obtain the 'struct device' first then use managed resources
> > > (devm_*)?
> >
> > I think any devres conversion should be done in a follow-up patch and
> > not be included in the fix (e.g. in order to facilitate backporting). We
> > also don't want to mix allocation schemes.
>
> I agree, but equally I'm not keen on accepting this patch as I believe
> it could be done better.
>
> Please submit two patches, one converting to shared resources and this
> being the subsequent one, fixed up to do the right thing.
A buffer-corruption fix is a candidate for stable, whereas a devres
conversion (clean up) is not. Hence the former should not depend on the
latter.
Johan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-24 12:26 ` Johan Hovold
@ 2014-09-24 12:34 ` Octavian Purdila
2014-09-24 12:34 ` Johan Hovold
0 siblings, 1 reply; 13+ messages in thread
From: Octavian Purdila @ 2014-09-24 12:34 UTC (permalink / raw)
To: Johan Hovold; +Cc: Lee Jones, lkml, linux-usb
On Wed, Sep 24, 2014 at 3:26 PM, Johan Hovold <johan@kernel.org> wrote:
> On Wed, Sep 24, 2014 at 01:00:02PM +0100, Lee Jones wrote:
>> On Wed, 24 Sep 2014, Johan Hovold wrote:
>>
>> > On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
>> > > On Mon, 22 Sep 2014, Octavian Purdila wrote:
>> > >
>> > > > Currently the I/O buffer is allocated part of the device status
>> > > > structure, potentially sharing the same cache line with other members
>> > > > in this structure.
>> > > >
>> > > > Allocate the buffer separately, to avoid the I/O operations corrupting
>> > > > the device status structure due to cache line sharing.
>> > > >
>> > > > Compiled tested only as I don't have access to hardware.
>> > > >
>> > > > Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
>> > > > ---
>> > > > drivers/mfd/viperboard.c | 8 ++++++++
>> > > > include/linux/mfd/viperboard.h | 2 +-
>> > > > 2 files changed, 9 insertions(+), 1 deletion(-)
>> > > >
>> > > > diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
>> > > > index e00f534..5f62f4e 100644
>> > > > --- a/drivers/mfd/viperboard.c
>> > > > +++ b/drivers/mfd/viperboard.c
>> > > > @@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
>> > > > return -ENOMEM;
>> > > > }
>> > > >
>> > > > + vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
>> > >
>> > > Can you obtain the 'struct device' first then use managed resources
>> > > (devm_*)?
>> >
>> > I think any devres conversion should be done in a follow-up patch and
>> > not be included in the fix (e.g. in order to facilitate backporting). We
>> > also don't want to mix allocation schemes.
>>
>> I agree, but equally I'm not keen on accepting this patch as I believe
>> it could be done better.
>>
>> Please submit two patches, one converting to shared resources and this
>> being the subsequent one, fixed up to do the right thing.
>
> A buffer-corruption fix is a candidate for stable, whereas a devres
> conversion (clean up) is not. Hence the former should not depend on the
> latter.
>
I can follow-up with a v3 3 patch series: first for the fix, second
for the OOM & error path cleanup, third for devm conversion.
I think this will address both issues (backport and better final result).
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
2014-09-24 12:34 ` Octavian Purdila
@ 2014-09-24 12:34 ` Johan Hovold
0 siblings, 0 replies; 13+ messages in thread
From: Johan Hovold @ 2014-09-24 12:34 UTC (permalink / raw)
To: Octavian Purdila; +Cc: Johan Hovold, Lee Jones, lkml, linux-usb
On Wed, Sep 24, 2014 at 03:34:08PM +0300, Octavian Purdila wrote:
> I can follow-up with a v3 3 patch series: first for the fix, second
> for the OOM & error path cleanup, third for devm conversion.
I'd include the error-path clean up bit in the devres conversion as that
is what it's really all about.
Johan
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-09-24 12:37 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-22 19:39 [PATCH v2 0/2] mfd: viperboard: cleanups and fix for cache line sharing Octavian Purdila
2014-09-22 19:39 ` [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
2014-09-23 7:35 ` Johan Hovold
2014-09-23 7:38 ` Johan Hovold
2014-09-23 7:47 ` Johan Hovold
2014-09-24 10:12 ` Lee Jones
2014-09-24 10:28 ` Johan Hovold
2014-09-24 12:00 ` Lee Jones
2014-09-24 12:26 ` Johan Hovold
2014-09-24 12:34 ` Octavian Purdila
2014-09-24 12:34 ` Johan Hovold
2014-09-22 19:39 ` [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check Octavian Purdila
2014-09-24 10:13 ` Lee Jones
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).