git: bc6d5725ed6c - main - emulators/virtualbox-ose-kmod*: Tie to a specific release branch.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 10 May 2022 20:50:04 UTC
The branch main has been updated by jhb (doc, src committer):

URL: https://cgit.FreeBSD.org/ports/commit/?id=bc6d5725ed6c7b6538da70328d89afe901736a90

commit bc6d5725ed6c7b6538da70328d89afe901736a90
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-05-10 20:48:31 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-10 20:48:31 +0000

    emulators/virtualbox-ose-kmod*: Tie to a specific release branch.
    
    Use a more restricted range of supported __FreeBSD_version values for
    the virtualbox kernel module since it uses internal KPIs for which KBI
    stability is not guaranteed.  DECLARE_MODULE_TIED would tie the module
    to a specific __FreeBSD_version which would cause the module to stop
    loading when an SA or EN is pushed on a release branch.  Instead, use
    DECLARE_MODULE_MAXVER with an upper bound that is limited to the range
    of a releng branch so that a module built on X.Y will load on X.Y with
    SAs or ENs applied but will fail to load on X.Y-1 or X.Y+1.
    
    Reviewed by:    kevans, imp, madpilot, lwhsu (earlier version)
    Differential Revision:  https://reviews.freebsd.org/D16119
---
 emulators/virtualbox-ose-kmod-legacy/Makefile      |  3 ++
 .../files/pkg-message.in                           | 10 +++++++
 emulators/virtualbox-ose-kmod/Makefile             |  4 +++
 emulators/virtualbox-ose-kmod/files/pkg-message.in | 10 +++++++
 ...ox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c | 32 ++++++++++++++--------
 ...ox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c | 28 +++++++++++++------
 6 files changed, 67 insertions(+), 20 deletions(-)

diff --git a/emulators/virtualbox-ose-kmod-legacy/Makefile b/emulators/virtualbox-ose-kmod-legacy/Makefile
index 06b78180fb46..dedde4502e84 100644
--- a/emulators/virtualbox-ose-kmod-legacy/Makefile
+++ b/emulators/virtualbox-ose-kmod-legacy/Makefile
@@ -19,6 +19,9 @@ BUILD_DEPENDS=	kmk:devel/kBuild
 CPE_VENDOR=	oracle
 CPE_PRODUCT=	vm_virtualbox
 
+SUB_FILES=	pkg-message
+SUB_LIST=	OPSYS=${OPSYS} OSREL=${OSREL}
+
 USES=		cpe kmod tar:bzip2
 PATCHDIR=	${.CURDIR}/../${PORTNAME}-legacy/files
 WRKSRC=		${WRKDIR}/VirtualBox-${PORTVERSION}
diff --git a/emulators/virtualbox-ose-kmod-legacy/files/pkg-message.in b/emulators/virtualbox-ose-kmod-legacy/files/pkg-message.in
new file mode 100644
index 000000000000..4e03cc0b5ec7
--- /dev/null
+++ b/emulators/virtualbox-ose-kmod-legacy/files/pkg-message.in
@@ -0,0 +1,10 @@
+[
+{ type: install
+  message: <<EOM
+The vboxdrv kernel module uses internal kernel APIs.
+
+To avoid crashes due to kernel incompatibility, this module will only
+load on %%OPSYS%% %%OSREL%% kernels.
+EOM
+}
+]
diff --git a/emulators/virtualbox-ose-kmod/Makefile b/emulators/virtualbox-ose-kmod/Makefile
index 9db98ebbbc31..702ebefd075c 100644
--- a/emulators/virtualbox-ose-kmod/Makefile
+++ b/emulators/virtualbox-ose-kmod/Makefile
@@ -2,6 +2,7 @@
 
 PORTNAME=	virtualbox-ose
 PORTVERSION=	6.1.34
+PORTREVISION=	1
 CATEGORIES=	emulators
 MASTER_SITES=	https://download.virtualbox.org/virtualbox/${PORTVERSION}/
 PKGNAMESUFFIX=	-kmod
@@ -18,6 +19,9 @@ BUILD_DEPENDS=	kmk:devel/kBuild
 CPE_VENDOR=	oracle
 CPE_PRODUCT=	vm_virtualbox
 
