Skip to contentSkip to conversation

vchiq: Patch to separate platform and cdev code

PATCH Superseded Ojaswin Mujoo 5 participants 20 messages Jul 4, 2021 – Jul 21, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover vchiq: Patch to separate platform and cdev code

Hello,

This patchset adderesses the TODO item number 10 specified at:

drivers/staging/vc04-services/interface/TODO

For reference, the task is:

10) Reorganize file structure: Move char driver to it's own file and join both platform files

The cdev is defined alongside with the platform code in vchiq_arm.c. It would be nice to completely decouple it from the actual core code. For instance to be able to use bcm2835-audio without having /dev/vchiq created. One could argue it's better for security reasons or general cleanliness. It could even be interesting to create two different kernel modules, something the likes of vchiq-core.ko and vchiq-dev.ko. This would also ease the upstreaming process.

A summary of the patches is as follows:

- Patch 1: Move cdev init code into a function
- Patch 2: Shift some devlarations from vchiq_arm.c to vchiq_arm.h for sharing
- Patch 3: Move vchiq cdev init code from vchiq_arm.c into vchiq_dev.c
- Patch 4: Decouple cdev code by defining a Kconfig entry to allow optional compilation of it.
- Patch 5: Merge code in vchiq_2835_arm.c to vchiq_arm.c

(More details can be found in the commit messages)

Changes since v2 [1]:

* In Patch 1, as suggested, I have added error handling code back to ensure the driver exits when there is an error in creating vchiq cdev

* I have built this patch against the right kernel (gregkh/staging, staging-next branch) to avoid introducing any unwanted inconsistencies like whitespace changes

I have tested the patch using vchiq_test utility on RPi 3B+.

Additionally, I had a small question regarding the next steps here (quoting my cover letter from v2):

This question is more related to the next set of patches I'm planning to submit. So the last thing left in this TODO is to completely decouple vchiq platform and cdev code into 2 separate modules and I am planning to do that in a different patchset.

The approach I have in mind is to start by using EXPORT_SYMBOL to export all the functions (and accessor functions for variables like g_state) that would be required for cdev init. Majority of these would be exported from vchiq_arm.c and vchiq_core.c, and will then be used in vchiq-dev.ko. Is this the right way to approach this?

Thank you in advance for the help. Please let me know if any changes/ additional info is required.

Regards,
Ojaswin

[1] v2: https://lkml.org/lkml/2021/6/20/63

Ojaswin Mujoo (5):
staging: vchiq: Refactor vchiq cdev code
staging: vchiq: Move certain declarations to vchiq_arm.h
staging: vchiq: Move vchiq char driver to its own file
staging: vchiq: Make creation of vchiq cdev optional
staging: vchiq: Combine vchiq platform code into single file

 drivers/staging/vc04_services/Kconfig         |   10 +
 drivers/staging/vc04_services/Makefile        |    5 +-
 .../interface/vchiq_arm/vchiq_2835_arm.c      |  564 ----
 .../interface/vchiq_arm/vchiq_arm.c           | 2344 +++++------------
 .../interface/vchiq_arm/vchiq_arm.h           |   82 +
 .../interface/vchiq_arm/vchiq_dev.c           | 1440 ++++++++++
 6 files changed, 2265 insertions(+), 2180 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
 create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/5 staging: vchiq: Refactor vchiq cdev code

Move the vchiq cdev initialization code to its own function for better code organization. Call the initialization function during probe, thus shifting the whole cdev creation logic (which was earlier split in vchiq_probe() and vchiq_driver_init()) to vchiq_probe().

---
 .../interface/vchiq_arm/vchiq_arm.c           | 142 ++++++++++++------
 1 file changed, 92 insertions(+), 50 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +92 -50
index b5aac862a298..3a0724fe25ea 100644
@@ -2134,6 +2134,81 @@ vchiq_fops = {
 	.read = vchiq_read
 };
 
+/**
+ *	vchiq_register_chrdev - Register the char driver for vchiq
+ *				and create the necessary class and
+ *				device files in userspace.
+ *	@parent		The parent of the char device.
+ *
+ *	Returns 0 on success else returns the error code.
+ */
+static int vchiq_register_chrdev(struct device *parent)
+{
+	struct device *vchiq_dev;
+	int ret;
+
+	vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
+	if (IS_ERR(vchiq_class)) {
+		pr_err("Failed to create vchiq class\n");
+		ret = PTR_ERR(vchiq_class);
+		goto error_exit;
+	}
+
+	ret = alloc_chrdev_region(&vchiq_devid, 0, 1, DEVICE_NAME);
+	if (ret) {
+		pr_err("vchiq: Failed to allocate vchiq's chrdev region\n");
+		goto alloc_region_error;
+	}
+
+	cdev_init(&vchiq_cdev, &vchiq_fops);
+	vchiq_cdev.owner = THIS_MODULE;
+	ret = cdev_add(&vchiq_cdev, vchiq_devid, 1);
+	if (ret) {
+		vchiq_log_error(vchiq_arm_log_level,
+				"Unable to register vchiq char device");
+		goto cdev_add_error;
+	}
+
+	vchiq_dev = device_create(vchiq_class, parent, vchiq_devid, NULL,
+				  DEVICE_NAME);
+	if (IS_ERR(vchiq_dev)) {
+		vchiq_log_error(vchiq_arm_log_level,
+				"Failed to create vchiq char device node");
+		ret = PTR_ERR(vchiq_dev);
+		goto device_create_error;
+	}
+
+	vchiq_log_info(vchiq_arm_log_level,
+		       "vchiq char dev initialised successfully - device %d.%d",
+			MAJOR(vchiq_devid), MINOR(vchiq_devid));
+
+	return 0;
+
+device_create_error:
+	cdev_del(&vchiq_cdev);
+
+cdev_add_error:
+	unregister_chrdev_region(vchiq_devid, 1);
+
+alloc_region_error:
+	class_destroy(vchiq_class);
+
+error_exit:
+	return ret;
+}
+
+/**
+ *	vchiq_deregister_chrdev	- Deregister and cleanup the vchiq char
+ *				  driver and device files
+ */
+static void vchiq_deregister_chrdev(void)
+{
+	device_destroy(vchiq_class, vchiq_devid);
+	cdev_del(&vchiq_cdev);
+	unregister_chrdev_region(vchiq_devid, 1);
+	class_destroy(vchiq_class);
+}
+
 /*
  * Autosuspend related functionality
  */
@@ -2644,7 +2719,6 @@ static int vchiq_probe(struct platform_device *pdev)
 	struct device_node *fw_node;
 	const struct of_device_id *of_id;
 	struct vchiq_drvdata *drvdata;
-	struct device *vchiq_dev;
 	int err;
 
 	of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
@@ -2670,38 +2744,31 @@ static int vchiq_probe(struct platform_device *pdev)
 	if (err)
 		goto failed_platform_init;
 
-	cdev_init(&vchiq_cdev, &vchiq_fops);
-	vchiq_cdev.owner = THIS_MODULE;
-	err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
-	if (err) {
-		vchiq_log_error(vchiq_arm_log_level,
-			"Unable to register device");
-		goto failed_platform_init;
-	}
-
-	vchiq_dev = device_create(vchiq_class, &pdev->dev, vchiq_devid, NULL,
-				  "vchiq");
-	if (IS_ERR(vchiq_dev)) {
-		err = PTR_ERR(vchiq_dev);
-		goto failed_device_create;
-	}
-
 	vchiq_debugfs_init();
 
 	vchiq_log_info(vchiq_arm_log_level,
-		"vchiq: initialised - version %d (min %d), device %d.%d",
-		VCHIQ_VERSION, VCHIQ_VERSION_MIN,
-		MAJOR(vchiq_devid), MINOR(vchiq_devid));
+		       "vchiq: platform initialised - version %d (min %d)",
+		       VCHIQ_VERSION, VCHIQ_VERSION_MIN);
+
+	/*
+	 * Simply exit on error since the function handles cleanup in
+	 * cases of failure.
+	 */
+	err = vchiq_register_chrdev(&pdev->dev);
+	if (err) {
+		vchiq_log_warning(vchiq_arm_log_level,
+				  "Failed to initialize vchiq cdev");
+		goto error_exit;
+	}
 
 	bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera");
 	bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
 
 	return 0;
 
