yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390x-protvirt-Disable-address-checks-for-PV-guest-I.patch

902636
From 1cfcff169f392179258e4535e60d4ef9cabae3c6 Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 29 May 2020 05:54:13 -0400
902636
Subject: [PATCH 31/42] s390x: protvirt: Disable address checks for PV guest IO
902636
 emulation
902636
902636
RH-Author: Thomas Huth <thuth@redhat.com>
902636
Message-id: <20200529055420.16855-32-thuth@redhat.com>
902636
Patchwork-id: 97044
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH v2 31/38] s390x: protvirt: Disable address checks for PV guest IO emulation
902636
Bugzilla: 1828317
902636
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Janosch Frank <frankja@linux.ibm.com>
902636
902636
IO instruction data is routed through SIDAD for protected guests, so
902636
adresses do not need to be checked, as this is kernel memory which is
902636
always available.
902636
902636
Also the instruction data always starts at offset 0 of the SIDAD.
902636
902636
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
902636
Reviewed-by: Thomas Huth <thuth@redhat.com>
902636
Reviewed-by: David Hildenbrand <david@redhat.com>
902636
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
902636
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
902636
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
902636
Message-Id: <20200319131921.2367-13-frankja@linux.ibm.com>
902636
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
902636
(cherry picked from commit c10b708752e5264a85b5c3afa0a0ccfcf6503ddf)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 target/s390x/ioinst.c | 35 ++++++++++++++++++++++++++++-------
902636
 1 file changed, 28 insertions(+), 7 deletions(-)
902636
902636
diff --git a/target/s390x/ioinst.c b/target/s390x/ioinst.c
902636
index c437a1d8c6..bbcccf6be2 100644
902636
--- a/target/s390x/ioinst.c
902636
+++ b/target/s390x/ioinst.c
902636
@@ -16,6 +16,25 @@
902636
 #include "hw/s390x/ioinst.h"
902636
 #include "trace.h"
902636
 #include "hw/s390x/s390-pci-bus.h"
902636
+#include "hw/s390x/pv.h"
902636
+
902636
+/* All I/O instructions but chsc use the s format */
902636
+static uint64_t get_address_from_regs(CPUS390XState *env, uint32_t ipb,
902636
+                                      uint8_t *ar)
902636
+{
902636
+    /*
902636
+     * Addresses for protected guests are all offsets into the
902636
+     * satellite block which holds the IO control structures. Those
902636
+     * control structures are always starting at offset 0 and are
902636
+     * always aligned and accessible. So we can return 0 here which
902636
+     * will pass the following address checks.
902636
+     */
902636
+    if (s390_is_pv()) {
902636
+        *ar = 0;
902636
+        return 0;
902636
+    }
902636
+    return decode_basedisp_s(env, ipb, ar);
902636
+}
902636
 
902636
 int ioinst_disassemble_sch_ident(uint32_t value, int *m, int *cssid, int *ssid,
902636
                                  int *schid)
902636
@@ -114,7 +133,7 @@ void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb, uintptr_t ra)
902636
     CPUS390XState *env = &cpu->env;
902636
     uint8_t ar;
902636
 
902636
-    addr = decode_basedisp_s(env, ipb, &ar);
902636
+    addr = get_address_from_regs(env, ipb, &ar);
902636
     if (addr & 3) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
         return;
902636
@@ -171,7 +190,7 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb, uintptr_t ra)
902636
     CPUS390XState *env = &cpu->env;
902636
     uint8_t ar;
902636
 
902636
-    addr = decode_basedisp_s(env, ipb, &ar);
902636
+    addr = get_address_from_regs(env, ipb, &ar);
902636
     if (addr & 3) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
         return;
902636
@@ -203,7 +222,7 @@ void ioinst_handle_stcrw(S390CPU *cpu, uint32_t ipb, uintptr_t ra)
902636
     CPUS390XState *env = &cpu->env;
902636
     uint8_t ar;
902636
 
902636
-    addr = decode_basedisp_s(env, ipb, &ar);
902636
+    addr = get_address_from_regs(env, ipb, &ar);
902636
     if (addr & 3) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
         return;
902636
@@ -234,7 +253,7 @@ void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb,
902636
     CPUS390XState *env = &cpu->env;
902636
     uint8_t ar;
902636
 
902636
-    addr = decode_basedisp_s(env, ipb, &ar);
902636
+    addr = get_address_from_regs(env, ipb, &ar);
902636
     if (addr & 3) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
         return;
902636
@@ -303,7 +322,7 @@ int ioinst_handle_tsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb, uintptr_t ra)
902636
         return -EIO;
902636
     }
902636
     trace_ioinst_sch_id("tsch", cssid, ssid, schid);
902636
-    addr = decode_basedisp_s(env, ipb, &ar);
902636
+    addr = get_address_from_regs(env, ipb, &ar);
902636
     if (addr & 3) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
         return -EIO;
902636
@@ -601,7 +620,7 @@ void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb, uintptr_t ra)
902636
 {
902636
     ChscReq *req;
902636
     ChscResp *res;
902636
-    uint64_t addr;
902636
+    uint64_t addr = 0;
902636
     int reg;
902636
     uint16_t len;
902636
     uint16_t command;
902636
@@ -610,7 +629,9 @@ void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb, uintptr_t ra)
902636
 
902636
     trace_ioinst("chsc");
902636
     reg = (ipb >> 20) & 0x00f;
902636
-    addr = env->regs[reg];
902636
+    if (!s390_is_pv()) {
902636
+        addr = env->regs[reg];
902636
+    }
902636
     /* Page boundary? */
902636
     if (addr & 0xfff) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
-- 
902636
2.27.0
902636