unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
@ 2024-03-19 15:15 Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader Zheng Junjie
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:15 UTC (permalink / raw)
  To: 69899

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





^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 2/7] vm: use #$ for kernel-arguments Zheng Junjie
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1908 bytes --]

* 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@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))))
+
 \f
 
 ;;;
@@ -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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 2/7] vm: use #$ for kernel-arguments.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 3/7] vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader Zheng Junjie
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1651 bytes --]

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@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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 3/7] vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 2/7] vm: use #$ for kernel-arguments Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 4/7] gnu: linux-libre-riscv64-generic: add more options Zheng Junjie
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899

* 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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 4/7] gnu: linux-libre-riscv64-generic: add more options.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (2 preceding siblings ...)
  2024-03-19 15:18 ` [bug#69899] [PATCH 3/7] vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 5/7] linux-initrd: don't add hid-apple module for riscv64-linux Zheng Junjie
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899; +Cc: Leo Famulari, Tobias Geerinckx-Rice, Wilko Meyer

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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 5/7] linux-initrd: don't add hid-apple module for riscv64-linux.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (3 preceding siblings ...)
  2024-03-19 15:18 ` [bug#69899] [PATCH 4/7] gnu: linux-libre-riscv64-generic: add more options Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 6/7] vm: add arguments to use virt machine type for qemu-riscv64 Zheng Junjie
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899

* 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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 6/7] vm: add arguments to use virt machine type for qemu-riscv64.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (4 preceding siblings ...)
  2024-03-19 15:18 ` [bug#69899] [PATCH 5/7] linux-initrd: don't add hid-apple module for riscv64-linux Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-19 15:18 ` [bug#69899] [PATCH 7/7] vm: If not the same local architecture, don't enable kvm Zheng Junjie
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899

* 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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 7/7] vm: If not the same local architecture, don't enable kvm.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (5 preceding siblings ...)
  2024-03-19 15:18 ` [bug#69899] [PATCH 6/7] vm: add arguments to use virt machine type for qemu-riscv64 Zheng Junjie
@ 2024-03-19 15:18 ` Zheng Junjie
  2024-03-26 16:07 ` [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Leo Famulari
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-03-19 15:18 UTC (permalink / raw)
  To: 69899

* 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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (6 preceding siblings ...)
  2024-03-19 15:18 ` [bug#69899] [PATCH 7/7] vm: If not the same local architecture, don't enable kvm Zheng Junjie
@ 2024-03-26 16:07 ` Leo Famulari
  2024-03-27  9:15   ` Zheng Junjie
  2024-03-31 21:03 ` bug#69899: " Ludovic Courtès
  2024-04-15 15:33 ` [bug#69899] [PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native emulator Zheng Junjie
  9 siblings, 1 reply; 17+ messages in thread
From: Leo Famulari @ 2024-03-26 16:07 UTC (permalink / raw)
  To: Zheng Junjie; +Cc: 69899

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.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-03-26 16:07 ` [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Leo Famulari
@ 2024-03-27  9:15   ` Zheng Junjie
  2024-03-31 21:02     ` Ludovic Courtès
  0 siblings, 1 reply; 17+ messages in thread
From: Zheng Junjie @ 2024-03-27  9:15 UTC (permalink / raw)
  To: Leo Famulari; +Cc: 69899

[-- Attachment #1: Type: text/plain, Size: 945 bytes --]


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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-03-27  9:15   ` Zheng Junjie
@ 2024-03-31 21:02     ` Ludovic Courtès
  2024-04-01 17:20       ` Zheng Junjie
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2024-03-31 21:02 UTC (permalink / raw)
  To: Zheng Junjie; +Cc: 69899, Leo Famulari

[-- Attachment #1: Type: text/plain, Size: 1471 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 886 bytes --]

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?

[-- Attachment #3: Type: text/plain, Size: 21 bytes --]


Thanks,
Ludo’.

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* bug#69899: [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (7 preceding siblings ...)
  2024-03-26 16:07 ` [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Leo Famulari
@ 2024-03-31 21:03 ` Ludovic Courtès
  2024-04-15 15:33 ` [bug#69899] [PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native emulator Zheng Junjie
  9 siblings, 0 replies; 17+ messages in thread
From: Ludovic Courtès @ 2024-03-31 21:03 UTC (permalink / raw)
  To: Zheng Junjie; +Cc: 69899-done

Hi,

Zheng Junjie <zhengjunjie@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’.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-03-31 21:02     ` Ludovic Courtès
@ 2024-04-01 17:20       ` Zheng Junjie
  2024-04-03 22:42         ` Leo Famulari
  2024-04-16 17:04         ` Ludovic Courtès
  0 siblings, 2 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-04-01 17:20 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 69899, Leo Famulari


[-- Attachment #1.1: Type: text/plain, Size: 1608 bytes --]


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

> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-vm-Don-t-add-enable-kvm-when-SYSTEM-and-system-are-n.patch --]
[-- Type: text/x-patch, Size: 2405 bytes --]

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(-)

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


[-- Attachment #1.3: Type: text/plain, Size: 1292 bytes --]



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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-04-01 17:20       ` Zheng Junjie
@ 2024-04-03 22:42         ` Leo Famulari
  2024-04-16 17:04         ` Ludovic Courtès
  1 sibling, 0 replies; 17+ messages in thread
From: Leo Famulari @ 2024-04-03 22:42 UTC (permalink / raw)
  To: Zheng Junjie; +Cc: 69899, Ludovic Courtès

[-- Attachment #1: Type: text/plain, Size: 207 bytes --]

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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native emulator.
  2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
                   ` (8 preceding siblings ...)
  2024-03-31 21:03 ` bug#69899: " Ludovic Courtès
@ 2024-04-15 15:33 ` Zheng Junjie
  2024-04-15 15:33   ` [bug#69899] [PATCH 2/2] vm: Don't add -enable-kvm when SYSTEM and %system are not same Zheng Junjie
  9 siblings, 1 reply; 17+ messages in thread
From: Zheng Junjie @ 2024-04-15 15:33 UTC (permalink / raw)
  To: 69899; +Cc: Ludovic Courtès

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(-)

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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 2/2] vm: Don't add -enable-kvm when SYSTEM and %system are not same.
  2024-04-15 15:33 ` [bug#69899] [PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native emulator Zheng Junjie
@ 2024-04-15 15:33   ` Zheng Junjie
  0 siblings, 0 replies; 17+ messages in thread
From: Zheng Junjie @ 2024-04-15 15:33 UTC (permalink / raw)
  To: 69899

* 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





^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64.
  2024-04-01 17:20       ` Zheng Junjie
  2024-04-03 22:42         ` Leo Famulari
@ 2024-04-16 17:04         ` Ludovic Courtès
  1 sibling, 0 replies; 17+ messages in thread
From: Ludovic Courtès @ 2024-04-16 17:04 UTC (permalink / raw)
  To: Zheng Junjie; +Cc: 69899, Leo Famulari

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

> Ludovic Courtès <ludo@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@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

[...]

> +     #$@(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’.




^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-04-16 17:06 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19 15:15 [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 1/7] bootloader: Add u-boot-qemu-riscv64-bootloader Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 2/7] vm: use #$ for kernel-arguments Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 3/7] vm: When target riscv64-linux, use u-boot-qemu-riscv64-bootloader Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 4/7] gnu: linux-libre-riscv64-generic: add more options Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 5/7] linux-initrd: don't add hid-apple module for riscv64-linux Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 6/7] vm: add arguments to use virt machine type for qemu-riscv64 Zheng Junjie
2024-03-19 15:18 ` [bug#69899] [PATCH 7/7] vm: If not the same local architecture, don't enable kvm Zheng Junjie
2024-03-26 16:07 ` [bug#69899] [PATCH 0/7] support to use `guix system vm' with riscv64 Leo Famulari
2024-03-27  9:15   ` Zheng Junjie
2024-03-31 21:02     ` Ludovic Courtès
2024-04-01 17:20       ` Zheng Junjie
2024-04-03 22:42         ` Leo Famulari
2024-04-16 17:04         ` Ludovic Courtès
2024-03-31 21:03 ` bug#69899: " Ludovic Courtès
2024-04-15 15:33 ` [bug#69899] [PATCH 1/2] vm: override %CURRENT-SYSTEM to always use a native emulator Zheng Junjie
2024-04-15 15:33   ` [bug#69899] [PATCH 2/2] vm: Don't add -enable-kvm when SYSTEM and %system are not same Zheng Junjie

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).