Skip to content

Commit

Permalink
Merge tag 'char-misc-5.2-rc4' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/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
  • Loading branch information
torvalds committed Jun 8, 2019
2 parents 902b2ed + e7bf2ce commit 1ce2c85
Show file tree
Hide file tree
Showing 27 changed files with 192 additions and 131 deletions.
2 changes: 1 addition & 1 deletion drivers/fpga/dfl-afu-dma-region.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata,
region->pages[0], 0,
region->length,
DMA_BIDIRECTIONAL);
if (dma_mapping_error(&pdata->dev->dev, region->iova)) {
if (dma_mapping_error(dfl_fpga_pdata_to_parent(pdata), region->iova)) {
dev_err(&pdata->dev->dev, "failed to map for dma\n");
ret = -EFAULT;
goto unpin_pages;
Expand Down
22 changes: 18 additions & 4 deletions drivers/fpga/dfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ enum dfl_fpga_devt_type {
DFL_FPGA_DEVT_MAX,
};

static struct lock_class_key dfl_pdata_keys[DFL_ID_MAX];

static const char *dfl_pdata_key_strings[DFL_ID_MAX] = {
"dfl-fme-pdata",
"dfl-port-pdata",
};

/**
* dfl_dev_info - dfl feature device information.
* @name: name string of the feature platform device.
Expand Down Expand Up @@ -315,7 +322,7 @@ static void dfl_chardev_uinit(void)
for (i = 0; i < DFL_FPGA_DEVT_MAX; i++)
if (MAJOR(dfl_chrdevs[i].devt)) {
unregister_chrdev_region(dfl_chrdevs[i].devt,
MINORMASK);
MINORMASK + 1);
dfl_chrdevs[i].devt = MKDEV(0, 0);
}
}
Expand All @@ -325,8 +332,8 @@ static int dfl_chardev_init(void)
int i, ret;

for (i = 0; i < DFL_FPGA_DEVT_MAX; i++) {
ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0, MINORMASK,
dfl_chrdevs[i].name);
ret = alloc_chrdev_region(&dfl_chrdevs[i].devt, 0,
MINORMASK + 1, dfl_chrdevs[i].name);
if (ret)
goto exit;
}
Expand Down Expand Up @@ -443,11 +450,16 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
struct platform_device *fdev = binfo->feature_dev;
struct dfl_feature_platform_data *pdata;
struct dfl_feature_info *finfo, *p;
enum dfl_id_type type;
int ret, index = 0;

if (!fdev)
return 0;

type = feature_dev_id_type(fdev);
if (WARN_ON_ONCE(type >= DFL_ID_MAX))
return -EINVAL;

/*
* we do not need to care for the memory which is associated with
* the platform device. After calling platform_device_unregister(),
Expand All @@ -463,6 +475,8 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
pdata->num = binfo->feature_num;
pdata->dfl_cdev = binfo->cdev;
mutex_init(&pdata->lock);
lockdep_set_class_and_name(&pdata->lock, &dfl_pdata_keys[type],
dfl_pdata_key_strings[type]);

/*
* the count should be initialized to 0 to make sure
Expand Down Expand Up @@ -497,7 +511,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)

ret = platform_device_add(binfo->feature_dev);
if (!ret) {
if (feature_dev_id_type(binfo->feature_dev) == PORT_ID)
if (type == PORT_ID)
dfl_fpga_cdev_add_port_dev(binfo->cdev,
binfo->feature_dev);
else
Expand Down
6 changes: 5 additions & 1 deletion drivers/fpga/stratix10-soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,16 @@ static int __init s10_init(void)
if (!fw_np)
return -ENODEV;

of_node_get(fw_np);
np = of_find_matching_node(fw_np, s10_of_match);
if (!np)
if (!np) {
of_node_put(fw_np);
return -ENODEV;
}

of_node_put(np);
ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL);
of_node_put(fw_np);
if (ret)
return ret;

Expand Down
4 changes: 2 additions & 2 deletions drivers/fpga/zynqmp-fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int zynqmp_fpga_ops_write(struct fpga_manager *mgr,
char *kbuf;
int ret;

if (!eemi_ops || !eemi_ops->fpga_load)
if (IS_ERR_OR_NULL(eemi_ops) || !eemi_ops->fpga_load)
return -ENXIO;

priv = mgr->priv;
Expand Down Expand Up @@ -81,7 +81,7 @@ static enum fpga_mgr_states zynqmp_fpga_ops_state(struct fpga_manager *mgr)
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
u32 status;

if (!eemi_ops || !eemi_ops->fpga_get_status)
if (IS_ERR_OR_NULL(eemi_ops) || !eemi_ops->fpga_get_status)
return FPGA_MGR_STATE_UNKNOWN;

eemi_ops->fpga_get_status(&status);
Expand Down
2 changes: 2 additions & 0 deletions drivers/misc/genwqe/card_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m)

if ((m->addr == 0x0) || (m->size == 0))
return -EINVAL;
if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK))
return -EINVAL;

map_addr = (m->addr & PAGE_MASK);
map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
Expand Down
4 changes: 4 additions & 0 deletions drivers/misc/genwqe/card_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,
/* determine space needed for page_list. */
data = (unsigned long)uaddr;
offs = offset_in_page(data);
if (size > ULONG_MAX - PAGE_SIZE - offs) {
m->size = 0; /* mark unused and not added */
return -EINVAL;
}
m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE);

m->page_list = kcalloc(m->nr_pages,
Expand Down
6 changes: 6 additions & 0 deletions drivers/misc/habanalabs/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ static void hl_ctx_fini(struct hl_ctx *ctx)
dma_fence_put(ctx->cs_pending[i]);

if (ctx->asid != HL_KERNEL_ASID_ID) {
/*
* The engines are stopped as there is no executing CS, but the
* Coresight might be still working by accessing addresses
* related to the stopped engines. Hence stop it explicitly.
*/
hdev->asic_funcs->halt_coresight(hdev);
hl_vm_ctx_fini(ctx);
hl_asid_free(hdev, ctx->asid);
}
Expand Down
65 changes: 22 additions & 43 deletions drivers/misc/habanalabs/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,41 +459,31 @@ static ssize_t mmu_write(struct file *file, const char __user *buf,
struct hl_debugfs_entry *entry = s->private;
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
struct hl_device *hdev = dev_entry->hdev;
char kbuf[MMU_KBUF_SIZE], asid_kbuf[MMU_ASID_BUF_SIZE],
addr_kbuf[MMU_ADDR_BUF_SIZE];
char kbuf[MMU_KBUF_SIZE];
char *c;
ssize_t rc;

if (!hdev->mmu_enable)
return count;

memset(kbuf, 0, sizeof(kbuf));
memset(asid_kbuf, 0, sizeof(asid_kbuf));
memset(addr_kbuf, 0, sizeof(addr_kbuf));

if (count > sizeof(kbuf) - 1)
goto err;
if (copy_from_user(kbuf, buf, count))
goto err;

kbuf[MMU_KBUF_SIZE - 1] = 0;
kbuf[count] = 0;

c = strchr(kbuf, ' ');
if (!c)
goto err;
*c = '\0';

memcpy(asid_kbuf, kbuf, c - kbuf);

rc = kstrtouint(asid_kbuf, 10, &dev_entry->mmu_asid);
rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid);
if (rc)
goto err;

c = strstr(kbuf, " 0x");
if (!c)
if (strncmp(c+1, "0x", 2))
goto err;

c += 3;
memcpy(addr_kbuf, c, (kbuf + count) - c);

rc = kstrtoull(addr_kbuf, 16, &dev_entry->mmu_addr);
rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr);
if (rc)
goto err;

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

if (!ctx) {
Expand Down Expand Up @@ -552,12 +543,14 @@ static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr,
goto not_mapped;
hop_pte_addr = get_hop4_pte_addr(ctx, hop_addr, virt_addr);
hop_pte = hdev->asic_funcs->read_pte(hdev, hop_pte_addr);

offset_mask = OFFSET_MASK;
}

if (!(hop_pte & PAGE_PRESENT_MASK))
goto not_mapped;

*phys_addr = (hop_pte & PTE_PHYS_ADDR_MASK) | (virt_addr & OFFSET_MASK);
*phys_addr = (hop_pte & ~offset_mask) | (virt_addr & offset_mask);

goto out;

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

sprintf(tmp_buf, "0x%08x\n", val);
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
strlen(tmp_buf) + 1);

