Skip to contentSkip to conversation

Fix privacy issue for MEI CSI

PATCH In review Wentong Wu 2 participants 6 messages Jun 7, 2024

Subsystems (2)
lore
Share & tools
lore

Wentong Wu

author
#0 lore raw

v2 cover Fix privacy issue for MEI CSI

Currently if starting stream goes with privacy mode on, the whole pipeline will fail because MEI CSI counts privacy mode on as error. In fact, the ongoing MEI command is well executed by firmware as well even if privacy mode is turned on. The status (-1) of command response is just to indicate current privacy on status instead of failed to execute command by firmware. This patch set changes the behavior to notify privacy mode on via v4l2 privacy controlinstead of fail the ongoing MEI command.

This patch set adds one dedicated lock for v4l2 control handler to avoid dead locking issue as well. And the useless privacy status in struct mei_csi is removed to make code clean.

---
v1 -> v2:
1. switch CSI_PRIVACY_ON to notif.cont.cont == CSI_PRIVACY_ON

Wentong Wu (3):
media: ivsc: csi: don't count privacy on as error
media: ivsc: csi: add separate lock for v4l2 control handler
media: ivsc: csi: remove privacy status in struct mei_csi

 drivers/media/pci/intel/ivsc/mei_csi.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/3 media: ivsc: csi: don't count privacy on as error

Prior to the ongoing command privacy is on, it would return -1 to indicate the current privacy status, and the ongoing command would be well executed by firmware as well, so this is not error. This patch changes its behavior to notify privacy on directly by V4L2 privacy control instead of reporting error.

Fixes 29006e196a56 ("media: pci: intel: ivsc: Add CSI submodule")
---
 drivers/media/pci/intel/ivsc/mei_csi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/pci/intel/ivsc/mei_csi.c +5 -1
index 89b582a221ab..05c0acb78939 100644
@@ -190,7 +190,11 @@ static int mei_csi_send(struct mei_csi *csi, u8 *buf, size_t len)
 
 	/* command response status */
 	ret = csi->cmd_response.status;