-failed_device_create:
-	cdev_del(&vchiq_cdev);
 failed_platform_init:
-	vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
+	vchiq_log_warning(vchiq_arm_log_level, "could not initialize vchiq platform");
+error_exit:
 	return err;
 }
 
@@ -2710,8 +2777,7 @@ static int vchiq_remove(struct platform_device *pdev)
 	platform_device_unregister(bcm2835_audio);
 	platform_device_unregister(bcm2835_camera);
 	vchiq_debugfs_deinit();
-	device_destroy(vchiq_class, vchiq_devid);
-	cdev_del(&vchiq_cdev);
+	vchiq_deregister_chrdev();
 
 	return 0;
 }
@@ -2729,31 +2795,9 @@ static int __init vchiq_driver_init(void)
 {
 	int ret;
 
-	vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
-	if (IS_ERR(vchiq_class)) {
-		pr_err("Failed to create vchiq class\n");
-		return PTR_ERR(vchiq_class);
-	}
-
-	ret = alloc_chrdev_region(&vchiq_devid, 0, 1, DEVICE_NAME);
-	if (ret) {
-		pr_err("Failed to allocate vchiq's chrdev region\n");
-		goto class_destroy;
-	}
-
 	ret = platform_driver_register(&vchiq_driver);
-	if (ret) {
+	if (ret)
 		pr_err("Failed to register vchiq driver\n");
-		goto region_unregister;
-	}
-
-	return 0;
-
-region_unregister:
-	unregister_chrdev_region(vchiq_devid, 1);
-
-class_destroy:
-	class_destroy(vchiq_class);
 
 	return ret;
 }
@@ -2762,8 +2806,6 @@ module_init(vchiq_driver_init);
 static void __exit vchiq_driver_exit(void)
 {
 	platform_driver_unregister(&vchiq_driver);
-	unregister_chrdev_region(vchiq_devid, 1);
-	class_destroy(vchiq_class);
 }
 module_exit(vchiq_driver_exit);
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 2/5 staging: vchiq: Move certain declarations to vchiq_arm.h

In reply to Ojaswin Mujoo

Move certain declarations from vchiq_arm.c to vchiq_arm.h to allow code sharing. This will be useful when we eventually separate the vchiq char driver code from platform code, into its own file.

---
 .../interface/vchiq_arm/vchiq_arm.c           | 68 ++---------------
 .../interface/vchiq_arm/vchiq_arm.h           | 73 +++++++++++++++++++
 2 files changed, 79 insertions(+), 62 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +6 -62
index 3a0724fe25ea..3152466086f3 100644
@@ -38,12 +38,6 @@
 #undef MODULE_PARAM_PREFIX
 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
 
-/* Some per-instance constants */
-#define MAX_COMPLETIONS 128
-#define MAX_SERVICES 64
-#define MAX_ELEMENTS 8
-#define MSG_QUEUE_SIZE 128
-
 #define KEEPALIVE_VER 1
 #define KEEPALIVE_VER_MIN KEEPALIVE_VER
 
@@ -51,62 +45,12 @@
 int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
 int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
 
-struct user_service {
-	struct vchiq_service *service;
-	void __user *userdata;
-	struct vchiq_instance *instance;
-	char is_vchi;
-	char dequeue_pending;
-	char close_pending;
-	int message_available_pos;
-	int msg_insert;
-	int msg_remove;
-	struct completion insert_event;
-	struct completion remove_event;
-	struct completion close_event;
-	struct vchiq_header *msg_queue[MSG_QUEUE_SIZE];
-};
-
-struct bulk_waiter_node {
-	struct bulk_waiter bulk_waiter;
-	int pid;
-	struct list_head list;
-};
-
-struct vchiq_instance {
-	struct vchiq_state *state;
-	struct vchiq_completion_data_kernel completions[MAX_COMPLETIONS];
-	int completion_insert;
-	int completion_remove;
-	struct completion insert_event;
-	struct completion remove_event;
-	struct mutex completion_mutex;
-
-	int connected;
-	int closing;
-	int pid;
-	int mark;
-	int use_close_delivered;
-	int trace;
-
-	struct list_head bulk_waiter_list;
-	struct mutex bulk_waiter_list_mutex;
-
-	struct vchiq_debugfs_node debugfs_node;
-};
-
-struct dump_context {
-	char __user *buf;
-	size_t actual;
-	size_t space;
-	loff_t offset;
-};
+DEFINE_SPINLOCK(msg_queue_spinlock);
+struct vchiq_state g_state;
 
 static struct cdev    vchiq_cdev;
 static dev_t          vchiq_devid;
-static struct vchiq_state g_state;
 static struct class  *vchiq_class;
-static DEFINE_SPINLOCK(msg_queue_spinlock);
 static struct platform_device *bcm2835_camera;
 static struct platform_device *bcm2835_audio;
 
@@ -199,7 +143,7 @@ int vchiq_initialise(struct vchiq_instance **instance_out)
 }
 EXPORT_SYMBOL(vchiq_initialise);
 
