Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6509898rwl; Tue, 4 Apr 2023 14:02:44 -0700 (PDT) X-Google-Smtp-Source: AKy350b/6S8iEn7D+nVEKEBI/GrOeY6b1exBPnbi3YHel/tagzE1EoKgpPKqkeriEOF9xllWZQ2g X-Received: by 2002:a17:906:7ca:b0:946:e68f:4032 with SMTP id m10-20020a17090607ca00b00946e68f4032mr748722ejc.64.1680642164504; Tue, 04 Apr 2023 14:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680642164; cv=none; d=google.com; s=arc-20160816; b=prpXEs9XBCgkAV2eDMZ/DanSG3sKMMFX2resPWEO7HS9WrKJExRUrfLa0te+UJzHjH I5cumcZJCkPNEAaRtPZ1kmjm+qLHV1b9+EHNUTIe76K3s4JGS4ranBzVSylu91Q6EvH5 QJ533kIF2rV6GQnbmN/apxKpteZn9vaKhG6ErM3DM3Q6nNavIO+lr8OYGgTztmHFTeVT ITYTB7TZzjQhP7AnauQ5Pwku3hGMfzaEdtlWGtfZIFww7xScpXTJwsmcGEmuUebF8LDr s2r6j865Rj7NxM2RsDYndu1S6bXBRqpSm7uImsXteyf3AWmr1aHygfW+FuyiYL64numJ MJ1A== 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=8XB956O45UzVksOyeGhwxzyBdQXHDRc1Q4yj23qYiJg=; b=iqZvpYZawFSeECtBaXUmd/9lBb9Yu78Lt3pBeLMzxEdR0sBsnrwYvD0gU/6l8/F5Hg sWPCtFQs2eVCgIX6pVaAtQyKY3ogoaIy9tvj+DLIsgq5P9DBC894Rgz4EiehYfKkJvWK 619GtGnQLnEdbuWObhF7D4oYJY5ajgjLRbD1wt89udxzyNMZnphWzn4p/etTiKbqYUDS 4H40Hno5lezQ/rcWYSvx+R1Gpvbnklar/5iHYzMUje3teWjGZjKN0KRBgUsS4N7d2y58 wQBGC0q1H2TWm3m82uWuJY0UDaByPMfIqZZN9o2JQ/Uhr1P/s5rwLb53YcC0J4hKN9gq KJpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RN3hkQEh; 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 gf23-20020a170906e21700b00925f618e1e6si2433876ejb.174.2023.04.04.14.02.13; Tue, 04 Apr 2023 14:02:44 -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=20210112 header.b=RN3hkQEh; 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 S236362AbjDDU7q (ORCPT + 99 others); Tue, 4 Apr 2023 16:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbjDDU7p (ORCPT ); Tue, 4 Apr 2023 16:59:45 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1943644BF for ; Tue, 4 Apr 2023 13:59:44 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id a30-20020a9d3e1e000000b006a13f728172so14875129otd.3 for ; Tue, 04 Apr 2023 13:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680641983; 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=8XB956O45UzVksOyeGhwxzyBdQXHDRc1Q4yj23qYiJg=; b=RN3hkQEhO24vo0vfwd4s0t68KhyLFB5bobj6eS6kQ1lCvGABwa562qwkSJpKBLhHsI j9WyV/bZ9XUUkmDYf+xx+nqLQRXXyoH1MuACy1KypDYbTisxMcFFPsQ27f1Wt48z1eCe Eff/XBDWq153oNecKmgeVWIXX2Wk5Cl2Wz2mDFmKW4gLy/ix+eYT7xT7Z8Onc9v69H+P akaXzFzIepYWUiCTz/CfJFD8qj4ynB6JoyOmjfvskEHLgdwgbEkTOaNBwplMqrR2YZQl 92xCtdgJd+LiU2AY20nwNoj0e73AWfEbcYIiJBKhfeBA1W8r725EEmwGfIftOIdiMXdj dSmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680641983; 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=8XB956O45UzVksOyeGhwxzyBdQXHDRc1Q4yj23qYiJg=; b=H5gv8ypQm3GuL9TI+xebb55jj0vsZEjRCt40Lbop8vNxsdCOubCaAMALOlrTPXfd24 s91OFXbZVHSmgdIcGWAF7EKA3qNGwR8+aOJ05Ak9mncXKGTITcDq+SiBasbzP1xL4TGS Dy4LLPC38Yl3i8UuV2VR8D/kDrhksh0IKE/l2v6+yhYn1vNBtYbgTg8RfhMrZDKm1DHw J+LjmR476qjARHH1Mu7s38Ck2RJEWekv2QS0EK4iN84Xv0ROxcj0nGrJDtXfZJBJoVnx hu5kPXZDaYkNDWiWKUhyHGY767PYQbUzX149yn1o5vsiMsupzsQHQQG7LsaPhWzAoCHF WJog== X-Gm-Message-State: AAQBX9f2FhA640tJSZaQwKnTacm++LTVbJ63/6D1i+0+hdwbTyE28Drp MW1QzcSA8n5Wf7jvjPLt4O1/QjZ5EbEu9vUbW3lx0Q== X-Received: by 2002:a9d:6191:0:b0:699:7883:940d with SMTP id g17-20020a9d6191000000b006997883940dmr1276983otk.7.1680641983242; Tue, 04 Apr 2023 13:59:43 -0700 (PDT) MIME-Version: 1.0 References: <20230206172340.2639971-1-rananta@google.com> <20230206172340.2639971-5-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Tue, 4 Apr 2023 13:59:31 -0700 Message-ID: Subject: Re: [PATCH v2 4/7] KVM: arm64: Implement kvm_arch_flush_remote_tlbs_range() To: Oliver Upton Cc: Oliver Upton , Marc Zyngier , Ricardo Koller , Reiji Watanabe , James Morse , Alexandru Elisei , Suzuki K Poulose , Will Deacon , Paolo Bonzini , Catalin Marinas , Jing Zhang , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.7 required=5.0 tests=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,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 Tue, Apr 4, 2023 at 12:09=E2=80=AFPM Oliver Upton wrote: > > On Mon, Apr 03, 2023 at 02:23:17PM -0700, Raghavendra Rao Ananta wrote: > > On Wed, Mar 29, 2023 at 5:53=E2=80=AFPM Oliver Upton wrote: > > > > > > On Mon, Feb 06, 2023 at 05:23:37PM +0000, Raghavendra Rao Ananta wrot= e: > > > > Implement kvm_arch_flush_remote_tlbs_range() for arm64, > > > > such that it can utilize the TLBI range based instructions > > > > if supported. > > > > > > > > Signed-off-by: Raghavendra Rao Ananta > > > > --- > > > > arch/arm64/include/asm/kvm_host.h | 3 +++ > > > > arch/arm64/kvm/mmu.c | 15 +++++++++++++++ > > > > 2 files changed, 18 insertions(+) > > > > > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include= /asm/kvm_host.h > > > > index dee530d75b957..211fab0c1de74 100644 > > > > --- a/arch/arm64/include/asm/kvm_host.h > > > > +++ b/arch/arm64/include/asm/kvm_host.h > > > > @@ -1002,6 +1002,9 @@ struct kvm *kvm_arch_alloc_vm(void); > > > > #define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS > > > > int kvm_arch_flush_remote_tlbs(struct kvm *kvm); > > > > > > > > +#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE > > > > +int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_= gfn, u64 pages); > > > > + > > > > static inline bool kvm_vm_is_protected(struct kvm *kvm) > > > > { > > > > return false; > > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > > > index e98910a8d0af6..409cb187f4911 100644 > > > > --- a/arch/arm64/kvm/mmu.c > > > > +++ b/arch/arm64/kvm/mmu.c > > > > @@ -91,6 +91,21 @@ int kvm_arch_flush_remote_tlbs(struct kvm *kvm) > > > > return 0; > > > > } > > > > > > > > +int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_= gfn, u64 pages) > > > > +{ > > > > + phys_addr_t start, end; > > > > + > > > > + if (!system_supports_tlb_range()) > > > > + return -EOPNOTSUPP; > > > > > > There's multiple layers of fallback throughout this series, as it wou= ld > > > appear that deep in __kvm_tlb_flush_range() you're blasting the whole > > > VMID if either the range is too large or the feature isn't supported. > > > > > > Is it possible to just normalize on a single spot to gate the use of > > > range-based invalidations? I have a slight preference for doing it de= ep > > > in the handler, as it keeps the upper layers of code a bit more > > > readable. > > > > > I was a little skeptical on this part, since the > > kvm_arch_flush_remote_tlbs_range() expects to return -EOPNOTSUPP if > > indeed there's no support. > > Well, the arch-neutral code can expect whatever it wants :) The only > real contract we have with it is to return 0 iff the specified range has > been invalidated, even if that comes with over-invalidating. > > > But I see your point. The if-else in kvm_pgtable_stage2_flush_range() > > seems redundant and I can simply manage this conditions inside > > __kvm_tlb_flush_range_vmid_ipa() itself, but I'll leave the > > kvm_arch_flush_remote_tlbs_range()'s implementation as is. Thoughts? > > The largest concern I had is that the series is testing for FEAT_TLBIRANG= E > all over the shop and I just raised that concern on this patch. AFAICT, > the iterative approach to invalidating a range of IPAs is effectively > dead code, as all flows into __kvm_tlb_flush_range_vmid_ipa() are gated > by system_supports_tlb_range() somewhere. > > Personally, I prefer keeping the higher level software models making > aggressive use of range-based interfaces and letting the actual > implementation under the hood select the appropriate instruction. That > helps readability, as it directly communicates the expected outcome of > the invalidation. > > So, if you want to make use of the iterative approach to TLB invalidation= s on > !TLBIRANGE systems, then this function should _not_ return EOPNOTSUPP. > Thanks for the explanation. I can make the calls consistent across the code, and let the actual handler deal TLBIRANGE support. - Raghavendra > -- > Thanks, > Oliver