public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Manish Mandlik <mmandlik@google.com>
Cc: Arend van Spriel <aspriel@gmail.com>,
	marcel@holtmann.org, luiz.dentz@gmail.com,
	chromeos-bluetooth-upstreaming@chromium.org,
	linux-bluetooth@vger.kernel.org,
	Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Johannes Berg <johannes@sipsolutions.net>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Won Chung <wonchung@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/5] devcoredump: Add per device sysfs entry to enable/disable coredump
Date: Tue, 9 Aug 2022 19:31:41 +0200	[thread overview]
Message-ID: <YvKZ/Wu3HR3ha/FC@kroah.com> (raw)
In-Reply-To: <20220809083112.v4.2.Ief1110784c6c1c3ac0ee5677c2d28d785af8686d@changeid>

On Tue, Aug 09, 2022 at 08:35:24AM -0700, Manish Mandlik wrote:
> The /sys/class/devcoredump/disabled provides only one-way disable
> functionality. Also, disabling devcoredump using it disables the
> devcoredump functionality for everyone who is using it.
> 
> Provide a way to selectively enable/disable devcoredump for the device
> which is bound to a driver that implements the '.coredump()' callback.
> 
> This adds the 'coredump_disabled' driver attribute. When the driver
> implements the '.coredump()' callback, 'coredump_disabled' file is added
> along with the 'coredump' file in the sysfs folder of the device upon
> driver binding. The file is removed when the driver is unbound.
> 
> Drivers can use this attribute to enable/disable devcoredump and the
> userspace can write 0 or 1 to /sys/devices/.../coredump_disabled sysfs
> entry to control enabling/disabling of devcoredump for that device.
> 
> Signed-off-by: Manish Mandlik <mmandlik@google.com>
> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> ---
> 
> Changes in v4:
> - New patch in the series
> 
>  drivers/base/dd.c          | 43 +++++++++++++++++++++++++++++++++++---
>  drivers/base/devcoredump.c |  2 +-
>  include/linux/device.h     |  4 ++++
>  3 files changed, 45 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 11b0fb6414d3..c76d1145c6d9 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -426,6 +426,31 @@ static ssize_t coredump_store(struct device *dev, struct device_attribute *attr,
>  }
>  static DEVICE_ATTR_WO(coredump);
>  
> +static ssize_t coredump_disabled_show(struct device *dev,
> +				      struct device_attribute *attr,
> +				      char *buf)
> +{
> +	return scnprintf(buf, 3, "%d\n", dev->coredump_disabled);

Also, please use sysfs_emit() for any sysfs file output.  It's in all
active kernels for a very long time now.

> +}
> +
> +static ssize_t coredump_disabled_store(struct device *dev,
> +				       struct device_attribute *attr,
> +				       const char *buf, size_t count)
> +{
> +	long coredump_disabled;
> +
> +	if (!kstrtol(buf, 10, &coredump_disabled)) {
> +		/* Consider any non-zero value as true */

We have a "Y/N/0/1/y/n" check function for sysfs store callbacks that
you should use instead.



> +		if (coredump_disabled)
> +			dev->coredump_disabled = true;
> +		else
> +			dev->coredump_disabled = false;
> +	}
> +
> +	return count;
> +}
> +static DEVICE_ATTR_RW(coredump_disabled);
> +
>  static int driver_sysfs_add(struct device *dev)
>  {
>  	int ret;
> @@ -448,9 +473,19 @@ static int driver_sysfs_add(struct device *dev)
>  		return 0;
>  
>  	ret = device_create_file(dev, &dev_attr_coredump);
> -	if (!ret)
> -		return 0;
> +	if (ret)
> +		goto rm_driver;
> +
> +	ret = device_create_file(dev, &dev_attr_coredump_disabled);

Please use an attribute group now that you have multiple files.



> +	if (ret)
> +		goto rm_coredump;
>  
> +	return 0;
> +
> +rm_coredump:
> +	device_remove_file(dev, &dev_attr_coredump);
> +
> +rm_driver:
>  	sysfs_remove_link(&dev->kobj, "driver");
>  
>  rm_dev:
> @@ -466,8 +501,10 @@ static void driver_sysfs_remove(struct device *dev)
>  	struct device_driver *drv = dev->driver;
>  
>  	if (drv) {
> -		if (drv->coredump)
> +		if (drv->coredump) {
> +			device_remove_file(dev, &dev_attr_coredump_disabled);
>  			device_remove_file(dev, &dev_attr_coredump);
> +		}
>  		sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
>  		sysfs_remove_link(&dev->kobj, "driver");
>  	}
> diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
> index f4d794d6bb85..c5e9af9f3181 100644
> --- a/drivers/base/devcoredump.c
> +++ b/drivers/base/devcoredump.c
> @@ -255,7 +255,7 @@ void dev_coredumpm(struct device *dev, struct module *owner,
>  	struct devcd_entry *devcd;
>  	struct device *existing;
>  
> -	if (devcd_disabled)
> +	if (devcd_disabled || dev->coredump_disabled)
>  		goto free;
>  
>  	existing = class_find_device(&devcd_class, NULL, dev,
> diff --git a/include/linux/device.h b/include/linux/device.h
> index dc941997795c..120dd656f99d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -469,6 +469,8 @@ struct device_physical_location {
>   * 		This identifies the device type and carries type-specific
>   * 		information.
>   * @mutex:	Mutex to synchronize calls to its driver.
> + * @coredump_disabled: Can be used by drivers to selectively enable/disable the
> + *		coredump for a particular device via sysfs entry.
>   * @bus:	Type of bus device is on.
>   * @driver:	Which driver has allocated this
>   * @platform_data: Platform data specific to the device.
> @@ -561,6 +563,8 @@ struct device {
>  	const char		*init_name; /* initial name of the device */
>  	const struct device_type *type;
>  
> +	bool			coredump_disabled;
> +

That just hosed the alignment in this structure :(

Please be aware of how memory layouts for common kernel structures are
managed, and try not to add holes when you do not need to.

thanks,

greg k-h

  parent reply	other threads:[~2022-08-09 17:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 15:35 [PATCH v4 1/5] sysfs: Add attribute info for /sys/devices/.../coredump_disabled Manish Mandlik
2022-08-09 15:35 ` [PATCH v4 2/5] devcoredump: Add per device sysfs entry to enable/disable coredump Manish Mandlik
2022-08-09 17:27   ` Greg Kroah-Hartman
2022-08-09 17:31   ` Greg Kroah-Hartman [this message]
2022-08-09 15:35 ` [PATCH v4 3/5] Bluetooth: Add support for hci devcoredump Manish Mandlik
2022-08-09 15:35 ` [PATCH v4 4/5] Bluetooth: btusb: Add btusb devcoredump support Manish Mandlik
2022-08-09 15:35 ` [PATCH v4 5/5] Bluetooth: btintel: Add Intel " Manish Mandlik
2022-08-09 16:09 ` [v4,1/5] sysfs: Add attribute info for /sys/devices/.../coredump_disabled bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YvKZ/Wu3HR3ha/FC@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=abhishekpandit@chromium.org \
    --cc=aspriel@gmail.com \
    --cc=chromeos-bluetooth-upstreaming@chromium.org \
    --cc=dan.j.williams@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=johannes@sipsolutions.net \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=mmandlik@google.com \
    --cc=rafael@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wonchung@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox