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 90708C433FE for ; Thu, 19 May 2022 16:44:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbiESQoD (ORCPT ); Thu, 19 May 2022 12:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbiESQn5 (ORCPT ); Thu, 19 May 2022 12:43:57 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77CE559095 for ; Thu, 19 May 2022 09:43:56 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id f10so5811195pjs.3 for ; Thu, 19 May 2022 09:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=221Yw0kf0kWHOuKCBmfC/ycEQMuPJsFgC9zSqVTAwSA=; b=bu8vQ+GWvqJrRdEuq8YVrsfud1b3bQhlBNIuRQm9N4t2Lj3E7ojrr5du8GpLJyVQpt zI6LAgP0cWVNyhkC2dx8jWx3d1dzS6qKn2apfQz90gm0zn8LV2J6jLUuu+darR0d5jp1 LpTWI9ig8g7I0oCfkW8terjt+U3QuRwraIIgfyUbQlX7hnu3WzrJLPVhPL16qrotB7X8 X0sGHQiLnxPwCuwzmOoubt1yCoAYcRgt5bbtFh+Kh0gFthhZS04NdGml6wCRoLPw4YTT 8exX0VVLnNWqt0NnU9LMNUK3s3E1Z3IQqSxPNndBTJ1hO64zu+VRfQofIL4ohxv4FNRK FrmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=221Yw0kf0kWHOuKCBmfC/ycEQMuPJsFgC9zSqVTAwSA=; b=MLk/Ec8NINVDjukt3OHxE/sdh8nnBqBftku4mHrxVdtDz6GBm/RognSaUoJWyGAAdw sXx4cwp5db4iSYIE7LDJNMKfJ03VJLT45JY2WoyIP5FwxQKM56OacQD7QBb3sNWZ5WV0 3VpWk/aI68JO3qgMm7xunHgsENl1S+Dlzt18/wlhoBeWwlliVkf8aUYBDwW1LBvUycyc Isgk32VJ0XQL1WZhCItSm3qiXxJzcyo8LpOkVJB7uGCQbDpV0tBDo/Bjj6LOCW2qWMzQ oD626EhZQ1b/l+E7Vk+8xU3F/KiTDn5tx4B0M4mKmGJCtPFswNl1dTaxskEE4KZ8tJQR 3rPw== X-Gm-Message-State: AOAM530szMUzyiHwG3PXKFe83nZe3S5T0nSrYdw0AO+4/pDpYqTwilu6 32a1wZpoV1c6f0Z538d3lCVBng== X-Google-Smtp-Source: ABdhPJw2CROjZjF/tfI3pH/231wqbGMtrzoTlXEZCDadRe7+Y7fJupSq7bjozl06CSrvxLG1Gs7+EA== X-Received: by 2002:a17:902:b289:b0:161:872d:6f03 with SMTP id u9-20020a170902b28900b00161872d6f03mr5698065plr.30.1652978635790; Thu, 19 May 2022 09:43:55 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id jh9-20020a170903328900b0015e8d4eb1f8sm4027559plb.66.2022.05.19.09.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 09:43:55 -0700 (PDT) Date: Thu, 19 May 2022 16:43:51 +0000 From: Sean Christopherson To: Maxim Levitsky Cc: kvm@vger.kernel.org, Wanpeng Li , Vitaly Kuznetsov , Jani Nikula , Paolo Bonzini , Tvrtko Ursulin , Rodrigo Vivi , Zhenyu Wang , Joonas Lahtinen , Tom Lendacky , Ingo Molnar , David Airlie , Thomas Gleixner , Dave Hansen , x86@kernel.org, intel-gfx@lists.freedesktop.org, Daniel Vetter , Borislav Petkov , Joerg Roedel , linux-kernel@vger.kernel.org, Jim Mattson , Zhi Wang , Brijesh Singh , "H. Peter Anvin" , intel-gvt-dev@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: Re: [RFC PATCH v3 06/19] KVM: x86: mmu: add gfn_in_memslot helper Message-ID: References: <20220427200314.276673-1-mlevitsk@redhat.com> <20220427200314.276673-7-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220427200314.276673-7-mlevitsk@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 27, 2022, Maxim Levitsky wrote: > This is a tiny refactoring, and can be useful to check > if a GPA/GFN is within a memslot a bit more cleanly. This doesn't explain the actual motivation, which is to use the new helper from arch code. > Signed-off-by: Maxim Levitsky > --- > include/linux/kvm_host.h | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 252ee4a61b58b..12e261559070b 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1580,6 +1580,13 @@ int kvm_request_irq_source_id(struct kvm *kvm); > void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id); > bool kvm_arch_irqfd_allowed(struct kvm *kvm, struct kvm_irqfd *args); > > + > +static inline bool gfn_in_memslot(struct kvm_memory_slot *slot, gfn_t gfn) > +{ > + return (gfn >= slot->base_gfn && gfn < slot->base_gfn + slot->npages); > +} > + Spurious newline. > + > /* > * Returns a pointer to the memslot if it contains gfn. > * Otherwise returns NULL. > @@ -1590,12 +1597,13 @@ try_get_memslot(struct kvm_memory_slot *slot, gfn_t gfn) > if (!slot) > return NULL; > > - if (gfn >= slot->base_gfn && gfn < slot->base_gfn + slot->npages) > + if (gfn_in_memslot(slot, gfn)) > return slot; > else > return NULL; At this point, maybe: if (!slot || !gfn_in_memslot(slot, gfn)) return NULL; return slot; > } > > + > /* > * Returns a pointer to the memslot that contains gfn. Otherwise returns NULL. > * > -- > 2.26.3 >