-	if (ret) {
+	if (ret == -1) {
+		/* notify privacy on instead of reporting error */
+		ret = 0;
+		v4l2_ctrl_s_ctrl(csi->privacy_ctrl, 1);
+	} else if (ret) {
 		ret = -EINVAL;
 		goto out;
 	}
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/3 media: ivsc: csi: add separate lock for v4l2 control handler

In reply to Wentong Wu

There're possibilities that privacy status change notification happens in the middle of the ongoing mei command which already takes the command lock, but v4l2_ctrl_s_ctrl() would also need the same lock prior to this patch, so this may results in circular locking problem. This patch adds one dedicated lock for v4l2 control handler to avoid described issue.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/pci/intel/ivsc/mei_csi.c +7 -1
index 05c0acb78939..a46a012b301f 100644
@@ -126,6 +126,8 @@ struct mei_csi {
 	struct v4l2_ctrl_handler ctrl_handler;
 	struct v4l2_ctrl *freq_ctrl;
 	struct v4l2_ctrl *privacy_ctrl;
+	/* lock for v4l2 controls */
+	struct mutex ctrl_lock;
 	unsigned int remote_pad;
 	/* start streaming or not */
 	int streaming;
@@ -563,11 +565,13 @@ static int mei_csi_init_controls(struct mei_csi *csi)
 	u32 max;
 	int ret;
 
+	mutex_init(&csi->ctrl_lock);
+
 	ret = v4l2_ctrl_handler_init(&csi->ctrl_handler, 2);
 	if (ret)
 		return ret;
 
-	csi->ctrl_handler.lock = &csi->lock;
+	csi->ctrl_handler.lock = &csi->ctrl_lock;
 
 	max = ARRAY_SIZE(link_freq_menu_items) - 1;
 	csi->freq_ctrl = v4l2_ctrl_new_int_menu(&csi->ctrl_handler,
@@ -756,6 +760,7 @@ static int mei_csi_probe(struct mei_cl_device *cldev,
 
 err_ctrl_handler:
 	v4l2_ctrl_handler_free(&csi->ctrl_handler);
+	mutex_destroy(&csi->ctrl_lock);
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
 
@@ -775,6 +780,7 @@ static void mei_csi_remove(struct mei_cl_device *cldev)
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
 	v4l2_ctrl_handler_free(&csi->ctrl_handler);
+	mutex_destroy(&csi->ctrl_lock);
 	v4l2_async_unregister_subdev(&csi->subdev);
 	v4l2_subdev_cleanup(&csi->subdev);
 	media_entity_cleanup(&csi->subdev.entity);
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 3/3 media: ivsc: csi: remove privacy status in struct mei_csi

In reply to Wentong Wu

The privacy status is maintained by privacy_ctrl, on which all of the privacy status changes will go through, so there is no point in maintaining one more element any more.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +3 -7
index a46a012b301f..bff0176fc8f1 100644
@@ -138,9 +138,6 @@ struct mei_csi {
 	u32 nr_of_lanes;
 	/* frequency of the CSI-2 link */
 	u64 link_freq;
-
-	/* privacy status */
-	enum ivsc_privacy_status status;
 };
 
 static const struct v4l2_mbus_framefmt mei_csi_format_mbus_default = {
@@ -271,10 +268,9 @@ static void mei_csi_rx(struct mei_cl_device *cldev)
 
 	switch (notif.cmd_id) {
 	case CSI_PRIVACY_NOTIF:
-		if (notif.cont.cont < CSI_PRIVACY_MAX) {
-			csi->status = notif.cont.cont;
-			v4l2_ctrl_s_ctrl(csi->privacy_ctrl, csi->status);
-		}
+		if (notif.cont.cont < CSI_PRIVACY_MAX)
+			v4l2_ctrl_s_ctrl(csi->privacy_ctrl,
+					 notif.cont.cont == CSI_PRIVACY_ON);
 		break;
 	case CSI_SET_OWNER:
 	case CSI_SET_CONF:
Signature · 1 line
2.34.1
maintainer
#4 lore raw
In reply to Wentong Wu
Quoted 9 lines · Wentong Wu

Currently if starting stream goes with privacy mode on, the whole pipeline will fail because MEI CSI counts privacy mode on as error. In fact, the ongoing MEI command is well executed by firmware as well even if privacy mode is turned on. The status (-1) of command response is just to indicate current privacy on status instead of failed to execute command by firmware. This patch set changes the behavior to notify privacy mode on via v4l2 privacy controlinstead of fail the ongoing MEI command.

Quoted 3 lines

This patch set adds one dedicated lock for v4l2 control handler to avoid dead locking issue as well. And the useless privacy status in struct mei_csi is removed to make code clean.

Thanks, Wentong!

I'm reordering the first and the second patch, to avoid a deadlock before applying the other one, and adding to both of the two:

Fixes 29006e196a56 ("media: pci: intel: ivsc: Add CSI submodule")
Cc [email protected] # for 6.6 and later
Signature · 1 line
Sakari Ailus
#5 lore raw
Quoted 11 lines

From: Sakari Ailus <[email protected]>

Quoted 9 lines · Wentong Wu

Currently if starting stream goes with privacy mode on, the whole pipeline will fail because MEI CSI counts privacy mode on as error. In fact, the ongoing MEI command is well executed by firmware as well even if privacy mode is turned on. The status (-1) of command response is just to indicate current privacy on status instead of failed to execute command by firmware. This patch set changes the behavior to notify privacy mode on via v4l2 privacy controlinstead of fail the ongoing MEI command.

Quoted 8 lines
Quoted 3 lines

This patch set adds one dedicated lock for v4l2 control handler to avoid dead locking issue as well. And the useless privacy status in struct mei_csi is removed to make code clean.

Thanks, Wentong!

I'm reordering the first and the second patch, to avoid a deadlock before applying the other one,

Make sense, thanks

Quoted 5 lines

and adding to both of the two:

Fixes 29006e196a56 ("media: pci: intel: ivsc: Add CSI submodule")
Cc [email protected] # for 6.6 and later

Thanks

BR,
Wentong

Quoted 2 lines

--
Sakari Ailus