summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-06-08 15:50:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-06-08 15:50:36 -0400
commit1ce2c85137b1db5b0e4158d558cb93dcff7674df (patch)
tree37f62adbc031e12747ba71f14b304edb8445fa82
parent902b2edfca34f88b04b86e605087e200e7e79880 (diff)
parente7bf2ce837475445bfd44ac1193ced0684a70d96 (diff)
Merge tag 'char-misc-5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver fixes from Greg KH: "Here are some small char and misc driver fixes for 5.2-rc4 to resolve a number of reported issues. The most "notable" one here is the kernel headers in proc^Wsysfs fixes. Those changes move the header file info into sysfs and fixes the build issues that you reported. Other than that, a bunch of small habanalabs driver fixes, some fpga driver fixes, and a few other tiny driver fixes. All of these have been in linux-next for a while with no reported issues" * tag 'char-misc-5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: habanalabs: Read upper bits of trace buffer from RWPHI habanalabs: Fix virtual address access via debugfs for 2MB pages fpga: zynqmp-fpga: Correctly handle error pointer habanalabs: fix bug in checking huge page optimization habanalabs: Avoid using a non-initialized MMU cache mutex habanalabs: fix debugfs code uapi/habanalabs: add opcode for enable/disable device debug mode habanalabs: halt debug engines on user process close test_firmware: Use correct snprintf() limit genwqe: Prevent an integer overflow in the ioctl parport: Fix mem leak in parport_register_dev_model fpga: dfl: expand minor range when registering chrdev region fpga: dfl: Add lockdep classes for pdata->lock fpga: dfl: afu: Pass the correct device to dma_mapping_error() fpga: stratix10-soc: fix use-after-free on s10_init() w1: ds2408: Fix typo after 49695ac46861 (reset on output_write retry with readback) kheaders: Do not regenerate archive if config is not changed kheaders: Move from proc to sysfs lkdtm/bugs: Adjust recursion test to avoid elision lkdtm/usercopy: Moves the KERNEL_DS test to non-canonical
-rw-r--r--drivers/fpga/dfl-afu-dma-region.c2
-rw-r--r--drivers/fpga/dfl.c22
-rw-r--r--drivers/fpga/stratix10-soc.c6
-rw-r--r--drivers/fpga/zynqmp-fpga.c4
-rw-r--r--drivers/misc/genwqe/card_dev.c2
-rw-r--r--drivers/misc/genwqe/card_utils.c4
-rw-r--r--drivers/misc/habanalabs/context.c6
-rw-r--r--drivers/misc/habanalabs/debugfs.c65
-rw-r--r--drivers/misc/habanalabs/device.c2
-rw-r--r--drivers/misc/habanalabs/goya/goya.c3
-rw-r--r--drivers/misc/habanalabs/goya/goyaP.h1
-rw-r--r--drivers/misc/habanalabs/goya/goya_coresight.c31
-rw-r--r--drivers/misc/habanalabs/habanalabs.h2
-rw-r--r--drivers/misc/habanalabs/memory.c6
-rw-r--r--drivers/misc/habanalabs/mmu.c8
-rw-r--r--drivers/misc/lkdtm/bugs.c23
-rw-r--r--drivers/misc/lkdtm/core.c6
-rw-r--r--drivers/misc/lkdtm/lkdtm.h2
-rw-r--r--drivers/misc/lkdtm/usercopy.c10
-rw-r--r--drivers/parport/share.c2
-rw-r--r--drivers/w1/slaves/w1_ds2408.c2
-rw-r--r--include/uapi/misc/habanalabs.h22
-rw-r--r--init/Kconfig17
-rw-r--r--kernel/Makefile4
-rwxr-xr-xkernel/gen_kheaders.sh (renamed from kernel/gen_ikh_data.sh)17
-rw-r--r--kernel/kheaders.c40
-rw-r--r--lib/test_firmware.c14
27 files changed, 192 insertions, 131 deletions
diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
index c438722bf4e1..dcd80b088c7b 100644
--- a/drivers/fpga/dfl-afu-dma-region.c
+++ b/drivers/fpga/dfl-afu-dma-region.c
@@ -399,7 +399,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata,
399 region->pages[0], 0, 399 region->pages[0], 0,
400 region->length, 400 region->length,
401 DMA_BIDIRECTIONAL); 401 DMA_BIDIRECTIONAL);
402 if (dma_mapping_error(&pdata->dev->dev, region->iova)) { 402 if (dma_mapping_error(dfl_fpga_pdata_to_parent(pdata), region->iova)) {
403 dev_err(&pdata->dev->dev, "failed to map for dma\n"); 403 dev_err(&pdata->dev->dev, "failed to map for dma\n");
404 ret = -EFAULT; 404 ret = -EFAULT;
405 goto unpin_pages; 405 goto unpin_pages;
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 2c09e502e721..4b66aaa32b5a 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -40,6 +40,13 @@ enum dfl_fpga_devt_type {
40 DFL_FPGA_DEVT_MAX, 40 DFL_FPGA_DEVT_MAX,
41}; 41};
42 42
43static struct lock_class_key dfl_pdata_keys[DFL_ID_MAX];
44
45static const char *dfl_pdata_key_strings[DFL_ID_MAX] = {
46 "dfl-fme-pdata",
47 "dfl-port-pdata",
48};
49
43/** 50/**
44 * dfl_dev_info - dfl feature device information. 51 * dfl_dev_info - dfl feature device information.
45 * @name: name string of the feature platform device. 52 * @name: name string of the feature platform device.
@@ -315,7 +322,7 @@ static void dfl_chardev_uinit(void)
315 for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) 322 for (i = 0; i < DFL_FPGA_DEVT_MAX; i++)
316 if (MAJOR(dfl_chrdevs[i].devt)) { 323 if (MAJOR(dfl_chrdevs[i].devt)) {
317 unregister_chrdev_region(dfl_chrdevs[i].devt, 324 unregister_chrdev_region(dfl_chrdevs[i].devt,
318 MINORMASK); 325 MINORMASK + 1);
319 dfl_chrdevs[i].devt = MKDEV(0, 0); 326 dfl_chrdevs[i].devt = MKDEV(0, 0);
320 } 327 }
321} 328}
@@ -325,8 +332,8 @@ static int dfl_chardev_init(void)
325 int i, ret; 332 int i, ret;
326 333
327 for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) { 334 for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) {
328 ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0, MINORMASK, 335 ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0,
329 dfl_chrdevs[i].name); 336 MINORMASK + 1, dfl_chrdevs[i].name);
330 if (ret) 337 if (ret)
331 goto exit; 338 goto exit;
332 } 339 }
@@ -443,11 +450,16 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
443 struct platform_device *fdev = binfo->feature_dev; 450 struct platform_device *fdev = binfo->feature_dev;
444 struct dfl_feature_platform_data *pdata; 451 struct dfl_feature_platform_data *pdata;
445 struct dfl_feature_info *finfo, *p; 452 struct dfl_feature_info *finfo, *p;
453 enum dfl_id_type type;
446 int ret, index = 0; 454 int ret, index = 0;
447 455
448 if (!fdev) 456 if (!fdev)
449 return 0; 457 return 0;
450 458
459 type = feature_dev_id_type(fdev);
460 if (WARN_ON_ONCE(type >= DFL_ID_MAX))
461 return -EINVAL;
462
451 /* 463 /*
452 * we do not need to care for the memory which is associated with 464 * we do not need to care for the memory which is associated with
453 * the platform device. After calling platform_device_unregister(), 465 * the platform device. After calling platform_device_unregister(),
@@ -463,6 +475,8 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
463 pdata->num = binfo->feature_num; 475 pdata->num = binfo->feature_num;
464 pdata->dfl_cdev = binfo->cdev; 476 pdata->dfl_cdev = binfo->cdev;
465 mutex_init(&pdata->lock); 477 mutex_init(&pdata->lock);
478 lockdep_set_class_and_name(&pdata->lock, &dfl_pdata_keys[type],
479 dfl_pdata_key_strings[type]);
466 480
467 /* 481 /*
468 * the count should be initialized to 0 to make sure 482 * the count should be initialized to 0 to make sure
@@ -497,7 +511,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
497 511
498 ret = platform_device_add(binfo->feature_dev); 512 ret = platform_device_add(binfo->feature_dev);
499 if (!ret) { 513 if (!ret) {
500 if (feature_dev_id_type(binfo->feature_dev) == PORT_ID) 514 if (type == PORT_ID)
501 dfl_fpga_cdev_add_port_dev(binfo->cdev, 515 dfl_fpga_cdev_add_port_dev(binfo->cdev,
502 binfo->feature_dev); 516 binfo->feature_dev);
503 else 517 else
diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
index 13851b3d1c56..215d33789c74 100644
--- a/drivers/fpga/stratix10-soc.c
+++ b/drivers/fpga/stratix10-soc.c
@@ -507,12 +507,16 @@ static int __init s10_init(void)
507 if (!fw_np) 507 if (!fw_np)
508 return -ENODEV; 508 return -ENODEV;
509 509
510 of_node_get(fw_np);
510 np = of_find_matching_node(fw_np, s10_of_match); 511 np = of_find_matching_node(fw_np, s10_of_match);
511 if (!np) 512 if (!np) {
513 of_node_put(fw_np);
512 return -ENODEV; 514 return -ENODEV;
515 }
513 516
514 of_node_put(np); 517 of_node_put(np);
515 ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL); 518 ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL);
519 of_node_put(fw_np);
516 if (ret) 520 if (ret)
517 return ret; 521 return ret;
518 522
diff --git a/drivers/fpga/zynqmp-fpga.c b/drivers/fpga/zynqmp-fpga.c
index f7cbaadf49ab..b8a88d21d038 100644
--- a/drivers/fpga/zynqmp-fpga.c
+++ b/drivers/fpga/zynqmp-fpga.c
@@ -47,7 +47,7 @@ static int zynqmp_fpga_ops_write(struct fpga_manager *mgr,
47 char *kbuf; 47 char *kbuf;
48 int ret; 48 int ret;
49 49
50 if (!eemi_ops || !eemi_ops->fpga_load) 50 if (IS_ERR_OR_NULL(eemi_ops) || !eemi_ops->fpga_load)
51 return -ENXIO; 51 return -ENXIO;
52 52
53 priv = mgr->priv; 53 priv = mgr->priv;
@@ -81,7 +81,7 @@ static enum fpga_mgr_states zynqmp_fpga_ops_state(struct fpga_manager *mgr)
81 const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops(); 81 const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
82 u32 status; 82 u32 status;
83 83
84 if (!eemi_ops || !eemi_ops->fpga_get_status) 84 if (IS_ERR_OR_NULL(eemi_ops) || !eemi_ops->fpga_get_status)
85 return FPGA_MGR_STATE_UNKNOWN; 85 return FPGA_MGR_STATE_UNKNOWN;
86 86
87 eemi_ops->fpga_get_status(&status); 87 eemi_ops->fpga_get_status(&status);
diff --git a/drivers/misc/genwqe/card_dev.c b/drivers/misc/genwqe/card_dev.c
index 8c1b63a4337b..d2098b4d2945 100644
--- a/drivers/misc/genwqe/card_dev.c
+++ b/drivers/misc/genwqe/card_dev.c
@@ -780,6 +780,8 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m)
780 780
781 if ((m->addr == 0x0) || (m->size == 0)) 781 if ((m->addr == 0x0) || (m->size == 0))
782 return -EINVAL; 782 return -EINVAL;
783 if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK))
784 return -EINVAL;
783 785
784 map_addr = (m->addr & PAGE_MASK); 786 map_addr = (m->addr & PAGE_MASK);
785 map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE); 787 map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index 89cff9d1012b..7571700abc6e 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -586,6 +586,10 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,
586 /* determine space needed for page_list. */ 586 /* determine space needed for page_list. */
587 data = (unsigned long)uaddr; 587 data = (unsigned long)uaddr;
588 offs = offset_in_page(data); 588 offs = offset_in_page(data);
589 if (size > ULONG_MAX - PAGE_SIZE - offs) {
590 m->size = 0; /* mark unused and not added */
591 return -EINVAL;
592 }
589 m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE); 593 m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE);
590 594
591 m->page_list = kcalloc(m->nr_pages, 595 m->page_list = kcalloc(m->nr_pages,
diff --git a/drivers/misc/habanalabs/context.c b/drivers/misc/habanalabs/context.c
index 4804cdcf4c48..f4c92f110a72 100644
--- a/drivers/misc/habanalabs/context.c
+++ b/drivers/misc/habanalabs/context.c
@@ -26,6 +26,12 @@ static void hl_ctx_fini(struct hl_ctx *ctx)
26 dma_fence_put(ctx->cs_pending[i]); 26 dma_fence_put(ctx->cs_pending[i]);
27 27
28 if (ctx->asid != HL_KERNEL_ASID_ID) { 28 if (ctx->asid != HL_KERNEL_ASID_ID) {
29 /*
30 * The engines are stopped as there is no executing CS, but the
31 * Coresight might be still working by accessing addresses
32 * related to the stopped engines. Hence stop it explicitly.
33 */
34 hdev->asic_funcs->halt_coresight(hdev);
29 hl_vm_ctx_fini(ctx); 35 hl_vm_ctx_fini(ctx);
30 hl_asid_free(hdev, ctx->asid); 36 hl_asid_free(hdev, ctx->asid);
31 } 37 }
diff --git a/drivers/misc/habanalabs/debugfs.c b/drivers/misc/habanalabs/debugfs.c
index a4447699ff4e..ba418aaa404c 100644
--- a/drivers/misc/habanalabs/debugfs.c
+++ b/drivers/misc/habanalabs/debugfs.c
@@ -459,41 +459,31 @@ static ssize_t mmu_write(struct file *file, const char __user *buf,
459 struct hl_debugfs_entry *entry = s->private; 459 struct hl_debugfs_entry *entry = s->private;
460 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; 460 struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
461 struct hl_device *hdev = dev_entry->hdev; 461 struct hl_device *hdev = dev_entry->hdev;
462 char kbuf[MMU_KBUF_SIZE], asid_kbuf[MMU_ASID_BUF_SIZE], 462 char kbuf[MMU_KBUF_SIZE];
463 addr_kbuf[MMU_ADDR_BUF_SIZE];
464 char *c; 463 char *c;
465 ssize_t rc; 464 ssize_t rc;
466 465
467 if (!hdev->mmu_enable) 466 if (!hdev->mmu_enable)
468 return count; 467 return count;
469 468
470 memset(kbuf, 0, sizeof(kbuf)); 469 if (count > sizeof(kbuf) - 1)
471 memset(asid_kbuf, 0, sizeof(asid_kbuf)); 470 goto err;
472 memset(addr_kbuf, 0, sizeof(addr_kbuf));
473
474 if (copy_from_user(kbuf, buf, count)) 471 if (copy_from_user(kbuf, buf, count))
475 goto err; 472 goto err;
476 473 kbuf[count] = 0;
477 kbuf[MMU_KBUF_SIZE - 1] = 0;
478 474
479 c = strchr(kbuf, ' '); 475 c = strchr(kbuf, ' ');
480 if (!c) 476 if (!c)
481 goto err; 477 goto err;
478 *c = '\0';
482 479
483 memcpy(asid_kbuf, kbuf, c - kbuf); 480 rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid);
484
485 rc = kstrtouint(asid_kbuf, 10, &dev_entry->mmu_asid);
486 if (rc) 481 if (rc)
487 goto err; 482 goto err;
488 483
489 c = strstr(kbuf, " 0x"); 484 if (strncmp(c+1, "0x", 2))
490 if (!c)
491 goto err; 485 goto err;
492 486 rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr);
493 c += 3;
494 memcpy(addr_kbuf, c, (kbuf + count) - c);
495
496 rc = kstrtoull(addr_kbuf, 16, &dev_entry->mmu_addr);
497 if (rc) 487 if (rc)
498 goto err; 488 goto err;
499 489
@@ -510,6 +500,7 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
510{ 500{
511 struct hl_ctx *ctx = hdev->user_ctx; 501 struct hl_ctx *ctx = hdev->user_ctx;
512 u64 hop_addr, hop_pte_addr, hop_pte; 502 u64 hop_addr, hop_pte_addr, hop_pte;
503 u64 offset_mask = HOP4_MASK | OFFSET_MASK;
513 int rc = 0; 504 int rc = 0;
514 505
515 if (!ctx) { 506 if (!ctx) {
@@ -552,12 +543,14 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
552 goto not_mapped; 543 goto not_mapped;
553 hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr); 544 hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr);
554 hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr); 545 hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr);
546
547 offset_mask = OFFSET_MASK;
555 } 548 }
556 549
557 if (!(hop_pte & PAGE_PRESENT_MASK)) 550 if (!(hop_pte & PAGE_PRESENT_MASK))
558 goto not_mapped; 551 goto not_mapped;
559 552
560 *phys_addr = (hop_pte & PTE_PHYS_ADDR_MASK) | (virt_addr & OFFSET_MASK); 553 *phys_addr = (hop_pte & ~offset_mask) | (virt_addr & offset_mask);
561 554
562 goto out; 555 goto out;
563 556
@@ -600,10 +593,8 @@ static ssize_t hl_data_read32(struct file *f, char __user *buf,
600 } 593 }
601 594
602 sprintf(tmp_buf, "0x%08x\n", val); 595 sprintf(tmp_buf, "0x%08x\n", val);
603 rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 596 return simple_read_from_buffer(buf, count, ppos, tmp_buf,
604 strlen(tmp_buf) + 1); 597 strlen(tmp_buf));
605
606 return rc;
607} 598}
608 599
609static ssize_t hl_data_write32(struct file *f, const char __user *buf, 600static ssize_t hl_data_write32(struct file *f, const char __user *buf,
@@ -645,7 +636,6 @@ static ssize_t hl_get_power_state(struct file *f, char __user *buf,
645 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; 636 struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
646 struct hl_device *hdev = entry->hdev; 637 struct hl_device *hdev = entry->hdev;
647 char tmp_buf[200]; 638 char tmp_buf[200];
648 ssize_t rc;
649 int i; 639 int i;
650 640
651 if (*ppos) 641 if (*ppos)
@@ -660,10 +650,8 @@ static ssize_t hl_get_power_state(struct file *f, char __user *buf,
660 650
661 sprintf(tmp_buf, 651 sprintf(tmp_buf,
662 "current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i); 652 "current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i);
663 rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 653 return simple_read_from_buffer(buf, count, ppos, tmp_buf,
664 strlen(tmp_buf) + 1); 654 strlen(tmp_buf));
665
666 return rc;
667} 655}
668 656
669static ssize_t hl_set_power_state(struct file *f, const char __user *buf, 657static ssize_t hl_set_power_state(struct file *f, const char __user *buf,
@@ -716,8 +704,8 @@ static ssize_t hl_i2c_data_read(struct file *f, char __user *buf,
716 } 704 }
717 705
718 sprintf(tmp_buf, "0x%02x\n", val); 706 sprintf(tmp_buf, "0x%02x\n", val);
719 rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 707 rc = simple_read_from_buffer(buf, count, ppos, tmp_buf,
720 strlen(tmp_buf) + 1); 708 strlen(tmp_buf));
721 709
722 return rc; 710 return rc;
723} 711}
@@ -806,18 +794,9 @@ static ssize_t hl_led2_write(struct file *f, const char __user *buf,
806static ssize_t hl_device_read(struct file *f, char __user *buf, 794static ssize_t hl_device_read(struct file *f, char __user *buf,
807 size_t count, loff_t *ppos) 795 size_t count, loff_t *ppos)
808{ 796{
809 char tmp_buf[200]; 797 static const char *help =
810 ssize_t rc; 798 "Valid values: disable, enable, suspend, resume, cpu_timeout\n";
811 799 return simple_read_from_buffer(buf, count, ppos, help, strlen(help));
812 if (*ppos)
813 return 0;
814
815 sprintf(tmp_buf,
816 "Valid values: disable, enable, suspend, resume, cpu_timeout\n");
817 rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
818 strlen(tmp_buf) + 1);
819
820 return rc;
821} 800}
822 801
823static ssize_t hl_device_write(struct file *f, const char __user *buf, 802static ssize_t hl_device_write(struct file *f, const char __user *buf,
@@ -825,7 +804,7 @@ static ssize_t hl_device_write(struct file *f, const char __user *buf,
825{ 804{
826 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; 805 struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
827 struct hl_device *hdev = entry->hdev; 806 struct hl_device *hdev = entry->hdev;
828 char data[30]; 807 char data[30] = {0};
829 808
830 /* don't allow partial writes */ 809 /* don't allow partial writes */
831 if (*ppos != 0) 810 if (*ppos != 0)
diff --git a/drivers/misc/habanalabs/device.c b/drivers/misc/habanalabs/device.c
index 91a9e47a3482..0b19d3eefb98 100644
--- a/drivers/misc/habanalabs/device.c
+++ b/drivers/misc/habanalabs/device.c
@@ -231,6 +231,7 @@ static int device_early_init(struct hl_device *hdev)
231 231
232 mutex_init(&hdev->fd_open_cnt_lock); 232 mutex_init(&hdev->fd_open_cnt_lock);
233 mutex_init(&hdev->send_cpu_message_lock); 233 mutex_init(&hdev->send_cpu_message_lock);
234 mutex_init(&hdev->mmu_cache_lock);
234 INIT_LIST_HEAD(&hdev->hw_queues_mirror_list); 235 INIT_LIST_HEAD(&hdev->hw_queues_mirror_list);
235 spin_lock_init(&hdev->hw_queues_mirror_lock); 236 spin_lock_init(&hdev->hw_queues_mirror_lock);
236 atomic_set(&hdev->in_reset, 0); 237 atomic_set(&hdev->in_reset, 0);
@@ -260,6 +261,7 @@ early_fini:
260 */ 261 */
261static void device_early_fini(struct hl_device *hdev) 262static void device_early_fini(struct hl_device *hdev)
262{ 263{
264 mutex_destroy(&hdev->mmu_cache_lock);
263 mutex_destroy(&hdev->send_cpu_message_lock); 265 mutex_destroy(&hdev->send_cpu_message_lock);
264 266
265 hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr); 267 hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr);
diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
index a582e29c1ee4..02d116b01a1a 100644
--- a/drivers/misc/habanalabs/goya/goya.c
+++ b/drivers/misc/habanalabs/goya/goya.c
@@ -4819,7 +4819,8 @@ static const struct hl_asic_funcs goya_funcs = {
4819 .set_dram_bar_base = goya_set_ddr_bar_base, 4819 .set_dram_bar_base = goya_set_ddr_bar_base,
4820 .init_iatu = goya_init_iatu, 4820 .init_iatu = goya_init_iatu,
4821 .rreg = hl_rreg, 4821 .rreg = hl_rreg,
4822 .wreg = hl_wreg 4822 .wreg = hl_wreg,
4823 .halt_coresight = goya_halt_coresight
4823}; 4824};
4824 4825
4825/* 4826/*
diff --git a/drivers/misc/habanalabs/goya/goyaP.h b/drivers/misc/habanalabs/goya/goyaP.h
index 14e216cb3668..c83cab0d641e 100644
--- a/drivers/misc/habanalabs/goya/goyaP.h
+++ b/drivers/misc/habanalabs/goya/goyaP.h
@@ -202,6 +202,7 @@ void goya_add_device_attr(struct hl_device *hdev,
202 struct attribute_group *dev_attr_grp); 202 struct attribute_group *dev_attr_grp);
203int goya_armcp_info_get(struct hl_device *hdev); 203int goya_armcp_info_get(struct hl_device *hdev);
204int goya_debug_coresight(struct hl_device *hdev, void *data); 204int goya_debug_coresight(struct hl_device *hdev, void *data);
205void goya_halt_coresight(struct hl_device *hdev);
205 206
206void goya_mmu_prepare(struct hl_device *hdev, u32 asid); 207void goya_mmu_prepare(struct hl_device *hdev, u32 asid);
207int goya_mmu_clear_pgt_range(struct hl_device *hdev); 208int goya_mmu_clear_pgt_range(struct hl_device *hdev);
diff --git a/drivers/misc/habanalabs/goya/goya_coresight.c b/drivers/misc/habanalabs/goya/goya_coresight.c
index 1ac951f52d1e..d7ec7ad84cc6 100644
--- a/drivers/misc/habanalabs/goya/goya_coresight.c
+++ b/drivers/misc/habanalabs/goya/goya_coresight.c
@@ -425,8 +425,18 @@ static int goya_config_etr(struct hl_device *hdev,
425 WREG32(base_reg + 0x28, 0); 425 WREG32(base_reg + 0x28, 0);
426 WREG32(base_reg + 0x304, 0); 426 WREG32(base_reg + 0x304, 0);
427 427
428 if (params->output_size >= sizeof(u32)) 428 if (params->output_size >= sizeof(u64)) {
429 *(u32 *) params->output = RREG32(base_reg + 0x18); 429 u32 rwp, rwphi;
430
431 /*
432 * The trace buffer address is 40 bits wide. The end of
433 * the buffer is set in the RWP register (lower 32
434 * bits), and in the RWPHI register (upper 8 bits).
435 */
436 rwp = RREG32(base_reg + 0x18);
437 rwphi = RREG32(base_reg + 0x3c) & 0xff;
438 *(u64 *) params->output = ((u64) rwphi << 32) | rwp;
439 }
430 } 440 }
431 441
432 return 0; 442 return 0;
@@ -626,3 +636,20 @@ int goya_debug_coresight(struct hl_device *hdev, void *data)
626 636
627 return rc; 637 return rc;
628} 638}
639
640void goya_halt_coresight(struct hl_device *hdev)
641{
642 struct hl_debug_params params = {};
643 int i, rc;
644
645 for (i = GOYA_ETF_FIRST ; i <= GOYA_ETF_LAST ; i++) {
646 params.reg_idx = i;
647 rc = goya_config_etf(hdev, &params);
648 if (rc)
649 dev_err(hdev->dev, "halt ETF failed, %d/%d\n", rc, i);
650 }
651
652 rc = goya_config_etr(hdev, &params);
653 if (rc)
654 dev_err(hdev->dev, "halt ETR failed, %d\n", rc);
655}
diff --git a/drivers/misc/habanalabs/habanalabs.h b/drivers/misc/habanalabs/habanalabs.h
index 71243b319920..adef7d9d7488 100644
--- a/drivers/misc/habanalabs/habanalabs.h
+++ b/drivers/misc/habanalabs/habanalabs.h
@@ -501,6 +501,7 @@ enum hl_pll_frequency {
501 * @init_iatu: Initialize the iATU unit inside the PCI controller. 501 * @init_iatu: Initialize the iATU unit inside the PCI controller.
502 * @rreg: Read a register. Needed for simulator support. 502 * @rreg: Read a register. Needed for simulator support.
503 * @wreg: Write a register. Needed for simulator support. 503 * @wreg: Write a register. Needed for simulator support.
504 * @halt_coresight: stop the ETF and ETR traces.
504 */ 505 */
505struct hl_asic_funcs { 506struct hl_asic_funcs {
506 int (*early_init)(struct hl_device *hdev); 507 int (*early_init)(struct hl_device *hdev);
@@ -578,6 +579,7 @@ struct hl_asic_funcs {
578 int (*init_iatu)(struct hl_device *hdev); 579 int (*init_iatu)(struct hl_device *hdev);
579 u32 (*rreg)(struct hl_device *hdev, u32 reg); 580 u32 (*rreg)(struct hl_device *hdev, u32 reg);
580 void (*wreg)(struct hl_device *hdev, u32 reg, u32 val); 581 void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
582 void (*halt_coresight)(struct hl_device *hdev);
581}; 583};
582 584
583 585
diff --git a/drivers/misc/habanalabs/memory.c b/drivers/misc/habanalabs/memory.c
index d67d24c13efd..693877e37fd8 100644
--- a/drivers/misc/habanalabs/memory.c
+++ b/drivers/misc/habanalabs/memory.c
@@ -675,11 +675,6 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx,
675 675
676 total_npages += npages; 676 total_npages += npages;
677 677
678 if (first) {
679 first = false;
680 dma_addr &= PAGE_MASK_2MB;
681 }
682
683 if ((npages % PGS_IN_2MB_PAGE) || 678 if ((npages % PGS_IN_2MB_PAGE) ||
684 (dma_addr & (PAGE_SIZE_2MB - 1))) 679 (dma_addr & (PAGE_SIZE_2MB - 1)))
685 is_huge_page_opt = false; 680 is_huge_page_opt = false;
@@ -704,7 +699,6 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx,
704 phys_pg_pack->total_size = total_npages * page_size; 699 phys_pg_pack->total_size = total_npages * page_size;
705 700
706 j = 0; 701 j = 0;
707 first = true;
708 for_each_sg(userptr->sgt->sgl, sg, userptr->sgt->nents, i) { 702 for_each_sg(userptr->sgt->sgl, sg, userptr->sgt->nents, i) {
709 npages = get_sg_info(sg, &dma_addr); 703 npages = get_sg_info(sg, &dma_addr);
710 704
diff --git a/drivers/misc/habanalabs/mmu.c b/drivers/misc/habanalabs/mmu.c
index 533d9315b6fb..10aee3141444 100644
--- a/drivers/misc/habanalabs/mmu.c
+++ b/drivers/misc/habanalabs/mmu.c
@@ -404,15 +404,12 @@ int hl_mmu_init(struct hl_device *hdev)
404 404
405 /* MMU H/W init was already done in device hw_init() */ 405 /* MMU H/W init was already done in device hw_init() */
406 406
407 mutex_init(&hdev->mmu_cache_lock);
408
409 hdev->mmu_pgt_pool = 407 hdev->mmu_pgt_pool =
410 gen_pool_create(__ffs(prop->mmu_hop_table_size), -1); 408 gen_pool_create(__ffs(prop->mmu_hop_table_size), -1);
411 409
412 if (!hdev->mmu_pgt_pool) { 410 if (!hdev->mmu_pgt_pool) {
413 dev_err(hdev->dev, "Failed to create page gen pool\n"); 411 dev_err(hdev->dev, "Failed to create page gen pool\n");
414 rc = -ENOMEM; 412 return -ENOMEM;
415 goto err_pool_create;
416 } 413 }
417 414
418 rc = gen_pool_add(hdev->mmu_pgt_pool, prop->mmu_pgt_addr + 415 rc = gen_pool_add(hdev->mmu_pgt_pool, prop->mmu_pgt_addr +
@@ -436,8 +433,6 @@ int hl_mmu_init(struct hl_device *hdev)
436 433
437err_pool_add: 434err_pool_add:
438 gen_pool_destroy(hdev->mmu_pgt_pool); 435 gen_pool_destroy(hdev->mmu_pgt_pool);
439err_pool_create:
440 mutex_destroy(&hdev->mmu_cache_lock);
441 436
442 return rc; 437 return rc;
443} 438}
@@ -459,7 +454,6 @@ void hl_mmu_fini(struct hl_device *hdev)
459 454
460 kvfree(hdev->mmu_shadow_hop0); 455 kvfree(hdev->mmu_shadow_hop0);
461 gen_pool_destroy(hdev->mmu_pgt_pool); 456 gen_pool_destroy(hdev->mmu_pgt_pool);
462 mutex_destroy(&hdev->mmu_cache_lock);
463 457
464 /* MMU H/W fini will be done in device hw_fini() */ 458 /* MMU H/W fini will be done in device hw_fini() */
465} 459}
diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
index 7eebbdfbcacd..17f839dee976 100644
--- a/drivers/misc/lkdtm/bugs.c
+++ b/drivers/misc/lkdtm/bugs.c
@@ -32,12 +32,20 @@ static int recur_count = REC_NUM_DEFAULT;
32 32
33static DEFINE_SPINLOCK(lock_me_up); 33static DEFINE_SPINLOCK(lock_me_up);
34 34
35static int recursive_loop(int remaining) 35/*
36 * Make sure compiler does not optimize this function or stack frame away:
37 * - function marked noinline
38 * - stack variables are marked volatile
39 * - stack variables are written (memset()) and read (pr_info())
40 * - function has external effects (pr_info())
41 * */
42static int noinline recursive_loop(int remaining)
36{ 43{
37 char buf[REC_STACK_SIZE]; 44 volatile char buf[REC_STACK_SIZE];
38 45
39 /* Make sure compiler does not optimize this away. */ 46 memset((void *)buf, remaining & 0xFF, sizeof(buf));
40 memset(buf, (remaining & 0xff) | 0x1, REC_STACK_SIZE); 47 pr_info("loop %d/%d ...\n", (int)buf[remaining % sizeof(buf)],
48 recur_count);
41 if (!remaining) 49 if (!remaining)
42 return 0; 50 return 0;
43 else 51 else
@@ -81,9 +89,12 @@ void lkdtm_LOOP(void)
81 ; 89 ;
82} 90}
83 91
84void lkdtm_OVERFLOW(void) 92void lkdtm_EXHAUST_STACK(void)
85{ 93{
86 (void) recursive_loop(recur_count); 94 pr_info("Calling function with %d frame size to depth %d ...\n",
95 REC_STACK_SIZE, recur_count);
96 recursive_loop(recur_count);
97 pr_info("FAIL: survived without exhausting stack?!\n");
87} 98}
88 99
89static noinline void __lkdtm_CORRUPT_STACK(void *stack) 100static noinline void __lkdtm_CORRUPT_STACK(void *stack)
diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
index 1972dad966f5..8a1428d4f138 100644
--- a/drivers/misc/lkdtm/core.c
+++ b/drivers/misc/lkdtm/core.c
@@ -106,12 +106,12 @@ static const struct crashtype crashtypes[] = {
106 CRASHTYPE(WARNING), 106 CRASHTYPE(WARNING),
107 CRASHTYPE(EXCEPTION), 107 CRASHTYPE(EXCEPTION),
108 CRASHTYPE(LOOP), 108 CRASHTYPE(LOOP),
109 CRASHTYPE(OVERFLOW), 109 CRASHTYPE(EXHAUST_STACK),
110 CRASHTYPE(CORRUPT_STACK),
111 CRASHTYPE(CORRUPT_STACK_STRONG),
110 CRASHTYPE(CORRUPT_LIST_ADD), 112 CRASHTYPE(CORRUPT_LIST_ADD),
111 CRASHTYPE(CORRUPT_LIST_DEL), 113 CRASHTYPE(CORRUPT_LIST_DEL),
112 CRASHTYPE(CORRUPT_USER_DS), 114 CRASHTYPE(CORRUPT_USER_DS),
113 CRASHTYPE(CORRUPT_STACK),
114 CRASHTYPE(CORRUPT_STACK_STRONG),
115 CRASHTYPE(STACK_GUARD_PAGE_LEADING), 115 CRASHTYPE(STACK_GUARD_PAGE_LEADING),
116 CRASHTYPE(STACK_GUARD_PAGE_TRAILING), 116 CRASHTYPE(STACK_GUARD_PAGE_TRAILING),
117 CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE), 117 CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE),
diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h
index b69ee004a3f7..23dc565b4307 100644
--- a/drivers/misc/lkdtm/lkdtm.h
+++ b/drivers/misc/lkdtm/lkdtm.h
@@ -13,7 +13,7 @@ void lkdtm_BUG(void);
13void lkdtm_WARNING(void); 13void lkdtm_WARNING(void);
14void lkdtm_EXCEPTION(void); 14void lkdtm_EXCEPTION(void);
15void lkdtm_LOOP(void); 15void lkdtm_LOOP(void);
16void lkdtm_OVERFLOW(void); 16void lkdtm_EXHAUST_STACK(void);
17void lkdtm_CORRUPT_STACK(void); 17void lkdtm_CORRUPT_STACK(void);
18void lkdtm_CORRUPT_STACK_STRONG(void); 18void lkdtm_CORRUPT_STACK_STRONG(void);
19void lkdtm_UNALIGNED_LOAD_STORE_WRITE(void); 19void lkdtm_UNALIGNED_LOAD_STORE_WRITE(void);
diff --git a/drivers/misc/lkdtm/usercopy.c b/drivers/misc/lkdtm/usercopy.c
index d5a0e7f1813b..e172719dd86d 100644
--- a/drivers/misc/lkdtm/usercopy.c
+++ b/drivers/misc/lkdtm/usercopy.c
@@ -324,14 +324,16 @@ free_user:
324 324
325void lkdtm_USERCOPY_KERNEL_DS(void) 325void lkdtm_USERCOPY_KERNEL_DS(void)
326{ 326{
327 char __user *user_ptr = (char __user *)ERR_PTR(-EINVAL); 327 char __user *user_ptr =
328 (char __user *)(0xFUL << (sizeof(unsigned long) * 8 - 4));
328 mm_segment_t old_fs = get_fs(); 329 mm_segment_t old_fs = get_fs();
329 char buf[10] = {0}; 330 char buf[10] = {0};
330 331
331 pr_info("attempting copy_to_user on unmapped kernel address\n"); 332 pr_info("attempting copy_to_user() to noncanonical address: %px\n",
333 user_ptr);
332 set_fs(KERNEL_DS); 334 set_fs(KERNEL_DS);
333 if (copy_to_user(user_ptr, buf, sizeof(buf))) 335 if (copy_to_user(user_ptr, buf, sizeof(buf)) == 0)
334 pr_info("copy_to_user un unmapped kernel address failed\n"); 336 pr_err("copy_to_user() to noncanonical address succeeded!?\n");
335 set_fs(old_fs); 337 set_fs(old_fs);
336} 338}
337 339
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index 5dc53d420ca8..7b4ee33c1935 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -895,6 +895,7 @@ parport_register_dev_model(struct parport *port, const char *name,
895 par_dev->devmodel = true; 895 par_dev->devmodel = true;
896 ret = device_register(&par_dev->dev); 896 ret = device_register(&par_dev->dev);
897 if (ret) { 897 if (ret) {
898 kfree(par_dev->state);
898 put_device(&par_dev->dev); 899 put_device(&par_dev->dev);
899 goto err_put_port; 900 goto err_put_port;
900 } 901 }
@@ -912,6 +913,7 @@ parport_register_dev_model(struct parport *port, const char *name,
912 spin_unlock(&port->physport->pardevice_lock); 913 spin_unlock(&port->physport->pardevice_lock);
913 pr_debug("%s: cannot grant exclusive access for device %s\n", 914 pr_debug("%s: cannot grant exclusive access for device %s\n",
914 port->name, name); 915 port->name, name);
916 kfree(par_dev->state);
915 device_unregister(&par_dev->dev); 917 device_unregister(&par_dev->dev);
916 goto err_put_port; 918 goto err_put_port;
917 } 919 }
diff --git a/drivers/w1/slaves/w1_ds2408.c b/drivers/w1/slaves/w1_ds2408.c
index 92e8f0755b9a..edf0bc98012c 100644
--- a/drivers/w1/slaves/w1_ds2408.c
+++ b/drivers/w1/slaves/w1_ds2408.c
@@ -138,7 +138,7 @@ static ssize_t status_control_read(struct file *filp, struct kobject *kobj,
138 W1_F29_REG_CONTROL_AND_STATUS, buf); 138 W1_F29_REG_CONTROL_AND_STATUS, buf);
139} 139}
140 140
141#ifdef fCONFIG_W1_SLAVE_DS2408_READBACK 141#ifdef CONFIG_W1_SLAVE_DS2408_READBACK
142static bool optional_read_back_valid(struct w1_slave *sl, u8 expected) 142static bool optional_read_back_valid(struct w1_slave *sl, u8 expected)
143{ 143{
144 u8 w1_buf[3]; 144 u8 w1_buf[3];
diff --git a/include/uapi/misc/habanalabs.h b/include/uapi/misc/habanalabs.h
index 8ac292cf4d00..204ab9b4ae67 100644
--- a/include/uapi/misc/habanalabs.h
+++ b/include/uapi/misc/habanalabs.h
@@ -413,6 +413,10 @@ struct hl_debug_params_spmu {
413#define HL_DEBUG_OP_SPMU 5 413#define HL_DEBUG_OP_SPMU 5
414/* Opcode for timestamp */ 414/* Opcode for timestamp */
415#define HL_DEBUG_OP_TIMESTAMP 6 415#define HL_DEBUG_OP_TIMESTAMP 6
416/* Opcode for setting the device into or out of debug mode. The enable
417 * variable should be 1 for enabling debug mode and 0 for disabling it
418 */
419#define HL_DEBUG_OP_SET_MODE 7
416 420
417struct hl_debug_args { 421struct hl_debug_args {
418 /* 422 /*
@@ -574,8 +578,22 @@ struct hl_debug_args {
574 * 578 *
575 * This IOCTL allows the user to get debug traces from the chip. 579 * This IOCTL allows the user to get debug traces from the chip.
576 * 580 *
577 * The user needs to provide the register index and essential data such as 581 * Before the user can send configuration requests of the various
578 * buffer address and size. 582 * debug/profile engines, it needs to set the device into debug mode.
583 * This is because the debug/profile infrastructure is shared component in the
584 * device and we can't allow multiple users to access it at the same time.
585 *
586 * Once a user set the device into debug mode, the driver won't allow other
587 * users to "work" with the device, i.e. open a FD. If there are multiple users
588 * opened on the device, the driver won't allow any user to debug the device.
589 *
590 * For each configuration request, the user needs to provide the register index
591 * and essential data such as buffer address and size.
592 *
593 * Once the user has finished using the debug/profile engines, he should
594 * set the device into non-debug mode, i.e. disable debug mode.
595 *
596 * The driver can decide to "kick out" the user if he abuses this interface.
579 * 597 *
580 */ 598 */
581#define HL_IOCTL_DEBUG \ 599#define HL_IOCTL_DEBUG \
diff --git a/init/Kconfig b/init/Kconfig
index 36894c9fb420..0e2344389501 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -580,15 +580,14 @@ config IKCONFIG_PROC
580 This option enables access to the kernel configuration file 580 This option enables access to the kernel configuration file
581 through /proc/config.gz. 581 through /proc/config.gz.
582 582
583config IKHEADERS_PROC 583config IKHEADERS
584 tristate "Enable kernel header artifacts through /proc/kheaders.tar.xz" 584 tristate "Enable kernel headers through /sys/kernel/kheaders.tar.xz"
585 depends on PROC_FS 585 depends on SYSFS
586 help 586 help
587 This option enables access to the kernel header and other artifacts that 587 This option enables access to the in-kernel headers that are generated during
588 are generated during the build process. These can be used to build eBPF 588 the build process. These can be used to build eBPF tracing programs,
589 tracing programs, or similar programs. If you build the headers as a 589 or similar programs. If you build the headers as a module, a module called
590 module, a module called kheaders.ko is built which can be loaded on-demand 590 kheaders.ko is built which can be loaded on-demand to get access to headers.
591 to get access to the headers.
592 591
593config LOG_BUF_SHIFT 592config LOG_BUF_SHIFT
594 int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" 593 int "Kernel log buffer size (16 => 64KB, 17 => 128KB)"
diff --git a/kernel/Makefile b/kernel/Makefile
index 33824f0385b3..a8d923b5481b 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -71,7 +71,7 @@ obj-$(CONFIG_UTS_NS) += utsname.o
71obj-$(CONFIG_USER_NS) += user_namespace.o 71obj-$(CONFIG_USER_NS) += user_namespace.o
72obj-$(CONFIG_PID_NS) += pid_namespace.o 72obj-$(CONFIG_PID_NS) += pid_namespace.o
73obj-$(CONFIG_IKCONFIG) += configs.o 73obj-$(CONFIG_IKCONFIG) += configs.o
74obj-$(CONFIG_IKHEADERS_PROC) += kheaders.o 74obj-$(CONFIG_IKHEADERS) += kheaders.o
75obj-$(CONFIG_SMP) += stop_machine.o 75obj-$(CONFIG_SMP) += stop_machine.o
76obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o 76obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
77obj-$(CONFIG_AUDIT) += audit.o auditfilter.o 77obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
@@ -127,7 +127,7 @@ $(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
127$(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz 127$(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz
128 128
129quiet_cmd_genikh = CHK $(obj)/kheaders_data.tar.xz 129quiet_cmd_genikh = CHK $(obj)/kheaders_data.tar.xz
130cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_ikh_data.sh $@ 130cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_kheaders.sh $@
131$(obj)/kheaders_data.tar.xz: FORCE 131$(obj)/kheaders_data.tar.xz: FORCE
132 $(call cmd,genikh) 132 $(call cmd,genikh)
133 133
diff --git a/kernel/gen_ikh_data.sh b/kernel/gen_kheaders.sh
index 591a94f7b387..9a34e1d9bd7f 100755
--- a/kernel/gen_ikh_data.sh
+++ b/kernel/gen_kheaders.sh
@@ -2,7 +2,7 @@
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3 3
4# This script generates an archive consisting of kernel headers 4# This script generates an archive consisting of kernel headers
5# for CONFIG_IKHEADERS_PROC. 5# for CONFIG_IKHEADERS.
6set -e 6set -e
7spath="$(dirname "$(readlink -f "$0")")" 7spath="$(dirname "$(readlink -f "$0")")"
8kroot="$spath/.." 8kroot="$spath/.."
@@ -31,9 +31,8 @@ arch/$SRCARCH/include/
31 31
32# This block is useful for debugging the incremental builds. 32# This block is useful for debugging the incremental builds.
33# Uncomment it for debugging. 33# Uncomment it for debugging.
34# iter=1 34# if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
35# if [ ! -f /tmp/iter ]; then echo 1 > /tmp/iter; 35# else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
36# else; iter=$(($(cat /tmp/iter) + 1)); fi
37# find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter 36# find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter
38# find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter 37# find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter
39 38
@@ -43,10 +42,18 @@ arch/$SRCARCH/include/
43pushd $kroot > /dev/null 42pushd $kroot > /dev/null
44src_files_md5="$(find $src_file_list -type f | 43src_files_md5="$(find $src_file_list -type f |
45 grep -v "include/generated/compile.h" | 44 grep -v "include/generated/compile.h" |
45 grep -v "include/generated/autoconf.h" |
46 grep -v "include/config/auto.conf" |
47 grep -v "include/config/auto.conf.cmd" |
48 grep -v "include/config/tristate.conf" |
46 xargs ls -lR | md5sum | cut -d ' ' -f1)" 49 xargs ls -lR | md5sum | cut -d ' ' -f1)"
47popd > /dev/null 50popd > /dev/null
48obj_files_md5="$(find $obj_file_list -type f | 51obj_files_md5="$(find $obj_file_list -type f |
49 grep -v "include/generated/compile.h" | 52 grep -v "include/generated/compile.h" |
53 grep -v "include/generated/autoconf.h" |
54 grep -v "include/config/auto.conf" |
55 grep -v "include/config/auto.conf.cmd" |
56 grep -v "include/config/tristate.conf" |
50 xargs ls -lR | md5sum | cut -d ' ' -f1)" 57 xargs ls -lR | md5sum | cut -d ' ' -f1)"
51 58
52if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi 59if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
@@ -82,7 +89,7 @@ find $cpio_dir -type f -print0 |
82 89
83tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null 90tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
84 91
85echo "$src_files_md5" > kernel/kheaders.md5 92echo "$src_files_md5" > kernel/kheaders.md5
86echo "$obj_files_md5" >> kernel/kheaders.md5 93echo "$obj_files_md5" >> kernel/kheaders.md5
87echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5 94echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
88 95
diff --git a/kernel/kheaders.c b/kernel/kheaders.c
index 70ae6052920d..8f69772af77b 100644
--- a/kernel/kheaders.c
+++ b/kernel/kheaders.c
@@ -8,9 +8,8 @@
8 8
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/proc_fs.h> 11#include <linux/kobject.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/uaccess.h>
14 13
15/* 14/*
16 * Define kernel_headers_data and kernel_headers_data_end, within which the 15 * Define kernel_headers_data and kernel_headers_data_end, within which the
@@ -31,39 +30,32 @@ extern char kernel_headers_data;
31extern char kernel_headers_data_end; 30extern char kernel_headers_data_end;
32 31
33static ssize_t 32static ssize_t
34ikheaders_read_current(struct file *file, char __user *buf, 33ikheaders_read(struct file *file, struct kobject *kobj,
35 size_t len, loff_t *offset) 34 struct bin_attribute *bin_attr,
35 char *buf, loff_t off, size_t len)
36{ 36{
37 return simple_read_from_buffer(buf, len, offset, 37 memcpy(buf, &kernel_headers_data + off, len);
38 &kernel_headers_data, 38 return len;
39 &kernel_headers_data_end -
40 &kernel_headers_data);
41} 39}
42 40
43static const struct file_operations ikheaders_file_ops = { 41static struct bin_attribute kheaders_attr __ro_after_init = {
44 .read = ikheaders_read_current, 42 .attr = {
45 .llseek = default_llseek, 43 .name = "kheaders.tar.xz",
44 .mode = 0444,
45 },
46 .read = &ikheaders_read,
46}; 47};
47 48
48static int __init ikheaders_init(void) 49static int __init ikheaders_init(void)
49{ 50{
50 struct proc_dir_entry *entry; 51 kheaders_attr.size = (&kernel_headers_data_end -
51 52 &kernel_headers_data);
52 /* create the current headers file */ 53 return sysfs_create_bin_file(kernel_kobj, &kheaders_attr);
53 entry = proc_create("kheaders.tar.xz", S_IRUGO, NULL,
54 &ikheaders_file_ops);
55 if (!entry)
56 return -ENOMEM;
57
58 proc_set_size(entry,
59 &kernel_headers_data_end -
60 &kernel_headers_data);
61 return 0;
62} 54}
63 55
64static void __exit ikheaders_cleanup(void) 56static void __exit ikheaders_cleanup(void)
65{ 57{
66 remove_proc_entry("kheaders.tar.xz", NULL); 58 sysfs_remove_bin_file(kernel_kobj, &kheaders_attr);
67} 59}
68 60
69module_init(ikheaders_init); 61module_init(ikheaders_init);
diff --git a/lib/test_firmware.c b/lib/test_firmware.c
index 787c146eb485..83ea6c4e623c 100644
--- a/lib/test_firmware.c
+++ b/lib/test_firmware.c
@@ -224,30 +224,30 @@ static ssize_t config_show(struct device *dev,
224 224
225 mutex_lock(&test_fw_mutex); 225 mutex_lock(&test_fw_mutex);
226 226
227 len += snprintf(buf, PAGE_SIZE, 227 len += scnprintf(buf, PAGE_SIZE - len,
228 "Custom trigger configuration for: %s\n", 228 "Custom trigger configuration for: %s\n",
229 dev_name(dev)); 229 dev_name(dev));
230 230
231 if (test_fw_config->name) 231 if (test_fw_config->name)
232 len += snprintf(buf+len, PAGE_SIZE, 232 len += scnprintf(buf+len, PAGE_SIZE - len,
233 "name:\t%s\n", 233 "name:\t%s\n",
234 test_fw_config->name); 234 test_fw_config->name);
235 else 235 else
236 len += snprintf(buf+len, PAGE_SIZE, 236 len += scnprintf(buf+len, PAGE_SIZE - len,
237 "name:\tEMTPY\n"); 237 "name:\tEMTPY\n");
238 238
239 len += snprintf(buf+len, PAGE_SIZE, 239 len += scnprintf(buf+len, PAGE_SIZE - len,
240 "num_requests:\t%u\n", test_fw_config->num_requests); 240 "num_requests:\t%u\n", test_fw_config->num_requests);
241 241
242 len += snprintf(buf+len, PAGE_SIZE, 242 len += scnprintf(buf+len, PAGE_SIZE - len,
243 "send_uevent:\t\t%s\n", 243 "send_uevent:\t\t%s\n",
244 test_fw_config->send_uevent ? 244 test_fw_config->send_uevent ?
245 "FW_ACTION_HOTPLUG" : 245 "FW_ACTION_HOTPLUG" :
246 "FW_ACTION_NOHOTPLUG"); 246 "FW_ACTION_NOHOTPLUG");
247 len += snprintf(buf+len, PAGE_SIZE, 247 len += scnprintf(buf+len, PAGE_SIZE - len,
248 "sync_direct:\t\t%s\n", 248 "sync_direct:\t\t%s\n",
249 test_fw_config->sync_direct ? "true" : "false"); 249 test_fw_config->sync_direct ? "true" : "false");
250 len += snprintf(buf+len, PAGE_SIZE, 250 len += scnprintf(buf+len, PAGE_SIZE - len,
251 "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx); 251 "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx);
252 252
253 mutex_unlock(&test_fw_mutex); 253 mutex_unlock(&test_fw_mutex);