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-329-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:17:48 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Bui Quang Minh <minhquangbui99@...il.com>,
	Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 328/437] drivers/net/ethernet/marvell/octeontx2: convert to read/write iterators

From: Bui Quang Minh <minhquangbui99@...il.com>

Signed-off-by: Bui Quang Minh <minhquangbui99@...il.com>
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 .../marvell/octeontx2/af/rvu_debugfs.c        | 159 ++++++++----------
 1 file changed, 73 insertions(+), 86 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
index 2500f5ba4f5a..be3b071743f5 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
@@ -209,8 +209,8 @@ static int rvu_dbg_open_##name(struct inode *inode, struct file *file) \
 static const struct file_operations rvu_dbg_##name##_fops = { \
 	.owner		= THIS_MODULE, \
 	.open		= rvu_dbg_open_##name, \
-	.read		= seq_read, \
-	.write		= rvu_dbg_##write_op, \
+	.read_iter	= seq_read_iter, \
+	.write_iter	= rvu_dbg_##write_op, \
 	.llseek		= seq_lseek, \
 	.release	= single_release, \
 }
@@ -219,8 +219,8 @@ static const struct file_operations rvu_dbg_##name##_fops = { \
 static const struct file_operations rvu_dbg_##name##_fops = { \
 	.owner = THIS_MODULE, \
 	.open = simple_open, \
-	.read = rvu_dbg_##read_op, \
-	.write = rvu_dbg_##write_op \
+	.read_iter = rvu_dbg_##read_op, \
+	.write_iter = rvu_dbg_##write_op \
 }
 
 static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf);
@@ -572,11 +572,10 @@ static void rvu_dbg_mcs_init(struct rvu *rvu)
 
 #define LMT_MAPTBL_ENTRY_SIZE 16
 /* Dump LMTST map table */
-static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp,
-					       char __user *buffer,
-					       size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_lmtst_map_table_display(struct kiocb *iocb,
+					       struct iov_iter *to)
 {
-	struct rvu *rvu = filp->private_data;
+	struct rvu *rvu = iocb->ki_filp->private_data;
 	u64 lmt_addr, val, tbl_base;
 	int pf, vf, num_vfs, hw_vfs;
 	void __iomem *lmt_map_base;
@@ -585,9 +584,10 @@ static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp,
 	int index = 0;
 	char *buf;
 	int ret;
+	size_t count = iov_iter_count(to);
 
 	/* don't allow partial reads */
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	buf = kzalloc(buf_size, GFP_KERNEL);
@@ -649,15 +649,15 @@ static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp,
 	off +=	scnprintf(&buf[off], buf_size - 1 - off, "\n");
 
 	ret = min(off, count);
-	if (copy_to_user(buffer, buf, ret))
-		ret = -EFAULT;
+	if (!copy_to_iter_full(buf, ret, to))
+		return -EFAULT;
 	kfree(buf);
 
 	iounmap(lmt_map_base);
 	if (ret < 0)
 		return ret;
 
-	*ppos = ret;
+	iocb->ki_pos = ret;
 	return ret;
 }
 
@@ -731,22 +731,21 @@ static int get_max_column_width(struct rvu *rvu)
 }
 
 /* Dumps current provisioning status of all RVU block LFs */
-static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
-					  char __user *buffer,
-					  size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_rsrc_attach_status(struct kiocb *iocb,
+					  struct iov_iter *to)
 {
 	int index, off = 0, flag = 0, len = 0, i = 0;
-	struct rvu *rvu = filp->private_data;
-	int bytes_not_copied = 0;
+	struct rvu *rvu = iocb->ki_filp->private_data;
 	struct rvu_block block;
 	int pf, vf, pcifunc;
 	int buf_size = 2048;
 	int lf_str_size;
 	char *lfs;
 	char *buf;
+	bool ret;
 
 	/* don't allow partial reads */
-	if (*ppos != 0)
+	if (iocb->ki_pos != 0)
 		return 0;
 
 	buf = kzalloc(buf_size, GFP_KERNEL);
@@ -771,12 +770,13 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
 		}
 
 	off += scnprintf(&buf[off], buf_size - 1 - off, "\n");