-static void free_bulk_waiter(struct vchiq_instance *instance)
+void free_bulk_waiter(struct vchiq_instance *instance)
 {
 	struct bulk_waiter_node *waiter, *next;
 
@@ -561,7 +505,7 @@ add_completion(struct vchiq_instance *instance, enum vchiq_reason reason,
 	return VCHIQ_SUCCESS;
 }
 
-static enum vchiq_status
+enum vchiq_status
 service_callback(enum vchiq_reason reason, struct vchiq_header *header,
 		 unsigned int handle, void *bulk_userdata)
 {
@@ -2142,7 +2086,7 @@ vchiq_fops = {
  *
  *	Returns 0 on success else returns the error code.
  */
-static int vchiq_register_chrdev(struct device *parent)
+int vchiq_register_chrdev(struct device *parent)
 {
 	struct device *vchiq_dev;
 	int ret;
@@ -2201,7 +2145,7 @@ static int vchiq_register_chrdev(struct device *parent)
  *	vchiq_deregister_chrdev	- Deregister and cleanup the vchiq char
  *				  driver and device files
  */
-static void vchiq_deregister_chrdev(void)
+void vchiq_deregister_chrdev(void)
 {
 	device_destroy(vchiq_class, vchiq_devid);
 	cdev_del(&vchiq_cdev);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +73 -0

92 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

PATCH v3 3/5 staging: vchiq: Move vchiq char driver to its own file

In reply to Ojaswin Mujoo

Split the initialization code of vchiq char driver and device files from that of vchiq platform. The char driver code now resides in vchiq_dev.c and the platform code resides in the original vchiq_arm.c file.

This commit focuses on separating the code into different files while maintaining the same functionality. It does not completely decouple them as the cdev init code is still called from the platform's vchiq_probe() function.

---
 drivers/staging/vc04_services/Makefile        |    1 +
 .../interface/vchiq_arm/vchiq_arm.c           | 1619 +----------------
 .../interface/vchiq_arm/vchiq_dev.c           | 1440 +++++++++++++++
 3 files changed, 1540 insertions(+), 1520 deletions(-)
 create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c
drivers/staging/vc04_services/Makefile +1 -0
index e21e73ae3cc6..db28be341239 100644
@@ -7,6 +7,7 @@ vchiq-objs := \
    interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
+   interface/vchiq_arm/vchiq_dev.o \
 
 obj-$(CONFIG_SND_BCM2835)		+= bcm2835-audio/
 obj-$(CONFIG_VIDEO_BCM2835)		+= bcm2835-camera/
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +99 -1520

1,680 lines not on this page · raw message

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c new file +1440 -0

1,313 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.25.1

Part of the diff is not shown here. View the raw message.

#11 lore raw

PATCH v3 4/5 staging: vchiq: Make creation of vchiq cdev optional

In reply to Ojaswin Mujoo

Before this commit, vchiq cdev (/dev/vchiq) was always created during platform initialization. Introduce a new Kconfig option CONFIG_VCHIQ_CDEV which determines if the cdev will be created or not.

---
 drivers/staging/vc04_services/Kconfig                  | 10 ++++++++++
 drivers/staging/vc04_services/Makefile                 |  5 ++++-
 .../vc04_services/interface/vchiq_arm/vchiq_arm.h      |  9 +++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
drivers/staging/vc04_services/Kconfig +10 -0
index 4b886293f198..63caa6818d37 100644
@@ -19,6 +19,16 @@ config BCM2835_VCHIQ
 		Defaults to Y when the Broadcom Videocore services
 		are included in the build, N otherwise.
 
+if BCM2835_VCHIQ
+
+config VCHIQ_CDEV
+	bool "VCHIQ Character Driver"
+	help
+		Enable the creation of VCHIQ character driver to help
+		communicate with the Videocore platform.
+
+endif
+
 source "drivers/staging/vc04_services/bcm2835-audio/Kconfig"
 
 source "drivers/staging/vc04_services/bcm2835-camera/Kconfig"
drivers/staging/vc04_services/Makefile +4 -1
index db28be341239..0a04338fc962 100644
@@ -7,7 +7,10 @@ vchiq-objs := \
    interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
-   interface/vchiq_arm/vchiq_dev.o \
+
+ifdef CONFIG_VCHIQ_CDEV
+vchiq-objs += interface/vchiq_arm/vchiq_dev.o
+endif
 
 obj-$(CONFIG_SND_BCM2835)		+= bcm2835-audio/
 obj-$(CONFIG_VIDEO_BCM2835)		+= bcm2835-camera/
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +9 -0
index 2453971b6b78..e8e39a154c74 100644
@@ -174,12 +174,21 @@ vchiq_instance_get_trace(struct vchiq_instance *instance);
 extern void
 vchiq_instance_set_trace(struct vchiq_instance *instance, int trace);
 
+#if IS_ENABLED(CONFIG_VCHIQ_CDEV)
+
 extern void
 vchiq_deregister_chrdev(void);
 
 extern int
 vchiq_register_chrdev(struct device *parent);
 
+#else
+
+static inline void vchiq_deregister_chrdev(void) { }
+static inline int vchiq_register_chrdev(struct device *parent) { return 0; }
+
+#endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */
+
 extern enum vchiq_status
 service_callback(enum vchiq_reason reason, struct vchiq_header *header,
 		 unsigned int handle, void *bulk_userdata);
Signature · 1 line
2.25.1
#13 lore raw

PATCH v3 5/5 staging: vchiq: Combine vchiq platform code into single file

In reply to Ojaswin Mujoo

Combine the vchiq platform initialization code into a single file by merging vchiq_2835_arm.c into vchiq_arm.c

---
 drivers/staging/vc04_services/Makefile        |   1 -
 .../interface/vchiq_arm/vchiq_2835_arm.c      | 564 ------------------
 .../interface/vchiq_arm/vchiq_arm.c           | 549 +++++++++++++++++
 3 files changed, 549 insertions(+), 565 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/Makefile +0 -1
index 0a04338fc962..1fd191e2e2a5 100644
@@ -4,7 +4,6 @@ obj-$(CONFIG_BCM2835_VCHIQ)	+= vchiq.o
 vchiq-objs := \
    interface/vchiq_arm/vchiq_core.o  \
    interface/vchiq_arm/vchiq_arm.o \
-   interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
 
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c deleted +0 -564

564 lines not on this page · raw message

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +549 -0

574 lines not on this page · raw message

Signature · 1 line
2.25.1
#14 lore raw

Re: [PATCH v3 5/5] staging: vchiq: Combine vchiq platform code into single file

Thank you for the patch! Perhaps something to improve:

Hi Ojaswin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on staging/staging-testing]
[also build test WARNING on next-20210701]
[cannot apply to v5.13]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ojaswin-Mujoo/vchiq-Patch-to-separate-platform-and-cdev-code/20210705-000124
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 77ad1f0e99bd00af024e650b862cfda3137af660
config: x86_64-randconfig-a004-20210704 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 89c1c64cc3170a05a881bb9954feafc3edca6704)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/6e25765ec91ba341b2c85fdd00da9ef4c2ed737c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ojaswin-Mujoo/vchiq-Patch-to-separate-platform-and-cdev-code/20210705-000124 git checkout 6e25765ec91ba341b2c85fdd00da9ef4c2ed737c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c:378:16: warning: result of comparison of constant 419244183493398898 with expression of type 'unsigned int' is always false [-Wtautological-constant-out-of-range-compare]

if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

vim +378 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

345
346 /* There is a potential problem with partial cache lines (pages?)
347 * at the ends of the block when reading. If the CPU accessed anything in
348 * the same line (page?) then it may have pulled old data into the cache,
349 * obscuring the new data underneath. We can solve this by transferring the
350 * partial cache lines separately, and allowing the ARM to copy into the
351 * cached area.
352 */
353
354 static struct vchiq_pagelist_info *
355 create_pagelist(char *buf, char __user *ubuf,
356 size_t count, unsigned short type)
357 {
358 struct pagelist *pagelist;
359 struct vchiq_pagelist_info *pagelistinfo;
360 struct page **pages;
361 u32 *addrs;
362 unsigned int num_pages, offset, i, k;
363 int actual_pages;
364 size_t pagelist_size;
365 struct scatterlist *scatterlist, *sg;
366 int dma_buffers;
367 dma_addr_t dma_addr;
368
369 if (count >= INT_MAX - PAGE_SIZE)
370 return NULL;
371
372 if (buf)
373 offset = (uintptr_t)buf & (PAGE_SIZE - 1);
374 else
375 offset = (uintptr_t)ubuf & (PAGE_SIZE - 1);
376 num_pages = DIV_ROUND_UP(count + offset, PAGE_SIZE);
377

 > 378		if (num_pages > (SIZE_MAX - sizeof(struct pagelist) -
   379				 sizeof(struct vchiq_pagelist_info)) /
   380				(sizeof(u32) + sizeof(pages[0]) +
   381				 sizeof(struct scatterlist)))
   382			return NULL;
   383	
   384		pagelist_size = sizeof(struct pagelist) +
   385				(num_pages * sizeof(u32)) +
   386				(num_pages * sizeof(pages[0]) +
   387				(num_pages * sizeof(struct scatterlist))) +
   388				sizeof(struct vchiq_pagelist_info);
   389	
   390		/* Allocate enough storage to hold the page pointers and the page
   391		 * list
   392		 */
   393		pagelist = dma_alloc_coherent(g_dev, pagelist_size, &dma_addr,
   394					      GFP_KERNEL);
   395	
   396		vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
   397	
   398		if (!pagelist)
   399			return NULL;
   400	
   401		addrs		= pagelist->addrs;
   402		pages		= (struct page **)(addrs + num_pages);
   403		scatterlist	= (struct scatterlist *)(pages + num_pages);
   404		pagelistinfo	= (struct vchiq_pagelist_info *)
   405				  (scatterlist + num_pages);
   406	
   407		pagelist->length = count;
   408		pagelist->type = type;
   409		pagelist->offset = offset;
   410	
   411		/* Populate the fields of the pagelistinfo structure */
   412		pagelistinfo->pagelist = pagelist;
   413		pagelistinfo->pagelist_buffer_size = pagelist_size;
   414		pagelistinfo->dma_addr = dma_addr;
   415		pagelistinfo->dma_dir =  (type == PAGELIST_WRITE) ?
   416					  DMA_TO_DEVICE : DMA_FROM_DEVICE;
   417		pagelistinfo->num_pages = num_pages;
   418		pagelistinfo->pages_need_release = 0;
   419		pagelistinfo->pages = pages;
   420		pagelistinfo->scatterlist = scatterlist;
   421		pagelistinfo->scatterlist_mapped = 0;
   422	
   423		if (buf) {
   424			unsigned long length = count;
   425			unsigned int off = offset;
   426	
   427			for (actual_pages = 0; actual_pages < num_pages;
   428			     actual_pages++) {
   429				struct page *pg =
   430					vmalloc_to_page((buf +
   431							 (actual_pages * PAGE_SIZE)));
   432				size_t bytes = PAGE_SIZE - off;
   433	
   434				if (!pg) {
   435					cleanup_pagelistinfo(pagelistinfo);
   436					return NULL;
   437				}
   438	
   439				if (bytes > length)
   440					bytes = length;
   441				pages[actual_pages] = pg;
   442				length -= bytes;
   443				off = 0;
   444			}
   445			/* do not try and release vmalloc pages */
   446		} else {
   447			actual_pages = pin_user_pages_fast(
   448						  (unsigned long)ubuf & PAGE_MASK,
   449						  num_pages,
   450						  type == PAGELIST_READ,
   451						  pages);

452
453 if (actual_pages != num_pages) {
454 vchiq_log_info(vchiq_arm_log_level,
455 "%s - only %d/%d pages locked",
456 __func__, actual_pages, num_pages);
457
458 /* This is probably due to the process being killed */
459 if (actual_pages > 0)
460 unpin_user_pages(pages, actual_pages);
461 cleanup_pagelistinfo(pagelistinfo);
462 return NULL;
463 }
464 /* release user pages */
465 pagelistinfo->pages_need_release = 1;
466 }
467
468 /*
469 * Initialize the scatterlist so that the magic cookie
470 * is filled if debugging is enabled
471 */
472 sg_init_table(scatterlist, num_pages);
473 /* Now set the pages for each scatterlist */
474 for (i = 0; i < num_pages; i++) {
475 unsigned int len = PAGE_SIZE - offset;
476
477 if (len > count)
478 len = count;
479 sg_set_page(scatterlist + i, pages[i], len, offset);
480 offset = 0;
481 count -= len;
482 }
483
484 dma_buffers = dma_map_sg(g_dev,
485 scatterlist,
486 num_pages,
487 pagelistinfo->dma_dir);
488
489 if (dma_buffers == 0) {
490 cleanup_pagelistinfo(pagelistinfo);
491 return NULL;
492 }
493
494 pagelistinfo->scatterlist_mapped = 1;
495
496 /* Combine adjacent blocks for performance */
497 k = 0;
498 for_each_sg(scatterlist, sg, dma_buffers, i) {
499 u32 len = sg_dma_len(sg);
500 u32 addr = sg_dma_address(sg);
501
502 /* Note: addrs is the address + page_count - 1
503 * The firmware expects blocks after the first to be page-
504 * aligned and a multiple of the page size
505 */
506 WARN_ON(len == 0);
507 WARN_ON(i && (i != (dma_buffers - 1)) && (len & ~PAGE_MASK));
508 WARN_ON(i && (addr & ~PAGE_MASK));
509 if (k > 0 &&
510 ((addrs[k - 1] & PAGE_MASK) +
511 (((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT))
512 == (addr & PAGE_MASK))
513 addrs[k - 1] += ((len + PAGE_SIZE - 1) >> PAGE_SHIFT);
514 else
515 addrs[k++] = (addr & PAGE_MASK) |
516 (((len + PAGE_SIZE - 1) >> PAGE_SHIFT) - 1);
517 }
518
519 /* Partial cache lines (fragments) require special measures */
520 if ((type == PAGELIST_READ) &&
521 ((pagelist->offset & (g_cache_line_size - 1)) ||
522 ((pagelist->offset + pagelist->length) &
523 (g_cache_line_size - 1)))) {
524 char *fragments;
525
526 if (down_interruptible(&g_free_fragments_sema)) {
527 cleanup_pagelistinfo(pagelistinfo);
528 return NULL;
529 }
530
531 WARN_ON(!g_free_fragments);
532
533 down(&g_free_fragments_mutex);
534 fragments = g_free_fragments;
535 WARN_ON(!fragments);
536 g_free_fragments = *(char **) g_free_fragments;
537 up(&g_free_fragments_mutex);
538 pagelist->type = PAGELIST_READ_WITH_FRAGMENTS +
539 (fragments - g_fragments_base) / g_fragments_size;
540 }
541
542 return pagelistinfo;
543 }
544

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

build bot
#6 lore raw

Re: [PATCH v3 3/5] staging: vchiq: Move vchiq char driver to its own file

In reply to Ojaswin Mujoo
CC: kbuild-all(a)lists.01.org In-Reply-To: <3b7178086322f774772d95141764ed99d0698139.1625401927.git.ojaswin98@gmail.com> References…

CC: kbuild-all(a)lists.01.org
In-Reply-To: <3b7178086322f774772d95141764ed99d0698139.1625401927.git.ojaswin98@gmail.com>
References: <3b7178086322f774772d95141764ed99d0698139.1625401927.git.ojaswin98@gmail.com>
TO: Ojaswin Mujoo <[email protected]>
TO: nsaenz(a)kernel.org
CC: gregkh(a)linuxfoundation.org
CC: stefan.wahren(a)i2se.com
CC: arnd(a)arndb.de
CC: dan.carpenter(a)oracle.com
CC: phil(a)raspberrypi.com
CC: bcm-kernel-feedback-list(a)broadcom.com
CC: linux-arm-kernel(a)lists.infradead.org
CC: linux-staging(a)lists.linux.dev
CC: linux-kernel(a)vger.kernel.org

Hi Ojaswin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on staging/staging-testing]
[also build test WARNING on next-20210701]
[cannot apply to v5.13]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ojaswin-Mujoo/vchiq-Patch-to-separate-platform-and-cdev-code/20210705-000124
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 77ad1f0e99bd00af024e650b862cfda3137af660

:::::: branch date: 16 hours ago
:::::: commit date: 16 hours ago
config: i386-randconfig-m021-20210705 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c:1235 vchiq_release() warn: argument 3 to %lx specifier is cast from pointer

vim +1235 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1226  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1227  static int vchiq_release(struct inode *inode, struct file *file)
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1228  {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1229  	struct vchiq_instance *instance = file->private_data;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1230  	struct vchiq_state *state = vchiq_get_state();
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1231  	struct vchiq_service *service;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1232  	int ret = 0;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1233  	int i;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1234  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 @1235  	vchiq_log_info(vchiq_arm_log_level, "%s: instance=%lx", __func__,
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1236  		       (unsigned long)instance);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1237  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1238  	if (!state) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1239  		ret = -EPERM;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1240  		goto out;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1241  	}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1242  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1243  	/* Ensure videocore is awake to allow termination. */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1244  	vchiq_use_internal(instance->state, NULL, USE_TYPE_VCHIQ);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1245  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1246  	mutex_lock(&instance->completion_mutex);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1247  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1248  	/* Wake the completion thread and ask it to exit */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1249  	instance->closing = 1;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1250  	complete(&instance->insert_event);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1251  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1252  	mutex_unlock(&instance->completion_mutex);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1253  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1254  	/* Wake the slot handler if the completion queue is full. */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1255  	complete(&instance->remove_event);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1256  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1257  	/* Mark all services for termination... */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1258  	i = 0;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1259  	while ((service = next_service_by_instance(state, instance, &i))) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1260  		struct user_service *user_service = service->base.userdata;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1261  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1262  		/* Wake the slot handler if the msg queue is full. */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1263  		complete(&user_service->remove_event);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1264  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1265  		vchiq_terminate_service_internal(service);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1266  		vchiq_service_put(service);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1267  	}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1268  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1269  	/* ...and wait for them to die */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1270  	i = 0;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1271  	while ((service = next_service_by_instance(state, instance, &i))) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1272  		struct user_service *user_service = service->base.userdata;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1273  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1274  		wait_for_completion(&service->remove_event);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1275  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1276  		if (WARN_ON(service->srvstate != VCHIQ_SRVSTATE_FREE)) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1277  			vchiq_service_put(service);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1278  			break;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1279  		}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1280  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1281  		spin_lock(&msg_queue_spinlock);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1282  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1283  		while (user_service->msg_remove != user_service->msg_insert) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1284  			struct vchiq_header *header;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1285  			int m = user_service->msg_remove & (MSG_QUEUE_SIZE - 1);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1286  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1287  			header = user_service->msg_queue[m];
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1288  			user_service->msg_remove++;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1289  			spin_unlock(&msg_queue_spinlock);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1290  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1291  			if (header)
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1292  				vchiq_release_message(service->handle, header);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1293  			spin_lock(&msg_queue_spinlock);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1294  		}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1295  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1296  		spin_unlock(&msg_queue_spinlock);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1297  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1298  		vchiq_service_put(service);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1299  	}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1300  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1301  	/* Release any closed services */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1302  	while (instance->completion_remove != instance->completion_insert) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1303  		struct vchiq_completion_data_kernel *completion;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1304  		struct vchiq_service *service;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1305  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1306  		completion = &instance->completions[
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1307  			instance->completion_remove & (MAX_COMPLETIONS - 1)];
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1308  		service = completion->service_userdata;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1309  		if (completion->reason == VCHIQ_SERVICE_CLOSED) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1310  			struct user_service *user_service =
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1311  							service->base.userdata;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1312  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1313  			/* Wake any blocked user-thread */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1314  			if (instance->use_close_delivered)
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1315  				complete(&user_service->close_event);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1316  			vchiq_service_put(service);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1317  		}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1318  		instance->completion_remove++;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1319  	}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1320  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1321  	/* Release the PEER service count. */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1322  	vchiq_release_internal(instance->state, NULL);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1323  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1324  	free_bulk_waiter(instance);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1325  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1326  	vchiq_debugfs_remove_instance(instance);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1327  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1328  	kfree(instance);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1329  	file->private_data = NULL;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1330  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1331  out:
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1332  	return ret;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1333  }
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1334  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#7 lore raw

