Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6071724rwb; Tue, 9 Aug 2022 08:38:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR74QNzDzHiV4JKYP3T+c7XD6taGdGQ6F0nj683i/F0PaShBt6CxQ16u4BEOymNJDoUVyfdb X-Received: by 2002:a17:902:7444:b0:170:c5e7:a68 with SMTP id e4-20020a170902744400b00170c5e70a68mr8007377plt.163.1660059501204; Tue, 09 Aug 2022 08:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660059501; cv=none; d=google.com; s=arc-20160816; b=g+r4fOoIMpxZuVM1LT53BlBwkp+QQ8Zg8USUVE2nkXuV86j1ghNHx/IXSXTg2zyxnO i6m517NMYDma6N8lpK1wNO1m+GxBr2z0sMy9C+xETOhMHeK0ZxBDw9nT+metYa6L1Bfm xkzgud6ahsLdcrw9mN5RzbCqw/60tIeLcIcBYCtlyyNSQSIpKPgds3HzALnxDAYzUPLH tFQ2NmFRaaFLxNIjmfw6UbghELPMC3wxpdbneY95PTrxlij+G24pfNxOoO0cSeLlJWaK zeh/stW0Y1KaHVZ91/LAnegzD3Ytj49R1RSqQc5iZdv8cZKlF2C/8zrKdpnsK84lN71I d/Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=f7QNBZGNnK5yYhhuUlGnKKkabxvWElh1Ug+FZ9u2MZY=; b=n8+BIMVS2QoDIWMaE1h2xJGMMjGxAckDVNi12NIqR0z90KStjEADMtnlVJPxzCU0xr hhUMvW5GwbCuZgvlN84PZBd/7HwsliCAZYnS6bP1DaSl9kvPwJjVxmf9EnJHGvo92b5T QKvHWKHekkkTyIeZoC75synl0so1YCATqzpDD65H/j8SxqYY/5dqg21ElnMZQupe81Rc bqY6V7BRpMmnhfjTShuPSeROyMZ2NG63w42RfDNhaWqunyLH6V+l0mQsuFBhaQhvbzvO /L07p60VlphV9v5jI2gnYTtSWGlS2XPLFWUQvNWtoWgUb0cJcOwP1jrN31xd9xP+fbtZ CHdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=a+U4jExm; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a8-20020a1709027d8800b0016e5ab112c9si14012258plm.179.2022.08.09.08.37.52; Tue, 09 Aug 2022 08:38:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=a+U4jExm; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242610AbiHIPgC (ORCPT + 99 others); Tue, 9 Aug 2022 11:36:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242751AbiHIPfq (ORCPT ); Tue, 9 Aug 2022 11:35:46 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A671C25F6 for ; Tue, 9 Aug 2022 08:35:43 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id f4-20020a056a00228400b0052fdbb301ddso221073pfe.15 for ; Tue, 09 Aug 2022 08:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=f7QNBZGNnK5yYhhuUlGnKKkabxvWElh1Ug+FZ9u2MZY=; b=a+U4jExmeiVGPDVS/VtZgtsM5CgcPE/IppJwGzKXGunG6gLctOgbV/HwHLJiW4LqOn SkduGFbSnHJrnM0+2DTSS8ITe+UcjruXx4Bf7cg3Or/nalbfUZWrjcLZd1K1j2mZN0qj s/W+N9qND8wus4pLak1UdI6s+hBykKIFt5+MAq24nd5cpca/trMgJrihO0Gt94saBY36 ZRck6GFsg/r6zzlpvVGmXBBlxDAVwjj4A7iEKZs5HihhcXkISZu+lTvgTzrRcu1HLZyv V7Wgr65qpvLexzl4CF9YKaczOcHVai9aNfI/agbYm9X+0KtrGKm1F4Y2MQsQSLWeeJuR X0PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=f7QNBZGNnK5yYhhuUlGnKKkabxvWElh1Ug+FZ9u2MZY=; b=W9kmNMjr+f7XnO1ZS65Ic6URLUZAXz4hvJM37hBXyRKVCmPhjdVFW6fCAal/3bvz8o Unk60+iFSttFwzXFNdqkLM9oG5bd9m4Dyou1L1+ZSw1O0Ac5S062rxcN/pNmuVylcgVE lvyHEQf4FyHfrfNbeAkd2VZjZVZLM8F+dIyUBTVgaBA2RGtXUsvxcusBgjcSwv2m9N1G oAW47sfRwe7jGjyOmXYDLVA7U/IyvWAyTuO1T+8d9xJw+LnE4MVSTArze3tcTHLypkQF C1pS145z2T99kJ95GwL2rHYai6cjrwGL3rDBP3Jl6At0HrCyha+xvRysehZ2aTgkByZE tMvQ== X-Gm-Message-State: ACgBeo1QsulOAwdg2P/2uwwk2H9bOkq/1vR5iiPJG+psu9IgqYc2QF2E 5FTvzNlSJzfyayHXwUp+KthP82nx7zsVbw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:91a6:8007:96f6:3fb3]) (user=mmandlik job=sendgmr) by 2002:a17:90b:394:b0:1f5:90a1:acf0 with SMTP id ga20-20020a17090b039400b001f590a1acf0mr21065299pjb.40.1660059343098; Tue, 09 Aug 2022 08:35:43 -0700 (PDT) Date: Tue, 9 Aug 2022 08:35:24 -0700 In-Reply-To: <20220809083112.v4.1.I5622b2a92dca4d2703a0f747e24f3ef19303e6df@changeid> Message-Id: <20220809083112.v4.2.Ief1110784c6c1c3ac0ee5677c2d28d785af8686d@changeid> Mime-Version: 1.0 References: <20220809083112.v4.1.I5622b2a92dca4d2703a0f747e24f3ef19303e6df@changeid> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog Subject: [PATCH v4 2/5] devcoredump: Add per device sysfs entry to enable/disable coredump From: Manish Mandlik To: Arend van Spriel , marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Manish Mandlik , Abhishek Pandit-Subedi , Dan Williams , Greg Kroah-Hartman , Jason Gunthorpe , Johannes Berg , "Rafael J. Wysocki" , Thomas Gleixner , Won Chung , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 Reviewed-by: Abhishek Pandit-Subedi --- 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); +} + +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 */ + 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); + 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; + struct bus_type *bus; /* type of bus device is on */ struct device_driver *driver; /* which driver has allocated this device */ -- 2.37.1.559.g78731f0fdb-goog