From patchwork Mon Feb 5 10:40:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10200109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 719C660247 for ; Mon, 5 Feb 2018 10:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F10C286A4 for ; Mon, 5 Feb 2018 10:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 537A4286F2; Mon, 5 Feb 2018 10:40:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0646286A4 for ; Mon, 5 Feb 2018 10:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752574AbeBEKki (ORCPT ); Mon, 5 Feb 2018 05:40:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46550 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752253AbeBEKkg (ORCPT ); Mon, 5 Feb 2018 05:40:36 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24DDDC047B97; Mon, 5 Feb 2018 10:40:36 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-199.ams2.redhat.com [10.36.116.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3ED82A2C6; Mon, 5 Feb 2018 10:40:30 +0000 (UTC) From: David Hildenbrand To: linux-s390@vger.kernel.org, kvm@vger.kernel.org Cc: Christian Borntraeger , Cornelia Huck , Janosch Frank , David Hildenbrand Subject: [PATCH v2] KVM: s390: take care of clock-comparator sign control Date: Mon, 5 Feb 2018 11:40:30 +0100 Message-Id: <20180205104030.643-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 05 Feb 2018 10:40:36 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Missed when enabling the Multiple-epoch facility. If the facility is installed and the control is set, a sign based comaprison has to be performed. Right now we would inject wrong interrupts and ignore interrupt conditions. Also the sleep time is calculated in a wrong way. Signed-off-by: David Hildenbrand --- We might be able to drop the checks for "test_kvm_facility(vcpu->kvm, 139)", as the architecture states: "When the multiple-epoch facility is not installed in the configuration and the clock-comparator sign control is one, it is unpredictable whether the comparison follows the rules of unsigned or signed binary arithmetic." Have no machine to test this with :( arch/s390/kvm/interrupt.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 024ad8bcc516..6566a853c0b8 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -170,7 +170,16 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu) static int ckc_irq_pending(struct kvm_vcpu *vcpu) { - if (vcpu->arch.sie_block->ckc >= kvm_s390_get_tod_clock_fast(vcpu->kvm)) + int64_t ckc, tod; + + if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul && + test_kvm_facility(vcpu->kvm, 139)) { + ckc = vcpu->arch.sie_block->ckc; + tod = kvm_s390_get_tod_clock_fast(vcpu->kvm); + if (ckc >= tod) + return 0; + } else if (vcpu->arch.sie_block->ckc >= + kvm_s390_get_tod_clock_fast(vcpu->kvm)) return 0; return ckc_interrupts_enabled(vcpu); } @@ -1011,13 +1020,24 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) static u64 __calculate_sltime(struct kvm_vcpu *vcpu) { - u64 now, cputm, sltime = 0; + u64 now, cputm, ckc, sltime = 0; + int64_t ckc_signed, now_signed; if (ckc_interrupts_enabled(vcpu)) { - now = kvm_s390_get_tod_clock_fast(vcpu->kvm); - sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); - /* already expired or overflow? */ - if (!sltime || vcpu->arch.sie_block->ckc <= now) + if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul && + test_kvm_facility(vcpu->kvm, 139)) { + now = kvm_s390_get_tod_clock_fast(vcpu->kvm); + ckc = vcpu->arch.sie_block->ckc; + if (ckc < now) + sltime = tod_to_ns(now - ckc); + } else { + now_signed = kvm_s390_get_tod_clock_fast(vcpu->kvm); + ckc_signed = vcpu->arch.sie_block->ckc; + if (ckc_signed < now_signed) + sltime = tod_to_ns(now_signed - ckc_signed); + } + /* already expired */ + if (!sltime) return 0; if (cpu_timer_interrupts_enabled(vcpu)) { cputm = kvm_s390_get_cpu_timer(vcpu);