Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3407803pxj; Tue, 1 Jun 2021 04:46:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy24Hdkm+iqTkcq8p4ifrUFN/tc4Par2fb1og/wFyVZHzRBEajVA9T/M/N2VJC+FHLKxX17 X-Received: by 2002:aa7:cd92:: with SMTP id x18mr31781186edv.17.1622547979615; Tue, 01 Jun 2021 04:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622547979; cv=none; d=google.com; s=arc-20160816; b=efJYdpT4xmutF6kIWCbyVOkAstBzLJMUmWLSoUhUs7QDEFzRYvjce/0uQC8VU0Sobg 71FtFlZ0zSGkIVHNAj2DL15EI8Nmo2gmPokWoDQ0zhm67cYwnw1s10AvFR/yF0MS+c/F 4WM6lleGdYHm9byh3fz9r7qRhSWV3NnmBGzyAhpoe7VzqKilpdGyvz1yjc8rmTT/QFZo oCtraMZviU5YBldsd1n8o82wyj3Ef2GAQ/ecMmX+7TJ3Er9YGnkSS23gNfnZK5CbZ2Gc 5dDYn6WYrtfLp7VuZUG6IwQa/Mmx+zfF+ps7wXgt8hnPJdNPahToyA7DpWQ+dQSEnTT4 mnIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=szIIFQ0my4lMboo8NibMaLxopfpWlveIlxwvRsRzTy8=; b=I/a1Fr24Gz/sFIUC3qz5hGUni5fUIHHpmM7Ja7aqMSxgh09MrBpC72jR4rcclMP/hv JJh075bAG/X55HtmOBlfGHkR0LKZyo0C0N72eU+pmcHq66ot31URqcCZ5k6cHo4I8tUr lVl3BFNLbO4oa2FpaUYqsP0ABEqAiNwpz7e37w5hNBqV9yx0yaiX4CJAf1YXx58bS8eB hnxKXWOeseQnQX9xpyd4pNwgRE7H9/Y/DqWi6JxJImRmncgRXgxK1BNDvfLtInGzCN0Z uuC1VY1Oco8+XweaFVChWuD26U8qCNF3RrDoQaAv4dUGhe9/VH/QY46UvgPJMjG7ZYy3 1ijw== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kk19si6589982ejc.460.2021.06.01.04.45.56; Tue, 01 Jun 2021 04:46:19 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233805AbhFALqN (ORCPT + 99 others); Tue, 1 Jun 2021 07:46:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233703AbhFALqM (ORCPT ); Tue, 1 Jun 2021 07:46:12 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (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 0A177610A0; Tue, 1 Jun 2021 11:44:31 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lo2ov-004o6Y-3K; Tue, 01 Jun 2021 12:44:29 +0100 Date: Tue, 01 Jun 2021 12:44:28 +0100 Message-ID: <87v96x24ir.wl-maz@kernel.org> From: Marc Zyngier To: Zenghui Yu Cc: , , , , , Subject: Re: [PATCH stable-5.12.y backport 1/2] KVM: arm64: Commit pending PC adjustemnts before returning to userspace In-Reply-To: <20210601111238.1059-2-yuzenghui@huawei.com> References: <20210601111238.1059-1-yuzenghui@huawei.com> <20210601111238.1059-2-yuzenghui@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, stable@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, sashal@kernel.org, alexandru.elisei@arm.com, wanghaibin.wang@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zenghui, Thanks for having a go at the backport. On Tue, 01 Jun 2021 12:12:37 +0100, Zenghui Yu wrote: > > From: Marc Zyngier > > commit 26778aaa134a9aefdf5dbaad904054d7be9d656d upstream. > > KVM currently updates PC (and the corresponding exception state) > using a two phase approach: first by setting a set of flags, > then by converting these flags into a state update when the vcpu > is about to enter the guest. > > However, this creates a disconnect with userspace if the vcpu thread > returns there with any exception/PC flag set. In this case, the exposed > context is wrong, as userspace doesn't have access to these flags > (they aren't architectural). It also means that these flags are > preserved across a reset, which isn't expected. > > To solve this problem, force an explicit synchronisation of the > exception state on vcpu exit to userspace. As an optimisation > for nVHE systems, only perform this when there is something pending. > > Reported-by: Zenghui Yu > Reviewed-by: Alexandru Elisei > Reviewed-by: Zenghui Yu > Tested-by: Zenghui Yu > Signed-off-by: Marc Zyngier > Cc: stable@vger.kernel.org # 5.11 > [yuz: stable-5.12.y backport: add __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc > macro manually and keep it consistent with mainline] I'd rather you allocated a new number here, irrespective of what mainline has (rational below). > Signed-off-by: Zenghui Yu > --- > arch/arm64/include/asm/kvm_asm.h | 1 + > arch/arm64/kvm/arm.c | 11 +++++++++++ > arch/arm64/kvm/hyp/exception.c | 4 ++-- > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 ++++++++ > 4 files changed, 22 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index a8578d650bb6..d7f769bb6c9c 100644 > --- a/arch/arm64/include/asm/kvm_asm.h > +++ b/arch/arm64/include/asm/kvm_asm.h > @@ -57,6 +57,7 @@ > #define __KVM_HOST_SMCCC_FUNC___kvm_get_mdcr_el2 12 > #define __KVM_HOST_SMCCC_FUNC___vgic_v3_save_aprs 13 > #define __KVM_HOST_SMCCC_FUNC___vgic_v3_restore_aprs 14 > +#define __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc 21 This is going to generate a larger than necessary host_hcall array in hyp/nvhe/hyp-main.c, which we're trying to keep tightly packed for obvious reasons. With this nit fixed: Reviewed-by: Marc Zyngier Thanks, M. -- Without deviation from the norm, progress is not possible.