Skip to contentSkip to conversation

platform/chrome: sensorhub: Fix dropped timestamp events and log spam

PATCH In review Tzung-Bi Shih 2 participants 5 messages Jul 15 – Jul 16

Subsystems (2)
lore
Share & tools
lore

Tzung-Bi Shih

author maintainer
#0 lore raw

PATCH v2 1/1 platform/chrome: sensorhub: Fix dropped timestamp events and log spam

Commit 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number") evaluated the sensor_num against the bounds limit even for timestamp events. A timestamp event typically has a sensor_num of 0xff [1], causing the driver to flag it as invalid and skip to the next event.

As a result, we'd see a flooding of "Invalid sensor number 255 from EC" warning logs and these timestamp events were being dropped.

Move the bounds-check into cros_ec_sensor_ring_process_event() and evaluate it only after standalone timestamp events have already been processed and returned early.

[1] https://crrev.com/219ca6ef82ba266da788b673ee4ad50bd3ea1285/common/motion_sense_fifo.c#427

Fixes 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number")

---
Bryam: sorry for reverting the decision (moving back the check to cros_ec_sensor_ring_process_event()). I realized we need to prevent dropping timestamp events and flooding the logs.
---
v2:
- Move the check to cros_ec_sensor_ring_process_event().
- Return earlier for standalone timestamp events.

v1: https://lore.kernel.org/all/[email protected]

---
 .../platform/chrome/cros_ec_sensorhub_ring.c  | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +15 -12
index 92941924c347..d92b60213720 100644
@@ -475,6 +475,21 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
 						  fifo_timestamp,
 						  *current_timestamp,
 						  now);
+
+		/*
+		 * A standalone timestamp event typically has a sensor_num of
+		 * 0xff.  Return early here to prevent it from hitting the
+		 * bounds check below and spamming the logs.
+		 */
+		return false;
+	}
+
+	/* Skip event if sensor_num from EC is out of bounds. */
+	if (in->sensor_num >= sensorhub->sensor_num) {
+		dev_warn_ratelimited(sensorhub->dev,
+				     "Invalid sensor number %u from EC\n",
+				     in->sensor_num);
+		return false;
 	}
 
 	if (in->flags & MOTIONSENSE_SENSOR_FLAG_ODR) {
@@ -502,10 +517,6 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
 		return true;
 	}
 
