IIO: Alignment fixes part 3 - __aligned(8) used to ensure alignment
Subsystems (6)
Jonathan Cameron
maintainercover IIO: Alignment fixes part 3 - __aligned(8) used to ensure alignment
From: Jonathan Cameron <[email protected]>
Resent as none of these have had any comments since being sent out over a month ago. Note these are very straight forward, but I've messed up such things in the past so really appreciate it if someone takes the time to do a quick sanity check.
I have picked up those patches that did get review in first posting and dropped them from this posting.
Cover letter from first posting.
I finally got around to do a manual audit of all the calls to iio_push_to_buffers_with_timestamp() which has the somewhat odd requirements of:
1. 8 byte alignment of the provided buffer.
2. space for an 8 byte naturally aligned timestamp to be inserted at the end.
Unfortunately there were rather a lot of these left, but time to bite the bullet and clean them up.
As discussed previous in
https://lore.kernel.org/linux-iio/[email protected]/
it is not easy to fix the alignment issue without requiring a bounce buffer (see part 4 of the alignment fixes for a proposal for that where it is absolutely necessary).
Part 3 contains the cases where the struct approach in part 2 did not seem appropriate. Normally there are two possible reasons for this.
1. Would have required an additional memset operation to avoid any possibility of leaking kernel data.
2. The location of the timestamp may depend on the channels enabled. This normally happens when the max sizeof channels is greater than 8 bytes.
Once all cases are fixes, I'll take a look at hardening against any accidental reintroductions. Note that on many platforms and usecases the bug in question will never occur.
Jonathan Cameron (8):
iio: adc: at91-sama5d2: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: hx711: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: mxs-lradc: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: ti-ads8688: Fix alignment of buffer in
iio_push_to_buffers_with_timestamp()
iio: magn: rm3100: Fix alignment of buffer in
iio_push_to_buffers_with_timestamp()
iio: light: vcnl4000: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: light: vcnl4035: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: prox: isl29501: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
drivers/iio/adc/at91-sama5d2_adc.c | 3 ++- drivers/iio/adc/hx711.c | 4 ++-- drivers/iio/adc/mxs-lradc-adc.c | 3 ++- drivers/iio/adc/ti-ads8688.c | 3 ++- drivers/iio/light/vcnl4000.c | 2 +- drivers/iio/light/vcnl4035.c | 3 ++- drivers/iio/magnetometer/rm3100-core.c | 3 ++- drivers/iio/proximity/isl29501.c | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-)
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 1/8 iio: adc: at91-sama5d2: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
From: Jonathan Cameron <[email protected]>
To make code more readable, use a structure to express the channel layout and ensure the timestamp is 8 byte aligned.
Found during an audit of all calls of this function.
--- drivers/iio/adc/at91-sama5d2_adc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/at91-sama5d2_adc.c +2 -1
@@ -403,7 +403,8 @@ struct at91_adc_state {struct at91_adc_dma dma_st;struct at91_adc_touch touch_st;struct iio_dev *indio_dev; -u16 buffer[AT91_BUFFER_MAX_HWORDS ]; +/* Ensure naturally aligned timestamp */ +u16 buffer[AT91_BUFFER_MAX_HWORDS ]__aligned(8) ;/* * lock to prevent concurrent 'single conversion' requests through * sysfs.
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 2/8 iio: adc: hx711: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
To make code more readable, use a structure to express the channel layout and ensure the timestamp is 8 byte aligned.
Found during an audit of all calls of this function.
--- drivers/iio/adc/hx711.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/hx711.c +2 -2
@@ -86,9 +86,9 @@ struct hx711_data {struct mutex lock;/* * triggered buffer -* 2x32-bit channel + 64-bit timestamp +* 2x32-bit channel + 64-bit naturally aligned timestamp */ -u32 buffer[4 ]; +u32 buffer[4 ]__aligned(8) ;/* * delay after a rising edge on SCK until the data is ready DOUT * this is dependent on the hx711 where the datasheet tells a
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 3/8 iio: adc: mxs-lradc: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
To make code more readable, use a structure to express the channel layout and ensure the timestamp is 8 byte aligned.
Add a comment on why the buffer is the size it is as not immediately obvious.
Found during an audit of all calls of this function.
--- drivers/iio/adc/mxs-lradc-adc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/mxs-lradc-adc.c +2 -1
@@ -115,7 +115,8 @@ struct mxs_lradc_adc {struct device *dev;void __iomem *base; -u32 buffer[10 ]; +/* Maximum of 8 channels + 8 byte ts */ +u32 buffer[10 ]__aligned(8) ;struct iio_trigger *trig;struct completion completion;spinlock_t lock;
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 4/8 iio: adc: ti-ads8688: Fix alignment of buffer in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Add __aligned(8) to ensure the buffer passed to iio_push_to_buffers_with_timestamp() is suitable for the naturally aligned timestamp that will be inserted.
--- drivers/iio/adc/ti-ads8688.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/ti-ads8688.c +2 -1
@@ -383,7 +383,8 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p) {struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev; -u16 buffer[ADS8688_MAX_CHANNELS +sizeof (s64)/sizeof (u16)]; +/* Ensure naturally aligned timestamp */ +u16 buffer[ADS8688_MAX_CHANNELS +sizeof (s64)/sizeof (u16)]__aligned(8) ;int i, j =0 ;for (i =0 ; i < indio_dev->masklength; i++) {
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 5/8 iio: magn: rm3100: Fix alignment of buffer in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Add __aligned(8) to ensure the buffer passed to iio_push_to_buffers_with_timestamp() is suitable for the naturally aligned timestamp that will be inserted.
Here an explicit structure is not used, because this buffer is used in a non-trivial way for data repacking.
--- drivers/iio/magnetometer/rm3100-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/magnetometer/rm3100-core.c +2 -1
@@ -78,7 +78,8 @@ struct rm3100_data {bool use_interrupt;int conversion_time;int scale; -u8 buffer[RM3100_SCAN_BYTES ]; +/* Ensure naturally aligned timestamp */ +u8 buffer[RM3100_SCAN_BYTES ]__aligned(8) ;struct iio_trigger *drdy_trig;/*
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 6/8 iio: light: vcnl4000: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Add __aligned(8) to ensure the buffer passed to iio_push_to_buffers_with_timestamp() is suitable for the naturally aligned timestamp that will be inserted.
Here an explicit structure is not used, because the holes would necessitate the addition of an explict memset(), to avoid a kernel data leak, making for a less minimal fix.
Found during an audit of all callers of iio_push_to_buffers_with_timestamp()
--- drivers/iio/light/vcnl4000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4000.c +1 -1
@@ -908,7 +908,7 @@ static irqreturn_t vcnl4010_trigger_handler(int irq, void *p)struct iio_dev *indio_dev = pf->indio_dev;struct vcnl4000_data *data =iio_priv (indio_dev);const unsigned long *active_scan_mask = indio_dev->active_scan_mask; -u16 buffer[8 ] = {0 };/* 1x16-bit + ts */ +u16 buffer[8 ]__aligned(8) = {0 };/* 1x16-bit + naturally aligned ts */ bool data_read = false;unsigned long isr;int val =0 ;
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 7/8 iio: light: vcnl4035: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Add __aligned(8) to ensure the buffer passed to iio_push_to_buffers_with_timestamp() is suitable for the naturally aligned timestamp that will be inserted.
Here an explicit structure is not used, because the holes would necessitate the addition of an explict memset(), to avoid a potential kernel data leak, making for a less minimal fix.
--- drivers/iio/light/vcnl4035.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +2 -1
@@ -102,7 +102,8 @@ static irqreturn_t vcnl4035_trigger_consumer_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct vcnl4035_data *data =iio_priv (indio_dev); -u8 buffer[ALIGN (sizeof (u16),sizeof (s64)) +sizeof (s64)]; +/* Ensure naturally aligned timestamp */ +u8 buffer[ALIGN (sizeof (u16),sizeof (s64)) +sizeof (s64)]__aligned(8) ;int ret; ret =regmap_read (data->regmap,VCNL4035_ALS_DATA , (int *)buffer);
Signature · 1 line
2.32.0
Jonathan Cameron
maintainerPATCH RESEND 8/8 iio: prox: isl29501: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Add __aligned(8) to ensure the buffer passed to iio_push_to_buffers_with_timestamp() is suitable for the naturally aligned timestamp that will be inserted.
Here an explicit structure is not used, because the holes would necessitate the addition of an explict memset(), to avoid a kernel data leak, making for a less minimal fix.
--- drivers/iio/proximity/isl29501.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/proximity/isl29501.c +1 -1
@@ -938,7 +938,7 @@ static irqreturn_t isl29501_trigger_handler(int irq, void *p)struct iio_dev *indio_dev = pf->indio_dev;struct isl29501_private *isl29501 =iio_priv (indio_dev);const unsigned long *active_mask = indio_dev->active_scan_mask; -u32 buffer[4 ] = {};/* 1x16-bit + ts */ +u32 buffer[4 ]__aligned(8) = {};/* 1x16-bit + naturally aligned ts */ if (test_bit (ISL29501_DISTANCE_SCAN_INDEX , active_mask))isl29501_register_read (isl29501,REG_DISTANCE , buffer);
Signature · 1 line
2.32.0
Hi Jonathan,
Quoted 95 lines
From: Jonathan Cameron <[email protected]>
Sent: Sunday, June 13, 2021 5:23 PM
To: [email protected]
Cc: Jonathan Cameron <[email protected]>; Eugen Hristev <[email protected]>; Andreas Klinger <ak@it- klinger.d>; Song Qiang <[email protected]>; Mathieu Othacehe <[email protected]>; Parthiban Nallathambi <[email protected]>
Subject: [PATCH RESEND 0/8] IIO: Alignment fixes part 3 -__aligned(8)used to ensure alignmentFrom: Jonathan Cameron <[email protected]>
Resent as none of these have had any comments since being sent out over
a month ago. Note these are very straight forward, but I've messed up such things in the past so really appreciate it if someone takes the time to do a quick sanity check.I have picked up those patches that did get review in first posting and dropped them from this posting.
Cover letter from first posting.
I finally got around to do a manual audit of all the calls to
iio_push_to_buffers_with_timestamp()which has the somewhat odd requirements
of:
1. 8 byte alignment of the provided buffer.
2. space for an 8 byte naturally aligned timestamp to be inserted at the end.Unfortunately there were rather a lot of these left, but time to bite the bullet
and clean them up.As discussed previous in
https://urldefense.com/v3/__https://lore.kernel.org/linux-
iio/20200920112742.170751-1- [email protected]/__;!!A3Ni8CS0y2Y!uCn6NSpGUvHYdcFazn7flxxjh8RA RqPCumitrRDDgGAjXF7crgi911KY2v_iyw$
it is not easy to fix the alignment issue without requiring a bounce buffer
(see part 4 of the alignment fixes for a proposal for that where it is absolutely necessary).Part 3 contains the cases where the struct approach in part 2 did not seem
appropriate. Normally there are two possible reasons for this.
1. Would have required an additional memset operation to avoid any possibility of leaking kernel data.
2. The location of the timestamp may depend on the channels enabled.
This normally happens when the max sizeof channels is greater than 8 bytes.Once all cases are fixes, I'll take a look at hardening against any accidental reintroductions. Note that on many platforms and usecases the
bug in question will never occur.Cc Eugen Hristev <[email protected]>Cc Andreas Klinger <[email protected]>Cc Song Qiang <[email protected]>Cc Mathieu Othacehe <[email protected]>Cc Parthiban Nallathambi <[email protected]>Jonathan Cameron (8):
iio: adc: at91-sama5d2: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: hx711: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: mxs-lradc: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: ti-ads8688: Fix alignment of buffer in
iio_push_to_buffers_with_timestamp()
iio: magn: rm3100: Fix alignment of buffer in
iio_push_to_buffers_with_timestamp()
iio: light: vcnl4000: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: light: vcnl4035: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: prox: isl29501: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()drivers/iio/adc/at91-sama5d2_adc.c | 3 ++- drivers/iio/adc/hx711.c | 4 ++-- drivers/iio/adc/mxs-lradc-adc.c | 3 ++- drivers/iio/adc/ti-ads8688.c | 3 ++- drivers/iio/light/vcnl4000.c | 2 +- drivers/iio/light/vcnl4035.c | 3 ++- drivers/iio/magnetometer/rm3100-core.c | 3 ++- drivers/iio/proximity/isl29501.c | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-)
Quoted 2 lines
--
2.32.0
LGTM. For the whole series:
- Nuno Sá
Jonathan Cameron
maintainerQuoted 97 lines · Nuno
Hi Jonathan,
Quoted 95 lines
From: Jonathan Cameron <[email protected]>
Sent: Sunday, June 13, 2021 5:23 PM
To: [email protected]
Cc: Jonathan Cameron <[email protected]>; Eugen Hristev <[email protected]>; Andreas Klinger <ak@it- klinger.d>; Song Qiang <[email protected]>; Mathieu Othacehe <[email protected]>; Parthiban Nallathambi <[email protected]>
Subject: [PATCH RESEND 0/8] IIO: Alignment fixes part 3 -__aligned(8)used to ensure alignmentFrom: Jonathan Cameron <[email protected]>
Resent as none of these have had any comments since being sent out over
a month ago. Note these are very straight forward, but I've messed up such things in the past so really appreciate it if someone takes the time to do a quick sanity check.I have picked up those patches that did get review in first posting and dropped them from this posting.
Cover letter from first posting.
I finally got around to do a manual audit of all the calls to
iio_push_to_buffers_with_timestamp()which has the somewhat odd requirements
of:
1. 8 byte alignment of the provided buffer.
2. space for an 8 byte naturally aligned timestamp to be inserted at the end.Unfortunately there were rather a lot of these left, but time to bite the bullet
and clean them up.As discussed previous in
https://urldefense.com/v3/__https://lore.kernel.org/linux-
iio/20200920112742.170751-1- [email protected]/__;!!A3Ni8CS0y2Y!uCn6NSpGUvHYdcFazn7flxxjh8RA RqPCumitrRDDgGAjXF7crgi911KY2v_iyw$
it is not easy to fix the alignment issue without requiring a bounce buffer
(see part 4 of the alignment fixes for a proposal for that where it is absolutely necessary).Part 3 contains the cases where the struct approach in part 2 did not seem
appropriate. Normally there are two possible reasons for this.
1. Would have required an additional memset operation to avoid any possibility of leaking kernel data.
2. The location of the timestamp may depend on the channels enabled.
This normally happens when the max sizeof channels is greater than 8 bytes.Once all cases are fixes, I'll take a look at hardening against any accidental reintroductions. Note that on many platforms and usecases the
bug in question will never occur.Cc Eugen Hristev <[email protected]>Cc Andreas Klinger <[email protected]>Cc Song Qiang <[email protected]>Cc Mathieu Othacehe <[email protected]>Cc Parthiban Nallathambi <[email protected]>Jonathan Cameron (8):
iio: adc: at91-sama5d2: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: hx711: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: mxs-lradc: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: adc: ti-ads8688: Fix alignment of buffer in
iio_push_to_buffers_with_timestamp()
iio: magn: rm3100: Fix alignment of buffer in
iio_push_to_buffers_with_timestamp()
iio: light: vcnl4000: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: light: vcnl4035: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()
iio: prox: isl29501: Fix buffer alignment in
iio_push_to_buffers_with_timestamp()drivers/iio/adc/at91-sama5d2_adc.c | 3 ++- drivers/iio/adc/hx711.c | 4 ++-- drivers/iio/adc/mxs-lradc-adc.c | 3 ++- drivers/iio/adc/ti-ads8688.c | 3 ++- drivers/iio/light/vcnl4000.c | 2 +- drivers/iio/light/vcnl4035.c | 3 ++- drivers/iio/magnetometer/rm3100-core.c | 3 ++- drivers/iio/proximity/isl29501.c | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-)
Quoted 6 lines
Quoted 2 lines
--
2.32.0LGTM. For the whole series:
Reviewed-by Nuno Sá <[email protected]>
Thanks!
Given how long they've been sitting around on list...
Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons.
Thanks,
Jonathan
Quoted 2 lines
- Nuno Sá