Received: by 10.223.185.116 with SMTP id b49csp5442080wrg; Wed, 7 Mar 2018 11:49:45 -0800 (PST) X-Google-Smtp-Source: AG47ELuJKA//7mdtLa5IPk/KnVdTgQdS15lcIutkCBD6HvsaHG9cgkky/8ysDYuUvt9naBBpJzOa X-Received: by 2002:a17:902:b58d:: with SMTP id a13-v6mr21918405pls.123.1520452185476; Wed, 07 Mar 2018 11:49:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520452185; cv=none; d=google.com; s=arc-20160816; b=tJvZx/e1hlgxVMZrbs0G791U/ytAOXDSz1VtT5hNNNvUzx9vJNH+krXNUN9eCwWWGN W6d3ngaBb1dptWDdcn172pEzozJKxIyvSvtbG4kiN0yAIEIGSu2DbpdI5AuGerSGPQQp G9wseWTKw03OYP6P3391Moxn+PTG2ESFcNNiHGbtRvfbScome8LSFPXXvDPqNyge8W+r 7ZZ0M++BqcfhcXEvgrMMjl1wDSKtzoC/I2GMCnf2g2qmCgw1U3tBKMnicsLHFaQeY99C uNu+fM/AEBLLYp4ElFTTdXaRlQHu2hzkH/qlM26Gi9I4SC9ipl6zvFjoWqntFDJjqbQI jzmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=P5mS3l/Z1dXm5+gkr+57UlS5lbimt4Eks3NS/Z0lPnY=; b=bPXoB0zx6iw9INbxw/27mx0AcgeQs/uhsEoAghRo0Y0ypW+nMCuUs9O0oSJEqy4Woz zyY6TRBWB5/kIOEfj3s7L5GNoc08ngjqrq3S6RL0JVdjWX8DcYkVivZtiE/dP15IrxSI xOc6bSxpIkwwNerRarOOx+rKYrWTOa7H0tfqjBSIRM7KBAkn1WLognx65VJ5F4gO/Nmi ZxFLJzpa7t/jKX+OoZOx3CRm70mo2OV5OVh/Oy8faepm/JlEgV9+t5Jc7M5XChWJPSwW EYeJeoXbtqlfAM44tMCuSdodFM4xJRbCm2zQawl6RNdxz2gdCu2oQV5NRLFDW1zMvIUS GMvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f35-v6si13445517plh.107.2018.03.07.11.49.31; Wed, 07 Mar 2018 11:49:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965986AbeCGTsj (ORCPT + 99 others); Wed, 7 Mar 2018 14:48:39 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45914 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965954AbeCGTsh (ORCPT ); Wed, 7 Mar 2018 14:48:37 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0F594EA6; Wed, 7 Mar 2018 19:48:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Christian Borntraeger Subject: [PATCH 4.14 089/110] KVM: s390: consider epoch index on TOD clock syncs Date: Wed, 7 Mar 2018 11:39:12 -0800 Message-Id: <20180307191051.269268206@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand commit 1575767ef3cf5326701d2ae3075b7732cbc855e4 upstream. For now, we don't take care of over/underflows. Especially underflows are critical: Assume the epoch is currently 0 and we get a sync request for delta=1, meaning the TOD is moved forward by 1 and we have to fix it up by subtracting 1 from the epoch. Right now, this will leave the epoch index untouched, resulting in epoch=-1, epoch_idx=0, which is wrong. We have to take care of over and underflows, also for the VSIE case. So let's factor out calculation into a separate function. Signed-off-by: David Hildenbrand Message-Id: <20180207114647.6220-5-david@redhat.com> Reviewed-by: Christian Borntraeger Fixes: 8fa1696ea781 ("KVM: s390: Multiple Epoch Facility support") Cc: stable@vger.kernel.org Signed-off-by: Christian Borntraeger [use u8 for idx] Signed-off-by: Greg Kroah-Hartman --- arch/s390/kvm/kvm-s390.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -169,6 +169,28 @@ int kvm_arch_hardware_enable(void) static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start, unsigned long end); +static void kvm_clock_sync_scb(struct kvm_s390_sie_block *scb, u64 delta) +{ + u8 delta_idx = 0; + + /* + * The TOD jumps by delta, we have to compensate this by adding + * -delta to the epoch. + */ + delta = -delta; + + /* sign-extension - we're adding to signed values below */ + if ((s64)delta < 0) + delta_idx = -1; + + scb->epoch += delta; + if (scb->ecd & ECD_MEF) { + scb->epdx += delta_idx; + if (scb->epoch < delta) + scb->epdx += 1; + } +} + /* * This callback is executed during stop_machine(). All CPUs are therefore * temporarily stopped. In order not to change guest behavior, we have to @@ -184,13 +206,17 @@ static int kvm_clock_sync(struct notifie unsigned long long *delta = v; list_for_each_entry(kvm, &vm_list, vm_list) { - kvm->arch.epoch -= *delta; kvm_for_each_vcpu(i, vcpu, kvm) { - vcpu->arch.sie_block->epoch -= *delta; + kvm_clock_sync_scb(vcpu->arch.sie_block, *delta); + if (i == 0) { + kvm->arch.epoch = vcpu->arch.sie_block->epoch; + kvm->arch.epdx = vcpu->arch.sie_block->epdx; + } if (vcpu->arch.cputm_enabled) vcpu->arch.cputm_start += *delta; if (vcpu->arch.vsie_block) - vcpu->arch.vsie_block->epoch -= *delta; + kvm_clock_sync_scb(vcpu->arch.vsie_block, + *delta); } } return NOTIFY_OK;