From nobody Tue Feb 10 10:54:07 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1507114997272862.1230881727208; Wed, 4 Oct 2017 04:03:17 -0700 (PDT) Received: from localhost ([::1]:34352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhS7-0001Oq-GO for importer@patchew.org; Wed, 04 Oct 2017 07:02:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhNQ-00061d-Gt for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:58:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhNL-0005IW-FF for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:58:08 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhNK-0005Gq-UO for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:58:03 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v94AsKdO042977 for ; Wed, 4 Oct 2017 06:57:59 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dcvrkw5rw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 04 Oct 2017 06:57:59 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Oct 2017 11:57:56 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Oct 2017 11:57:53 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v94AvqeT23199894; Wed, 4 Oct 2017 10:57:52 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 728CFA4040; Wed, 4 Oct 2017 11:53:35 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D471A404D; Wed, 4 Oct 2017 11:53:35 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 4 Oct 2017 11:53:35 +0100 (BST) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id 5BE2820F62E; Wed, 4 Oct 2017 12:57:52 +0200 (CEST) From: Christian Borntraeger To: Cornelia Huck Date: Wed, 4 Oct 2017 12:57:50 +0200 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20171004105751.24655-1-borntraeger@de.ibm.com> References: <20171004105751.24655-1-borntraeger@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17100410-0012-0000-0000-0000057E5733 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100410-0013-0000-0000-000018F7C575 Message-Id: <20171004105751.24655-2-borntraeger@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-04_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710040157 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 1/2] s390/kvm: Support for get/set of extended TOD-Clock for guest 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: Thomas Huth , David Hildenbrand , qemu-devel , Alexander Graf , Christian Borntraeger , "Collin L. Walling" , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Collin L. Walling" Provides an interface for getting and setting the guest's extended TOD-Clock via a single ioctl to kvm. If the ioctl fails because it is not support by kvm, then we fall back to the old style of retrieving the clock via two ioctls. Signed-off-by: Collin L. Walling Reviewed-by: Eric Farman Reviewed-by: Claudio Imbrenda Signed-off-by: Christian Borntraeger [split failure change from epoch index change] Reviewed-by: Thomas Huth --- target/s390x/cpu.c | 26 +++++++++++++++++++------- target/s390x/kvm-stub.c | 10 ++++++++++ target/s390x/kvm.c | 35 ++++++++++++++++++++++++++++++++++- target/s390x/kvm_s390x.h | 2 ++ 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 34538c3..c8f1219 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -357,22 +357,34 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S3= 90CPU *cpu) =20 int s390_get_clock(uint8_t *tod_high, uint64_t *tod_low) { + int r =3D 0; + if (kvm_enabled()) { - return kvm_s390_get_clock(tod_high, tod_low); + r =3D kvm_s390_get_clock_ext(tod_high, tod_low); + if (r =3D=3D -ENXIO) { + return kvm_s390_get_clock(tod_high, tod_low); + } + } else { + /* Fixme TCG */ + *tod_high =3D 0; + *tod_low =3D 0; } - /* Fixme TCG */ - *tod_high =3D 0; - *tod_low =3D 0; - return 0; + + return r; } =20 int s390_set_clock(uint8_t *tod_high, uint64_t *tod_low) { + int r =3D 0; + if (kvm_enabled()) { - return kvm_s390_set_clock(tod_high, tod_low); + r =3D kvm_s390_set_clock_ext(tod_high, tod_low); + if (r =3D=3D -ENXIO) { + return kvm_s390_set_clock(tod_high, tod_low); + } } /* Fixme TCG */ - return 0; + return r; } =20 int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit) diff --git a/target/s390x/kvm-stub.c b/target/s390x/kvm-stub.c index 261e1cd..43f02c2 100644 --- a/target/s390x/kvm-stub.c +++ b/target/s390x/kvm-stub.c @@ -68,11 +68,21 @@ int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod= _low) return -ENOSYS; } =20 +int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_low) +{ + return -ENOSYS; +} + int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low) { return -ENOSYS; } =20 +int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_low) +{ + return -ENOSYS; +} + void kvm_s390_enable_css_support(S390CPU *cpu) { } diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index ebb75ca..4c944a5 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -643,10 +643,27 @@ int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *t= od_low) return kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr); } =20 +int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_low) +{ + int r; + struct kvm_s390_vm_tod_clock gtod; + + struct kvm_device_attr attr =3D { + .group =3D KVM_S390_VM_TOD, + .attr =3D KVM_S390_VM_TOD_EXT, + .addr =3D (uint64_t)(>od), + }; + + r =3D kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr); + *tod_high =3D gtod.epoch_idx; + *tod_low =3D gtod.tod; + + return r; +} + int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low) { int r; - struct kvm_device_attr attr =3D { .group =3D KVM_S390_VM_TOD, .attr =3D KVM_S390_VM_TOD_LOW, @@ -663,6 +680,22 @@ int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *to= d_low) return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr); } =20 +int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_low) +{ + struct kvm_s390_vm_tod_clock gtod =3D { + .epoch_idx =3D *tod_high, + .tod =3D *tod_low, + }; + + struct kvm_device_attr attr =3D { + .group =3D KVM_S390_VM_TOD, + .attr =3D KVM_S390_VM_TOD_EXT, + .addr =3D (uint64_t)(>od), + }; + + return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr); +} + /** * kvm_s390_mem_op: * @addr: the logical start address in guest memory diff --git a/target/s390x/kvm_s390x.h b/target/s390x/kvm_s390x.h index 2d594bd..501fc5a 100644 --- a/target/s390x/kvm_s390x.h +++ b/target/s390x/kvm_s390x.h @@ -29,7 +29,9 @@ int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu); int kvm_s390_get_ri(void); int kvm_s390_get_gs(void); int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_clock); +int kvm_s390_get_clock_ext(uint8_t *tod_high, uint64_t *tod_clock); int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_clock); +int kvm_s390_set_clock_ext(uint8_t *tod_high, uint64_t *tod_clock); void kvm_s390_enable_css_support(S390CPU *cpu); int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, int vq, bool assign); --=20 2.9.4