From owner-freebsd-arch@FreeBSD.ORG Fri Feb 8 23:33:20 2008 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B007516A418 for ; Fri, 8 Feb 2008 23:33:20 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail.speedfactory.net [66.23.216.219]) by mx1.freebsd.org (Postfix) with ESMTP id 42B4E13C4CC for ; Fri, 8 Feb 2008 23:33:19 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.8s) with ESMTP id 231307513-1834499 for ; Fri, 08 Feb 2008 18:33:26 -0500 Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.14.2/8.14.2) with ESMTP id m18NXE2Y019247 for ; Fri, 8 Feb 2008 18:33:14 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: arch@freebsd.org Date: Fri, 8 Feb 2008 18:02:54 -0500 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802081802.54313.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Fri, 08 Feb 2008 18:33:14 -0500 (EST) X-Virus-Scanned: ClamAV 0.91.2/5744/Fri Feb 8 08:32:41 2008 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Subject: [PATCH] Automatic kernel version module dependencies.. X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Feb 2008 23:33:20 -0000 So one of the things that people run into periodically are problems with mismatched kernels and modules. My understanding of our kernel module ABI compatibility is that if you build a module on in a X.Y build environment the module should work fine for all kernels with version X.Z where Z >= Y. In concrete terms, a module built on a 6.2 system is not guaranteed to work on a 6.1 kernel, a 5.2 kernel, or a 7.0 kernel. However, it should work fine on 6.2, 6.3, etc. The patch below implements this policy by create a 'kernel' module version based on __FreeBSD_version. It then adds a version dependency on 'kernel' in every kernel module that requires a version range starting with the current __FreeBSD_version and ending with the maximum __FreeBSD_version value for the current branch. This does seem to work in that a kernel module compiled with artificial values of __FreeBSD_version refuses to load when it violates the rule above (too old or wrong branch). One thing this doesn't fix is that right now the error from the kernel linker is simply that "kernel could not be found" or some such. It might be nicer if the error could be "module requires kernel version X to Y, but only Z was found", but that would be a separate patch. --- //depot/vendor/freebsd/src/sys/kern/kern_module.c 2007/12/06 23:12:58 +++ //depot/user/jhb/acpipci/kern/kern_module.c 2008/02/07 18:59:28 @@ -414,6 +414,8 @@ return (error); } +MODULE_VERSION(kernel, __FreeBSD_version); + #ifdef COMPAT_IA32 #include #include --- //depot/vendor/freebsd/src/sys/sys/module.h 2006/04/17 19:46:13 +++ //depot/user/jhb/acpipci/sys/module.h 2008/02/07 22:11:55 @@ -114,7 +114,20 @@ MODULE_METADATA(_md_##module##_on_##mdepend, MDT_DEPEND, \ &_##module##_depend_on_##mdepend, #mdepend) +/* + * Every kernel has a 'kernel' module with the version set to + * __FreeBSD_version. We embed a MODULE_DEPEND() inside every module + * that depends on the 'kernel' module. It uses the current value of + * __FreeBSD_version as the minimum and preferred versions. For the + * maximum version it rounds the version up to the end of its branch + * (i.e. M99999 for M.x). This allows a module built on M.x to work + * on M.y systems where y >= x, but fail on M.z systems where z < x. + */ +#define MODULE_KERNEL_MAXVER (roundup(__FreeBSD_version, 100000) - 1) + #define DECLARE_MODULE(name, data, sub, order) \ + MODULE_DEPEND(name, kernel, __FreeBSD_version, \ + __FreeBSD_version, MODULE_KERNEL_MAXVER); \ MODULE_METADATA(_md_##name, MDT_MODULE, &data, #name); \ SYSINIT(name##module, sub, order, module_register_init, &data) \ struct __hack -- John Baldwin