Skip to contentSkip to conversation

kvm: replace fprintf with error_report/printf() in kvm_init()

PATCH Superseded Ani Sinha 3 participants 9 messages Aug 9, 2024 – Aug 27, 2024 KVM

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH v3 1/1 kvm: replace fprintf with error_report/printf() in kvm_init()

error_report() is more appropriate for error situations. Replace fprintf with error_report. Cosmetic. No functional change.

---
 accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added tags.

accel/kvm/kvm-all.c +18 -22
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
     QLIST_INIT(&s->kvm_parked_vcpus);
     s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
     if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
         ret = -errno;
         goto err;
     }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
         if (ret >= 0) {
             ret = -EINVAL;
         }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
         goto err;
     }
 
     if (ret > KVM_API_VERSION) {
         ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
         goto err;
     }
 
@@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
     } while (ret == -EINTR);
 
     if (ret < 0) {
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
 
 #ifdef TARGET_S390X
         if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please verify:\n");
-            fprintf(stderr, "- for kernels supporting the switch_amode or"
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address space\n");
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste sysctl, "
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected. Please verify:");
+            error_report("- for kernels supporting the switch_amode or"
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address space");
+            error_report("- for kernels supporting the vm.allocate_pgste "
+                        "sysctl, whether it is enabled");
         }
 #elif defined(TARGET_PPC)
         if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "PPC KVM module is not loaded. Try modprobe kvm_%s.\n",
-                    (type == 2) ? "pr" : "hv");
+            error_report("PPC KVM module is not loaded. Try modprobe kvm_%s.",
+                        (type == 2) ? "pr" : "hv");
         }
 #endif
         goto err;
@@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms)
                         nc->name, nc->num, soft_vcpus_limit);
 
             if (nc->num > hard_vcpus_limit) {
-                fprintf(stderr, "Number of %s cpus requested (%d) exceeds "
-                        "the maximum cpus supported by KVM (%d)\n",
-                        nc->name, nc->num, hard_vcpus_limit);
+                error_report("Number of %s cpus requested (%d) exceeds "
+                             "the maximum cpus supported by KVM (%d)",
+                             nc->name, nc->num, hard_vcpus_limit);
                 exit(1);
             }
         }
@@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms)
     }
     if (missing_cap) {
         ret = -EINVAL;
-        fprintf(stderr, "kvm does not support %s\n%s",
-                missing_cap->name, upgrade_note);
+        error_printf("kvm does not support %s\n%s",
+                     missing_cap->name, upgrade_note);
         goto err;
     }
 
Signature · 1 line
2.45.2
#1 lore raw

Hi Ani,

Quoted 5 lines · Ani Sinha

error_report() is more appropriate for error situations. Replace fprintf with error_report. Cosmetic. No functional change.

(Pointless to carry Cc line when patch is already reviewed next line)

Quoted 50 lines
---
  accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
  1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added tags.

accel/kvm/kvm-all.c +5 -5
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
      QLIST_INIT(&s->kvm_parked_vcpus);
      s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
      if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
          ret = -errno;
          goto err;
      }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
          if (ret >= 0) {
              ret = -EINVAL;
          }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
          goto err;
      }
 
      if (ret > KVM_API_VERSION) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
          goto err;
      }
 
@@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
      } while (ret == -EINTR);
 
      if (ret < 0) {
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
 
  #ifdef TARGET_S390X
          if (ret == -EINVAL) {

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2496

Quoted 10 lines
accel/kvm/kvm-all.c +1 -9
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please verify:\n");
-            fprintf(stderr, "- for kernels supporting the switch_amode or"
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address space\n");
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste sysctl, "
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected.

\n"

Should we use error_printf_unless_qmp() for the following?

" Please verify:");

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 10 lines
accel/kvm/kvm-all.c +5 -2
+            error_report("- for kernels supporting the switch_amode or"
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address space");
+            error_report("- for kernels supporting the vm.allocate_pgste "
+                        "sysctl, whether it is enabled");
          }
  #elif defined(TARGET_PPC)
          if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "PPC KVM module is not loaded.

\n"

Ditto.

" Try modprobe kvm_%s.\n",

Quoted 20 lines
accel/kvm/kvm-all.c +5 -4
-                    (type == 2) ? "pr" : "hv");
+            error_report("PPC KVM module is not loaded. Try modprobe kvm_%s.",
+                        (type == 2) ? "pr" : "hv");
          }
  #endif
          goto err;
