Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3501268pxj; Tue, 1 Jun 2021 06:49:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzL0y+LTaFRy/24CgZHZ8kGDEkeU2t+v+ms+D2IiV3YDA89leleJLTcC9NXhKq4s6+MncF+ X-Received: by 2002:aa7:c349:: with SMTP id j9mr24591454edr.48.1622555354473; Tue, 01 Jun 2021 06:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622555354; cv=none; d=google.com; s=arc-20160816; b=cIjOepiheMcsFzGLH5ykdsbNNbtKiFzEAitqBopRCz6cyhJLUFE4DY95hjx6Syi30J gWkWAA5b10njeBk89iQqEIPHdxLZ+ubycaOHas7AxW58WLFbmO9Kjr4ukEtxhN9mtDX3 RbCxhTD5+Js+ARp6B+H1MQ8ZfAPIRtLS9T+4J0qtTyODu/qW8XmpGBbraareawaria/P DMOEfrVnrBY+0B3HdfFfqxUKrN9am8s218gWbWE0PmiHoJB6WrlLr+gV/gLibIC1boHP s9bhn7Hgy7yJtrMhCLL2fBooc0ywwtlGFsnwC3ACrZA3+1Fh0D6Bo9VZgp/7a3/DUAW5 vXSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=vU36EPDCplsksY0+ZZVViRSG8QWkvr3RvhdNrOwYI80=; b=SuX2vHnOxM+f/Of8rrTURML8h/39nbC547e+aozXtKwrCWeUyA2nCR30gfUyl8j7Iz R60S8+j5syp71C1/XC96SdjEfrb1ZPnu52sKwU5UFu15rgrZO7kYDsLxlZADNJFrR5IO Lju6r5uCqcdHUXfxj4bN5bGTUeACR/wBDUfUfmOOwFCIk/WXnn4BJgvyXa2HVdBJYlMe KkgChuKG57ZmGbnwaGLzFjnu0sJ1JJHiykwGVUF1+ObgJDXHsl9kTg8qNFjQkGqGYm0L aJRO0TLAh0n9TOifqDq+aOhqJRgbGZl8HlhjOBsvgzX7cTPlH0UdhK7KxHJu0AdxX3FF yH1g== 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 v5si14881955edi.123.2021.06.01.06.48.52; Tue, 01 Jun 2021 06:49: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 S234021AbhFANt2 (ORCPT + 99 others); Tue, 1 Jun 2021 09:49:28 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6117 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233584AbhFANt2 (ORCPT ); Tue, 1 Jun 2021 09:49:28 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FvYLh6cJtzYnjB; Tue, 1 Jun 2021 21:45:00 +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 21:47:44 +0800 Received: from [10.174.185.179] (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 21:47:43 +0800 Subject: Re: [PATCH stable-5.12.y backport 1/2] KVM: arm64: Commit pending PC adjustemnts before returning to userspace To: Marc Zyngier CC: , , , , , References: <20210601111238.1059-1-yuzenghui@huawei.com> <20210601111238.1059-2-yuzenghui@huawei.com> <87v96x24ir.wl-maz@kernel.org> From: Zenghui Yu Message-ID: Date: Tue, 1 Jun 2021 21:47:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <87v96x24ir.wl-maz@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.185.179] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 Hi Marc, On 2021/6/1 19:44, Marc Zyngier wrote: > 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. It isn't obvious to me ;-). But this creates some invalid entries (HVC handlers) in the host_hcall array, which is not good. I'll change __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc to 15. Thanks for your reminder. > With this nit fixed: > > Reviewed-by: Marc Zyngier Thanks! Zenghui