Re: [PATCH v3 3/5] staging: vchiq: Move vchiq char driver to its own file

Hello Dan,

Quoted 24 lines · Dan Carpenter

Hi Ojaswin,

url:    https://github.com/0day-ci/linux/commits/Ojaswin-Mujoo/vchiq-Patch-to-separate-platform-and-cdev-code/20210705-000124
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 77ad1f0e99bd00af024e650b862cfda3137af660
config: i386-randconfig-m021-20210705 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c:1235 vchiq_release() warn: argument 3 to %lx specifier is cast from pointer

vim +1235 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1227  static int vchiq_release(struct inode *inode, struct file *file)
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1228  {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1229  	struct vchiq_instance *instance = file->private_data;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1230  	struct vchiq_state *state = vchiq_get_state();
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1231  	struct vchiq_service *service;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1232  	int ret = 0;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1233  	int i;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1234  
Quoted 5 lines

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 @1235 vchiq_log_info(vchiq_arm_log_level, "%s: instance=%lx", __func__,
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 1236 (unsigned long)instance);

This should eventually be converted to %p so it doesn't defeat KASLR. (Not that we really care on raspberry pi, I think?)

Yes, that does seem right, however, this patchset only moves the code from vchiq_arm.c to vchiq_dev.c and I've not really touched any of the existing code itself (Except moving it to a new file which is why it shows up in the patch).

Hence, I'm not sure if this fix is in scope of this patchset. (I also have a similar warning by kernel test robot here [1] which and I'm not sure if I need to act upon). Maybe we can look at this in a separate patch?