@@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms)
                          nc->name, nc->num, soft_vcpus_limit);
 
              if (nc->num > hard_vcpus_limit) {
-                fprintf(stderr, "Number of %s cpus requested (%d) exceeds "
-                        "the maximum cpus supported by KVM (%d)\n",
-                        nc->name, nc->num, hard_vcpus_limit);
+                error_report("Number of %s cpus requested (%d) exceeds "
+                             "the maximum cpus supported by KVM (%d)",
+                             nc->name, nc->num, hard_vcpus_limit);
                  exit(1);
              }
          }

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2542

Quoted 7 lines
accel/kvm/kvm-all.c +2 -2
@@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms)
      }
      if (missing_cap) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm does not support %s\n%s",
-                missing_cap->name, upgrade_note);
+        error_printf("kvm does not support %s\n%s",
+                     missing_cap->name, upgrade_note);

Similarly, should we print upgrade_note using error_printf_unless_qmp?

Quoted 3 lines
accel/kvm/kvm-all.c +0 -0
          goto err;
      }
 
author
#2 lore raw
Quoted 75 lines · Philippe Mathieu-Daudé

Hi Ani,

Quoted 5 lines · Ani Sinha

error_report() is more appropriate for error situations. Replace fprintf with error_report. Cosmetic. No functional change.

(Pointless to carry Cc line when patch is already reviewed next line)

Quoted 50 lines
---
  accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
  1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added tags.

accel/kvm/kvm-all.c +5 -5
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
      QLIST_INIT(&s->kvm_parked_vcpus);
      s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
      if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
          ret = -errno;
          goto err;
      }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
          if (ret >= 0) {
              ret = -EINVAL;
          }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
          goto err;
      }
 
      if (ret > KVM_API_VERSION) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
          goto err;
      }
 
@@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
      } while (ret == -EINTR);
 
      if (ret < 0) {
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
 
  #ifdef TARGET_S390X
          if (ret == -EINVAL) {

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2496

Quoted 10 lines
accel/kvm/kvm-all.c +1 -9
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please verify:\n");
-            fprintf(stderr, "- for kernels supporting the switch_amode or"
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address space\n");
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste sysctl, "
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected.

\n"

Quoted 1 line

Should we use error_printf_unless_qmp() for the following?

Do you believe that qemu_init() -> configure_accelerators() -> do_configure_accelerator,() -> accel_init_machine() -> kvm_init() can be called from QMP context?

Quoted 52 lines

" Please verify:");

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 10 lines
accel/kvm/kvm-all.c +5 -2
+            error_report("- for kernels supporting the switch_amode or"
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address space");
+            error_report("- for kernels supporting the vm.allocate_pgste "
+                        "sysctl, whether it is enabled");
          }
  #elif defined(TARGET_PPC)
          if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "PPC KVM module is not loaded.

\n"

Ditto.

" Try modprobe kvm_%s.\n",

Quoted 20 lines
accel/kvm/kvm-all.c +5 -4
-                    (type == 2) ? "pr" : "hv");
+            error_report("PPC KVM module is not loaded. Try modprobe kvm_%s.",
+                        (type == 2) ? "pr" : "hv");
          }
  #endif
          goto err;
@@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms)
                          nc->name, nc->num, soft_vcpus_limit);
 
              if (nc->num > hard_vcpus_limit) {
-                fprintf(stderr, "Number of %s cpus requested (%d) exceeds "
-                        "the maximum cpus supported by KVM (%d)\n",
-                        nc->name, nc->num, hard_vcpus_limit);
+                error_report("Number of %s cpus requested (%d) exceeds "
+                             "the maximum cpus supported by KVM (%d)",
+                             nc->name, nc->num, hard_vcpus_limit);
                  exit(1);
              }
          }

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2542