+SUB_FILES=	pkg-message
+SUB_LIST=	OPSYS=${OPSYS} OSREL=${OSREL}
+
 USES=		cpe compiler:c++14-lang kmod tar:bzip2
 PATCHDIR=	${.CURDIR}/../${PORTNAME}/files
 WRKSRC=		${WRKDIR}/VirtualBox-${PORTVERSION}
diff --git a/emulators/virtualbox-ose-kmod/files/pkg-message.in b/emulators/virtualbox-ose-kmod/files/pkg-message.in
new file mode 100644
index 000000000000..4e03cc0b5ec7
--- /dev/null
+++ b/emulators/virtualbox-ose-kmod/files/pkg-message.in
@@ -0,0 +1,10 @@
+[
+{ type: install
+  message: <<EOM
+The vboxdrv kernel module uses internal kernel APIs.
+
+To avoid crashes due to kernel incompatibility, this module will only
+load on %%OPSYS%% %%OSREL%% kernels.
+EOM
+}
+]
diff --git a/emulators/virtualbox-ose-legacy/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c b/emulators/virtualbox-ose-legacy/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
index 63e8769ce7c2..d3e36a79d745 100644
--- a/emulators/virtualbox-ose-legacy/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
+++ b/emulators/virtualbox-ose-legacy/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
@@ -1,5 +1,5 @@
---- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig	2020-05-13 19:43:53 UTC
-+++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
+--- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig	2020-07-09 09:57:00.000000000 -0700
++++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c	2021-11-19 15:10:40.470972000 -0800
 @@ -46,6 +46,7 @@
  #include <sys/uio.h>
  
@@ -33,7 +33,17 @@
  
  
  /*********************************************************************************************************************************
-@@ -182,6 +192,13 @@ static int VBoxDrvFreeBSDLoad(void)
+@@ -93,7 +103,8 @@ static moduledata_t         g_VBoxDrvFreeBSDModule =
+ };
+ 
+ /** Declare the module as a pseudo device. */
+-DECLARE_MODULE(vboxdrv,     g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
++#define	KERNEL_RELBRANCHEND	(roundup(__FreeBSD_version, 500) - 1)
++DECLARE_MODULE_WITH_MAXVER(vboxdrv,     g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY, KERNEL_RELBRANCHEND);
+ MODULE_VERSION(vboxdrv, 1);
+ 
+ /**
+@@ -182,6 +193,13 @@ static int VBoxDrvFreeBSDLoad(void)
          rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION));
          if (RT_SUCCESS(rc))
          {
@@ -47,7 +57,7 @@
              /*
               * Configure character devices. Add symbolic links for compatibility.
               */
-@@ -311,7 +328,21 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
+@@ -311,7 +329,21 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
      PSUPDRVSESSION pSession;
      devfs_get_cdevpriv((void **)&pSession);
  
@@ -69,7 +79,7 @@
       * Deal with the fast ioctl path first.
       */
      if (   (   ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
-@@ -325,6 +356,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
+@@ -325,6 +357,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
  
  
  /**
@@ -115,7 +125,7 @@
   * Deal with the 'slow' I/O control requests.
   *
   * @returns 0 on success, appropriate errno on failure.
-@@ -373,11 +443,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+@@ -373,11 +444,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
           */
          SUPREQHDR Hdr;
          pvUser = *(void **)pvData;
@@ -130,7 +140,7 @@
          }
          if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
          {
-@@ -402,13 +471,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+@@ -402,13 +472,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
              OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd));
              return ENOMEM;
          }
@@ -148,7 +158,7 @@
          }
          if (Hdr.cbIn < cbReq)
              RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
-@@ -436,9 +504,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+@@ -436,9 +505,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
                  OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd));
                  cbOut = cbReq;
              }
