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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24169CE7B1F for ; Fri, 29 Sep 2023 09:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232732AbjI2JRs (ORCPT ); Fri, 29 Sep 2023 05:17:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231774AbjI2JRr (ORCPT ); Fri, 29 Sep 2023 05:17:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C82FA180; Fri, 29 Sep 2023 02:17:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70E5DC433C7; Fri, 29 Sep 2023 09:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695979065; bh=8DbphEmZd2h1m2uHAVTUOzw0cvjdxCl6crQ1p98OncM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KzyUyXLp6Zqsl3HMYd/fky8xlvENzMKFiVhjkUcOIS20nOaDojKYrOSmfByrj7iJc raHPprponGw7Iv6avsZRJ6jJyJEclMh9ZUbKj1dRVa+UamS2PuuN32hVlPrdPlTxiE tDJHuNSZDly8sR+XnwF1raL9HZQiHDQdcvQxesuT3EOLU+4ZKMM+yVYXedO4Hl4VJd +bOUph2VyocPA2ylHv6XIYPtY+nnRGIhuR+/kjkyLY2/tqtjuIw/KmWQltNgS9cntq 9ti+aIioAaQhEJXxhpVwAMY5Ce7O3+VtwQUeY8QS+57SMdWxaF4nBx/dWLBZ1W36xK nOb6zbQZXUVlQ== Received: from [85.255.233.37] (helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qm9d0-00HCXE-VT; Fri, 29 Sep 2023 10:17:43 +0100 Date: Fri, 29 Sep 2023 10:17:41 +0100 Message-ID: <87il7tmj7u.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Zenghui Yu , Vipin Sharma , Jing Zhang , stable@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Always invalidate TLB for stage-2 permission faults In-Reply-To: References: <20230922223229.1608155-1-oliver.upton@linux.dev> <87ttrj5181.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/28.2 (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: 85.255.233.37 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, vipinsh@google.com, jingzhangos@google.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: stable@vger.kernel.org On Tue, 26 Sep 2023 00:43:21 +0100, Oliver Upton wrote: > > On Sun, Sep 24, 2023 at 11:12:30AM +0100, Marc Zyngier wrote: > > On Sat, 23 Sep 2023 00:08:21 +0100, > > Oliver Upton wrote: > > > > > > On Fri, Sep 22, 2023 at 10:32:29PM +0000, Oliver Upton wrote: > > > > It is possible for multiple vCPUs to fault on the same IPA and attempt > > > > to resolve the fault. One of the page table walks will actually update > > > > the PTE and the rest will return -EAGAIN per our race detection scheme. > > > > KVM elides the TLB invalidation on the racing threads as the return > > > > value is nonzero. > > > > > > > > Before commit a12ab1378a88 ("KVM: arm64: Use local TLBI on permission > > > > relaxation") KVM always used broadcast TLB invalidations when handling > > > > permission faults, which had the convenient property of making the > > > > stage-2 updates visible to all CPUs in the system. However now we do a > > > > local invalidation, and TLBI elision leads to vCPUs getting stuck in a > > > > permission fault loop. Remember that the architecture permits the TLB to > > > > cache translations that precipitate a permission fault. > > > > > > The effects of this are slightly overstated (got ahead of myself). > > > EAGAIN only crops up if the cmpxchg() fails, we return 0 if the PTE > > > didn't need to be updated. > > > > > > On the subsequent permission fault we'll do the right thing and > > > invalidate the TLB, so this change is purely an optimization rather than > > > a correctness issue. > > > > Can you measure the actual effect of this change? In my (limited) > > experience, I had to actually trick the guest into doing this, and > > opportunistically invalidating TLBs didn't have any significant > > benefit. > > Sure. We were debugging some issues of vCPU hangs during post-copy > migration but that's more likely to be an issue with our VMM + out of > tree code. > > Marginal improvements be damned, I'm still somewhat keen on doing the > TLB invalidation upon race detection anyway. Going back to the guest is > pointless, since in all likelihood we will hit the TLB entry that led to > the permission fault in the first place. I guess it completely depends on the size of the TLB. The machines I deal with have a relatively small number of entries, and it doesn't take much to fully evict them. Now, all of that is probably irrelevant as there should be little impact in performing the invalidation as long as it is local (unless you trap, but that's another problem). FWIW: Acked-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.