return rc;
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
strlen(tmp_buf));
}

static ssize_t hl_data_write32(struct file *f, const char __user *buf,
Expand Down Expand Up @@ -645,7 +636,6 @@ static ssize_t hl_get_power_state(struct file *f, char __user *buf,
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
struct hl_device *hdev = entry->hdev;
char tmp_buf[200];
ssize_t rc;
int i;

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

sprintf(tmp_buf,
"current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i);
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
strlen(tmp_buf) + 1);

return rc;
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
strlen(tmp_buf));
}

static ssize_t hl_set_power_state(struct file *f, const char __user *buf,
Expand Down Expand Up @@ -716,8 +704,8 @@ static ssize_t hl_i2c_data_read(struct file *f, char __user *buf,
}

sprintf(tmp_buf, "0x%02x\n", val);
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
strlen(tmp_buf) + 1);
rc = simple_read_from_buffer(buf, count, ppos, tmp_buf,
strlen(tmp_buf));

return rc;
}
Expand Down Expand Up @@ -806,26 +794,17 @@ static ssize_t hl_led2_write(struct file *f, const char __user *buf,
static ssize_t hl_device_read(struct file *f, char __user *buf,
size_t count, loff_t *ppos)
{
char tmp_buf[200];
ssize_t rc;

if (*ppos)
return 0;

sprintf(tmp_buf,
"Valid values: disable, enable, suspend, resume, cpu_timeout\n");
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
strlen(tmp_buf) + 1);

return rc;
static const char *help =
"Valid values: disable, enable, suspend, resume, cpu_timeout\n";
return simple_read_from_buffer(buf, count, ppos, help, strlen(help));
}

