lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-107-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:14:06 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 106/437] crypto: hisilicon: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/crypto/hisilicon/debugfs.c        | 51 +++++++++++------------
 drivers/crypto/hisilicon/hpre/hpre_main.c | 23 +++++-----
 drivers/crypto/hisilicon/qm.c             | 22 +++++-----
 drivers/crypto/hisilicon/sec2/sec_main.c  | 23 +++++-----
 drivers/crypto/hisilicon/zip/zip_main.c   | 23 +++++-----
 5 files changed, 68 insertions(+), 74 deletions(-)

diff --git a/drivers/crypto/hisilicon/debugfs.c b/drivers/crypto/hisilicon/debugfs.c
index cd67fa348ca7..6dd67b0fcf36 100644
--- a/drivers/crypto/hisilicon/debugfs.c
+++ b/drivers/crypto/hisilicon/debugfs.c
@@ -137,8 +137,7 @@ static struct hisi_qm *file_to_qm(struct debugfs_file *file)
 	return container_of(debug, struct hisi_qm, debug);
 }
 
-static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
-			   size_t count, loff_t *pos)
+static ssize_t qm_cmd_read(struct kiocb *iocb, struct iov_iter *to)
 {
 	char buf[QM_DBG_READ_LEN];
 	int len;
@@ -146,7 +145,7 @@ static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
 	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n",
 			"Please echo help to cmd to get help information");
 
-	return simple_read_from_buffer(buffer, count, pos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 static void dump_show(struct hisi_qm *qm, void *info,
@@ -502,14 +501,14 @@ static int qm_cmd_write_dump(struct hisi_qm *qm, const char *cmd_buf)
 	return ret;
 }
 
-static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
-			    size_t count, loff_t *pos)
+static ssize_t qm_cmd_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char *cmd_buf, *cmd_buf_tmp;
 	int ret;
 
-	if (*pos)
+	if (iocb->ki_pos)
 		return 0;
 
 	ret = hisi_qm_get_dfx_access(qm);
@@ -527,7 +526,7 @@ static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
 		goto put_dfx_access;
 	}
 