-	bytes_not_copied = copy_to_user(buffer + (i * off), buf, off);
-	if (bytes_not_copied)
+	iov_iter_advance(to, i * off);
+	ret = !copy_to_iter_full(buf, off, to);
+	if (ret)
 		goto out;
 
 	i++;
-	*ppos += off;
+	iocb->ki_pos += off;
 	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
 		for (vf = 0; vf <= rvu->hw->total_vfs; vf++) {
 			off = 0;
@@ -813,14 +813,13 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
 			if (flag) {
 				off +=	scnprintf(&buf[off],
 						  buf_size - 1 - off, "\n");
-				bytes_not_copied = copy_to_user(buffer +
-								(i * off),
-								buf, off);
-				if (bytes_not_copied)
+				iov_iter_advance(to, i * off);
+				ret = !copy_to_iter_full(buf, off, to);
+				if (ret)
 					goto out;
 
 				i++;
-				*ppos += off;
+				iocb->ki_pos += off;
 			}
 		}
 	}
@@ -828,10 +827,10 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
 out:
 	kfree(lfs);
 	kfree(buf);
-	if (bytes_not_copied)
+	if (!ret)
 		return -EFAULT;
 
-	return *ppos;
+	return iocb->ki_pos;
 }
 
 RVU_DEBUG_FOPS(rsrc_status, rsrc_attach_status, NULL);
@@ -986,23 +985,26 @@ static int rvu_dbg_qsize_display(struct seq_file *filp, void *unsused,
 	return 0;
 }
 
