git: 0f14bcbe3840 - main - vmci: fix panic due to freeing unallocated resources

2021-10-09 Thread Mark Peek
The branch main has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0f14bcbe384091c729464cb770372aeb79061070

commit 0f14bcbe384091c729464cb770372aeb79061070
Author: Mark Peek 
AuthorDate: 2021-10-09 21:21:16 +
Commit: Mark Peek 
CommitDate: 2021-10-09 21:21:16 +

vmci: fix panic due to freeing unallocated resources

Summary:
An error mapping PCI resources results in a panic due to unallocated
resources being freed up. This change puts the appropriate checks in
place to prevent the panic.

PR: 252445
Reported by:Marek Zarychta 
Tested by:  marcus
MFC after:  1 week
Sponsored by:   VMware

Test Plan:
Along with user testing, also simulated error by inserting a ENXIO
return in vmci_map_bars().

Reviewed by:marcus
Subscribers:imp
Differential Revision: https://reviews.freebsd.org/D32016
---
 sys/dev/vmware/vmci/vmci.c|  9 ---
 sys/dev/vmware/vmci/vmci_event.c  |  3 +++
 sys/dev/vmware/vmci/vmci_kernel_if.c  | 48 ++-
 sys/dev/vmware/vmci/vmci_kernel_if.h  |  2 ++
 sys/dev/vmware/vmci/vmci_queue_pair.c |  3 +++
 5 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/sys/dev/vmware/vmci/vmci.c b/sys/dev/vmware/vmci/vmci.c
index bbf17bbe7e41..8adcb7f532b7 100644
--- a/sys/dev/vmware/vmci/vmci.c
+++ b/sys/dev/vmware/vmci/vmci.c
@@ -242,8 +242,10 @@ vmci_detach(device_t dev)
 
vmci_components_cleanup();
 
-   taskqueue_drain(taskqueue_thread, &sc->vmci_delayed_work_task);
-   mtx_destroy(&sc->vmci_delayed_work_lock);
+   if mtx_initialized(&sc->vmci_spinlock) {
+   taskqueue_drain(taskqueue_thread, &sc->vmci_delayed_work_task);
+   mtx_destroy(&sc->vmci_delayed_work_lock);
+   }
 
if (sc->vmci_res0 != NULL)
bus_space_write_4(sc->vmci_iot0, sc->vmci_ioh0,
@@ -254,7 +256,8 @@ vmci_detach(device_t dev)
 
vmci_unmap_bars(sc);
 
-   mtx_destroy(&sc->vmci_spinlock);
+   if mtx_initialized(&sc->vmci_spinlock)
+   mtx_destroy(&sc->vmci_spinlock);
 
pci_disable_busmaster(dev);
 
diff --git a/sys/dev/vmware/vmci/vmci_event.c b/sys/dev/vmware/vmci/vmci_event.c
index 7f3bf9039e12..192828cc6f6a 100644
--- a/sys/dev/vmware/vmci/vmci_event.c
+++ b/sys/dev/vmware/vmci/vmci_event.c
@@ -593,6 +593,9 @@ vmci_event_unregister_subscription(vmci_id sub_id)
 {
struct vmci_subscription *s;
 
+   if (!vmci_initialized_lock(&subscriber_lock))
+   return NULL;
+
vmci_grab_lock_bh(&subscriber_lock);
s = vmci_event_find(sub_id);
if (s != NULL) {
diff --git a/sys/dev/vmware/vmci/vmci_kernel_if.c 
b/sys/dev/vmware/vmci/vmci_kernel_if.c
index e845650873b5..de54a8d1ca4f 100644
--- a/sys/dev/vmware/vmci/vmci_kernel_if.c
+++ b/sys/dev/vmware/vmci/vmci_kernel_if.c
@@ -70,7 +70,8 @@ void
 vmci_cleanup_lock(vmci_lock *lock)
 {
 
-   mtx_destroy(lock);
+   if mtx_initialized(lock)
+   mtx_destroy(lock);
 }
 
 /*
@@ -165,6 +166,29 @@ vmci_release_lock_bh(vmci_lock *lock)
mtx_unlock(lock);
 }
 
+/*
+ 
*--
+ *
+ * vmci_initialized_lock
+ *
+ * Returns whether a lock has been initialized.
+ *
+ * Results:
+ * Return 1 if initialized or 0 if unininitialized.
+ *
+ * Side effects:
+ * None
+ *
+ 
*--
+ */
+
+int
+vmci_initialized_lock(vmci_lock *lock)
+{
+
+   return mtx_initialized(lock);
+}
+
 /*
  
*--
  *
@@ -446,6 +470,28 @@ vmci_mutex_release(vmci_mutex *mutex)
mtx_unlock(mutex);
 }
 
+/*
+ 
*--
+ *
+ * vmci_mutex_initialized
+ *
+ * Returns whether a mutex has been initialized.
+ *
+ * Results:
+ * Return 1 if initialized or 0 if unininitialized.
+ *
+ * Side effects:
+ * None
+ *
+ 
*--
+ */
+
+int
+vmci_mutex_initialized(vmci_mutex *mutex)
+{
+
+   return mtx_initialized(mutex);
+}
 /*
  
*--
  *
diff --git a/sys/dev/vmware/vmci/vmci_kernel_if.h 
b/sys/dev/vmware/vmci/vmci_kernel_if.h
index fc23eefe98e0..048e480b0698 100644
--- a/sys/dev/vmware/vmci/vmci_kernel_if.h
+++ b/sys/dev/vmware/vmci/vmci_kernel_if.h
@@ -48,6 +48,7 @@ void  vmci_grab_lock(vmci_lock *lock);
 void   vmci_release_lock(vmci_lock *lock);
 void   vmci_grab_lock_bh(vmci_lock *lock);
 void   vmci_release_lock_bh(vmci_lock *lock);
+intvmci_initialized_lock(vmci_lock *lock);
 
 void   *vmci_alloc_kernel_mem(size_t size, int flags);
 v

git: 4e5c1be4202a - stable/13 - vmci: fix panic due to freeing unallocated resources

2021-10-16 Thread Mark Peek
The branch stable/13 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4e5c1be4202a141b7a15c505848abcbea535912f

commit 4e5c1be4202a141b7a15c505848abcbea535912f
Author: Mark Peek 
AuthorDate: 2021-10-09 21:21:16 +
Commit: Mark Peek 
CommitDate: 2021-10-16 18:22:43 +

vmci: fix panic due to freeing unallocated resources

Summary:
An error mapping PCI resources results in a panic due to unallocated
resources being freed up. This change puts the appropriate checks in
place to prevent the panic.

PR: 252445
Reported by:Marek Zarychta 
Tested by:  marcus
MFC after:  1 week
Sponsored by:   VMware

Test Plan:
Along with user testing, also simulated error by inserting a ENXIO
return in vmci_map_bars().

Reviewed by:marcus
Subscribers:imp
Differential Revision: https://reviews.freebsd.org/D32016

(cherry picked from commit 0f14bcbe384091c729464cb770372aeb79061070)
---
 sys/dev/vmware/vmci/vmci.c|  9 ---
 sys/dev/vmware/vmci/vmci_event.c  |  3 +++
 sys/dev/vmware/vmci/vmci_kernel_if.c  | 48 ++-
 sys/dev/vmware/vmci/vmci_kernel_if.h  |  2 ++
 sys/dev/vmware/vmci/vmci_queue_pair.c |  3 +++
 5 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/sys/dev/vmware/vmci/vmci.c b/sys/dev/vmware/vmci/vmci.c
index bbf17bbe7e41..8adcb7f532b7 100644
--- a/sys/dev/vmware/vmci/vmci.c
+++ b/sys/dev/vmware/vmci/vmci.c
@@ -242,8 +242,10 @@ vmci_detach(device_t dev)
 
vmci_components_cleanup();
 
-   taskqueue_drain(taskqueue_thread, &sc->vmci_delayed_work_task);
-   mtx_destroy(&sc->vmci_delayed_work_lock);
+   if mtx_initialized(&sc->vmci_spinlock) {
+   taskqueue_drain(taskqueue_thread, &sc->vmci_delayed_work_task);
+   mtx_destroy(&sc->vmci_delayed_work_lock);
+   }
 
if (sc->vmci_res0 != NULL)
bus_space_write_4(sc->vmci_iot0, sc->vmci_ioh0,
@@ -254,7 +256,8 @@ vmci_detach(device_t dev)
 
vmci_unmap_bars(sc);
 
-   mtx_destroy(&sc->vmci_spinlock);
+   if mtx_initialized(&sc->vmci_spinlock)
+   mtx_destroy(&sc->vmci_spinlock);
 
pci_disable_busmaster(dev);
 
diff --git a/sys/dev/vmware/vmci/vmci_event.c b/sys/dev/vmware/vmci/vmci_event.c
index 7f3bf9039e12..192828cc6f6a 100644
--- a/sys/dev/vmware/vmci/vmci_event.c
+++ b/sys/dev/vmware/vmci/vmci_event.c
@@ -593,6 +593,9 @@ vmci_event_unregister_subscription(vmci_id sub_id)
 {
struct vmci_subscription *s;
 
+   if (!vmci_initialized_lock(&subscriber_lock))
+   return NULL;
+
vmci_grab_lock_bh(&subscriber_lock);
s = vmci_event_find(sub_id);
if (s != NULL) {
diff --git a/sys/dev/vmware/vmci/vmci_kernel_if.c 
b/sys/dev/vmware/vmci/vmci_kernel_if.c
index e845650873b5..de54a8d1ca4f 100644
--- a/sys/dev/vmware/vmci/vmci_kernel_if.c
+++ b/sys/dev/vmware/vmci/vmci_kernel_if.c
@@ -70,7 +70,8 @@ void
 vmci_cleanup_lock(vmci_lock *lock)
 {
 
-   mtx_destroy(lock);
+   if mtx_initialized(lock)
+   mtx_destroy(lock);
 }
 
 /*
@@ -165,6 +166,29 @@ vmci_release_lock_bh(vmci_lock *lock)
mtx_unlock(lock);
 }
 
+/*
+ 
*--
+ *
+ * vmci_initialized_lock
+ *
+ * Returns whether a lock has been initialized.
+ *
+ * Results:
+ * Return 1 if initialized or 0 if unininitialized.
+ *
+ * Side effects:
+ * None
+ *
+ 
*--
+ */
+
+int
+vmci_initialized_lock(vmci_lock *lock)
+{
+
+   return mtx_initialized(lock);
+}
+
 /*
  
*--
  *
@@ -446,6 +470,28 @@ vmci_mutex_release(vmci_mutex *mutex)
mtx_unlock(mutex);
 }
 
+/*
+ 
*--
+ *
+ * vmci_mutex_initialized
+ *
+ * Returns whether a mutex has been initialized.
+ *
+ * Results:
+ * Return 1 if initialized or 0 if unininitialized.
+ *
+ * Side effects:
+ * None
+ *
+ 
*--
+ */
+
+int
+vmci_mutex_initialized(vmci_mutex *mutex)
+{
+
+   return mtx_initialized(mutex);
+}
 /*
  
*--
  *
diff --git a/sys/dev/vmware/vmci/vmci_kernel_if.h 
b/sys/dev/vmware/vmci/vmci_kernel_if.h
index fc23eefe98e0..048e480b0698 100644
--- a/sys/dev/vmware/vmci/vmci_kernel_if.h
+++ b/sys/dev/vmware/vmci/vmci_kernel_if.h
@@ -48,6 +48,7 @@ void  vmci_grab_lock(vmci_lock *lock);
 void   vmci_release_lock(vmci_lock *lock);
 void   vmci_grab_lock_bh(vmci_lock *lock);
 void   vmci_release_lock_bh(vmci_lock *lock);
+intvmci_initialized

git: b5d236785dc3 - stable/12 - vmci: fix panic due to freeing unallocated resources

2021-10-17 Thread Mark Peek
The branch stable/12 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=b5d236785dc352a65bc29d97c8a89b40387eb7a0

commit b5d236785dc352a65bc29d97c8a89b40387eb7a0
Author: Mark Peek 
AuthorDate: 2021-10-09 21:21:16 +
Commit: Mark Peek 
CommitDate: 2021-10-17 15:31:53 +

vmci: fix panic due to freeing unallocated resources

Summary:
An error mapping PCI resources results in a panic due to unallocated
resources being freed up. This change puts the appropriate checks in
place to prevent the panic.

PR: 252445
Reported by:Marek Zarychta 
Tested by:  marcus
MFC after:  1 week
Sponsored by:   VMware

Test Plan:
Along with user testing, also simulated error by inserting a ENXIO
return in vmci_map_bars().

Reviewed by:marcus
Subscribers:imp
Differential Revision: https://reviews.freebsd.org/D32016

(cherry picked from commit 0f14bcbe384091c729464cb770372aeb79061070)
---
 sys/dev/vmware/vmci/vmci.c|  9 ---
 sys/dev/vmware/vmci/vmci_event.c  |  3 +++
 sys/dev/vmware/vmci/vmci_kernel_if.c  | 48 ++-
 sys/dev/vmware/vmci/vmci_kernel_if.h  |  2 ++
 sys/dev/vmware/vmci/vmci_queue_pair.c |  3 +++
 5 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/sys/dev/vmware/vmci/vmci.c b/sys/dev/vmware/vmci/vmci.c
index 3f195231d8e2..9d0cbbdef67c 100644
--- a/sys/dev/vmware/vmci/vmci.c
+++ b/sys/dev/vmware/vmci/vmci.c
@@ -242,8 +242,10 @@ vmci_detach(device_t dev)
 
vmci_components_cleanup();
 
-   taskqueue_drain(taskqueue_thread, &sc->vmci_delayed_work_task);
-   mtx_destroy(&sc->vmci_delayed_work_lock);
+   if mtx_initialized(&sc->vmci_spinlock) {
+   taskqueue_drain(taskqueue_thread, &sc->vmci_delayed_work_task);
+   mtx_destroy(&sc->vmci_delayed_work_lock);
+   }
 
if (sc->vmci_res0 != NULL)
bus_space_write_4(sc->vmci_iot0, sc->vmci_ioh0,
@@ -254,7 +256,8 @@ vmci_detach(device_t dev)
 
vmci_unmap_bars(sc);
 
-   mtx_destroy(&sc->vmci_spinlock);
+   if mtx_initialized(&sc->vmci_spinlock)
+   mtx_destroy(&sc->vmci_spinlock);
 
pci_disable_busmaster(dev);
 
diff --git a/sys/dev/vmware/vmci/vmci_event.c b/sys/dev/vmware/vmci/vmci_event.c
index 9a932340a7b6..c34ff113978b 100644
--- a/sys/dev/vmware/vmci/vmci_event.c
+++ b/sys/dev/vmware/vmci/vmci_event.c
@@ -594,6 +594,9 @@ vmci_event_unregister_subscription(vmci_id sub_id)
 {
struct vmci_subscription *s;
 
+   if (!vmci_initialized_lock(&subscriber_lock))
+   return NULL;
+
vmci_grab_lock_bh(&subscriber_lock);
s = vmci_event_find(sub_id);
if (s != NULL) {
diff --git a/sys/dev/vmware/vmci/vmci_kernel_if.c 
b/sys/dev/vmware/vmci/vmci_kernel_if.c
index 851c4c9df214..a550277500aa 100644
--- a/sys/dev/vmware/vmci/vmci_kernel_if.c
+++ b/sys/dev/vmware/vmci/vmci_kernel_if.c
@@ -70,7 +70,8 @@ void
 vmci_cleanup_lock(vmci_lock *lock)
 {
 
-   mtx_destroy(lock);
+   if mtx_initialized(lock)
+   mtx_destroy(lock);
 }
 
 /*
@@ -165,6 +166,29 @@ vmci_release_lock_bh(vmci_lock *lock)
mtx_unlock(lock);
 }
 
+/*
+ 
*--
+ *
+ * vmci_initialized_lock
+ *
+ * Returns whether a lock has been initialized.
+ *
+ * Results:
+ * Return 1 if initialized or 0 if unininitialized.
+ *
+ * Side effects:
+ * None
+ *
+ 
*--
+ */
+
+int
+vmci_initialized_lock(vmci_lock *lock)
+{
+
+   return mtx_initialized(lock);
+}
+
 /*
  
*--
  *
@@ -446,6 +470,28 @@ vmci_mutex_release(vmci_mutex *mutex)
mtx_unlock(mutex);
 }
 
+/*
+ 
*--
+ *
+ * vmci_mutex_initialized
+ *
+ * Returns whether a mutex has been initialized.
+ *
+ * Results:
+ * Return 1 if initialized or 0 if unininitialized.
+ *
+ * Side effects:
+ * None
+ *
+ 
*--
+ */
+
+int
+vmci_mutex_initialized(vmci_mutex *mutex)
+{
+
+   return mtx_initialized(mutex);
+}
 /*
  
*--
  *
diff --git a/sys/dev/vmware/vmci/vmci_kernel_if.h 
b/sys/dev/vmware/vmci/vmci_kernel_if.h
index fc23eefe98e0..048e480b0698 100644
--- a/sys/dev/vmware/vmci/vmci_kernel_if.h
+++ b/sys/dev/vmware/vmci/vmci_kernel_if.h
@@ -48,6 +48,7 @@ void  vmci_grab_lock(vmci_lock *lock);
 void   vmci_release_lock(vmci_lock *lock);
 void   vmci_grab_lock_bh(vmci_lock *lock);
 void   vmci_release_lock_bh(vmci_lock *lock);
+intvmci_initialized

git: dda0f9837b1c - main - bhyve: support noVNC SetPixelFormat request

2024-09-09 Thread Mark Peek
The branch main has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=dda0f9837b1c4049079aeaefb35076aef5f06a6c

commit dda0f9837b1c4049079aeaefb35076aef5f06a6c
Author: Mark Peek 
AuthorDate: 2024-09-09 17:21:17 +
Commit: Mark Peek 
CommitDate: 2024-09-09 17:21:17 +

bhyve: support noVNC SetPixelFormat request

The bhyve VNC server would ignore the SetPixelFormat message from the
VNC client. This change supports a limited implementation to detect
and reorder the colors such as requested from the noVNC client.

PR: 280984
Reviewed by:corvink
Differential Revision:  https://reviews.freebsd.org/D46402
MFC after:  3 weeks
---
 usr.sbin/bhyve/rfb.c | 143 ---
 1 file changed, 136 insertions(+), 7 deletions(-)

diff --git a/usr.sbin/bhyve/rfb.c b/usr.sbin/bhyve/rfb.c
index bb989a33f484..6af374a83bbe 100644
--- a/usr.sbin/bhyve/rfb.c
+++ b/usr.sbin/bhyve/rfb.c
@@ -103,6 +103,13 @@ static int rfb_debug = 0;
 #define AUTH_FAILED_UNAUTH 1
 #define AUTH_FAILED_ERROR  2
 
+struct pixfmt {
+   booladjust_pixels;
+   uint8_t red_shift;
+   uint8_t green_shift;
+   uint8_t blue_shift;
+};
+
 struct rfb_softc {
int sfd;
pthread_t   tid;
@@ -131,14 +138,20 @@ struct rfb_softc {
atomic_bool pending;
atomic_bool update_all;
atomic_bool input_detected;
+   atomic_bool update_pixfmt;
 
pthread_mutex_t mtx;
+   pthread_mutex_t pixfmt_mtx;
pthread_cond_t  cond;
 
int hw_crc;
uint32_t*crc;   /* WxH crc cells */
uint32_t*crc_tmp;   /* buffer to store single crc row */
int crc_width, crc_height;
+
+   struct pixfmt   pixfmt; /* owned by the write thread */
+   struct pixfmt   new_pixfmt; /* managed with pixfmt_mtx */
+   uint32_t*pixrow;
 };
 
 struct rfb_pixfmt {
@@ -179,6 +192,10 @@ struct rfb_pixfmt_msg {
 #defineRFB_MAX_HEIGHT  1200
 #defineRFB_ZLIB_BUFSZ  RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
 
+#define PIXEL_RED_SHIFT16
+#define PIXEL_GREEN_SHIFT  8
+#define PIXEL_BLUE_SHIFT   0
+
 /* percentage changes to screen before sending the entire screen */
 #defineRFB_SEND_ALL_THRESH 25
 
@@ -261,9 +278,9 @@ rfb_send_server_init_msg(int cfd)
sinfo.pixfmt.red_max = htons(255);
sinfo.pixfmt.green_max = htons(255);
sinfo.pixfmt.blue_max = htons(255);
-   sinfo.pixfmt.red_shift = 16;
-   sinfo.pixfmt.green_shift = 8;
-   sinfo.pixfmt.blue_shift = 0;
+   sinfo.pixfmt.red_shift = PIXEL_RED_SHIFT;
+   sinfo.pixfmt.green_shift = PIXEL_GREEN_SHIFT;
+   sinfo.pixfmt.blue_shift = PIXEL_BLUE_SHIFT;
sinfo.pixfmt.pad[0] = 0;
sinfo.pixfmt.pad[1] = 0;
sinfo.pixfmt.pad[2] = 0;
@@ -318,9 +335,67 @@ static void
 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc __unused, int cfd)
 {
struct rfb_pixfmt_msg pixfmt_msg;
+   uint8_t red_shift, green_shift, blue_shift;
+   uint16_t red_max, green_max, blue_max;
+   bool adjust_pixels = true;
 
(void)stream_read(cfd, (uint8_t *)&pixfmt_msg + 1,
sizeof(pixfmt_msg) - 1);
+
+   /*
+* The framebuffer is fixed at 32 bit and orders the colors
+* as RGB bytes. However, some VNC clients request a different
+* ordering. We will still require the same bit depth and size
+* but allow the colors to be shifted when sent to the client.
+*/
+   if (pixfmt_msg.pixfmt.bpp != 32 || pixfmt_msg.pixfmt.truecolor != 1) {
+   WPRINTF(("rfb: pixfmt unsupported bitdepth bpp: %d "
+"truecolor: %d",
+pixfmt_msg.pixfmt.bpp, pixfmt_msg.pixfmt.truecolor));
+   return;
+   }
+
+   red_max = ntohs(pixfmt_msg.pixfmt.red_max);
+   green_max = ntohs(pixfmt_msg.pixfmt.green_max);
+   blue_max = ntohs(pixfmt_msg.pixfmt.blue_max);
+
+   /* Check for valid max values */
+   if (red_max != 255 || green_max != 255 || blue_max != 255) {
+   WPRINTF(("rfb: pixfmt unsupported max values "
+"r: %d g: %d b: %d",
+red_max, green_max, blue_max));
+   return;
+   }
+
+   red_shift = pixfmt_msg.pixfmt.red_shift;
+   green_shift = pixfmt_msg.pixfmt.green_shift;
+   blue_shift = pixfmt_msg.pixfmt.blue_shift;
+
+   /* Check shifts are 8 bit aligned */
+   if ((red_shift & 0x7) != 0 ||
+   (green_shift & 0x7) != 0 ||
+   (blue_shift & 0x7) != 0) {
+   WPRINTF(("rfb: pixfmt unsupported shift values "
+"r: %d g:

git: 63a7c4be4ad5 - main - hyperv/hn: Don't return error when setting media to autoselect

2024-03-13 Thread Mark Peek
The branch main has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=63a7c4be4ad524629292eee659d6542f1c5e9c21

commit 63a7c4be4ad524629292eee659d6542f1c5e9c21
Author: Mark Peek 
AuthorDate: 2024-03-13 23:53:07 +
Commit: Mark Peek 
CommitDate: 2024-03-14 00:05:19 +

hyperv/hn: Don't return error when setting media to autoselect

Setting media to autoselect would always return EOPNOTSUPP.
As autoselect is the only valid media, this change now returns
success instead.

PR: 264253
Reported by:Prakash Shiva 
Reviewed by:Dexuan Cui , whu
Approved by:whu
MFC after:  2 weeks
---
 sys/dev/hyperv/netvsc/if_hn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/hyperv/netvsc/if_hn.c b/sys/dev/hyperv/netvsc/if_hn.c
index 9949e0a16ab1..9f51f5b32199 100644
--- a/sys/dev/hyperv/netvsc/if_hn.c
+++ b/sys/dev/hyperv/netvsc/if_hn.c
@@ -1103,7 +1103,8 @@ static int
 hn_ifmedia_upd(if_t ifp __unused)
 {
 
-   return EOPNOTSUPP;
+   /* Ignore since autoselect is the only defined and valid media */
+   return (0);
 }
 
 static void



git: 65904399db91 - main - efibootmgr: allow -u as a valid option

2024-03-24 Thread Mark Peek
The branch main has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=65904399db9167b0970e42e14642e1d6bdbf6d3a

commit 65904399db9167b0970e42e14642e1d6bdbf6d3a
Author: Mark Peek 
AuthorDate: 2024-03-24 19:37:12 +
Commit: Mark Peek 
CommitDate: 2024-03-24 19:37:12 +

efibootmgr: allow -u as a valid option

PR: 277907
Reported by:vsasja...@gmail.com
MFC after:  1 week
---
 usr.sbin/efibootmgr/efibootmgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c
index 2bc79ee26f51..b919130d9c11 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -204,8 +204,8 @@ parse_args(int argc, char *argv[])
int ch;
const char *arg;
 
-   while ((ch = getopt_long(argc, argv, "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:v",
-   lopts, NULL)) != -1) {
+   while ((ch = getopt_long(argc, argv,
+   "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:u:v", lopts, NULL)) != -1) {
switch (ch) {
case 'A':
opts.set_inactive = true;



Re: git: 65904399db91 - main - efibootmgr: allow -u as a valid option

2024-03-25 Thread Mark Peek
On Mon, Mar 25, 2024 at 2:01 AM Gary Jennejohn  wrote:

> On Sun, 24 Mar 2024 19:39:49 GMT
> Mark Peek  wrote:
>
> > The branch main has been updated by mp:
> >
> > URL:
> https://cgit.FreeBSD.org/src/commit/?id=65904399db9167b0970e42e14642e1d6bdbf6d3a
> >
> > commit 65904399db9167b0970e42e14642e1d6bdbf6d3a
> > Author: Mark Peek 
> > AuthorDate: 2024-03-24 19:37:12 +
> > Commit: Mark Peek 
> > CommitDate: 2024-03-24 19:37:12 +
> >
> > efibootmgr: allow -u as a valid option
> >
> > PR: 277907
> > Reported by:vsasja...@gmail.com
> > MFC after:  1 week
> > ---
> >  usr.sbin/efibootmgr/efibootmgr.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/usr.sbin/efibootmgr/efibootmgr.c
> b/usr.sbin/efibootmgr/efibootmgr.c
> > index 2bc79ee26f51..b919130d9c11 100644
> > --- a/usr.sbin/efibootmgr/efibootmgr.c
> > +++ b/usr.sbin/efibootmgr/efibootmgr.c
> > @@ -204,8 +204,8 @@ parse_args(int argc, char *argv[])
> >   int ch;
> >   const char *arg;
> >
> > - while ((ch = getopt_long(argc, argv,
> "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:v",
> > - lopts, NULL)) != -1) {
> > + while ((ch = getopt_long(argc, argv,
> > + "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:u:v", lopts, NULL)) != -1) {
> >   switch (ch) {
> >   case 'A':
> >   opts.set_inactive = true;
> >
>
> -u is not documented in the man page for efibootmgr, although it was
> already in the source.
>
> --
> Gary Jennejohn
>

Gary,
I'm not sure I understand your comment. The man page was updated for -u in
this commit:
https://github.com/freebsd/freebsd-src/commit/9a7915299484a767fbffc7234b8dc45c29954cca

And man shows this as:
 efibootmgr -u unix-path
 ...
 -u --efidev unix-path
 Displays the UEFI device path of unix-path.

Mark


git: a1f89082dcb5 - stable/14 - hyperv/hn: Don't return error when setting media to autoselect

2024-03-31 Thread Mark Peek
The branch stable/14 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a1f89082dcb591886acc22c5503a2d5a82b267d9

commit a1f89082dcb591886acc22c5503a2d5a82b267d9
Author: Mark Peek 
AuthorDate: 2024-03-13 23:53:07 +
Commit: Mark Peek 
CommitDate: 2024-03-31 16:51:02 +

hyperv/hn: Don't return error when setting media to autoselect

Setting media to autoselect would always return EOPNOTSUPP.
As autoselect is the only valid media, this change now returns
success instead.

PR: 264253
Reported by:Prakash Shiva 
Reviewed by:Dexuan Cui , whu
Approved by:whu
MFC after:  2 weeks

(cherry picked from commit 63a7c4be4ad524629292eee659d6542f1c5e9c21)
---
 sys/dev/hyperv/netvsc/if_hn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/hyperv/netvsc/if_hn.c b/sys/dev/hyperv/netvsc/if_hn.c
index 6e1c9771a02d..41be4226e592 100644
--- a/sys/dev/hyperv/netvsc/if_hn.c
+++ b/sys/dev/hyperv/netvsc/if_hn.c
@@ -1103,7 +1103,8 @@ static int
 hn_ifmedia_upd(if_t ifp __unused)
 {
 
-   return EOPNOTSUPP;
+   /* Ignore since autoselect is the only defined and valid media */
+   return (0);
 }
 
 static void



git: a26e93052a38 - stable/13 - hyperv/hn: Don't return error when setting media to autoselect

2024-03-31 Thread Mark Peek
The branch stable/13 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a26e93052a3897bb55301954dff7e40547d7f291

commit a26e93052a3897bb55301954dff7e40547d7f291
Author: Mark Peek 
AuthorDate: 2024-03-13 23:53:07 +
Commit: Mark Peek 
CommitDate: 2024-03-31 16:49:01 +

hyperv/hn: Don't return error when setting media to autoselect

Setting media to autoselect would always return EOPNOTSUPP.
As autoselect is the only valid media, this change now returns
success instead.

PR: 264253
Reported by:Prakash Shiva 
Reviewed by:Dexuan Cui , whu
Approved by:whu
MFC after:  2 weeks

(cherry picked from commit 63a7c4be4ad524629292eee659d6542f1c5e9c21)
---
 sys/dev/hyperv/netvsc/if_hn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/hyperv/netvsc/if_hn.c b/sys/dev/hyperv/netvsc/if_hn.c
index a18f608e1aab..dc90f7b0dd22 100644
--- a/sys/dev/hyperv/netvsc/if_hn.c
+++ b/sys/dev/hyperv/netvsc/if_hn.c
@@ -,7 +,8 @@ static int
 hn_ifmedia_upd(struct ifnet *ifp __unused)
 {
 
-   return EOPNOTSUPP;
+   /* Ignore since autoselect is the only defined and valid media */
+   return (0);
 }
 
 static void



git: 811bd332abdd - stable/14 - efibootmgr: allow -u as a valid option

2024-03-31 Thread Mark Peek
The branch stable/14 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=811bd332abddf44a2f410fd04a6a61849d1b736a

commit 811bd332abddf44a2f410fd04a6a61849d1b736a
Author: Mark Peek 
AuthorDate: 2024-03-24 19:37:12 +
Commit: Mark Peek 
CommitDate: 2024-03-31 16:58:45 +

efibootmgr: allow -u as a valid option

PR: 277907
Reported by:vsasja...@gmail.com
MFC after:  1 week

(cherry picked from commit 65904399db9167b0970e42e14642e1d6bdbf6d3a)
---
 usr.sbin/efibootmgr/efibootmgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c
index be1157b4aa84..dfe8bfb1c145 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -203,8 +203,8 @@ parse_args(int argc, char *argv[])
 {
int ch;
 
-   while ((ch = getopt_long(argc, argv, "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:v",
-   lopts, NULL)) != -1) {
+   while ((ch = getopt_long(argc, argv,
+   "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:u:v", lopts, NULL)) != -1) {
switch (ch) {
case 'A':
opts.set_inactive = true;



git: 14b2221ae7ce - stable/13 - efibootmgr: allow -u as a valid option

2024-03-31 Thread Mark Peek
The branch stable/13 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=14b2221ae7cee33b5b75d662da6a396ca5c46f95

commit 14b2221ae7cee33b5b75d662da6a396ca5c46f95
Author: Mark Peek 
AuthorDate: 2024-03-24 19:37:12 +
Commit: Mark Peek 
CommitDate: 2024-03-31 16:57:17 +

efibootmgr: allow -u as a valid option

PR: 277907
Reported by:vsasja...@gmail.com
MFC after:  1 week

(cherry picked from commit 65904399db9167b0970e42e14642e1d6bdbf6d3a)
---
 usr.sbin/efibootmgr/efibootmgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c
index be1157b4aa84..dfe8bfb1c145 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -203,8 +203,8 @@ parse_args(int argc, char *argv[])
 {
int ch;
 
-   while ((ch = getopt_long(argc, argv, "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:v",
-   lopts, NULL)) != -1) {
+   while ((ch = getopt_long(argc, argv,
+   "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:u:v", lopts, NULL)) != -1) {
switch (ch) {
case 'A':
opts.set_inactive = true;



git: f9e09dc5b1d5 - stable/14 - bhyve: support noVNC SetPixelFormat request

2024-10-31 Thread Mark Peek
The branch stable/14 has been updated by mp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f9e09dc5b1d593a239d170a975ff60114030b471

commit f9e09dc5b1d593a239d170a975ff60114030b471
Author: Mark Peek 
AuthorDate: 2024-09-09 17:21:17 +
Commit: Mark Peek 
CommitDate: 2024-10-31 14:41:17 +

bhyve: support noVNC SetPixelFormat request

The bhyve VNC server would ignore the SetPixelFormat message from the
VNC client. This change supports a limited implementation to detect
and reorder the colors such as requested from the noVNC client.

PR: 280984
Reviewed by:corvink
Differential Revision:  https://reviews.freebsd.org/D46402
MFC after:  3 weeks

(cherry picked from commit dda0f9837b1c4049079aeaefb35076aef5f06a6c)
---
 usr.sbin/bhyve/rfb.c | 143 ---
 1 file changed, 136 insertions(+), 7 deletions(-)

diff --git a/usr.sbin/bhyve/rfb.c b/usr.sbin/bhyve/rfb.c
index db2924fee453..4e9f52ed4700 100644
--- a/usr.sbin/bhyve/rfb.c
+++ b/usr.sbin/bhyve/rfb.c
@@ -104,6 +104,13 @@ static int rfb_debug = 0;
 #define AUTH_FAILED_UNAUTH 1
 #define AUTH_FAILED_ERROR  2
 
+struct pixfmt {
+   booladjust_pixels;
+   uint8_t red_shift;
+   uint8_t green_shift;
+   uint8_t blue_shift;
+};
+
 struct rfb_softc {
int sfd;
pthread_t   tid;
@@ -132,14 +139,20 @@ struct rfb_softc {
atomic_bool pending;
atomic_bool update_all;
atomic_bool input_detected;
+   atomic_bool update_pixfmt;
 
pthread_mutex_t mtx;
+   pthread_mutex_t pixfmt_mtx;
pthread_cond_t  cond;
 
int hw_crc;
uint32_t*crc;   /* WxH crc cells */
uint32_t*crc_tmp;   /* buffer to store single crc row */
int crc_width, crc_height;
+
+   struct pixfmt   pixfmt; /* owned by the write thread */
+   struct pixfmt   new_pixfmt; /* managed with pixfmt_mtx */
+   uint32_t*pixrow;
 };
 
 struct rfb_pixfmt {
@@ -180,6 +193,10 @@ struct rfb_pixfmt_msg {
 #defineRFB_MAX_HEIGHT  1200
 #defineRFB_ZLIB_BUFSZ  RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
 
+#define PIXEL_RED_SHIFT16
+#define PIXEL_GREEN_SHIFT  8
+#define PIXEL_BLUE_SHIFT   0
+
 /* percentage changes to screen before sending the entire screen */
 #defineRFB_SEND_ALL_THRESH 25
 
@@ -262,9 +279,9 @@ rfb_send_server_init_msg(int cfd)
sinfo.pixfmt.red_max = htons(255);
sinfo.pixfmt.green_max = htons(255);
sinfo.pixfmt.blue_max = htons(255);
-   sinfo.pixfmt.red_shift = 16;
-   sinfo.pixfmt.green_shift = 8;
-   sinfo.pixfmt.blue_shift = 0;
+   sinfo.pixfmt.red_shift = PIXEL_RED_SHIFT;
+   sinfo.pixfmt.green_shift = PIXEL_GREEN_SHIFT;
+   sinfo.pixfmt.blue_shift = PIXEL_BLUE_SHIFT;
sinfo.pixfmt.pad[0] = 0;
sinfo.pixfmt.pad[1] = 0;
sinfo.pixfmt.pad[2] = 0;
@@ -319,9 +336,67 @@ static void
 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc __unused, int cfd)
 {
struct rfb_pixfmt_msg pixfmt_msg;
+   uint8_t red_shift, green_shift, blue_shift;
+   uint16_t red_max, green_max, blue_max;
+   bool adjust_pixels = true;
 
(void)stream_read(cfd, (uint8_t *)&pixfmt_msg + 1,
sizeof(pixfmt_msg) - 1);
+
+   /*
+* The framebuffer is fixed at 32 bit and orders the colors
+* as RGB bytes. However, some VNC clients request a different
+* ordering. We will still require the same bit depth and size
+* but allow the colors to be shifted when sent to the client.
+*/
+   if (pixfmt_msg.pixfmt.bpp != 32 || pixfmt_msg.pixfmt.truecolor != 1) {
+   WPRINTF(("rfb: pixfmt unsupported bitdepth bpp: %d "
+"truecolor: %d",
+pixfmt_msg.pixfmt.bpp, pixfmt_msg.pixfmt.truecolor));
+   return;
+   }
+
+   red_max = ntohs(pixfmt_msg.pixfmt.red_max);
+   green_max = ntohs(pixfmt_msg.pixfmt.green_max);
+   blue_max = ntohs(pixfmt_msg.pixfmt.blue_max);
+
+   /* Check for valid max values */
+   if (red_max != 255 || green_max != 255 || blue_max != 255) {
+   WPRINTF(("rfb: pixfmt unsupported max values "
+"r: %d g: %d b: %d",
+red_max, green_max, blue_max));
+   return;
+   }
+
+   red_shift = pixfmt_msg.pixfmt.red_shift;
+   green_shift = pixfmt_msg.pixfmt.green_shift;
+   blue_shift = pixfmt_msg.pixfmt.blue_shift;
+
+   /* Check shifts are 8 bit aligned */
+   if ((red_shift & 0x7) != 0 ||
+   (green_shift & 0x7) != 0 ||
+   (blue_shift & 0x7) != 0) {
+