Skip to content

Commit 88fe492

Browse files
committed
Merge tag 'char-misc-5.12-rc3' 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 misc/char driver fixes to resolve some reported problems: - habanalabs driver fixes - Acrn build fixes (reported many times) - pvpanic module table export fix All of these have been in linux-next for a while with no reported issues" * tag 'char-misc-5.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: misc/pvpanic: Export module FDT device table misc: fastrpc: restrict user apps from sending kernel RPC messages virt: acrn: Correct type casting of argument of copy_from_user() virt: acrn: Use EPOLLIN instead of POLLIN virt: acrn: Use vfs_poll() instead of f_op->poll() virt: acrn: Make remove_cpu sysfs invisible with !CONFIG_HOTPLUG_CPU cpu/hotplug: Fix build error of using {add,remove}_cpu() with !CONFIG_SMP habanalabs: fix debugfs address translation habanalabs: Disable file operations after device is removed habanalabs: Call put_pid() when releasing control device drivers: habanalabs: remove unused dentry pointer for debugfs files habanalabs: mark hl_eq_inc_ptr() as static
2 parents be61af3 + 65527a5 commit 88fe492

File tree

11 files changed

+97
-28
lines changed

11 files changed

+97
-28
lines changed

drivers/misc/fastrpc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,11 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
950950
if (!fl->cctx->rpdev)
951951
return -EPIPE;
952952

953+
if (handle == FASTRPC_INIT_HANDLE && !kernel) {
954+
dev_warn_ratelimited(fl->sctx->dev, "user app trying to send a kernel RPC message (%d)\n", handle);
955+
return -EPERM;
956+
}
957+
953958
ctx = fastrpc_context_alloc(fl, kernel, sc, args);
954959
if (IS_ERR(ctx))
955960
return PTR_ERR(ctx);

drivers/misc/habanalabs/common/debugfs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ void hl_debugfs_add_device(struct hl_device *hdev)
992992
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
993993
int count = ARRAY_SIZE(hl_debugfs_list);
994994
struct hl_debugfs_entry *entry;
995-
struct dentry *ent;
996995
int i;
997996

998997
dev_entry->hdev = hdev;
@@ -1105,13 +1104,11 @@ void hl_debugfs_add_device(struct hl_device *hdev)
11051104
&hl_security_violations_fops);
11061105

