Skip to contentSkip to conversation

s390x/pv: Retry ioctls on -EINTR

PATCH Superseded Christian Borntraeger 3 participants 7 messages Mar 27, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/pv: Retry ioctls on -EINTR

PV_ENABLE (and maybe others) might return -EINTR when a signal is pending. Let us retry the ioctl in that case.

Fixes 4d226deafc44 ("s390x: protvirt: Support unpack facility")
---
 hw/s390x/pv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/pv.c +5 -1
index 8cf5cd2c9b..2758b02c96 100644
@@ -23,7 +23,11 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
         .cmd = cmd,
         .data = (uint64_t)data,
     };
-    int rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    int rc;
+
+    do {
+        rc  = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    } while (rc == -EINTR);
 
     if (rc) {
         error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "
Signature · 1 line
2.25.1
#1 lore raw
Quoted 19 lines · Christian Borntraeger

PV_ENABLE (and maybe others) might return -EINTR when a signal is pending. Let us retry the ioctl in that case.

Fixes 4d226deafc44 ("s390x: protvirt: Support unpack facility")
---
 hw/s390x/pv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/pv.c +0 -0
index 8cf5cd2c9b..2758b02c96 100644
@@ -23,7 +23,11 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
         .cmd = cmd,
         .data = (uint64_t)data,

hw/s390x/pv.c static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) · line 33

Quoted 10 lines
hw/s390x/pv.c +5 -1
     };
