mbox series

[v3,0/3] Add interconnect debugfs client

Message ID 20230807142914.12480-1-quic_mdtipton@quicinc.com
Headers show
Series Add interconnect debugfs client | expand

Message

Mike Tipton Aug. 7, 2023, 2:29 p.m. UTC
This series introduces interconnect debugfs files that support voting
for any path the framework supports.

We've historically relied on an out-of-tree module for this, which used
the old icc_get() that was recently removed in [0]. The old icc_get()
took integer endpoint IDs, which made identifying paths in our old
implementation non-intuitive. The logical node names typically don't
change much chip-to-chip, but the raw integer IDs do. Take this
opportunity to introduce an icc_get() that uses string names instead,
which allows for a more intuitive and generic debugfs interface.

We rely on this support for debug, test, and verification. Hopefully
it'll be useful for other vendors as well.

[0] commit 7dcdad6f32c9 ("interconnect: drop unused icc_get() interface")

Changes in v3:
- Use GFP_ATOMIC when allocating with the rcu lock held.

Changes in v2:
- Make icc_get() an internal interface.
- RCU-protect src_node and dst_node.
- Replace PLATFORM_DEVID_AUTO with PLATFORM_DEVID_NONE.
- Remove unnecessary #include.
- Add debugfs client documentation.

Mike Tipton (3):
  debugfs: Add write support to debugfs_create_str()
  interconnect: Reintroduce icc_get()
  interconnect: Add debugfs test client

 Documentation/driver-api/interconnect.rst |  25 ++++
 drivers/interconnect/Makefile             |   2 +-
 drivers/interconnect/core.c               |  66 +++++++++
 drivers/interconnect/debugfs-client.c     | 168 ++++++++++++++++++++++
 drivers/interconnect/internal.h           |   3 +
 fs/debugfs/file.c                         |  48 ++++++-
 6 files changed, 309 insertions(+), 3 deletions(-)
 create mode 100644 drivers/interconnect/debugfs-client.c

Comments

Georgi Djakov Aug. 11, 2023, 7:46 a.m. UTC | #1
On 7.08.23 17:29, Mike Tipton wrote:
> Currently, debugfs_create_str() only supports reading strings from
> debugfs. Add support for writing them as well.
> 
> Based on original implementation by Peter Zijlstra [0]. Write support
> was present in the initial patch version, but dropped in v2 due to lack
> of users. We have a user now, so reintroduce it.
> 
> [0] https://lore.kernel.org/all/YF3Hv5zXb%2F6lauzs@hirez.programming.kicks-ass.net/
> 

Hi Greg,

Looks like the original code was reviewed two years ago (not sure if it
counts). But in any case, i need an ack from you to apply this.

There is no build dependency with the rest of the patches (but there is a
functional one). It should be also fine if you apply it directly, if you
prefer so?

Thanks,
Georgi

> Signed-off-by: Mike Tipton <quic_mdtipton@quicinc.com>
> ---
>   fs/debugfs/file.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index b7711888dd17..87b3753aa4b1 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -904,8 +904,52 @@ EXPORT_SYMBOL_GPL(debugfs_create_str);
>   static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf,
>   				      size_t count, loff_t *ppos)
>   {
> -	/* This is really only for read-only strings */
> -	return -EINVAL;
> +	struct dentry *dentry = F_DENTRY(file);
> +	char *old, *new = NULL;
> +	int pos = *ppos;
> +	int r;
> +
> +	r = debugfs_file_get(dentry);
> +	if (unlikely(r))
> +		return r;
> +
> +	old = *(char **)file->private_data;
> +
> +	/* only allow strict concatenation */
> +	r = -EINVAL;
> +	if (pos && pos != strlen(old))
> +		goto error;
> +
> +	r = -E2BIG;
> +	if (pos + count + 1 > PAGE_SIZE)
> +		goto error;
> +
> +	r = -ENOMEM;
> +	new = kmalloc(pos + count + 1, GFP_KERNEL);
> +	if (!new)
> +		goto error;
> +
> +	if (pos)
> +		memcpy(new, old, pos);
> +
> +	r = -EFAULT;
> +	if (copy_from_user(new + pos, user_buf, count))
> +		goto error;
> +
> +	new[pos + count] = '\0';
> +	strim(new);
> +
> +	rcu_assign_pointer(*(char **)file->private_data, new);
> +	synchronize_rcu();
> +	kfree(old);
> +
> +	debugfs_file_put(dentry);
> +	return count;
> +
> +error:
> +	kfree(new);
> +	debugfs_file_put(dentry);
> +	return r;
>   }
>   
>   static const struct file_operations fops_str = {
Greg Kroah-Hartman Aug. 12, 2023, 10:36 a.m. UTC | #2
On Fri, Aug 11, 2023 at 10:46:34AM +0300, Georgi Djakov wrote:
> On 7.08.23 17:29, Mike Tipton wrote:
> > Currently, debugfs_create_str() only supports reading strings from
> > debugfs. Add support for writing them as well.
> > 
> > Based on original implementation by Peter Zijlstra [0]. Write support
> > was present in the initial patch version, but dropped in v2 due to lack
> > of users. We have a user now, so reintroduce it.
> > 
> > [0] https://lore.kernel.org/all/YF3Hv5zXb%2F6lauzs@hirez.programming.kicks-ass.net/
> > 
> 
> Hi Greg,
> 
> Looks like the original code was reviewed two years ago (not sure if it
> counts). But in any case, i need an ack from you to apply this.
> 
> There is no build dependency with the rest of the patches (but there is a
> functional one). It should be also fine if you apply it directly, if you
> prefer so?

Feel free for this to go with the code that uses it:

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg Kroah-Hartman Aug. 12, 2023, 10:37 a.m. UTC | #3
On Sat, Aug 12, 2023 at 12:36:12PM +0200, Greg KH wrote:
> On Fri, Aug 11, 2023 at 10:46:34AM +0300, Georgi Djakov wrote:
> > On 7.08.23 17:29, Mike Tipton wrote:
> > > Currently, debugfs_create_str() only supports reading strings from
> > > debugfs. Add support for writing them as well.
> > > 
> > > Based on original implementation by Peter Zijlstra [0]. Write support
> > > was present in the initial patch version, but dropped in v2 due to lack
> > > of users. We have a user now, so reintroduce it.
> > > 
> > > [0] https://lore.kernel.org/all/YF3Hv5zXb%2F6lauzs@hirez.programming.kicks-ass.net/
> > > 
> > 
> > Hi Greg,
> > 
> > Looks like the original code was reviewed two years ago (not sure if it
> > counts). But in any case, i need an ack from you to apply this.
> > 
> > There is no build dependency with the rest of the patches (but there is a
> > functional one). It should be also fine if you apply it directly, if you
> > prefer so?
> 
> Feel free for this to go with the code that uses it:
> 
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Wait, no, this isn't ok, this ACK is now rescinded:

NACKED-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>