Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9938099ybi; Wed, 24 Jul 2019 12:40:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVAxJ9kifYrQebkl1bCXez0yaiMvDV7JH6KMxa9295h9fzlHsfUwCFasFSJXpjlqVjJqri X-Received: by 2002:a17:90a:109:: with SMTP id b9mr84733775pjb.112.1563997222499; Wed, 24 Jul 2019 12:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563997222; cv=none; d=google.com; s=arc-20160816; b=XAC0vC6luAQ5CNyRoFmzYMnhZ8v8DOhsOlnoXfrWqGq5iq0Zr7BQB8q7fNzdIaTRe2 cWHyakN4OK7da3QDqZOMuO/7+YUaZgB1y/wU9+D6BxlkGLGjH7NX0iwoP3JdRW30+5Gu DrtES1aRTR/lytATOcDyQJU2yG0+bFJpysYCZDxhKZueDXcpxas/uE5Iz583oySASeW7 PIVh5qha8KSv13G0M079iy/d1cvS5X+lk+0vCBZQtt/1j+UZDSnTWZaw09189lJSj7bK dMxObUCeUndPVpgEad8ztbp3VQ/f6cXXZwG/TBbF2N4P1zaLLyijpvak900iHsXzizg1 hQWg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wbU10SnltAaUxZ3yB1PS1+u38bX4lCstTiaRT6KKE0w=; b=OXWruFz+hAdPfVRpfOf92KSKpE6P9PldVlfNFA1TpOQzfNSKZGzTZMHnTjUepdAiTb VKWU35g9Bghx1JMdLLnTj8NLqhSRPzKtnMAWzrig+vFVZUf981Yxm7It3bXBwYQWjJYR xSvRVoAAZsVlIpQ1fZmhHOC9EawkcG7QILHkU61+xhRZOUnKVmN99vw5OkgFDvfu78Mh vhp5tPhfNVRJ/y9sgWnbzJY47J27PyqmfFpjIHZr2lYgulUiKy1l7ndUZrDesCdlh9+T w04ITL7YlKeFk11oUgoy9nFK6Nm6lWC0+wdhq2Ye2BWSLnHQfJwPjR8JTdxYWIjxPdKx ji6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QR3Fr5E5; 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 u2si14899607pgm.242.2019.07.24.12.40.08; Wed, 24 Jul 2019 12:40:22 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=QR3Fr5E5; 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 S2389837AbfGXTjA (ORCPT + 99 others); Wed, 24 Jul 2019 15:39:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:39892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389063AbfGXTi7 (ORCPT ); Wed, 24 Jul 2019 15:38:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 01170217D4; Wed, 24 Jul 2019 19:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997139; bh=7aBdbD0pAZ7cT7Z1XWB4rwLOq1yj8nUthLML5JV9tDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QR3Fr5E5MiA/fy0FLI+SuGS9S7ruhBsMmHbLYWGhROtSK41M0cxbjQ/xLzRBoxGEk TLC1tnHjdDheggylgiK9Ym2K6l0rm+QQ2RezmQOankdLSNxuQyBSrYeDURlhfjL8j4 +9vx1NrumRofinFqDKb4bsNQ+BHxKJ6BafaQwU08= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suraj Jitindar Singh , Michael Ellerman Subject: [PATCH 5.2 333/413] KVM: PPC: Book3S HV: Clear pending decrementer exceptions on nested guest entry Date: Wed, 24 Jul 2019 21:20:24 +0200 Message-Id: <20190724191759.646814518@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Suraj Jitindar Singh commit 3c25ab35fbc8526ac0c9b298e8a78e7ad7a55479 upstream. If we enter an L1 guest with a pending decrementer exception then this is cleared on guest exit if the guest has writtien a positive value into the decrementer (indicating that it handled the decrementer exception) since there is no other way to detect that the guest has handled the pending exception and that it should be dequeued. In the event that the L1 guest tries to run a nested (L2) guest immediately after this and the L2 guest decrementer is negative (which is loaded by L1 before making the H_ENTER_NESTED hcall), then the pending decrementer exception isn't cleared and the L2 entry is blocked since L1 has a pending exception, even though L1 may have already handled the exception and written a positive value for it's decrementer. This results in a loop of L1 trying to enter the L2 guest and L0 blocking the entry since L1 has an interrupt pending with the outcome being that L2 never gets to run and hangs. Fix this by clearing any pending decrementer exceptions when L1 makes the H_ENTER_NESTED hcall since it won't do this if it's decrementer has gone negative, and anyway it's decrementer has been communicated to L0 in the hdec_expires field and L0 will return control to L1 when this goes negative by delivering an H_DECREMENTER exception. Fixes: 95a6432ce903 ("KVM: PPC: Book3S HV: Streamlined guest entry/exit path on P9 for radix guests") Cc: stable@vger.kernel.org # v4.20+ Signed-off-by: Suraj Jitindar Singh Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kvm/book3s_hv.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4124,8 +4124,15 @@ int kvmhv_run_single_vcpu(struct kvm_run preempt_enable(); - /* cancel pending decrementer exception if DEC is now positive */ - if (get_tb() < vcpu->arch.dec_expires && kvmppc_core_pending_dec(vcpu)) + /* + * cancel pending decrementer exception if DEC is now positive, or if + * entering a nested guest in which case the decrementer is now owned + * by L2 and the L1 decrementer is provided in hdec_expires + */ + if (kvmppc_core_pending_dec(vcpu) && + ((get_tb() < vcpu->arch.dec_expires) || + (trap == BOOK3S_INTERRUPT_SYSCALL && + kvmppc_get_gpr(vcpu, 3) == H_ENTER_NESTED))) kvmppc_core_dequeue_dec(vcpu); trace_kvm_guest_exit(vcpu);