-	cmd_buf = memdup_user_nul(buffer, count);
+	cmd_buf = iterdup_nul(from, count);
 	if (IS_ERR(cmd_buf)) {
 		ret = PTR_ERR(cmd_buf);
 		goto put_dfx_access;
@@ -557,8 +556,8 @@ static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer,
 static const struct file_operations qm_cmd_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_cmd_read,
-	.write = qm_cmd_write,
+	.read_iter = qm_cmd_read,
+	.write_iter = qm_cmd_write,
 };
 
 /**
@@ -704,10 +703,9 @@ static int current_qm_write(struct hisi_qm *qm, u32 val)
 	return 0;
 }
 
-static ssize_t qm_debug_read(struct file *filp, char __user *buf,
-			     size_t count, loff_t *pos)
+static ssize_t qm_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct debugfs_file *file = filp->private_data;
+	struct debugfs_file *file = iocb->ki_filp->private_data;
 	enum qm_debug_file index = file->index;
 	struct hisi_qm *qm = file_to_qm(file);
 	char tbuf[QM_DBG_TMP_BUF_LEN];
@@ -736,7 +734,7 @@ static ssize_t qm_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = scnprintf(tbuf, QM_DBG_TMP_BUF_LEN, "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	mutex_unlock(&file->lock);
@@ -744,24 +742,24 @@ static ssize_t qm_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t qm_debug_write(struct file *filp, const char __user *buf,
-			      size_t count, loff_t *pos)
+static ssize_t qm_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct debugfs_file *file = filp->private_data;
+	struct debugfs_file *file = iocb->ki_filp->private_data;
 	enum qm_debug_file index = file->index;
 	struct hisi_qm *qm = file_to_qm(file);
+	size_t count = iov_iter_count(from);
 	unsigned long val;
 	char tbuf[QM_DBG_TMP_BUF_LEN];
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= QM_DBG_TMP_BUF_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, QM_DBG_TMP_BUF_LEN - 1, pos, buf,
-				     count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos, QM_DBG_TMP_BUF_LEN - 1,
+					from);
 	if (len < 0)
 		return len;
 
@@ -800,8 +798,8 @@ static ssize_t qm_debug_write(struct file *filp, const char __user *buf,
 static const struct file_operations qm_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_debug_read,
-	.write = qm_debug_write,
+	.read_iter = qm_debug_read,
+	.write_iter = qm_debug_write,
 };
 
 static void dfx_regs_uninit(struct hisi_qm *qm,
@@ -1051,23 +1049,22 @@ static int qm_state_show(struct seq_file *s, void *unused)
 
 DEFINE_SHOW_ATTRIBUTE(qm_state);
 
-static ssize_t qm_status_read(struct file *filp, char __user *buffer,
-			      size_t count, loff_t *pos)
+static ssize_t qm_status_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
 	char buf[QM_DBG_READ_LEN];
 	int val, len;
 
 	val = atomic_read(&qm->status.flags);
 	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
 
-	return simple_read_from_buffer(buffer, count, pos, buf, len);
+	return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
 }
 
 static const struct file_operations qm_status_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_status_read,
+	.read_iter = qm_status_read,
 };
 
 static void qm_create_debugfs_file(struct hisi_qm *qm, struct dentry *dir,
diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c
index d93aa6630a57..b9257a368aa9 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_main.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_main.c
@@ -829,10 +829,9 @@ static void hpre_cluster_inqry_write(struct hpre_debugfs_file *file, u32 val)
 	writel(val, qm->io_base + offset + HPRE_CLUSTER_INQURY);
 }
 
-static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf,
-				    size_t count, loff_t *pos)
+static ssize_t hpre_ctrl_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hpre_debugfs_file *file = filp->private_data;
+	struct hpre_debugfs_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = hpre_file_to_qm(file);
 	char tbuf[HPRE_DBGFS_VAL_MAX_LEN];
 	u32 val;
@@ -857,7 +856,7 @@ static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = snprintf(tbuf, HPRE_DBGFS_VAL_MAX_LEN, "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	spin_unlock_irq(&file->lock);
@@ -865,23 +864,23 @@ static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t hpre_ctrl_debug_write(struct file *filp, const char __user *buf,
-				     size_t count, loff_t *pos)
+static ssize_t hpre_ctrl_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hpre_debugfs_file *file = filp->private_data;
+	struct hpre_debugfs_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = hpre_file_to_qm(file);
+	size_t count = iov_iter_count(from);
 	char tbuf[HPRE_DBGFS_VAL_MAX_LEN];
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= HPRE_DBGFS_VAL_MAX_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, HPRE_DBGFS_VAL_MAX_LEN - 1,
-				     pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos,
+					HPRE_DBGFS_VAL_MAX_LEN - 1, from);
 	if (len < 0)
 		return len;
 
@@ -919,8 +918,8 @@ static ssize_t hpre_ctrl_debug_write(struct file *filp, const char __user *buf,
 static const struct file_operations hpre_ctrl_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = hpre_ctrl_debug_read,
-	.write = hpre_ctrl_debug_write,
+	.read_iter = hpre_ctrl_debug_read,
+	.write_iter = hpre_ctrl_debug_write,
 };
 
 static int hpre_debugfs_atomic64_get(void *data, u64 *val)
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 92f0a1d9b4a6..604cff89f0c8 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -3591,10 +3591,9 @@ static int qm_vf_read_qos(struct hisi_qm *qm)
 	return ret;
 }
 
-static ssize_t qm_algqos_read(struct file *filp, char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t qm_algqos_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
 	char tbuf[QM_DBG_READ_LEN];
 	u32 qos_val, ir;
 	int ret;
@@ -3622,7 +3621,7 @@ static ssize_t qm_algqos_read(struct file *filp, char __user *buf,
 	qos_val = ir / QM_QOS_RATE;
 	ret = scnprintf(tbuf, QM_DBG_READ_LEN, "%u\n", qos_val);
 
-	ret = simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	ret = simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_get_status:
 	clear_bit(QM_RESETTING, &qm->misc_ctl);
@@ -3665,22 +3664,23 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
 	return 0;
 }
 
-static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t qm_algqos_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct hisi_qm *qm = filp->private_data;
+	struct hisi_qm *qm = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char tbuf[QM_DBG_READ_LEN];
 	unsigned int fun_index;
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= QM_DBG_READ_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, QM_DBG_READ_LEN - 1, pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos, QM_DBG_READ_LEN - 1,
+					from);
 	if (len < 0)
 		return len;
 
@@ -3722,8 +3722,8 @@ static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
 static const struct file_operations qm_algqos_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = qm_algqos_read,
-	.write = qm_algqos_write,
+	.read_iter = qm_algqos_read,
+	.write_iter = qm_algqos_write,
 };
 
 /**
diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c
index c290d8937b19..bb168d97de30 100644
--- a/drivers/crypto/hisilicon/sec2/sec_main.c
+++ b/drivers/crypto/hisilicon/sec2/sec_main.c
@@ -718,10 +718,9 @@ static int sec_clear_enable_write(struct hisi_qm *qm, u32 val)
 	return 0;
 }
 
-static ssize_t sec_debug_read(struct file *filp, char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t sec_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct sec_debug_file *file = filp->private_data;
+	struct sec_debug_file *file = iocb->ki_filp->private_data;
 	char tbuf[SEC_DBGFS_VAL_MAX_LEN];
 	struct hisi_qm *qm = file->qm;
 	u32 val;
@@ -745,7 +744,7 @@ static ssize_t sec_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = snprintf(tbuf, SEC_DBGFS_VAL_MAX_LEN, "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	spin_unlock_irq(&file->lock);
@@ -753,23 +752,23 @@ static ssize_t sec_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t sec_debug_write(struct file *filp, const char __user *buf,
-			       size_t count, loff_t *pos)
+static ssize_t sec_debug_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct sec_debug_file *file = filp->private_data;
+	struct sec_debug_file *file = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	char tbuf[SEC_DBGFS_VAL_MAX_LEN];
 	struct hisi_qm *qm = file->qm;
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= SEC_DBGFS_VAL_MAX_LEN)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, SEC_DBGFS_VAL_MAX_LEN - 1,
-				     pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos,
+					SEC_DBGFS_VAL_MAX_LEN - 1, from);
 	if (len < 0)
 		return len;
 
@@ -805,8 +804,8 @@ static ssize_t sec_debug_write(struct file *filp, const char __user *buf,
 static const struct file_operations sec_dbg_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = sec_debug_read,
-	.write = sec_debug_write,
+	.read_iter = sec_debug_read,
+	.write_iter = sec_debug_write,
 };
 
 static int sec_debugfs_atomic64_get(void *data, u64 *val)
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index c065fd867161..47319ba13873 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -689,10 +689,9 @@ static int clear_enable_write(struct hisi_qm *qm, u32 val)
 	return  0;
 }
 
-static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
-					size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct ctrl_debug_file *file = filp->private_data;
+	struct ctrl_debug_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = file_to_qm(file);
 	char tbuf[HZIP_BUF_SIZE];
 	u32 val;
@@ -714,7 +713,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
 
 	hisi_qm_put_dfx_access(qm);
 	ret = scnprintf(tbuf, sizeof(tbuf), "%u\n", val);
-	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
+	return simple_copy_to_iter(tbuf, &iocb->ki_pos, ret, to);
 
 err_input:
 	spin_unlock_irq(&file->lock);
@@ -722,23 +721,23 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
 	return -EINVAL;
 }
 
-static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
-					 const char __user *buf,
-					 size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_write(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct ctrl_debug_file *file = filp->private_data;
+	struct ctrl_debug_file *file = iocb->ki_filp->private_data;
 	struct hisi_qm *qm = file_to_qm(file);
+	size_t count = iov_iter_count(from);
 	char tbuf[HZIP_BUF_SIZE];
 	unsigned long val;
 	int len, ret;
 
-	if (*pos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	if (count >= HZIP_BUF_SIZE)
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(tbuf, HZIP_BUF_SIZE - 1, pos, buf, count);
+	len = simple_copy_from_iter(tbuf, &iocb->ki_pos, HZIP_BUF_SIZE - 1, from);
 	if (len < 0)
 		return len;
 
@@ -774,8 +773,8 @@ static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
 static const struct file_operations ctrl_debug_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read = hisi_zip_ctrl_debug_read,
-	.write = hisi_zip_ctrl_debug_write,
+	.read_iter = hisi_zip_ctrl_debug_read,
+	.write_iter = hisi_zip_ctrl_debug_write,
 };
 
 static int zip_debugfs_atomic64_set(void *data, u64 val)
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