-	if (in->flags & MOTIONSENSE_SENSOR_FLAG_TIMESTAMP)
-		/* If we just have a timestamp, skip this entry. */
-		return false;
-
 	/* Regular sample */
 	out->sensor_id = in->sensor_num;
 	trace_cros_ec_sensorhub_data(in->sensor_num,
@@ -897,14 +908,6 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub)
 
 		for (in = sensorhub->resp->fifo_read.data, j = 0;
 		     j < number_data; j++, in++) {
-			/* Skip event if sensor_num from EC is out of bounds. */
-			if (in->sensor_num >= sensorhub->sensor_num) {
-				dev_warn_ratelimited(sensorhub->dev,
-						     "Invalid sensor number %u from EC\n",
-						     in->sensor_num);
-				continue;
-			}
-
 			if (cros_ec_sensor_ring_process_event(
 						sensorhub, fifo_info,
 						fifo_timestamp,
Signature · 1 line
2.55.0.229.g6434b31f56-goog
#1 lore raw
Quoted 59 lines · Tzung-Bi Shih

Commit 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number") evaluated the sensor_num against the bounds limit even for timestamp events. A timestamp event typically has a sensor_num of 0xff [1], causing the driver to flag it as invalid and skip to the next event.

As a result, we'd see a flooding of "Invalid sensor number 255 from EC" warning logs and these timestamp events were being dropped.

Move the bounds-check into cros_ec_sensor_ring_process_event() and evaluate it only after standalone timestamp events have already been processed and returned early.

[1] https://crrev.com/219ca6ef82ba266da788b673ee4ad50bd3ea1285/common/motion_sense_fifo.c#427

Fixes 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number")

---
Bryam: sorry for reverting the decision (moving back the check to cros_ec_sensor_ring_process_event()). I realized we need to prevent dropping timestamp events and flooding the logs.
---
v2:
- Move the check to cros_ec_sensor_ring_process_event().
- Return earlier for standalone timestamp events.

v1: https://lore.kernel.org/all/[email protected]

---
 .../platform/chrome/cros_ec_sensorhub_ring.c  | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +15 -0
index 92941924c347..d92b60213720 100644
@@ -475,6 +475,21 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
                                                  fifo_timestamp,
                                                  *current_timestamp,
                                                  now);
+
+               /*
+                * A standalone timestamp event typically has a sensor_num of
+                * 0xff.  Return early here to prevent it from hitting the
+                * bounds check below and spamming the logs.
+                */
+               return false;
+       }
+
+       /* Skip event if sensor_num from EC is out of bounds. */
+       if (in->sensor_num >= sensorhub->sensor_num) {
+               dev_warn_ratelimited(sensorhub->dev,
+                                    "Invalid sensor number %u from EC\n",
+                                    in->sensor_num);
+               return false;
        }
 
        if (in->flags & MOTIONSENSE_SENSOR_FLAG_ODR) {

drivers/platform/chrome/cros_ec_sensorhub_ring.c cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub, · line 508

Quoted 7 lines
drivers/platform/chrome/cros_ec_sensorhub_ring.c +0 -4
@@ -502,10 +517,6 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
                return true;
        }
 
-       if (in->flags & MOTIONSENSE_SENSOR_FLAG_TIMESTAMP)
-               /* If we just have a timestamp, skip this entry. */
-               return false;
-

Isn't this still needed for the case of MOTIONSENSE_SENSOR_FLAG_TIMESTAMP and (MOTIONSENSE_SENSOR_FLAG_ODR and/or MOTIONSENSE_SENSOR_FLAG_FLUSH)?

Quoted 19 lines
drivers/platform/chrome/cros_ec_sensorhub_ring.c +0 -9
        /* Regular sample */
        out->sensor_id = in->sensor_num;
        trace_cros_ec_sensorhub_data(in->sensor_num,
@@ -897,14 +908,6 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub)
 
                for (in = sensorhub->resp->fifo_read.data, j = 0;
                     j < number_data; j++, in++) {
-                       /* Skip event if sensor_num from EC is out of bounds. */
-                       if (in->sensor_num >= sensorhub->sensor_num) {
-                               dev_warn_ratelimited(sensorhub->dev,
-                                                    "Invalid sensor number %u from EC\n",
-                                                    in->sensor_num);
-                               continue;
-                       }
-
                        if (cros_ec_sensor_ring_process_event(
                                                sensorhub, fifo_info,
                                                fifo_timestamp,
--
Quoted 2 lines

2.55.0.229.g6434b31f56-goog

Best,
Tomasz

author maintainer
#2 lore raw
Quoted 63 lines · Tomasz Figa
Quoted 62 lines · Tzung-Bi Shih

Commit 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number") evaluated the sensor_num against the bounds limit even for timestamp events. A timestamp event typically has a sensor_num of 0xff [1], causing the driver to flag it as invalid and skip to the next event.

As a result, we'd see a flooding of "Invalid sensor number 255 from EC" warning logs and these timestamp events were being dropped.

Move the bounds-check into cros_ec_sensor_ring_process_event() and evaluate it only after standalone timestamp events have already been processed and returned early.

[1] https://crrev.com/219ca6ef82ba266da788b673ee4ad50bd3ea1285/common/motion_sense_fifo.c#427

Fixes 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number")

---
Bryam: sorry for reverting the decision (moving back the check to cros_ec_sensor_ring_process_event()). I realized we need to prevent dropping timestamp events and flooding the logs.
---
v2:
- Move the check to cros_ec_sensor_ring_process_event().
- Return earlier for standalone timestamp events.

v1: https://lore.kernel.org/all/[email protected]

---
 .../platform/chrome/cros_ec_sensorhub_ring.c  | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +15 -0
index 92941924c347..d92b60213720 100644
@@ -475,6 +475,21 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
                                                  fifo_timestamp,
                                                  *current_timestamp,
                                                  now);
+
+               /*
+                * A standalone timestamp event typically has a sensor_num of
+                * 0xff.  Return early here to prevent it from hitting the
+                * bounds check below and spamming the logs.
+                */
+               return false;
+       }
+
+       /* Skip event if sensor_num from EC is out of bounds. */
+       if (in->sensor_num >= sensorhub->sensor_num) {
+               dev_warn_ratelimited(sensorhub->dev,
+                                    "Invalid sensor number %u from EC\n",
+                                    in->sensor_num);
+               return false;
        }
 
        if (in->flags & MOTIONSENSE_SENSOR_FLAG_ODR) {
@@ -502,10 +517,6 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
                return true;
        }
 
Quoted 8 lines

drivers/platform/chrome/cros_ec_sensorhub_ring.c cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub, · line 508

Quoted 4 lines
drivers/platform/chrome/cros_ec_sensorhub_ring.c +0 -4
-       if (in->flags & MOTIONSENSE_SENSOR_FLAG_TIMESTAMP)
-               /* If we just have a timestamp, skip this entry. */
-               return false;
-

Isn't this still needed for the case of MOTIONSENSE_SENSOR_FLAG_TIMESTAMP and (MOTIONSENSE_SENSOR_FLAG_ODR and/or MOTIONSENSE_SENSOR_FLAG_FLUSH)?

The block serves for standalone MOTIONSENSE_SENSOR_FLAG_TIMESTAMP events. If the flags contains ODR or FLUSH, it returns in other branches.

After applying the patch, the flow of cros_ec_sensor_ring_process_event() looks like:

If TIMESTAMP but (!ODR and !FLUSH):
...
return <--- The patch merges the block and returns early.

Check bounds for sensor_num

If ODR:

     ...
     return

If FLUSH:

     ...
     return
Reviewed-by
#3 lore raw
Quoted 86 lines · Tzung-Bi Shih
Quoted 63 lines · Tomasz Figa
Quoted 62 lines · Tzung-Bi Shih

Commit 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number") evaluated the sensor_num against the bounds limit even for timestamp events. A timestamp event typically has a sensor_num of 0xff [1], causing the driver to flag it as invalid and skip to the next event.

As a result, we'd see a flooding of "Invalid sensor number 255 from EC" warning logs and these timestamp events were being dropped.

Move the bounds-check into cros_ec_sensor_ring_process_event() and evaluate it only after standalone timestamp events have already been processed and returned early.

[1] https://crrev.com/219ca6ef82ba266da788b673ee4ad50bd3ea1285/common/motion_sense_fifo.c#427

Fixes 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number")

---
Bryam: sorry for reverting the decision (moving back the check to cros_ec_sensor_ring_process_event()). I realized we need to prevent dropping timestamp events and flooding the logs.
---
v2:
- Move the check to cros_ec_sensor_ring_process_event().
- Return earlier for standalone timestamp events.

v1: https://lore.kernel.org/all/[email protected]

---
 .../platform/chrome/cros_ec_sensorhub_ring.c  | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +15 -0
index 92941924c347..d92b60213720 100644
@@ -475,6 +475,21 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
                                                  fifo_timestamp,
                                                  *current_timestamp,
                                                  now);
+
+               /*
+                * A standalone timestamp event typically has a sensor_num of
+                * 0xff.  Return early here to prevent it from hitting the
+                * bounds check below and spamming the logs.
+                */
+               return false;
+       }
+
+       /* Skip event if sensor_num from EC is out of bounds. */
+       if (in->sensor_num >= sensorhub->sensor_num) {
+               dev_warn_ratelimited(sensorhub->dev,
+                                    "Invalid sensor number %u from EC\n",
+                                    in->sensor_num);
+               return false;
        }
 
        if (in->flags & MOTIONSENSE_SENSOR_FLAG_ODR) {
@@ -502,10 +517,6 @@ cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub,
                return true;
        }
 
