Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'driver-core-3.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core and sysfs updates from Greg KH:
"Here's the big driver core / sysfs update for 3.15-rc1.

Lots of kernfs updates to make it useful for other subsystems, and a
few other tiny driver core patches.

All have been in linux-next for a while"

* tag 'driver-core-3.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (42 commits)
Revert "sysfs, driver-core: remove unused {sysfs|device}_schedule_callback_owner()"
kernfs: cache atomic_write_len in kernfs_open_file
numa: fix NULL pointer access and memory leak in unregister_one_node()
Revert "driver core: synchronize device shutdown"
kernfs: fix off by one error.
kernfs: remove duplicate dir.c at the top dir
x86: align x86 arch with generic CPU modalias handling
cpu: add generic support for CPU feature based module autoloading
sysfs: create bin_attributes under the requested group
driver core: unexport static function create_syslog_header
firmware: use power efficient workqueue for unloading and aborting fw load
firmware: give a protection when map page failed
firmware: google memconsole driver fixes
firmware: fix google/gsmi duplicate efivars_sysfs_init()
drivers/base: delete non-required instances of include <linux/init.h>
kernfs: fix kernfs_node_from_dentry()
ACPI / platform: drop redundant ACPI_HANDLE check
kernfs: fix hash calculation in kernfs_rename_ns()
kernfs: add CONFIG_KERNFS
sysfs, kobject: add sysfs wrapper for kernfs_enable_ns()
...

