Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1465654rwd; Wed, 31 May 2023 14:30:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nmkxcu36Mcl88EkP9tPn/YLW4Vvjtgm3WECrAz2ZqiZqP2h6ZIoFt3Dgefnp2gg+NKKhr X-Received: by 2002:a54:4588:0:b0:398:2f01:ec40 with SMTP id z8-20020a544588000000b003982f01ec40mr5067765oib.57.1685568654586; Wed, 31 May 2023 14:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685568654; cv=none; d=google.com; s=arc-20160816; b=M07CXINmltC5i/EQpc8wSaS9lwXPuoZCLQWXz864unLU8Jc+auopGTqo495UjJ4MTo r9vqb27U1jOI2vTOARMxn3mJG3m2eq6qh3HPem4KqfPZmUBP6ssWHZmkBzbyZSSCZNyY eUNv5Hzs2zEvHKBFNk5hISz369OASiCaagz5HLGhmY/6DiQvdO3iCXzuQHr13Mg07N1t KmWx94n9sb9XIAXpZMhxMlfddVw5HmH51kxtpAKSgD6ZgYKwSaAwNJUlayG3WztXQvI5 KU//MDw0NPgsgsCKrLhxsPJ8YWjTxtzcGWCfcN4FaugZMWX5N2Jfq6xI87F5CbPNPJWn YKzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7+2qoqODzznlrzJdzN64MjbCVNNnQuwRRtJuX4ggbCU=; b=W+3zSUfmli2QtiGrw2b1v70L+DD4rMRHhe859zblO6x38ptzpfeAa1tp3qjb7Nf6ty UY2Y195uvoVwDY7V4hTZjyyVq3JicA/ZiyT0o29tfWxKQK6t9d5Juoz9+GRJoo+rr9b0 s8m1ZQoVjyHWVS3l5c+xmVPMN2DTAx6XI0QpeqYzMzRCjSNERfa3jbiiXozpB3AdjF8z jovZFb/jQ3mtckV0G3HhqjlqRuTkDYjkdnqr+U27NlgLUP7UTI1IG/KV3yQJkt2Mj8LV K9u8qUxE5DczCSHpO0+8jV6YjAY+zR/HUKwV96O2XgxXEbZUM2flKNd9gVsKfVKBwU2g 2XZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=kHJHBx69; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020aa78ec3000000b006391322d3f8si4306666pfr.375.2023.05.31.14.30.32; Wed, 31 May 2023 14:30:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=kHJHBx69; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbjEaVNV (ORCPT + 99 others); Wed, 31 May 2023 17:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjEaVNT (ORCPT ); Wed, 31 May 2023 17:13:19 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A36F129 for ; Wed, 31 May 2023 14:13:17 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-3f81ffc9065so19721cf.1 for ; Wed, 31 May 2023 14:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685567596; x=1688159596; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7+2qoqODzznlrzJdzN64MjbCVNNnQuwRRtJuX4ggbCU=; b=kHJHBx69u6844yWRg+bdMx0m0tvgPlagRdL9WAIhqNvPpu8LX6GMuzHUHixyWgd9Mf qMY0qxpAkEmOxYZNrn0heIVjfGWpYgIwlgNcz8wlOeZnnk3GSZB4NDa6DPPoQDzEoBo0 lR6HimNkut+XEN2CfKEthgqEw9XODXPnFgApD2MocwWQg3P600hpjTCFdeQ/aa4jxYoA id1X9co22nLUO5CFxyBWnUvevyXMChC/vrSNZ3kgUh9Qq84ljrXGo9BVv2lPuo5FhPmW R5vkwByRhT5602h6iBd8eMi2T7L9oJexCh5hLLcf6GpQ/OcBRYje/jyno1z0YmKsVGx1 h3gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685567596; x=1688159596; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7+2qoqODzznlrzJdzN64MjbCVNNnQuwRRtJuX4ggbCU=; b=Sf299TP8I/+ozZKRCuZ9xEb6VBtyUmBGQ8OThsW76hMjhLJw8apwBsSHv3OaEam3x/ 0GXh6f42cK0eLMgN2SmNjqe/eCyYmpqrZH2oGsEqggxEAbPc4Fu0qEya3xJb29U/1A7x 7f/o1MS//e0gTM35rSDP/FFwVMiqWegifiMw76cglNoFkwpBMg6plyQCx/By1O42gaT9 EgM1zAwEMjrL4uL97nkauMD28qz4nUZWuFAy0TCGt0m9h2+p37VdoYrxpDBo8ViX9Im2 x7gL5CYTdFqdE45rYqeRe9FhqdobUC+tMWLShqKUk7+X5M3QytgSnMtdpkzqjyYx8KGX +Rgw== X-Gm-Message-State: AC+VfDzBBF11eCVjK/wEBVnMiSVq1ndDxXEPGoFVHJPGz+LlVsHFy4Lm F0S7yQwikdk+YBYT88LPnSmZFSV+wnlk5c+InRDikg== X-Received: by 2002:a05:622a:1a11:b0:3f8:3065:7fc5 with SMTP id f17-20020a05622a1a1100b003f830657fc5mr7534qtb.1.1685567595969; Wed, 31 May 2023 14:13:15 -0700 (PDT) MIME-Version: 1.0 References: <20230526234435.662652-1-yuzhao@google.com> <20230526234435.662652-6-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Wed, 31 May 2023 15:12:39 -0600 Message-ID: Subject: Re: [PATCH mm-unstable v2 05/10] kvm/arm64: add kvm_arch_test_clear_young() To: Oliver Upton Cc: Andrew Morton , Paolo Bonzini , Alistair Popple , Anup Patel , Ben Gardon , Borislav Petkov , Catalin Marinas , Chao Peng , Christophe Leroy , Dave Hansen , Fabiano Rosas , Gaosheng Cui , Gavin Shan , "H. Peter Anvin" , Ingo Molnar , James Morse , "Jason A. Donenfeld" , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Masami Hiramatsu , Michael Ellerman , Michael Larabel , Mike Rapoport , Nicholas Piggin , Paul Mackerras , Peter Xu , Sean Christopherson , Steven Rostedt , Suzuki K Poulose , Thomas Gleixner , Thomas Huth , Will Deacon , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org, linux-mm@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 31, 2023 at 1:56=E2=80=AFPM Oliver Upton wrote: > > Hi Yu, > > On Fri, May 26, 2023 at 05:44:30PM -0600, Yu Zhao wrote: > > Implement kvm_arch_test_clear_young() to support the fast path in > > mmu_notifier_ops->test_clear_young(). > > > > It focuses on a simple case, i.e., hardware sets the accessed bit in > > KVM PTEs and VMs are not protected, where it can rely on RCU and > > cmpxchg to safely clear the accessed bit without taking > > kvm->mmu_lock. Complex cases fall back to the existing slow path > > where kvm->mmu_lock is then taken. > > > > Signed-off-by: Yu Zhao > > --- > > arch/arm64/include/asm/kvm_host.h | 6 ++++++ > > arch/arm64/kvm/mmu.c | 36 +++++++++++++++++++++++++++++++ > > 2 files changed, 42 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm= /kvm_host.h > > index 7e7e19ef6993..da32b0890716 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -1113,4 +1113,10 @@ static inline void kvm_hyp_reserve(void) { } > > void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu); > > bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu); > > > > +#define kvm_arch_has_test_clear_young kvm_arch_has_test_clear_young > > +static inline bool kvm_arch_has_test_clear_young(void) > > +{ > > + return cpu_has_hw_af() && !is_protected_kvm_enabled(); > > +} > > I would *strongly* suggest you consider supporting test_clear_young on > systems that do software Access Flag management. FEAT_HAFDBS is an > *optional* extension to the architecture, so we're going to support > software AF management for a very long time in KVM. It is also a valid > fallback option in the case of hardware errata which render HAFDBS > broken. Hi Oliver, It's not about willingness but resources. Ideally we want to make everything perfect, but in reality, we can only move forward one step a time. If I looked at your request from ARM's POV, I would agree with you. But my goal is to lay the foundation for all architectures that could benefit, so I may not be able to cover a lot for each architecture. Specifically, I don't have the bandwidth to test the !FEAT_HAFDBS case for ARM. So here are some options I could offer, ordered by my preferences: 1. We proceed as it is for now. I *will* find someone from my team (or yours) to follow up -- this way we can make sure !FEAT_HAFDBS is well tested. 2. I drop the cpu_has_hw_af() check above. Not that I think there is much risk, I'm just trying to be cautious. 3. I drop the entire ARM support (and include the RISC-V support which I previously deprioritized). We revisit after the test is done. Sounds reasonable? > So, we should expect (and support) systems of all shapes and sizes that > do software AF. I'm sure we'll hear about more in the not-too-distant > future... > > For future reference (even though I'm suggesting you support software > AF), decisions such of these need an extremely verbose comment > describing the rationale behind the decision. > > > + > > #endif /* __ARM64_KVM_HOST_H__ */ > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > index c3b3e2afe26f..26a8d955b49c 100644 > > --- a/arch/arm64/kvm/mmu.c > > +++ b/arch/arm64/kvm/mmu.c > > Please do not implement page table walkers outside of hyp/pgtable.c > > > @@ -1678,6 +1678,42 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kv= m_gfn_range *range) > > range->start << PAGE_SHIFT); > > } > > > > +static int stage2_test_clear_young(const struct kvm_pgtable_visit_ctx = *ctx, > > + enum kvm_pgtable_walk_flags flags) > > +{ > > + kvm_pte_t new =3D ctx->old & ~KVM_PTE_LEAF_ATTR_LO_S2_AF; > > + > > + VM_WARN_ON_ONCE(!page_count(virt_to_page(ctx->ptep))); > > This sort of sanity checking is a bit excessive. Isn't there a risk of > false negatives here too? IOW, if we tragically mess up RCU in the page > table code, what's stopping a prematurely freed page from being > allocated to another user? Yes, but from my aforementioned POV (the breadth I'm focusing on), this is a good practice. I can live without this assertion if you feel strongly about it. > > + if (!kvm_pte_valid(new)) > > + return 0; > > + > > + if (new =3D=3D ctx->old) > > + return 0; > > + > > + if (kvm_should_clear_young(ctx->arg, ctx->addr / PAGE_SIZE)) > > + stage2_try_set_pte(ctx, new); > > + > > + return 0; > > +} > > + > > +bool kvm_arch_test_clear_young(struct kvm *kvm, struct kvm_gfn_range *= range) > > +{ > > + u64 start =3D range->start * PAGE_SIZE; > > + u64 end =3D range->end * PAGE_SIZE; > > + struct kvm_pgtable_walker walker =3D { > > + .cb =3D stage2_test_clear_young, > > + .arg =3D range, > > + .flags =3D KVM_PGTABLE_WALK_LEAF | KVM_PGTABLE_WALK_SHAR= ED, > > + }; > > + > > + BUILD_BUG_ON(is_hyp_code()); > > Delete this assertion. Will do.