Quoted 8 lines

drivers/platform/chrome/cros_ec_sensorhub_ring.c cros_ec_sensor_ring_process_event(struct cros_ec_sensorhub *sensorhub, · line 508

Quoted 4 lines
drivers/platform/chrome/cros_ec_sensorhub_ring.c +0 -4
-       if (in->flags & MOTIONSENSE_SENSOR_FLAG_TIMESTAMP)
-               /* If we just have a timestamp, skip this entry. */
-               return false;
-

Isn't this still needed for the case of MOTIONSENSE_SENSOR_FLAG_TIMESTAMP and (MOTIONSENSE_SENSOR_FLAG_ODR and/or MOTIONSENSE_SENSOR_FLAG_FLUSH)?

The block serves for standalone MOTIONSENSE_SENSOR_FLAG_TIMESTAMP events. If the flags contains ODR or FLUSH, it returns in other branches.

After applying the patch, the flow of cros_ec_sensor_ring_process_event() looks like:

If TIMESTAMP but (!ODR and !FLUSH):
...
return <--- The patch merges the block and returns early.

Check bounds for sensor_num

Quoted 7 lines

If ODR:

     ...
     return

If FLUSH:

     ...
     return

Ah, right, I didn't notice that those blocks already returned. Sorry for the noise.

Best,
Tomasz

author maintainer
#4 lore raw
In reply to Tzung-Bi Shih
Quoted 10 lines · Tzung-Bi Shih

Commit 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number") evaluated the sensor_num against the bounds limit even for timestamp events. A timestamp event typically has a sensor_num of 0xff [1], causing the driver to flag it as invalid and skip to the next event.

As a result, we'd see a flooding of "Invalid sensor number 255 from EC" warning logs and these timestamp events were being dropped.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

[1/1] platform/chrome: sensorhub: Fix dropped timestamp events and log spam

      commit: 9a3f43b30373c61477d0d3ab52946c05f9492bf9

Thanks!