Skip to content

Commit 1ce2c85

Browse files
committed
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 49695ac (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
2 parents 902b2ed + e7bf2ce commit 1ce2c85

27 files changed

Lines changed: 192 additions & 131 deletions

‎drivers/fpga/dfl-afu-dma-region.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata,
399399
region->pages[0], 0,
400400
region->length,
401401
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)) {
403403
dev_err(&pdata->dev->dev, "failed to map for dma\n");
404404
ret = -EFAULT;
405405
goto unpin_pages;

‎drivers/fpga/dfl.c‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ enum dfl_fpga_devt_type {
4040
DFL_FPGA_DEVT_MAX,
4141
};
4242

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+
4350
/**
4451
* dfl_dev_info - dfl feature device information.
4552
* @name: name string of the feature platform device.
@@ -315,7 +322,7 @@ static void dfl_chardev_uinit(void)
315322
for (i = 0; i < DFL_FPGA_DEVT_MAX; i++)
316323
if (MAJOR(dfl_chrdevs[i].devt)) {
317324
unregister_chrdev_region(dfl_chrdevs[i].devt,
318-
MINORMASK);
325+
MINORMASK + 1);
319326
dfl_chrdevs[i].devt = MKDEV(0, 0);
320327
}
321328
}
@@ -325,8 +332,8 @@ static int dfl_chardev_init(void)
325332
int i, ret;
326333

327334
for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) {
328-
ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0, MINORMASK,
329-
dfl_chrdevs[i].name);
335+
ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0,
336+
MINORMASK + 1, dfl_chrdevs[i].name);
330337
if (ret)
331338
goto exit;
332339
}
@@ -443,11 +450,16 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
443450
struct platform_device *fdev = binfo->feature_dev;
444451
struct dfl_feature_platform_data *pdata;
445452
struct dfl_feature_info *finfo, *p;
453+
enum dfl_id_type type;
446454
int ret, index = 0;
447455

448456
if (!fdev)
449457
return 0;
450458

459+
type = feature_dev_id_type(fdev);
460+
if (WARN_ON_ONCE(type >= DFL_ID_MAX))
461+
return -EINVAL;
462+
451463
/*
452464
* we do not need to care for the memory which is associated with
453465
* the platform device. After calling platform_device_unregister(),
@@ -463,6 +475,8 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
463475
pdata->num = binfo->feature_num;
464476
pdata->dfl_cdev = binfo->cdev;
465477
mutex_init(&pdata->lock);
478+
lockdep_set_class_and_name(&pdata->lock, &dfl_pdata_keys[type],
479+
dfl_pdata_key_strings[type]);
466480

467481
/*
468482
* 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)
497511

498512
ret = platform_device_add(binfo->feature_dev);
499513
if (!ret) {
500-
if (feature_dev_id_type(binfo->feature_dev) == PORT_ID)
514+
if (type == PORT_ID)
501515
dfl_fpga_cdev_add_port_dev(binfo->cdev,
502516
binfo->feature_dev);
503517
else

‎drivers/fpga/stratix10-soc.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,16 @@ static int __init s10_init(void)
507507
if (!fw_np)
508508
return -ENODEV;
509509

510+
of_node_get(fw_np);
510511
np = of_find_matching_node(fw_np, s10_of_match);
511-
if (!np)
512+
if (!np) {
513+
of_node_put(fw_np);
512514
return -ENODEV;
515+
}
513516

514517
of_node_put(np);
515518
ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL);
519+
of_node_put(fw_np);
516520
if (ret)
517521
return ret;
518522

‎drivers/fpga/zynqmp-fpga.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int zynqmp_fpga_ops_write(struct fpga_manager *mgr,
4747
char *kbuf;
4848
int ret;
4949

50-
if (!eemi_ops || !eemi_ops->fpga_load)
50+
if (IS_ERR_OR_NULL(eemi_ops) || !eemi_ops->fpga_load)
5151
return -ENXIO;
5252

5353
priv = mgr->priv;
@@ -81,7 +81,7 @@ static enum fpga_mgr_states zynqmp_fpga_ops_state(struct fpga_manager *mgr)
8181
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
8282
u32 status;
8383

84-
if (!eemi_ops || !eemi_ops->fpga_get_status)
84+
if (IS_ERR_OR_NULL(eemi_ops) || !eemi_ops->fpga_get_status)
8585
return FPGA_MGR_STATE_UNKNOWN;
8686

8787
eemi_ops->fpga_get_status(&status);

‎drivers/misc/genwqe/card_dev.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,8 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m)
780780

781781
if ((m->addr == 0x0) || (m->size == 0))
782782
return -EINVAL;
783+
if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK))
784+
return -EINVAL;
783785

784786
map_addr = (m->addr & PAGE_MASK);
785787
map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);

‎drivers/misc/genwqe/card_utils.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,
586586
/* determine space needed for page_list. */
587587
data = (unsigned long)uaddr;
588588
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+
}
589593
m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE);
590594

591595
m->page_list = kcalloc(m->nr_pages,

‎drivers/misc/habanalabs/context.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ static void hl_ctx_fini(struct hl_ctx *ctx)
2626
dma_fence_put(ctx->cs_pending[i]);
2727

2828
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);
2935
hl_vm_ctx_fini(ctx);
3036
hl_asid_free(hdev, ctx->asid);
3137
}

