From 53929f13c4179c32206740f77abd646c35142fec Mon Sep 17 00:00:00 2001 From: jc_gargma Date: Mon, 31 Aug 2020 00:36:36 -0700 Subject: Updated to 5.8.5 --- ...ctl-and-CONFIG-to-disallow-unprivileged-C.patch | 84 ++- ...-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch | 38 -- ...dd-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch | 645 +++++++++++++++++++++ ...dd-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch | 645 --------------------- PKGBUILD | 38 +- config | 617 +++++++++++--------- 6 files changed, 1073 insertions(+), 994 deletions(-) delete mode 100644 0002-PCI-EDR-Log-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch create mode 100644 0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch delete mode 100644 0003-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch diff --git a/0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch b/0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch index 04852f6..5700e7d 100644 --- a/0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch +++ b/0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch @@ -1,21 +1,44 @@ -From 673deeaa0505b542ef9516a42ced24d724c2cc6f Mon Sep 17 00:00:00 2001 +From 78508a927d710e4077f50f188b69ba5000b68e78 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Mon, 16 Sep 2019 04:53:20 +0200 Subject: ZEN: Add sysctl and CONFIG to disallow unprivileged CLONE_NEWUSER Our default behavior continues to match the vanilla kernel. --- - init/Kconfig | 16 ++++++++++++++++ - kernel/fork.c | 15 +++++++++++++++ - kernel/sysctl.c | 12 ++++++++++++ - kernel/user_namespace.c | 7 +++++++ - 4 files changed, 50 insertions(+) + include/linux/user_namespace.h | 4 ++++ + init/Kconfig | 16 ++++++++++++++++ + kernel/fork.c | 14 ++++++++++++++ + kernel/sysctl.c | 12 ++++++++++++ + kernel/user_namespace.c | 7 +++++++ + 5 files changed, 53 insertions(+) +diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h +index 6ef1c7109fc4..2140091b0b8d 100644 +--- a/include/linux/user_namespace.h ++++ b/include/linux/user_namespace.h +@@ -106,6 +106,8 @@ void dec_ucount(struct ucounts *ucounts, enum ucount_type type); + + #ifdef CONFIG_USER_NS + ++extern int unprivileged_userns_clone; ++ + static inline struct user_namespace *get_user_ns(struct user_namespace *ns) + { + if (ns) +@@ -139,6 +141,8 @@ extern bool current_in_userns(const struct user_namespace *target_ns); + struct ns_common *ns_get_owner(struct ns_common *ns); + #else + ++#define unprivileged_userns_clone 0 ++ + static inline struct user_namespace *get_user_ns(struct user_namespace *ns) + { + return &init_user_ns; diff --git a/init/Kconfig b/init/Kconfig -index a34064a031a5..0342f34271b3 100644 +index 0498af567f70..078a0b73effd 100644 --- a/init/Kconfig +++ b/init/Kconfig -@@ -1102,6 +1102,22 @@ config USER_NS +@@ -1140,6 +1140,22 @@ config USER_NS If unsure, say N. @@ -39,22 +62,21 @@ index a34064a031a5..0342f34271b3 100644 bool "PID Namespaces" default y diff --git a/kernel/fork.c b/kernel/fork.c -index 080809560072..1cb7b827b57b 100644 +index efc5493203ae..90859b7531d3 100644 --- a/kernel/fork.c +++ b/kernel/fork.c -@@ -106,6 +106,11 @@ +@@ -96,6 +96,10 @@ + #include + #include - #define CREATE_TRACE_POINTS - #include +#ifdef CONFIG_USER_NS -+extern int unprivileged_userns_clone; -+#else -+#define unprivileged_userns_clone 0 ++#include +#endif - - /* - * Minimum number of threads to boot the kernel -@@ -1843,6 +1848,10 @@ static __latent_entropy struct task_struct *copy_process( ++ + #include + #include + #include +@@ -1861,6 +1865,10 @@ static __latent_entropy struct task_struct *copy_process( if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS)) return ERR_PTR(-EINVAL); @@ -65,7 +87,7 @@ index 080809560072..1cb7b827b57b 100644 /* * Thread groups must share signals as well, and detached threads * can only be started up within the thread group. -@@ -2923,6 +2932,12 @@ int ksys_unshare(unsigned long unshare_flags) +@@ -2961,6 +2969,12 @@ int ksys_unshare(unsigned long unshare_flags) if (unshare_flags & CLONE_NEWNS) unshare_flags |= CLONE_FS; @@ -79,20 +101,20 @@ index 080809560072..1cb7b827b57b 100644 if (err) goto bad_unshare_out; diff --git a/kernel/sysctl.c b/kernel/sysctl.c -index 70665934d53e..9797869ed829 100644 +index db1ce7af2563..9b73467e279d 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c -@@ -110,6 +110,9 @@ extern int core_uses_pid; - extern char core_pattern[]; - extern unsigned int core_pipe_limit; +@@ -103,6 +103,9 @@ + #ifdef CONFIG_LOCKUP_DETECTOR + #include #endif +#ifdef CONFIG_USER_NS -+extern int unprivileged_userns_clone; ++#include +#endif - extern int pid_max; - extern int pid_max_min, pid_max_max; - extern int percpu_pagelist_fraction; -@@ -546,6 +549,15 @@ static struct ctl_table kern_table[] = { + + #if defined(CONFIG_SYSCTL) + +@@ -1882,6 +1885,15 @@ static struct ctl_table kern_table[] = { .proc_handler = proc_dointvec, }, #endif @@ -109,7 +131,7 @@ index 70665934d53e..9797869ed829 100644 { .procname = "tainted", diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c -index 8eadadc478f9..c36ecd19562c 100644 +index 87804e0371fe..66b5afb0d0ee 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -21,6 +21,13 @@ @@ -127,5 +149,5 @@ index 8eadadc478f9..c36ecd19562c 100644 static DEFINE_MUTEX(userns_state_mutex); -- -cgit v1.2.1-1-g437b +cgit v1.2.3-1-gf6bb5 diff --git a/0002-PCI-EDR-Log-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch b/0002-PCI-EDR-Log-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch deleted file mode 100644 index 1631d9a..0000000 --- a/0002-PCI-EDR-Log-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 6535fe9061b6f1ce76ac658ae34b85fb3ed38ad9 Mon Sep 17 00:00:00 2001 -From: Kuppuswamy Sathyanarayanan -Date: Wed, 15 Apr 2020 17:38:32 -0700 -Subject: PCI/EDR: Log only ACPI_NOTIFY_DISCONNECT_RECOVER events - -Previously we logged *all* ACPI SYSTEM-level events, which may include lots -of non-EDR events. Move the message so we only log those related to EDR. - -Link: https://lore.kernel.org/r/01afb4e01efbe455de0c445bef6cf3ffc59340d2.1586996350.git.sathyanarayanan.kuppuswamy@linux.intel.com -[bhelgaas: drop the pci_dbg() of all events since ACPI can log those -already] -Signed-off-by: Kuppuswamy Sathyanarayanan -Signed-off-by: Bjorn Helgaas ---- - drivers/pci/pcie/edr.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/drivers/pci/pcie/edr.c b/drivers/pci/pcie/edr.c -index 594622a6cb16..a6b9b479b97a 100644 ---- a/drivers/pci/pcie/edr.c -+++ b/drivers/pci/pcie/edr.c -@@ -148,11 +148,11 @@ static void edr_handle_event(acpi_handle handle, u32 event, void *data) - pci_ers_result_t estate = PCI_ERS_RESULT_DISCONNECT; - u16 status; - -- pci_info(pdev, "ACPI event %#x received\n", event); -- - if (event != ACPI_NOTIFY_DISCONNECT_RECOVER) - return; - -+ pci_info(pdev, "EDR event received\n"); -+ - /* Locate the port which issued EDR event */ - edev = acpi_dpc_port_get(pdev); - if (!edev) { --- -cgit v1.2.3-1-gf6bb5 - diff --git a/0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch b/0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch new file mode 100644 index 0000000..cf6db1b --- /dev/null +++ b/0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch @@ -0,0 +1,645 @@ +From 4e456a10768c64b2d2129b67caf21a7b79a1945b Mon Sep 17 00:00:00 2001 +From: "Jan Alexander Steffens (heftig)" +Date: Wed, 15 Jul 2020 22:42:07 +0200 +Subject: virt: vbox: Add support for the new + VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES ioctl + +https://lore.kernel.org/patchwork/cover/1270301/ + +Needed for https://bugs.archlinux.org/task/67253 + +Squashed commit of the following: + +commit 0d7bec556896815f4920a5ed87339732c697175c +Author: Hans de Goede +Date: Thu Jul 9 14:08:58 2020 +0200 + + virt: vbox: Fix some comments which talk about the "session spinlock" + + The session lock is a mutex, not a spinlock, fix the comments to match. + + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit fed91350029e0c3bf626bd55a148e766587ec439 +Author: Hans de Goede +Date: Thu Jul 9 14:08:57 2020 +0200 + + virt: vbox: Log unknown ioctl requests as error + + Every now and then upstream adds new ioctls without notifying us, + log unknown ioctl requests as an error to catch these. + + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit 245d06f4c1b8f84cde07d14c09296a4fe90a26f0 +Author: Hans de Goede +Date: Thu Jul 9 14:08:56 2020 +0200 + + virt: vbox: Add a few new vmmdev request types to the userspace whitelist + + Upstream VirtualBox has defined and is using a few new request types for + vmmdev requests passed through /dev/vboxguest to the hypervisor. + + Add the defines for these to vbox_vmmdev_types.h and add add them to the + whitelists of vmmdev requests which userspace is allowed to make. + + BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1789545 + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit 2f24f5446915322bbbb1ccf4ee2297512feab942 +Author: Hans de Goede +Date: Thu Jul 9 14:08:55 2020 +0200 + + virt: vbox: Add support for the new VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES ioctl + + Add support for the new VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES ioctl, this + is necessary for automatic resizing of the guest resolution to match the + VM-window size to work with the new VMSVGA virtual GPU which is now the + new default in VirtualBox. + + BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1789545 + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit 2fc9822453e8dd215765cd2b28e5e6e26338829e +Author: Hans de Goede +Date: Thu Jul 9 14:08:54 2020 +0200 + + virt: vbox: Add vbg_set_host_capabilities() helper function + + Add vbg_set_host_capabilities() helper function, this is a preparation + patch for adding support for the VBGL_IOCTL_GUEST_CAPS_ACQUIRE ioctl. + + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit 1594daf929c8691849c00e49e4a1ed977048addc +Author: Hans de Goede +Date: Thu Jul 9 14:08:53 2020 +0200 + + virt: vbox: Rename guest_caps struct members to set_guest_caps + + Rename guest_caps[_tracker] struct members to set_guest_caps[_tracker] + this is a preparation patch for adding support for the + VBGL_IOCTL_GUEST_CAPS_ACQUIRE ioctl. + + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit d7f3b7cec66d171cf5194ad37f647f4562da6ccc +Author: Hans de Goede +Date: Thu Jul 9 14:08:52 2020 +0200 + + virt: vbox: Fix guest capabilities mask check + + Check the passed in capabilities against VMMDEV_GUEST_CAPABILITIES_MASK + instead of against VMMDEV_EVENT_VALID_EVENT_MASK. + This tightens the allowed mask from 0x7ff to 0x7. + + Fixes: 0ba002bc4393 ("virt: Add vboxguest driver for Virtual Box Guest integration") + Cc: stable@vger.kernel.org + Acked-by: Arnd Bergmann + Signed-off-by: Hans de Goede + +commit f6694fa90e2183874def2d022d097795e2269a15 +Author: Hans de Goede +Date: Thu Jul 9 14:08:51 2020 +0200 + + virt: vbox: Fix VBGL_IOCTL_VMMDEV_REQUEST_BIG and _LOG req numbers to match upstream + + Until this commit the mainline kernel version (this version) of the + vboxguest module contained a bug where it defined + VBGL_IOCTL_VMMDEV_REQUEST_BIG and VBGL_IOCTL_LOG using + _IOC(_IOC_READ | _IOC_WRITE, 'V', ...) instead of + _IO(V, ...) as the out of tree VirtualBox upstream version does. + + Since the VirtualBox userspace bits are always built against VirtualBox + upstream's headers, this means that so far the mainline kernel version + of the vboxguest module has been failing these 2 ioctls with -ENOTTY. + I guess that VBGL_IOCTL_VMMDEV_REQUEST_BIG is never used causing us to + not hit that one and sofar the vboxguest driver has failed to actually + log any log messages passed it through VBGL_IOCTL_LOG. + + This commit changes the VBGL_IOCTL_VMMDEV_REQUEST_BIG and VBGL_IOCTL_LOG + defines to match the out of tree VirtualBox upstream vboxguest version, + while keeping compatibility with the old wrong request defines so as + to not break the kernel ABI in case someone has been using the old + request defines. + + Fixes: f6ddd094f579 ("virt: Add vboxguest driver for Virtual Box Guest integration UAPI") + Cc: stable@vger.kernel.org + Acked-by: Arnd Bergmann + Reviewed-by: Arnd Bergmann + Signed-off-by: Hans de Goede +--- + drivers/virt/vboxguest/vboxguest_core.c | 266 +++++++++++++++++++++++++------ + drivers/virt/vboxguest/vboxguest_core.h | 23 ++- + drivers/virt/vboxguest/vboxguest_utils.c | 1 + + include/linux/vbox_utils.h | 1 + + include/uapi/linux/vbox_vmmdev_types.h | 3 + + include/uapi/linux/vboxguest.h | 24 +++ + 6 files changed, 269 insertions(+), 49 deletions(-) + +diff --git a/drivers/virt/vboxguest/vboxguest_core.c b/drivers/virt/vboxguest/vboxguest_core.c +index 18ebd7a6af98..0b43efddea22 100644 +--- a/drivers/virt/vboxguest/vboxguest_core.c ++++ b/drivers/virt/vboxguest/vboxguest_core.c +@@ -559,7 +559,7 @@ static int vbg_reset_host_event_filter(struct vbg_dev *gdev, + * Changes the event filter mask for the given session. + * + * This is called in response to VBG_IOCTL_CHANGE_FILTER_MASK as well as to +- * do session cleanup. Takes the session spinlock. ++ * do session cleanup. Takes the session mutex. + * + * Return: 0 or negative errno value. + * @gdev: The Guest extension device. +@@ -662,7 +662,156 @@ static int vbg_reset_host_capabilities(struct vbg_dev *gdev) + } + + /** +- * Sets the guest capabilities for a session. Takes the session spinlock. ++ * Set guest capabilities on the host. ++ * Must be called with gdev->session_mutex hold. ++ * Return: 0 or negative errno value. ++ * @gdev: The Guest extension device. ++ * @session: The session. ++ * @session_termination: Set if we're called by the session cleanup code. ++ */ ++static int vbg_set_host_capabilities(struct vbg_dev *gdev, ++ struct vbg_session *session, ++ bool session_termination) ++{ ++ struct vmmdev_mask *req; ++ u32 caps; ++ int rc; ++ ++ WARN_ON(!mutex_is_locked(&gdev->session_mutex)); ++ ++ caps = gdev->acquired_guest_caps | gdev->set_guest_caps_tracker.mask; ++ ++ if (gdev->guest_caps_host == caps) ++ return 0; ++ ++ /* On termination the requestor is the kernel, as we're cleaning up. */ ++ req = vbg_req_alloc(sizeof(*req), VMMDEVREQ_SET_GUEST_CAPABILITIES, ++ session_termination ? VBG_KERNEL_REQUEST : ++ session->requestor); ++ if (!req) { ++ gdev->guest_caps_host = U32_MAX; ++ return -ENOMEM; ++ } ++ ++ req->or_mask = caps; ++ req->not_mask = ~caps; ++ rc = vbg_req_perform(gdev, req); ++ vbg_req_free(req, sizeof(*req)); ++ ++ gdev->guest_caps_host = (rc >= 0) ? caps : U32_MAX; ++ ++ return vbg_status_code_to_errno(rc); ++} ++ ++/** ++ * Acquire (get exclusive access) guest capabilities for a session. ++ * Takes the session mutex. ++ * Return: 0 or negative errno value. ++ * @gdev: The Guest extension device. ++ * @session: The session. ++ * @flags: Flags (VBGL_IOC_AGC_FLAGS_XXX). ++ * @or_mask: The capabilities to add. ++ * @not_mask: The capabilities to remove. ++ * @session_termination: Set if we're called by the session cleanup code. ++ * This tweaks the error handling so we perform ++ * proper session cleanup even if the host ++ * misbehaves. ++ */ ++static int vbg_acquire_session_capabilities(struct vbg_dev *gdev, ++ struct vbg_session *session, ++ u32 or_mask, u32 not_mask, ++ u32 flags, bool session_termination) ++{ ++ unsigned long irqflags; ++ bool wakeup = false; ++ int ret = 0; ++ ++ mutex_lock(&gdev->session_mutex); ++ ++ if (gdev->set_guest_caps_tracker.mask & or_mask) { ++ vbg_err("%s error: cannot acquire caps which are currently set\n", ++ __func__); ++ ret = -EINVAL; ++ goto out; ++ } ++ ++ /* ++ * Mark any caps in the or_mask as now being in acquire-mode. Note ++ * once caps are in acquire_mode they always stay in this mode. ++ * This impacts event handling, so we take the event-lock. ++ */ ++ spin_lock_irqsave(&gdev->event_spinlock, irqflags); ++ gdev->acquire_mode_guest_caps |= or_mask; ++ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); ++ ++ /* If we only have to switch the caps to acquire mode, we're done. */ ++ if (flags & VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE) ++ goto out; ++ ++ not_mask &= ~or_mask; /* or_mask takes priority over not_mask */ ++ not_mask &= session->acquired_guest_caps; ++ or_mask &= ~session->acquired_guest_caps; ++ ++ if (or_mask == 0 && not_mask == 0) ++ goto out; ++ ++ if (gdev->acquired_guest_caps & or_mask) { ++ ret = -EBUSY; ++ goto out; ++ } ++ ++ gdev->acquired_guest_caps |= or_mask; ++ gdev->acquired_guest_caps &= ~not_mask; ++ /* session->acquired_guest_caps impacts event handling, take the lock */ ++ spin_lock_irqsave(&gdev->event_spinlock, irqflags); ++ session->acquired_guest_caps |= or_mask; ++ session->acquired_guest_caps &= ~not_mask; ++ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); ++ ++ ret = vbg_set_host_capabilities(gdev, session, session_termination); ++ /* Roll back on failure, unless it's session termination time. */ ++ if (ret < 0 && !session_termination) { ++ gdev->acquired_guest_caps &= ~or_mask; ++ gdev->acquired_guest_caps |= not_mask; ++ spin_lock_irqsave(&gdev->event_spinlock, irqflags); ++ session->acquired_guest_caps &= ~or_mask; ++ session->acquired_guest_caps |= not_mask; ++ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); ++ } ++ ++ /* ++ * If we added a capability, check if that means some other thread in ++ * our session should be unblocked because there are events pending ++ * (the result of vbg_get_allowed_event_mask_for_session() may change). ++ * ++ * HACK ALERT! When the seamless support capability is added we generate ++ * a seamless change event so that the ring-3 client can sync with ++ * the seamless state. ++ */ ++ if (ret == 0 && or_mask != 0) { ++ spin_lock_irqsave(&gdev->event_spinlock, irqflags); ++ ++ if (or_mask & VMMDEV_GUEST_SUPPORTS_SEAMLESS) ++ gdev->pending_events |= ++ VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST; ++ ++ if (gdev->pending_events) ++ wakeup = true; ++ ++ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); ++ ++ if (wakeup) ++ wake_up(&gdev->event_wq); ++ } ++ ++out: ++ mutex_unlock(&gdev->session_mutex); ++ ++ return ret; ++} ++ ++/** ++ * Sets the guest capabilities for a session. Takes the session mutex. + * Return: 0 or negative errno value. + * @gdev: The Guest extension device. + * @session: The session. +@@ -678,62 +827,40 @@ static int vbg_set_session_capabilities(struct vbg_dev *gdev, + u32 or_mask, u32 not_mask, + bool session_termination) + { +- struct vmmdev_mask *req; + u32 changed, previous; +- int rc, ret = 0; +- +- /* +- * Allocate a request buffer before taking the spinlock, when +- * the session is being terminated the requestor is the kernel, +- * as we're cleaning up. +- */ +- req = vbg_req_alloc(sizeof(*req), VMMDEVREQ_SET_GUEST_CAPABILITIES, +- session_termination ? VBG_KERNEL_REQUEST : +- session->requestor); +- if (!req) { +- if (!session_termination) +- return -ENOMEM; +- /* Ignore allocation failure, we must do session cleanup. */ +- } ++ int ret = 0; + + mutex_lock(&gdev->session_mutex); + ++ if (gdev->acquire_mode_guest_caps & or_mask) { ++ vbg_err("%s error: cannot set caps which are in acquire_mode\n", ++ __func__); ++ ret = -EBUSY; ++ goto out; ++ } ++ + /* Apply the changes to the session mask. */ +- previous = session->guest_caps; +- session->guest_caps |= or_mask; +- session->guest_caps &= ~not_mask; ++ previous = session->set_guest_caps; ++ session->set_guest_caps |= or_mask; ++ session->set_guest_caps &= ~not_mask; + + /* If anything actually changed, update the global usage counters. */ +- changed = previous ^ session->guest_caps; ++ changed = previous ^ session->set_guest_caps; + if (!changed) + goto out; + +- vbg_track_bit_usage(&gdev->guest_caps_tracker, changed, previous); +- or_mask = gdev->guest_caps_tracker.mask; +- +- if (gdev->guest_caps_host == or_mask || !req) +- goto out; ++ vbg_track_bit_usage(&gdev->set_guest_caps_tracker, changed, previous); + +- gdev->guest_caps_host = or_mask; +- req->or_mask = or_mask; +- req->not_mask = ~or_mask; +- rc = vbg_req_perform(gdev, req); +- if (rc < 0) { +- ret = vbg_status_code_to_errno(rc); +- +- /* Failed, roll back (unless it's session termination time). */ +- gdev->guest_caps_host = U32_MAX; +- if (session_termination) +- goto out; +- +- vbg_track_bit_usage(&gdev->guest_caps_tracker, changed, +- session->guest_caps); +- session->guest_caps = previous; ++ ret = vbg_set_host_capabilities(gdev, session, session_termination); ++ /* Roll back on failure, unless it's session termination time. */ ++ if (ret < 0 && !session_termination) { ++ vbg_track_bit_usage(&gdev->set_guest_caps_tracker, changed, ++ session->set_guest_caps); ++ session->set_guest_caps = previous; + } + + out: + mutex_unlock(&gdev->session_mutex); +- vbg_req_free(req, sizeof(*req)); + + return ret; + } +@@ -949,6 +1076,7 @@ void vbg_core_close_session(struct vbg_session *session) + struct vbg_dev *gdev = session->gdev; + int i, rc; + ++ vbg_acquire_session_capabilities(gdev, session, 0, U32_MAX, 0, true); + vbg_set_session_capabilities(gdev, session, 0, U32_MAX, true); + vbg_set_session_event_filter(gdev, session, 0, U32_MAX, true); + +@@ -1006,6 +1134,25 @@ static int vbg_ioctl_driver_version_info( + return 0; + } + ++/* Must be called with the event_lock held */ ++static u32 vbg_get_allowed_event_mask_for_session(struct vbg_dev *gdev, ++ struct vbg_session *session) ++{ ++ u32 acquire_mode_caps = gdev->acquire_mode_guest_caps; ++ u32 session_acquired_caps = session->acquired_guest_caps; ++ u32 allowed_events = VMMDEV_EVENT_VALID_EVENT_MASK; ++ ++ if ((acquire_mode_caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS) && ++ !(session_acquired_caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS)) ++ allowed_events &= ~VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST; ++ ++ if ((acquire_mode_caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS) && ++ !(session_acquired_caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS)) ++ allowed_events &= ~VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST; ++ ++ return allowed_events; ++} ++ + static bool vbg_wait_event_cond(struct vbg_dev *gdev, + struct vbg_session *session, + u32 event_mask) +@@ -1017,6 +1164,7 @@ static bool vbg_wait_event_cond(struct vbg_dev *gdev, + spin_lock_irqsave(&gdev->event_spinlock, flags); + + events = gdev->pending_events & event_mask; ++ events &= vbg_get_allowed_event_mask_for_session(gdev, session); + wakeup = events || session->cancel_waiters; + + spin_unlock_irqrestore(&gdev->event_spinlock, flags); +@@ -1031,6 +1179,7 @@ static u32 vbg_consume_events_locked(struct vbg_dev *gdev, + { + u32 events = gdev->pending_events & event_mask; + ++ events &= vbg_get_allowed_event_mask_for_session(gdev, session); + gdev->pending_events &= ~events; + return events; + } +@@ -1150,7 +1299,9 @@ static int vbg_req_allowed(struct vbg_dev *gdev, struct vbg_session *session, + case VMMDEVREQ_VIDEO_ACCEL_ENABLE: + case VMMDEVREQ_VIDEO_ACCEL_FLUSH: + case VMMDEVREQ_VIDEO_SET_VISIBLE_REGION: ++ case VMMDEVREQ_VIDEO_UPDATE_MONITOR_POSITIONS: + case VMMDEVREQ_GET_DISPLAY_CHANGE_REQEX: ++ case VMMDEVREQ_GET_DISPLAY_CHANGE_REQ_MULTI: + case VMMDEVREQ_GET_SEAMLESS_CHANGE_REQ: + case VMMDEVREQ_GET_VRDPCHANGE_REQ: + case VMMDEVREQ_LOG_STRING: +@@ -1432,6 +1583,29 @@ static int vbg_ioctl_change_filter_mask(struct vbg_dev *gdev, + false); + } + ++static int vbg_ioctl_acquire_guest_capabilities(struct vbg_dev *gdev, ++ struct vbg_session *session, ++ struct vbg_ioctl_acquire_guest_caps *caps) ++{ ++ u32 flags, or_mask, not_mask; ++ ++ if (vbg_ioctl_chk(&caps->hdr, sizeof(caps->u.in), 0)) ++ return -EINVAL; ++ ++ flags = caps->u.in.flags; ++ or_mask = caps->u.in.or_mask; ++ not_mask = caps->u.in.not_mask; ++ ++ if (flags & ~VBGL_IOC_AGC_FLAGS_VALID_MASK) ++ return -EINVAL; ++ ++ if ((or_mask | not_mask) & ~VMMDEV_GUEST_CAPABILITIES_MASK) ++ return -EINVAL; ++ ++ return vbg_acquire_session_capabilities(gdev, session, or_mask, ++ not_mask, flags, false); ++} ++ + static int vbg_ioctl_change_guest_capabilities(struct vbg_dev *gdev, + struct vbg_session *session, struct vbg_ioctl_set_guest_caps *caps) + { +@@ -1452,7 +1626,7 @@ static int vbg_ioctl_change_guest_capabilities(struct vbg_dev *gdev, + if (ret) + return ret; + +- caps->u.out.session_caps = session->guest_caps; ++ caps->u.out.session_caps = session->set_guest_caps; + caps->u.out.global_caps = gdev->guest_caps_host; + + return 0; +@@ -1541,6 +1715,8 @@ int vbg_core_ioctl(struct vbg_session *session, unsigned int req, void *data) + return vbg_ioctl_interrupt_all_wait_events(gdev, session, data); + case VBG_IOCTL_CHANGE_FILTER_MASK: + return vbg_ioctl_change_filter_mask(gdev, session, data); ++ case VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES: ++ return vbg_ioctl_acquire_guest_capabilities(gdev, session, data); + case VBG_IOCTL_CHANGE_GUEST_CAPABILITIES: + return vbg_ioctl_change_guest_capabilities(gdev, session, data); + case VBG_IOCTL_CHECK_BALLOON: +@@ -1563,7 +1739,7 @@ int vbg_core_ioctl(struct vbg_session *session, unsigned int req, void *data) + return vbg_ioctl_log(data); + } + +- vbg_debug("VGDrvCommonIoCtl: Unknown req %#08x\n", req); ++ vbg_err_ratelimited("Userspace made an unknown ioctl req %#08x\n", req); + return -ENOTTY; + } + +diff --git a/drivers/virt/vboxguest/vboxguest_core.h b/drivers/virt/vboxguest/vboxguest_core.h +index 77c3a9c8255d..ab4bf64e2cec 100644 +--- a/drivers/virt/vboxguest/vboxguest_core.h ++++ b/drivers/virt/vboxguest/vboxguest_core.h +@@ -118,11 +118,21 @@ struct vbg_dev { + u32 event_filter_host; + + /** +- * Usage counters for guest capabilities. Indexed by capability bit ++ * Guest capabilities which have been switched to acquire_mode. ++ */ ++ u32 acquire_mode_guest_caps; ++ /** ++ * Guest capabilities acquired by vbg_acquire_session_capabilities(). ++ * Only one session can acquire a capability at a time. ++ */ ++ u32 acquired_guest_caps; ++ /** ++ * Usage counters for guest capabilities requested through ++ * vbg_set_session_capabilities(). Indexed by capability bit + * number, one count per session using a capability. + * Protected by session_mutex. + */ +- struct vbg_bit_usage_tracker guest_caps_tracker; ++ struct vbg_bit_usage_tracker set_guest_caps_tracker; + /** + * The guest capabilities last reported to the host (or UINT32_MAX). + * Protected by session_mutex. +@@ -164,11 +174,16 @@ struct vbg_session { + */ + u32 event_filter; + /** +- * Guest capabilities for this session. ++ * Guest capabilities acquired by vbg_acquire_session_capabilities(). ++ * Only one session can acquire a capability at a time. ++ */ ++ u32 acquired_guest_caps; ++ /** ++ * Guest capabilities set through vbg_set_session_capabilities(). + * A capability claimed by any guest session will be reported to the + * host. Protected by vbg_gdev.session_mutex. + */ +- u32 guest_caps; ++ u32 set_guest_caps; + /** VMMDEV_REQUESTOR_* flags */ + u32 requestor; + /** Set on CANCEL_ALL_WAITEVENTS, protected by vbg_devevent_spinlock. */ +diff --git a/drivers/virt/vboxguest/vboxguest_utils.c b/drivers/virt/vboxguest/vboxguest_utils.c +index 7396187ee32a..ea05af41ec69 100644 +--- a/drivers/virt/vboxguest/vboxguest_utils.c ++++ b/drivers/virt/vboxguest/vboxguest_utils.c +@@ -59,6 +59,7 @@ EXPORT_SYMBOL(name) + VBG_LOG(vbg_info, pr_info); + VBG_LOG(vbg_warn, pr_warn); + VBG_LOG(vbg_err, pr_err); ++VBG_LOG(vbg_err_ratelimited, pr_err_ratelimited); + #if defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG) + VBG_LOG(vbg_debug, pr_debug); + #endif +diff --git a/include/linux/vbox_utils.h b/include/linux/vbox_utils.h +index ff56c443180c..db8a7d118093 100644 +--- a/include/linux/vbox_utils.h ++++ b/include/linux/vbox_utils.h +@@ -16,6 +16,7 @@ struct vbg_dev; + __printf(1, 2) void vbg_info(const char *fmt, ...); + __printf(1, 2) void vbg_warn(const char *fmt, ...); + __printf(1, 2) void vbg_err(const char *fmt, ...); ++__printf(1, 2) void vbg_err_ratelimited(const char *fmt, ...); + + /* Only use backdoor logging for non-dynamic debug builds */ + #if defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG) +diff --git a/include/uapi/linux/vbox_vmmdev_types.h b/include/uapi/linux/vbox_vmmdev_types.h +index c27289fd619a..f8a8d6b3c521 100644 +--- a/include/uapi/linux/vbox_vmmdev_types.h ++++ b/include/uapi/linux/vbox_vmmdev_types.h +@@ -63,6 +63,7 @@ enum vmmdev_request_type { + VMMDEVREQ_SET_GUEST_CAPABILITIES = 56, + VMMDEVREQ_VIDEMODE_SUPPORTED2 = 57, /* since version 3.2.0 */ + VMMDEVREQ_GET_DISPLAY_CHANGE_REQEX = 80, /* since version 4.2.4 */ ++ VMMDEVREQ_GET_DISPLAY_CHANGE_REQ_MULTI = 81, + VMMDEVREQ_HGCM_CONNECT = 60, + VMMDEVREQ_HGCM_DISCONNECT = 61, + VMMDEVREQ_HGCM_CALL32 = 62, +@@ -92,6 +93,8 @@ enum vmmdev_request_type { + VMMDEVREQ_WRITE_COREDUMP = 218, + VMMDEVREQ_GUEST_HEARTBEAT = 219, + VMMDEVREQ_HEARTBEAT_CONFIGURE = 220, ++ VMMDEVREQ_NT_BUG_CHECK = 221, ++ VMMDEVREQ_VIDEO_UPDATE_MONITOR_POSITIONS = 222, + /* Ensure the enum is a 32 bit data-type */ + VMMDEVREQ_SIZEHACK = 0x7fffffff + }; +diff --git a/include/uapi/linux/vboxguest.h b/include/uapi/linux/vboxguest.h +index f79d7abe27db..15125f6ec60d 100644 +--- a/include/uapi/linux/vboxguest.h ++++ b/include/uapi/linux/vboxguest.h +@@ -257,6 +257,30 @@ VMMDEV_ASSERT_SIZE(vbg_ioctl_change_filter, 24 + 8); + _IOWR('V', 12, struct vbg_ioctl_change_filter) + + ++/** VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES data structure. */ ++struct vbg_ioctl_acquire_guest_caps { ++ /** The header. */ ++ struct vbg_ioctl_hdr hdr; ++ union { ++ struct { ++ /** Flags (VBGL_IOC_AGC_FLAGS_XXX). */ ++ __u32 flags; ++ /** Capabilities to set (VMMDEV_GUEST_SUPPORTS_XXX). */ ++ __u32 or_mask; ++ /** Capabilities to drop (VMMDEV_GUEST_SUPPORTS_XXX). */ ++ __u32 not_mask; ++ } in; ++ } u; ++}; ++VMMDEV_ASSERT_SIZE(vbg_ioctl_acquire_guest_caps, 24 + 12); ++ ++#define VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE 0x00000001 ++#define VBGL_IOC_AGC_FLAGS_VALID_MASK 0x00000001 ++ ++#define VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES \ ++ _IOWR('V', 13, struct vbg_ioctl_acquire_guest_caps) ++ ++ + /** VBG_IOCTL_CHANGE_GUEST_CAPABILITIES data structure. */ + struct vbg_ioctl_set_guest_caps { + /** The header. */ +-- +cgit v1.2.3-1-gf6bb5 + diff --git a/0003-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch b/0003-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch deleted file mode 100644 index 4fd4ec0..0000000 --- a/0003-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch +++ /dev/null @@ -1,645 +0,0 @@ -From d14a96d0a5e05d99c5fe083c49d33197c215dbe1 Mon Sep 17 00:00:00 2001 -From: "Jan Alexander Steffens (heftig)" -Date: Wed, 15 Jul 2020 22:42:07 +0200 -Subject: virt: vbox: Add support for the new - VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES ioctl - -https://lore.kernel.org/patchwork/cover/1270301/ - -Needed for https://bugs.archlinux.org/task/67253 - -Squashed commit of the following: - -commit 0d7bec556896815f4920a5ed87339732c697175c -Author: Hans de Goede -Date: Thu Jul 9 14:08:58 2020 +0200 - - virt: vbox: Fix some comments which talk about the "session spinlock" - - The session lock is a mutex, not a spinlock, fix the comments to match. - - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit fed91350029e0c3bf626bd55a148e766587ec439 -Author: Hans de Goede -Date: Thu Jul 9 14:08:57 2020 +0200 - - virt: vbox: Log unknown ioctl requests as error - - Every now and then upstream adds new ioctls without notifying us, - log unknown ioctl requests as an error to catch these. - - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit 245d06f4c1b8f84cde07d14c09296a4fe90a26f0 -Author: Hans de Goede -Date: Thu Jul 9 14:08:56 2020 +0200 - - virt: vbox: Add a few new vmmdev request types to the userspace whitelist - - Upstream VirtualBox has defined and is using a few new request types for - vmmdev requests passed through /dev/vboxguest to the hypervisor. - - Add the defines for these to vbox_vmmdev_types.h and add add them to the - whitelists of vmmdev requests which userspace is allowed to make. - - BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1789545 - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit 2f24f5446915322bbbb1ccf4ee2297512feab942 -Author: Hans de Goede -Date: Thu Jul 9 14:08:55 2020 +0200 - - virt: vbox: Add support for the new VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES ioctl - - Add support for the new VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES ioctl, this - is necessary for automatic resizing of the guest resolution to match the - VM-window size to work with the new VMSVGA virtual GPU which is now the - new default in VirtualBox. - - BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1789545 - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit 2fc9822453e8dd215765cd2b28e5e6e26338829e -Author: Hans de Goede -Date: Thu Jul 9 14:08:54 2020 +0200 - - virt: vbox: Add vbg_set_host_capabilities() helper function - - Add vbg_set_host_capabilities() helper function, this is a preparation - patch for adding support for the VBGL_IOCTL_GUEST_CAPS_ACQUIRE ioctl. - - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit 1594daf929c8691849c00e49e4a1ed977048addc -Author: Hans de Goede -Date: Thu Jul 9 14:08:53 2020 +0200 - - virt: vbox: Rename guest_caps struct members to set_guest_caps - - Rename guest_caps[_tracker] struct members to set_guest_caps[_tracker] - this is a preparation patch for adding support for the - VBGL_IOCTL_GUEST_CAPS_ACQUIRE ioctl. - - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit d7f3b7cec66d171cf5194ad37f647f4562da6ccc -Author: Hans de Goede -Date: Thu Jul 9 14:08:52 2020 +0200 - - virt: vbox: Fix guest capabilities mask check - - Check the passed in capabilities against VMMDEV_GUEST_CAPABILITIES_MASK - instead of against VMMDEV_EVENT_VALID_EVENT_MASK. - This tightens the allowed mask from 0x7ff to 0x7. - - Fixes: 0ba002bc4393 ("virt: Add vboxguest driver for Virtual Box Guest integration") - Cc: stable@vger.kernel.org - Acked-by: Arnd Bergmann - Signed-off-by: Hans de Goede - -commit f6694fa90e2183874def2d022d097795e2269a15 -Author: Hans de Goede -Date: Thu Jul 9 14:08:51 2020 +0200 - - virt: vbox: Fix VBGL_IOCTL_VMMDEV_REQUEST_BIG and _LOG req numbers to match upstream - - Until this commit the mainline kernel version (this version) of the - vboxguest module contained a bug where it defined - VBGL_IOCTL_VMMDEV_REQUEST_BIG and VBGL_IOCTL_LOG using - _IOC(_IOC_READ | _IOC_WRITE, 'V', ...) instead of - _IO(V, ...) as the out of tree VirtualBox upstream version does. - - Since the VirtualBox userspace bits are always built against VirtualBox - upstream's headers, this means that so far the mainline kernel version - of the vboxguest module has been failing these 2 ioctls with -ENOTTY. - I guess that VBGL_IOCTL_VMMDEV_REQUEST_BIG is never used causing us to - not hit that one and sofar the vboxguest driver has failed to actually - log any log messages passed it through VBGL_IOCTL_LOG. - - This commit changes the VBGL_IOCTL_VMMDEV_REQUEST_BIG and VBGL_IOCTL_LOG - defines to match the out of tree VirtualBox upstream vboxguest version, - while keeping compatibility with the old wrong request defines so as - to not break the kernel ABI in case someone has been using the old - request defines. - - Fixes: f6ddd094f579 ("virt: Add vboxguest driver for Virtual Box Guest integration UAPI") - Cc: stable@vger.kernel.org - Acked-by: Arnd Bergmann - Reviewed-by: Arnd Bergmann - Signed-off-by: Hans de Goede ---- - drivers/virt/vboxguest/vboxguest_core.c | 266 +++++++++++++++++++++++++------ - drivers/virt/vboxguest/vboxguest_core.h | 23 ++- - drivers/virt/vboxguest/vboxguest_utils.c | 1 + - include/linux/vbox_utils.h | 1 + - include/uapi/linux/vbox_vmmdev_types.h | 3 + - include/uapi/linux/vboxguest.h | 24 +++ - 6 files changed, 269 insertions(+), 49 deletions(-) - -diff --git a/drivers/virt/vboxguest/vboxguest_core.c b/drivers/virt/vboxguest/vboxguest_core.c -index 18ebd7a6af98..0b43efddea22 100644 ---- a/drivers/virt/vboxguest/vboxguest_core.c -+++ b/drivers/virt/vboxguest/vboxguest_core.c -@@ -559,7 +559,7 @@ static int vbg_reset_host_event_filter(struct vbg_dev *gdev, - * Changes the event filter mask for the given session. - * - * This is called in response to VBG_IOCTL_CHANGE_FILTER_MASK as well as to -- * do session cleanup. Takes the session spinlock. -+ * do session cleanup. Takes the session mutex. - * - * Return: 0 or negative errno value. - * @gdev: The Guest extension device. -@@ -662,7 +662,156 @@ static int vbg_reset_host_capabilities(struct vbg_dev *gdev) - } - - /** -- * Sets the guest capabilities for a session. Takes the session spinlock. -+ * Set guest capabilities on the host. -+ * Must be called with gdev->session_mutex hold. -+ * Return: 0 or negative errno value. -+ * @gdev: The Guest extension device. -+ * @session: The session. -+ * @session_termination: Set if we're called by the session cleanup code. -+ */ -+static int vbg_set_host_capabilities(struct vbg_dev *gdev, -+ struct vbg_session *session, -+ bool session_termination) -+{ -+ struct vmmdev_mask *req; -+ u32 caps; -+ int rc; -+ -+ WARN_ON(!mutex_is_locked(&gdev->session_mutex)); -+ -+ caps = gdev->acquired_guest_caps | gdev->set_guest_caps_tracker.mask; -+ -+ if (gdev->guest_caps_host == caps) -+ return 0; -+ -+ /* On termination the requestor is the kernel, as we're cleaning up. */ -+ req = vbg_req_alloc(sizeof(*req), VMMDEVREQ_SET_GUEST_CAPABILITIES, -+ session_termination ? VBG_KERNEL_REQUEST : -+ session->requestor); -+ if (!req) { -+ gdev->guest_caps_host = U32_MAX; -+ return -ENOMEM; -+ } -+ -+ req->or_mask = caps; -+ req->not_mask = ~caps; -+ rc = vbg_req_perform(gdev, req); -+ vbg_req_free(req, sizeof(*req)); -+ -+ gdev->guest_caps_host = (rc >= 0) ? caps : U32_MAX; -+ -+ return vbg_status_code_to_errno(rc); -+} -+ -+/** -+ * Acquire (get exclusive access) guest capabilities for a session. -+ * Takes the session mutex. -+ * Return: 0 or negative errno value. -+ * @gdev: The Guest extension device. -+ * @session: The session. -+ * @flags: Flags (VBGL_IOC_AGC_FLAGS_XXX). -+ * @or_mask: The capabilities to add. -+ * @not_mask: The capabilities to remove. -+ * @session_termination: Set if we're called by the session cleanup code. -+ * This tweaks the error handling so we perform -+ * proper session cleanup even if the host -+ * misbehaves. -+ */ -+static int vbg_acquire_session_capabilities(struct vbg_dev *gdev, -+ struct vbg_session *session, -+ u32 or_mask, u32 not_mask, -+ u32 flags, bool session_termination) -+{ -+ unsigned long irqflags; -+ bool wakeup = false; -+ int ret = 0; -+ -+ mutex_lock(&gdev->session_mutex); -+ -+ if (gdev->set_guest_caps_tracker.mask & or_mask) { -+ vbg_err("%s error: cannot acquire caps which are currently set\n", -+ __func__); -+ ret = -EINVAL; -+ goto out; -+ } -+ -+ /* -+ * Mark any caps in the or_mask as now being in acquire-mode. Note -+ * once caps are in acquire_mode they always stay in this mode. -+ * This impacts event handling, so we take the event-lock. -+ */ -+ spin_lock_irqsave(&gdev->event_spinlock, irqflags); -+ gdev->acquire_mode_guest_caps |= or_mask; -+ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); -+ -+ /* If we only have to switch the caps to acquire mode, we're done. */ -+ if (flags & VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE) -+ goto out; -+ -+ not_mask &= ~or_mask; /* or_mask takes priority over not_mask */ -+ not_mask &= session->acquired_guest_caps; -+ or_mask &= ~session->acquired_guest_caps; -+ -+ if (or_mask == 0 && not_mask == 0) -+ goto out; -+ -+ if (gdev->acquired_guest_caps & or_mask) { -+ ret = -EBUSY; -+ goto out; -+ } -+ -+ gdev->acquired_guest_caps |= or_mask; -+ gdev->acquired_guest_caps &= ~not_mask; -+ /* session->acquired_guest_caps impacts event handling, take the lock */ -+ spin_lock_irqsave(&gdev->event_spinlock, irqflags); -+ session->acquired_guest_caps |= or_mask; -+ session->acquired_guest_caps &= ~not_mask; -+ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); -+ -+ ret = vbg_set_host_capabilities(gdev, session, session_termination); -+ /* Roll back on failure, unless it's session termination time. */ -+ if (ret < 0 && !session_termination) { -+ gdev->acquired_guest_caps &= ~or_mask; -+ gdev->acquired_guest_caps |= not_mask; -+ spin_lock_irqsave(&gdev->event_spinlock, irqflags); -+ session->acquired_guest_caps &= ~or_mask; -+ session->acquired_guest_caps |= not_mask; -+ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); -+ } -+ -+ /* -+ * If we added a capability, check if that means some other thread in -+ * our session should be unblocked because there are events pending -+ * (the result of vbg_get_allowed_event_mask_for_session() may change). -+ * -+ * HACK ALERT! When the seamless support capability is added we generate -+ * a seamless change event so that the ring-3 client can sync with -+ * the seamless state. -+ */ -+ if (ret == 0 && or_mask != 0) { -+ spin_lock_irqsave(&gdev->event_spinlock, irqflags); -+ -+ if (or_mask & VMMDEV_GUEST_SUPPORTS_SEAMLESS) -+ gdev->pending_events |= -+ VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST; -+ -+ if (gdev->pending_events) -+ wakeup = true; -+ -+ spin_unlock_irqrestore(&gdev->event_spinlock, irqflags); -+ -+ if (wakeup) -+ wake_up(&gdev->event_wq); -+ } -+ -+out: -+ mutex_unlock(&gdev->session_mutex); -+ -+ return ret; -+} -+ -+/** -+ * Sets the guest capabilities for a session. Takes the session mutex. - * Return: 0 or negative errno value. - * @gdev: The Guest extension device. - * @session: The session. -@@ -678,62 +827,40 @@ static int vbg_set_session_capabilities(struct vbg_dev *gdev, - u32 or_mask, u32 not_mask, - bool session_termination) - { -- struct vmmdev_mask *req; - u32 changed, previous; -- int rc, ret = 0; -- -- /* -- * Allocate a request buffer before taking the spinlock, when -- * the session is being terminated the requestor is the kernel, -- * as we're cleaning up. -- */ -- req = vbg_req_alloc(sizeof(*req), VMMDEVREQ_SET_GUEST_CAPABILITIES, -- session_termination ? VBG_KERNEL_REQUEST : -- session->requestor); -- if (!req) { -- if (!session_termination) -- return -ENOMEM; -- /* Ignore allocation failure, we must do session cleanup. */ -- } -+ int ret = 0; - - mutex_lock(&gdev->session_mutex); - -+ if (gdev->acquire_mode_guest_caps & or_mask) { -+ vbg_err("%s error: cannot set caps which are in acquire_mode\n", -+ __func__); -+ ret = -EBUSY; -+ goto out; -+ } -+ - /* Apply the changes to the session mask. */ -- previous = session->guest_caps; -- session->guest_caps |= or_mask; -- session->guest_caps &= ~not_mask; -+ previous = session->set_guest_caps; -+ session->set_guest_caps |= or_mask; -+ session->set_guest_caps &= ~not_mask; - - /* If anything actually changed, update the global usage counters. */ -- changed = previous ^ session->guest_caps; -+ changed = previous ^ session->set_guest_caps; - if (!changed) - goto out; - -- vbg_track_bit_usage(&gdev->guest_caps_tracker, changed, previous); -- or_mask = gdev->guest_caps_tracker.mask; -- -- if (gdev->guest_caps_host == or_mask || !req) -- goto out; -+ vbg_track_bit_usage(&gdev->set_guest_caps_tracker, changed, previous); - -- gdev->guest_caps_host = or_mask; -- req->or_mask = or_mask; -- req->not_mask = ~or_mask; -- rc = vbg_req_perform(gdev, req); -- if (rc < 0) { -- ret = vbg_status_code_to_errno(rc); -- -- /* Failed, roll back (unless it's session termination time). */ -- gdev->guest_caps_host = U32_MAX; -- if (session_termination) -- goto out; -- -- vbg_track_bit_usage(&gdev->guest_caps_tracker, changed, -- session->guest_caps); -- session->guest_caps = previous; -+ ret = vbg_set_host_capabilities(gdev, session, session_termination); -+ /* Roll back on failure, unless it's session termination time. */ -+ if (ret < 0 && !session_termination) { -+ vbg_track_bit_usage(&gdev->set_guest_caps_tracker, changed, -+ session->set_guest_caps); -+ session->set_guest_caps = previous; - } - - out: - mutex_unlock(&gdev->session_mutex); -- vbg_req_free(req, sizeof(*req)); - - return ret; - } -@@ -949,6 +1076,7 @@ void vbg_core_close_session(struct vbg_session *session) - struct vbg_dev *gdev = session->gdev; - int i, rc; - -+ vbg_acquire_session_capabilities(gdev, session, 0, U32_MAX, 0, true); - vbg_set_session_capabilities(gdev, session, 0, U32_MAX, true); - vbg_set_session_event_filter(gdev, session, 0, U32_MAX, true); - -@@ -1006,6 +1134,25 @@ static int vbg_ioctl_driver_version_info( - return 0; - } - -+/* Must be called with the event_lock held */ -+static u32 vbg_get_allowed_event_mask_for_session(struct vbg_dev *gdev, -+ struct vbg_session *session) -+{ -+ u32 acquire_mode_caps = gdev->acquire_mode_guest_caps; -+ u32 session_acquired_caps = session->acquired_guest_caps; -+ u32 allowed_events = VMMDEV_EVENT_VALID_EVENT_MASK; -+ -+ if ((acquire_mode_caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS) && -+ !(session_acquired_caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS)) -+ allowed_events &= ~VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST; -+ -+ if ((acquire_mode_caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS) && -+ !(session_acquired_caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS)) -+ allowed_events &= ~VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST; -+ -+ return allowed_events; -+} -+ - static bool vbg_wait_event_cond(struct vbg_dev *gdev, - struct vbg_session *session, - u32 event_mask) -@@ -1017,6 +1164,7 @@ static bool vbg_wait_event_cond(struct vbg_dev *gdev, - spin_lock_irqsave(&gdev->event_spinlock, flags); - - events = gdev->pending_events & event_mask; -+ events &= vbg_get_allowed_event_mask_for_session(gdev, session); - wakeup = events || session->cancel_waiters; - - spin_unlock_irqrestore(&gdev->event_spinlock, flags); -@@ -1031,6 +1179,7 @@ static u32 vbg_consume_events_locked(struct vbg_dev *gdev, - { - u32 events = gdev->pending_events & event_mask; - -+ events &= vbg_get_allowed_event_mask_for_session(gdev, session); - gdev->pending_events &= ~events; - return events; - } -@@ -1150,7 +1299,9 @@ static int vbg_req_allowed(struct vbg_dev *gdev, struct vbg_session *session, - case VMMDEVREQ_VIDEO_ACCEL_ENABLE: - case VMMDEVREQ_VIDEO_ACCEL_FLUSH: - case VMMDEVREQ_VIDEO_SET_VISIBLE_REGION: -+ case VMMDEVREQ_VIDEO_UPDATE_MONITOR_POSITIONS: - case VMMDEVREQ_GET_DISPLAY_CHANGE_REQEX: -+ case VMMDEVREQ_GET_DISPLAY_CHANGE_REQ_MULTI: - case VMMDEVREQ_GET_SEAMLESS_CHANGE_REQ: - case VMMDEVREQ_GET_VRDPCHANGE_REQ: - case VMMDEVREQ_LOG_STRING: -@@ -1432,6 +1583,29 @@ static int vbg_ioctl_change_filter_mask(struct vbg_dev *gdev, - false); - } - -+static int vbg_ioctl_acquire_guest_capabilities(struct vbg_dev *gdev, -+ struct vbg_session *session, -+ struct vbg_ioctl_acquire_guest_caps *caps) -+{ -+ u32 flags, or_mask, not_mask; -+ -+ if (vbg_ioctl_chk(&caps->hdr, sizeof(caps->u.in), 0)) -+ return -EINVAL; -+ -+ flags = caps->u.in.flags; -+ or_mask = caps->u.in.or_mask; -+ not_mask = caps->u.in.not_mask; -+ -+ if (flags & ~VBGL_IOC_AGC_FLAGS_VALID_MASK) -+ return -EINVAL; -+ -+ if ((or_mask | not_mask) & ~VMMDEV_GUEST_CAPABILITIES_MASK) -+ return -EINVAL; -+ -+ return vbg_acquire_session_capabilities(gdev, session, or_mask, -+ not_mask, flags, false); -+} -+ - static int vbg_ioctl_change_guest_capabilities(struct vbg_dev *gdev, - struct vbg_session *session, struct vbg_ioctl_set_guest_caps *caps) - { -@@ -1452,7 +1626,7 @@ static int vbg_ioctl_change_guest_capabilities(struct vbg_dev *gdev, - if (ret) - return ret; - -- caps->u.out.session_caps = session->guest_caps; -+ caps->u.out.session_caps = session->set_guest_caps; - caps->u.out.global_caps = gdev->guest_caps_host; - - return 0; -@@ -1541,6 +1715,8 @@ int vbg_core_ioctl(struct vbg_session *session, unsigned int req, void *data) - return vbg_ioctl_interrupt_all_wait_events(gdev, session, data); - case VBG_IOCTL_CHANGE_FILTER_MASK: - return vbg_ioctl_change_filter_mask(gdev, session, data); -+ case VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES: -+ return vbg_ioctl_acquire_guest_capabilities(gdev, session, data); - case VBG_IOCTL_CHANGE_GUEST_CAPABILITIES: - return vbg_ioctl_change_guest_capabilities(gdev, session, data); - case VBG_IOCTL_CHECK_BALLOON: -@@ -1563,7 +1739,7 @@ int vbg_core_ioctl(struct vbg_session *session, unsigned int req, void *data) - return vbg_ioctl_log(data); - } - -- vbg_debug("VGDrvCommonIoCtl: Unknown req %#08x\n", req); -+ vbg_err_ratelimited("Userspace made an unknown ioctl req %#08x\n", req); - return -ENOTTY; - } - -diff --git a/drivers/virt/vboxguest/vboxguest_core.h b/drivers/virt/vboxguest/vboxguest_core.h -index 77c3a9c8255d..ab4bf64e2cec 100644 ---- a/drivers/virt/vboxguest/vboxguest_core.h -+++ b/drivers/virt/vboxguest/vboxguest_core.h -@@ -118,11 +118,21 @@ struct vbg_dev { - u32 event_filter_host; - - /** -- * Usage counters for guest capabilities. Indexed by capability bit -+ * Guest capabilities which have been switched to acquire_mode. -+ */ -+ u32 acquire_mode_guest_caps; -+ /** -+ * Guest capabilities acquired by vbg_acquire_session_capabilities(). -+ * Only one session can acquire a capability at a time. -+ */ -+ u32 acquired_guest_caps; -+ /** -+ * Usage counters for guest capabilities requested through -+ * vbg_set_session_capabilities(). Indexed by capability bit - * number, one count per session using a capability. - * Protected by session_mutex. - */ -- struct vbg_bit_usage_tracker guest_caps_tracker; -+ struct vbg_bit_usage_tracker set_guest_caps_tracker; - /** - * The guest capabilities last reported to the host (or UINT32_MAX). - * Protected by session_mutex. -@@ -164,11 +174,16 @@ struct vbg_session { - */ - u32 event_filter; - /** -- * Guest capabilities for this session. -+ * Guest capabilities acquired by vbg_acquire_session_capabilities(). -+ * Only one session can acquire a capability at a time. -+ */ -+ u32 acquired_guest_caps; -+ /** -+ * Guest capabilities set through vbg_set_session_capabilities(). - * A capability claimed by any guest session will be reported to the - * host. Protected by vbg_gdev.session_mutex. - */ -- u32 guest_caps; -+ u32 set_guest_caps; - /** VMMDEV_REQUESTOR_* flags */ - u32 requestor; - /** Set on CANCEL_ALL_WAITEVENTS, protected by vbg_devevent_spinlock. */ -diff --git a/drivers/virt/vboxguest/vboxguest_utils.c b/drivers/virt/vboxguest/vboxguest_utils.c -index 7396187ee32a..ea05af41ec69 100644 ---- a/drivers/virt/vboxguest/vboxguest_utils.c -+++ b/drivers/virt/vboxguest/vboxguest_utils.c -@@ -59,6 +59,7 @@ EXPORT_SYMBOL(name) - VBG_LOG(vbg_info, pr_info); - VBG_LOG(vbg_warn, pr_warn); - VBG_LOG(vbg_err, pr_err); -+VBG_LOG(vbg_err_ratelimited, pr_err_ratelimited); - #if defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG) - VBG_LOG(vbg_debug, pr_debug); - #endif -diff --git a/include/linux/vbox_utils.h b/include/linux/vbox_utils.h -index ff56c443180c..db8a7d118093 100644 ---- a/include/linux/vbox_utils.h -+++ b/include/linux/vbox_utils.h -@@ -16,6 +16,7 @@ struct vbg_dev; - __printf(1, 2) void vbg_info(const char *fmt, ...); - __printf(1, 2) void vbg_warn(const char *fmt, ...); - __printf(1, 2) void vbg_err(const char *fmt, ...); -+__printf(1, 2) void vbg_err_ratelimited(const char *fmt, ...); - - /* Only use backdoor logging for non-dynamic debug builds */ - #if defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG) -diff --git a/include/uapi/linux/vbox_vmmdev_types.h b/include/uapi/linux/vbox_vmmdev_types.h -index c27289fd619a..f8a8d6b3c521 100644 ---- a/include/uapi/linux/vbox_vmmdev_types.h -+++ b/include/uapi/linux/vbox_vmmdev_types.h -@@ -63,6 +63,7 @@ enum vmmdev_request_type { - VMMDEVREQ_SET_GUEST_CAPABILITIES = 56, - VMMDEVREQ_VIDEMODE_SUPPORTED2 = 57, /* since version 3.2.0 */ - VMMDEVREQ_GET_DISPLAY_CHANGE_REQEX = 80, /* since version 4.2.4 */ -+ VMMDEVREQ_GET_DISPLAY_CHANGE_REQ_MULTI = 81, - VMMDEVREQ_HGCM_CONNECT = 60, - VMMDEVREQ_HGCM_DISCONNECT = 61, - VMMDEVREQ_HGCM_CALL32 = 62, -@@ -92,6 +93,8 @@ enum vmmdev_request_type { - VMMDEVREQ_WRITE_COREDUMP = 218, - VMMDEVREQ_GUEST_HEARTBEAT = 219, - VMMDEVREQ_HEARTBEAT_CONFIGURE = 220, -+ VMMDEVREQ_NT_BUG_CHECK = 221, -+ VMMDEVREQ_VIDEO_UPDATE_MONITOR_POSITIONS = 222, - /* Ensure the enum is a 32 bit data-type */ - VMMDEVREQ_SIZEHACK = 0x7fffffff - }; -diff --git a/include/uapi/linux/vboxguest.h b/include/uapi/linux/vboxguest.h -index f79d7abe27db..15125f6ec60d 100644 ---- a/include/uapi/linux/vboxguest.h -+++ b/include/uapi/linux/vboxguest.h -@@ -257,6 +257,30 @@ VMMDEV_ASSERT_SIZE(vbg_ioctl_change_filter, 24 + 8); - _IOWR('V', 12, struct vbg_ioctl_change_filter) - - -+/** VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES data structure. */ -+struct vbg_ioctl_acquire_guest_caps { -+ /** The header. */ -+ struct vbg_ioctl_hdr hdr; -+ union { -+ struct { -+ /** Flags (VBGL_IOC_AGC_FLAGS_XXX). */ -+ __u32 flags; -+ /** Capabilities to set (VMMDEV_GUEST_SUPPORTS_XXX). */ -+ __u32 or_mask; -+ /** Capabilities to drop (VMMDEV_GUEST_SUPPORTS_XXX). */ -+ __u32 not_mask; -+ } in; -+ } u; -+}; -+VMMDEV_ASSERT_SIZE(vbg_ioctl_acquire_guest_caps, 24 + 12); -+ -+#define VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE 0x00000001 -+#define VBGL_IOC_AGC_FLAGS_VALID_MASK 0x00000001 -+ -+#define VBG_IOCTL_ACQUIRE_GUEST_CAPABILITIES \ -+ _IOWR('V', 13, struct vbg_ioctl_acquire_guest_caps) -+ -+ - /** VBG_IOCTL_CHANGE_GUEST_CAPABILITIES data structure. */ - struct vbg_ioctl_set_guest_caps { - /** The header. */ --- -cgit v1.2.3-1-gf6bb5 - diff --git a/PKGBUILD b/PKGBUILD index 46bac8f..c6507ae 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -9,14 +9,16 @@ # Parabola version is 300 Hz # Parabola version does not disable lockdown eee # Parabola version does not disable hdcp +# Parabola version does not disable IME/PSP +# Parabola version does not disable VMware and HyperV pkgbase=linux-libre _supver=5 -_majver=7 -_minver=19 +_majver=8 +_minver=5 _gccpatchver='20200615' _gccpatchger='10.1' -_gccpatchker='5.7' +_gccpatchker='5.8' if [ "$_minver" == "0" ]; then pkgver=${_supver}.${_majver} else @@ -39,8 +41,7 @@ _gnupkgver=${pkgver}-gnu source=( https://linux-libre.fsfla.org/pub/linux-libre/releases/${_gnumajver}/linux-libre-${_gnumajver}.tar.xz{,.sign} 0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch - 0002-PCI-EDR-Log-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch - 0003-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch + 0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch kernel_gcc_patch-${_gccpatchver}.tar.gz::https://github.com/graysky2/kernel_gcc_patch/archive/${_gccpatchver}.tar.gz ath9k-regdom-hack.patch raid6-default-algo.patch @@ -53,20 +54,19 @@ source=( validpgpkeys=( '474402C8C582DAFBE389C427BCB7CF877E7D47A7' # Alexandre Oliva ) -b2sums=('bb65e65c69d1c38943327a0859028c843439590e9f1af66705a0fe01aaf006daf14a5a0adfaef6d1de53511e50b2f6b8ee13caa63dd7cf4065253599fe524998' +b2sums=('30db9a0143db9824e69c772d4a6634527dfe0aa6fb2dad8177facd57d4e2587a3344a174e48f7d35cb1b3fce00f274143be2495239cba09e6b95e06029a29183' 'SKIP' - 'ab1fb19c67d4c107f75767581c33d9c1458b4d9fdb88f4adb41d30a36f5a2f95f1c48ef079eb87e1e6e8ce2f98b293195cb2c0f2a8ec975aa817453289158c6e' - '490c7d188215f1d24b5807a744853fa308c2cd17c9eb8668918a50a0c58cab9cbc9ee13ac9abbb614eb010a4a56e9092fea4440d44c80c8e67f2d9abdf19a83f' - '00900ec68ad9ebdf5b9103cb8383ee94b97d2b243cb4458f04f877a1b294817e8a140ce2832d424030d039c48f37eaa5bc5fae7a158da495d78e659b8b3006dc' + 'dd8d62b88c0d79eb18b5695b39ca374657b5dd3f5c296a9b262b98e8d0058709b52ad4b56e69afe2fa3db25f944636b8b1eec951e40bd5d02b4127dde6cc4796' + 'e54020096951d8e1adb06f524259238fe56922f535f44645d30e4645ac0cb53264afc4840ff77052e3fe8bea4d1a5199d5909041596f0fdfa60203f3ef34248c' 'c8d0697f99fe6105815217b8ec059d8f587415ea8dd2b88a65e1087feedf697341a64cd56810fde9e7aeada79125fc8235faccc7e7b06492c099e27a8abbe99c' '2e58bb89b247b1678355368956e67c1de51fcde97a227b2162f6771e30f17fa5520faafe7be4b6816a542e7ae10d05f64c6b6354f352c12746d4b8da632936dd' 'fde132f3705d908e6f2147c78a2193289916d72304ca5efa2229d79fc3e57a857314ce94e71425caef2f7f7b6cf87f05ef86335dc8bd4be78e7035afe608005a' - '136edb4b4fdc3c247a8dcfe9615c0cc5ffa7c4c8913bfe59d41c816a5ec432969781b70ea52c21a2343782fb04dd238e69d8d2dbcf9740f7cbacc5ccca7b32c4' + '57f5fd7013589cdd71e9b23090a8f06d0e42da9f1fd706788421b50ef407049bb012e4f99b88a05a9aad9c4fad139f104fbe7c4aea72168a838c1df39baaecde' 'b4e1377d97ad7e8144d6e55b6d43731e3271a5aec65b65ca6d81026a95f15f549b9303fb3c6f492099ca691e3f65f4cf7f0c3aa742df03b396d7f6d81813aa95' - '0d2e336dae6213f78d3dce26c80751f0a0e18f401ea061960e735a4ec010cec3e8fe73380a7d5b89d097a374ab2eb7560020f39d60f0eb9ae214a77a605ea206' + '311e4d06e690070b5ae9b823bfc89b3449ecba2cc4fd9032118a6a086a1202a6c660882d11ecd729af66cea50aef0cfc10c28bb9836562c4cbe963bf971ad4aa' 'SKIP') -#export KBUILD_BUILD_HOST=arc4linux +export KBUILD_BUILD_HOST=arc4linux export KBUILD_BUILD_USER=$pkgbase export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})" @@ -83,8 +83,7 @@ prepare() { # Hotfixes echo "Applying hotfixes" patch -p1 -i ../0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch - patch -p1 -i ../0002-PCI-EDR-Log-only-ACPI_NOTIFY_DISCONNECT_RECOVER-even.patch - patch -p1 -i ../0003-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch + patch -p1 -i ../0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch patch -p1 -i ../sphinx-workaround.patch @@ -155,8 +154,8 @@ _package() { depends=(coreutils kmod initramfs) optdepends=('crda: to set the correct wireless channels of your country' 'linux-libre-firmware: firmware images needed for some devices') - provides=(WIREGUARD-MODULE) - replaces=(wireguard-arch) + provides=(VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE) + replaces=(virtualbox-guest-modules-arch wireguard-arch) cd $_srcname local kernver="$(