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

Configure Feed

Select the types of activity you want to include in your feed.

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

+191 -130
+1 -1
drivers/fpga/dfl-afu-dma-region.c
··· 399 399 region->pages[0], 0, 400 400 region->length, 401 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 403 dev_err(&pdata->dev->dev, "failed to map for dma\n"); 404 404 ret = -EFAULT; 405 405 goto unpin_pages;
+18 -4
drivers/fpga/dfl.c
··· 40 40 DFL_FPGA_DEVT_MAX, 41 41 }; 42 42 43 + static struct lock_class_key dfl_pdata_keys[DFL_ID_MAX]; 44 + 45 + static const char *dfl_pdata_key_strings[DFL_ID_MAX] = { 46 + "dfl-fme-pdata", 47 + "dfl-port-pdata", 48 + }; 49 + 43 50 /** 44 51 * dfl_dev_info - dfl feature device information. 45 52 * @name: name string of the feature platform device. ··· 322 315 for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) 323 316 if (MAJOR(dfl_chrdevs[i].devt)) { 324 317 unregister_chrdev_region(dfl_chrdevs[i].devt, 325 - MINORMASK); 318 + MINORMASK + 1); 326 319 dfl_chrdevs[i].devt = MKDEV(0, 0); 327 320 } 328 321 } ··· 332 325 int i, ret; 333 326 334 327 for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) { 335 - ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0, MINORMASK, 336 - dfl_chrdevs[i].name); 328 + ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0, 329 + MINORMASK + 1, dfl_chrdevs[i].name); 337 330 if (ret) 338 331 goto exit; 339 332 } ··· 450 443 struct platform_device *fdev = binfo->feature_dev; 451 444 struct dfl_feature_platform_data *pdata; 452 445 struct dfl_feature_info *finfo, *p; 446 + enum dfl_id_type type; 453 447 int ret, index = 0; 454 448 455 449 if (!fdev) 456 450 return 0; 451 + 452 + type = feature_dev_id_type(fdev); 453 + if (WARN_ON_ONCE(type >= DFL_ID_MAX)) 454 + return -EINVAL; 457 455 458 456 /* 459 457 * we do not need to care for the memory which is associated with ··· 475 463 pdata->num = binfo->feature_num; 476 464 pdata->dfl_cdev = binfo->cdev; 477 465 mutex_init(&pdata->lock); 466 + lockdep_set_class_and_name(&pdata->lock, &dfl_pdata_keys[type], 467 + dfl_pdata_key_strings[type]); 478 468 479 469 /* 480 470 * the count should be initialized to 0 to make sure ··· 511 497 512 498 ret = platform_device_add(binfo->feature_dev); 513 499 if (!ret) { 514 - if (feature_dev_id_type(binfo->feature_dev) == PORT_ID) 500 + if (type == PORT_ID) 515 501 dfl_fpga_cdev_add_port_dev(binfo->cdev, 516 502 binfo->feature_dev); 517 503 else
+5 -1
drivers/fpga/stratix10-soc.c
··· 507 507 if (!fw_np) 508 508 return -ENODEV; 509 509 510 + of_node_get(fw_np); 510 511 np = of_find_matching_node(fw_np, s10_of_match); 511 - if (!np) 512 + if (!np) { 513 + of_node_put(fw_np); 512 514 return -ENODEV; 515 + } 513 516 514 517 of_node_put(np); 515 518 ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL); 519 + of_node_put(fw_np); 516 520 if (ret) 517 521 return ret; 518 522
+2 -2
drivers/fpga/zynqmp-fpga.c
··· 47 47 char *kbuf; 48 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 51 return -ENXIO; 52 52 53 53 priv = mgr->priv; ··· 81 81 const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops(); 82 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 85 return FPGA_MGR_STATE_UNKNOWN; 86 86 87 87 eemi_ops->fpga_get_status(&status);
+2
drivers/misc/genwqe/card_dev.c
··· 780 780 781 781 if ((m->addr == 0x0) || (m->size == 0)) 782 782 return -EINVAL; 783 + if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK)) 784 + return -EINVAL; 783 785 784 786 map_addr = (m->addr & PAGE_MASK); 785 787 map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
+4
drivers/misc/genwqe/card_utils.c
··· 586 586 /* determine space needed for page_list. */ 587 587 data = (unsigned long)uaddr; 588 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 593 m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE); 590 594 591 595 m->page_list = kcalloc(m->nr_pages,
+6
drivers/misc/habanalabs/context.c
··· 26 26 dma_fence_put(ctx->cs_pending[i]); 27 27 28 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 35 hl_vm_ctx_fini(ctx); 30 36 hl_asid_free(hdev, ctx->asid); 31 37 }
+22 -43
drivers/misc/habanalabs/debugfs.c
··· 459 459 struct hl_debugfs_entry *entry = s->private; 460 460 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; 461 461 struct hl_device *hdev = dev_entry->hdev; 462 - char kbuf[MMU_KBUF_SIZE], asid_kbuf[MMU_ASID_BUF_SIZE], 463 - addr_kbuf[MMU_ADDR_BUF_SIZE]; 462 + char kbuf[MMU_KBUF_SIZE]; 464 463 char *c; 465 464 ssize_t rc; 466 465 467 466 if (!hdev->mmu_enable) 468 467 return count; 469 468 470 - memset(kbuf, 0, sizeof(kbuf)); 471 - memset(asid_kbuf, 0, sizeof(asid_kbuf)); 472 - memset(addr_kbuf, 0, sizeof(addr_kbuf)); 473 - 469 + if (count > sizeof(kbuf) - 1) 470 + goto err; 474 471 if (copy_from_user(kbuf, buf, count)) 475 472 goto err; 476 - 477 - kbuf[MMU_KBUF_SIZE - 1] = 0; 473 + kbuf[count] = 0; 478 474 479 475 c = strchr(kbuf, ' '); 480 476 if (!c) 481 477 goto err; 478 + *c = '\0'; 482 479 483 - memcpy(asid_kbuf, kbuf, c - kbuf); 484 - 485 - rc = kstrtouint(asid_kbuf, 10, &dev_entry->mmu_asid); 480 + rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid); 486 481 if (rc) 487 482 goto err; 488 483 489 - c = strstr(kbuf, " 0x"); 490 - if (!c) 484 + if (strncmp(c+1, "0x", 2)) 491 485 goto err; 492 - 493 - c += 3; 494 - memcpy(addr_kbuf, c, (kbuf + count) - c); 495 - 496 - rc = kstrtoull(addr_kbuf, 16, &dev_entry->mmu_addr); 486 + rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr); 497 487 if (rc) 498 488 goto err; 499 489 ··· 500 510 { 501 511 struct hl_ctx *ctx = hdev->user_ctx; 502 512 u64 hop_addr, hop_pte_addr, hop_pte; 513 + u64 offset_mask = HOP4_MASK | OFFSET_MASK; 503 514 int rc = 0; 504 515 505 516 if (!ctx) { ··· 543 552 goto not_mapped; 544 553 hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr); 545 554 hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr); 555 + 556 + offset_mask = OFFSET_MASK; 546 557 } 547 558 548 559 if (!(hop_pte & PAGE_PRESENT_MASK)) 549 560 goto not_mapped; 550 561 551 - *phys_addr = (hop_pte & PTE_PHYS_ADDR_MASK) | (virt_addr & OFFSET_MASK); 562 + *phys_addr = (hop_pte & ~offset_mask) | (virt_addr & offset_mask); 552 563 553 564 goto out; 554 565 ··· 593 600 } 594 601 595 602 sprintf(tmp_buf, "0x%08x\n", val); 596 - rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 597 - strlen(tmp_buf) + 1); 598 - 599 - return rc; 603 + return simple_read_from_buffer(buf, count, ppos, tmp_buf, 604 + strlen(tmp_buf)); 600 605 } 601 606 602 607 static ssize_t hl_data_write32(struct file *f, const char __user *buf, ··· 636 645 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; 637 646 struct hl_device *hdev = entry->hdev; 638 647 char tmp_buf[200]; 639 - ssize_t rc; 640 648 int i; 641 649 642 650 if (*ppos) ··· 650 660 651 661 sprintf(tmp_buf, 652 662 "current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i); 653 - rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 654 - strlen(tmp_buf) + 1); 655 - 656 - return rc; 663 + return simple_read_from_buffer(buf, count, ppos, tmp_buf, 664 + strlen(tmp_buf)); 657 665 } 658 666 659 667 static ssize_t hl_set_power_state(struct file *f, const char __user *buf, ··· 704 716 } 705 717 706 718 sprintf(tmp_buf, "0x%02x\n", val); 707 - rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 708 - strlen(tmp_buf) + 1); 719 + rc = simple_read_from_buffer(buf, count, ppos, tmp_buf, 720 + strlen(tmp_buf)); 709 721 710 722 return rc; 711 723 } ··· 794 806 static ssize_t hl_device_read(struct file *f, char __user *buf, 795 807 size_t count, loff_t *ppos) 796 808 { 797 - char tmp_buf[200]; 798 - ssize_t rc; 799 - 800 - if (*ppos) 801 - return 0; 802 - 803 - sprintf(tmp_buf, 804 - "Valid values: disable, enable, suspend, resume, cpu_timeout\n"); 805 - rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf, 806 - strlen(tmp_buf) + 1); 807 - 808 - return rc; 809 + static const char *help = 810 + "Valid values: disable, enable, suspend, resume, cpu_timeout\n"; 811 + return simple_read_from_buffer(buf, count, ppos, help, strlen(help)); 809 812 } 810 813 811 814 static ssize_t hl_device_write(struct file *f, const char __user *buf, ··· 804 825 { 805 826 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; 806 827 struct hl_device *hdev = entry->hdev; 807 - char data[30]; 828 + char data[30] = {0}; 808 829 809 830 /* don't allow partial writes */ 810 831 if (*ppos != 0)
+2
drivers/misc/habanalabs/device.c
··· 231 231 232 232 mutex_init(&hdev->fd_open_cnt_lock); 233 233 mutex_init(&hdev->send_cpu_message_lock); 234 + mutex_init(&hdev->mmu_cache_lock); 234 235 INIT_LIST_HEAD(&hdev->hw_queues_mirror_list); 235 236 spin_lock_init(&hdev->hw_queues_mirror_lock); 236 237 atomic_set(&hdev->in_reset, 0); ··· 261 260 */ 262 261 static void device_early_fini(struct hl_device *hdev) 263 262 { 263 + mutex_destroy(&hdev->mmu_cache_lock); 264 264 mutex_destroy(&hdev->send_cpu_message_lock); 265 265 266 266 hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr);
+2 -1
drivers/misc/habanalabs/goya/goya.c
··· 4819 4819 .set_dram_bar_base = goya_set_ddr_bar_base, 4820 4820 .init_iatu = goya_init_iatu, 4821 4821 .rreg = hl_rreg, 4822 - .wreg = hl_wreg 4822 + .wreg = hl_wreg, 4823 + .halt_coresight = goya_halt_coresight 4823 4824 }; 4824 4825 4825 4826 /*
+1
drivers/misc/habanalabs/goya/goyaP.h
··· 202 202 struct attribute_group *dev_attr_grp); 203 203 int goya_armcp_info_get(struct hl_device *hdev); 204 204 int goya_debug_coresight(struct hl_device *hdev, void *data); 205 + void goya_halt_coresight(struct hl_device *hdev); 205 206 206 207 void goya_mmu_prepare(struct hl_device *hdev, u32 asid); 207 208 int goya_mmu_clear_pgt_range(struct hl_device *hdev);
+29 -2
drivers/misc/habanalabs/goya/goya_coresight.c
··· 425 425 WREG32(base_reg + 0x28, 0); 426 426 WREG32(base_reg + 0x304, 0); 427 427 428 - if (params->output_size >= sizeof(u32)) 429 - *(u32 *) params->output = RREG32(base_reg + 0x18); 428 + if (params->output_size >= sizeof(u64)) { 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 442 return 0; ··· 635 625 val = RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG); 636 626 637 627 return rc; 628 + } 629 + 630 + void goya_halt_coresight(struct hl_device *hdev) 631 + { 632 + struct hl_debug_params params = {}; 633 + int i, rc; 634 + 635 + for (i = GOYA_ETF_FIRST ; i <= GOYA_ETF_LAST ; i++) { 636 + params.reg_idx = i; 637 + rc = goya_config_etf(hdev, &params); 638 + if (rc) 639 + dev_err(hdev->dev, "halt ETF failed, %d/%d\n", rc, i); 640 + } 641 + 642 + rc = goya_config_etr(hdev, &params); 643 + if (rc) 644 + dev_err(hdev->dev, "halt ETR failed, %d\n", rc); 638 645 }
+2
drivers/misc/habanalabs/habanalabs.h
··· 501 501 * @init_iatu: Initialize the iATU unit inside the PCI controller. 502 502 * @rreg: Read a register. Needed for simulator support. 503 503 * @wreg: Write a register. Needed for simulator support. 504 + * @halt_coresight: stop the ETF and ETR traces. 504 505 */ 505 506 struct hl_asic_funcs { 506 507 int (*early_init)(struct hl_device *hdev); ··· 579 578 int (*init_iatu)(struct hl_device *hdev); 580 579 u32 (*rreg)(struct hl_device *hdev, u32 reg); 581 580 void (*wreg)(struct hl_device *hdev, u32 reg, u32 val); 581 + void (*halt_coresight)(struct hl_device *hdev); 582 582 }; 583 583 584 584
-6
drivers/misc/habanalabs/memory.c
··· 675 675 676 676 total_npages += npages; 677 677 678 - if (first) { 679 - first = false; 680 - dma_addr &= PAGE_MASK_2MB; 681 - } 682 - 683 678 if ((npages % PGS_IN_2MB_PAGE) || 684 679 (dma_addr & (PAGE_SIZE_2MB - 1))) 685 680 is_huge_page_opt = false; ··· 699 704 phys_pg_pack->total_size = total_npages * page_size; 700 705 701 706 j = 0; 702 - first = true; 703 707 for_each_sg(userptr->sgt->sgl, sg, userptr->sgt->nents, i) { 704 708 npages = get_sg_info(sg, &dma_addr); 705 709
+1 -7
drivers/misc/habanalabs/mmu.c
··· 404 404 405 405 /* MMU H/W init was already done in device hw_init() */ 406 406 407 - mutex_init(&hdev->mmu_cache_lock); 408 - 409 407 hdev->mmu_pgt_pool = 410 408 gen_pool_create(__ffs(prop->mmu_hop_table_size), -1); 411 409 412 410 if (!hdev->mmu_pgt_pool) { 413 411 dev_err(hdev->dev, "Failed to create page gen pool\n"); 414 - rc = -ENOMEM; 415 - goto err_pool_create; 412 + return -ENOMEM; 416 413 } 417 414 418 415 rc = gen_pool_add(hdev->mmu_pgt_pool, prop->mmu_pgt_addr + ··· 433 436 434 437 err_pool_add: 435 438 gen_pool_destroy(hdev->mmu_pgt_pool); 436 - err_pool_create: 437 - mutex_destroy(&hdev->mmu_cache_lock); 438 439 439 440 return rc; 440 441 } ··· 454 459 455 460 kvfree(hdev->mmu_shadow_hop0); 456 461 gen_pool_destroy(hdev->mmu_pgt_pool); 457 - mutex_destroy(&hdev->mmu_cache_lock); 458 462 459 463 /* MMU H/W fini will be done in device hw_fini() */ 460 464 }
+17 -6
drivers/misc/lkdtm/bugs.c
··· 32 32 33 33 static DEFINE_SPINLOCK(lock_me_up); 34 34 35 - static 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 + * */ 42 + static 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. */ 40 - memset(buf, (remaining & 0xff) | 0x1, REC_STACK_SIZE); 46 + memset((void *)buf, remaining & 0xFF, sizeof(buf)); 47 + pr_info("loop %d/%d ...\n", (int)buf[remaining % sizeof(buf)], 48 + recur_count); 41 49 if (!remaining) 42 50 return 0; 43 51 else ··· 89 81 ; 90 82 } 91 83 92 - void lkdtm_OVERFLOW(void) 84 + void lkdtm_EXHAUST_STACK(void) 93 85 { 94 - (void) recursive_loop(recur_count); 86 + pr_info("Calling function with %d frame size to depth %d ...\n", 87 + REC_STACK_SIZE, recur_count); 88 + recursive_loop(recur_count); 89 + pr_info("FAIL: survived without exhausting stack?!\n"); 95 90 } 96 91 97 92 static noinline void __lkdtm_CORRUPT_STACK(void *stack)
+3 -3
drivers/misc/lkdtm/core.c
··· 106 106 CRASHTYPE(WARNING), 107 107 CRASHTYPE(EXCEPTION), 108 108 CRASHTYPE(LOOP), 109 - CRASHTYPE(OVERFLOW), 109 + CRASHTYPE(EXHAUST_STACK), 110 + CRASHTYPE(CORRUPT_STACK), 111 + CRASHTYPE(CORRUPT_STACK_STRONG), 110 112 CRASHTYPE(CORRUPT_LIST_ADD), 111 113 CRASHTYPE(CORRUPT_LIST_DEL), 112 114 CRASHTYPE(CORRUPT_USER_DS), 113 - CRASHTYPE(CORRUPT_STACK), 114 - CRASHTYPE(CORRUPT_STACK_STRONG), 115 115 CRASHTYPE(STACK_GUARD_PAGE_LEADING), 116 116 CRASHTYPE(STACK_GUARD_PAGE_TRAILING), 117 117 CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE),
+1 -1
drivers/misc/lkdtm/lkdtm.h
··· 13 13 void lkdtm_WARNING(void); 14 14 void lkdtm_EXCEPTION(void); 15 15 void lkdtm_LOOP(void); 16 - void lkdtm_OVERFLOW(void); 16 + void lkdtm_EXHAUST_STACK(void); 17 17 void lkdtm_CORRUPT_STACK(void); 18 18 void lkdtm_CORRUPT_STACK_STRONG(void); 19 19 void lkdtm_UNALIGNED_LOAD_STORE_WRITE(void);
+6 -4
drivers/misc/lkdtm/usercopy.c
··· 324 324 325 325 void 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 329 mm_segment_t old_fs = get_fs(); 329 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 334 set_fs(KERNEL_DS); 333 - if (copy_to_user(user_ptr, buf, sizeof(buf))) 334 - pr_info("copy_to_user un unmapped kernel address failed\n"); 335 + if (copy_to_user(user_ptr, buf, sizeof(buf)) == 0) 336 + pr_err("copy_to_user() to noncanonical address succeeded!?\n"); 335 337 set_fs(old_fs); 336 338 } 337 339
+2
drivers/parport/share.c
··· 895 895 par_dev->devmodel = true; 896 896 ret = device_register(&par_dev->dev); 897 897 if (ret) { 898 + kfree(par_dev->state); 898 899 put_device(&par_dev->dev); 899 900 goto err_put_port; 900 901 } ··· 913 912 spin_unlock(&port->physport->pardevice_lock); 914 913 pr_debug("%s: cannot grant exclusive access for device %s\n", 915 914 port->name, name); 915 + kfree(par_dev->state); 916 916 device_unregister(&par_dev->dev); 917 917 goto err_put_port; 918 918 }
+1 -1
drivers/w1/slaves/w1_ds2408.c
··· 138 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 142 142 static bool optional_read_back_valid(struct w1_slave *sl, u8 expected) 143 143 { 144 144 u8 w1_buf[3];
+20 -2
include/uapi/misc/habanalabs.h
··· 413 413 #define HL_DEBUG_OP_SPMU 5 414 414 /* Opcode for timestamp */ 415 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 417 421 struct hl_debug_args { 418 422 /* ··· 578 574 * 579 575 * This IOCTL allows the user to get debug traces from the chip. 580 576 * 581 - * The user needs to provide the register index and essential data such as 582 - * buffer address and size. 577 + * Before the user can send configuration requests of the various 578 + * debug/profile engines, it needs to set the device into debug mode. 579 + * This is because the debug/profile infrastructure is shared component in the 580 + * device and we can't allow multiple users to access it at the same time. 581 + * 582 + * Once a user set the device into debug mode, the driver won't allow other 583 + * users to "work" with the device, i.e. open a FD. If there are multiple users 584 + * opened on the device, the driver won't allow any user to debug the device. 585 + * 586 + * For each configuration request, the user needs to provide the register index 587 + * and essential data such as buffer address and size. 588 + * 589 + * Once the user has finished using the debug/profile engines, he should 590 + * set the device into non-debug mode, i.e. disable debug mode. 591 + * 592 + * The driver can decide to "kick out" the user if he abuses this interface. 583 593 * 584 594 */ 585 595 #define HL_IOCTL_DEBUG \
+7 -8
init/Kconfig
··· 580 580 This option enables access to the kernel configuration file 581 581 through /proc/config.gz. 582 582 583 - config IKHEADERS_PROC 584 - tristate "Enable kernel header artifacts through /proc/kheaders.tar.xz" 585 - depends on PROC_FS 583 + config IKHEADERS 584 + tristate "Enable kernel headers through /sys/kernel/kheaders.tar.xz" 585 + depends on SYSFS 586 586 help 587 - This option enables access to the kernel header and other artifacts that 588 - are generated during the build process. These can be used to build eBPF 589 - tracing programs, or similar programs. If you build the headers as a 590 - module, a module called kheaders.ko is built which can be loaded on-demand 591 - to get access to the headers. 587 + This option enables access to the in-kernel headers that are generated during 588 + the build process. These can be used to build eBPF tracing programs, 589 + or similar programs. If you build the headers as a module, a module called 590 + kheaders.ko is built which can be loaded on-demand to get access to headers. 592 591 593 592 config LOG_BUF_SHIFT 594 593 int "Kernel log buffer size (16 => 64KB, 17 => 128KB)"
+2 -2
kernel/Makefile
··· 71 71 obj-$(CONFIG_USER_NS) += user_namespace.o 72 72 obj-$(CONFIG_PID_NS) += pid_namespace.o 73 73 obj-$(CONFIG_IKCONFIG) += configs.o 74 - obj-$(CONFIG_IKHEADERS_PROC) += kheaders.o 74 + obj-$(CONFIG_IKHEADERS) += kheaders.o 75 75 obj-$(CONFIG_SMP) += stop_machine.o 76 76 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o 77 77 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o ··· 127 127 $(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz 128 128 129 129 quiet_cmd_genikh = CHK $(obj)/kheaders_data.tar.xz 130 - cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_ikh_data.sh $@ 130 + cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_kheaders.sh $@ 131 131 $(obj)/kheaders_data.tar.xz: FORCE 132 132 $(call cmd,genikh) 133 133
+12 -5
kernel/gen_ikh_data.sh kernel/gen_kheaders.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 # This script generates an archive consisting of kernel headers 5 - # for CONFIG_IKHEADERS_PROC. 5 + # for CONFIG_IKHEADERS. 6 6 set -e 7 7 spath="$(dirname "$(readlink -f "$0")")" 8 8 kroot="$spath/.." ··· 31 31 32 32 # This block is useful for debugging the incremental builds. 33 33 # Uncomment it for debugging. 34 - # iter=1 35 - # if [ ! -f /tmp/iter ]; then echo 1 > /tmp/iter; 36 - # else; iter=$(($(cat /tmp/iter) + 1)); fi 34 + # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter; 35 + # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi 37 36 # find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter 38 37 # find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter 39 38 ··· 42 43 pushd $kroot > /dev/null 43 44 src_files_md5="$(find $src_file_list -type f | 44 45 grep -v "include/generated/compile.h" | 46 + grep -v "include/generated/autoconf.h" | 47 + grep -v "include/config/auto.conf" | 48 + grep -v "include/config/auto.conf.cmd" | 49 + grep -v "include/config/tristate.conf" | 45 50 xargs ls -lR | md5sum | cut -d ' ' -f1)" 46 51 popd > /dev/null 47 52 obj_files_md5="$(find $obj_file_list -type f | 48 53 grep -v "include/generated/compile.h" | 54 + grep -v "include/generated/autoconf.h" | 55 + grep -v "include/config/auto.conf" | 56 + grep -v "include/config/auto.conf.cmd" | 57 + grep -v "include/config/tristate.conf" | 49 58 xargs ls -lR | md5sum | cut -d ' ' -f1)" 50 59 51 60 if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi ··· 89 82 90 83 tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null 91 84 92 - echo "$src_files_md5" > kernel/kheaders.md5 85 + echo "$src_files_md5" > kernel/kheaders.md5 93 86 echo "$obj_files_md5" >> kernel/kheaders.md5 94 87 echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5 95 88
+16 -24
kernel/kheaders.c
··· 8 8 9 9 #include <linux/kernel.h> 10 10 #include <linux/module.h> 11 - #include <linux/proc_fs.h> 11 + #include <linux/kobject.h> 12 12 #include <linux/init.h> 13 - #include <linux/uaccess.h> 14 13 15 14 /* 16 15 * Define kernel_headers_data and kernel_headers_data_end, within which the ··· 30 31 extern char kernel_headers_data_end; 31 32 32 33 static ssize_t 33 - ikheaders_read_current(struct file *file, char __user *buf, 34 - size_t len, loff_t *offset) 34 + ikheaders_read(struct file *file, struct kobject *kobj, 35 + struct bin_attribute *bin_attr, 36 + char *buf, loff_t off, size_t len) 35 37 { 36 - return simple_read_from_buffer(buf, len, offset, 37 - &kernel_headers_data, 38 - &kernel_headers_data_end - 39 - &kernel_headers_data); 38 + memcpy(buf, &kernel_headers_data + off, len); 39 + return len; 40 40 } 41 41 42 - static const struct file_operations ikheaders_file_ops = { 43 - .read = ikheaders_read_current, 44 - .llseek = default_llseek, 42 + static struct bin_attribute kheaders_attr __ro_after_init = { 43 + .attr = { 44 + .name = "kheaders.tar.xz", 45 + .mode = 0444, 46 + }, 47 + .read = &ikheaders_read, 45 48 }; 46 49 47 50 static int __init ikheaders_init(void) 48 51 { 49 - struct proc_dir_entry *entry; 50 - 51 - /* create the current headers file */ 52 - entry = proc_create("kheaders.tar.xz", S_IRUGO, NULL, 53 - &ikheaders_file_ops); 54 - if (!entry) 55 - return -ENOMEM; 56 - 57 - proc_set_size(entry, 58 - &kernel_headers_data_end - 59 - &kernel_headers_data); 60 - return 0; 52 + kheaders_attr.size = (&kernel_headers_data_end - 53 + &kernel_headers_data); 54 + return sysfs_create_bin_file(kernel_kobj, &kheaders_attr); 61 55 } 62 56 63 57 static void __exit ikheaders_cleanup(void) 64 58 { 65 - remove_proc_entry("kheaders.tar.xz", NULL); 59 + sysfs_remove_bin_file(kernel_kobj, &kheaders_attr); 66 60 } 67 61 68 62 module_init(ikheaders_init);
+7 -7
lib/test_firmware.c
··· 224 224 225 225 mutex_lock(&test_fw_mutex); 226 226 227 - len += snprintf(buf, PAGE_SIZE, 227 + len += scnprintf(buf, PAGE_SIZE - len, 228 228 "Custom trigger configuration for: %s\n", 229 229 dev_name(dev)); 230 230 231 231 if (test_fw_config->name) 232 - len += snprintf(buf+len, PAGE_SIZE, 232 + len += scnprintf(buf+len, PAGE_SIZE - len, 233 233 "name:\t%s\n", 234 234 test_fw_config->name); 235 235 else 236 - len += snprintf(buf+len, PAGE_SIZE, 236 + len += scnprintf(buf+len, PAGE_SIZE - len, 237 237 "name:\tEMTPY\n"); 238 238 239 - len += snprintf(buf+len, PAGE_SIZE, 239 + len += scnprintf(buf+len, PAGE_SIZE - len, 240 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 243 "send_uevent:\t\t%s\n", 244 244 test_fw_config->send_uevent ? 245 245 "FW_ACTION_HOTPLUG" : 246 246 "FW_ACTION_NOHOTPLUG"); 247 - len += snprintf(buf+len, PAGE_SIZE, 247 + len += scnprintf(buf+len, PAGE_SIZE - len, 248 248 "sync_direct:\t\t%s\n", 249 249 test_fw_config->sync_direct ? "true" : "false"); 250 - len += snprintf(buf+len, PAGE_SIZE, 250 + len += scnprintf(buf+len, PAGE_SIZE - len, 251 251 "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx); 252 252 253 253 mutex_unlock(&test_fw_mutex);