GNU bug report logs - #69899
[PATCH 0/7] support to use `guix system vm' with riscv64.

Previous Next

Package: guix-patches;

Reported by: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>

Date: Tue, 19 Mar 2024 15:17:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 69899 in the body.
You can then email your comments to 69899 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zheng Junjie <zhengjunjie <at> iscas.ac.cn>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Tue, 19 Mar 2024 15:17:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: guix-patches <at> gnu.org
Subject: [PATCH 0/7] support to use `guix system vm' with riscv64.
Date: Tue, 19 Mar 2024 23:15:53 +0800
hello!. this patchset make `guix system vm --target=riscv64-linux-gnu' work.
and `guix system vm --system=riscv64-linux` also work, But there is a problem
that the qemu running with --system=riscv64-linux is also riscv architecture,
now you have to manually modify to use native qemu or the guix of qemu-system
on qemu-user is too slow. and must enable qemu-binfmt.

Zheng Junjie (7):
  bootloader: Add u-boot-qemu-riscv64-bootloader.
  vm: use #$ for kernel-arguments.
  vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader.
  gnu: linux-libre-riscv64-generic: add more options.
  linux-initrd: don't add hid-apple module for riscv64-linux.
  vm: add arguments to use virt machine type for qemu-riscv64.
  vm: If not the same local architecture, don't enable kvm.

 gnu/bootloader/u-boot.scm   | 15 ++++++++++++++
 gnu/packages/linux.scm      | 19 +++++++++++++++++-
 gnu/system/linux-initrd.scm |  5 ++++-
 gnu/system/vm.scm           | 40 ++++++++++++++++++++++++++-----------
 4 files changed, 65 insertions(+), 14 deletions(-)


base-commit: 83c5e7169d3bfa23a51225a8d809a435c1f2dd6b
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:20:02 GMT) Full text and rfc822 format available.

Message #8 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 2/7] vm: use #$ for kernel-arguments.
Date: Tue, 19 Mar 2024 23:18:36 +0800
Use #$ allow cross-compile to with support current system kernel.

e.g. linux-libre-riscv64-generic.

* gnu/system/vm.scm(system-qemu-image/shared-store-script)
(linux-image-startup-command): use #$ for kernel-arguments.

Change-Id: I9d2e7df296ce590b95cd30996b33f8ca692ac1b1
---
 gnu/system/vm.scm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index fcfd1cdb48..40e965d272 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe <at> gmail.com>
 ;;; Copyright © 2017 Marius Bakke <mbakke <at> fastmail.com>
 ;;; Copyright © 2018 Chris Marusich <cmmarusich <at> gmail.com>
+;;; Copyright © 2024 Zheng Junjie <873216071 <at> qq.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -270,7 +271,7 @@ (define* (system-qemu-image/shared-store-script os
                                         (volatile-root? volatile?)))))
     (define kernel-arguments
       #~(list #$@(if graphic? #~() #~("console=ttyS0"))
-              #+@(operating-system-kernel-arguments os "/dev/vda1")))
+              #$@(operating-system-kernel-arguments os "/dev/vda1")))
 
     (define rw-image
       #~(format #f "/tmp/guix-image-~a" (basename #$base-image)))
@@ -340,7 +341,7 @@ (define* (linux-image-startup-command image
 
   (define kernel-arguments
     #~(list #$@(if graphic? #~() #~("console=ttyS0"))
-            #+@(operating-system-kernel-arguments os "/dev/vda1")))
+            #$@(operating-system-kernel-arguments os "/dev/vda1")))
 
   #~`(#+(file-append qemu "/bin/"
                      (qemu-command (or target system)))
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:20:02 GMT) Full text and rfc822 format available.

Message #11 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 7/7] vm: If not the same local architecture, don't enable kvm.
Date: Tue, 19 Mar 2024 23:18:41 +0800
* gnu/system/vm.scm (common-qemu-options): Add target keyword.

