Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp2287394qtg; Mon, 3 Apr 2023 14:24:47 -0700 (PDT) X-Google-Smtp-Source: AKy350YKiXAivaFyjBt0EbN8LWmXrMz0yQi48rE8PTKjhSBndxovCc91OTxcD/1iZXUt6FbhkXMB X-Received: by 2002:a17:903:228b:b0:19e:6cb9:4c8f with SMTP id b11-20020a170903228b00b0019e6cb94c8fmr447482plh.41.1680557087140; Mon, 03 Apr 2023 14:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557087; cv=none; d=google.com; s=arc-20160816; b=bziY1OYni6bK3nOoJcu55f0bIPcyFu3fSksGTiA4YaKQYXqHuN7jOmORYhoXU6hRX5 f0vU53Wp/bwz5IK5oSbgMwgzMfcHXXzFJIKZDnfLh1aXfOTknqB7CCCE3+slSesTRjmd q8UbclV+6wW5yuHwy1XR+PWuZLDthLOR9p+OZAzks+fHgXzNg4swNapIE+PZeDI+g3FZ hv8iTZNGUDNvWfzaT8n6Bhh6pQ/pxSMaIwV3/yKfGVKHYrGxM1n8FLY44diOb+RTYOQw ssP6gQ+KNzgyCtChB/Db39F2snM3al8UJGYnzxqCmdV9j5z27EMTF3UqQAWSg68vqiBe c+/w== 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=X9EPMXOr7/BpSW0fz3V3pwNkNbHFJwN9oEHw10txBko=; b=wLbEpNRmWTwNMmMLMtT5lA7b2/tRfjtwnu5Q7XJBNZZjeTzPiHO8usNzt5KDfod0u2 LmjkCHAYizQpOCWinxyMg4SmwOwdMFAXXmVFLf1bEEItjqReXLCmNDrIzvM9rGsrlvfW KHmOtrVT5KG8BPnTTaEA7g+KiM2HrGs8QSvMYWAcEKp3CToMQKaP5izasj28svEcymYn EOcV16MkvsRp5Zgq7Ufg1a98MNpG4N6Z4rj8e6JQ8xs9Kt7lQ1KFhCWsEGbmrdLyQsAB 6rjezcriZ6cc4gfyAZYGuHJmtJ/b9a14DYn+rwHEFWCFOJYCvk4TvY12v0uxAx+A3gMU 7Wrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JSrJHjc8; 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 w14-20020a170902a70e00b0019e8d4cb8d3si8328928plq.614.2023.04.03.14.24.34; Mon, 03 Apr 2023 14:24:47 -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=JSrJHjc8; 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 S233746AbjDCVYN (ORCPT + 99 others); Mon, 3 Apr 2023 17:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233542AbjDCVXv (ORCPT ); Mon, 3 Apr 2023 17:23:51 -0400 Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 867F64C30 for ; Mon, 3 Apr 2023 14:23:30 -0700 (PDT) Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-17aceccdcf6so32313375fac.9 for ; Mon, 03 Apr 2023 14:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680557009; 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=X9EPMXOr7/BpSW0fz3V3pwNkNbHFJwN9oEHw10txBko=; b=JSrJHjc8ZlkN946jtgq7pXnminH4yEpKyDgM/gCOAmSADuPaZeN8qyXKh6Lz/tzW1k vTRrhW3M0FG6eVQiT1zs3JO0WEUFCRAZXEmnyUVmCQfh325zdk6HjRCKfWEO5vHZ2RSV GeyPLeOR4EuNwTOZEGuko3LAMXLdC7iuV1Zwrm4P2sKWvXR9ibfS69kHCma4Gu3Go0Bl N0hS3WBTKQ4Fgr4To1R7dFmoSj2mJpzvYRJ4QLoHHQcRjM7UoUVVOXbRWEgE/Yix3v4F qNsnERfOgf0ulmyZMGLFUpMyd/z89HcxRIWryz4ryLmHOlJnDzJUmy8/eUVgYwgz32x+ 5bJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680557009; 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=X9EPMXOr7/BpSW0fz3V3pwNkNbHFJwN9oEHw10txBko=; b=K6Kf/uWpam/6nQmlnB0oolE9fIOcro2V90Cb33RYkaJbOoG/9VpwSTo2gz8OYwpXFN lR16dWGeQHpou4p52B3xYjUXe113sqrKS+5KZTOWlTKRFYHYMpeOhx5/D1lMfkQlcd0F 280cm/QGsDeRgI9Q73xPCk78QucZ+Qbue3udHsY4R30Lzlb7MvX7OupYJno2UjyBcnKX NpxsSoGx4RYV874YYLcniGG0S8yt7SNTWWVDAUuTFCf72XWQwnFPEYJ68crzpnqmjyBO i4G/pL0I4DkHlBNj4/bbFdTOaiRWKVxq7Y0+yYmhPzIK9cuYUmyXH9338CJdLwVwJ40a IeNA== X-Gm-Message-State: AAQBX9dR6lE7WE5zeqpZGZPUwWUIzpFdPfik4Pjr7UuYBYjL99tHwI9J yn4ZIdMCvFbNmMdbVhfZfcZLCnyYmZ6dq9tvKLehzw== X-Received: by 2002:a05:6870:339e:b0:17e:7674:8df0 with SMTP id w30-20020a056870339e00b0017e76748df0mr281290oae.9.1680557008648; Mon, 03 Apr 2023 14:23:28 -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: Mon, 3 Apr 2023 14:23:17 -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 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 wrote: > > 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 would > 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 deep > 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. 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? Thank you. Raghavendra > > + start =3D start_gfn << PAGE_SHIFT; > > + end =3D (start_gfn + pages) << PAGE_SHIFT; > > + > > + kvm_call_hyp(__kvm_tlb_flush_range_vmid_ipa, &kvm->arch.mmu, > > + start, end, KVM_PGTABLE_MAX_LEVELS - 1, 0); > > + return 0; > > +} > > + > > static bool kvm_is_device_pfn(unsigned long pfn) > > { > > return !pfn_is_map_memory(pfn); > > -- > > 2.39.1.519.gcb327c4b5f-goog > > > > > > -- > Thanks, > Oliver