Quoted 7 lines
accel/kvm/kvm-all.c +2 -2
@@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms)
      }
      if (missing_cap) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm does not support %s\n%s",
-                missing_cap->name, upgrade_note);
+        error_printf("kvm does not support %s\n%s",
+                     missing_cap->name, upgrade_note);

Similarly, should we print upgrade_note using error_printf_unless_qmp?

Quoted 3 lines
accel/kvm/kvm-all.c +0 -0
          goto err;
      }
 
author
#3 lore raw
Quoted 81 lines · Ani Sinha,
Quoted 5 lines · Philippe Mathieu-Daudé

Hi Ani,

Quoted 1 line · Ani Sinha

error_report() is more appropriate for error situations. Replace

fprintf with

Quoted 16 lines
Quoted 4 lines

error_report. Cosmetic. No functional change.

(Pointless to carry Cc line when patch is already reviewed next line)

Quoted 9 lines
---
  accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
  1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added

tags.

Quoted 39 lines
Quoted 39 lines
accel/kvm/kvm-all.c +5 -5
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
      QLIST_INIT(&s->kvm_parked_vcpus);
      s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
      if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
          ret = -errno;
          goto err;
      }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
          if (ret >= 0) {
              ret = -EINVAL;
          }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
          goto err;
      }
 
      if (ret > KVM_API_VERSION) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
          goto err;
      }
 
@@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
      } while (ret == -EINTR);
 
      if (ret < 0) {
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
 
Quoted 4 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 4 lines
accel/kvm/kvm-all.c +0 -2
  #ifdef TARGET_S390X
          if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please

verify:\n");

Quoted 1 line

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2498

Quoted 1 line
accel/kvm/kvm-all.c +0 -1
-            fprintf(stderr, "- for kernels supporting the

switch_amode or"

Quoted 3 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 3 lines
accel/kvm/kvm-all.c +0 -3
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address

space\n");

Quoted 2 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2503

Quoted 2 lines
accel/kvm/kvm-all.c +0 -2
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste

sysctl, "

Quoted 3 lines
Quoted 2 lines
accel/kvm/kvm-all.c +1 -1
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected.
Quoted 8 lines
Quoted 3 lines

\n"

Should we use error_printf_unless_qmp() for the following?

Do you believe that qemu_init() -> configure_accelerators() -> do_configure_accelerator,() -> accel_init_machine() -> kvm_init() can be called from QMP context?

To clarify, that is the only path I saw that calls kvm_init()

Quoted 59 lines
Quoted 3 lines

" Please verify:");

Quoted 1 line
accel/kvm/kvm-all.c +1 -0
+            error_report("- for kernels supporting the switch_amode

or"

Quoted 2 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2499

Quoted 2 lines
accel/kvm/kvm-all.c +2 -0
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address

space");

Quoted 1 line

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2500

Quoted 1 line
accel/kvm/kvm-all.c +1 -0
+            error_report("- for kernels supporting the

vm.allocate_pgste "

Quoted 7 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 6 lines
accel/kvm/kvm-all.c +1 -2
+                        "sysctl, whether it is enabled");
          }
  #elif defined(TARGET_PPC)
          if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "PPC KVM module is not loaded.
Quoted 7 lines

\n"

Ditto.

" Try modprobe kvm_%s.\n",

Quoted 2 lines
accel/kvm/kvm-all.c +1 -1
-                    (type == 2) ? "pr" : "hv");
+            error_report("PPC KVM module is not loaded. Try modprobe

kvm_%s.",

Quoted 9 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2529

Quoted 9 lines
accel/kvm/kvm-all.c +1 -1
+                        (type == 2) ? "pr" : "hv");
          }
  #endif
          goto err;
