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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 4FC27C433B4 for ; Tue, 11 May 2021 12:22:18 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9DFC16188B for ; Tue, 11 May 2021 12:22:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DFC16188B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:Cc:To: From:Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DLt4c/1MAQeg9fMqq8i+yClTcDDDOUgVvCukA8r94Dk=; b=Qk5UHHJwrV3iHDe1lGf7Z25ne UyjNyOXp8jyu7Hr4BsiRttNDECF3UumNjzE8LVjtw2sZIFxOnJeclUqs1+aUrUKSV9CI0IhDJhOTf i7vlOGfeSNW1e4ZECBNh910riOJC3xiHqVKVnaxBljUewsB6kJpWElxGqB/Cz2sqczH27WKT1DiKc vgyg+GgTrYlEd7fQuYHBaAOSvJ1WVO9cnFxHvmmgs+sLwvbjRGgeDn2S5gwcP21oAoYX/dyt4LM0L SW5MPA23+7L2Ka4efL2AAIJTsIE16zPr6mz5jO6N4aHPsSG3Bc30fMfklZONISPxV7VBUDBgH5R3l R/IyT2fww==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgRNm-00HLnj-HK; Tue, 11 May 2021 12:21:03 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgO0r-00Gd8N-0L for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 08:45:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:References: In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=cFHN+EFNAyWHsF90rIgQYvKAsHexvpG7Db2ta5UdkP4=; b=V/2P8FIZBDV5cNrej6cEF9e+BV OxkWO440R2qmJOUajNyOjkboDj54mgHyuNU0o3F7BVdvDEYiiw96JqLynWagNRQQsZ1meQDjUiDct kSFlIu7C3dBckWlYVK/fTe1Qc8wnj9gw5sm+tE3nagPULWElgJhK3GjnzVXIyCtjCcnLEwaA51DZU xFnwnhBR4G17jqGSzlTRO0gWAi8pORZJOFTZvXln3ezQMkYrK4E2lVIE4LhjtHuK439WIZ7fub3Ya aouDKDEbqWrgpLean+5Hp3zvspJj/bgJ/Kp3SFFx6WROjuBD7gqakFLmeVlMsnRZCj/apkr2xz7FB 1c4b9y9A==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgO0n-009PKz-Ta for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 08:45:07 +0000 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") 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210511_014506_048665_58745927 X-CRM114-Status: GOOD ( 32.92 ) /bin/ln: failed to access 'reaver_cache/texts/20210511_014506_048665_58745927': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210511_014506_048665_58745927 X-CRM114-Status: GOOD ( 27.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel