From owner-freebsd-hackers Thu Mar 6 0: 7:26 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B2B4F37B401 for ; Thu, 6 Mar 2003 00:07:24 -0800 (PST) Received: from cirb503493.alcatel.com.au (c18609.belrs1.nsw.optusnet.com.au [210.49.80.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id AEAC743F93 for ; Thu, 6 Mar 2003 00:07:22 -0800 (PST) (envelope-from peterjeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1]) by cirb503493.alcatel.com.au (8.12.5/8.12.5) with ESMTP id h2687LLZ093991; Thu, 6 Mar 2003 19:07:21 +1100 (EST) (envelope-from jeremyp@cirb503493.alcatel.com.au) Received: (from jeremyp@localhost) by cirb503493.alcatel.com.au (8.12.6/8.12.5/Submit) id h2687L7G093990; Thu, 6 Mar 2003 19:07:21 +1100 (EST) Date: Thu, 6 Mar 2003 19:07:21 +1100 From: Peter Jeremy To: Sean Kelly Cc: hackers@FreeBSD.ORG Subject: Re: Smarter kernel modules? Message-ID: <20030306080721.GA93885@cirb503493.alcatel.com.au> References: <20030305.215901.36360277.imp@bsdimp.com> <20030306074919.GA3045@edgemaster.zombie.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030306074919.GA3045@edgemaster.zombie.org> User-Agent: Mutt/1.4i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Mar 06, 2003 at 01:49:20AM -0600, Sean Kelly wrote: >> +/* >> + * Define the version. Change the symbol name when things get too >> + * incompatible. version_5_1 means the 'ABI compatible with FreeBSD 5.1' >> + */ >> +char __version_5_1 = 1; >... > >Wouldn't it make more sense to have a symbol name that doesn't change >across versions? Something like '_module_version' perhaps. Then the value >of the symbol is the version which the module corresponds to. This would >let you use something like kern.osreldate or a per-subsystem version index. No. Warner's trick is that each module includes an unresolved reference to the version symbol (in ), which is defined in the kernel. If the kernel run-time loader can't resolve the reference (meaning that the version symbol has changed in the kernel) then it will report and error and refuse to load the module - neither the kernel nor the module need to know anything about versioning. (Though the name needs to be kept aligned in two different files). The actual value of the symbol is irrelevant (though it could potentially be used to differentiate different mostly-compatible kernels). >config.h: >#define API_VERSION 500100 > >mymodule.c: >long _module_version = API_VERSION; And I presume the kernel then verifies that _module_version in the just-loaded .ko matches the kernel's idea of API_VERSION. Overall, this is equivalent to Warner's approach except that the kernel needs to explicitly check the contents of _module_version (and the loader needs to understand having identical symbols declared in multiple modules - ie _module_version becomes a special name). >Another benefit(?) is that if _module_version is missing, you can decide >that you don't care about versioning and just load the module. This exists implicitly in Warner's code as well - if there's no reference to the kernel version symbol then the load will succeed whatever the name of the version symbol in the kernel. Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message