Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3517980pxj; Tue, 1 Jun 2021 07:10:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytiJ4c+Juh5DABCJQGN7I4wf/Ef0LIJYSMB1YaYqFJwI21JauUREzCEuC3gQIA2NMIwRiX X-Received: by 2002:a02:6f5e:: with SMTP id b30mr1324093jae.94.1622556614776; Tue, 01 Jun 2021 07:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622556614; cv=none; d=google.com; s=arc-20160816; b=iIrM5STwdltQSSe7XHJtRaRBjwVSRZzvFWqalFFO1beX/fek4YEfm0jaYjMsk4Fn/G MB9JnV5lWDpCTRqtGFb5y8xgykPaP9Qis/4hW9rE3k1KsCnMj2fMyzFVqrKbPre6kQeu xoCEyAG8HvIThZfM7Y9O4R086QY8opRabbsHsWqROK/tPSRsoKdLEyIEf9wo6szv8b1n 1PtC2XYPLto4TmrPjZj+hHwX9fDqmPhEr4o+s3HL9Gq2HB79MRcLXn37vmvT9JhYu8GJ zFzeK8iNOPMRbV70WckKKbHBoxPjAQlewe2ot9iwMSR/5NepsPRnJLvYwNjRjyVTP6I0 mq0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=21aw1MbkMtwDkAhOYf8cCvSTQOUS1cB1/JWaPXfkE9I=; b=KyhV+bx4XRR0xxm0YjJIaGrbl0sk0W4xklpynpOMsrlMtY8hkSlf67LRF1ewQp76EO NdaqEVGSTI+x9JP800QrOHTqNyzPAJN00bYxF9e9JcLXEKdayl9IKqRIdw8OQS5HFBfE EVyPB3a4f3+xIvRse5yeP5BpxGaAwMOU+UHcT0hJGXD+Z2niFyISR/A47gYGqT1sxObR kcVSpRK0rAea7MCcROdIRL6d5Yi7v5qt633WjI0RzOrJbRl1zu7RUulSaDMURpHv10oO /jSSMyWQOtSECUZVCpkLwHqxGxrbW+mHJEXgjoUYN1UeYk+2vw71BRo3PTlKqr9GqKv6 HVTQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w12si18975158ilg.25.2021.06.01.07.10.01; Tue, 01 Jun 2021 07:10:14 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234417AbhFAOJw (ORCPT + 99 others); Tue, 1 Jun 2021 10:09:52 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2829 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234233AbhFAOJe (ORCPT ); Tue, 1 Jun 2021 10:09:34 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FvYlc4gvnzWqcj; Tue, 1 Jun 2021 22:03:08 +0800 (CST) Received: from dggema764-chm.china.huawei.com (10.1.198.206) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 1 Jun 2021 22:07:50 +0800 Received: from DESKTOP-8RFUVS3.china.huawei.com (10.174.185.179) by dggema764-chm.china.huawei.com (10.1.198.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 1 Jun 2021 22:07:49 +0800 From: Zenghui Yu To: , CC: , , , , , Subject: [PATCH v2 stable-5.12.y backport 2/2] KVM: arm64: Resolve all pending PC updates before immediate exit Date: Tue, 1 Jun 2021 22:07:38 +0800 Message-ID: <20210601140738.2026-3-yuzenghui@huawei.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20210601140738.2026-1-yuzenghui@huawei.com> References: <20210601140738.2026-1-yuzenghui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.185.179] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggema764-chm.china.huawei.com (10.1.198.206) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/kvm/arm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index c18740a1e541..7730b81aad6d 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -715,11 +715,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) 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_vcpu *vcpu) kvm_sigset_deactivate(vcpu); +out: /* * In the unlikely event that we are returning to userspace * with pending exceptions or PC adjustment, commit these -- 2.19.1