* [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
@ 2020-08-26 13:22 Alexandru Ardelean
2020-08-27 6:56 ` Krzysztof Kozlowski
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Alexandru Ardelean @ 2020-08-26 13:22 UTC (permalink / raw)
To: linux-iio, linux-kernel
Cc: jic23, kgene, krzk, Sergiu Cuciurean, Alexandru Ardelean
From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock, to protect potential concurrent access to the
completion callback during a conversion.
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/iio/adc/exynos_adc.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 7d23b6c33284..6a49f8dfab22 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -132,6 +132,8 @@ struct exynos_adc {
struct completion completion;
+ struct mutex lock;
+
u32 value;
unsigned int version;
@@ -542,7 +544,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
return -EINVAL;
}
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&info->lock);
reinit_completion(&info->completion);
/* Select the channel to be used and Trigger conversion */
@@ -562,7 +564,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
ret = IIO_VAL_INT;
}
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&info->lock);
return ret;
}
@@ -573,7 +575,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
unsigned long timeout;
int ret;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&info->lock);
info->read_ts = true;
reinit_completion(&info->completion);
@@ -598,7 +600,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
}
info->read_ts = false;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&info->lock);
return ret;
}
@@ -872,6 +874,8 @@ static int exynos_adc_probe(struct platform_device *pdev)
indio_dev->channels = exynos_adc_iio_channels;
indio_dev->num_channels = info->data->num_channels;
+ mutex_init(&info->lock);
+
ret = request_irq(info->irq, exynos_adc_isr,
0, dev_name(&pdev->dev), info);
if (ret < 0) {
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
2020-08-26 13:22 [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock Alexandru Ardelean
@ 2020-08-27 6:56 ` Krzysztof Kozlowski
2020-08-27 8:53 ` Alexandru Ardelean
2020-08-29 15:35 ` Jonathan Cameron
2020-09-16 9:31 ` [PATCH v2] " Alexandru Ardelean
2 siblings, 1 reply; 7+ messages in thread
From: Krzysztof Kozlowski @ 2020-08-27 6:56 UTC (permalink / raw)
To: Alexandru Ardelean
Cc: linux-iio, linux-kernel, jic23, kgene, Sergiu Cuciurean
On Wed, Aug 26, 2020 at 04:22:03PM +0300, Alexandru Ardelean wrote:
> From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
>
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock, to protect potential concurrent access to the
> completion callback during a conversion.
I don't know the bigger picture (and no links here for general cleanup)
but I assume it is part of wider work and that mlock is unwanted. In
such case:
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
If it is part of some bigger work, please put a link to lore.kernel.org
under separators ---, so everyone can get the context.
Best regards,
Krzysztof
>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
> drivers/iio/adc/exynos_adc.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
2020-08-27 6:56 ` Krzysztof Kozlowski
@ 2020-08-27 8:53 ` Alexandru Ardelean
2020-08-29 15:33 ` Jonathan Cameron
0 siblings, 1 reply; 7+ messages in thread
From: Alexandru Ardelean @ 2020-08-27 8:53 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Alexandru Ardelean, linux-iio, LKML, Jonathan Cameron, kgene,
Sergiu Cuciurean
On Thu, Aug 27, 2020 at 9:57 AM Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On Wed, Aug 26, 2020 at 04:22:03PM +0300, Alexandru Ardelean wrote:
> > From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> >
> > As part of the general cleanup of indio_dev->mlock, this change replaces
> > it with a local lock, to protect potential concurrent access to the
> > completion callback during a conversion.
>
> I don't know the bigger picture (and no links here for general cleanup)
> but I assume it is part of wider work and that mlock is unwanted. In
> such case:
>
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
>
> If it is part of some bigger work, please put a link to lore.kernel.org
> under separators ---, so everyone can get the context.
Will keep that in mind.
I am not sure if there is a lore.kernel.org link that's easy to find
for a discussion on this topic, maybe I can describe it here and use
the link [from this later].
This was something that popped up during reviews we got from Jonathan
[or others], saying "please don't use indio_dev->mlock, that is an IIO
framework lock, and an IIO driver should not use it".
Reasons include [and some may be repeated a bit]:
- this could cause a deadlock if the IIO framework holds this lock and
an IIO driver also tries to get a hold of this lock
- similar to the previous point, this mlock is taken by
iio_device_claim_direct_mode() and released by
iio_device_release_direct_mode() ; which means that mlock aims to
become more of an IIO framework lock, than a general usage lock;
- this wasn't policed/reviewed intensely in the older driver [a few
years ago], but has become a point in recent reviews;
- if we want to develop/enhance the IIO framework, some elements like
this need to be taken care of, as more drivers get added and more
complexity gets added;
- there is an element of fairness [obviously], where someone writing a
new IIO driver, takes an older one as example, and gets hit on the
review; the person feels they did a good job in mimicking the old
driver; their feeling is correct; the IIO framework should provide
good references and/or cleanup existing drivers;
- same as the previous point, we don't want to keep telling people
writing new IIO drivers [and starting out with IIO] to "not use mlock
[because it was copied from an old driver]"; it's more/needless review
work
>
>
> Best regards,
> Krzysztof
>
> >
> > Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > ---
> > drivers/iio/adc/exynos_adc.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
2020-08-27 8:53 ` Alexandru Ardelean
@ 2020-08-29 15:33 ` Jonathan Cameron
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2020-08-29 15:33 UTC (permalink / raw)
To: Alexandru Ardelean
Cc: Krzysztof Kozlowski, Alexandru Ardelean, linux-iio, LKML, kgene,
Sergiu Cuciurean
On Thu, 27 Aug 2020 11:53:44 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
> On Thu, Aug 27, 2020 at 9:57 AM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >
> > On Wed, Aug 26, 2020 at 04:22:03PM +0300, Alexandru Ardelean wrote:
> > > From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> > >
> > > As part of the general cleanup of indio_dev->mlock, this change replaces
> > > it with a local lock, to protect potential concurrent access to the
> > > completion callback during a conversion.
> >
> > I don't know the bigger picture (and no links here for general cleanup)
> > but I assume it is part of wider work and that mlock is unwanted. In
> > such case:
> >
> > Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> >
> > If it is part of some bigger work, please put a link to lore.kernel.org
> > under separators ---, so everyone can get the context.
>
> Will keep that in mind.
> I am not sure if there is a lore.kernel.org link that's easy to find
> for a discussion on this topic, maybe I can describe it here and use
> the link [from this later].
>
> This was something that popped up during reviews we got from Jonathan
> [or others], saying "please don't use indio_dev->mlock, that is an IIO
> framework lock, and an IIO driver should not use it".
Shortest one is the docs for that lock say don't use it directly in
a driver :)
https://elixir.bootlin.com/linux/latest/source/include/linux/iio/iio.h#L495
> Reasons include [and some may be repeated a bit]:
> - this could cause a deadlock if the IIO framework holds this lock and
> an IIO driver also tries to get a hold of this lock
> - similar to the previous point, this mlock is taken by
> iio_device_claim_direct_mode() and released by
> iio_device_release_direct_mode() ; which means that mlock aims to
> become more of an IIO framework lock, than a general usage lock;
> - this wasn't policed/reviewed intensely in the older driver [a few
> years ago], but has become a point in recent reviews;
> - if we want to develop/enhance the IIO framework, some elements like
> this need to be taken care of, as more drivers get added and more
> complexity gets added;
One side note here is we want to make all this [INTERN] state in
struct iio_dev opaque to drivers. It'll take a while as the boundary
gets crossed in various drivers.
> - there is an element of fairness [obviously], where someone writing a
> new IIO driver, takes an older one as example, and gets hit on the
> review; the person feels they did a good job in mimicking the old
> driver; their feeling is correct; the IIO framework should provide
> good references and/or cleanup existing drivers;
> - same as the previous point, we don't want to keep telling people
> writing new IIO drivers [and starting out with IIO] to "not use mlock
> [because it was copied from an old driver]"; it's more/needless review
> work
Good explanation.
Thanks,
Jonathan
>
>
> >
> >
> > Best regards,
> > Krzysztof
> >
> > >
> > > Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > > ---
> > > drivers/iio/adc/exynos_adc.c | 12 ++++++++----
> > > 1 file changed, 8 insertions(+), 4 deletions(-)
> > >
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
2020-08-26 13:22 [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock Alexandru Ardelean
2020-08-27 6:56 ` Krzysztof Kozlowski
@ 2020-08-29 15:35 ` Jonathan Cameron
2020-09-16 9:31 ` [PATCH v2] " Alexandru Ardelean
2 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2020-08-29 15:35 UTC (permalink / raw)
To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel, kgene, krzk, Sergiu Cuciurean
On Wed, 26 Aug 2020 16:22:03 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
>
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock, to protect potential concurrent access to the
> completion callback during a conversion.
>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Same comment as the other one about needing lock scope to be documented.
Otherwise looks good. I thought we only had complicated uses of this
left, but clearly not :)
Jonathan
> ---
> drivers/iio/adc/exynos_adc.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 7d23b6c33284..6a49f8dfab22 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -132,6 +132,8 @@ struct exynos_adc {
>
> struct completion completion;
>
> + struct mutex lock;
> +
> u32 value;
> unsigned int version;
>
> @@ -542,7 +544,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
> return -EINVAL;
> }
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&info->lock);
> reinit_completion(&info->completion);
>
> /* Select the channel to be used and Trigger conversion */
> @@ -562,7 +564,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
> ret = IIO_VAL_INT;
> }
>
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&info->lock);
>
> return ret;
> }
> @@ -573,7 +575,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
> unsigned long timeout;
> int ret;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&info->lock);
> info->read_ts = true;
>
> reinit_completion(&info->completion);
> @@ -598,7 +600,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
> }
>
> info->read_ts = false;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&info->lock);
>
> return ret;
> }
> @@ -872,6 +874,8 @@ static int exynos_adc_probe(struct platform_device *pdev)
> indio_dev->channels = exynos_adc_iio_channels;
> indio_dev->num_channels = info->data->num_channels;
>
> + mutex_init(&info->lock);
> +
> ret = request_irq(info->irq, exynos_adc_isr,
> 0, dev_name(&pdev->dev), info);
> if (ret < 0) {
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
2020-08-26 13:22 [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock Alexandru Ardelean
2020-08-27 6:56 ` Krzysztof Kozlowski
2020-08-29 15:35 ` Jonathan Cameron
@ 2020-09-16 9:31 ` Alexandru Ardelean
2020-09-19 15:19 ` Jonathan Cameron
2 siblings, 1 reply; 7+ messages in thread
From: Alexandru Ardelean @ 2020-09-16 9:31 UTC (permalink / raw)
To: linux-iio, linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: jic23, kgene, krzk, Sergiu Cuciurean, Alexandru Ardelean
From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock, to protect potential concurrent access to the
completion callback during a conversion.
This is part of a bigger cleanup.
Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/iio/adc/exynos_adc.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 20477b249f2a..99f4404e9fd1 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -138,6 +138,16 @@ struct exynos_adc {
bool read_ts;
u32 ts_x;
u32 ts_y;
+
+ /*
+ * Lock to protect from potential concurrent access to the
+ * completion callback during a manual conversion. For this driver
+ * a wait-callback is used to wait for the conversion result,
+ * so in the meantime no other read request (or conversion start)
+ * must be performed, otherwise it would interfere with the
+ * current conversion result.
+ */
+ struct mutex lock;
};
struct exynos_adc_data {
@@ -542,7 +552,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
return -EINVAL;
}
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&info->lock);
reinit_completion(&info->completion);
/* Select the channel to be used and Trigger conversion */
@@ -562,7 +572,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
ret = IIO_VAL_INT;
}
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&info->lock);
return ret;
}
@@ -573,7 +583,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
unsigned long timeout;
int ret;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&info->lock);
info->read_ts = true;
reinit_completion(&info->completion);
@@ -598,7 +608,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
}
info->read_ts = false;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&info->lock);
return ret;
}
@@ -868,6 +878,8 @@ static int exynos_adc_probe(struct platform_device *pdev)
indio_dev->channels = exynos_adc_iio_channels;
indio_dev->num_channels = info->data->num_channels;
+ mutex_init(&info->lock);
+
ret = request_irq(info->irq, exynos_adc_isr,
0, dev_name(&pdev->dev), info);
if (ret < 0) {
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock
2020-09-16 9:31 ` [PATCH v2] " Alexandru Ardelean
@ 2020-09-19 15:19 ` Jonathan Cameron
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2020-09-19 15:19 UTC (permalink / raw)
To: Alexandru Ardelean
Cc: linux-iio, linux-arm-kernel, linux-samsung-soc, linux-kernel,
kgene, krzk, Sergiu Cuciurean
On Wed, 16 Sep 2020 12:31:23 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> From: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
>
> As part of the general cleanup of indio_dev->mlock, this change replaces
> it with a local lock, to protect potential concurrent access to the
> completion callback during a conversion.
>
> This is part of a bigger cleanup.
> Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/
>
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/adc/exynos_adc.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 20477b249f2a..99f4404e9fd1 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -138,6 +138,16 @@ struct exynos_adc {
> bool read_ts;
> u32 ts_x;
> u32 ts_y;
> +
> + /*
> + * Lock to protect from potential concurrent access to the
> + * completion callback during a manual conversion. For this driver
> + * a wait-callback is used to wait for the conversion result,
> + * so in the meantime no other read request (or conversion start)
> + * must be performed, otherwise it would interfere with the
> + * current conversion result.
> + */
> + struct mutex lock;
> };
>
> struct exynos_adc_data {
> @@ -542,7 +552,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
> return -EINVAL;
> }
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&info->lock);
> reinit_completion(&info->completion);
>
> /* Select the channel to be used and Trigger conversion */
> @@ -562,7 +572,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
> ret = IIO_VAL_INT;
> }
>
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&info->lock);
>
> return ret;
> }
> @@ -573,7 +583,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
> unsigned long timeout;
> int ret;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&info->lock);
> info->read_ts = true;
>
> reinit_completion(&info->completion);
> @@ -598,7 +608,7 @@ static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
> }
>
> info->read_ts = false;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&info->lock);
>
> return ret;
> }
> @@ -868,6 +878,8 @@ static int exynos_adc_probe(struct platform_device *pdev)
> indio_dev->channels = exynos_adc_iio_channels;
> indio_dev->num_channels = info->data->num_channels;
>
> + mutex_init(&info->lock);
> +
> ret = request_irq(info->irq, exynos_adc_isr,
> 0, dev_name(&pdev->dev), info);
> if (ret < 0) {
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-09-19 15:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26 13:22 [PATCH] iio: adc: exynos_adc: Replace indio_dev->mlock with own device lock Alexandru Ardelean
2020-08-27 6:56 ` Krzysztof Kozlowski
2020-08-27 8:53 ` Alexandru Ardelean
2020-08-29 15:33 ` Jonathan Cameron
2020-08-29 15:35 ` Jonathan Cameron
2020-09-16 9:31 ` [PATCH v2] " Alexandru Ardelean
2020-09-19 15:19 ` Jonathan Cameron
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).