[1] https://lkml.org/lkml/2021/7/4/138

Quoted 11 lines
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1237  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1238  	if (!state) {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1239  		ret = -EPERM;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1240  		goto out;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1241  	}
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1242  
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1243  	/* Ensure videocore is awake to allow termination. */
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1244  	vchiq_use_internal(instance->state, NULL, USE_TYPE_VCHIQ);
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1245  
Quoted 4 lines

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

Thank you for looking into this,
Ojaswin

#8 lore raw

Re: [PATCH v3 3/5] staging: vchiq: Move vchiq char driver to its own file

Quoted 37 lines · Ojaswin Mujoo

Hello Dan,

Quoted 24 lines · Dan Carpenter

Hi Ojaswin,

url:    https://github.com/0day-ci/linux/commits/Ojaswin-Mujoo/vchiq-Patch-to-separate-platform-and-cdev-code/20210705-000124 
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git  77ad1f0e99bd00af024e650b862cfda3137af660
config: i386-randconfig-m021-20210705 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c:1235 vchiq_release() warn: argument 3 to %lx specifier is cast from pointer

vim +1235 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1227  static int vchiq_release(struct inode *inode, struct file *file)
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1228  {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1229  	struct vchiq_instance *instance = file->private_data;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1230  	struct vchiq_state *state = vchiq_get_state();
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1231  	struct vchiq_service *service;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1232  	int ret = 0;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1233  	int i;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1234  
Quoted 5 lines

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 @1235 vchiq_log_info(vchiq_arm_log_level, "%s: instance=%lx", __func__,
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 1236 (unsigned long)instance);

This should eventually be converted to %p so it doesn't defeat KASLR. (Not that we really care on raspberry pi, I think?)

Yes, that does seem right, however, this patchset only moves the code from vchiq_arm.c to vchiq_dev.c and I've not really touched any of the existing code itself (Except moving it to a new file which is why it shows up in the patch).

Quoted 4 lines

Hence, I'm not sure if this fix is in scope of this patchset. (I also have a similar warning by kernel test robot here [1] which and I'm not sure if I need to act upon). Maybe we can look at this in a separate patch?

Yes. Correct. Don't mix this into the patch, do it "eventually". Or you don't have to do it at all since it wasn't something you introduced. Someone will check the driver for Smatch warnings before it can be moved out of staging.

(I just forwarded the kbuild bot messages for informational purposes only).

regards,
dan carpenter

#9 lore raw

Re: [PATCH v3 3/5] staging: vchiq: Move vchiq char driver to its own file

Quoted 43 lines · Dan Carpenter
Quoted 37 lines · Ojaswin Mujoo

Hello Dan,

Quoted 24 lines · Dan Carpenter

Hi Ojaswin,

url:    https://github.com/0day-ci/linux/commits/Ojaswin-Mujoo/vchiq-Patch-to-separate-platform-and-cdev-code/20210705-000124 
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git  77ad1f0e99bd00af024e650b862cfda3137af660
config: i386-randconfig-m021-20210705 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c:1235 vchiq_release() warn: argument 3 to %lx specifier is cast from pointer