Change-Id: Ic9bf18cf60ac5ce623289df31ea050a22c6e604e
---
 gnu/system/vm.scm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 64cc321ebf..7d9d07ebb7 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -210,7 +210,9 @@ (define* (virtualized-operating-system os
                        virtual-file-systems)))))
 
 (define* (common-qemu-options image shared-fs
-                              #:key rw-image?)
+                              #:key
+                              rw-image?
+                              (target (%current-target-system)))
   "Return the a string-value gexp with the common QEMU options to boot IMAGE,
 with '-virtfs' options for the host file systems listed in SHARED-FS."
 
@@ -221,7 +223,7 @@ (define* (common-qemu-options image shared-fs
   #~(;; Only enable kvm if we see /dev/kvm exists.
      ;; This allows users without hardware virtualization to still use these
      ;; commands.
-     #$@(if (file-exists? "/dev/kvm")
+     #$@(if (and (not target) (file-exists? "/dev/kvm"))
             '("-enable-kvm")
             '())
 
@@ -302,7 +304,8 @@ (define* (system-qemu-image/shared-store-script os
               #$@(common-qemu-options (if volatile? base-image rw-image)
                                       (map file-system-mapping-source
                                            (cons %store-mapping mappings))
-                                      #:rw-image? (not volatile?))
+                                      #:rw-image? (not volatile?)
+                                      #:target target)
               "-m " (number->string #$memory-size)
               #$@options))
 
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:26:02 GMT) Full text and rfc822 format available.

Message #14 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 5/7] linux-initrd: don't add hid-apple module for
 riscv64-linux.
Date: Tue, 19 Mar 2024 23:18:39 +0800
* gnu/system/linux-initrd.scm(default-initrd-modules): when target-riscv64,
don't add hid-apple module.

Change-Id: I633468421db0cb1ebd61e0603021fa1c79038473
---
 gnu/system/linux-initrd.scm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 6236d25b9d..f5d86219a8 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -363,7 +363,10 @@ (define* (default-initrd-modules
 
   `("ahci"                                  ;for SATA controllers
     "usb-storage" "uas"                     ;for the installation image etc.
-    "usbhid" "hid-generic" "hid-apple"      ;keyboards during early boot
+    "usbhid" "hid-generic"                  ;keyboards during early boot
+    ,@(if (target-riscv64? system)
+          '()
+          '("hid-apple"))
     "dm-crypt" "xts" "serpent_generic" "wp512" ;for encrypted root partitions
     "nls_iso8859-1"                            ;for `mkfs.fat`, et.al
     ,@(if (string-match "^(x86_64|i[3-6]86)-" system)
-- 
2.41.0





Information forwarded to leo <at> famulari.name, me <at> tobias.gr, w <at> wmeyer.eu, guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:26:02 GMT) Full text and rfc822 format available.

Message #17 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 4/7] gnu: linux-libre-riscv64-generic: add more options.
Date: Tue, 19 Mar 2024 23:18:38 +0800
This is required by `guix system vm'.

* gnu/packages/linux (linux-libre-riscv64-generic)[#:extra-options]: Add more
option.

Change-Id: I5697ba7158d44ef0ea9cf28cadb4d59f312b4206
---
 gnu/packages/linux.scm | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 343e8c1032..73b08fcf82 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -1312,7 +1312,24 @@ (define-public linux-libre-riscv64-generic
                      linux-libre-gnu-revision
                      linux-libre-source
                      '("riscv64-linux")
-                     #:extra-version "riscv64-generic"))
+                     #:extra-version "riscv64-generic"
+                     #:extra-options
+                     (append
+                      ;; required `guix system vm'
+                      `(("CONFIG_USB_HID" . m)
+                        ("CONFIG_HID_GEMBIRD" . m)
+                        ("CONFIG_AHCI_DWC" . m)
+                        ("CONFIG_SATA_AHCI" . m)
+                        ("CONFIG_CRYPTO_SERPENT" . m)
+                        ("CONFIG_CRYPTO_WP512" . m)
+                        ("CONFIG_USB_UAS" . m)
+                        ("CONFIG_USB_STORAGE" . m)
+                        ("CONFIG_HID_GENERIC" . m)
+                        ("CONFIG_DRM_CIRRUS_QEMU" . m)
+                        ("CONFIG_HW_RANDOM_VIRTIO" . m)
+                        ("CONFIG_VIRTIO_CONSOLE" . m)
+                        ("CONFIG_CRYPTO_XTS" . m))
+                      %default-extra-linux-options)))
 
 (define-public linux-libre-mips64el-fuloong2e
   (make-linux-libre* linux-libre-version
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:26:03 GMT) Full text and rfc822 format available.

Message #20 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 6/7] vm: add arguments to use virt machine type for
 qemu-riscv64.
Date: Tue, 19 Mar 2024 23:18:40 +0800
* gnu/system/vm.scm (system-qemu-image/shared-store-script): When target
riscv64, add arguments to set qemu virt machine type.

Change-Id: I974c82fdd2d5bfc01caff9e6411db38e472b5cd4
---
 gnu/system/vm.scm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index d4044a4a39..64cc321ebf 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -295,6 +295,10 @@ (define* (system-qemu-image/shared-store-script os
                         "-initrd" #$(file-append os "/initrd")
                         (format #f "-append ~s"
                                 (string-join #$kernel-arguments " "))))
+              ;; Default qemu-riscv64 have not PCI, virt have it, so we set it.
+              #$@(if (target-riscv64? (or target system))
+                     #~("-M" "virt")
+                     #~())
               #$@(common-qemu-options (if volatile? base-image rw-image)
                                       (map file-system-mapping-source
                                            (cons %store-mapping mappings))
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:26:03 GMT) Full text and rfc822 format available.

Message #23 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 3/7] vm: When target riscv64-linux,
 use u-boot-qemu-riscv64-bootloader.
Date: Tue, 19 Mar 2024 23:18:37 +0800
* gnu/system/vm.scm (virtualized-operating-system) When target riscv64-linux,
use u-boot-qemu-riscv64-bootloader. Add system, target keyword.

Change-Id: I22d64d00670a705e4b81427e44a83d504598b536
---
 gnu/system/vm.scm | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 40e965d272..d4044a4a39 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -52,6 +52,7 @@ (define-module (gnu system vm)
 
   #:use-module (gnu bootloader)
   #:use-module (gnu bootloader grub)
+  #:use-module (gnu bootloader u-boot)
   #:use-module (gnu image)
   #:use-module (gnu system image)
   #:use-module (gnu system linux-container)
@@ -137,7 +138,9 @@ (define (mapping->file-system mapping)
 
 (define* (virtualized-operating-system os
                                        #:optional (mappings '())
-                                       #:key (full-boot? #f) volatile?)
+                                       #:key (full-boot? #f) volatile?
+                                       (system (%current-system))
+                                       (target (%current-target-system)))
   "Return an operating system based on OS suitable for use in a virtualized
 environment with the store shared with the host.  MAPPINGS is a list of
 <file-system-mapping> to realize in the virtualized OS."
@@ -167,15 +170,18 @@ (define* (virtualized-operating-system os
           (append (map mapping->file-system mappings)
                   user-file-systems)))
 
-  (operating-system (inherit os)
-
+  (operating-system
+    (inherit os)
     ;; XXX: Until we run QEMU with UEFI support (with the OVMF firmware),
     ;; force the traditional i386/BIOS method.
     ;; See <https://bugs.gnu.org/28768>.
     (bootloader (bootloader-configuration
-                  (inherit (operating-system-bootloader os))
-                  (bootloader grub-bootloader)
-                  (targets '("/dev/vda"))))
+                 (inherit (operating-system-bootloader os))
+                 (bootloader
+                  (if (target-riscv64? (or target system))
+                      u-boot-qemu-riscv64-bootloader
+                      grub-bootloader))
+                 (targets '("/dev/vda"))))
 
     (initrd (lambda (file-systems . rest)
               (apply (operating-system-initrd os)
@@ -259,7 +265,9 @@ (define* (system-qemu-image/shared-store-script os
   (mlet* %store-monad ((os ->  (virtualized-operating-system
                                 os mappings
                                 #:full-boot? full-boot?
-                                #:volatile? volatile?))
+                                #:volatile? volatile?
+                                #:system system
+                                #:target target))
                        (base-image -> (system-image
                                        (image
                                         (inherit
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 19 Mar 2024 15:26:04 GMT) Full text and rfc822 format available.

Message #26 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader.
Date: Tue, 19 Mar 2024 23:18:35 +0800
* gnu/bootloader/u-boot.scm (u-boot-qemu-riscv64-bootloader): New variable.

Change-Id: If6622838d2250c90a26380849b92387aa7122fbb
---
 gnu/bootloader/u-boot.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index d20aabd538..8e7cc05191 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
 ;;; Copyright © 2023 Efraim Flashner <efraim <at> flashner.co.il>
 ;;; Copyright © 2023 Herman Rimm <herman_rimm <at> protonmail.com>
+;;; Copyright © 2024 Zheng Junjie <873216071 <at> qq.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -47,6 +48,7 @@ (define-module (gnu bootloader u-boot)
             u-boot-rock64-rk3328-bootloader
             u-boot-rockpro64-rk3399-bootloader
             u-boot-sifive-unmatched-bootloader
+            u-boot-qemu-riscv64-bootloader
             u-boot-ts7970-q-2g-1000mhz-c-bootloader
             u-boot-wandboard-bootloader))
 
@@ -157,6 +159,12 @@ (define install-sifive-unmatched-u-boot
         (write-file-on-device u-boot (stat:size (stat u-boot))
                               image (* 2082 512)))))
 
+(define install-qemu-riscv64-u-boot
+  #~(lambda (bootloader device mount-point)
+      (let ((u-boot.bin (string-append bootloader "/libexec/u-boot.bin"))
+            (install-dir (string-append mount-point "/boot")))
+        (install-file u-boot.bin install-dir))))
+
 
 
 ;;;
@@ -307,3 +315,10 @@ (define u-boot-sifive-unmatched-bootloader
    (inherit u-boot-bootloader)
    (package u-boot-sifive-unmatched)
    (disk-image-installer install-sifive-unmatched-u-boot)))
+
+(define u-boot-qemu-riscv64-bootloader
+  (bootloader
+   (inherit u-boot-bootloader)
+   (package u-boot-qemu-riscv64)
+   (installer install-qemu-riscv64-u-boot)
+   (disk-image-installer #f)))
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 26 Mar 2024 16:08:01 GMT) Full text and rfc822 format available.

Message #29 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
Cc: 69899 <at> debbugs.gnu.org
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Tue, 26 Mar 2024 12:07:46 -0400
Hi, thanks for these patches!

On Tue, Mar 19, 2024 at 11:15:53PM +0800, Zheng Junjie wrote:
> hello!. this patchset make `guix system vm --target=riscv64-linux-gnu' work.
> and `guix system vm --system=riscv64-linux` also work, But there is a problem
> that the qemu running with --system=riscv64-linux is also riscv architecture,
> now you have to manually modify to use native qemu or the guix of qemu-system
> on qemu-user is too slow. and must enable qemu-binfmt.

So, what should we do about the problem? What's the ideal solution for
Guix? I don't have any experience with this subject matter.




Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Wed, 27 Mar 2024 09:21:01 GMT) Full text and rfc822 format available.

Message #32 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: Leo Famulari <leo <at> famulari.name>
Cc: 69899 <at> debbugs.gnu.org
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Wed, 27 Mar 2024 17:15:26 +0800
[Message part 1 (text/plain, inline)]
Leo Famulari <leo <at> famulari.name> writes:

> Hi, thanks for these patches!
>
> On Tue, Mar 19, 2024 at 11:15:53PM +0800, Zheng Junjie wrote:
>> hello!. this patchset make `guix system vm --target=riscv64-linux-gnu' work.
>> and `guix system vm --system=riscv64-linux` also work, But there is a problem
>> that the qemu running with --system=riscv64-linux is also riscv architecture,
>> now you have to manually modify to use native qemu or the guix of qemu-system
>> on qemu-user is too slow. and must enable qemu-binfmt.
>
> So, what should we do about the problem? What's the ideal solution for
> Guix? I don't have any experience with this subject matter.

I've come up with two ideas:

1. Force the current system's qemu to be used, on x86_64 and -s
riscv64-linux, use x86_64's qemu.
2. add an environment variable, GUIX_QEMU, to allow the internal qemu
execution to be replaced

There may be other solutions, but I can't think of them yet.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Sun, 31 Mar 2024 21:04:01 GMT) Full text and rfc822 format available.

Message #35 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
Cc: 69899 <at> debbugs.gnu.org, Leo Famulari <leo <at> famulari.name>
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Sun, 31 Mar 2024 23:02:54 +0200
[Message part 1 (text/plain, inline)]
Hi,

Zheng Junjie <zhengjunjie <at> iscas.ac.cn> skribis:

> Leo Famulari <leo <at> famulari.name> writes:
>
>> Hi, thanks for these patches!
>>
>> On Tue, Mar 19, 2024 at 11:15:53PM +0800, Zheng Junjie wrote:
>>> hello!. this patchset make `guix system vm --target=riscv64-linux-gnu' work.
>>> and `guix system vm --system=riscv64-linux` also work, But there is a problem
>>> that the qemu running with --system=riscv64-linux is also riscv architecture,
>>> now you have to manually modify to use native qemu or the guix of qemu-system
>>> on qemu-user is too slow. and must enable qemu-binfmt.
>>
>> So, what should we do about the problem? What's the ideal solution for
>> Guix? I don't have any experience with this subject matter.
>
> I've come up with two ideas:
>
> 1. Force the current system's qemu to be used, on x86_64 and -s
> riscv64-linux, use x86_64's qemu.
> 2. add an environment variable, GUIX_QEMU, to allow the internal qemu
> execution to be replaced
>
> There may be other solutions, but I can't think of them yet.

Thing is, ‘--system=X’ is supposed to be giving the exact same result as
if you were building natively on X.  Thus, it’s not surprising that
‘guix system vm --system=X’ gives on a QEMU binary built for X.

Now, it’s admittedly not very useful in this case.  I believe the
attached patch implements #1 (I wasn’t able to test it yet because too
many things had to be built).  How does it sound?

[Message part 2 (text/x-patch, inline)]
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 7d9d07ebb7..a2743453e7 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -287,8 +287,11 @@ (define* (system-qemu-image/shared-store-script os
       #~(format #f "/tmp/guix-image-~a" (basename #$base-image)))
 
     (define qemu-exec
-      #~(list #+(file-append qemu "/bin/"
-                             (qemu-command (or target system)))
+      #~(list #+(with-parameters ((%current-system %system)
+                                  (%current-target-system #f))
+                  ;; Override %CURRENT-SYSTEM to always use a native emulator.
+                  (file-append qemu "/bin/"
+                               (qemu-command (or target system))))
               ;; Tells qemu to use the terminal it was started in for IO.
               #$@(if graphic? '() #~("-nographic"))
               #$@(if full-boot?
[Message part 3 (text/plain, inline)]
Thanks,
Ludo’.

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sun, 31 Mar 2024 21:04:02 GMT) Full text and rfc822 format available.

Notification sent to Zheng Junjie <zhengjunjie <at> iscas.ac.cn>:
bug acknowledged by developer. (Sun, 31 Mar 2024 21:04:02 GMT) Full text and rfc822 format available.

Message #40 received at 69899-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
Cc: 69899-done <at> debbugs.gnu.org
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Sun, 31 Mar 2024 23:03:20 +0200
Hi,

Zheng Junjie <zhengjunjie <at> iscas.ac.cn> skribis:

>   bootloader: Add u-boot-qemu-riscv64-bootloader.
>   vm: use #$ for kernel-arguments.
>   vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader.
>   gnu: linux-libre-riscv64-generic: add more options.
>   linux-initrd: don't add hid-apple module for riscv64-linux.
>   vm: add arguments to use virt machine type for qemu-riscv64.
>   vm: If not the same local architecture, don't enable kvm.

Applied, thanks!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 02 Apr 2024 15:42:02 GMT) Full text and rfc822 format available.

Message #43 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 69899 <at> debbugs.gnu.org, Leo Famulari <leo <at> famulari.name>
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Tue, 02 Apr 2024 01:20:12 +0800
[Message part 1 (text/plain, inline)]
Ludovic Courtès <ludo <at> gnu.org> writes:

> Hi,
>
> Zheng Junjie <zhengjunjie <at> iscas.ac.cn> skribis:
>
>> Leo Famulari <leo <at> famulari.name> writes:
>>
>>> Hi, thanks for these patches!
>>>
>>> On Tue, Mar 19, 2024 at 11:15:53PM +0800, Zheng Junjie wrote:
>>>> hello!. this patchset make `guix system vm --target=riscv64-linux-gnu' work.
>>>> and `guix system vm --system=riscv64-linux` also work, But there is a problem
>>>> that the qemu running with --system=riscv64-linux is also riscv architecture,
>>>> now you have to manually modify to use native qemu or the guix of qemu-system
>>>> on qemu-user is too slow. and must enable qemu-binfmt.
>>>
>>> So, what should we do about the problem? What's the ideal solution for
>>> Guix? I don't have any experience with this subject matter.
>>
>> I've come up with two ideas:
>>
>> 1. Force the current system's qemu to be used, on x86_64 and -s
>> riscv64-linux, use x86_64's qemu.
>> 2. add an environment variable, GUIX_QEMU, to allow the internal qemu
>> execution to be replaced
>>
>> There may be other solutions, but I can't think of them yet.
>
> Thing is, ‘--system=X’ is supposed to be giving the exact same result as
> if you were building natively on X.  Thus, it’s not surprising that
> ‘guix system vm --system=X’ gives on a QEMU binary built for X.
>
> Now, it’s admittedly not very useful in this case.  I believe the
> attached patch implements #1 (I wasn’t able to test it yet because too
> many things had to be built).  How does it sound?

it works, and the following patch is required.

[0001-vm-Don-t-add-enable-kvm-when-SYSTEM-and-system-are-n.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]

And maybe shebang interpreter also need override %CURRENT-SYSTEM?[1]
Even though when the Shebang interpreter cannot execute, the file will
be interpreted and executed by the current shell.

>
> diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
> index 7d9d07ebb7..a2743453e7 100644
> --- a/gnu/system/vm.scm
> +++ b/gnu/system/vm.scm
> @@ -287,8 +287,11 @@ (define* (system-qemu-image/shared-store-script os
>        #~(format #f "/tmp/guix-image-~a" (basename #$base-image)))
>  
>      (define qemu-exec
> -      #~(list #+(file-append qemu "/bin/"
> -                             (qemu-command (or target system)))
> +      #~(list #+(with-parameters ((%current-system %system)
> +                                  (%current-target-system #f))
> +                  ;; Override %CURRENT-SYSTEM to always use a native emulator.
> +                  (file-append qemu "/bin/"
> +                               (qemu-command (or target system))))
>                ;; Tells qemu to use the terminal it was started in for IO.
>                #$@(if graphic? '() #~("-nographic"))
>                #$@(if full-boot?
>
>
> Thanks,
> Ludo’.

[1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/system/vm.scm?h=9e9ec741d0dc5ce58f8d21d31800ff2cafce128f#n328
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Wed, 03 Apr 2024 22:43:02 GMT) Full text and rfc822 format available.

Message #46 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
Cc: 69899 <at> debbugs.gnu.org, Ludovic Courtès <ludo <at> gnu.org>
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Wed, 3 Apr 2024 18:42:06 -0400
[Message part 1 (text/plain, inline)]
On Tue, Apr 02, 2024 at 01:20:12AM +0800, Zheng Junjie wrote:
> it works, and the following patch is required.

Great! Does this mean you can send a ready-to-build v2 patch series
including these additions?
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Mon, 15 Apr 2024 15:35:03 GMT) Full text and rfc822 format available.

Message #49 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native
 emulator.
Date: Mon, 15 Apr 2024 23:33:37 +0800
From: Ludovic Courtès <ludo <at> gnu.org>

* gnu/system/vm.scm (system-qemu-image/shared-store-script): override
%CURRENT-SYSTEM to always use a native emulator.

Change-Id: Ia2cb7cca33eec018d810bd00d0208b58392ea483
---
 gnu/system/vm.scm | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 7d9d07ebb7..2d1a4a9df1 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -287,8 +287,11 @@ (define* (system-qemu-image/shared-store-script os
       #~(format #f "/tmp/guix-image-~a" (basename #$base-image)))
 
     (define qemu-exec
-      #~(list #+(file-append qemu "/bin/"
-                             (qemu-command (or target system)))
+      #~(list #+(with-parameters ((%current-system %system)
+                                  (%current-target-system #f))
+                  ;; Override %CURRENT-SYSTEM to always use a native emulator.
+                  (file-append qemu "/bin/"
+                               (qemu-command (or target system))))
               ;; Tells qemu to use the terminal it was started in for IO.
               #$@(if graphic? '() #~("-nographic"))
               #$@(if full-boot?
@@ -325,7 +328,9 @@ (define* (system-qemu-image/shared-store-script os
       #~(call-with-output-file #$output
           (lambda (port)
             (format port "#!~a~%"
-                    #+(file-append bash "/bin/sh"))
+                    #+(with-parameters ((%current-system %system)
+                                        (%current-target-system #f))
+                        (file-append bash "/bin/sh")))
             #$@(if volatile?
                    #~()
                    #~((format port "~a~%" #+copy-image)))

base-commit: 6b3c90f638292f9604a221ac6dbf22234f6e4c4b
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Mon, 15 Apr 2024 15:35:05 GMT) Full text and rfc822 format available.

Message #52 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
To: 69899 <at> debbugs.gnu.org
Subject: [PATCH 2/2] vm: Don't add -enable-kvm when SYSTEM and %system are not
 same.
Date: Mon, 15 Apr 2024 23:33:38 +0800
* gnu/system/vm.scm (common-qemu-options): Don't add -enable-kvm when SYSTEM
and %system are not same.

Change-Id: Ie6c602b297c39423a693fdc26bed1627266e5911
---
 gnu/system/vm.scm | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 2d1a4a9df1..b7ee5f8d42 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -212,7 +212,8 @@ (define* (virtualized-operating-system os
 (define* (common-qemu-options image shared-fs
                               #:key
                               rw-image?
-                              (target (%current-target-system)))
+                              (target (%current-target-system))
+                              (system (%current-system)))
   "Return the a string-value gexp with the common QEMU options to boot IMAGE,
 with '-virtfs' options for the host file systems listed in SHARED-FS."
 
@@ -223,7 +224,9 @@ (define* (common-qemu-options image shared-fs
   #~(;; Only enable kvm if we see /dev/kvm exists.
      ;; This allows users without hardware virtualization to still use these
      ;; commands.
-     #$@(if (and (not target) (file-exists? "/dev/kvm"))
+     #$@(if (and (not target)
+                 (string=? system %system)
+                 (file-exists? "/dev/kvm"))
             '("-enable-kvm")
             '())
 
@@ -308,7 +311,8 @@ (define* (system-qemu-image/shared-store-script os
                                       (map file-system-mapping-source
                                            (cons %store-mapping mappings))
                                       #:rw-image? (not volatile?)
-                                      #:target target)
+                                      #:target target
+                                      #:system system)
               "-m " (number->string #$memory-size)
               #$@options))
 
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#69899; Package guix-patches. (Tue, 16 Apr 2024 17:06:02 GMT) Full text and rfc822 format available.

Message #55 received at 69899 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
Cc: 69899 <at> debbugs.gnu.org, Leo Famulari <leo <at> famulari.name>
Subject: Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with
 riscv64.
Date: Tue, 16 Apr 2024 19:04:41 +0200
Zheng Junjie <zhengjunjie <at> iscas.ac.cn> skribis:

> Ludovic Courtès <ludo <at> gnu.org> writes:

[...]

>> Thing is, ‘--system=X’ is supposed to be giving the exact same result as
>> if you were building natively on X.  Thus, it’s not surprising that
>> ‘guix system vm --system=X’ gives on a QEMU binary built for X.
>>
>> Now, it’s admittedly not very useful in this case.  I believe the
>> attached patch implements #1 (I wasn’t able to test it yet because too
>> many things had to be built).  How does it sound?
>
> it works,

Great, I’ll push it shortly.

> and the following patch is required.
>
> From e178de931859399abdd4bd3300b7ce7c5593a6e3 Mon Sep 17 00:00:00 2001
> Message-ID: <e178de931859399abdd4bd3300b7ce7c5593a6e3.1712026332.git.zhengjunjie <at> iscas.ac.cn>
> From: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>
> Date: Tue, 2 Apr 2024 00:59:54 +0800
> Subject: [PATCH] vm: Don't add -enable-kvm when SYSTEM and %system are not
>  same.
>
> * gnu/system/vm.scm (common-qemu-options): Don't add -enable-kvm when SYSTEM
> and %system are not same.
>
> Change-Id: Ie6c602b297c39423a693fdc26bed1627266e5911

[...]

> +     #$@(if (and (not target)
> +                 (string=? system %system)
> +                 (file-exists? "/dev/kvm"))

I’m afraid this is too simple: we still want KVM when emulating i686 on
x86_64, or armhf on aarch64.

Does it really hurt to pass ‘-enable-kvm’?  Can you think of another
way?

Thanks,
Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 15 May 2024 11:24:13 GMT) Full text and rfc822 format available.

This bug report was last modified 1 day ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.