static ssize_t hl_device_write(struct file *f, const char __user *buf,
size_t count, loff_t *ppos)
{
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
struct hl_device *hdev = entry->hdev;
char data[30];
char data[30] = {0};

/* don't allow partial writes */
if (*ppos != 0)
Expand Down
2 changes: 2 additions & 0 deletions drivers/misc/habanalabs/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ static int device_early_init(struct hl_device *hdev)

mutex_init(&hdev->fd_open_cnt_lock);
mutex_init(&hdev->send_cpu_message_lock);
mutex_init(&hdev->mmu_cache_lock);
INIT_LIST_HEAD(&hdev->hw_queues_mirror_list);
spin_lock_init(&hdev->hw_queues_mirror_lock);
atomic_set(&hdev->in_reset, 0);
Expand Down Expand Up @@ -260,6 +261,7 @@ static int device_early_init(struct hl_device *hdev)
*/
static void device_early_fini(struct hl_device *hdev)
{
mutex_destroy(&hdev->mmu_cache_lock);
mutex_destroy(&hdev->send_cpu_message_lock);

hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr);
Expand Down
3 changes: 2 additions & 1 deletion drivers/misc/habanalabs/goya/goya.c
Original file line number Diff line number Diff line change
Expand Up @@ -4819,7 +4819,8 @@ static const struct hl_asic_funcs goya_funcs = {
.set_dram_bar_base = goya_set_ddr_bar_base,
.init_iatu = goya_init_iatu,
.rreg = hl_rreg,
.wreg = hl_wreg
.wreg = hl_wreg,
.halt_coresight = goya_halt_coresight
};

/*
Expand Down
1 change: 1 addition & 0 deletions drivers/misc/habanalabs/goya/goyaP.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void goya_add_device_attr(struct hl_device *hdev,
struct attribute_group *dev_attr_grp);
int goya_armcp_info_get(struct hl_device *hdev);
int goya_debug_coresight(struct hl_device *hdev, void *data);
void goya_halt_coresight(struct hl_device *hdev);

void goya_mmu_prepare(struct hl_device *hdev, u32 asid);
int goya_mmu_clear_pgt_range(struct hl_device *hdev);
Expand Down
31 changes: 29 additions & 2 deletions drivers/misc/habanalabs/goya/goya_coresight.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,18 @@ static int goya_config_etr(struct hl_device *hdev,
WREG32(base_reg + 0x28, 0);
WREG32(base_reg + 0x304, 0);

if (params->output_size >= sizeof(u32))
*(u32 *) params->output = RREG32(base_reg + 0x18);
if (params->output_size >= sizeof(u64)) {
u32 rwp, rwphi;

/*
* The trace buffer address is 40 bits wide. The end of
* the buffer is set in the RWP register (lower 32
* bits), and in the RWPHI register (upper 8 bits).
*/
rwp = RREG32(base_reg + 0x18);
rwphi = RREG32(base_reg + 0x3c) & 0xff;
*(u64 *) params->output = ((u64) rwphi << 32) | rwp;
}
}

return 0;
Expand Down Expand Up @@ -626,3 +636,20 @@ int goya_debug_coresight(struct hl_device *hdev, void *data)

return rc;
}

void goya_halt_coresight(struct hl_device *hdev)
{
struct hl_debug_params params = {};
int i, rc;

for (i = GOYA_ETF_FIRST ; i <= GOYA_ETF_LAST ; i++) {
params.reg_idx = i;
rc = goya_config_etf(hdev, &params);
if (rc)
dev_err(hdev->dev, "halt ETF failed, %d/%d\n", rc, i);
}

rc = goya_config_etr(hdev, &params);
if (rc)
dev_err(hdev->dev, "halt ETR failed, %d\n", rc);
}
2 changes: 2 additions & 0 deletions drivers/misc/habanalabs/habanalabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ enum hl_pll_frequency {
* @init_iatu: Initialize the iATU unit inside the PCI controller.
* @rreg: Read a register. Needed for simulator support.
* @wreg: Write a register. Needed for simulator support.
* @halt_coresight: stop the ETF and ETR traces.
*/
struct hl_asic_funcs {
int (*early_init)(struct hl_device *hdev);
Expand Down Expand Up @@ -578,6 +579,7 @@ struct hl_asic_funcs {
int (*init_iatu)(struct hl_device *hdev);
u32 (*rreg)(struct hl_device *hdev, u32 reg);
void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
void (*halt_coresight)(struct hl_device *hdev);
};


Expand Down
Loading

0 comments on commit 1ce2c85

Please sign in to comment.