From ec084e4ec314df8041882e22975fca2caff3bcce Mon Sep 17 00:00:00 2001 From: Ninad Palsule Date: Tue, 10 Oct 2023 15:43:47 -0500 Subject: [PATCH 1/3] fsi: sbefifo: Bump up user write cmd length This commit increases user write limit for command length from 1MB to 4MB. This is required to support images larger than 1MB. As per 'commit 15e2a7218c27 ("fsi: sbefifo: Bump max command length")' the alternate solution is to break image into 1MB pieces by cronous server that means kernel driver needs to provide way to send end of message command once all pieces are transferred. This requires restructuring of both kernel driver and cronus server (application). Hence this commit chose to bump up cmd length to reduce code impact. Testing: Loaded 3 MB image through cronus server. Signed-off-by: Ninad Palsule Reviewed-by: Eddie James Link: https://lore.kernel.org/r/20231010204348.2600242-2-ninad@linux.ibm.com Signed-off-by: Joel Stanley --- drivers/fsi/fsi-sbefifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c index 0a98517f3959..c47426b9bfc6 100644 --- a/drivers/fsi/fsi-sbefifo.c +++ b/drivers/fsi/fsi-sbefifo.c @@ -113,7 +113,7 @@ enum sbe_state #define SBEFIFO_TIMEOUT_IN_RSP 1000 /* Other constants */ -#define SBEFIFO_MAX_USER_CMD_LEN (0x100000 + PAGE_SIZE) +#define SBEFIFO_MAX_USER_CMD_LEN (0x400000 + PAGE_SIZE) #define SBEFIFO_RESET_MAGIC 0x52534554 /* "RSET" */ struct sbefifo { From f7236a0c919eca31c5def62bf52aa8aabcc6effb Mon Sep 17 00:00:00 2001 From: Ninad Palsule Date: Tue, 10 Oct 2023 15:43:48 -0500 Subject: [PATCH 2/3] fsi: sbefifo: Handle pending write command If previous write command is still pending then free it first. As per the current kernel driver design, write operation prepares a buffer for FSI write, the actual FSI write is performed on next read operation. There is a possibility of memory leak if buggy application sends two back to back writes or two parallel writes. Signed-off-by: Ninad Palsule Reviewed-by: Eddie James Link: https://lore.kernel.org/r/20231010204348.2600242-3-ninad@linux.ibm.com Signed-off-by: Joel Stanley --- drivers/fsi/fsi-sbefifo.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c index c47426b9bfc6..0385476bfb03 100644 --- a/drivers/fsi/fsi-sbefifo.c +++ b/drivers/fsi/fsi-sbefifo.c @@ -882,6 +882,13 @@ static ssize_t sbefifo_user_write(struct file *file, const char __user *buf, mutex_lock(&user->file_lock); + /* If previous write command is still pending then free it. It is safe + * to do that because read cannot be in progress since we hold the + * lock. + */ + if (user->pending_cmd) + sbefifo_release_command(user); + /* Can we use the pre-allocate buffer ? If not, allocate */ if (len <= PAGE_SIZE) user->pending_cmd = user->cmd_page; From c5eeb63edac9497f9a0d46d3b75cf8b293771ecf Mon Sep 17 00:00:00 2001 From: Lakshmi Yadlapati Date: Wed, 13 Dec 2023 18:07:44 -0600 Subject: [PATCH 3/3] fsi: Fix panic on scom file read Reading the scom file without the custom open method (i2cr_scom_open) causes a kernel panic. This change replaces simple_open with i2cr_scom_open to properly initialize the private_data field in the file structure, preventing the panic during scom file operations. Fixes: c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver") Signed-off-by: Lakshmi Yadlapati Reviewed-by: Ninad Palsule Link: https://lore.kernel.org/r/20231214000744.1281464-1-lakshmiy@us.ibm.com Signed-off-by: Joel Stanley --- drivers/fsi/i2cr-scom.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c index cb7e02213032..8d65c562b488 100644 --- a/drivers/fsi/i2cr-scom.c +++ b/drivers/fsi/i2cr-scom.c @@ -73,9 +73,18 @@ static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_ return len; } +static int i2cr_scom_open(struct inode *inode, struct file *file) +{ + struct i2cr_scom *scom = container_of(inode->i_cdev, struct i2cr_scom, cdev); + + file->private_data = scom; + + return 0; +} + static const struct file_operations i2cr_scom_fops = { .owner = THIS_MODULE, - .open = simple_open, + .open = i2cr_scom_open, .llseek = i2cr_scom_llseek, .read = i2cr_scom_read, .write = i2cr_scom_write,