forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/misc/vmw_vmci/vmci_host.c
....@@ -1,21 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * VMware VMCI Driver
34 *
45 * Copyright (C) 2012 VMware, Inc. All rights reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License as published by the
8
- * Free Software Foundation version 2 and no later version.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
- * for more details.
146 */
157
168 #include <linux/vmw_vmci_defs.h>
179 #include <linux/vmw_vmci_api.h>
18
-#include <linux/moduleparam.h>
1910 #include <linux/miscdevice.h>
2011 #include <linux/interrupt.h>
2112 #include <linux/highmem.h>
....@@ -115,6 +106,11 @@
115106 return vmci_host_device_initialized &&
116107 (!vmci_guest_code_active() ||
117108 atomic_read(&vmci_host_active_users) > 0);
109
+}
110
+
111
+int vmci_host_users(void)
112
+{
113
+ return atomic_read(&vmci_host_active_users);
118114 }
119115
120116 /*
....@@ -237,13 +233,11 @@
237233 * about the size.
238234 */
239235 BUILD_BUG_ON(sizeof(bool) != sizeof(u8));
240
- if (!access_ok(VERIFY_WRITE, (void __user *)uva, sizeof(u8)))
241
- return VMCI_ERROR_GENERIC;
242236
243237 /*
244238 * Lock physical page backing a given user VA.
245239 */
246
- retval = get_user_pages_fast(uva, 1, 1, &context->notify_page);
240
+ retval = get_user_pages_fast(uva, 1, FOLL_WRITE, &context->notify_page);
247241 if (retval != 1) {
248242 context->notify_page = NULL;
249243 return VMCI_ERROR_GENERIC;
....@@ -347,6 +341,8 @@
347341 vmci_host_dev->ct_type = VMCIOBJ_CONTEXT;
348342 atomic_inc(&vmci_host_active_users);
349343
344
+ vmci_call_vsock_callback(true);
345
+
350346 retval = 0;
351347
352348 out:
....@@ -448,14 +444,11 @@
448444 struct vmci_handle handle;
449445 int vmci_status;
450446 int __user *retptr;
451
- u32 cid;
452447
453448 if (vmci_host_dev->ct_type != VMCIOBJ_CONTEXT) {
454449 vmci_ioctl_err("only valid for contexts\n");
455450 return -EINVAL;
456451 }
457
-
458
- cid = vmci_ctx_get_id(vmci_host_dev->context);
459452
460453 if (vmci_host_dev->user_version < VMCI_VERSION_NOVMVM) {
461454 struct vmci_qp_alloc_info_vmvm alloc_info;
....@@ -754,19 +747,10 @@
754747 if (copy_from_user(&set_info, uptr, sizeof(set_info)))
755748 return -EFAULT;
756749
757
- cpt_buf = kmalloc(set_info.buf_size, GFP_KERNEL);
758
- if (!cpt_buf) {
759
- vmci_ioctl_err(
760
- "cannot allocate memory to set cpt state (type=%d)\n",
761
- set_info.cpt_type);
762
- return -ENOMEM;
763
- }
764
-
765
- if (copy_from_user(cpt_buf, (void __user *)(uintptr_t)set_info.cpt_buf,
766
- set_info.buf_size)) {
767
- retval = -EFAULT;
768
- goto out;
769
- }
750
+ cpt_buf = memdup_user((void __user *)(uintptr_t)set_info.cpt_buf,
751
+ set_info.buf_size);
752
+ if (IS_ERR(cpt_buf))
753
+ return PTR_ERR(cpt_buf);
770754
771755 cid = vmci_ctx_get_id(vmci_host_dev->context);
772756 set_info.result = vmci_ctx_set_chkpt_state(cid, set_info.cpt_type,
....@@ -774,7 +758,6 @@
774758
775759 retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0;
776760
777
-out:
778761 kfree(cpt_buf);
779762 return retval;
780763 }
....@@ -983,7 +966,7 @@
983966 .release = vmci_host_close,
984967 .poll = vmci_host_poll,
985968 .unlocked_ioctl = vmci_host_unlocked_ioctl,
986
- .compat_ioctl = vmci_host_unlocked_ioctl,
969
+ .compat_ioctl = compat_ptr_ioctl,
987970 };
988971
989972 static struct miscdevice vmci_host_miscdev = {