From nobody Sat Oct 25 21:42:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521156553346539.8617174429999; Thu, 15 Mar 2018 16:29:13 -0700 (PDT) Received: from localhost ([::1]:53807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewcJ6-0003rD-HI for importer@patchew.org; Thu, 15 Mar 2018 19:29:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewcFd-0001Y0-Rs for qemu-devel@nongnu.org; Thu, 15 Mar 2018 19:25:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewcFa-0000EZ-MA for qemu-devel@nongnu.org; Thu, 15 Mar 2018 19:25:37 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42778 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewcFa-0000EK-FE for qemu-devel@nongnu.org; Thu, 15 Mar 2018 19:25:34 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2FNLLwt002405 for ; Thu, 15 Mar 2018 19:25:34 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gr0f3497s-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 15 Mar 2018 19:25:33 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 15 Mar 2018 17:25:31 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 15 Mar 2018 17:25:27 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2FNPQI911403546; Thu, 15 Mar 2018 16:25:26 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 430EB136044; Thu, 15 Mar 2018 17:25:26 -0600 (MDT) Received: from localhost.localdomain (unknown [9.80.217.151]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTPS id E31FD13603A; Thu, 15 Mar 2018 17:25:23 -0600 (MDT) From: Tony Krowiak To: qemu-devel@nongnu.org Date: Thu, 15 Mar 2018 19:24:59 -0400 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1521156300-19296-1-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1521156300-19296-1-git-send-email-akrowiak@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031523-0008-0000-0000-00000976DF58 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008681; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000254; SDB=6.01003605; UDB=6.00510771; IPR=6.00782931; MB=3.00020058; MTD=3.00000008; XFM=3.00000015; UTC=2018-03-15 23:25:30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031523-0009-0000-0000-00004668E032 Message-Id: <1521156300-19296-7-git-send-email-akrowiak@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-15_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803150253 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3 6/7] s390x/kvm: handle AP instruction interception X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mjrosato@linux.vnet.ibm.com, peter.maydell@linaro.org, pasic@linux.vnet.ibm.com, alifm@linux.vnet.ibm.com, eskultet@redhat.com, david@redhat.com, pmorel@linux.vnet.ibm.com, cohuck@redhat.com, heiko.carstens@de.ibm.com, alex.williamson@redhat.com, agraf@suse.de, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, akrowiak@linux.vnet.ibm.com, jjherne@linux.vnet.ibm.com, schwidefsky@de.ibm.com, pbonzini@redhat.com, bjsdjshi@linux.vnet.ibm.com, eric.auger@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the CPU model indicates that AP facility is installed on the guest (i.e., -cpu xxxx,ap=3Don), then the expectation is that the AP bus running in the guest will initialize; however, if the AP instructions are not being interpreted by the firmware, then they will be intercepted and routed back to QEMU for handling. If a handler is not defined to process the intercepted instruciton, then an operation exception will be injected into the guest, in which case the AP bus will not initialize. There are two situations where AP instructions will not be interpreted: 1. The guest is not configured with a vfio-ap device (i.e., -device vfio-ap,sysfsdev=3D$path-to-mdev). The realize function for the vfio-ap device enables interpretive execution of AP instructions. 2. The guest is a second level guest but the first level guest has not enabled interpretive execution. This patch introduces AP instruction handlers to ensure the AP bus module initializes on the guest when the AP facility is installed on the guest but AP instructions are not being interpreted. The logic incorporated is: * If the CPU model indicates AP instructions are installed * Set the status response code for the instruction to indicate that the APQN contained in the instruction is not valid. This is a valid response because there will be no devices configured for the guest in any of the above scenarios. * Else return an error from the handler. This will result in an operation being injected into the guest and the AP bus will not initialize on the guest. That is commensurate with how things work today. Signed-off-by: Tony Krowiak --- hw/vfio/ap.c | 45 ++++++++++++++++++++++++++++++++++++++= ++++ include/hw/s390x/ap-device.h | 6 +++++ target/s390x/kvm.c | 14 +++++++++++++ 3 files changed, 65 insertions(+), 0 deletions(-) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index b397bb1..88e744d 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -148,6 +148,51 @@ static void vfio_ap_unrealize(DeviceState *dev, Error = **errp) kvm_s390_set_interpret_ap(0); } =20 +int ap_device_handle_nqap(S390CPU *cpu) +{ + CPUS390XState *env =3D &cpu->env; + + if (s390_has_feat(S390_FEAT_AP)) { + env->regs[1] =3D 0x10000; + + return 0; + } + + return -EOPNOTSUPP; +} + +int ap_device_handle_dqap(S390CPU *cpu) +{ + CPUS390XState *env =3D &cpu->env; + + if (s390_has_feat(S390_FEAT_AP)) { + env->regs[1] =3D 0x10000; + + return 0; + } + + return -EOPNOTSUPP; +} + +int ap_device_handle_pqap(S390CPU *cpu) +{ + CPUS390XState *env =3D &cpu->env; + int fc =3D 4 & (env->regs[0] >> 24); + + /* + * The Query Configuration Information (QCI) function (fc =3D=3D 4) do= es not + * set a response code in reg 1, so check for that along with the + * AP feature. + */ + if ((fc !=3D 4) && s390_has_feat(S390_FEAT_AP)) { + env->regs[1] =3D 0x10000; + + return 0; + } + + return -EOPNOTSUPP; +} + static Property vfio_ap_properties[] =3D { DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev), DEFINE_PROP_END_OF_LIST(), diff --git a/include/hw/s390x/ap-device.h b/include/hw/s390x/ap-device.h index 693df90..d45ae38 100644 --- a/include/hw/s390x/ap-device.h +++ b/include/hw/s390x/ap-device.h @@ -11,6 +11,8 @@ #ifndef HW_S390X_AP_DEVICE_H #define HW_S390X_AP_DEVICE_H =20 +#include "cpu.h" + #define AP_DEVICE_TYPE "ap-device" =20 typedef struct APDevice { @@ -35,4 +37,8 @@ static inline APDevice *to_ap_dev(DeviceState *dev) #define AP_DEVICE_CLASS(klass) \ OBJECT_CLASS_CHECK(APDeviceClass, (klass), AP_DEVICE_TYPE) =20 +int ap_device_handle_nqap(S390CPU *cpu); +int ap_device_handle_dqap(S390CPU *cpu); +int ap_device_handle_pqap(S390CPU *cpu); + #endif /* HW_S390X_AP_DEVICE_H */ diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index 2812e28..a636394 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -50,6 +50,7 @@ #include "exec/memattrs.h" #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/ap-device.h" =20 #ifndef DEBUG_KVM #define DEBUG_KVM 0 @@ -88,6 +89,9 @@ #define PRIV_B2_CHSC 0x5f #define PRIV_B2_SIGA 0x74 #define PRIV_B2_XSCH 0x76 +#define PRIV_B2_NQAP 0xad +#define PRIV_B2_DQAP 0xae +#define PRIV_B2_PQAP 0xaf =20 #define PRIV_EB_SQBS 0x8a #define PRIV_EB_PCISTB 0xd0 @@ -1245,6 +1249,16 @@ static int handle_b2(S390CPU *cpu, struct kvm_run *r= un, uint8_t ipa1) case PRIV_B2_SCLP_CALL: rc =3D kvm_sclp_service_call(cpu, run, ipbh0); break; + case PRIV_B2_NQAP: + rc =3D ap_device_handle_nqap(cpu); + break; + case PRIV_B2_DQAP: + rc =3D ap_device_handle_dqap(cpu); + break; + case PRIV_B2_PQAP: + rc =3D ap_device_handle_pqap(cpu); + break; + break; default: rc =3D -1; DPRINTF("KVM: unhandled PRIV: 0xb2%x\n", ipa1); --=20 1.7.1