@@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms)
                          nc->name, nc->num, soft_vcpus_limit);
 
              if (nc->num > hard_vcpus_limit) {
-                fprintf(stderr, "Number of %s cpus requested (%d)

exceeds "

Quoted 3 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 3 lines
accel/kvm/kvm-all.c +1 -2
-                        "the maximum cpus supported by KVM (%d)\n",
-                        nc->name, nc->num, hard_vcpus_limit);
+                error_report("Number of %s cpus requested (%d)

exceeds "

Quoted 20 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2542

Quoted 13 lines
accel/kvm/kvm-all.c +4 -2
+                             "the maximum cpus supported by KVM (%d)",
+                             nc->name, nc->num, hard_vcpus_limit);
                  exit(1);
              }
          }
@@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms)
      }
      if (missing_cap) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm does not support %s\n%s",
-                missing_cap->name, upgrade_note);
+        error_printf("kvm does not support %s\n%s",
+                     missing_cap->name, upgrade_note);

Similarly, should we print upgrade_note using error_printf_unless_qmp?

Quoted 3 lines
accel/kvm/kvm-all.c +0 -0
          goto err;
      }
 
#4 lore raw
Quoted 98 lines · Ani Sinha

On Mon, 12 Aug, 2024, 3:23 pm Ani Sinha, <[email protected] <mailto:[email protected]>> wrote:

    On Fri, Aug 9, 2024 at 2:06 PM Philippe Mathieu-Daudé
    <[email protected] <mailto:[email protected]>> wrote:
     >
     > Hi Ani,
     >
     > On 9/8/24 08:49, Ani Sinha wrote:
     > > error_report() is more appropriate for error situations.
    Replace fprintf with
     > > error_report. Cosmetic. No functional change.
     > >
     > > CC: [email protected] <mailto:[email protected]>
     > > CC: [email protected] <mailto:[email protected]>
     >
     > (Pointless to carry Cc line when patch is already reviewed next line)
     >
     > > Reviewed-by: Zhao Liu <[email protected]
    <mailto:[email protected]>>
     > > Signed-off-by: Ani Sinha <[email protected]
    <mailto:[email protected]>>
     > > ---
     > >   accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
     > >   1 file changed, 18 insertions(+), 22 deletions(-)
     > >
     > > changelog:
     > > v2: fix a bug.
     > > v3: replace one instance of error_report() with error_printf().
    added tags.
     > >
     > > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
     > > index 75d11a07b2..5bc9d35b61 100644
     > > --- a/accel/kvm/kvm-all.c
     > > +++ b/accel/kvm/kvm-all.c
     > > @@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
     > >       QLIST_INIT(&s->kvm_parked_vcpus);
     > >       s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
     > >       if (s->fd == -1) {
     > > -        fprintf(stderr, "Could not access KVM kernel module:
    %m\n");
     > > +        error_report("Could not access KVM kernel module: %m");
     > >           ret = -errno;
     > >           goto err;
     > >       }
     > > @@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
     > >           if (ret >= 0) {
     > >               ret = -EINVAL;
     > >           }
     > > -        fprintf(stderr, "kvm version too old\n");
     > > +        error_report("kvm version too old");
     > >           goto err;
     > >       }
     > >
     > >       if (ret > KVM_API_VERSION) {
     > >           ret = -EINVAL;
     > > -        fprintf(stderr, "kvm version not supported\n");
     > > +        error_report("kvm version not supported");
     > >           goto err;
     > >       }
     > >
     > > @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
     > >       } while (ret == -EINTR);
     > >
     > >       if (ret < 0) {
     > > -        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d
    %s\n", -ret,
     > > -                strerror(-ret));
     > > +        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
     > > +                    strerror(-ret));
     > >
     > >   #ifdef TARGET_S390X
     > >           if (ret == -EINVAL) {
     > > -            fprintf(stderr,
     > > -                    "Host kernel setup problem detected.
    Please verify:\n");
     > > -            fprintf(stderr, "- for kernels supporting the
    switch_amode or"
     > > -                    " user_mode parameters, whether\n");
     > > -            fprintf(stderr,
     > > -                    "  user space is running in primary
    address space\n");
     > > -            fprintf(stderr,
     > > -                    "- for kernels supporting the
    vm.allocate_pgste sysctl, "
     > > -                    "whether it is enabled\n");
     > > +            error_report("Host kernel setup problem detected.
     >
     > \n"
     >
     > Should we use error_printf_unless_qmp() for the following?

    Do you believe that qemu_init() -> configure_accelerators() ->
    do_configure_accelerator,() -> accel_init_machine() -> kvm_init()  can
    be called from QMP context?
Quoted 1 line

To clarify, that is the only path I saw that calls kvm_init()

We don't know whether this code can end refactored or not. Personally I rather consistent API uses, since snipped of code are often used as example. Up to the maintainer.

Quoted 62 lines
     >
     > " Please verify:");
     > > +            error_report("- for kernels supporting the
    switch_amode or"
     > > +                        " user_mode parameters, whether");
     > > +            error_report("  user space is running in primary
    address space");
     > > +            error_report("- for kernels supporting the
    vm.allocate_pgste "
     > > +                        "sysctl, whether it is enabled");
     > >           }
     > >   #elif defined(TARGET_PPC)
     > >           if (ret == -EINVAL) {
     > > -            fprintf(stderr,
     > > -                    "PPC KVM module is not loaded.
     >
     > \n"
     >
     > Ditto.
     >
     > " Try modprobe kvm_%s.\n",
     > > -                    (type == 2) ? "pr" : "hv");
     > > +            error_report("PPC KVM module is not loaded. Try
    modprobe kvm_%s.",
     > > +                        (type == 2) ? "pr" : "hv");
     > >           }
     > >   #endif
     > >           goto err;
     > > @@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms)
     > >                           nc->name, nc->num, soft_vcpus_limit);
     > >
     > >               if (nc->num > hard_vcpus_limit) {
     > > -                fprintf(stderr, "Number of %s cpus requested
    (%d) exceeds "
     > > -                        "the maximum cpus supported by KVM
    (%d)\n",
     > > -                        nc->name, nc->num, hard_vcpus_limit);
     > > +                error_report("Number of %s cpus requested (%d)
    exceeds "
     > > +                             "the maximum cpus supported by
    KVM (%d)",
     > > +                             nc->name, nc->num, hard_vcpus_limit);
     > >                   exit(1);
     > >               }
     > >           }
     > > @@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms)
     > >       }
     > >       if (missing_cap) {
     > >           ret = -EINVAL;
     > > -        fprintf(stderr, "kvm does not support %s\n%s",
     > > -                missing_cap->name, upgrade_note);
     > > +        error_printf("kvm does not support %s\n%s",
     > > +                     missing_cap->name, upgrade_note);
     >
     > Similarly, should we print upgrade_note using
    error_printf_unless_qmp?
     >
     > >           goto err;
     > >       }
     > >
     >
author
#5 lore raw
Quoted 93 lines · Philippe Mathieu-Daudé
Quoted 88 lines · Ani Sinha

On Mon, 12 Aug, 2024, 3:23 pm Ani Sinha, <[email protected] <mailto:[email protected]>> wrote:

   On Fri, Aug 9, 2024 at 2:06 PM Philippe Mathieu-Daudé
   <[email protected] <mailto:[email protected]>> wrote:
    >
    > Hi Ani,
    >
    > On 9/8/24 08:49, Ani Sinha wrote:
    > > error_report() is more appropriate for error situations.
   Replace fprintf with
    > > error_report. Cosmetic. No functional change.
    > >
    > > CC: [email protected] <mailto:[email protected]>
    > > CC: [email protected] <mailto:[email protected]>
    >
    > (Pointless to carry Cc line when patch is already reviewed next line)
    >
    > > Reviewed-by: Zhao Liu <[email protected]
   <mailto:[email protected]>>
    > > Signed-off-by: Ani Sinha <[email protected]
   <mailto:[email protected]>>
    > > ---
    > >   accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
    > >   1 file changed, 18 insertions(+), 22 deletions(-)
    > >
    > > changelog:
    > > v2: fix a bug.
    > > v3: replace one instance of error_report() with error_printf().
   added tags.
    > >
    > > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
    > > index 75d11a07b2..5bc9d35b61 100644
    > > --- a/accel/kvm/kvm-all.c
    > > +++ b/accel/kvm/kvm-all.c
    > > @@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
    > >       QLIST_INIT(&s->kvm_parked_vcpus);
    > >       s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
    > >       if (s->fd == -1) {
    > > -        fprintf(stderr, "Could not access KVM kernel module:
   %m\n");
    > > +        error_report("Could not access KVM kernel module: %m");
    > >           ret = -errno;
    > >           goto err;
    > >       }
    > > @@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
    > >           if (ret >= 0) {
    > >               ret = -EINVAL;
    > >           }
    > > -        fprintf(stderr, "kvm version too old\n");
    > > +        error_report("kvm version too old");
    > >           goto err;
    > >       }
    > >
    > >       if (ret > KVM_API_VERSION) {
    > >           ret = -EINVAL;
    > > -        fprintf(stderr, "kvm version not supported\n");
    > > +        error_report("kvm version not supported");
    > >           goto err;
    > >       }
    > >
    > > @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
    > >       } while (ret == -EINTR);
    > >
    > >       if (ret < 0) {
    > > -        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d
   %s\n", -ret,
    > > -                strerror(-ret));
    > > +        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
    > > +                    strerror(-ret));
    > >
    > >   #ifdef TARGET_S390X
    > >           if (ret == -EINVAL) {
    > > -            fprintf(stderr,
    > > -                    "Host kernel setup problem detected.
   Please verify:\n");
    > > -            fprintf(stderr, "- for kernels supporting the
   switch_amode or"
    > > -                    " user_mode parameters, whether\n");
    > > -            fprintf(stderr,
    > > -                    "  user space is running in primary
   address space\n");
    > > -            fprintf(stderr,
    > > -                    "- for kernels supporting the
   vm.allocate_pgste sysctl, "
    > > -                    "whether it is enabled\n");
    > > +            error_report("Host kernel setup problem detected.
    >
    > \n"
    >
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Should we use error_printf_unless_qmp() for the following?

Do you believe that qemu_init() -> configure_accelerators() -> do_configure_accelerator,() -> accel_init_machine() -> kvm_init() can be called from QMP context?
To clarify, that is the only path I saw that calls kvm_init()

We don't know whether this code can end refactored or not.

Ok personally I think we can cross the bridge when we get there.

Quoted 2 lines

Personally I rather consistent API uses, since snipped of code are often used as example. Up to the maintainer.

OK up to Paolo then :-)

Quoted 62 lines
Quoted 62 lines
Quoted 4 lines

" Please verify:");

Quoted 1 line

+ error_report("- for kernels supporting the

switch_amode or"

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary

address space");

Quoted 1 line
Quoted 1 line

+ error_report("- for kernels supporting the

vm.allocate_pgste "

Quoted 7 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 6 lines
accel/kvm/kvm-all.c +1 -2
+                        "sysctl, whether it is enabled");
          }
  #elif defined(TARGET_PPC)
          if (ret == -EINVAL) {
-            fprintf(stderr,
-                    "PPC KVM module is not loaded.
Quoted 7 lines

\n"

Ditto.

" Try modprobe kvm_%s.\n",

Quoted 2 lines
(quoted diff) +1 -1
-                    (type == 2) ? "pr" : "hv");
+            error_report("PPC KVM module is not loaded. Try

modprobe kvm_%s.",

Quoted 9 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2529

Quoted 9 lines
accel/kvm/kvm-all.c +1 -1
+                        (type == 2) ? "pr" : "hv");
          }
  #endif
          goto err;
@@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms)
                          nc->name, nc->num, soft_vcpus_limit);
 
              if (nc->num > hard_vcpus_limit) {
-                fprintf(stderr, "Number of %s cpus requested

(%d) exceeds "

Quoted 1 line

Review static int kvm_init(MachineState *ms) · line 2530

Quoted 1 line
(quoted diff) +0 -1
-                        "the maximum cpus supported by KVM

(%d)\n",

Quoted 2 lines

Review static int kvm_init(MachineState *ms) · line 2525

Quoted 2 lines
(quoted diff) +1 -1
-                        nc->name, nc->num, hard_vcpus_limit);
+                error_report("Number of %s cpus requested (%d)

exceeds "

Quoted 1 line

Review static int kvm_init(MachineState *ms) · line 2526

Quoted 1 line
(quoted diff) +1 -0
+                             "the maximum cpus supported by

KVM (%d)",

Quoted 6 lines
Quoted 6 lines
accel/kvm/kvm-all.c +1 -0
+                             nc->name, nc->num, hard_vcpus_limit);
                  exit(1);
              }
          }