11071106
for (i = 0, entry = dev_entry->entry_arr ; i < count ; i++, entry++) {
1108-
1109-
ent = debugfs_create_file(hl_debugfs_list[i].name,
1107+
debugfs_create_file(hl_debugfs_list[i].name,
11101108
0444,
11111109
dev_entry->root,
11121110
entry,
11131111
&hl_debugfs_fops);
1114-
entry->dent = ent;
11151112
entry->info_ent = &hl_debugfs_list[i];
11161113
entry->dev_entry = dev_entry;
11171114
}

drivers/misc/habanalabs/common/device.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,19 @@ void hl_hpriv_put(struct hl_fpriv *hpriv)
9393
static int hl_device_release(struct inode *inode, struct file *filp)
9494
{
9595
struct hl_fpriv *hpriv = filp->private_data;
96+
struct hl_device *hdev = hpriv->hdev;
97+
98+
filp->private_data = NULL;
99+
100+
if (!hdev) {
101+
pr_crit("Closing FD after device was removed. Memory leak will occur and it is advised to reboot.\n");
102+
put_pid(hpriv->taskpid);
103+
return 0;
104+
}
96105

97106
hl_cb_mgr_fini(hpriv->hdev, &hpriv->cb_mgr);
98107
hl_ctx_mgr_fini(hpriv->hdev, &hpriv->ctx_mgr);
99108

100-
filp->private_data = NULL;
101-
102109
hl_hpriv_put(hpriv);
103110

104111
return 0;
@@ -107,15 +114,20 @@ static int hl_device_release(struct inode *inode, struct file *filp)
107114
static int hl_device_release_ctrl(struct inode *inode, struct file *filp)
108115
{
109116
struct hl_fpriv *hpriv = filp->private_data;
110-
struct hl_device *hdev;
117+
struct hl_device *hdev = hpriv->hdev;
111118

112119
filp->private_data = NULL;
113120

114-
hdev = hpriv->hdev;
121+
if (!hdev) {
122+
pr_err("Closing FD after device was removed\n");
123+
goto out;
124+
}
115125

116126
mutex_lock(&hdev->fpriv_list_lock);
117127
list_del(&hpriv->dev_node);
118128
mutex_unlock(&hdev->fpriv_list_lock);
129+
out:
130+
put_pid(hpriv->taskpid);
119131

120132
kfree(hpriv);
121133

@@ -134,8 +146,14 @@ static int hl_device_release_ctrl(struct inode *inode, struct file *filp)
134146
static int hl_mmap(struct file *filp, struct vm_area_struct *vma)
135147
{
136148
struct hl_fpriv *hpriv = filp->private_data;
149+
struct hl_device *hdev = hpriv->hdev;
137150
unsigned long vm_pgoff;
138151

152+
if (!hdev) {
153+
pr_err_ratelimited("Trying to mmap after device was removed! Please close FD\n");
154+
return -ENODEV;
155+
}
156+
139157
vm_pgoff = vma->vm_pgoff;
140158
vma->vm_pgoff = HL_MMAP_OFFSET_VALUE_GET(vm_pgoff);
141159

@@ -883,6 +901,16 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout)
883901
return -EBUSY;
884902
}
885903

904+
static void device_disable_open_processes(struct hl_device *hdev)
905+
{
906+
struct hl_fpriv *hpriv;
907+
908+
mutex_lock(&hdev->fpriv_list_lock);
909+
list_for_each_entry(hpriv, &hdev->fpriv_list, dev_node)
910+
hpriv->hdev = NULL;
911+
mutex_unlock(&hdev->fpriv_list_lock);
912+
}
913+
886914
/*
887915
* hl_device_reset - reset the device
888916
*
@@ -1556,8 +1584,10 @@ void hl_device_fini(struct hl_device *hdev)
15561584
HL_PENDING_RESET_LONG_SEC);
15571585

15581586
rc = device_kill_open_processes(hdev, HL_PENDING_RESET_LONG_SEC);
1559-
if (rc)
1587+
if (rc) {
15601588
dev_crit(hdev->dev, "Failed to kill all open processes\n");
1589+
device_disable_open_processes(hdev);
1590+
}
15611591

15621592
hl_cb_pool_fini(hdev);
15631593

drivers/misc/habanalabs/common/habanalabs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,12 +1465,10 @@ struct hl_info_list {
14651465

14661466
/**
14671467
* struct hl_debugfs_entry - debugfs dentry wrapper.
1468-
* @dent: base debugfs entry structure.
14691468
* @info_ent: dentry realted ops.
14701469
* @dev_entry: ASIC specific debugfs manager.
14711470
*/
14721471
struct hl_debugfs_entry {
1473-
struct dentry *dent;
14741472
const struct hl_info_list *info_ent;
14751473
struct hl_dbg_device_entry *dev_entry;
14761474
};

drivers/misc/habanalabs/common/habanalabs_ioctl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* All Rights Reserved.
66
*/
77

8+
#define pr_fmt(fmt) "habanalabs: " fmt
9+
810
#include <uapi/misc/habanalabs.h>
911
#include "habanalabs.h"
1012

@@ -682,6 +684,11 @@ long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
682684
const struct hl_ioctl_desc *ioctl = NULL;
683685
unsigned int nr = _IOC_NR(cmd);
684686

687+
if (!hdev) {
688+
pr_err_ratelimited("Sending ioctl after device was removed! Please close FD\n");
689+
return -ENODEV;
690+
}
691+
685692
if ((nr >= HL_COMMAND_START) && (nr < HL_COMMAND_END)) {
686693
ioctl = &hl_ioctls[nr];
687694
} else {
@@ -700,6 +707,11 @@ long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg)
700707
const struct hl_ioctl_desc *ioctl = NULL;
701708
unsigned int nr = _IOC_NR(cmd);
702709

710+
if (!hdev) {
711+
pr_err_ratelimited("Sending ioctl after device was removed! Please close FD\n");
712+
return -ENODEV;
713+
}
714+
703715
if (nr == _IOC_NR(HL_IOCTL_INFO)) {
704716
ioctl = &hl_ioctls_control[nr];
705717
} else {

drivers/misc/habanalabs/common/irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ inline u32 hl_cq_inc_ptr(u32 ptr)
4747
* Increment ptr by 1. If it reaches the number of event queue
4848
* entries, set it to 0
4949
*/
50-
inline u32 hl_eq_inc_ptr(u32 ptr)
50+
static inline u32 hl_eq_inc_ptr(u32 ptr)
5151
{
5252
ptr++;
5353
if (unlikely(ptr == HL_EQ_LENGTH))

drivers/misc/habanalabs/common/mmu/mmu.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,32 @@ static void hl_mmu_pa_page_with_offset(struct hl_ctx *ctx, u64 virt_addr,
499499
else /* HL_VA_RANGE_TYPE_DRAM */
500500
p = &prop->dmmu;
501501

502-
/*
503-
* find the correct hop shift field in hl_mmu_properties structure
504-
* in order to determine the right maks for the page offset.
505-
*/
506-
hop0_shift_off = offsetof(struct hl_mmu_properties, hop0_shift);
507-
p = (char *)p + hop0_shift_off;
508-
p = (char *)p + ((hops->used_hops - 1) * sizeof(u64));
509-
hop_shift = *(u64 *)p;
510-
offset_mask = (1ull << hop_shift) - 1;
511-
addr_mask = ~(offset_mask);
512-
*phys_addr = (tmp_phys_addr & addr_mask) |
513-
(virt_addr & offset_mask);
502+
if ((hops->range_type == HL_VA_RANGE_TYPE_DRAM) &&
503+
!is_power_of_2(prop->dram_page_size)) {
504+
u32 bit;
505+
u64 page_offset_mask;
506+
u64 phys_addr_mask;
507+
508+
bit = __ffs64((u64)prop->dram_page_size);
509+
page_offset_mask = ((1ull << bit) - 1);
510+
phys_addr_mask = ~page_offset_mask;
511+
*phys_addr = (tmp_phys_addr & phys_addr_mask) |
512+
(virt_addr & page_offset_mask);
513+
} else {
514+
/*
515+
* find the correct hop shift field in hl_mmu_properties
516+
* structure in order to determine the right masks
517+
* for the page offset.
518+
*/
519+
hop0_shift_off = offsetof(struct hl_mmu_properties, hop0_shift);
520+
p = (char *)p + hop0_shift_off;
521+
p = (char *)p + ((hops->used_hops - 1) * sizeof(u64));
522+
hop_shift = *(u64 *)p;
523+
offset_mask = (1ull << hop_shift) - 1;
524+
addr_mask = ~(offset_mask);
525+
*phys_addr = (tmp_phys_addr & addr_mask) |
526+
(virt_addr & offset_mask);
527+
}
514528
}
515529

516530
int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr)

drivers/misc/pvpanic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static const struct of_device_id pvpanic_mmio_match[] = {
140140
{ .compatible = "qemu,pvpanic-mmio", },
141141
{}
142142
};
143+
MODULE_DEVICE_TABLE(of, pvpanic_mmio_match);
143144

144145
static const struct acpi_device_id pvpanic_device_ids[] = {
145146
{ "QEMU0001", 0 },

drivers/virt/acrn/hsm.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd,
333333
acrn_ioreq_request_clear(vm);
334334
break;
335335
case ACRN_IOCTL_PM_GET_CPU_STATE:
336-
if (copy_from_user(&cstate_cmd, (void *)ioctl_param,
336+
if (copy_from_user(&cstate_cmd, (void __user *)ioctl_param,
337337
sizeof(cstate_cmd)))
338338
return -EFAULT;
339339

@@ -404,13 +404,22 @@ static ssize_t remove_cpu_store(struct device *dev,
404404
}
405405
static DEVICE_ATTR_WO(remove_cpu);
406406

407+
static umode_t acrn_attr_visible(struct kobject *kobj, struct attribute *a, int n)
408+
{
409+
if (a == &dev_attr_remove_cpu.attr)
410+
return IS_ENABLED(CONFIG_HOTPLUG_CPU) ? a->mode : 0;
411+
412+
return a->mode;
413+
}
414+
407415
static struct attribute *acrn_attrs[] = {
408416
&dev_attr_remove_cpu.attr,
409417
NULL
410418
};
411419

412420
static struct attribute_group acrn_attr_group = {
413421
.attrs = acrn_attrs,
422+
.is_visible = acrn_attr_visible,
414423
};
415424

416425
static const struct attribute_group *acrn_attr_groups[] = {

drivers/virt/acrn/irqfd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
112112
{
113113
struct eventfd_ctx *eventfd = NULL;
114114
struct hsm_irqfd *irqfd, *tmp;
115-
unsigned int events;
115+
__poll_t events;
116116
struct fd f;
117117
int ret = 0;
118118

@@ -158,9 +158,9 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
158158
mutex_unlock(&vm->irqfds_lock);
159159

160160
/* Check the pending event in this stage */
161-
events = f.file->f_op->poll(f.file, &irqfd->pt);
161+
events = vfs_poll(f.file, &irqfd->pt);
162162

163-
if (events & POLLIN)
163+
if (events & EPOLLIN)
164164
acrn_irqfd_inject(irqfd);
165165

166166
fdput(f);

0 commit comments

Comments
 (0)