From mboxrd@z Thu Jan 1 00:00:00 1970 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=-4.0 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 CA0F7C433B4 for ; Tue, 11 May 2021 08:45:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C4116186A for ; Tue, 11 May 2021 08:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230482AbhEKIqN (ORCPT ); Tue, 11 May 2021 04:46:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:49308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbhEKIqL (ORCPT ); Tue, 11 May 2021 04:46:11 -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 7F5A9616EC; Tue, 11 May 2021 08:45:04 +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 1lgO0k-000dSP-4n; Tue, 11 May 2021 09:45:02 +0100 Date: Tue, 11 May 2021 09:45:01 +0100 Message-ID: <87lf8loe0i.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvm@vger.kernel.org, "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , Zenghui Yu , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com, stable@vger.kernel.org Subject: Re: [PATCH 2/2] KVM: arm64: Commit pending PC adjustemnts before returning to userspace In-Reply-To: References: <20210510094915.1909484-1-maz@kernel.org> <20210510094915.1909484-3-maz@kernel.org> <871radvg9n.wl-maz@kernel.org> 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: tabba@google.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, yuzenghui@huawei.com, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.com, stable@vger.kernel.org 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: kvm@vger.kernel.org On Tue, 11 May 2021 09:22:37 +0100, Fuad Tabba wrote: > > Hi Marc, > > > On Tue, May 11, 2021 at 9:14 AM Marc Zyngier wrote: > > > > Hi Fuad, > > > > On Tue, 11 May 2021 09:03:40 +0100, > > Fuad Tabba wrote: > > > > > > Hi Marc, > > > > > > > KVM: arm64: Commit pending PC adjustemnts before returning to userspace > > > > > > s/adjustments/adjustments > > > > Looks like Gmail refuses to let you mimic my spelling mistakes! :D > > > > > > > > On Mon, May 10, 2021 at 10:49 AM Marc Zyngier wrote: > > > > > > > > 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 userpsace 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. > > > > > > I've tested this with a few nvhe and vhe tests that exercise both > > > __kvm_adjust_pc call paths (__kvm_vcpu_run and > > > kvm_arch_vcpu_ioctl_run), and the tests ran as expected. I'll do the > > > same for v2 when you send it out. > > > > Ah, that's interesting. Do you have tests that actually fail when > > hitting this bug? Given that this is pretty subtle, it'd be good to > > have a way to make sure it doesn't crop up again. > > Nothing that fails, just code that generates exceptions or emulates > instructions at various points. That said, I think it should be > straightforward to write a selftest for this. I'll give it a go. PC adjustment is easy-ish: have a vcpu to hit WFI with no interrupt pending, send the thread a signal to make it exit to userspace, update the PC to another address, and check that the instruction at that address is actually executed. Exception injection is a lot more difficult: you need to force a vcpu exit to userspace right after having caused an exception to be injected by KVM. I can't think of an easy way to do that other than repeatedly executing an instruction that generates an exception while signalling the thread to force the exit. Ugly. M. -- Without deviation from the norm, progress is not possible.