‎drivers/misc/habanalabs/debugfs.c‎

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -459,41 +459,31 @@ static ssize_t mmu_write(struct file *file, const char __user *buf,
459459
struct hl_debugfs_entry *entry = s->private;
460460
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
461461
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];
464463
char *c;
465464
ssize_t rc;
466465

467466
if (!hdev->mmu_enable)
468467
return count;
469468

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;
474471
if (copy_from_user(kbuf, buf, count))
475472
goto err;
476-
477-
kbuf[MMU_KBUF_SIZE - 1] = 0;
473+
kbuf[count] = 0;
478474

479475
c = strchr(kbuf, ' ');
480476
if (!c)
481477
goto err;
478+
*c = '\0';
482479

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);
486481
if (rc)
487482
goto err;
488483

489-
c = strstr(kbuf, " 0x");
490-
if (!c)
484+
if (strncmp(c+1, "0x", 2))
491485
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);
497487
if (rc)
498488
goto err;
499489

@@ -510,6 +500,7 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
510500
{
511501
struct hl_ctx *ctx = hdev->user_ctx;
512502
u64 hop_addr, hop_pte_addr, hop_pte;
503+
u64 offset_mask = HOP4_MASK | OFFSET_MASK;
513504
int rc = 0;
514505

515506
if (!ctx) {
@@ -552,12 +543,14 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
552543
goto not_mapped;
553544
hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr);
554545
hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr);
546+
547+
offset_mask = OFFSET_MASK;
555548
}
556549

557550
if (!(hop_pte & PAGE_PRESENT_MASK))
558551
goto not_mapped;
559552

560-
*phys_addr = (hop_pte & PTE_PHYS_ADDR_MASK) | (virt_addr & OFFSET_MASK);
553+
*phys_addr = (hop_pte & ~offset_mask) | (virt_addr & offset_mask);
561554

562555
goto out;
563556

@@ -600,10 +593,8 @@ static ssize_t hl_data_read32(struct file *f, char __user *buf,
600593
}
601594

602595
sprintf(tmp_buf, "0x%08x\n", val);
603-
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
604-
strlen(tmp_buf) + 1);
605-
606-
return rc;
596+
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
597+
strlen(tmp_buf));
607598
}
608599

609600
static 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,
645636
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
646637
struct hl_device *hdev = entry->hdev;
647638
char tmp_buf[200];
648-
ssize_t rc;
649639
int i;
650640

651641
if (*ppos)
@@ -660,10 +650,8 @@ static ssize_t hl_get_power_state(struct file *f, char __user *buf,
660650

661651
sprintf(tmp_buf,
662652
"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,
664-
strlen(tmp_buf) + 1);
665-
666-
return rc;
653+
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
654+
strlen(tmp_buf));
667655
}
668656

669657
static 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,
716704
}
717705

718706
sprintf(tmp_buf, "0x%02x\n", val);
719-
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
720-
strlen(tmp_buf) + 1);
707+
rc = simple_read_from_buffer(buf, count, ppos, tmp_buf,
708+
strlen(tmp_buf));
721709

722710
return rc;
723711
}
@@ -806,26 +794,17 @@ static ssize_t hl_led2_write(struct file *f, const char __user *buf,
806794
static ssize_t hl_device_read(struct file *f, char __user *buf,
807795
size_t count, loff_t *ppos)
808796
{
809-
char tmp_buf[200];
810-
ssize_t rc;
811-
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;
797+
static const char *help =
798+
"Valid values: disable, enable, suspend, resume, cpu_timeout\n";
799+
return simple_read_from_buffer(buf, count, ppos, help, strlen(help));
821800
}
822801

823802
static ssize_t hl_device_write(struct file *f, const char __user *buf,
824803
size_t count, loff_t *ppos)
825804
{
826805
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
827806
struct hl_device *hdev = entry->hdev;
828-
char data[30];
807+
char data[30] = {0};
829808

830809
/* don't allow partial writes */
831810
if (*ppos != 0)

‎drivers/misc/habanalabs/device.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static int device_early_init(struct hl_device *hdev)
231231

232232
mutex_init(&hdev->fd_open_cnt_lock);
233233
mutex_init(&hdev->send_cpu_message_lock);
234+
mutex_init(&hdev->mmu_cache_lock);
234235
INIT_LIST_HEAD(&hdev->hw_queues_mirror_list);
235236
spin_lock_init(&hdev->hw_queues_mirror_lock);
236237
atomic_set(&hdev->in_reset, 0);
@@ -260,6 +261,7 @@ static int device_early_init(struct hl_device *hdev)
260261
*/
261262
static void device_early_fini(struct hl_device *hdev)
262263
{
264+
mutex_destroy(&hdev->mmu_cache_lock);
263265
mutex_destroy(&hdev->send_cpu_message_lock);
264266

265267
hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr);

‎drivers/misc/habanalabs/goya/goya.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4819,7 +4819,8 @@ static const struct hl_asic_funcs goya_funcs = {
48194819
.set_dram_bar_base = goya_set_ddr_bar_base,
48204820
.init_iatu = goya_init_iatu,
48214821
.rreg = hl_rreg,
4822-
.wreg = hl_wreg
4822+
.wreg = hl_wreg,
4823+
.halt_coresight = goya_halt_coresight
48234824
};
48244825

48254826
/*

0 commit comments

Comments
 (0)