From patchwork Mon Feb 17 14:34:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Morgan Arnold X-Patchwork-Id: 38780 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5032027BBEA; Mon, 17 Feb 2025 14:36:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7680527BBE2 for ; Mon, 17 Feb 2025 14:36:23 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tk2ED-0007Um-Ar; Mon, 17 Feb 2025 09:36:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tk2E7-0007Tv-BI for guix-patches@gnu.org; Mon, 17 Feb 2025 09:36:05 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tk2E6-00037b-Mo for guix-patches@gnu.org; Mon, 17 Feb 2025 09:36:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:From:Date:To:In-Reply-To:References:Subject; bh=m0DrksV4UMimhWHwf1Dqc7dogmkQrhluY9l5siVBdTI=; b=Qea7e1wuBYbYIozXdKpE2QnY4GvLZK80dkKdXvdhNp9koz2/7uMZvuhcxGm6tBTG1uf7/vCpYWMdN4aBZRkuKSF/ZHIWyOjgNhvDRxOtyy7CZ0M1/vV7b7GST/FdH45pPoRbSCGA3yo/BSRedPoaHQhyBqWj9667gHrMkm6T5aWM9BgXV8TlLDJ3CK4SGhI/yDehvwlDxF1do80aqaVA6tSCheKnQFDtl9WT1rkGy5Xcyd1iKgWHqGyy8Ocw9iXENJWqPqZlxkGw6rV+DxiuHrdb5JGBsnBfaFqFI+wOFdozRV7MGm7duAk8C5uRsSe9qi8BoM6mI59nnOqNA7RISw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tk2E6-0001aj-Et for guix-patches@gnu.org; Mon, 17 Feb 2025 09:36:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#55231] [PATCH v7 1/4] Allow copying of out-of-tree modules to the Linux initrd. References: <87wnf3pv87.fsf@ditto.jhoto.spork.org> In-Reply-To: <87wnf3pv87.fsf@ditto.jhoto.spork.org> Resent-From: Morgan Arnold Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 14:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55231 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55231@debbugs.gnu.org Cc: Maxim Cournoyer , Brian Cully Received: via spool by 55231-submit@debbugs.gnu.org id=B55231.17398029145914 (code B ref 55231); Mon, 17 Feb 2025 14:36:02 +0000 Received: (at 55231) by debbugs.gnu.org; 17 Feb 2025 14:35:14 +0000 Received: from localhost ([127.0.0.1]:45003 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tk2DI-0001XD-E3 for submit@debbugs.gnu.org; Mon, 17 Feb 2025 09:35:13 -0500 Received: from mail-4322.protonmail.ch ([185.70.43.22]:36973) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tk2DD-0001QV-BV for 55231@debbugs.gnu.org; Mon, 17 Feb 2025 09:35:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=6ojnzcdkr5fxrkuaqdocsg5vxm.protonmail; t=1739802898; x=1740062098; bh=m0DrksV4UMimhWHwf1Dqc7dogmkQrhluY9l5siVBdTI=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=BBRzogF5yKJystxh1wXsqETpF9b3WuX5D021ZHc/W/ImhTKka6NYfEsQGtjui1lFk 8NfPjzIu6VruO1VU9WWUYftAaKS0VcXKC3sYF81isnFv/VkrkHM/FV4TuX+d0It8JL giUR1l6wE1P/ovlCEkBWL5I11wWZ+ZCBm081N/RJ7xO5BRyUXT68rAv5uXhuQLT7l7 gP3XzGmxtE7bEmuzbN5zHYhCGusnPMgmvENSNb8DzU+zV1YwPeWz8BWypGy7Tc18x8 SmDl94wQ7XjMJkR0VbE/G2x4JG13nJu4d8OJsa+281S0pc9ntHKCvHiU6v6QCqB7Qv pRTa20crzRaOQ== Date: Mon, 17 Feb 2025 14:34:52 +0000 Message-ID: Feedback-ID: 45510636:user:proton X-Pm-Message-ID: ffa7461925d3790da96d5b088cc6199c3c095dd3 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Morgan Arnold X-ACL-Warn: , Morgan Arnold via Guix-patches X-Patchwork-Original-From: Morgan Arnold via Guix-patches via From: Morgan Arnold Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Brian Cully With this patch, modules for ‘initrd-modules’ will not only be searched for in the in-tree Linux modules, but also any additional modules specified in ‘kernel-loadable-modules’. * gnu/build/linux-modules.scm (find-module-file): Change DIRECTORY argument to DIRECTORIES. Now takes a list of directories to search, rather than a single one. * gnu/system/linux-initrd.scm (flat-linux-module-directory): change LINUX argument to PACKAGES. Now contains a list of file-like objects to search for modules. (raw-initrd): Add LINUX-EXTRA-MODULE-DIRECTORIES keyword argument. Pass it to (flat-linux-module-directory) along with the selected LINUX package. (base-initrd): Add LINUX-EXTRA-MODULE-DIRECTORIES keyword argument. Pass it to (raw-initrd). * gnu/system.scm (operating-system-initrd-file): Pass in operating system definition's kernel-loadable-modules into (make-initrd) as LINUX-EXTRA-MODULE-DIRECTORIES. * doc/guix.texi (Initial RAM Disk): Document how out-of-tree modules can be used. Change-Id: Ic39f2abcfabc3ec34a71acce840038396bf9c82e Signed-off-by: Maxim Cournoyer Modified-by: Maxim Cournoyer --- doc/guix.texi | 15 ++++++++++++ gnu/build/linux-modules.scm | 22 +++++++++++------ gnu/system.scm | 2 ++ gnu/system/linux-initrd.scm | 49 +++++++++++++++++++++++-------------- 4 files changed, 62 insertions(+), 26 deletions(-) base-commit: b30669e15d2e8c3d1b74b32f77e2095682aab4ca diff --git a/doc/guix.texi b/doc/guix.texi index ce78068..3c7ece7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -43346,6 +43346,21 @@ Initial RAM Disk (initrd-modules (cons "megaraid_sas" %base-initrd-modules))) @end lisp +If a module listed in @code{initrd-modules} is not included in the +Linux-libre kernel, then its location must be provided via the +@code{kernel-loadable-modules} list. + +As an example, if you need the driver for a Realtek RTL8821CE wireless +network adapter for mounting the root file system over NFS, your +configuration might include the following: + +@lisp +(operating-system + ;; @dots{} + (initrd-modules (cons "8821ce" %base-initrd-modules)) + (kernel-loadable-modules (list (list rtl8821ce-linux-module "module")))) +@end lisp + @defvar %base-initrd-modules This is the list of kernel modules included in the initrd by default. @end defvar diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 32baf6c..24bbe08 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -246,8 +246,8 @@ (define (file-name->module-name file) '.ko[.gz|.xz|.zst]' and normalizing it." (normalize-module-name (strip-extension (basename file)))) -(define (find-module-file directory module) - "Lookup module NAME under DIRECTORY, and return its absolute file name. +(define (find-module-file directories module) + "Lookup module NAME under DIRECTORIES, and return its absolute file name. NAME can be a file name with or without '.ko', or it can be a module name. Raise an error if it could not be found. @@ -255,6 +255,9 @@ (define (find-module-file directory module) module names usually (always?) use underscores as the inter-word separator, whereas file names often, but not always, use hyphens. Examples: \"usb-storage.ko\", \"serpent_generic.ko\"." + (define directories (if (pair? directories) + directories + (list directories))) ;for backward compatibility (define names ;; List of possible file names. XXX: It would of course be cleaner to ;; have a database that maps module names to file names and vice versa, @@ -268,16 +271,19 @@ (define (find-module-file directory module) (else chr))) module)))) - (match (find-files directory - (lambda (file stat) - (member (strip-extension - (basename file)) names))) + (match (append-map (lambda (directory) + (find-files directory + (lambda (file _) + (member (strip-extension + (basename file)) + names)))) + directories) ((file) file) (() - (error "kernel module not found" module directory)) + (error "kernel module not found" module directories)) ((_ ...) - (error "several modules by that name" module directory)))) + (error "several modules by that name" module directories)))) (define* (recursive-module-dependencies files #:key (lookup-module dot-ko)) diff --git a/gnu/system.scm b/gnu/system.scm index 8df871f..1921b60 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -1373,6 +1373,8 @@ (define (operating-system-initrd-file os) #:linux (operating-system-kernel os) #:linux-modules (operating-system-initrd-modules os) + #:linux-extra-module-directories + (operating-system-kernel-loadable-modules os) #:mapped-devices mapped-devices #:keyboard-layout (operating-system-keyboard-layout os))) diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index dc08edc..a8df905 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -120,13 +120,19 @@ (define* (expression->initrd exp `(#:references-graphs (("closure" ,init)))) "/initrd.cpio.gz")) -(define (flat-linux-module-directory linux modules) +(define (flat-linux-module-directory packages modules) "Return a flat directory containing the Linux kernel modules listed in -MODULES and taken from LINUX." +MODULES and taken from PACKAGES." (define imported-modules (source-module-closure '((gnu build linux-modules) (guix build utils)))) + (define package-inputs + (map (match-lambda + ((p o) (gexp-input p o)) + (p (gexp-input p "out"))) + packages)) + (define build-exp (with-imported-modules imported-modules (with-extensions (list guile-zlib guile-zstd) @@ -138,8 +144,9 @@ (define (flat-linux-module-directory linux modules) (srfi srfi-26) (ice-9 match)) - (define module-dir - (string-append #$linux "/lib/modules")) + (define module-dirs + (map (cut string-append <> "/lib/modules") + '#$package-inputs)) (define builtin-modules (match (find-files module-dir (lambda (file stat) @@ -157,7 +164,7 @@ (define (flat-linux-module-directory linux modules) (lset-difference string=? '#$modules builtin-modules)) (define modules - (let* ((lookup (cut find-module-file module-dir <>)) + (let* ((lookup (cut find-module-file module-dirs <>)) (modules (map lookup modules-to-lookup))) (append modules (recursive-module-dependencies @@ -192,6 +199,7 @@ (define* (raw-initrd file-systems #:key (linux linux-libre) (linux-modules '()) + (linux-extra-module-directories '()) (pre-mount #t) (mapped-devices '()) (keyboard-layout #f) @@ -199,15 +207,16 @@ (define* (raw-initrd file-systems qemu-networking? volatile-root? (on-error 'debug)) - "Return as a file-like object a raw initrd, with kernel -modules taken from LINUX. FILE-SYSTEMS is a list of file-systems to be -mounted by the initrd, possibly in addition to the root file system specified -on the kernel command line via 'root'. LINUX-MODULES is a list of kernel -modules to be loaded at boot time. MAPPED-DEVICES is a list of device -mappings to realize before FILE-SYSTEMS are mounted. PRE-MOUNT is a -G-expression to evaluate before realizing MAPPED-DEVICES. -HELPER-PACKAGES is a list of packages to be copied in the initrd. It may include -e2fsck/static or other packages needed by the initrd to check root partition. + "Return as a file-like object a raw initrd, with kernel modules taken from +LINUX. FILE-SYSTEMS is a list of file-systems to be mounted by the initrd, +possibly in addition to the root file system specified on the kernel command +line via 'root'. LINUX-MODULES is a list of kernel modules to be loaded at +boot time. LINUX-EXTRA-MODULE-DIRECTORIES is a list of file-like objects which +will be searched for modules in addition to the linux kernel. MAPPED-DEVICES +is a list of device mappings to realize before FILE-SYSTEMS are mounted. +HELPER-PACKAGES is a list of packages to be copied in the initrd. It may +include e2fsck/static or other packages needed by the initrd to check root +partition. When true, KEYBOARD-LAYOUT is a record denoting the desired console keyboard layout. This is done before MAPPED-DEVICES are set up and @@ -243,7 +252,8 @@ (define* (raw-initrd file-systems #~()))) (define kodir - (flat-linux-module-directory linux linux-modules)) + (flat-linux-module-directory (cons linux linux-extra-module-directories) + linux-modules)) (expression->initrd (with-imported-modules (source-module-closure @@ -390,6 +400,7 @@ (define* (base-initrd file-systems #:key (linux linux-libre) (linux-modules '()) + (linux-extra-module-directories '()) (mapped-devices '()) (keyboard-layout #f) qemu-networking? @@ -410,9 +421,10 @@ (define* (base-initrd file-systems QEMU-NETWORKING? and VOLATILE-ROOT? behaves as in raw-initrd. The initrd is automatically populated with all the kernel modules necessary -for FILE-SYSTEMS and for the given options. Additional kernel -modules can be listed in LINUX-MODULES. They will be added to the initrd, and -loaded at boot time in the order in which they appear." +for FILE-SYSTEMS and for the given options. Additional kernel modules can be +listed in LINUX-MODULES. Additional directories for modules can be listed in +LINUX-EXTRA-MODULE-DIRECTORIES. They will be added to the initrd, and loaded +at boot time in the order in which they appear." (define linux-modules* ;; Modules added to the initrd and loaded from the initrd. `(,@linux-modules @@ -432,6 +444,7 @@ (define* (base-initrd file-systems (raw-initrd file-systems #:linux linux #:linux-modules linux-modules* + #:linux-extra-module-directories linux-extra-module-directories #:mapped-devices mapped-devices #:helper-packages helper-packages #:keyboard-layout keyboard-layout