-    int rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    int rc;
+
+    do {
+        rc  = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    } while (rc == -EINTR);
 
     if (rc) {
         error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "

I fail to see where that is triggered in the kernel.

t480s: ~/git/linux/arch/s390/kvm (HEAD losgelöst bei next/master) $ git grep "EINTR"

kvm-s390.c:     if (exit_reason == -EINTR) {
kvm-s390.c:             return -EINTR;
kvm-s390.c:             rc = -EINTR;
vsie.c: if (rc == -EINTR) {

Can you help me out? Is that documented?

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
Quoted 35 lines · David Hildenbrand
Quoted 19 lines · Christian Borntraeger

PV_ENABLE (and maybe others) might return -EINTR when a signal is pending. Let us retry the ioctl in that case.

Fixes 4d226deafc44 ("s390x: protvirt: Support unpack facility")
---
 hw/s390x/pv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/pv.c +0 -0
index 8cf5cd2c9b..2758b02c96 100644
@@ -23,7 +23,11 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
         .cmd = cmd,
         .data = (uint64_t)data,

hw/s390x/pv.c static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) · line 33

Quoted 10 lines
hw/s390x/pv.c +5 -1
     };
-    int rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    int rc;
+
+    do {
+        rc  = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    } while (rc == -EINTR);
 
     if (rc) {
         error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "

I fail to see where that is triggered in the kernel.

t480s: ~/git/linux/arch/s390/kvm (HEAD losgelöst bei next/master) $ git grep "EINTR"

Quoted 7 lines
kvm-s390.c:     if (exit_reason == -EINTR) {
kvm-s390.c:             return -EINTR;
kvm-s390.c:             rc = -EINTR;
vsie.c: if (rc == -EINTR) {

Can you help me out? Is that documented?

It is related to the kernel patch.
ksm_madvise->unmerge_ksm_pages has

                if (signal_pending(current))
                        err = -ERESTARTSYS;

entry.S will retranslate ERESTARTSYS into -EINTR.

#3 lore raw
Quoted 46 lines · Christian Borntraeger
Quoted 35 lines · David Hildenbrand
Quoted 19 lines · Christian Borntraeger

PV_ENABLE (and maybe others) might return -EINTR when a signal is pending. Let us retry the ioctl in that case.

Fixes 4d226deafc44 ("s390x: protvirt: Support unpack facility")
---
 hw/s390x/pv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/pv.c +0 -0
index 8cf5cd2c9b..2758b02c96 100644
@@ -23,7 +23,11 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
         .cmd = cmd,
         .data = (uint64_t)data,

hw/s390x/pv.c static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) · line 33

Quoted 10 lines
hw/s390x/pv.c +5 -1
     };
-    int rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    int rc;
+
+    do {
+        rc  = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    } while (rc == -EINTR);
 
     if (rc) {
         error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "

I fail to see where that is triggered in the kernel.

t480s: ~/git/linux/arch/s390/kvm (HEAD losgelöst bei next/master) $ git grep "EINTR"

Quoted 7 lines
kvm-s390.c:     if (exit_reason == -EINTR) {
kvm-s390.c:             return -EINTR;
kvm-s390.c:             rc = -EINTR;
vsie.c: if (rc == -EINTR) {

Can you help me out? Is that documented?

Quoted 8 lines

It is related to the kernel patch.
ksm_madvise->unmerge_ksm_pages has

                if (signal_pending(current))
                        err = -ERESTARTSYS;

entry.S will retranslate ERESTARTSYS into -EINTR.

That's valuable information that should go into the patch description. Also, the documentation should be updated to reflect this. Not obvious :)

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
In reply to Christian Borntraeger
Quoted 12 lines
Quoted 11 lines

I fail to see where that is triggered in the kernel.

t480s: ~/git/linux/arch/s390/kvm (HEAD losgelöst bei next/master) $ git grep "EINTR"

kvm-s390.c:     if (exit_reason == -EINTR) {
kvm-s390.c:             return -EINTR;
kvm-s390.c:             rc = -EINTR;
vsie.c: if (rc == -EINTR) {

Can you help me out? Is that documented?

Quoted 9 lines

It is related to the kernel patch.
ksm_madvise->unmerge_ksm_pages has

                if (signal_pending(current))
                        err = -ERESTARTSYS;

entry.S will retranslate ERESTARTSYS into -EINTR.

In the end both patches fixes an odd-ball case. Marc had a test running that in parallel started guests and randomly killing QEMUs with pkill. The QEMUs did end with

qemu-system-s390x: KVM PV command 0 (KVM_PV_ENABLE) failed: header rc 0 rrc 0 IOCTL rc: -12

instead of

qemu-system-s390x: terminating on signal 15 from pid 26495 (pkill)

#5 lore raw
Quoted 26 lines · Christian Borntraeger
Quoted 12 lines
Quoted 11 lines

I fail to see where that is triggered in the kernel.

t480s: ~/git/linux/arch/s390/kvm (HEAD losgelöst bei next/master) $ git grep "EINTR"

kvm-s390.c:     if (exit_reason == -EINTR) {
kvm-s390.c:             return -EINTR;
kvm-s390.c:             rc = -EINTR;
vsie.c: if (rc == -EINTR) {

Can you help me out? Is that documented?

Quoted 9 lines

It is related to the kernel patch.
ksm_madvise->unmerge_ksm_pages has

                if (signal_pending(current))
                        err = -ERESTARTSYS;

entry.S will retranslate ERESTARTSYS into -EINTR.

In the end both patches fixes an odd-ball case. Marc had a test running that in parallel started guests and randomly killing QEMUs with pkill. The QEMUs did end with

Quoted 6 lines

qemu-system-s390x: KVM PV command 0 (KVM_PV_ENABLE) failed: header rc 0 rrc 0 IOCTL rc: -12

instead of

qemu-system-s390x: terminating on signal 15 from pid 26495 (pkill)

I guess the same can happen with a qemu_cpu_kick(), just that the BQL protects us from that to happen concurrently.

Signature · 3 lines
Thanks,

David / dhildenb
Acked-by on v1 1/1
#6 lore raw
In reply to Christian Borntraeger
Quoted 7 lines · Christian Borntraeger

PV_ENABLE (and maybe others) might return -EINTR when a signal is pending. Let us retry the ioctl in that case.

Fixes 4d226deafc44 ("s390x: protvirt: Support unpack facility")
Quoted 9 lines
---
 hw/s390x/pv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/pv.c +0 -0
index 8cf5cd2c9b..2758b02c96 100644

hw/s390x/pv.c static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) · line 29

Quoted 8 lines
hw/s390x/pv.c +4 -1
@@ -23,7 +23,11 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
         .cmd = cmd,
         .data = (uint64_t)data,
     };
-    int rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
+    int rc;
+
+    do {
+        rc  = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);

Double whitespace after rc.

Quoted 5 lines
hw/s390x/pv.c +1 -0
+    } while (rc == -EINTR);
 
     if (rc) {
         error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "