[PATCH 0/7] support to use `guix system vm' with riscv64.

  • Done
  • quality assurance status badge
Details
3 participants
  • Leo Famulari
  • Ludovic Courtès
  • Zheng Junjie
Owner
unassigned
Submitted by
Zheng Junjie
Severity
normal

Debbugs page

Z
Z
Zheng Junjie wrote on 19 Mar 08:15 -0700
(address . guix-patches@gnu.org)
cover.1710861023.git.zhengjunjie@iscas.ac.cn
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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 2/7] vm: use #$ for kernel-arguments.
(address . 69899@debbugs.gnu.org)
384e20b4da664cd75a9e6f3be0b6fff8605033e7.1710861023.git.zhengjunjie@iscas.ac.cn
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(-)

Toggle diff (32 lines)
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@gmail.com>
;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
+;;; Copyright © 2024 Zheng Junjie <873216071@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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 7/7] vm: If not the same local architecture, don't enable kvm.
(address . 69899@debbugs.gnu.org)
94accdc1b6c6b86766117e8bf1720f79e33ad2aa.1710861023.git.zhengjunjie@iscas.ac.cn
* 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(-)

Toggle diff (36 lines)
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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 5/7] linux-initrd: don't add hid-apple module for riscv64-linux.
(address . 69899@debbugs.gnu.org)
531cfd3b53b47867c80b30f69abef3bdcbf66c06.1710861023.git.zhengjunjie@iscas.ac.cn
* 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(-)

Toggle diff (18 lines)
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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 4/7] gnu: linux-libre-riscv64-generic: add more options.
(address . 69899@debbugs.gnu.org)
8d66e9e260397c834199f77d124f4e5841a60653.1710861023.git.zhengjunjie@iscas.ac.cn
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(-)

Toggle diff (32 lines)
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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 6/7] vm: add arguments to use virt machine type for qemu-riscv64.
(address . 69899@debbugs.gnu.org)
c1874f516878f4f6f8c3d1db7f5a84d1134b6a00.1710861023.git.zhengjunjie@iscas.ac.cn
* 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(+)

Toggle diff (17 lines)
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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 3/7] vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader.
(address . 69899@debbugs.gnu.org)
528b248a19b9debbaad5181749f49f5aa4e82f77.1710861023.git.zhengjunjie@iscas.ac.cn
* 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(-)

Toggle diff (60 lines)
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
Z
Z
Zheng Junjie wrote on 19 Mar 08:18 -0700
[PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader.
(address . 69899@debbugs.gnu.org)
560d073808f3cda2f330a0b30bf2f59b79f21fbd.1710861023.git.zhengjunjie@iscas.ac.cn
* 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(+)

Toggle diff (46 lines)
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@gmail.com>
;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2023 Herman Rimm <herman_rimm@protonmail.com>
+;;; Copyright © 2024 Zheng Junjie <873216071@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
L
L
Leo Famulari wrote on 26 Mar 09:07 -0700
Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
(name . Zheng Junjie)(address . zhengjunjie@iscas.ac.cn)(address . 69899@debbugs.gnu.org)
ZgLy0pJPuDtnOz83@jasmine.lan
Hi, thanks for these patches!

On Tue, Mar 19, 2024 at 11:15:53PM +0800, Zheng Junjie wrote:
Toggle quote (6 lines)
> 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.
Z
Z
Zheng Junjie wrote on 27 Mar 02:15 -0700
(name . Leo Famulari)(address . leo@famulari.name)(address . 69899@debbugs.gnu.org)
87ttksgheo.fsf@iscas.ac.cn
Leo Famulari <leo@famulari.name> writes:

Toggle quote (12 lines)
> 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.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEfr6klGDOXiwIdX/bO1qpk+Gi3/AFAmYD5N8ACgkQO1qpk+Gi
3/CN5w/+JtBauA6LnRD0wSDmkxuYo/8Jyy1kJkKREu2RXeJxH2koif3k+XvRf/81
LAZ1dfSgtOPJ8p0mlQAVTWOqx/+fppQhoBDe2QgGQ3rtHZLQScqY8s1MDuab92P1
OflJTKWSs94KdDTsx7OnzvkFOUR5/FLv8gldFt3YEppiCy+SDc4UvebM8iJXZwP/
qb4dRGzylgh5m10yW/P8AXY4nvUB/RINakqoUcwOjqPSYJdJVhu1x0vJaJqx4r0M
88GnI4yRIfh/qLojJUHoaKUodPMVRmp5QCu26zGBaKqBA5cId38sKy6mcv4aXQcd
aZb24iEbst/Pb/F0MBR6pJ4UaHI6DVYwQUcMQgFNAKZTvTLTIfh8tyXUqyuRrlUF
zR+WlLCR8Hn3xVdVt5rG4i8JfqfcL2t5J0ZC2ag2VnRLwQ7KT4LKqW3TriIy+ILp
Stl959O6QR9ZzuudoMVm0aIXCxllW/xeFAj9hoCU5HSnEbkoQjdLoIxbVupyOx2x
GxJZzfw2as5OgTMlMDEnxFvWyd7zTJHbNJ1o98pXy+AIjxm4BhDJtIfE96PItjga
y/aPz/ExNRTO4Vk0RDLSkwK7DRg0zKE2BJW1zP2H5ZJg/1My+qQuqOWUtGYMKx9i
xMhCILbAGMK6SvUku2ddFzczAIQ1NVkrcYt3RkWxAm5slAWt2U8=
=WqCt
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 31 Mar 14:02 -0700
(name . Zheng Junjie)(address . zhengjunjie@iscas.ac.cn)
877chidsht.fsf@gnu.org
Hi,

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

Toggle quote (23 lines)
> Leo Famulari <leo@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?
Toggle diff (18 lines)
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’.
L
L
Ludovic Courtès wrote on 31 Mar 14:03 -0700
(name . Zheng Junjie)(address . zhengjunjie@iscas.ac.cn)(address . 69899-done@debbugs.gnu.org)
8734s6dsh3.fsf@gnu.org
Hi,

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

Toggle quote (8 lines)
> 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’.
Closed
Z
Z
Zheng Junjie wrote on 1 Apr 10:20 -0700
(name . Ludovic Courtès)(address . ludo@gnu.org)
87zfub3h8l.fsf@iscas.ac.cn
Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (35 lines)
> Hi,
>
> Zheng Junjie <zhengjunjie@iscas.ac.cn> skribis:
>
>> Leo Famulari <leo@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.
From e178de931859399abdd4bd3300b7ce7c5593a6e3 Mon Sep 17 00:00:00 2001
Message-ID: <e178de931859399abdd4bd3300b7ce7c5593a6e3.1712026332.git.zhengjunjie@iscas.ac.cn>
From: Zheng Junjie <zhengjunjie@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
---
gnu/system/vm.scm | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

Toggle diff (40 lines)
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index a2743453e7..42e9a08722 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))

base-commit: 9e9ec741d0dc5ce58f8d21d31800ff2cafce128f
prerequisite-patch-id: 6183d199c58355eea1a85e1f1fe51f2f5fe44f65
--
2.41.0
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.

Toggle quote (24 lines)
>
> 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’.

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEfr6klGDOXiwIdX/bO1qpk+Gi3/AFAmYMJvoACgkQO1qpk+Gi
3/C23w/+KC2fwYpU3+FQ1LHIu/gi2aUcZR/FUn6qTbCZ6fhwaps6zYFQaQulhwxM
SftFfDcZ0PuOA+stY+7nHKKvM8pshOA9nOTtifCeddFO++FZ0jcX2YqDBVSvcVnS
ZWKgnPXj7ryq0ld8C5oqQMuF/NmEoGKZJPLHqfa64qtHbVzEjLcJ94d/MmhPofcY
rT1FOlp0ozcQfBUntkOcs5aMUfDgbtN22ufVsCuLthTPXgKJgu5udKODN8g4qOE6
NHcJtN2uVqDII/7TQ9L4jw3Qp5N+WiU5fvitSviIMpWgBfBzrTOTymBHiDqeNzvv
UMvWgQpxpsh7eiUrWGfHqgIR2IH1CTyo0k9qmYDcrDrmwMKIyZ5BNJgCjeMrVt8J
0nJ1TJXHmHafV9/tjHW0El6U0gtw/2mNCoBe+6Qz3hzejEgspmUqHY9zzuHpP6CE
EtmA9SlrIt77mb8wcRdVk1xzboM+2CYb87ubL3okDpTZ5A4nAabb/knY629x1v/8
cmAPze2Xaoh/GsROaRyneX4wG6mHm43lZ/f18LDC9r3vBYw7ZJO3OZfjwRyxo5Is
CgfHhV8esH99z37UC34FZEFpgtdWHa2Q9nirE/bP+0HegvdrgG06VtVjV5G+rQjf
cO8r5Y0H/S5YHyzWopc6cOFw7OiQAWMBy/ibTlIRDyc1DO1NqwU=
=BIfo
-----END PGP SIGNATURE-----

L
L
Leo Famulari wrote on 3 Apr 15:42 -0700
(name . Zheng Junjie)(address . zhengjunjie@iscas.ac.cn)
Zg3bPpl9p8AbrZfq@jasmine.lan
On Tue, Apr 02, 2024 at 01:20:12AM +0800, Zheng Junjie wrote:
Toggle quote (2 lines)
> 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?
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEaEByLu7k06ZO5T6saqwZY3V/R/8FAmYN2z4ACgkQaqwZY3V/
R/8oRw/8DZBqAvtLmrvmsQ6u1qQfwkKyqgFo7QDcJy5hsgztDpPGmKWCF7aC4knb
KouLITG1jSP2jFp5Kqjcnzigw7FNWiqrzEEyTlf66ad+MosDqmDjsTll9WXpne3x
sdeX21vjZ8Zcu8rg97a5gZHdUlk89f9/AYg2LZOjNwLIZaMMiqVme3yssLv2Vvkj
GZQVU81XmRNEXgTtbupgrtHmng77OnwP5OADVCkiLf9ga9MKkQV+8Bd0NSLDNPQD
fTarxx+0M+lrQkTi2g2UNcYgM4s8Bz1zMwp47bBOGB+ES0A1slpJKfR3TGiuXLP7
bxuakk/Hxv8y34uTRgwXd+ONQ7revGttnw4xYBSTfQVK7nWRB7j6Q8XiSfnlxDby
c/w/9288ObIw/CIJVIe7VrZ+S2oBrxmk9G4y9QecJ38ZU6i/L7onLEOy5U1uQ7tk
BgQ0cbTZTPXQdxNXMhdM3NFDFWKleMaSwzxM6Gq3uDUrRo/eq34xzWPn998sUUSD
rk4YLiQaOGsP85fh6T8NY3JdWri7nI/5RYkGZ+VQQTuWPsVgcjG9QmkEVlvqFN5L
fW+Tk7RGnrHw23eGCOQNluxaKM9QRA/vXeaYAkJ46ckCNguiIqibTnvkvmXTJUfo
6p5TCJn6n4etrAGtLoaFCipYYY1Az0sodbu2yxa+uOpr0ifSllQ=
=9PD6
-----END PGP SIGNATURE-----


Z
Z
Zheng Junjie wrote on 15 Apr 08:33 -0700
[PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native emulator.
(address . 69899@debbugs.gnu.org)(name . Ludovic Courtès)(address . ludo@gnu.org)
4d858dc7d62800138c0d8fd78c598c9a89044662.1713194805.git.zhengjunjie@iscas.ac.cn
From: Ludovic Courtès <ludo@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(-)

Toggle diff (33 lines)
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
Z
Z
Zheng Junjie wrote on 15 Apr 08:33 -0700
[PATCH 2/2] vm: Don't add -enable-kvm when SYSTEM and %system are not same.
(address . 69899@debbugs.gnu.org)
fbdee02737458f99e9e7d3116e3e828c8f204bf8.1713194805.git.zhengjunjie@iscas.ac.cn
* 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(-)

Toggle diff (37 lines)
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
L
L
Ludovic Courtès wrote on 16 Apr 10:04 -0700
Re: [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
(name . Zheng Junjie)(address . zhengjunjie@iscas.ac.cn)
87le5dkzme.fsf@gnu.org
Zheng Junjie <zhengjunjie@iscas.ac.cn> skribis:

Toggle quote (2 lines)
> Ludovic Courtès <ludo@gnu.org> writes:

[...]

Toggle quote (10 lines)
>> 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.

Toggle quote (14 lines)
> and the following patch is required.
>
> From e178de931859399abdd4bd3300b7ce7c5593a6e3 Mon Sep 17 00:00:00 2001
> Message-ID: <e178de931859399abdd4bd3300b7ce7c5593a6e3.1712026332.git.zhengjunjie@iscas.ac.cn>
> From: Zheng Junjie <zhengjunjie@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

[...]

Toggle quote (4 lines)
> + #$@(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’.
?
Your comment

This issue is archived.

To comment on this conversation send an email to 69899@patchwise.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 69899
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch