Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4851674rwl; Mon, 3 Apr 2023 10:27:13 -0700 (PDT) X-Google-Smtp-Source: AKy350Z4xkDLJJ8f6ZAey5elO+dnAslzyAQ9Z6Fj8WzacjECeh1yQos251LDlbKirlvdSDxrW5SG X-Received: by 2002:a17:906:598:b0:931:cd1b:3c0 with SMTP id 24-20020a170906059800b00931cd1b03c0mr18450424ejn.3.1680542832831; Mon, 03 Apr 2023 10:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680542832; cv=none; d=google.com; s=arc-20160816; b=WpuJFTEGF41QTxhB0qHr9NZahiXQKyFBB/bzyjSb6hPb09iRN9CSFHOd39d1FUIOeu ixVoePQeqFtxZU+cwzIbU/r0FLCYyJqQMbcJZsMI3pVpxNiNCFfI9MNojIHAUfCs4I19 hDWvh+OnnLvubySKeNfdpULAF5EjqJlMAp+LvmLlOr2wXCmw7LWhSTTxJqURh+hHnLml /POp1UFDp5MV8lH5gFEaroecLO4QQnGL3xc4VMDIyOMJUVzWffghB0HMQenh7VZkqIca pjK06g5DposQOyprxb3fb9LAre5TJetHMKvtTvpgGx5SPHzdmrg/B4LeniI3o/k2CT7t RKJg== 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=qd9vNo8gmYRz8Z2M2O7ElfQfkdlOYiM1xlJu96lXJAs=; b=HC4QEzpl1t93htqo01VbpEUaXBb8N1D8NPRZa/GEZ7w8wdp11aDfa2PO6vzVAlZ90p TGTxLyQl+uFgE/hXZZYJuHNAR1nBGdr3m8GHb0APJfJz5+6GoXyv1V5Hc/w+GutQHOwg tEnWctvSlDzYEPeYHlDpaEn1GC6q0tNltYD6TBar2CUyYDFBv1gjZU5ohwmPpxXTg3nB /mw4QyVb3rmH0YulhbjexKLuspwG1/4lZK3e+G5rF4zg4eWOsUV3LW7ybQHT6lu61UOd 3DL0fgiTElXCycxZQOejOOH+6Pj72tJUsEsTnhyO2IxvwJH4qh878Lyy1VuPBYRc2J3q Wevw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oX8NBYb5; 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 rc17-20020a170907a31100b00947b226e1cesi784634ejc.40.2023.04.03.10.26.47; Mon, 03 Apr 2023 10:27:12 -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=oX8NBYb5; 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 S233100AbjDCR0Q (ORCPT + 99 others); Mon, 3 Apr 2023 13:26:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbjDCR0P (ORCPT ); Mon, 3 Apr 2023 13:26:15 -0400 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162B2F9 for ; Mon, 3 Apr 2023 10:26:14 -0700 (PDT) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-17ab3a48158so31610834fac.1 for ; Mon, 03 Apr 2023 10:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680542773; 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=qd9vNo8gmYRz8Z2M2O7ElfQfkdlOYiM1xlJu96lXJAs=; b=oX8NBYb547UrM6ZoqymNw1EdsaXNXl8OfwHwQLHx77p13cWWg7QxpeSNTbBJQzK7zN GORcfbDwlQG/J8YJ/Udb5aZvAsZpBIlCzL5NbfC07p+OldQfiBWgQjJ8edDqp5/JEwGN Vlja5+ZGYN22+5FeGnB3oCd/Aa+fHf5RSjiYxKABYg15BXJODLZ9FdRg3q60s7f5oIII 1ZaKJSwt6SqvgmHP3cde1MNJOh0BUK71PwH06e/+YCLXpBZJKUOFuthBS6ylbRdFUA5Q ivFv1wsc705bWl5a4i6xDG64+T17HQ0h/Kz7lLpBDTcuufNYWZl//dh86SgqnSl/k0nU YYGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680542773; 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=qd9vNo8gmYRz8Z2M2O7ElfQfkdlOYiM1xlJu96lXJAs=; b=qDtFPRTVIMFHgbj4/m7YvE8uAcFTxLkc7hqRoYVS+x5/KxHcWRgDNZWcuU8rLk7h9X TD9yuIQo7/4s7hqru6fNp4DBVCAyfFrfMyKhjuMdMwpqcppqgTVkvz7JlSGw+jRx06VM RZvDzvdSX7GHCGZuCDveDvoHxA+oInSTk/4rvjp4SDY+5l+cs0ee514XrYrdQtdDsX57 1opTsMG5TqSAXH8hG598KAeuvYvnIn6396y6haEfIzhGfbYqhUtBRAJksslqD9TcyB+C ACpLY5KnCLblqGCceyluHyUb2e5Y3t9KwVYCAVK9zg0f3vpqThBEGCltn6wTvxkjiifH w+Hw== X-Gm-Message-State: AAQBX9dMYSUMpWFizg3AdbXzSOiW26V63Hle+Uk58zM5+uhqC0bLcDlF YD3YUFjHP+GqHxPC999GAmSqJSO4901gWDBW16oHVg== X-Received: by 2002:a05:6870:96a2:b0:17e:d94f:90d9 with SMTP id o34-20020a05687096a200b0017ed94f90d9mr7605490oaq.3.1680542773212; Mon, 03 Apr 2023 10:26:13 -0700 (PDT) MIME-Version: 1.0 References: <20230206172340.2639971-1-rananta@google.com> <20230206172340.2639971-3-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Mon, 3 Apr 2023 10:26:01 -0700 Message-ID: Subject: Re: [PATCH v2 2/7] KVM: arm64: Add FEAT_TLBIRANGE support 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 Hi Oliver, On Wed, Mar 29, 2023 at 6:19=E2=80=AFPM Oliver Upton wrote: > > On Mon, Feb 06, 2023 at 05:23:35PM +0000, Raghavendra Rao Ananta wrote: > > Define a generic function __kvm_tlb_flush_range() to > > invalidate the TLBs over a range of addresses. The > > implementation accepts 'op' as a generic TLBI operation. > > Upcoming patches will use this to implement IPA based > > TLB invalidations (ipas2e1is). > > > > If the system doesn't support FEAT_TLBIRANGE, the > > implementation falls back to flushing the pages one by one > > for the range supplied. > > > > Signed-off-by: Raghavendra Rao Ananta > > --- > > arch/arm64/include/asm/kvm_asm.h | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/= kvm_asm.h > > index 43c3bc0f9544d..995ff048e8851 100644 > > --- a/arch/arm64/include/asm/kvm_asm.h > > +++ b/arch/arm64/include/asm/kvm_asm.h > > @@ -221,6 +221,24 @@ DECLARE_KVM_NVHE_SYM(__per_cpu_end); > > DECLARE_KVM_HYP_SYM(__bp_harden_hyp_vecs); > > #define __bp_harden_hyp_vecs CHOOSE_HYP_SYM(__bp_harden_hyp_vecs) > > > > +#define __kvm_tlb_flush_range(op, mmu, start, end, level, tlb_level) d= o { \ > > + unsigned long pages, stride; = \ > > + = \ > > + stride =3D kvm_granule_size(level); = \ > > Hmm... There's a rather subtle and annoying complication here that I > don't believe is handled. > > Similar to what I said in the last spin of the series, there is no > guarantee that a range of IPAs is mapped at the exact same level > throughout. Dirty logging and memslots that aren't hugepage aligned > could lead to a mix of mapping levels being used within a range of the > IPA space. > Unlike the comment on v1, the level/stride here is used to jump the addresses in case the system doesn't support TLBIRANGE. The TTL hint is 0. That being said, do you think we can always assume the least possible stride (say, 4k) and hardcode it? With respect to alignment, since the function is only called while breaking the table PTE, do you think it'll still be a problem even if we go with the least granularity stride? > > + start =3D round_down(start, stride); = \ > > + end =3D round_up(end, stride); = \ > > + pages =3D (end - start) >> PAGE_SHIFT; = \ > > + = \ > > + if ((!system_supports_tlb_range() && = \ > > + (end - start) >=3D (MAX_TLBI_OPS * stride)) || = \ > > Doesn't checking for TLBIRANGE above eliminate the need to test against > MAX_TLBI_OPS? > Derived from __flush_tlb_range(), I think the condition is used to just flush everything if the range is too large to iterate and flush when the system doesn't support TLBIRANGE. Probably to prevent soft-lockups? Thank you. Raghavendra > > + pages >=3D MAX_TLBI_RANGE_PAGES) { = \ > > + __kvm_tlb_flush_vmid(mmu); = \ > > + break; = \ > > + } = \ > > + = \ > > + __flush_tlb_range_op(op, start, pages, stride, 0, tlb_level, fals= e); \ > > +} while (0) > > + > > extern void __kvm_flush_vm_context(void); > > extern void __kvm_flush_cpu_context(struct kvm_s2_mmu *mmu); > > extern void __kvm_tlb_flush_vmid_ipa(struct kvm_s2_mmu *mmu, phys_addr= _t ipa, > > -- > > 2.39.1.519.gcb327c4b5f-goog > > > > > > -- > Thanks, > Oliver