Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3387367pxj; Tue, 1 Jun 2021 04:15:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRCJUCqyeN+svEOsQrypiRB1phuFKvhINdwOCO4v+C7hhLjeSu9rG1sZAwwG8AzABXT9lz X-Received: by 2002:a05:6638:3290:: with SMTP id f16mr25287811jav.49.1622546122848; Tue, 01 Jun 2021 04:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622546122; cv=none; d=google.com; s=arc-20160816; b=IDwN9+0v4vN8Inq9QlN/OyYxWY4vPuGhiQjeaHEzo6VViGjLlydzMNOQnHlBkN6FLo QpJEV28+F4s9D9hBc4d3frzUp/GYcnxEZXFcyQ8sgQc1eRvlN++v4rzOYe6DDO2Oxdp8 1MHTnzlEe+nKWMwFz6GfCUr3Nhi48zjbUXLCMyhwLg0NXPvTsEICK93NWoAx9a609Awi jLq3ruaU922sR+B94Ur3sSIqTWBs+1fRed34cZSycWEbhW5Vc5HsxALSibtiPAj8xnOB mQYfA2sMMHAGSQaOnCyqN0oBx8YMcWR2BWwp1eHkPWK4A8/SK2LkR55MPULSlQHPxQMl P0iA== 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=/laPI4/GDCqSSZgOZ6BSkl+ETbCAdGHvBj+Gxi+DY+s=; b=esF5CAf9Eioz9Y/Fll8c4Zv/96wZUf92TKGIm2Ukbl0uOgW52tIZrcTp1ur6AvfiAI 7wDGgcVaua3o45rH8Mlqghnp7Vbgn9liIVIlagpHfIn65Y1RJIdamzzfsBI9WrgVB199 PVM0OdM/DzQ4fEUnjOc32nwrUKLSzKvGQU7glPL8psgsrzD1CDoHowbNFMpRgA/sParQ 7lyQIDbmCJyPK0XQ3G8VrpQeZ/jd7qJOMSN0P2ol9/IGaOSLHuscKs8eUjEYAT5v2tSa j4jQ8u1Srx4+LFD3fPLRTyVqMivBPb4pyy95CnOWeptdHDA9UdFbxU6Xa+Z0Bj6L1W8Y g+BA== 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 c7si20087983ioi.54.2021.06.01.04.15.09; Tue, 01 Jun 2021 04:15:22 -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 S233718AbhFALOr (ORCPT + 99 others); Tue, 1 Jun 2021 07:14:47 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6113 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233556AbhFALOn (ORCPT ); Tue, 1 Jun 2021 07:14:43 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FvTw90gBQzYmrR; Tue, 1 Jun 2021 19:10:17 +0800 (CST) Received: from dggema764-chm.china.huawei.com (10.1.198.206) by dggemv703-chm.china.huawei.com (10.3.19.46) 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 19:13:00 +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 19:13:00 +0800 From: Zenghui Yu To: , CC: , , , , , Subject: [PATCH stable-5.12.y backport 2/2] KVM: arm64: Resolve all pending PC updates before immediate exit Date: Tue, 1 Jun 2021 19:12:38 +0800 Message-ID: <20210601111238.1059-3-yuzenghui@huawei.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20210601111238.1059-1-yuzenghui@huawei.com> References: <20210601111238.1059-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 --- 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