vim +1235 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1227  static int vchiq_release(struct inode *inode, struct file *file)
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1228  {
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1229  	struct vchiq_instance *instance = file->private_data;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1230  	struct vchiq_state *state = vchiq_get_state();
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1231  	struct vchiq_service *service;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1232  	int ret = 0;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1233  	int i;
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04  1234  
Quoted 5 lines

62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 @1235 vchiq_log_info(vchiq_arm_log_level, "%s: instance=%lx", __func__,
62b5eb4fdf3f5f Ojaswin Mujoo 2021-07-04 1236 (unsigned long)instance);

This should eventually be converted to %p so it doesn't defeat KASLR. (Not that we really care on raspberry pi, I think?)

Yes, that does seem right, however, this patchset only moves the code from vchiq_arm.c to vchiq_dev.c and I've not really touched any of the existing code itself (Except moving it to a new file which is why it shows up in the patch).

Quoted 4 lines

Hence, I'm not sure if this fix is in scope of this patchset. (I also have a similar warning by kernel test robot here [1] which and I'm not sure if I need to act upon). Maybe we can look at this in a separate patch?

Quoted 7 lines

Yes. Correct. Don't mix this into the patch, do it "eventually". Or you don't have to do it at all since it wasn't something you introduced. Someone will check the driver for Smatch warnings before it can be moved out of staging.

(I just forwarded the kbuild bot messages for informational purposes only).

Ahh okay, got it.

Thanks,
Ojaswin

Quoted 4 lines

regards,
dan carpenter

#19 lore raw
In reply to Ojaswin Mujoo

Hi Ojaswin,

Am 04.07.21 um 17:56 schrieb Ojaswin Mujoo:

Quoted 50 lines

Hello,

This patchset adderesses the TODO item number 10 specified at:

drivers/staging/vc04-services/interface/TODO

For reference, the task is:

10) Reorganize file structure: Move char driver to it's own file and join both platform files

The cdev is defined alongside with the platform code in vchiq_arm.c. It would be nice to completely decouple it from the actual core code. For instance to be able to use bcm2835-audio without having /dev/vchiq created. One could argue it's better for security reasons or general cleanliness. It could even be interesting to create two different kernel modules, something the likes of vchiq-core.ko and vchiq-dev.ko. This would also ease the upstreaming process.

A summary of the patches is as follows:

- Patch 1: Move cdev init code into a function
- Patch 2: Shift some devlarations from vchiq_arm.c to vchiq_arm.h for sharing
- Patch 3: Move vchiq cdev init code from vchiq_arm.c into vchiq_dev.c
- Patch 4: Decouple cdev code by defining a Kconfig entry to allow optional compilation of it.
- Patch 5: Merge code in vchiq_2835_arm.c to vchiq_arm.c

(More details can be found in the commit messages)

Changes since v2 [1]:

* In Patch 1, as suggested, I have added error handling code back to ensure the driver exits when there is an error in creating vchiq cdev

* I have built this patch against the right kernel (gregkh/staging, staging-next branch) to avoid introducing any unwanted inconsistencies like whitespace changes

I have tested the patch using vchiq_test utility on RPi 3B+.

Additionally, I had a small question regarding the next steps here (quoting my cover letter from v2):

This question is more related to the next set of patches I'm planning to submit. So the last thing left in this TODO is to completely decouple vchiq platform and cdev code into 2 separate modules and I am planning to do that in a different patchset.

Quoted 5 lines

The approach I have in mind is to start by using EXPORT_SYMBOL to export all the functions (and accessor functions for variables like g_state) that would be required for cdev init. Majority of these would be exported from vchiq_arm.c and vchiq_core.c, and will then be used in vchiq-dev.ko. Is this the right way to approach this?

i'm back from vacation and had some time for review. IMHO the patch series is fine (except some nits in patch 5) regarding the task in the TODO list. Making cdev a separate module is a cool idea, but it's not really necessary for moving this driver out of staging. There are more important things to do.

Thank you

Regards
Stefan

Quoted 26 lines

Thank you in advance for the help. Please let me know if any changes/ additional info is required.

Regards,
Ojaswin

[1] v2: https://lkml.org/lkml/2021/6/20/63

Ojaswin Mujoo (5):
staging: vchiq: Refactor vchiq cdev code
staging: vchiq: Move certain declarations to vchiq_arm.h
staging: vchiq: Move vchiq char driver to its own file
staging: vchiq: Make creation of vchiq cdev optional
staging: vchiq: Combine vchiq platform code into single file

 drivers/staging/vc04_services/Kconfig         |   10 +
 drivers/staging/vc04_services/Makefile        |    5 +-
 .../interface/vchiq_arm/vchiq_2835_arm.c      |  564 ----
 .../interface/vchiq_arm/vchiq_arm.c           | 2344 +++++------------
 .../interface/vchiq_arm/vchiq_arm.h           |   82 +
 .../interface/vchiq_arm/vchiq_dev.c           | 1440 ++++++++++
 6 files changed, 2265 insertions(+), 2180 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
 create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] staging: vchiq: Refactor vchiq cdev code

In reply to Ojaswin Mujoo

Am 04.07.21 um 17:57 schrieb Ojaswin Mujoo:

Quoted 6 lines

Move the vchiq cdev initialization code to its own function for better code organization. Call the initialization function during probe, thus shifting the whole cdev creation logic (which was earlier split in vchiq_probe() and vchiq_driver_init()) to vchiq_probe().

Reviewed-by on v3 2/5
#4 lore raw

Re: [PATCH v3 2/5] staging: vchiq: Move certain declarations to vchiq_arm.h

In reply to Ojaswin Mujoo

Am 04.07.21 um 17:57 schrieb Ojaswin Mujoo:

Quoted 5 lines

Move certain declarations from vchiq_arm.c to vchiq_arm.h to allow code sharing. This will be useful when we eventually separate the vchiq char driver code from platform code, into its own file.

Reviewed-by on v3 3/5
#10 lore raw

Re: [PATCH v3 3/5] staging: vchiq: Move vchiq char driver to its own file

In reply to Ojaswin Mujoo

Am 04.07.21 um 17:58 schrieb Ojaswin Mujoo:

Quoted 10 lines

Split the initialization code of vchiq char driver and device files from that of vchiq platform. The char driver code now resides in vchiq_dev.c and the platform code resides in the original vchiq_arm.c file.

This commit focuses on separating the code into different files while maintaining the same functionality. It does not completely decouple them as the cdev init code is still called from the platform's vchiq_probe() function.

Reviewed-by on v3 4/5
#12 lore raw

Re: [PATCH v3 4/5] staging: vchiq: Make creation of vchiq cdev optional

In reply to Ojaswin Mujoo

Am 04.07.21 um 17:59 schrieb Ojaswin Mujoo:

Quoted 5 lines

Before this commit, vchiq cdev (/dev/vchiq) was always created during platform initialization. Introduce a new Kconfig option CONFIG_VCHIQ_CDEV which determines if the cdev will be created or not.

#15 lore raw

Re: [PATCH v3 5/5] staging: vchiq: Combine vchiq platform code into single file

In reply to Ojaswin Mujoo

Am 04.07.21 um 17:59 schrieb Ojaswin Mujoo:

Quoted 23 lines

Combine the vchiq platform initialization code into a single file by merging vchiq_2835_arm.c into vchiq_arm.c

---
 drivers/staging/vc04_services/Makefile        |   1 -
 .../interface/vchiq_arm/vchiq_2835_arm.c      | 564 ------------------
 .../interface/vchiq_arm/vchiq_arm.c           | 549 +++++++++++++++++
 3 files changed, 549 insertions(+), 565 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/Makefile +0 -1
index 0a04338fc962..1fd191e2e2a5 100644
@@ -4,7 +4,6 @@ obj-$(CONFIG_BCM2835_VCHIQ)	+= vchiq.o
 vchiq-objs := \
    interface/vchiq_arm/vchiq_core.o  \
    interface/vchiq_arm/vchiq_arm.o \
-   interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
 

...

Quoted 77 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +53 -0
index 0f2de571eba7..9057d01ffd48 100644
@@ -25,15 +25,32 @@
 #include <linux/rcupdate.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 #include <soc/bcm2835/raspberrypi-firmware.h>
 
 #include "vchiq_core.h"
 #include "vchiq_ioctl.h"
 #include "vchiq_arm.h"
 #include "vchiq_debugfs.h"