@@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms)
      }
Quoted 8 lines

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2542

Quoted 6 lines
accel/kvm/kvm-all.c +2 -2
      if (missing_cap) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm does not support %s\n%s",
-                missing_cap->name, upgrade_note);
+        error_printf("kvm does not support %s\n%s",
+                     missing_cap->name, upgrade_note);

Similarly, should we print upgrade_note using

error_printf_unless_qmp?

Quoted 5 lines
Quoted 4 lines
accel/kvm/kvm-all.c +0 -0
          goto err;
      }
 
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 67 lines · Philippe Mathieu-Daudé

Hi Ani,

Quoted 4 lines · Ani Sinha

error_report() is more appropriate for error situations. Replace fprintf with error_report. Cosmetic. No functional change.
CC: [email protected]
CC: [email protected]

(Pointless to carry Cc line when patch is already reviewed next line)

Quoted 44 lines
---
  accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
  1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added tags.

accel/kvm/kvm-all.c +3 -3
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
      QLIST_INIT(&s->kvm_parked_vcpus);
      s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
      if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
          ret = -errno;
          goto err;
      }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
          if (ret >= 0) {
              ret = -EINVAL;
          }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
          goto err;
      }
        if (ret > KVM_API_VERSION) {
          ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
          goto err;
      }
  @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
      } while (ret == -EINTR);
        if (ret < 0) {
accel/kvm/kvm-all.c +2 -2
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
    #ifdef TARGET_S390X
          if (ret == -EINVAL) {

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 10 lines
accel/kvm/kvm-all.c +1 -9
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please verify:\n");
-            fprintf(stderr, "- for kernels supporting the switch_amode or"
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address space\n");
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste sysctl, "
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected.

\n"

Quoted 8 lines

Should we use error_printf_unless_qmp() for the following?

" Please verify:");

Quoted 5 lines
accel/kvm/kvm-all.c +5 -0
+            error_report("- for kernels supporting the switch_amode or"
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address space");
+            error_report("- for kernels supporting the vm.allocate_pgste "
+                        "sysctl, whether it is enabled");

Do not put newlines into error messages. error_report()'s function comment demands "The resulting message should be a single phrase, with no newline or trailing punctuation."

You can do this:

    error_report(... the actual error message ...);
    error_printf(... hints on what to do about it ...);

Questions?

[...]

author
#7 lore raw
Quoted 86 lines · Markus Armbruster
Quoted 67 lines · Philippe Mathieu-Daudé

Hi Ani,

Quoted 4 lines · Ani Sinha

error_report() is more appropriate for error situations. Replace fprintf with error_report. Cosmetic. No functional change.
CC: [email protected]
CC: [email protected]

(Pointless to carry Cc line when patch is already reviewed next line)

Quoted 44 lines
---
 accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added tags.

accel/kvm/kvm-all.c +3 -3
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
     QLIST_INIT(&s->kvm_parked_vcpus);
     s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
     if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
         ret = -errno;
         goto err;
     }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
         if (ret >= 0) {
             ret = -EINVAL;
         }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
         goto err;
     }
       if (ret > KVM_API_VERSION) {
         ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
         goto err;
     }
 @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
     } while (ret == -EINTR);
       if (ret < 0) {
accel/kvm/kvm-all.c +2 -2
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
   #ifdef TARGET_S390X
         if (ret == -EINVAL) {

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 10 lines
accel/kvm/kvm-all.c +1 -9
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please verify:\n");
-            fprintf(stderr, "- for kernels supporting the switch_amode or"
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address space\n");
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste sysctl, "
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected.

\n"

Quoted 8 lines

Should we use error_printf_unless_qmp() for the following?

" Please verify:");

Quoted 5 lines
accel/kvm/kvm-all.c +5 -0
+            error_report("- for kernels supporting the switch_amode or"
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address space");
+            error_report("- for kernels supporting the vm.allocate_pgste "
+                        "sysctl, whether it is enabled");

Do not put newlines into error messages. error_report()'s function comment demands "The resulting message should be a single phrase, with no newline or trailing punctuation."

Quoted 6 lines

You can do this:

   error_report(... the actual error message ...);
   error_printf(... hints on what to do about it ...);

Questions?

Do you see any newlines in my proposed patch?

#8 lore raw
Quoted 84 lines · Ani Sinha
Quoted 84 lines · Markus Armbruster
Quoted 67 lines · Philippe Mathieu-Daudé

Hi Ani,

Quoted 4 lines · Ani Sinha

error_report() is more appropriate for error situations. Replace fprintf with error_report. Cosmetic. No functional change.
CC: [email protected]
CC: [email protected]

(Pointless to carry Cc line when patch is already reviewed next line)

Quoted 44 lines
---
 accel/kvm/kvm-all.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

changelog:
v2: fix a bug.
v3: replace one instance of error_report() with error_printf(). added tags.

accel/kvm/kvm-all.c +3 -3
index 75d11a07b2..5bc9d35b61 100644
@@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms)
     QLIST_INIT(&s->kvm_parked_vcpus);
     s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
     if (s->fd == -1) {
-        fprintf(stderr, "Could not access KVM kernel module: %m\n");
+        error_report("Could not access KVM kernel module: %m");
         ret = -errno;
         goto err;
     }
@@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms)
         if (ret >= 0) {
             ret = -EINVAL;
         }
-        fprintf(stderr, "kvm version too old\n");
+        error_report("kvm version too old");
         goto err;
     }
       if (ret > KVM_API_VERSION) {
         ret = -EINVAL;
-        fprintf(stderr, "kvm version not supported\n");
+        error_report("kvm version not supported");
         goto err;
     }
 @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms)
     } while (ret == -EINTR);
       if (ret < 0) {
accel/kvm/kvm-all.c +2 -2
-        fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret,
-                strerror(-ret));
+        error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret,
+                    strerror(-ret));
   #ifdef TARGET_S390X
         if (ret == -EINVAL) {

accel/kvm/kvm-all.c static int kvm_init(MachineState *ms)

Quoted 10 lines
accel/kvm/kvm-all.c +1 -9
-            fprintf(stderr,
-                    "Host kernel setup problem detected. Please verify:\n");
-            fprintf(stderr, "- for kernels supporting the switch_amode or"
-                    " user_mode parameters, whether\n");
-            fprintf(stderr,
-                    "  user space is running in primary address space\n");
-            fprintf(stderr,
-                    "- for kernels supporting the vm.allocate_pgste sysctl, "
-                    "whether it is enabled\n");
+            error_report("Host kernel setup problem detected.

\n"

Quoted 8 lines

Should we use error_printf_unless_qmp() for the following?

" Please verify:");

Quoted 5 lines
accel/kvm/kvm-all.c +5 -0
+            error_report("- for kernels supporting the switch_amode or"
+                        " user_mode parameters, whether");
+            error_report("  user space is running in primary address space");
+            error_report("- for kernels supporting the vm.allocate_pgste "
+                        "sysctl, whether it is enabled");

Do not put newlines into error messages. error_report()'s function comment demands "The resulting message should be a single phrase, with no newline or trailing punctuation."

Quoted 8 lines
Quoted 6 lines

You can do this:

   error_report(... the actual error message ...);
   error_printf(... hints on what to do about it ...);

Questions?

Do you see any newlines in my proposed patch?

I see some in Philippe's suggestion.

Your patch's use of multiple error_report() for a single error condition is inappropriate.

Questions?