-static ssize_t rvu_dbg_qsize_write(struct file *filp,
-				   const char __user *buffer, size_t count,
-				   loff_t *ppos, int blktype)
+static ssize_t rvu_dbg_qsize_write(struct kiocb *iocb, struct iov_iter *from,
+				   int blktype)
 {
 	char *blk_string = (blktype == BLKTYPE_NPA) ? "npa" : "nix";
-	struct seq_file *seqfile = filp->private_data;
+	struct seq_file *seqfile = iocb->ki_filp->private_data;
 	char *cmd_buf, *cmd_buf_tmp, *subtoken;
 	struct rvu *rvu = seqfile->private;
 	struct dentry *current_dir;
 	int blkaddr;
 	u16 pcifunc;
 	int ret, lf;
+	size_t count = iov_iter_count(from);
 
-	cmd_buf = memdup_user(buffer, count + 1);
-	if (IS_ERR(cmd_buf))
+	cmd_buf = kmalloc(count + 1, GFP_KERNEL);
+	if (!cmd_buf)
 		return -ENOMEM;
 
+	if (!copy_from_iter_full(cmd_buf, count, from))
+		return -EFAULT;
+
 	cmd_buf[count] = '\0';
 
 	cmd_buf_tmp = strchr(cmd_buf, '\n');
@@ -1025,7 +1027,7 @@ static ssize_t rvu_dbg_qsize_write(struct file *filp,
 	if (blktype == BLKTYPE_NPA) {
 		blkaddr = BLKADDR_NPA;
 	} else {
-		current_dir = filp->f_path.dentry->d_parent;
+		current_dir = iocb->ki_filp->f_path.dentry->d_parent;
 		blkaddr = (!strcmp(current_dir->d_name.name, "nix1") ?
 				   BLKADDR_NIX1 : BLKADDR_NIX0);
 	}
@@ -1044,12 +1046,10 @@ static ssize_t rvu_dbg_qsize_write(struct file *filp,
 	return ret ? ret : count;
 }
 
-static ssize_t rvu_dbg_npa_qsize_write(struct file *filp,
-				       const char __user *buffer,
-				       size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_npa_qsize_write(struct kiocb *iocb,
+				       struct iov_iter *from)
 {
-	return rvu_dbg_qsize_write(filp, buffer, count, ppos,
-					    BLKTYPE_NPA);
+	return rvu_dbg_qsize_write(iocb, from, BLKTYPE_NPA);
 }
 
 static int rvu_dbg_npa_qsize_display(struct seq_file *filp, void *unused)
@@ -1292,16 +1292,14 @@ static int write_npa_ctx(struct rvu *rvu, bool all,
 }
 
 static int parse_cmd_buffer_ctx(char *cmd_buf, size_t *count,
-				const char __user *buffer, int *npalf,
+				struct iov_iter *from, int *npalf,
 				int *id, bool *all)
 {
-	int bytes_not_copied;
 	char *cmd_buf_tmp;
 	char *subtoken;
 	int ret;
 
-	bytes_not_copied = copy_from_user(cmd_buf, buffer, *count);
-	if (bytes_not_copied)
+	if (!copy_from_iter_full(cmd_buf, *count, from))
 		return -EFAULT;
 
 	cmd_buf[*count] = '\0';
@@ -1329,24 +1327,25 @@ static int parse_cmd_buffer_ctx(char *cmd_buf, size_t *count,
 	return ret;
 }
 
-static ssize_t rvu_dbg_npa_ctx_write(struct file *filp,
-				     const char __user *buffer,
-				     size_t count, loff_t *ppos, int ctype)
+static ssize_t rvu_dbg_npa_ctx_write(struct kiocb *iocb,
+				     struct iov_iter *from,
+				     int ctype)
 {
 	char *cmd_buf, *ctype_string = (ctype == NPA_AQ_CTYPE_AURA) ?
 					"aura" : "pool";
-	struct seq_file *seqfp = filp->private_data;
+	struct seq_file *seqfp = iocb->ki_filp->private_data;
 	struct rvu *rvu = seqfp->private;
 	int npalf, id = 0, ret;
 	bool all = false;
+	size_t count = iov_iter_count(from);
 
-	if ((*ppos != 0) || !count)
+	if (iocb->ki_pos != 0 || !count)
 		return -EINVAL;
 
 	cmd_buf = kzalloc(count + 1, GFP_KERNEL);
 	if (!cmd_buf)
 		return count;
-	ret = parse_cmd_buffer_ctx(cmd_buf, &count, buffer,
+	ret = parse_cmd_buffer_ctx(cmd_buf, &count, from,
 				   &npalf, &id, &all);
 	if (ret < 0) {
 		dev_info(rvu->dev,
@@ -1361,12 +1360,10 @@ static ssize_t rvu_dbg_npa_ctx_write(struct file *filp,
 	return ret ? ret : count;
 }
 
-static ssize_t rvu_dbg_npa_aura_ctx_write(struct file *filp,
-					  const char __user *buffer,
-					  size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_npa_aura_ctx_write(struct kiocb *iocb,
+					  struct iov_iter *from)
 {
-	return rvu_dbg_npa_ctx_write(filp, buffer, count, ppos,
-				     NPA_AQ_CTYPE_AURA);
+	return rvu_dbg_npa_ctx_write(iocb, from, NPA_AQ_CTYPE_AURA);
 }
 
 static int rvu_dbg_npa_aura_ctx_display(struct seq_file *filp, void *unused)
@@ -1376,12 +1373,10 @@ static int rvu_dbg_npa_aura_ctx_display(struct seq_file *filp, void *unused)
 
 RVU_DEBUG_SEQ_FOPS(npa_aura_ctx, npa_aura_ctx_display, npa_aura_ctx_write);
 
-static ssize_t rvu_dbg_npa_pool_ctx_write(struct file *filp,
-					  const char __user *buffer,
-					  size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_npa_pool_ctx_write(struct kiocb *iocb,
+					  struct iov_iter *from)
 {
-	return rvu_dbg_npa_ctx_write(filp, buffer, count, ppos,
-				     NPA_AQ_CTYPE_POOL);
+	return rvu_dbg_npa_ctx_write(iocb, from, NPA_AQ_CTYPE_POOL);
 }
 
 static int rvu_dbg_npa_pool_ctx_display(struct seq_file *filp, void *unused)
@@ -2021,19 +2016,19 @@ static int write_nix_queue_ctx(struct rvu *rvu, bool all, int nixlf,
 	return 0;
 }
 
-static ssize_t rvu_dbg_nix_queue_ctx_write(struct file *filp,
-					   const char __user *buffer,
-					   size_t count, loff_t *ppos,
+static ssize_t rvu_dbg_nix_queue_ctx_write(struct kiocb *iocb,
+					   struct iov_iter *from,
 					   int ctype)
 {
-	struct seq_file *m = filp->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct nix_hw *nix_hw = m->private;
 	struct rvu *rvu = nix_hw->rvu;
 	char *cmd_buf, *ctype_string;
 	int nixlf, id = 0, ret;
 	bool all = false;
+	size_t count = iov_iter_count(from);
 
-	if ((*ppos != 0) || !count)
+	if (iocb->ki_pos != 0 || !count)
 		return -EINVAL;
 
 	switch (ctype) {
@@ -2055,7 +2050,7 @@ static ssize_t rvu_dbg_nix_queue_ctx_write(struct file *filp,
 	if (!cmd_buf)
 		return count;
 
-	ret = parse_cmd_buffer_ctx(cmd_buf, &count, buffer,
+	ret = parse_cmd_buffer_ctx(cmd_buf, &count, from,
 				   &nixlf, &id, &all);
 	if (ret < 0) {
 		dev_info(rvu->dev,
@@ -2071,12 +2066,10 @@ static ssize_t rvu_dbg_nix_queue_ctx_write(struct file *filp,
 	return ret ? ret : count;
 }
 
-static ssize_t rvu_dbg_nix_sq_ctx_write(struct file *filp,
-					const char __user *buffer,
-					size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_nix_sq_ctx_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	return rvu_dbg_nix_queue_ctx_write(filp, buffer, count, ppos,
-					    NIX_AQ_CTYPE_SQ);
+	return rvu_dbg_nix_queue_ctx_write(iocb, from, NIX_AQ_CTYPE_SQ);
 }
 
 static int rvu_dbg_nix_sq_ctx_display(struct seq_file *filp, void *unused)
@@ -2086,12 +2079,10 @@ static int rvu_dbg_nix_sq_ctx_display(struct seq_file *filp, void *unused)
 
 RVU_DEBUG_SEQ_FOPS(nix_sq_ctx, nix_sq_ctx_display, nix_sq_ctx_write);
 
-static ssize_t rvu_dbg_nix_rq_ctx_write(struct file *filp,
-					const char __user *buffer,
-					size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_nix_rq_ctx_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	return rvu_dbg_nix_queue_ctx_write(filp, buffer, count, ppos,
-					    NIX_AQ_CTYPE_RQ);
+	return rvu_dbg_nix_queue_ctx_write(iocb, from, NIX_AQ_CTYPE_RQ);
 }
 
 static int rvu_dbg_nix_rq_ctx_display(struct seq_file *filp, void  *unused)
@@ -2101,12 +2092,10 @@ static int rvu_dbg_nix_rq_ctx_display(struct seq_file *filp, void  *unused)
 
 RVU_DEBUG_SEQ_FOPS(nix_rq_ctx, nix_rq_ctx_display, nix_rq_ctx_write);
 
-static ssize_t rvu_dbg_nix_cq_ctx_write(struct file *filp,
-					const char __user *buffer,
-					size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_nix_cq_ctx_write(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	return rvu_dbg_nix_queue_ctx_write(filp, buffer, count, ppos,
-					    NIX_AQ_CTYPE_CQ);
+	return rvu_dbg_nix_queue_ctx_write(iocb, from, NIX_AQ_CTYPE_CQ);
 }
 
 static int rvu_dbg_nix_cq_ctx_display(struct seq_file *filp, void *unused)
@@ -2153,12 +2142,10 @@ static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf)
 				     "sq");
 }
 
-static ssize_t rvu_dbg_nix_qsize_write(struct file *filp,
-				       const char __user *buffer,
-				       size_t count, loff_t *ppos)
+static ssize_t rvu_dbg_nix_qsize_write(struct kiocb *iocb,
+				       struct iov_iter *from)
 {
-	return rvu_dbg_qsize_write(filp, buffer, count, ppos,
-				   BLKTYPE_NIX);
+	return rvu_dbg_qsize_write(iocb, from, BLKTYPE_NIX);
 }
 
 static int rvu_dbg_nix_qsize_display(struct seq_file *filp, void *unused)
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