From patchwork Tue Jun 8 18:28:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 457527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FF37C47082 for ; Tue, 8 Jun 2021 19:20:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B7CA6108E for ; Tue, 8 Jun 2021 19:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237392AbhFHTWi (ORCPT ); Tue, 8 Jun 2021 15:22:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:40970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238799AbhFHTUF (ORCPT ); Tue, 8 Jun 2021 15:20:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0B41D61477; Tue, 8 Jun 2021 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178348; bh=aEDxG6h29ivDTypq5aoukTCRXsGpyc6ZjU+N2yJn6Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sRZh3X13O175tBWps/jDGyeZgsgswnrSh6QR6LB4AMadXRdq6rbo1uiONywe0MjI8 OmS05qcJ9JCSYQYJW9u+i6XKyDqqQAGgvXPgnLxIxUiboUGU3SoMmK+O3nFVq+qtF1 D7wQGcv7bVTfZVZaLO94bROhSNFiWfNDs9Gkg9d8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zenghui Yu , Marc Zyngier Subject: [PATCH 5.12 155/161] KVM: arm64: Resolve all pending PC updates before immediate exit Date: Tue, 8 Jun 2021 20:28:05 +0200 Message-Id: <20210608175950.700983250@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zenghui Yu commit e3e880bb1518eb10a4b4bb4344ed614d6856f190 upstream. Commit 26778aaa134a ("KVM: arm64: Commit pending PC adjustemnts before returning to userspace") fixed the PC updating issue by forcing an explicit synchronisation of the exception state on vcpu exit to userspace. However, we forgot to take into account the case where immediate_exit is set by userspace and KVM_RUN will exit immediately. Fix it by resolving all pending PC updates before returning to userspace. Since __kvm_adjust_pc() relies on a loaded vcpu context, I moved the immediate_exit checking right after vcpu_load(). We will get some overhead if immediate_exit is true (which should hopefully be rare). Fixes: 26778aaa134a ("KVM: arm64: Commit pending PC adjustemnts before returning to userspace") Signed-off-by: Zenghui Yu Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20210526141831.1662-1-yuzenghui@huawei.com Cc: stable@vger.kernel.org # 5.11 [yuz: stable-5.12.y backport] Signed-off-by: Zenghui Yu Reviewed-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kvm/arm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -715,11 +715,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_v return ret; } - if (run->immediate_exit) - return -EINTR; - vcpu_load(vcpu); + if (run->immediate_exit) { + ret = -EINTR; + goto out; + } + kvm_sigset_activate(vcpu); ret = 1; @@ -892,6 +894,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_v kvm_sigset_deactivate(vcpu); +out: /* * In the unlikely event that we are returning to userspace * with pending exceptions or PC adjustment, commit these