+1021 -464
+1
arch/s390/include/asm/ccwgroup.h
··· 23 23 unsigned int count; 24 24 struct device dev; 25 25 struct ccw_device *cdev[0]; 26 + struct work_struct ungroup_work; 26 27 }; 27 28 28 29 /**
+8 -10
arch/s390/pci/pci_sysfs.c
··· 48 48 } 49 49 static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL); 50 50 51 - static void recover_callback(struct device *dev) 51 + static ssize_t store_recover(struct device *dev, struct device_attribute *attr, 52 + const char *buf, size_t count) 52 53 { 53 54 struct pci_dev *pdev = to_pci_dev(dev); 54 55 struct zpci_dev *zdev = get_zdev(pdev); 55 56 int ret; 56 57 58 + if (!device_remove_file_self(dev, attr)) 59 + return count; 60 + 57 61 pci_stop_and_remove_bus_device(pdev); 58 62 ret = zpci_disable_device(zdev); 59 63 if (ret) 60 - return; 64 + return ret; 61 65 62 66 ret = zpci_enable_device(zdev); 63 67 if (ret) 64 - return; 68 + return ret; 65 69 66 70 pci_rescan_bus(zdev->bus); 67 - } 68 - 69 - static ssize_t store_recover(struct device *dev, struct device_attribute *attr, 70 - const char *buf, size_t count) 71 - { 72 - int rc = device_schedule_callback(dev, recover_callback); 73 - return rc ? rc : count; 71 + return count; 74 72 } 75 73 static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover); 76 74
+1 -3
arch/x86/Kconfig
··· 127 127 select HAVE_DEBUG_STACKOVERFLOW 128 128 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 129 129 select HAVE_CC_STACKPROTECTOR 130 + select GENERIC_CPU_AUTOPROBE 130 131 131 132 config INSTRUCTION_DECODER 132 133 def_bool y ··· 194 193 def_bool y 195 194 196 195 config ARCH_HAS_CACHE_LINE_SIZE 197 - def_bool y 198 - 199 - config ARCH_HAS_CPU_AUTOPROBE 200 196 def_bool y 201 197 202 198 config HAVE_SETUP_PER_CPU_AREA
+7
arch/x86/include/asm/cpufeature.h
··· 546 546 #define static_cpu_has_bug(bit) static_cpu_has((bit)) 547 547 #define boot_cpu_has_bug(bit) cpu_has_bug(&boot_cpu_data, (bit)) 548 548 549 + #define MAX_CPU_FEATURES (NCAPINTS * 32) 550 + #define cpu_have_feature boot_cpu_has 551 + 552 + #define CPU_FEATURE_TYPEFMT "x86,ven%04Xfam%04Xmod%04X" 553 + #define CPU_FEATURE_TYPEVAL boot_cpu_data.x86_vendor, boot_cpu_data.x86, \ 554 + boot_cpu_data.x86_model 555 + 549 556 #endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ 550 557 551 558 #endif /* _ASM_X86_CPUFEATURE_H */
-42
arch/x86/kernel/cpu/match.c
··· 47 47 return NULL; 48 48 } 49 49 EXPORT_SYMBOL(x86_match_cpu); 50 - 51 - ssize_t arch_print_cpu_modalias(struct device *dev, 52 - struct device_attribute *attr, 53 - char *bufptr) 54 - { 55 - int size = PAGE_SIZE; 56 - int i, n; 57 - char *buf = bufptr; 58 - 59 - n = snprintf(buf, size, "x86cpu:vendor:%04X:family:%04X:" 60 - "model:%04X:feature:", 61 - boot_cpu_data.x86_vendor, 62 - boot_cpu_data.x86, 63 - boot_cpu_data.x86_model); 64 - size -= n; 65 - buf += n; 66 - size -= 1; 67 - for (i = 0; i < NCAPINTS*32; i++) { 68 - if (boot_cpu_has(i)) { 69 - n = snprintf(buf, size, ",%04X", i); 70 - if (n >= size) { 71 - WARN(1, "x86 features overflow page\n"); 72 - break; 73 - } 74 - size -= n; 75 - buf += n; 76 - } 77 - } 78 - *buf++ = '\n'; 79 - return buf - bufptr; 80 - } 81 - 82 - int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env) 83 - { 84 - char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL); 85 - if (buf) { 86 - arch_print_cpu_modalias(NULL, NULL, buf); 87 - add_uevent_var(env, "MODALIAS=%s", buf); 88 - kfree(buf); 89 - } 90 - return 0; 91 - }
+3
drivers/base/Kconfig
··· 185 185 bool 186 186 default n 187 187 188 + config GENERIC_CPU_AUTOPROBE 189 + bool 190 + 188 191 config SOC_BUS 189 192 bool 190 193
-1
drivers/base/attribute_container.c
··· 12 12 */ 13 13 14 14 #include <linux/attribute_container.h> 15 - #include <linux/init.h> 16 15 #include <linux/device.h> 17 16 #include <linux/kernel.h> 18 17 #include <linux/slab.h>
+17 -3
drivers/base/core.c
··· 23 23 #include <linux/genhd.h> 24 24 #include <linux/kallsyms.h> 25 25 #include <linux/mutex.h> 26 - #include <linux/async.h> 27 26 #include <linux/pm_runtime.h> 28 27 #include <linux/netdevice.h> 29 28 #include <linux/sysfs.h> ··· 568 569 sysfs_remove_file(&dev->kobj, &attr->attr); 569 570 } 570 571 EXPORT_SYMBOL_GPL(device_remove_file); 572 + 573 + /** 574 + * device_remove_file_self - remove sysfs attribute file from its own method. 575 + * @dev: device. 576 + * @attr: device attribute descriptor. 577 + * 578 + * See kernfs_remove_self() for details. 579 + */ 580 + bool device_remove_file_self(struct device *dev, 581 + const struct device_attribute *attr) 582 + { 583 + if (dev) 584 + return sysfs_remove_file_self(&dev->kobj, &attr->attr); 585 + else 586 + return false; 587 + } 588 + EXPORT_SYMBOL_GPL(device_remove_file_self); 571 589 572 590 /** 573 591 * device_create_bin_file - create sysfs binary attribute file for device. ··· 2019 2003 spin_lock(&devices_kset->list_lock); 2020 2004 } 2021 2005 spin_unlock(&devices_kset->list_lock); 2022 - async_synchronize_full(); 2023 2006 } 2024 2007 2025 2008 /* ··· 2073 2058 2074 2059 return pos; 2075 2060 } 2076 - EXPORT_SYMBOL(create_syslog_header); 2077 2061 2078 2062 int dev_vprintk_emit(int level, const struct device *dev, 2079 2063 const char *fmt, va_list args)
+41 -5
drivers/base/cpu.c
··· 15 15 #include <linux/percpu.h> 16 16 #include <linux/acpi.h> 17 17 #include <linux/of.h> 18 + #include <linux/cpufeature.h> 18 19 19 20 #include "base.h" 20 21 ··· 287 286 */ 288 287 } 289 288 289 + #ifdef CONFIG_GENERIC_CPU_AUTOPROBE 290 + static ssize_t print_cpu_modalias(struct device *dev, 291 + struct device_attribute *attr, 292 + char *buf) 293 + { 294 + ssize_t n; 295 + u32 i; 296 + 297 + n = sprintf(buf, "cpu:type:" CPU_FEATURE_TYPEFMT ":feature:", 298 + CPU_FEATURE_TYPEVAL); 299 + 300 + for (i = 0; i < MAX_CPU_FEATURES; i++) 301 + if (cpu_have_feature(i)) { 302 + if (PAGE_SIZE < n + sizeof(",XXXX\n")) { 303 + WARN(1, "CPU features overflow page\n"); 304 + break; 305 + } 306 + n += sprintf(&buf[n], ",%04X", i); 307 + } 308 + buf[n++] = '\n'; 309 + return n; 310 + } 311 + 312 + static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env) 313 + { 314 + char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL); 315 + if (buf) { 316 + print_cpu_modalias(NULL, NULL, buf); 317 + add_uevent_var(env, "MODALIAS=%s", buf); 318 + kfree(buf); 319 + } 320 + return 0; 321 + } 322 + #endif 323 + 290 324 /* 291 325 * register_cpu - Setup a sysfs device for a CPU. 292 326 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in ··· 342 306 cpu->dev.offline_disabled = !cpu->hotpluggable; 343 307 cpu->dev.offline = !cpu_online(num); 344 308 cpu->dev.of_node = of_get_cpu_node(num, NULL); 345 - #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE 346 - cpu->dev.bus->uevent = arch_cpu_uevent; 309 + #ifdef CONFIG_GENERIC_CPU_AUTOPROBE 310 + cpu->dev.bus->uevent = cpu_uevent; 347 311 #endif 348 312 cpu->dev.groups = common_cpu_attr_groups; 349 313 if (cpu->hotpluggable) ··· 366 330 } 367 331 EXPORT_SYMBOL_GPL(get_cpu_device); 368 332 369 - #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE 370 - static DEVICE_ATTR(modalias, 0444, arch_print_cpu_modalias, NULL); 333 + #ifdef CONFIG_GENERIC_CPU_AUTOPROBE 334 + static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL); 371 335 #endif 372 336 373 337 static struct attribute *cpu_root_attrs[] = { ··· 380 344 &cpu_attrs[2].attr.attr, 381 345 &dev_attr_kernel_max.attr, 382 346 &dev_attr_offline.attr, 383 - #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE 347 + #ifdef CONFIG_GENERIC_CPU_AUTOPROBE 384 348 &dev_attr_modalias.attr, 385 349 #endif 386 350 NULL
+11 -7
drivers/base/dma-buf.c
··· 251 251 * @dmabuf: [in] buffer to attach device to. 252 252 * @dev: [in] device to be attached. 253 253 * 254 - * Returns struct dma_buf_attachment * for this attachment; may return negative 255 - * error codes. 256 - * 254 + * Returns struct dma_buf_attachment * for this attachment; returns ERR_PTR on 255 + * error. 257 256 */ 258 257 struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, 259 258 struct device *dev) ··· 318 319 * @attach: [in] attachment whose scatterlist is to be returned 319 320 * @direction: [in] direction of DMA transfer 320 321 * 321 - * Returns sg_table containing the scatterlist to be returned; may return NULL 322 - * or ERR_PTR. 323 - * 322 + * Returns sg_table containing the scatterlist to be returned; returns ERR_PTR 323 + * on error. 324 324 */ 325 325 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, 326 326 enum dma_data_direction direction) ··· 332 334 return ERR_PTR(-EINVAL); 333 335 334 336 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); 337 + if (!sg_table) 338 + sg_table = ERR_PTR(-ENOMEM); 335 339 336 340 return sg_table; 337 341 } ··· 544 544 * These calls are optional in drivers. The intended use for them 545 545 * is for mapping objects linear in kernel space for high use objects. 546 546 * Please attempt to use kmap/kunmap before thinking about these interfaces. 547 + * 548 + * Returns NULL on error. 547 549 */ 548 550 void *dma_buf_vmap(struct dma_buf *dmabuf) 549 551 { ··· 568 566 BUG_ON(dmabuf->vmap_ptr); 569 567 570 568 ptr = dmabuf->ops->vmap(dmabuf); 571 - if (IS_ERR_OR_NULL(ptr)) 569 + if (WARN_ON_ONCE(IS_ERR(ptr))) 570 + ptr = NULL; 571 + if (!ptr) 572 572 goto out_unlock; 573 573 574 574 dmabuf->vmap_ptr = ptr;
+9 -4
drivers/base/firmware_class.c
··· 649 649 * see the mapped 'buf->data' once the loading 650 650 * is completed. 651 651 * */ 652 - fw_map_pages_buf(fw_buf); 652 + if (fw_map_pages_buf(fw_buf)) 653 + dev_err(dev, "%s: map pages failed\n", 654 + __func__); 653 655 list_del_init(&fw_buf->pending_list); 654 656 complete_all(&fw_buf->completion); 655 657 break; ··· 902 900 dev_set_uevent_suppress(f_dev, false); 903 901 dev_dbg(f_dev, "firmware: requesting %s\n", buf->fw_id); 904 902 if (timeout != MAX_SCHEDULE_TIMEOUT) 905 - schedule_delayed_work(&fw_priv->timeout_work, timeout); 903 + queue_delayed_work(system_power_efficient_wq, 904 + &fw_priv->timeout_work, timeout); 906 905 907 906 kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD); 908 907 } ··· 911 908 wait_for_completion(&buf->completion); 912 909 913 910 cancel_delayed_work_sync(&fw_priv->timeout_work); 911 + if (!buf->data) 912 + retval = -ENOMEM; 914 913 915 914 device_remove_file(f_dev, &dev_attr_loading); 916 915 err_del_bin_attr: ··· 1575 1570 */ 1576 1571 static void device_uncache_fw_images_delay(unsigned long delay) 1577 1572 { 1578 - schedule_delayed_work(&fw_cache.work, 1579 - msecs_to_jiffies(delay)); 1573 + queue_delayed_work(system_power_efficient_wq, &fw_cache.work, 1574 + msecs_to_jiffies(delay)); 1580 1575 } 1581 1576 1582 1577 static int fw_pm_notify(struct notifier_block *notify_block,
+4
drivers/base/node.c
··· 599 599 600 600 void unregister_one_node(int nid) 601 601 { 602 + if (!node_devices[nid]) 603 + return; 604 + 602 605 unregister_node(node_devices[nid]); 606 + kfree(node_devices[nid]); 603 607 node_devices[nid] = NULL; 604 608 } 605 609
+4 -7
drivers/base/platform.c
··· 481 481 struct platform_device *dev = to_platform_device(_dev); 482 482 int ret; 483 483 484 - if (ACPI_HANDLE(_dev)) 485 - acpi_dev_pm_attach(_dev, true); 484 + acpi_dev_pm_attach(_dev, true); 486 485 487 486 ret = drv->probe(dev); 488 - if (ret && ACPI_HANDLE(_dev)) 487 + if (ret) 489 488 acpi_dev_pm_detach(_dev, true); 490 489 491 490 if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) { ··· 507 508 int ret; 508 509 509 510 ret = drv->remove(dev); 510 - if (ACPI_HANDLE(_dev)) 511 - acpi_dev_pm_detach(_dev, true); 511 + acpi_dev_pm_detach(_dev, true); 512 512 513 513 return ret; 514 514 } ··· 518 520 struct platform_device *dev = to_platform_device(_dev); 519 521 520 522 drv->shutdown(dev); 521 - if (ACPI_HANDLE(_dev)) 522 - acpi_dev_pm_detach(_dev, true); 523 + acpi_dev_pm_detach(_dev, true); 523 524 } 524 525 525 526 /**
-1
drivers/base/power/clock_ops.c
··· 6 6 * This file is released under the GPLv2. 7 7 */ 8 8 9 - #include <linux/init.h> 10 9 #include <linux/kernel.h> 11 10 #include <linux/device.h> 12 11 #include <linux/io.h>
-1
drivers/base/power/common.c
··· 6 6 * This file is released under the GPLv2. 7 7 */ 8 8 9 - #include <linux/init.h> 10 9 #include <linux/kernel.h> 11 10 #include <linux/device.h> 12 11 #include <linux/export.h>
-1
drivers/base/power/domain.c
··· 6 6 * This file is released under the GPLv2. 7 7 */ 8 8 9 - #include <linux/init.h> 10 9 #include <linux/kernel.h> 11 10 #include <linux/io.h> 12 11 #include <linux/pm_runtime.h>
-1
drivers/base/power/domain_governor.c
··· 6 6 * This file is released under the GPLv2. 7 7 */ 8 8 9 - #include <linux/init.h> 10 9 #include <linux/kernel.h> 11 10 #include <linux/pm_domain.h> 12 11 #include <linux/pm_qos.h>
-1
drivers/base/power/opp.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/errno.h> 16 16 #include <linux/err.h> 17 - #include <linux/init.h> 18 17 #include <linux/slab.h> 19 18 #include <linux/cpufreq.h> 20 19 #include <linux/device.h>
-1
drivers/base/regmap/regmap-i2c.c
··· 13 13 #include <linux/regmap.h> 14 14 #include <linux/i2c.h> 15 15 #include <linux/module.h> 16 - #include <linux/init.h> 17 16 18 17 static int regmap_i2c_write(void *context, const void *data, size_t count) 19 18 {
-1
drivers/base/regmap/regmap-mmio.c
··· 18 18 19 19 #include <linux/clk.h> 20 20 #include <linux/err.h> 21 - #include <linux/init.h> 22 21 #include <linux/io.h> 23 22 #include <linux/module.h> 24 23 #include <linux/regmap.h>
-1
drivers/base/regmap/regmap-spi.c
··· 12 12 13 13 #include <linux/regmap.h> 14 14 #include <linux/spi/spi.h> 15 - #include <linux/init.h> 16 15 #include <linux/module.h> 17 16 18 17 #include "internal.h"
-1
drivers/base/topology.c
··· 23 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 24 * 25 25 */ 26 - #include <linux/init.h> 27 26 #include <linux/mm.h> 28 27 #include <linux/cpu.h> 29 28 #include <linux/module.h>
-7
drivers/firmware/google/gsmi.c
··· 892 892 goto out_remove_sysfs_files; 893 893 } 894 894 895 - ret = efivars_sysfs_init(); 896 - if (ret) { 897 - printk(KERN_INFO "gsmi: Failed to create efivars files\n"); 898 - efivars_unregister(&efivars); 899 - goto out_remove_sysfs_files; 900 - } 901 - 902 895 register_reboot_notifier(&gsmi_reboot_notifier); 903 896 register_die_notifier(&gsmi_die_notifier); 904 897 atomic_notifier_chain_register(&panic_notifier_list,
+26 -21
drivers/firmware/google/memconsole.c
··· 15 15 #include <linux/kobject.h> 16 16 #include <linux/module.h> 17 17 #include <linux/dmi.h> 18 + #include <linux/io.h> 18 19 #include <asm/bios_ebda.h> 19 20 20 21 #define BIOS_MEMCONSOLE_V1_MAGIC 0xDEADBABE ··· 42 41 }; 43 42 } __packed; 44 43 45 - static char *memconsole_baseaddr; 44 + static u32 memconsole_baseaddr; 46 45 static size_t memconsole_length; 47 46 48 47 static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, 49 48 struct bin_attribute *bin_attr, char *buf, 50 49 loff_t pos, size_t count) 51 50 { 52 - return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, 53 - memconsole_length); 51 + char *memconsole; 52 + ssize_t ret; 53 + 54 + memconsole = ioremap_cache(memconsole_baseaddr, memconsole_length); 55 + if (!memconsole) { 56 + pr_err("memconsole: ioremap_cache failed\n"); 57 + return -ENOMEM; 58 + } 59 + ret = memory_read_from_buffer(buf, count, &pos, memconsole, 60 + memconsole_length); 61 + iounmap(memconsole); 62 + return ret; 54 63 } 55 64 56 65 static struct bin_attribute memconsole_bin_attr = { ··· 69 58 }; 70 59 71 60 72 - static void found_v1_header(struct biosmemcon_ebda *hdr) 61 + static void __init found_v1_header(struct biosmemcon_ebda *hdr) 73 62 { 74 - printk(KERN_INFO "BIOS console v1 EBDA structure found at %p\n", hdr); 75 - printk(KERN_INFO "BIOS console buffer at 0x%.8x, " 63 + pr_info("BIOS console v1 EBDA structure found at %p\n", hdr); 64 + pr_info("BIOS console buffer at 0x%.8x, " 76 65 "start = %d, end = %d, num = %d\n", 77 66 hdr->v1.buffer_addr, hdr->v1.start, 78 67 hdr->v1.end, hdr->v1.num_chars); 79 68 80 69 memconsole_length = hdr->v1.num_chars; 81 - memconsole_baseaddr = phys_to_virt(hdr->v1.buffer_addr); 70 + memconsole_baseaddr = hdr->v1.buffer_addr; 82 71 } 83 72 84 - static void found_v2_header(struct biosmemcon_ebda *hdr) 73 + static void __init found_v2_header(struct biosmemcon_ebda *hdr) 85 74 { 86 - printk(KERN_INFO "BIOS console v2 EBDA structure found at %p\n", hdr); 87 - printk(KERN_INFO "BIOS console buffer at 0x%.8x, " 75 + pr_info("BIOS console v2 EBDA structure found at %p\n", hdr); 76 + pr_info("BIOS console buffer at 0x%.8x, " 88 77 "start = %d, end = %d, num_bytes = %d\n", 89 78 hdr->v2.buffer_addr, hdr->v2.start, 90 79 hdr->v2.end, hdr->v2.num_bytes); 91 80 92 81 memconsole_length = hdr->v2.end - hdr->v2.start; 93 - memconsole_baseaddr = phys_to_virt(hdr->v2.buffer_addr 94 - + hdr->v2.start); 82 + memconsole_baseaddr = hdr->v2.buffer_addr + hdr->v2.start; 95 83 } 96 84 97 85 /* 98 86 * Search through the EBDA for the BIOS Memory Console, and 99 87 * set the global variables to point to it. Return true if found. 100 88 */ 101 - static bool found_memconsole(void) 89 + static bool __init found_memconsole(void) 102 90 { 103 91 unsigned int address; 104 92 size_t length, cur; 105 93 106 94 address = get_bios_ebda(); 107 95 if (!address) { 108 - printk(KERN_INFO "BIOS EBDA non-existent.\n"); 96 + pr_info("BIOS EBDA non-existent.\n"); 109 97 return false; 110 98 } 111 99 ··· 132 122 } 133 123 } 134 124 135 - printk(KERN_INFO "BIOS console EBDA structure not found!\n"); 125 + pr_info("BIOS console EBDA structure not found!\n"); 136 126 return false; 137 127 } 138 128 ··· 149 139 150 140 static int __init memconsole_init(void) 151 141 { 152 - int ret; 153 - 154 142 if (!dmi_check_system(memconsole_dmi_table)) 155 143 return -ENODEV; 156 144 ··· 156 148 return -ENODEV; 157 149 158 150 memconsole_bin_attr.size = memconsole_length; 159 - 160 - ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); 161 - 162 - return ret; 151 + return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); 163 152 } 164 153 165 154 static void __exit memconsole_exit(void)
+1 -1
drivers/gpu/drm/drm_prime.c
··· 471 471 get_dma_buf(dma_buf); 472 472 473 473 sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); 474 - if (IS_ERR_OR_NULL(sgt)) { 474 + if (IS_ERR(sgt)) { 475 475 ret = PTR_ERR(sgt); 476 476 goto fail_detach; 477 477 }
+1 -1
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
··· 224 224 get_dma_buf(dma_buf); 225 225 226 226 sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); 227 - if (IS_ERR_OR_NULL(sgt)) { 227 + if (IS_ERR(sgt)) { 228 228 ret = PTR_ERR(sgt); 229 229 goto err_buf_detach; 230 230 }
+1 -1
drivers/media/v4l2-core/videobuf2-dma-contig.c
··· 719 719 720 720 /* get the associated scatterlist for this buffer */ 721 721 sgt = dma_buf_map_attachment(buf->db_attach, buf->dma_dir); 722 - if (IS_ERR_OR_NULL(sgt)) { 722 + if (IS_ERR(sgt)) { 723 723 pr_err("Error getting dmabuf scatterlist\n"); 724 724 return -EINVAL; 725 725 }
+3 -14
drivers/pci/pci-sysfs.c
··· 351 351 (S_IWUSR|S_IWGRP), 352 352 NULL, dev_rescan_store); 353 353 354 - static void remove_callback(struct device *dev) 355 - { 356 - pci_stop_and_remove_bus_device_locked(to_pci_dev(dev)); 357 - } 358 - 359 354 static ssize_t 360 - remove_store(struct device *dev, struct device_attribute *dummy, 355 + remove_store(struct device *dev, struct device_attribute *attr, 361 356 const char *buf, size_t count) 362 357 { 363 - int ret = 0; 364 358 unsigned long val; 365 359 366 360 if (kstrtoul(buf, 0, &val) < 0) 367 361 return -EINVAL; 368 362 369 - /* An attribute cannot be unregistered by one of its own methods, 370 - * so we have to use this roundabout approach. 371 - */ 372 - if (val) 373 - ret = device_schedule_callback(dev, remove_callback); 374 - if (ret) 375 - count = ret; 363 + if (val && device_remove_file_self(dev, attr)) 364 + pci_stop_and_remove_bus_device_locked(to_pci_dev(dev)); 376 365 return count; 377 366 } 378 367 static struct device_attribute dev_remove_attr = __ATTR(remove,
+7 -7
drivers/s390/block/dcssblk.c
··· 304 304 return rc; 305 305 } 306 306 307 - static void dcssblk_unregister_callback(struct device *dev) 308 - { 309 - device_unregister(dev); 310 - put_device(dev); 311 - } 312 - 313 307 /* 314 308 * device attribute for switching shared/nonshared (exclusive) 315 309 * operation (show + store) ··· 391 397 blk_cleanup_queue(dev_info->dcssblk_queue); 392 398 dev_info->gd->queue = NULL; 393 399 put_disk(dev_info->gd); 394 - rc = device_schedule_callback(dev, dcssblk_unregister_callback); 400 + up_write(&dcssblk_devices_sem); 401 + 402 + if (device_remove_file_self(dev, attr)) { 403 + device_unregister(dev); 404 + put_device(dev); 405 + } 406 + return rc; 395 407 out: 396 408 up_write(&dcssblk_devices_sem); 397 409 return rc;
+16 -10
drivers/s390/cio/ccwgroup.c
··· 168 168 * Provide an 'ungroup' attribute so the user can remove group devices no 169 169 * longer needed or accidentially created. Saves memory :) 170 170 */ 171 - static void ccwgroup_ungroup_callback(struct device *dev) 171 + static void ccwgroup_ungroup(struct ccwgroup_device *gdev) 172 172 { 173 - struct ccwgroup_device *gdev = to_ccwgroupdev(dev); 174 - 175 173 mutex_lock(&gdev->reg_mutex); 176 174 if (device_is_registered(&gdev->dev)) { 177 175 __ccwgroup_remove_symlinks(gdev); 178 - device_unregister(dev); 176 + device_unregister(&gdev->dev); 179 177 __ccwgroup_remove_cdev_refs(gdev); 180 178 } 181 179 mutex_unlock(&gdev->reg_mutex); ··· 193 195 rc = -EINVAL; 194 196 goto out; 195 197 } 196 - /* Note that we cannot unregister the device from one of its 197 - * attribute methods, so we have to use this roundabout approach. 198 - */ 199 - rc = device_schedule_callback(dev, ccwgroup_ungroup_callback); 198 + 199 + if (device_remove_file_self(dev, attr)) 200 + ccwgroup_ungroup(gdev); 200 201 out: 201 202 if (rc) { 202 203 if (rc != -EAGAIN) ··· 220 223 &ccwgroup_attr_group, 221 224 NULL, 222 225 }; 226 + 227 + static void ccwgroup_ungroup_workfn(struct work_struct *work) 228 + { 229 + struct ccwgroup_device *gdev = 230 + container_of(work, struct ccwgroup_device, ungroup_work); 231 + 232 + ccwgroup_ungroup(gdev); 233 + } 223 234 224 235 static void ccwgroup_release(struct device *dev) 225 236 { ··· 328 323 atomic_set(&gdev->onoff, 0); 329 324 mutex_init(&gdev->reg_mutex); 330 325 mutex_lock(&gdev->reg_mutex); 326 + INIT_WORK(&gdev->ungroup_work, ccwgroup_ungroup_workfn); 331 327 gdev->count = num_devices; 332 328 gdev->dev.bus = &ccwgroup_bus_type; 333 329 gdev->dev.parent = parent; ··· 410 404 static int ccwgroup_notifier(struct notifier_block *nb, unsigned long action, 411 405 void *data) 412 406 { 413 - struct device *dev = data; 407 + struct ccwgroup_device *gdev = to_ccwgroupdev(data); 414 408 415 409 if (action == BUS_NOTIFY_UNBIND_DRIVER) 416 - device_schedule_callback(dev, ccwgroup_ungroup_callback); 410 + schedule_work(&gdev->ungroup_work); 417 411 418 412 return NOTIFY_OK; 419 413 }
+2 -13
drivers/scsi/scsi_sysfs.c
··· 649 649 } 650 650 static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field); 651 651 652 - static void sdev_store_delete_callback(struct device *dev) 653 - { 654 - scsi_remove_device(to_scsi_device(dev)); 655 - } 656 - 657 652 static ssize_t 658 653 sdev_store_delete(struct device *dev, struct device_attribute *attr, 659 654 const char *buf, size_t count) 660 655 { 661 - int rc; 662 - 663 - /* An attribute cannot be unregistered by one of its own methods, 664 - * so we have to use this roundabout approach. 665 - */ 666 - rc = device_schedule_callback(dev, sdev_store_delete_callback); 667 - if (rc) 668 - count = rc; 656 + if (device_remove_file_self(dev, attr)) 657 + scsi_remove_device(to_scsi_device(dev)); 669 658 return count; 670 659 }; 671 660 static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
+1
fs/Kconfig
··· 96 96 menu "Pseudo filesystems" 97 97 98 98 source "fs/proc/Kconfig" 99 + source "fs/kernfs/Kconfig" 99 100 source "fs/sysfs/Kconfig" 100 101 101 102 config TMPFS
+2 -1
fs/Makefile
··· 52 52 obj-y += quota/ 53 53 54 54 obj-$(CONFIG_PROC_FS) += proc/ 55 - obj-$(CONFIG_SYSFS) += sysfs/ kernfs/ 55 + obj-$(CONFIG_KERNFS) += kernfs/ 56 + obj-$(CONFIG_SYSFS) += sysfs/ 56 57 obj-$(CONFIG_CONFIGFS_FS) += configfs/ 57 58 obj-y += devpts/ 58 59
+7
fs/kernfs/Kconfig
··· 1 + # 2 + # KERNFS should be selected by its users 3 + # 4 + 5 + config KERNFS 6 + bool 7 + default n
+554 -204
fs/kernfs/dir.c
··· 8 8 * This file is released under the GPLv2. 9 9 */ 10 10 11 + #include <linux/sched.h> 11 12 #include <linux/fs.h> 12 13 #include <linux/namei.h> 13 14 #include <linux/idr.h> ··· 19 18 #include "kernfs-internal.h" 20 19 21 20 DEFINE_MUTEX(kernfs_mutex); 21 + static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */ 22 + static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by rename_lock */ 22 23 23 24 #define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb) 25 + 26 + static bool kernfs_active(struct kernfs_node *kn) 27 + { 28 + lockdep_assert_held(&kernfs_mutex); 29 + return atomic_read(&kn->active) >= 0; 30 + } 31 + 32 + static bool kernfs_lockdep(struct kernfs_node *kn) 33 + { 34 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 35 + return kn->flags & KERNFS_LOCKDEP; 36 + #else 37 + return false; 38 + #endif 39 + } 40 + 41 + static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen) 42 + { 43 + return strlcpy(buf, kn->parent ? kn->name : "/", buflen); 44 + } 45 + 46 + static char * __must_check kernfs_path_locked(struct kernfs_node *kn, char *buf, 47 + size_t buflen) 48 + { 49 + char *p = buf + buflen; 50 + int len; 51 + 52 + *--p = '\0'; 53 + 54 + do { 55 + len = strlen(kn->name); 56 + if (p - buf < len + 1) { 57 + buf[0] = '\0'; 58 + p = NULL; 59 + break; 60 + } 61 + p -= len; 62 + memcpy(p, kn->name, len); 63 + *--p = '/'; 64 + kn = kn->parent; 65 + } while (kn && kn->parent); 66 + 67 + return p; 68 + } 69 + 70 + /** 71 + * kernfs_name - obtain the name of a given node 72 + * @kn: kernfs_node of interest 73 + * @buf: buffer to copy @kn's name into 74 + * @buflen: size of @buf 75 + * 76 + * Copies the name of @kn into @buf of @buflen bytes. The behavior is 77 + * similar to strlcpy(). It returns the length of @kn's name and if @buf 78 + * isn't long enough, it's filled upto @buflen-1 and nul terminated. 79 + * 80 + * This function can be called from any context. 81 + */ 82 + int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) 83 + { 84 + unsigned long flags; 85 + int ret; 86 + 87 + spin_lock_irqsave(&kernfs_rename_lock, flags); 88 + ret = kernfs_name_locked(kn, buf, buflen); 89 + spin_unlock_irqrestore(&kernfs_rename_lock, flags); 90 + return ret; 91 + } 92 + 93 + /** 94 + * kernfs_path - build full path of a given node 95 + * @kn: kernfs_node of interest 96 + * @buf: buffer to copy @kn's name into 97 + * @buflen: size of @buf 98 + * 99 + * Builds and returns the full path of @kn in @buf of @buflen bytes. The 100 + * path is built from the end of @buf so the returned pointer usually 101 + * doesn't match @buf. If @buf isn't long enough, @buf is nul terminated 102 + * and %NULL is returned. 103 + */ 104 + char *kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen) 105 + { 106 + unsigned long flags; 107 + char *p; 108 + 109 + spin_lock_irqsave(&kernfs_rename_lock, flags); 110 + p = kernfs_path_locked(kn, buf, buflen); 111 + spin_unlock_irqrestore(&kernfs_rename_lock, flags); 112 + return p; 113 + } 114 + 115 + /** 116 + * pr_cont_kernfs_name - pr_cont name of a kernfs_node 117 + * @kn: kernfs_node of interest 118 + * 119 + * This function can be called from any context. 120 + */ 121 + void pr_cont_kernfs_name(struct kernfs_node *kn) 122 + { 123 + unsigned long flags; 124 + 125 + spin_lock_irqsave(&kernfs_rename_lock, flags); 126 + 127 + kernfs_name_locked(kn, kernfs_pr_cont_buf, sizeof(kernfs_pr_cont_buf)); 128 + pr_cont("%s", kernfs_pr_cont_buf); 129 + 130 + spin_unlock_irqrestore(&kernfs_rename_lock, flags); 131 + } 132 + 133 + /** 134 + * pr_cont_kernfs_path - pr_cont path of a kernfs_node 135 + * @kn: kernfs_node of interest 136 + * 137 + * This function can be called from any context. 138 + */ 139 + void pr_cont_kernfs_path(struct kernfs_node *kn) 140 + { 141 + unsigned long flags; 142 + char *p; 143 + 144 + spin_lock_irqsave(&kernfs_rename_lock, flags); 145 + 146 + p = kernfs_path_locked(kn, kernfs_pr_cont_buf, 147 + sizeof(kernfs_pr_cont_buf)); 148 + if (p) 149 + pr_cont("%s", p); 150 + else 151 + pr_cont("<name too long>"); 152 + 153 + spin_unlock_irqrestore(&kernfs_rename_lock, flags); 154 + } 155 + 156 + /** 157 + * kernfs_get_parent - determine the parent node and pin it 158 + * @kn: kernfs_node of interest 159 + * 160 + * Determines @kn's parent, pins and returns it. This function can be 161 + * called from any context. 162 + */ 163 + struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn) 164 + { 165 + struct kernfs_node *parent; 166 + unsigned long flags; 167 + 168 + spin_lock_irqsave(&kernfs_rename_lock, flags); 169 + parent = kn->parent; 170 + kernfs_get(parent); 171 + spin_unlock_irqrestore(&kernfs_rename_lock, flags); 172 + 173 + return parent; 174 + } 24 175 25 176 /** 26 177 * kernfs_name_hash ··· 190 37 hash = (end_name_hash(hash) ^ hash_ptr((void *)ns, 31)); 191 38 hash &= 0x7fffffffU; 192 39 /* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */ 193 - if (hash < 1) 40 + if (hash < 2) 194 41 hash += 2; 195 42 if (hash >= INT_MAX) 196 43 hash = INT_MAX - 1; ··· 258 105 * kernfs_unlink_sibling - unlink kernfs_node from sibling rbtree 259 106 * @kn: kernfs_node of interest 260 107 * 261 - * Unlink @kn from its sibling rbtree which starts from 262 - * kn->parent->dir.children. 108 + * Try to unlink @kn from its sibling rbtree which starts from 109 + * kn->parent->dir.children. Returns %true if @kn was actually 110 + * removed, %false if @kn wasn't on the rbtree. 263 111 * 264 112 * Locking: 265 113 * mutex_lock(kernfs_mutex) 266 114 */ 267 - static void kernfs_unlink_sibling(struct kernfs_node *kn) 115 + static bool kernfs_unlink_sibling(struct kernfs_node *kn) 268 116 { 117 + if (RB_EMPTY_NODE(&kn->rb)) 118 + return false; 119 + 269 120 if (kernfs_type(kn) == KERNFS_DIR) 270 121 kn->parent->dir.subdirs--; 271 122 272 123 rb_erase(&kn->rb, &kn->parent->dir.children); 124 + RB_CLEAR_NODE(&kn->rb); 125 + return true; 273 126 } 274 127 275 128 /** ··· 296 137 if (!atomic_inc_unless_negative(&kn->active)) 297 138 return NULL; 298 139 299 - if (kn->flags & KERNFS_LOCKDEP) 140 + if (kernfs_lockdep(kn)) 300 141 rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_); 301 142 return kn; 302 143 } ··· 310 151 */ 311 152 void kernfs_put_active(struct kernfs_node *kn) 312 153 { 154 + struct kernfs_root *root = kernfs_root(kn); 313 155 int v; 314 156 315 157 if (unlikely(!kn)) 316 158 return; 317 159 318 - if (kn->flags & KERNFS_LOCKDEP) 160 + if (kernfs_lockdep(kn)) 319 161 rwsem_release(&kn->dep_map, 1, _RET_IP_); 320 162 v = atomic_dec_return(&kn->active); 321 163 if (likely(v != KN_DEACTIVATED_BIAS)) 322 164 return; 323 165 324 - /* 325 - * atomic_dec_return() is a mb(), we'll always see the updated 326 - * kn->u.completion. 327 - */ 328 - complete(kn->u.completion); 166 + wake_up_all(&root->deactivate_waitq); 329 167 } 330 168 331 169 /** 332 - * kernfs_deactivate - deactivate kernfs_node 333 - * @kn: kernfs_node to deactivate 170 + * kernfs_drain - drain kernfs_node 171 + * @kn: kernfs_node to drain 334 172 * 335 - * Deny new active references and drain existing ones. 173 + * Drain existing usages and nuke all existing mmaps of @kn. Mutiple 174 + * removers may invoke this function concurrently on @kn and all will 175 + * return after draining is complete. 336 176 */ 337 - static void kernfs_deactivate(struct kernfs_node *kn) 177 + static void kernfs_drain(struct kernfs_node *kn) 178 + __releases(&kernfs_mutex) __acquires(&kernfs_mutex) 338 179 { 339 - DECLARE_COMPLETION_ONSTACK(wait); 340 - int v; 180 + struct kernfs_root *root = kernfs_root(kn); 341 181 342 - BUG_ON(!(kn->flags & KERNFS_REMOVED)); 182 + lockdep_assert_held(&kernfs_mutex); 183 + WARN_ON_ONCE(kernfs_active(kn)); 343 184 344 - if (!(kernfs_type(kn) & KERNFS_ACTIVE_REF)) 345 - return; 185 + mutex_unlock(&kernfs_mutex); 346 186 347 - kn->u.completion = (void *)&wait; 348 - 349 - if (kn->flags & KERNFS_LOCKDEP) 187 + if (kernfs_lockdep(kn)) { 350 188 rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); 351 - /* atomic_add_return() is a mb(), put_active() will always see 352 - * the updated kn->u.completion. 353 - */ 354 - v = atomic_add_return(KN_DEACTIVATED_BIAS, &kn->active); 355 - 356 - if (v != KN_DEACTIVATED_BIAS) { 357 - if (kn->flags & KERNFS_LOCKDEP) 189 + if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS) 358 190 lock_contended(&kn->dep_map, _RET_IP_); 359 - wait_for_completion(&wait); 360 191 } 361 192 362 - if (kn->flags & KERNFS_LOCKDEP) { 193 + /* but everyone should wait for draining */ 194 + wait_event(root->deactivate_waitq, 195 + atomic_read(&kn->active) == KN_DEACTIVATED_BIAS); 196 + 197 + if (kernfs_lockdep(kn)) { 363 198 lock_acquired(&kn->dep_map, _RET_IP_); 364 199 rwsem_release(&kn->dep_map, 1, _RET_IP_); 365 200 } 201 + 202 + kernfs_unmap_bin_file(kn); 203 + 204 + mutex_lock(&kernfs_mutex); 366 205 } 367 206 368 207 /** ··· 391 234 return; 392 235 root = kernfs_root(kn); 393 236 repeat: 394 - /* Moving/renaming is always done while holding reference. 237 + /* 238 + * Moving/renaming is always done while holding reference. 395 239 * kn->parent won't change beneath us. 396 240 */ 397 241 parent = kn->parent; 398 242 399 - WARN(!(kn->flags & KERNFS_REMOVED), "kernfs: free using entry: %s/%s\n", 400 - parent ? parent->name : "", kn->name); 243 + WARN_ONCE(atomic_read(&kn->active) != KN_DEACTIVATED_BIAS, 244 + "kernfs_put: %s/%s: released with incorrect active_ref %d\n", 245 + parent ? parent->name : "", kn->name, atomic_read(&kn->active)); 401 246 402 247 if (kernfs_type(kn) == KERNFS_LINK) 403 248 kernfs_put(kn->symlink.target_kn); ··· 441 282 kn = dentry->d_fsdata; 442 283 mutex_lock(&kernfs_mutex); 443 284 444 - /* The kernfs node has been deleted */ 445 - if (kn->flags & KERNFS_REMOVED) 285 + /* The kernfs node has been deactivated */ 286 + if (!kernfs_active(kn)) 446 287 goto out_bad; 447 288 448 289 /* The kernfs node has been moved? */ ··· 487 328 .d_release = kernfs_dop_release, 488 329 }; 489 330 331 + /** 332 + * kernfs_node_from_dentry - determine kernfs_node associated with a dentry 333 + * @dentry: the dentry in question 334 + * 335 + * Return the kernfs_node associated with @dentry. If @dentry is not a 336 + * kernfs one, %NULL is returned. 337 + * 338 + * While the returned kernfs_node will stay accessible as long as @dentry 339 + * is accessible, the returned node can be in any state and the caller is 340 + * fully responsible for determining what's accessible. 341 + */ 342 + struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry) 343 + { 344 + if (dentry->d_sb->s_op == &kernfs_sops) 345 + return dentry->d_fsdata; 346 + return NULL; 347 + } 348 + 490 349 static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, 491 350 const char *name, umode_t mode, 492 351 unsigned flags) ··· 529 352 kn->ino = ret; 530 353 531 354 atomic_set(&kn->count, 1); 532 - atomic_set(&kn->active, 0); 355 + atomic_set(&kn->active, KN_DEACTIVATED_BIAS); 356 + RB_CLEAR_NODE(&kn->rb); 533 357 534 358 kn->name = name; 535 359 kn->mode = mode; 536 - kn->flags = flags | KERNFS_REMOVED; 360 + kn->flags = flags; 537 361 538 362 return kn; 539 363 ··· 560 382 } 561 383 562 384 /** 563 - * kernfs_addrm_start - prepare for kernfs_node add/remove 564 - * @acxt: pointer to kernfs_addrm_cxt to be used 565 - * 566 - * This function is called when the caller is about to add or remove 567 - * kernfs_node. This function acquires kernfs_mutex. @acxt is used 568 - * to keep and pass context to other addrm functions. 569 - * 570 - * LOCKING: 571 - * Kernel thread context (may sleep). kernfs_mutex is locked on 572 - * return. 573 - */ 574 - void kernfs_addrm_start(struct kernfs_addrm_cxt *acxt) 575 - __acquires(kernfs_mutex) 576 - { 577 - memset(acxt, 0, sizeof(*acxt)); 578 - 579 - mutex_lock(&kernfs_mutex); 580 - } 581 - 582 - /** 583 385 * kernfs_add_one - add kernfs_node to parent without warning 584 - * @acxt: addrm context to use 585 386 * @kn: kernfs_node to be added 586 387 * 587 388 * The caller must already have initialized @kn->parent. This 588 389 * function increments nlink of the parent's inode if @kn is a 589 390 * directory and link into the children list of the parent. 590 391 * 591 - * This function should be called between calls to 592 - * kernfs_addrm_start() and kernfs_addrm_finish() and should be passed 593 - * the same @acxt as passed to kernfs_addrm_start(). 594 - * 595 - * LOCKING: 596 - * Determined by kernfs_addrm_start(). 597 - * 598 392 * RETURNS: 599 393 * 0 on success, -EEXIST if entry with the given name already 600 394 * exists. 601 395 */ 602 - int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn) 396 + int kernfs_add_one(struct kernfs_node *kn) 603 397 { 604 398 struct kernfs_node *parent = kn->parent; 605 - bool has_ns = kernfs_ns_enabled(parent); 606 399 struct kernfs_iattrs *ps_iattr; 400 + bool has_ns; 607 401 int ret; 608 402 609 - if (has_ns != (bool)kn->ns) { 610 - WARN(1, KERN_WARNING "kernfs: ns %s in '%s' for '%s'\n", 611 - has_ns ? "required" : "invalid", parent->name, kn->name); 612 - return -EINVAL; 613 - } 403 + mutex_lock(&kernfs_mutex); 404 + 405 + ret = -EINVAL; 406 + has_ns = kernfs_ns_enabled(parent); 407 + if (WARN(has_ns != (bool)kn->ns, KERN_WARNING "kernfs: ns %s in '%s' for '%s'\n", 408 + has_ns ? "required" : "invalid", parent->name, kn->name)) 409 + goto out_unlock; 614 410 615 411 if (kernfs_type(parent) != KERNFS_DIR) 616 - return -EINVAL; 412 + goto out_unlock; 617 413 618 - if (parent->flags & KERNFS_REMOVED) 619 - return -ENOENT; 414 + ret = -ENOENT; 415 + if ((parent->flags & KERNFS_ACTIVATED) && !kernfs_active(parent)) 416 + goto out_unlock; 620 417 621 418 kn->hash = kernfs_name_hash(kn->name, kn->ns); 622 419 623 420 ret = kernfs_link_sibling(kn); 624 421 if (ret) 625 - return ret; 422 + goto out_unlock; 626 423 627 424 /* Update timestamps on the parent */ 628 425 ps_iattr = parent->iattr; ··· 606 453 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 607 454 } 608 455 609 - /* Mark the entry added into directory tree */ 610 - kn->flags &= ~KERNFS_REMOVED; 611 - 612 - return 0; 613 - } 614 - 615 - /** 616 - * kernfs_remove_one - remove kernfs_node from parent 617 - * @acxt: addrm context to use 618 - * @kn: kernfs_node to be removed 619 - * 620 - * Mark @kn removed and drop nlink of parent inode if @kn is a 621 - * directory. @kn is unlinked from the children list. 622 - * 623 - * This function should be called between calls to 624 - * kernfs_addrm_start() and kernfs_addrm_finish() and should be 625 - * passed the same @acxt as passed to kernfs_addrm_start(). 626 - * 627 - * LOCKING: 628 - * Determined by kernfs_addrm_start(). 629 - */ 630 - static void kernfs_remove_one(struct kernfs_addrm_cxt *acxt, 631 - struct kernfs_node *kn) 632 - { 633 - struct kernfs_iattrs *ps_iattr; 634 - 635 - /* 636 - * Removal can be called multiple times on the same node. Only the 637 - * first invocation is effective and puts the base ref. 638 - */ 639 - if (kn->flags & KERNFS_REMOVED) 640 - return; 641 - 642 - if (kn->parent) { 643 - kernfs_unlink_sibling(kn); 644 - 645 - /* Update timestamps on the parent */ 646 - ps_iattr = kn->parent->iattr; 647 - if (ps_iattr) { 648 - ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 649 - ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 650 - } 651 - } 652 - 653 - kn->flags |= KERNFS_REMOVED; 654 - kn->u.removed_list = acxt->removed; 655 - acxt->removed = kn; 656 - } 657 - 658 - /** 659 - * kernfs_addrm_finish - finish up kernfs_node add/remove 660 - * @acxt: addrm context to finish up 661 - * 662 - * Finish up kernfs_node add/remove. Resources acquired by 663 - * kernfs_addrm_start() are released and removed kernfs_nodes are 664 - * cleaned up. 665 - * 666 - * LOCKING: 667 - * kernfs_mutex is released. 668 - */ 669 - void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt) 670 - __releases(kernfs_mutex) 671 - { 672 - /* release resources acquired by kernfs_addrm_start() */ 673 456 mutex_unlock(&kernfs_mutex); 674 457 675 - /* kill removed kernfs_nodes */ 676 - while (acxt->removed) { 677 - struct kernfs_node *kn = acxt->removed; 458 + /* 459 + * Activate the new node unless CREATE_DEACTIVATED is requested. 460 + * If not activated here, the kernfs user is responsible for 461 + * activating the node with kernfs_activate(). A node which hasn't 462 + * been activated is not visible to userland and its removal won't 463 + * trigger deactivation. 464 + */ 465 + if (!(kernfs_root(kn)->flags & KERNFS_ROOT_CREATE_DEACTIVATED)) 466 + kernfs_activate(kn); 467 + return 0; 678 468 679 - acxt->removed = kn->u.removed_list; 680 - 681 - kernfs_deactivate(kn); 682 - kernfs_unmap_bin_file(kn); 683 - kernfs_put(kn); 684 - } 469 + out_unlock: 470 + mutex_unlock(&kernfs_mutex); 471 + return ret; 685 472 } 686 473 687 474 /** ··· 692 599 693 600 /** 694 601 * kernfs_create_root - create a new kernfs hierarchy 695 - * @kdops: optional directory syscall operations for the hierarchy 602 + * @scops: optional syscall operations for the hierarchy 603 + * @flags: KERNFS_ROOT_* flags 696 604 * @priv: opaque data associated with the new directory 697 605 * 698 606 * Returns the root of the new hierarchy on success, ERR_PTR() value on 699 607 * failure. 700 608 */ 701 - struct kernfs_root *kernfs_create_root(struct kernfs_dir_ops *kdops, void *priv) 609 + struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, 610 + unsigned int flags, void *priv) 702 611 { 703 612 struct kernfs_root *root; 704 613 struct kernfs_node *kn; ··· 719 624 return ERR_PTR(-ENOMEM); 720 625 } 721 626 722 - kn->flags &= ~KERNFS_REMOVED; 723 627 kn->priv = priv; 724 628 kn->dir.root = root; 725 629 726 - root->dir_ops = kdops; 630 + root->syscall_ops = scops; 631 + root->flags = flags; 727 632 root->kn = kn; 633 + init_waitqueue_head(&root->deactivate_waitq); 634 + 635 + if (!(root->flags & KERNFS_ROOT_CREATE_DEACTIVATED)) 636 + kernfs_activate(kn); 728 637 729 638 return root; 730 639 } ··· 759 660 const char *name, umode_t mode, 760 661 void *priv, const void *ns) 761 662 { 762 - struct kernfs_addrm_cxt acxt; 763 663 struct kernfs_node *kn; 764 664 int rc; 765 665 ··· 772 674 kn->priv = priv; 773 675 774 676 /* link in */ 775 - kernfs_addrm_start(&acxt); 776 - rc = kernfs_add_one(&acxt, kn); 777 - kernfs_addrm_finish(&acxt); 778 - 677 + rc = kernfs_add_one(kn); 779 678 if (!rc) 780 679 return kn; 781 680 ··· 798 703 kn = kernfs_find_ns(parent, dentry->d_name.name, ns); 799 704 800 705 /* no such entry */ 801 - if (!kn) { 706 + if (!kn || !kernfs_active(kn)) { 802 707 ret = NULL; 803 708 goto out_unlock; 804 709 } ··· 823 728 umode_t mode) 824 729 { 825 730 struct kernfs_node *parent = dir->i_private; 826 - struct kernfs_dir_ops *kdops = kernfs_root(parent)->dir_ops; 731 + struct kernfs_syscall_ops *scops = kernfs_root(parent)->syscall_ops; 732 + int ret; 827 733 828 - if (!kdops || !kdops->mkdir) 734 + if (!scops || !scops->mkdir) 829 735 return -EPERM; 830 736 831 - return kdops->mkdir(parent, dentry->d_name.name, mode); 737 + if (!kernfs_get_active(parent)) 738 + return -ENODEV; 739 + 740 + ret = scops->mkdir(parent, dentry->d_name.name, mode); 741 + 742 + kernfs_put_active(parent); 743 + return ret; 832 744 } 833 745 834 746 static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry) 835 747 { 836 748 struct kernfs_node *kn = dentry->d_fsdata; 837 - struct kernfs_dir_ops *kdops = kernfs_root(kn)->dir_ops; 749 + struct kernfs_syscall_ops *scops = kernfs_root(kn)->syscall_ops; 750 + int ret; 838 751 839 - if (!kdops || !kdops->rmdir) 752 + if (!scops || !scops->rmdir) 840 753 return -EPERM; 841 754 842 - return kdops->rmdir(kn); 755 + if (!kernfs_get_active(kn)) 756 + return -ENODEV; 757 + 758 + ret = scops->rmdir(kn); 759 + 760 + kernfs_put_active(kn); 761 + return ret; 843 762 } 844 763 845 764 static int kernfs_iop_rename(struct inode *old_dir, struct dentry *old_dentry, ··· 861 752 { 862 753 struct kernfs_node *kn = old_dentry->d_fsdata; 863 754 struct kernfs_node *new_parent = new_dir->i_private; 864 - struct kernfs_dir_ops *kdops = kernfs_root(kn)->dir_ops; 755 + struct kernfs_syscall_ops *scops = kernfs_root(kn)->syscall_ops; 756 + int ret; 865 757 866 - if (!kdops || !kdops->rename) 758 + if (!scops || !scops->rename) 867 759 return -EPERM; 868 760 869 - return kdops->rename(kn, new_parent, new_dentry->d_name.name); 761 + if (!kernfs_get_active(kn)) 762 + return -ENODEV; 763 + 764 + if (!kernfs_get_active(new_parent)) { 765 + kernfs_put_active(kn); 766 + return -ENODEV; 767 + } 768 + 769 + ret = scops->rename(kn, new_parent, new_dentry->d_name.name); 770 + 771 + kernfs_put_active(new_parent); 772 + kernfs_put_active(kn); 773 + return ret; 870 774 } 871 775 872 776 const struct inode_operations kernfs_dir_iops = { ··· 952 830 return pos->parent; 953 831 } 954 832 955 - static void __kernfs_remove(struct kernfs_addrm_cxt *acxt, 956 - struct kernfs_node *kn) 833 + /** 834 + * kernfs_activate - activate a node which started deactivated 835 + * @kn: kernfs_node whose subtree is to be activated 836 + * 837 + * If the root has KERNFS_ROOT_CREATE_DEACTIVATED set, a newly created node 838 + * needs to be explicitly activated. A node which hasn't been activated 839 + * isn't visible to userland and deactivation is skipped during its 840 + * removal. This is useful to construct atomic init sequences where 841 + * creation of multiple nodes should either succeed or fail atomically. 842 + * 843 + * The caller is responsible for ensuring that this function is not called 844 + * after kernfs_remove*() is invoked on @kn. 845 + */ 846 + void kernfs_activate(struct kernfs_node *kn) 957 847 { 958 - struct kernfs_node *pos, *next; 848 + struct kernfs_node *pos; 959 849 960 - if (!kn) 850 + mutex_lock(&kernfs_mutex); 851 + 852 + pos = NULL; 853 + while ((pos = kernfs_next_descendant_post(pos, kn))) { 854 + if (!pos || (pos->flags & KERNFS_ACTIVATED)) 855 + continue; 856 + 857 + WARN_ON_ONCE(pos->parent && RB_EMPTY_NODE(&pos->rb)); 858 + WARN_ON_ONCE(atomic_read(&pos->active) != KN_DEACTIVATED_BIAS); 859 + 860 + atomic_sub(KN_DEACTIVATED_BIAS, &pos->active); 861 + pos->flags |= KERNFS_ACTIVATED; 862 + } 863 + 864 + mutex_unlock(&kernfs_mutex); 865 + } 866 + 867 + static void __kernfs_remove(struct kernfs_node *kn) 868 + { 869 + struct kernfs_node *pos; 870 + 871 + lockdep_assert_held(&kernfs_mutex); 872 + 873 + /* 874 + * Short-circuit if non-root @kn has already finished removal. 875 + * This is for kernfs_remove_self() which plays with active ref 876 + * after removal. 877 + */ 878 + if (!kn || (kn->parent && RB_EMPTY_NODE(&kn->rb))) 961 879 return; 962 880 963 881 pr_debug("kernfs %s: removing\n", kn->name); 964 882 965 - next = NULL; 883 + /* prevent any new usage under @kn by deactivating all nodes */ 884 + pos = NULL; 885 + while ((pos = kernfs_next_descendant_post(pos, kn))) 886 + if (kernfs_active(pos)) 887 + atomic_add(KN_DEACTIVATED_BIAS, &pos->active); 888 + 889 + /* deactivate and unlink the subtree node-by-node */ 966 890 do { 967 - pos = next; 968 - next = kernfs_next_descendant_post(pos, kn); 969 - if (pos) 970 - kernfs_remove_one(acxt, pos); 971 - } while (next); 891 + pos = kernfs_leftmost_descendant(kn); 892 + 893 + /* 894 + * kernfs_drain() drops kernfs_mutex temporarily and @pos's 895 + * base ref could have been put by someone else by the time 896 + * the function returns. Make sure it doesn't go away 897 + * underneath us. 898 + */ 899 + kernfs_get(pos); 900 + 901 + /* 902 + * Drain iff @kn was activated. This avoids draining and 903 + * its lockdep annotations for nodes which have never been 904 + * activated and allows embedding kernfs_remove() in create 905 + * error paths without worrying about draining. 906 + */ 907 + if (kn->flags & KERNFS_ACTIVATED) 908 + kernfs_drain(pos); 909 + else 910 + WARN_ON_ONCE(atomic_read(&kn->active) != KN_DEACTIVATED_BIAS); 911 + 912 + /* 913 + * kernfs_unlink_sibling() succeeds once per node. Use it 914 + * to decide who's responsible for cleanups. 915 + */ 916 + if (!pos->parent || kernfs_unlink_sibling(pos)) { 917 + struct kernfs_iattrs *ps_iattr = 918 + pos->parent ? pos->parent->iattr : NULL; 919 + 920 + /* update timestamps on the parent */ 921 + if (ps_iattr) { 922 + ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 923 + ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 924 + } 925 + 926 + kernfs_put(pos); 927 + } 928 + 929 + kernfs_put(pos); 930 + } while (pos != kn); 972 931 } 973 932 974 933 /** ··· 1060 857 */ 1061 858 void kernfs_remove(struct kernfs_node *kn) 1062 859 { 1063 - struct kernfs_addrm_cxt acxt; 860 + mutex_lock(&kernfs_mutex); 861 + __kernfs_remove(kn); 862 + mutex_unlock(&kernfs_mutex); 863 + } 1064 864 1065 - kernfs_addrm_start(&acxt); 1066 - __kernfs_remove(&acxt, kn); 1067 - kernfs_addrm_finish(&acxt); 865 + /** 866 + * kernfs_break_active_protection - break out of active protection 867 + * @kn: the self kernfs_node 868 + * 869 + * The caller must be running off of a kernfs operation which is invoked 870 + * with an active reference - e.g. one of kernfs_ops. Each invocation of 871 + * this function must also be matched with an invocation of 872 + * kernfs_unbreak_active_protection(). 873 + * 874 + * This function releases the active reference of @kn the caller is 875 + * holding. Once this function is called, @kn may be removed at any point 876 + * and the caller is solely responsible for ensuring that the objects it 877 + * dereferences are accessible. 878 + */ 879 + void kernfs_break_active_protection(struct kernfs_node *kn) 880 + { 881 + /* 882 + * Take out ourself out of the active ref dependency chain. If 883 + * we're called without an active ref, lockdep will complain. 884 + */ 885 + kernfs_put_active(kn); 886 + } 887 + 888 + /** 889 + * kernfs_unbreak_active_protection - undo kernfs_break_active_protection() 890 + * @kn: the self kernfs_node 891 + * 892 + * If kernfs_break_active_protection() was called, this function must be 893 + * invoked before finishing the kernfs operation. Note that while this 894 + * function restores the active reference, it doesn't and can't actually 895 + * restore the active protection - @kn may already or be in the process of 896 + * being removed. Once kernfs_break_active_protection() is invoked, that 897 + * protection is irreversibly gone for the kernfs operation instance. 898 + * 899 + * While this function may be called at any point after 900 + * kernfs_break_active_protection() is invoked, its most useful location 901 + * would be right before the enclosing kernfs operation returns. 902 + */ 903 + void kernfs_unbreak_active_protection(struct kernfs_node *kn) 904 + { 905 + /* 906 + * @kn->active could be in any state; however, the increment we do 907 + * here will be undone as soon as the enclosing kernfs operation 908 + * finishes and this temporary bump can't break anything. If @kn 909 + * is alive, nothing changes. If @kn is being deactivated, the 910 + * soon-to-follow put will either finish deactivation or restore 911 + * deactivated state. If @kn is already removed, the temporary 912 + * bump is guaranteed to be gone before @kn is released. 913 + */ 914 + atomic_inc(&kn->active); 915 + if (kernfs_lockdep(kn)) 916 + rwsem_acquire(&kn->dep_map, 0, 1, _RET_IP_); 917 + } 918 + 919 + /** 920 + * kernfs_remove_self - remove a kernfs_node from its own method 921 + * @kn: the self kernfs_node to remove 922 + * 923 + * The caller must be running off of a kernfs operation which is invoked 924 + * with an active reference - e.g. one of kernfs_ops. This can be used to 925 + * implement a file operation which deletes itself. 926 + * 927 + * For example, the "delete" file for a sysfs device directory can be 928 + * implemented by invoking kernfs_remove_self() on the "delete" file 929 + * itself. This function breaks the circular dependency of trying to 930 + * deactivate self while holding an active ref itself. It isn't necessary 931 + * to modify the usual removal path to use kernfs_remove_self(). The 932 + * "delete" implementation can simply invoke kernfs_remove_self() on self 933 + * before proceeding with the usual removal path. kernfs will ignore later 934 + * kernfs_remove() on self. 935 + * 936 + * kernfs_remove_self() can be called multiple times concurrently on the 937 + * same kernfs_node. Only the first one actually performs removal and 938 + * returns %true. All others will wait until the kernfs operation which 939 + * won self-removal finishes and return %false. Note that the losers wait 940 + * for the completion of not only the winning kernfs_remove_self() but also 941 + * the whole kernfs_ops which won the arbitration. This can be used to 942 + * guarantee, for example, all concurrent writes to a "delete" file to 943 + * finish only after the whole operation is complete. 944 + */ 945 + bool kernfs_remove_self(struct kernfs_node *kn) 946 + { 947 + bool ret; 948 + 949 + mutex_lock(&kernfs_mutex); 950 + kernfs_break_active_protection(kn); 951 + 952 + /* 953 + * SUICIDAL is used to arbitrate among competing invocations. Only 954 + * the first one will actually perform removal. When the removal 955 + * is complete, SUICIDED is set and the active ref is restored 956 + * while holding kernfs_mutex. The ones which lost arbitration 957 + * waits for SUICDED && drained which can happen only after the 958 + * enclosing kernfs operation which executed the winning instance 959 + * of kernfs_remove_self() finished. 960 + */ 961 + if (!(kn->flags & KERNFS_SUICIDAL)) { 962 + kn->flags |= KERNFS_SUICIDAL; 963 + __kernfs_remove(kn); 964 + kn->flags |= KERNFS_SUICIDED; 965 + ret = true; 966 + } else { 967 + wait_queue_head_t *waitq = &kernfs_root(kn)->deactivate_waitq; 968 + DEFINE_WAIT(wait); 969 + 970 + while (true) { 971 + prepare_to_wait(waitq, &wait, TASK_UNINTERRUPTIBLE); 972 + 973 + if ((kn->flags & KERNFS_SUICIDED) && 974 + atomic_read(&kn->active) == KN_DEACTIVATED_BIAS) 975 + break; 976 + 977 + mutex_unlock(&kernfs_mutex); 978 + schedule(); 979 + mutex_lock(&kernfs_mutex); 980 + } 981 + finish_wait(waitq, &wait); 982 + WARN_ON_ONCE(!RB_EMPTY_NODE(&kn->rb)); 983 + ret = false; 984 + } 985 + 986 + /* 987 + * This must be done while holding kernfs_mutex; otherwise, waiting 988 + * for SUICIDED && deactivated could finish prematurely. 989 + */ 990 + kernfs_unbreak_active_protection(kn); 991 + 992 + mutex_unlock(&kernfs_mutex); 993 + return ret; 1068 994 } 1069 995 1070 996 /** ··· 1208 876 int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, 1209 877 const void *ns) 1210 878 { 1211 - struct kernfs_addrm_cxt acxt; 1212 879 struct kernfs_node *kn; 1213 880 1214 881 if (!parent) { ··· 1216 885 return -ENOENT; 1217 886 } 1218 887 1219 - kernfs_addrm_start(&acxt); 888 + mutex_lock(&kernfs_mutex); 1220 889 1221 890 kn = kernfs_find_ns(parent, name, ns); 1222 891 if (kn) 1223 - __kernfs_remove(&acxt, kn); 892 + __kernfs_remove(kn); 1224 893 1225 - kernfs_addrm_finish(&acxt); 894 + mutex_unlock(&kernfs_mutex); 1226 895 1227 896 if (kn) 1228 897 return 0; ··· 1240 909 int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, 1241 910 const char *new_name, const void *new_ns) 1242 911 { 912 + struct kernfs_node *old_parent; 913 + const char *old_name = NULL; 1243 914 int error; 915 + 916 + /* can't move or rename root */ 917 + if (!kn->parent) 918 + return -EINVAL; 1244 919 1245 920 mutex_lock(&kernfs_mutex); 1246 921 1247 922 error = -ENOENT; 1248 - if ((kn->flags | new_parent->flags) & KERNFS_REMOVED) 923 + if (!kernfs_active(kn) || !kernfs_active(new_parent)) 1249 924 goto out; 1250 925 1251 926 error = 0; ··· 1269 932 new_name = kstrdup(new_name, GFP_KERNEL); 1270 933 if (!new_name) 1271 934 goto out; 1272 - 1273 - if (kn->flags & KERNFS_STATIC_NAME) 1274 - kn->flags &= ~KERNFS_STATIC_NAME; 1275 - else 1276 - kfree(kn->name); 1277 - 1278 - kn->name = new_name; 935 + } else { 936 + new_name = NULL; 1279 937 } 1280 938 1281 939 /* ··· 1278 946 */ 1279 947 kernfs_unlink_sibling(kn); 1280 948 kernfs_get(new_parent); 1281 - kernfs_put(kn->parent); 1282 - kn->ns = new_ns; 1283 - kn->hash = kernfs_name_hash(kn->name, kn->ns); 949 + 950 + /* rename_lock protects ->parent and ->name accessors */ 951 + spin_lock_irq(&kernfs_rename_lock); 952 + 953 + old_parent = kn->parent; 1284 954 kn->parent = new_parent; 955 + 956 + kn->ns = new_ns; 957 + if (new_name) { 958 + if (!(kn->flags & KERNFS_STATIC_NAME)) 959 + old_name = kn->name; 960 + kn->flags &= ~KERNFS_STATIC_NAME; 961 + kn->name = new_name; 962 + } 963 + 964 + spin_unlock_irq(&kernfs_rename_lock); 965 + 966 + kn->hash = kernfs_name_hash(kn->name, kn->ns); 1285 967 kernfs_link_sibling(kn); 968 + 969 + kernfs_put(old_parent); 970 + kfree(old_name); 1286 971 1287 972 error = 0; 1288 973 out: ··· 1323 974 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos) 1324 975 { 1325 976 if (pos) { 1326 - int valid = !(pos->flags & KERNFS_REMOVED) && 977 + int valid = kernfs_active(pos) && 1327 978 pos->parent == parent && hash == pos->hash; 1328 979 kernfs_put(pos); 1329 980 if (!valid) ··· 1342 993 break; 1343 994 } 1344 995 } 1345 - /* Skip over entries in the wrong namespace */ 1346 - while (pos && pos->ns != ns) { 996 + /* Skip over entries which are dying/dead or in the wrong namespace */ 997 + while (pos && (!kernfs_active(pos) || pos->ns != ns)) { 1347 998 struct rb_node *node = rb_next(&pos->rb); 1348 999 if (!node) 1349 1000 pos = NULL; ··· 1357 1008 struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos) 1358 1009 { 1359 1010 pos = kernfs_dir_pos(ns, parent, ino, pos); 1360 - if (pos) 1011 + if (pos) { 1361 1012 do { 1362 1013 struct rb_node *node = rb_next(&pos->rb); 1363 1014 if (!node) 1364 1015 pos = NULL; 1365 1016 else 1366 1017 pos = rb_to_kn(node); 1367 - } while (pos && pos->ns != ns); 1018 + } while (pos && (!kernfs_active(pos) || pos->ns != ns)); 1019 + } 1368 1020 return pos; 1369 1021 } 1370 1022
+16 -6
fs/kernfs/file.c
··· 252 252 size_t count, loff_t *ppos) 253 253 { 254 254 struct kernfs_open_file *of = kernfs_of(file); 255 - ssize_t len = min_t(size_t, count, PAGE_SIZE); 256 255 const struct kernfs_ops *ops; 256 + size_t len; 257 257 char *buf; 258 + 259 + if (of->atomic_write_len) { 260 + len = count; 261 + if (len > of->atomic_write_len) 262 + return -E2BIG; 263 + } else { 264 + len = min_t(size_t, count, PAGE_SIZE); 265 + } 258 266 259 267 buf = kmalloc(len + 1, GFP_KERNEL); 260 268 if (!buf) ··· 661 653 of->file = file; 662 654 663 655 /* 656 + * Write path needs to atomic_write_len outside active reference. 657 + * Cache it in open_file. See kernfs_fop_write() for details. 658 + */ 659 + of->atomic_write_len = ops->atomic_write_len; 660 + 661 + /* 664 662 * Always instantiate seq_file even if read access doesn't use 665 663 * seq_file or is not requested. This unifies private data access 666 664 * and readable regular files are the vast majority anyway. ··· 834 820 bool name_is_static, 835 821 struct lock_class_key *key) 836 822 { 837 - struct kernfs_addrm_cxt acxt; 838 823 struct kernfs_node *kn; 839 824 unsigned flags; 840 825 int rc; ··· 868 855 if (ops->mmap) 869 856 kn->flags |= KERNFS_HAS_MMAP; 870 857 871 - kernfs_addrm_start(&acxt); 872 - rc = kernfs_add_one(&acxt, kn); 873 - kernfs_addrm_finish(&acxt); 874 - 858 + rc = kernfs_add_one(kn); 875 859 if (rc) { 876 860 kernfs_put(kn); 877 861 return ERR_PTR(rc);
+4 -11
fs/kernfs/kernfs-internal.h
··· 26 26 struct simple_xattrs xattrs; 27 27 }; 28 28 29 - #define KN_DEACTIVATED_BIAS INT_MIN 29 + /* +1 to avoid triggering overflow warning when negating it */ 30 + #define KN_DEACTIVATED_BIAS (INT_MIN + 1) 30 31 31 32 /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ 32 33 ··· 44 43 kn = kn->parent; 45 44 return kn->dir.root; 46 45 } 47 - 48 - /* 49 - * Context structure to be used while adding/removing nodes. 50 - */ 51 - struct kernfs_addrm_cxt { 52 - struct kernfs_node *removed; 53 - }; 54 46 55 47 /* 56 48 * mount.c ··· 65 71 }; 66 72 #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info)) 67 73 74 + extern const struct super_operations kernfs_sops; 68 75 extern struct kmem_cache *kernfs_node_cache; 69 76 70 77 /* ··· 95 100 96 101 struct kernfs_node *kernfs_get_active(struct kernfs_node *kn); 97 102 void kernfs_put_active(struct kernfs_node *kn); 98 - void kernfs_addrm_start(struct kernfs_addrm_cxt *acxt); 99 - int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn); 100 - void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt); 103 + int kernfs_add_one(struct kernfs_node *kn); 101 104 struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, 102 105 const char *name, umode_t mode, 103 106 unsigned flags);
+38 -1
fs/kernfs/mount.c
··· 19 19 20 20 struct kmem_cache *kernfs_node_cache; 21 21 22 - static const struct super_operations kernfs_sops = { 22 + static int kernfs_sop_remount_fs(struct super_block *sb, int *flags, char *data) 23 + { 24 + struct kernfs_root *root = kernfs_info(sb)->root; 25 + struct kernfs_syscall_ops *scops = root->syscall_ops; 26 + 27 + if (scops && scops->remount_fs) 28 + return scops->remount_fs(root, flags, data); 29 + return 0; 30 + } 31 + 32 + static int kernfs_sop_show_options(struct seq_file *sf, struct dentry *dentry) 33 + { 34 + struct kernfs_root *root = kernfs_root(dentry->d_fsdata); 35 + struct kernfs_syscall_ops *scops = root->syscall_ops; 36 + 37 + if (scops && scops->show_options) 38 + return scops->show_options(sf, root); 39 + return 0; 40 + } 41 + 42 + const struct super_operations kernfs_sops = { 23 43 .statfs = simple_statfs, 24 44 .drop_inode = generic_delete_inode, 25 45 .evict_inode = kernfs_evict_inode, 46 + 47 + .remount_fs = kernfs_sop_remount_fs, 48 + .show_options = kernfs_sop_show_options, 26 49 }; 50 + 51 + /** 52 + * kernfs_root_from_sb - determine kernfs_root associated with a super_block 53 + * @sb: the super_block in question 54 + * 55 + * Return the kernfs_root associated with @sb. If @sb is not a kernfs one, 56 + * %NULL is returned. 57 + */ 58 + struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) 59 + { 60 + if (sb->s_op == &kernfs_sops) 61 + return kernfs_info(sb)->root; 62 + return NULL; 63 + } 27 64 28 65 static int kernfs_fill_super(struct super_block *sb) 29 66 {
+1 -5
fs/kernfs/symlink.c
··· 27 27 struct kernfs_node *target) 28 28 { 29 29 struct kernfs_node *kn; 30 - struct kernfs_addrm_cxt acxt; 31 30 int error; 32 31 33 32 kn = kernfs_new_node(parent, name, S_IFLNK|S_IRWXUGO, KERNFS_LINK); ··· 38 39 kn->symlink.target_kn = target; 39 40 kernfs_get(target); /* ref owned by symlink */ 40 41 41 - kernfs_addrm_start(&acxt); 42 - error = kernfs_add_one(&acxt, kn); 43 - kernfs_addrm_finish(&acxt); 44 - 42 + error = kernfs_add_one(kn); 45 43 if (!error) 46 44 return kn; 47 45
+1
fs/sysfs/Kconfig
··· 1 1 config SYSFS 2 2 bool "sysfs file system support" if EXPERT 3 3 default y 4 + select KERNFS 4 5 help 5 6 The sysfs filesystem is a virtual filesystem that the kernel uses to 6 7 export internal kernel objects, their attributes, and their
+13 -31
fs/sysfs/dir.c
··· 19 19 20 20 DEFINE_SPINLOCK(sysfs_symlink_target_lock); 21 21 22 - /** 23 - * sysfs_pathname - return full path to sysfs dirent 24 - * @kn: kernfs_node whose path we want 25 - * @path: caller allocated buffer of size PATH_MAX 26 - * 27 - * Gives the name "/" to the sysfs_root entry; any path returned 28 - * is relative to wherever sysfs is mounted. 29 - */ 30 - static char *sysfs_pathname(struct kernfs_node *kn, char *path) 31 - { 32 - if (kn->parent) { 33 - sysfs_pathname(kn->parent, path); 34 - strlcat(path, "/", PATH_MAX); 35 - } 36 - strlcat(path, kn->name, PATH_MAX); 37 - return path; 38 - } 39 - 40 22 void sysfs_warn_dup(struct kernfs_node *parent, const char *name) 41 23 { 42 - char *path; 24 + char *buf, *path = NULL; 43 25 44 - path = kzalloc(PATH_MAX, GFP_KERNEL); 45 - if (path) { 46 - sysfs_pathname(parent, path); 47 - strlcat(path, "/", PATH_MAX); 48 - strlcat(path, name, PATH_MAX); 49 - } 26 + buf = kzalloc(PATH_MAX, GFP_KERNEL); 27 + if (buf) 28 + path = kernfs_path(parent, buf, PATH_MAX); 50 29 51 - WARN(1, KERN_WARNING "sysfs: cannot create duplicate filename '%s'\n", 52 - path ? path : name); 30 + WARN(1, KERN_WARNING "sysfs: cannot create duplicate filename '%s/%s'\n", 31 + path, name); 53 32 54 - kfree(path); 33 + kfree(buf); 55 34 } 56 35 57 36 /** ··· 101 122 int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, 102 123 const void *new_ns) 103 124 { 104 - struct kernfs_node *parent = kobj->sd->parent; 125 + struct kernfs_node *parent; 126 + int ret; 105 127 106 - return kernfs_rename_ns(kobj->sd, parent, new_name, new_ns); 128 + parent = kernfs_get_parent(kobj->sd); 129 + ret = kernfs_rename_ns(kobj->sd, parent, new_name, new_ns); 130 + kernfs_put(parent); 131 + return ret; 107 132 } 108 133 109 134 int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, ··· 116 133 struct kernfs_node *kn = kobj->sd; 117 134 struct kernfs_node *new_parent; 118 135 119 - BUG_ON(!kn->parent); 120 136 new_parent = new_parent_kobj && new_parent_kobj->sd ? 121 137 new_parent_kobj->sd : sysfs_root_kn; 122 138
+23
fs/sysfs/file.c
··· 372 372 } 373 373 EXPORT_SYMBOL_GPL(sysfs_remove_file_ns); 374 374 375 + /** 376 + * sysfs_remove_file_self - remove an object attribute from its own method 377 + * @kobj: object we're acting for 378 + * @attr: attribute descriptor 379 + * 380 + * See kernfs_remove_self() for details. 381 + */ 382 + bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr) 383 + { 384 + struct kernfs_node *parent = kobj->sd; 385 + struct kernfs_node *kn; 386 + bool ret; 387 + 388 + kn = kernfs_find_and_get(parent, attr->name); 389 + if (WARN_ON_ONCE(!kn)) 390 + return false; 391 + 392 + ret = kernfs_remove_self(kn); 393 + 394 + kernfs_put(kn); 395 + return ret; 396 + } 397 + 375 398 void sysfs_remove_files(struct kobject *kobj, const struct attribute **ptr) 376 399 { 377 400 int i;
+5 -2
fs/sysfs/group.c
··· 70 70 if (grp->bin_attrs) { 71 71 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) { 72 72 if (update) 73 - sysfs_remove_bin_file(kobj, *bin_attr); 74 - error = sysfs_create_bin_file(kobj, *bin_attr); 73 + kernfs_remove_by_name(parent, 74 + (*bin_attr)->attr.name); 75 + error = sysfs_add_file_mode_ns(parent, 76 + &(*bin_attr)->attr, true, 77 + (*bin_attr)->attr.mode, NULL); 75 78 if (error) 76 79 break; 77 80 }
+1 -1
fs/sysfs/mount.c
··· 63 63 { 64 64 int err; 65 65 66 - sysfs_root = kernfs_create_root(NULL, NULL); 66 + sysfs_root = kernfs_create_root(NULL, 0, NULL); 67 67 if (IS_ERR(sysfs_root)) 68 68 return PTR_ERR(sysfs_root); 69 69
-7
include/linux/cpu.h
··· 46 46 #endif 47 47 struct notifier_block; 48 48 49 - #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE 50 - extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env); 51 - extern ssize_t arch_print_cpu_modalias(struct device *dev, 52 - struct device_attribute *attr, 53 - char *bufptr); 54 - #endif 55 - 56 49 /* 57 50 * CPU notifier priorities. 58 51 */
+60
include/linux/cpufeature.h
··· 1 + /* 2 + * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + 9 + #ifndef __LINUX_CPUFEATURE_H 10 + #define __LINUX_CPUFEATURE_H 11 + 12 + #ifdef CONFIG_GENERIC_CPU_AUTOPROBE 13 + 14 + #include <linux/mod_devicetable.h> 15 + #include <asm/cpufeature.h> 16 + 17 + /* 18 + * Macros imported from <asm/cpufeature.h>: 19 + * - cpu_feature(x) ordinal value of feature called 'x' 20 + * - cpu_have_feature(u32 n) whether feature #n is available 21 + * - MAX_CPU_FEATURES upper bound for feature ordinal values 22 + * Optional: 23 + * - CPU_FEATURE_TYPEFMT format string fragment for printing the cpu type 24 + * - CPU_FEATURE_TYPEVAL set of values matching the format string above 25 + */ 26 + 27 + #ifndef CPU_FEATURE_TYPEFMT 28 + #define CPU_FEATURE_TYPEFMT "%s" 29 + #endif 30 + 31 + #ifndef CPU_FEATURE_TYPEVAL 32 + #define CPU_FEATURE_TYPEVAL ELF_PLATFORM 33 + #endif 34 + 35 + /* 36 + * Use module_cpu_feature_match(feature, module_init_function) to 37 + * declare that 38 + * a) the module shall be probed upon discovery of CPU feature 'feature' 39 + * (typically at boot time using udev) 40 + * b) the module must not be loaded if CPU feature 'feature' is not present 41 + * (not even by manual insmod). 42 + * 43 + * For a list of legal values for 'feature', please consult the file 44 + * 'asm/cpufeature.h' of your favorite architecture. 45 + */ 46 + #define module_cpu_feature_match(x, __init) \ 47 + static struct cpu_feature const cpu_feature_match_ ## x[] = \ 48 + { { .feature = cpu_feature(x) }, { } }; \ 49 + MODULE_DEVICE_TABLE(cpu, cpu_feature_match_ ## x); \ 50 + \ 51 + static int cpu_feature_match_ ## x ## _init(void) \ 52 + { \ 53 + if (!cpu_have_feature(cpu_feature(x))) \ 54 + return -ENODEV; \ 55 + return __init(); \ 56 + } \ 57 + module_init(cpu_feature_match_ ## x ## _init) 58 + 59 + #endif 60 + #endif
+2
include/linux/device.h
··· 560 560 const struct device_attribute *entry); 561 561 extern void device_remove_file(struct device *dev, 562 562 const struct device_attribute *attr); 563 + extern bool device_remove_file_self(struct device *dev, 564 + const struct device_attribute *attr); 563 565 extern int __must_check device_create_bin_file(struct device *dev, 564 566 const struct bin_attribute *attr); 565 567 extern void device_remove_bin_file(struct device *dev,
+86 -23
include/linux/kernfs.h
··· 15 15 #include <linux/lockdep.h> 16 16 #include <linux/rbtree.h> 17 17 #include <linux/atomic.h> 18 - #include <linux/completion.h> 18 + #include <linux/wait.h> 19 19 20 20 struct file; 21 21 struct dentry; ··· 35 35 }; 36 36 37 37 #define KERNFS_TYPE_MASK 0x000f 38 - #define KERNFS_ACTIVE_REF KERNFS_FILE 39 38 #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK 40 39 41 40 enum kernfs_node_flag { 42 - KERNFS_REMOVED = 0x0010, 41 + KERNFS_ACTIVATED = 0x0010, 43 42 KERNFS_NS = 0x0020, 44 43 KERNFS_HAS_SEQ_SHOW = 0x0040, 45 44 KERNFS_HAS_MMAP = 0x0080, 46 45 KERNFS_LOCKDEP = 0x0100, 47 46 KERNFS_STATIC_NAME = 0x0200, 47 + KERNFS_SUICIDAL = 0x0400, 48 + KERNFS_SUICIDED = 0x0800, 49 + }; 50 + 51 + /* @flags for kernfs_create_root() */ 52 + enum kernfs_root_flag { 53 + KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001, 48 54 }; 49 55 50 56 /* type-specific structures for kernfs_node union members */ ··· 91 85 #ifdef CONFIG_DEBUG_LOCK_ALLOC 92 86 struct lockdep_map dep_map; 93 87 #endif 94 - /* the following two fields are published */ 88 + /* 89 + * Use kernfs_get_parent() and kernfs_name/path() instead of 90 + * accessing the following two fields directly. If the node is 91 + * never moved to a different parent, it is safe to access the 92 + * parent directly. 93 + */ 95 94 struct kernfs_node *parent; 96 95 const char *name; 97 96 98 97 struct rb_node rb; 99 - 100 - union { 101 - struct completion *completion; 102 - struct kernfs_node *removed_list; 103 - } u; 104 98 105 99 const void *ns; /* namespace tag */ 106 100 unsigned int hash; /* ns + name hash */ ··· 119 113 }; 120 114 121 115 /* 122 - * kernfs_dir_ops may be specified on kernfs_create_root() to support 123 - * directory manipulation syscalls. These optional callbacks are invoked 124 - * on the matching syscalls and can perform any kernfs operations which 125 - * don't necessarily have to be the exact operation requested. 116 + * kernfs_syscall_ops may be specified on kernfs_create_root() to support 117 + * syscalls. These optional callbacks are invoked on the matching syscalls 118 + * and can perform any kernfs operations which don't necessarily have to be 119 + * the exact operation requested. An active reference is held for each 120 + * kernfs_node parameter. 126 121 */ 127 - struct kernfs_dir_ops { 122 + struct kernfs_syscall_ops { 123 + int (*remount_fs)(struct kernfs_root *root, int *flags, char *data); 124 + int (*show_options)(struct seq_file *sf, struct kernfs_root *root); 125 + 128 126 int (*mkdir)(struct kernfs_node *parent, const char *name, 129 127 umode_t mode); 130 128 int (*rmdir)(struct kernfs_node *kn); ··· 139 129 struct kernfs_root { 140 130 /* published fields */ 141 131 struct kernfs_node *kn; 132 + unsigned int flags; /* KERNFS_ROOT_* flags */ 142 133 143 134 /* private fields, do not use outside kernfs proper */ 144 135 struct ida ino_ida; 145 - struct kernfs_dir_ops *dir_ops; 136 + struct kernfs_syscall_ops *syscall_ops; 137 + wait_queue_head_t deactivate_waitq; 146 138 }; 147 139 148 140 struct kernfs_open_file { 149 141 /* published fields */ 150 142 struct kernfs_node *kn; 151 143 struct file *file; 144 + void *priv; 152 145 153 146 /* private fields, do not use outside kernfs proper */ 154 147 struct mutex mutex; 155 148 int event; 156 149 struct list_head list; 157 150 151 + size_t atomic_write_len; 158 152 bool mmapped; 159 153 const struct vm_operations_struct *vm_ops; 160 154 }; ··· 185 171 loff_t off); 186 172 187 173 /* 188 - * write() is bounced through kernel buffer and a write larger than 189 - * PAGE_SIZE results in partial operation of PAGE_SIZE. 174 + * write() is bounced through kernel buffer. If atomic_write_len 175 + * is not set, a write larger than PAGE_SIZE results in partial 176 + * operations of PAGE_SIZE chunks. If atomic_write_len is set, 177 + * writes upto the specified size are executed atomically but 178 + * larger ones are rejected with -E2BIG. 190 179 */ 180 + size_t atomic_write_len; 191 181 ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes, 192 182 loff_t off); 193 183 ··· 202 184 #endif 203 185 }; 204 186 205 - #ifdef CONFIG_SYSFS 187 + #ifdef CONFIG_KERNFS 206 188 207 189 static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) 208 190 { ··· 235 217 return kn->flags & KERNFS_NS; 236 218 } 237 219 220 + int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen); 221 + char * __must_check kernfs_path(struct kernfs_node *kn, char *buf, 222 + size_t buflen); 223 + void pr_cont_kernfs_name(struct kernfs_node *kn); 224 + void pr_cont_kernfs_path(struct kernfs_node *kn); 225 + struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn); 238 226 struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, 239 227 const char *name, const void *ns); 240 228 void kernfs_get(struct kernfs_node *kn); 241 229 void kernfs_put(struct kernfs_node *kn); 242 230 243 - struct kernfs_root *kernfs_create_root(struct kernfs_dir_ops *kdops, 244 - void *priv); 231 + struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry); 232 + struct kernfs_root *kernfs_root_from_sb(struct super_block *sb); 233 + 234 + struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, 235 + unsigned int flags, void *priv); 245 236 void kernfs_destroy_root(struct kernfs_root *root); 246 237 247 238 struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, ··· 266 239 struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, 267 240 const char *name, 268 241 struct kernfs_node *target); 242 + void kernfs_activate(struct kernfs_node *kn); 269 243 void kernfs_remove(struct kernfs_node *kn); 244 + void kernfs_break_active_protection(struct kernfs_node *kn); 245 + void kernfs_unbreak_active_protection(struct kernfs_node *kn); 246 + bool kernfs_remove_self(struct kernfs_node *kn); 270 247 int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, 271 248 const void *ns); 272 249 int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, ··· 286 255 287 256 void kernfs_init(void); 288 257 289 - #else /* CONFIG_SYSFS */ 258 + #else /* CONFIG_KERNFS */ 290 259 291 260 static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) 292 261 { return 0; } /* whatever */ ··· 296 265 static inline bool kernfs_ns_enabled(struct kernfs_node *kn) 297 266 { return false; } 298 267 268 + static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) 269 + { return -ENOSYS; } 270 + 271 + static inline char * __must_check kernfs_path(struct kernfs_node *kn, char *buf, 272 + size_t buflen) 273 + { return NULL; } 274 + 275 + static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { } 276 + static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { } 277 + 278 + static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn) 279 + { return NULL; } 280 + 299 281 static inline struct kernfs_node * 300 282 kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, 301 283 const void *ns) ··· 317 273 static inline void kernfs_get(struct kernfs_node *kn) { } 318 274 static inline void kernfs_put(struct kernfs_node *kn) { } 319 275 276 + static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry) 277 + { return NULL; } 278 + 279 + static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) 280 + { return NULL; } 281 + 320 282 static inline struct kernfs_root * 321 - kernfs_create_root(struct kernfs_dir_ops *kdops, void *priv) 283 + kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags, 284 + void *priv) 322 285 { return ERR_PTR(-ENOSYS); } 323 286 324 287 static inline void kernfs_destroy_root(struct kernfs_root *root) { } ··· 347 296 struct kernfs_node *target) 348 297 { return ERR_PTR(-ENOSYS); } 349 298 299 + static inline void kernfs_activate(struct kernfs_node *kn) { } 300 + 350 301 static inline void kernfs_remove(struct kernfs_node *kn) { } 302 + 303 + static inline bool kernfs_remove_self(struct kernfs_node *kn) 304 + { return false; } 351 305 352 306 static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn, 353 307 const char *name, const void *ns) ··· 381 325 382 326 static inline void kernfs_init(void) { } 383 327 384 - #endif /* CONFIG_SYSFS */ 328 + #endif /* CONFIG_KERNFS */ 385 329 386 330 static inline struct kernfs_node * 387 331 kernfs_find_and_get(struct kernfs_node *kn, const char *name) ··· 421 365 const char *name) 422 366 { 423 367 return kernfs_remove_by_name_ns(parent, name, NULL); 368 + } 369 + 370 + static inline int kernfs_rename(struct kernfs_node *kn, 371 + struct kernfs_node *new_parent, 372 + const char *new_name) 373 + { 374 + return kernfs_rename_ns(kn, new_parent, new_name, NULL); 424 375 } 425 376 426 377 static inline struct dentry *
+9
include/linux/mod_devicetable.h
··· 572 572 #define X86_MODEL_ANY 0 573 573 #define X86_FEATURE_ANY 0 /* Same as FPU, you can't test for that */ 574 574 575 + /* 576 + * Generic table type for matching CPU features. 577 + * @feature: the bit number of the feature (0 - 65535) 578 + */ 579 + 580 + struct cpu_feature { 581 + __u16 feature; 582 + }; 583 + 575 584 #define IPACK_ANY_FORMAT 0xff 576 585 #define IPACK_ANY_ID (~0) 577 586 struct ipack_device_id {
+16
include/linux/sysfs.h
··· 198 198 const struct attribute *attr, umode_t mode); 199 199 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, 200 200 const void *ns); 201 + bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr); 201 202 void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr); 202 203 203 204 int __must_check sysfs_create_bin_file(struct kobject *kobj, ··· 246 245 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); 247 246 248 247 int __must_check sysfs_init(void); 248 + 249 + static inline void sysfs_enable_ns(struct kernfs_node *kn) 250 + { 251 + return kernfs_enable_ns(kn); 252 + } 249 253 250 254 #else /* CONFIG_SYSFS */ 251 255 ··· 305 299 const struct attribute *attr, 306 300 const void *ns) 307 301 { 302 + } 303 + 304 + static inline bool sysfs_remove_file_self(struct kobject *kobj, 305 + const struct attribute *attr) 306 + { 307 + return false; 308 308 } 309 309 310 310 static inline void sysfs_remove_files(struct kobject *kobj, ··· 428 416 static inline int __must_check sysfs_init(void) 429 417 { 430 418 return 0; 419 + } 420 + 421 + static inline void sysfs_enable_ns(struct kernfs_node *kn) 422 + { 431 423 } 432 424 433 425 #endif /* CONFIG_SYSFS */
+1 -1
lib/kobject.c
··· 94 94 BUG_ON(ops->type >= KOBJ_NS_TYPES); 95 95 BUG_ON(!kobj_ns_type_registered(ops->type)); 96 96 97 - kernfs_enable_ns(kobj->sd); 97 + sysfs_enable_ns(kobj->sd); 98 98 } 99 99 100 100 return 0;
+3
scripts/mod/devicetable-offsets.c
··· 174 174 DEVID_FIELD(x86_cpu_id, model); 175 175 DEVID_FIELD(x86_cpu_id, vendor); 176 176 177 + DEVID(cpu_feature); 178 + DEVID_FIELD(cpu_feature, feature); 179 + 177 180 DEVID(mei_cl_device_id); 178 181 DEVID_FIELD(mei_cl_device_id, name); 179 182
+15 -5
scripts/mod/file2alias.c
··· 1110 1110 } 1111 1111 ADD_TO_DEVTABLE("amba", amba_id, do_amba_entry); 1112 1112 1113 - /* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,* 1113 + /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,* 1114 1114 * All fields are numbers. It would be nicer to use strings for vendor 1115 1115 * and feature, but getting those out of the build system here is too 1116 1116 * complicated. ··· 1124 1124 DEF_FIELD(symval, x86_cpu_id, model); 1125 1125 DEF_FIELD(symval, x86_cpu_id, vendor); 1126 1126 1127 - strcpy(alias, "x86cpu:"); 1128 - ADD(alias, "vendor:", vendor != X86_VENDOR_ANY, vendor); 1129 - ADD(alias, ":family:", family != X86_FAMILY_ANY, family); 1130 - ADD(alias, ":model:", model != X86_MODEL_ANY, model); 1127 + strcpy(alias, "cpu:type:x86,"); 1128 + ADD(alias, "ven", vendor != X86_VENDOR_ANY, vendor); 1129 + ADD(alias, "fam", family != X86_FAMILY_ANY, family); 1130 + ADD(alias, "mod", model != X86_MODEL_ANY, model); 1131 1131 strcat(alias, ":feature:*"); 1132 1132 if (feature != X86_FEATURE_ANY) 1133 1133 sprintf(alias + strlen(alias), "%04X*", feature); 1134 1134 return 1; 1135 1135 } 1136 1136 ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry); 1137 + 1138 + /* LOOKS like cpu:type:*:feature:*FEAT* */ 1139 + static int do_cpu_entry(const char *filename, void *symval, char *alias) 1140 + { 1141 + DEF_FIELD(symval, cpu_feature, feature); 1142 + 1143 + sprintf(alias, "cpu:type:*:feature:*%04X*", feature); 1144 + return 1; 1145 + } 1146 + ADD_TO_DEVTABLE("cpu", cpu_feature, do_cpu_entry); 1137 1147 1138 1148 /* Looks like: mei:S */ 1139 1149 static int do_mei_entry(const char *filename, void *symval,