+#include "vchiq_connected.h"
+#include "vchiq_pagelist.h"
 
 #define DEVICE_NAME "vchiq"
 
+#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
+
+#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
+
+#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
+#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX  1
+
+#define BELL0	0x00
+#define BELL2	0x08
+
+#define ARM_DS_ACTIVE	BIT(2)
+
 /* Override the default prefix, which would be vchiq_arm (from the filename) */
 #undef MODULE_PARAM_PREFIX
 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
@@ -59,10 +76,542 @@ static struct vchiq_drvdata bcm2836_drvdata = {
 	.cache_line_size = 64,
 };
 
+struct vchiq_2835_state {
+	int inited;
+	struct vchiq_arm_state arm_state;
+};
+
+struct vchiq_pagelist_info {
+	struct pagelist *pagelist;
+	size_t pagelist_buffer_size;
+	dma_addr_t dma_addr;
+	enum dma_data_direction dma_dir;
+	unsigned int num_pages;
+	unsigned int pages_need_release;
+	struct page **pages;
+	struct scatterlist *scatterlist;
+	unsigned int scatterlist_mapped;
+};
+
+static void __iomem *g_regs;
+/* This value is the size of the L2 cache lines as understood by the
+ * VPU firmware, which determines the required alignment of the
+ * offsets/sizes in pagelists.
+ *
+ * Modern VPU firmware looks for a DT "cache-line-size" property in
+ * the VCHIQ node and will overwrite it with the actual L2 cache size,
+ * which the kernel must then respect.  That property was rejected
+ * upstream, so we have to use the VPU firmware's compatibility value
+ * of 32.
+ */
+static unsigned int g_cache_line_size = 32;
+static unsigned int g_fragments_size;
+static char *g_fragments_base;
+static char *g_free_fragments;
+static struct semaphore g_free_fragments_sema;
+static struct device *g_dev;
+
+static DEFINE_SEMAPHORE(g_free_fragments_mutex);

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static struct vchiq_drvdata bcm2836_drvdata = { · line 124

Quoted 10 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +10 -0
+
+static irqreturn_t
+vchiq_doorbell_irq(int irq, void *dev_id);
+
+static struct vchiq_pagelist_info *
+create_pagelist(char *buf, char __user *ubuf, size_t count, unsigned short type);
+
+static void
+free_pagelist(struct vchiq_pagelist_info *pagelistinfo,
+	      int actual);

please no forward declarations of these 3 functions. Put them into the right order instead ...

Since this patch is independent from the other ones from the series, maybe Greg can merg the rest of the series.

#16 lore raw

Re: [PATCH v3 5/5] staging: vchiq: Combine vchiq platform code into single file

Quoted 116 lines · Stefan Wahren

Am 04.07.21 um 17:59 schrieb Ojaswin Mujoo:

Quoted 23 lines

Combine the vchiq platform initialization code into a single file by merging vchiq_2835_arm.c into vchiq_arm.c

---
 drivers/staging/vc04_services/Makefile        |   1 -
 .../interface/vchiq_arm/vchiq_2835_arm.c      | 564 ------------------
 .../interface/vchiq_arm/vchiq_arm.c           | 549 +++++++++++++++++
 3 files changed, 549 insertions(+), 565 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/Makefile +0 -1
index 0a04338fc962..1fd191e2e2a5 100644
@@ -4,7 +4,6 @@ obj-$(CONFIG_BCM2835_VCHIQ)	+= vchiq.o
 vchiq-objs := \
    interface/vchiq_arm/vchiq_core.o  \
    interface/vchiq_arm/vchiq_arm.o \
-   interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
 

...

Quoted 77 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +53 -0
index 0f2de571eba7..9057d01ffd48 100644
@@ -25,15 +25,32 @@
 #include <linux/rcupdate.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 #include <soc/bcm2835/raspberrypi-firmware.h>
 
 #include "vchiq_core.h"
 #include "vchiq_ioctl.h"
 #include "vchiq_arm.h"
 #include "vchiq_debugfs.h"
+#include "vchiq_connected.h"
+#include "vchiq_pagelist.h"
 
 #define DEVICE_NAME "vchiq"
 
+#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
+
+#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
+
+#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
+#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX  1
+
+#define BELL0	0x00
+#define BELL2	0x08
+
+#define ARM_DS_ACTIVE	BIT(2)
+
 /* Override the default prefix, which would be vchiq_arm (from the filename) */
 #undef MODULE_PARAM_PREFIX
 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
@@ -59,10 +76,542 @@ static struct vchiq_drvdata bcm2836_drvdata = {
 	.cache_line_size = 64,
 };
 
+struct vchiq_2835_state {
+	int inited;
+	struct vchiq_arm_state arm_state;
+};
+
+struct vchiq_pagelist_info {
+	struct pagelist *pagelist;
+	size_t pagelist_buffer_size;
+	dma_addr_t dma_addr;
+	enum dma_data_direction dma_dir;
+	unsigned int num_pages;
+	unsigned int pages_need_release;
+	struct page **pages;
+	struct scatterlist *scatterlist;
+	unsigned int scatterlist_mapped;
+};
+
+static void __iomem *g_regs;
+/* This value is the size of the L2 cache lines as understood by the
+ * VPU firmware, which determines the required alignment of the
+ * offsets/sizes in pagelists.
+ *
+ * Modern VPU firmware looks for a DT "cache-line-size" property in
+ * the VCHIQ node and will overwrite it with the actual L2 cache size,
+ * which the kernel must then respect.  That property was rejected
+ * upstream, so we have to use the VPU firmware's compatibility value
+ * of 32.
+ */
+static unsigned int g_cache_line_size = 32;
+static unsigned int g_fragments_size;
+static char *g_fragments_base;
+static char *g_free_fragments;
+static struct semaphore g_free_fragments_sema;
+static struct device *g_dev;
+
+static DEFINE_SEMAPHORE(g_free_fragments_mutex);

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static struct vchiq_drvdata bcm2836_drvdata = { · line 124

Quoted 10 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +10 -0
+
+static irqreturn_t
+vchiq_doorbell_irq(int irq, void *dev_id);
+
+static struct vchiq_pagelist_info *
+create_pagelist(char *buf, char __user *ubuf, size_t count, unsigned short type);
+
+static void
+free_pagelist(struct vchiq_pagelist_info *pagelistinfo,
+	      int actual);

please no forward declarations of these 3 functions. Put them into the right order instead ...

Quoted 5 lines

Since this patch is independent from the other ones from the series, maybe Greg can merg the rest of the series.

Hello Stefan,

Thanks for the review. As for the forward declerations, sure I can fix these 3 functions and send an independent patch for this.

Regards,
Ojaswin

maintainer
#17 lore raw

Re: [PATCH v3 5/5] staging: vchiq: Combine vchiq platform code into single file

Quoted 123 lines · Ojaswin Mujoo
Quoted 116 lines · Stefan Wahren

Am 04.07.21 um 17:59 schrieb Ojaswin Mujoo:

Quoted 23 lines

Combine the vchiq platform initialization code into a single file by merging vchiq_2835_arm.c into vchiq_arm.c

---
 drivers/staging/vc04_services/Makefile        |   1 -
 .../interface/vchiq_arm/vchiq_2835_arm.c      | 564 ------------------
 .../interface/vchiq_arm/vchiq_arm.c           | 549 +++++++++++++++++
 3 files changed, 549 insertions(+), 565 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/Makefile +0 -1
index 0a04338fc962..1fd191e2e2a5 100644
@@ -4,7 +4,6 @@ obj-$(CONFIG_BCM2835_VCHIQ)	+= vchiq.o
 vchiq-objs := \
    interface/vchiq_arm/vchiq_core.o  \
    interface/vchiq_arm/vchiq_arm.o \
-   interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
 

...

Quoted 77 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +53 -0
index 0f2de571eba7..9057d01ffd48 100644
@@ -25,15 +25,32 @@
 #include <linux/rcupdate.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 #include <soc/bcm2835/raspberrypi-firmware.h>
 
 #include "vchiq_core.h"
 #include "vchiq_ioctl.h"
 #include "vchiq_arm.h"
 #include "vchiq_debugfs.h"
+#include "vchiq_connected.h"
+#include "vchiq_pagelist.h"
 
 #define DEVICE_NAME "vchiq"
 
+#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
+
+#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
+
+#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
+#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX  1
+
+#define BELL0	0x00
+#define BELL2	0x08
+
+#define ARM_DS_ACTIVE	BIT(2)
+
 /* Override the default prefix, which would be vchiq_arm (from the filename) */
 #undef MODULE_PARAM_PREFIX
 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
@@ -59,10 +76,542 @@ static struct vchiq_drvdata bcm2836_drvdata = {
 	.cache_line_size = 64,
 };
 
+struct vchiq_2835_state {
+	int inited;
+	struct vchiq_arm_state arm_state;
+};
+
+struct vchiq_pagelist_info {
+	struct pagelist *pagelist;
+	size_t pagelist_buffer_size;
+	dma_addr_t dma_addr;
+	enum dma_data_direction dma_dir;
+	unsigned int num_pages;
+	unsigned int pages_need_release;
+	struct page **pages;
+	struct scatterlist *scatterlist;
+	unsigned int scatterlist_mapped;
+};
+
+static void __iomem *g_regs;
+/* This value is the size of the L2 cache lines as understood by the
+ * VPU firmware, which determines the required alignment of the
+ * offsets/sizes in pagelists.
+ *
+ * Modern VPU firmware looks for a DT "cache-line-size" property in
+ * the VCHIQ node and will overwrite it with the actual L2 cache size,
+ * which the kernel must then respect.  That property was rejected
+ * upstream, so we have to use the VPU firmware's compatibility value
+ * of 32.
+ */
+static unsigned int g_cache_line_size = 32;
+static unsigned int g_fragments_size;
+static char *g_fragments_base;
+static char *g_free_fragments;
+static struct semaphore g_free_fragments_sema;
+static struct device *g_dev;
+
+static DEFINE_SEMAPHORE(g_free_fragments_mutex);

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static struct vchiq_drvdata bcm2836_drvdata = { · line 124

Quoted 10 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +10 -0
+
+static irqreturn_t
+vchiq_doorbell_irq(int irq, void *dev_id);
+
+static struct vchiq_pagelist_info *
+create_pagelist(char *buf, char __user *ubuf, size_t count, unsigned short type);
+
+static void
+free_pagelist(struct vchiq_pagelist_info *pagelistinfo,
+	      int actual);

please no forward declarations of these 3 functions. Put them into the right order instead ...

Quoted 5 lines

Since this patch is independent from the other ones from the series, maybe Greg can merg the rest of the series.

Quoted 4 lines

Hello Stefan,

Thanks for the review. As for the forward declerations, sure I can fix these 3 functions and send an independent patch for this.

Please fix up and resend the whole series properly so that I can apply them that way.

thanks,

greg k-h

#18 lore raw

Re: [PATCH v3 5/5] staging: vchiq: Combine vchiq platform code into single file

Quoted 129 lines · Greg KH
Quoted 123 lines · Ojaswin Mujoo
Quoted 116 lines · Stefan Wahren

Am 04.07.21 um 17:59 schrieb Ojaswin Mujoo:

Quoted 23 lines

Combine the vchiq platform initialization code into a single file by merging vchiq_2835_arm.c into vchiq_arm.c

---
 drivers/staging/vc04_services/Makefile        |   1 -
 .../interface/vchiq_arm/vchiq_2835_arm.c      | 564 ------------------
 .../interface/vchiq_arm/vchiq_arm.c           | 549 +++++++++++++++++
 3 files changed, 549 insertions(+), 565 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/Makefile +0 -1
index 0a04338fc962..1fd191e2e2a5 100644
@@ -4,7 +4,6 @@ obj-$(CONFIG_BCM2835_VCHIQ)	+= vchiq.o
 vchiq-objs := \
    interface/vchiq_arm/vchiq_core.o  \
    interface/vchiq_arm/vchiq_arm.o \
-   interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_connected.o \
 

...

Quoted 77 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +53 -0
index 0f2de571eba7..9057d01ffd48 100644
@@ -25,15 +25,32 @@
 #include <linux/rcupdate.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 #include <soc/bcm2835/raspberrypi-firmware.h>
 
 #include "vchiq_core.h"
 #include "vchiq_ioctl.h"
 #include "vchiq_arm.h"
 #include "vchiq_debugfs.h"
+#include "vchiq_connected.h"
+#include "vchiq_pagelist.h"
 
 #define DEVICE_NAME "vchiq"
 
+#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
+
+#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
+
+#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
+#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX  1
+
+#define BELL0	0x00
+#define BELL2	0x08
+
+#define ARM_DS_ACTIVE	BIT(2)
+
 /* Override the default prefix, which would be vchiq_arm (from the filename) */
 #undef MODULE_PARAM_PREFIX
 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
@@ -59,10 +76,542 @@ static struct vchiq_drvdata bcm2836_drvdata = {
 	.cache_line_size = 64,
 };
 
+struct vchiq_2835_state {
+	int inited;
+	struct vchiq_arm_state arm_state;
+};
+
+struct vchiq_pagelist_info {
+	struct pagelist *pagelist;
+	size_t pagelist_buffer_size;
+	dma_addr_t dma_addr;
+	enum dma_data_direction dma_dir;
+	unsigned int num_pages;
+	unsigned int pages_need_release;
+	struct page **pages;
+	struct scatterlist *scatterlist;
+	unsigned int scatterlist_mapped;
+};
+
+static void __iomem *g_regs;
+/* This value is the size of the L2 cache lines as understood by the
+ * VPU firmware, which determines the required alignment of the
+ * offsets/sizes in pagelists.
+ *
+ * Modern VPU firmware looks for a DT "cache-line-size" property in
+ * the VCHIQ node and will overwrite it with the actual L2 cache size,
+ * which the kernel must then respect.  That property was rejected
+ * upstream, so we have to use the VPU firmware's compatibility value
+ * of 32.
+ */
+static unsigned int g_cache_line_size = 32;
+static unsigned int g_fragments_size;
+static char *g_fragments_base;
+static char *g_free_fragments;
+static struct semaphore g_free_fragments_sema;
+static struct device *g_dev;
+
+static DEFINE_SEMAPHORE(g_free_fragments_mutex);

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c static struct vchiq_drvdata bcm2836_drvdata = { · line 124

Quoted 10 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +10 -0
+
+static irqreturn_t
+vchiq_doorbell_irq(int irq, void *dev_id);
+
+static struct vchiq_pagelist_info *
+create_pagelist(char *buf, char __user *ubuf, size_t count, unsigned short type);
+
+static void
+free_pagelist(struct vchiq_pagelist_info *pagelistinfo,
+	      int actual);

please no forward declarations of these 3 functions. Put them into the right order instead ...

Quoted 5 lines

Since this patch is independent from the other ones from the series, maybe Greg can merg the rest of the series.

Quoted 4 lines

Hello Stefan,

Thanks for the review. As for the forward declerations, sure I can fix these 3 functions and send an independent patch for this.

Quoted 6 lines

Please fix up and resend the whole series properly so that I can apply them that way.

thanks,

greg k-h

Hello,

I have just sent a revised patchset with requested changes. [1]

[1] https://lore.kernel.org/patchwork/cover/1465322/

Thank you,
Ojaswin