Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp130746pxa; Mon, 10 Aug 2020 21:20:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOaG5KR2GphZpJUJovCNNrnHaVxpEOIWdOST+jhW+X8m4CupAyxG44FMeSoMv1X6Bknl66 X-Received: by 2002:a17:906:fa19:: with SMTP id lo25mr17630519ejb.456.1597119644551; Mon, 10 Aug 2020 21:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597119644; cv=none; d=google.com; s=arc-20160816; b=G4zihUBIhyPNMZ8NGNeKHoc6Gi/suXVIs/ZA4415CpCfyEZaWiPFqom4dwLMut5nmL bZdF5jGPNuuDJN9RobiUCFvgrquuw8SivEcO7K2k4JNBTLkL4tTy0JSLaiPBQtLTqo0S B+IzXXOUqT6+gttkjNn9oL/EzCLy8F2/QKBqI3qj1VUSX6gX7WTSeEQk9n2I2NwKJxYY lCXX/mSaVFMTGAFMRtMhZgITbn/oc7ZxeDyBHw3QpqBUt8DfMGZiuvt3dE1h4NoKnRru rKWt+aj4SuzdsLJVzAFI1rKgMgRfN9EJLA5jAQ8v3vqgkcBP1ktwAuyF8ZD4QQJJ0MSS 9iNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LxFMQY6yV9KJaeeFf8I8vZLUhzeDpcXVO+YmYobioIM=; b=wrvCwU5f+lvgEt7AC/IlD/ZWzbAMHjIEe/je3xSGQw67G1OQ4aMIoa7U0w7R041/ic DMAHmr4J1B6ut5iR67pFh3Pg7AvgsCz9muTcFIaSp5wpM8tBM+O4l9mpBDZMb5pG7aXI XtD4Lmev+ItK7AQZs4JTzD5emTknfL3vUL/0ZV3RKhGGnOHzS84VW8z7kJFFlS4ibgdK 6M4YULVyNd0SHaj9qNMsk4x2cZ4pTekNTjYk88PAndGqpWCbiY499UOPZqzohrYWyfpK vaf48m+9w992tav1P61CDdJC9L+eM5GuWDdpogkv9pmhz3yV/W4cVK5OUJf2w//JBtqZ Izvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=WH64YnKM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o5si11782287ejx.202.2020.08.10.21.20.21; Mon, 10 Aug 2020 21:20:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=WH64YnKM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbgHKETU (ORCPT + 99 others); Tue, 11 Aug 2020 00:19:20 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:33701 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbgHKETU (ORCPT ); Tue, 11 Aug 2020 00:19:20 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BQfjf3pLbz9sTS; Tue, 11 Aug 2020 14:19:18 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1597119558; bh=2NZiS/B9GDmUuTZl+DIdhj2fNIhZ6RGfvaIFICHqFSM=; h=From:To:Cc:Subject:Date:From; b=WH64YnKMptRO4Eox2YloZbysBg7ADBHWYMCYZMpjNkFkZ7mEP/KxNx5G3tL1CKXQu uhBEtjcHOmb30U2vTPlkz9eIoTSffzJN8sLu7PUF5NjsEsY4f3vQru3UoQGzwgIqFU 0ONoy5meOvv+eWlw4dGBg3SCcKueEgHNmY1/1gNM= From: David Gibson To: paulus@samba.org, mpe@ellerman.id.au Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, David Gibson Subject: [PATCH] powerpc: kvm: Increase HDEC threshold to enter guest Date: Tue, 11 Aug 2020 14:08:34 +1000 Message-Id: <20200811040834.45930-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before entering a guest, we need to set the HDEC to pull us out again when the guest's time is up. This needs some care, though, because the HDEC is edge triggered, which means that if it expires before entering the guest, the interrupt will be lost, meaning we stay in the guest indefinitely (in practice, until the the hard lockup detector pulls us out with an NMI). For the POWER9, independent threads mode specific path, we attempt to prevent that, by testing time has already expired before setting the HDEC in kvmhv_load_regs_and_go(). However, that doesn't account for the case where the timer expires between that test and the actual guest entry. Preliminary instrumentation suggests that can take as long as 1.5µs under certain load conditions, and simply checking the HDEC value we're going to load is positive isn't enough to guarantee that leeway. That test here is sometimes masked by a test in kvmhv_p9_guest_entry(), its caller. That checks that the remaining time is at 1µs. However as noted above that doesn't appear to be sufficient in all circumstances even from the point HDEC is set, let alone this earlier point. Therefore, increase the threshold we check for in both locations to 4µs (2048 timebase ticks). This is a pretty crude approach, but it addresses a real problem where guest load can trigger a host hard lockup. We're hoping to refine this in future by gathering more data on exactly how long these paths can take, and possibly by moving the check closer to the actual guest entry point to reduce the variance. Getting the details for that might take some time however. NOTE: For reasons I haven't yet tracked down yet, I haven't actually managed to reproduce this on current upstream. I have reproduced it on RHEL kernels without obvious differences in this area. I'm still trying to determine what the cause of that difference is, but I think it's worth applying this change as a precaution in the interim. Signed-off-by: David Gibson --- arch/powerpc/kvm/book3s_hv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 0f83f39a2bd2..65a92dd890cb 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3435,7 +3435,7 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long host_pidr = mfspr(SPRN_PID); hdec = time_limit - mftb(); - if (hdec < 0) + if (hdec < 2048) return BOOK3S_INTERRUPT_HV_DECREMENTER; mtspr(SPRN_HDEC, hdec); @@ -3564,7 +3564,7 @@ int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, dec = mfspr(SPRN_DEC); tb = mftb(); - if (dec < 512) + if (dec < 2048) return BOOK3S_INTERRUPT_HV_DECREMENTER; local_paca->kvm_hstate.dec_expires = dec + tb; if (local_paca->kvm_hstate.dec_expires < time_limit) -- 2.26.2