@@ -160,7 +170,7 @@
  
              Log(("VBoxDrvFreeBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd));
  
-@@ -541,8 +608,7 @@ bool VBOXCALL  supdrvOSGetForcedAsyncTscMode(PSUPDRVDE
+@@ -541,8 +609,7 @@ bool VBOXCALL  supdrvOSGetForcedAsyncTscMode(PSUPDRVDE
  
  bool VBOXCALL  supdrvOSAreCpusOfflinedOnSuspend(void)
  {
@@ -170,7 +180,7 @@
  }
  
  
-@@ -625,11 +691,25 @@ int VBOXCALL    supdrvOSMsrProberModify(RTCPUID idCpu,
+@@ -625,11 +692,25 @@ int VBOXCALL    supdrvOSMsrProberModify(RTCPUID idCpu,
  #endif /* SUPDRV_WITH_MSR_PROBER */
  
  
@@ -196,7 +206,7 @@
  
      va_start(va, pszFormat);
      cch = RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, va);
-@@ -637,12 +717,19 @@ SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
+@@ -637,12 +718,19 @@ SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
  
      printf("%s", szMsg);
  
diff --git a/emulators/virtualbox-ose/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c b/emulators/virtualbox-ose/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
index fb3a4470d560..2e2c292d7ee8 100644
--- a/emulators/virtualbox-ose/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
+++ b/emulators/virtualbox-ose/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
@@ -1,5 +1,5 @@
---- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig	2021-10-18 17:58:03 UTC
-+++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
+--- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig	2021-10-18 10:58:03.000000000 -0700
++++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c	2021-11-19 15:31:33.152269000 -0800
 @@ -44,8 +44,10 @@
  #include <sys/fcntl.h>
  #include <sys/conf.h>
@@ -36,7 +36,17 @@
  
  
  /*********************************************************************************************************************************
-@@ -182,6 +193,13 @@ static int VBoxDrvFreeBSDLoad(void)
+@@ -93,7 +104,8 @@ static moduledata_t         g_VBoxDrvFreeBSDModule =
+ };
+ 
+ /** Declare the module as a pseudo device. */
+-DECLARE_MODULE(vboxdrv,     g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
++#define	KERNEL_RELBRANCHEND	(roundup(__FreeBSD_version, 500) - 1)
++DECLARE_MODULE_WITH_MAXVER(vboxdrv,     g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY, KERNEL_RELBRANCHEND);
+ MODULE_VERSION(vboxdrv, 1);
+ 
+ /**
+@@ -182,6 +194,13 @@ static int VBoxDrvFreeBSDLoad(void)
          rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION));
          if (RT_SUCCESS(rc))
          {
@@ -50,7 +60,7 @@
              /*
               * Configure character devices. Add symbolic links for compatibility.
               */
-@@ -324,6 +342,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
+@@ -324,6 +343,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
  
  
  /**
@@ -96,7 +106,7 @@
   * Deal with the 'slow' I/O control requests.
   *
   * @returns 0 on success, appropriate errno on failure.
-@@ -372,11 +429,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+@@ -372,11 +430,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
           */
          SUPREQHDR Hdr;
          pvUser = *(void **)pvData;
@@ -111,7 +121,7 @@
          }
          if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
          {
-@@ -401,13 +457,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+@@ -401,13 +458,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
              OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd));
              return ENOMEM;
          }
@@ -129,7 +139,7 @@
          }
          if (Hdr.cbIn < cbReq)
              RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
-@@ -435,9 +490,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+@@ -435,9 +491,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
                  OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd));
                  cbOut = cbReq;
              }
@@ -141,7 +151,7 @@
  
              Log(("VBoxDrvFreeBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd));
  
-@@ -540,8 +594,7 @@ bool VBOXCALL  supdrvOSGetForcedAsyncTscMode(PSUPDRVDE
+@@ -540,8 +595,7 @@ bool VBOXCALL  supdrvOSGetForcedAsyncTscMode(PSUPDRVDE
  
  bool VBOXCALL  supdrvOSAreCpusOfflinedOnSuspend(void)
  {
@@ -151,7 +161,7 @@
  }
  
  
-@@ -624,19 +677,43 @@ int VBOXCALL    supdrvOSMsrProberModify(RTCPUID idCpu,
+@@ -624,19 +678,43 @@ int VBOXCALL    supdrvOSMsrProberModify(RTCPUID idCpu,
  #endif /* SUPDRV_WITH_MSR_PROBER */