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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 337BDC433EF for ; Tue, 19 Oct 2021 23:39:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16AC560C40 for ; Tue, 19 Oct 2021 23:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbhJSXlM (ORCPT ); Tue, 19 Oct 2021 19:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbhJSXlJ (ORCPT ); Tue, 19 Oct 2021 19:41:09 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86BDC061746 for ; Tue, 19 Oct 2021 16:38:55 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id s136so17612170pgs.4 for ; Tue, 19 Oct 2021 16:38:55 -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=2QsW5fKhp22EmYwLesRxP1OLU4KgoBD8JpSEUKHaa7U=; b=FF+oKNuXuU00ds8QRcbr8sqquKLJ4lADTJLozGgltzxK1vJNNa3JX+ICrkY1N3x5fH xb5TH5P7t7MeFi7+vruSFecBpwDZaBGidgcRbLz4uj4FlWxXFvErHYc6Tq9HNwHjfcL/ 2RlxSyk1TwEXi0zIB38Cqo/cvaeezCyd6SPhN3bCWZY17CN5WJZ2vfBY3+8Wa8OGSVtI WGasOZtksSYbDGJjHF5nUU2M5Gop3ebb57GX87eEuJsytHpw9607G+3Sm/TMVOPJsgzw /nPXMCdvr1WQ7JT6mFFCIA7gGJFX9fnYTujCkLs1TOYj0Ex4kvZP70hoBSpmMEiDDKoP 5a7Q== 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=2QsW5fKhp22EmYwLesRxP1OLU4KgoBD8JpSEUKHaa7U=; b=OwOX/qTokBIOILwwZXSYtUSTwoyY180D9KmivyfwoDhoegjpLCtfROu4F/rS4qL3Lt Osh+r8Mcvs+JZF3KlQz+GxvRVsX++Mf25obE+/xXM5mFuPVgcCbIrJAsOFai4/cwoCRG PCslj69fLN8goNKsUglPG7ahL0+IVpNLkiRM6Yk4sy1hHxSJpuMBMxY7Fp64YGaIZuVi 4ec+tcLEhUmjLQVrtfPXQpKG36WJowCcFyX8boXT55fsd+ewY9npQMtFUO86B/OudPIY NLyh+MCjzCrP5aqtzMWDXaT8v7eqJ3PQAPsxHm25E8Ope1a+IBqHY0slvuRhu+hgbFtZ e6+w== X-Gm-Message-State: AOAM532VB7KCYMMBB7Jjhlmc2/aaVYlHJ+bv9ix8Pd8Xg1eembSibU3A lhiohlv1IuMEid0xaw4my/8kvg== X-Google-Smtp-Source: ABdhPJx+NMf/4ZfMDchDW6N8cMJnMUiaMZv4+dmhnJZoV4qJJH2iE4M9g2JQOk/S53ObxAEo0exQ/w== X-Received: by 2002:a05:6a00:2343:b0:44d:2e13:3edf with SMTP id j3-20020a056a00234300b0044d2e133edfmr2744482pfj.72.1634686734917; Tue, 19 Oct 2021 16:38:54 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id p17sm3752720pju.34.2021.10.19.16.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Oct 2021 16:38:54 -0700 (PDT) Date: Tue, 19 Oct 2021 23:38:50 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Igor Mammedov , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 05/13] KVM: Integrate gfn_to_memslot_approx() into search_memslots() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 20, 2021, Maciej S. Szmigiero wrote: > @@ -1267,7 +1280,7 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn, int *index) > * itself isn't here as an inline because that would bloat other code too much. > */ > static inline struct kvm_memory_slot * > -__gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) > +__gfn_to_memslot_approx(struct kvm_memslots *slots, gfn_t gfn, bool approx) This function name is a misnomer. The helper is not an "approx" version, it's an inner helper that takes an @approx param. Unless someone has a more clever name, the dreaded four underscores seems like the way to go. Warning away users is a good thing in this case... > { > struct kvm_memory_slot *slot; > int slot_index = atomic_read(&slots->last_used_slot); > @@ -1276,7 +1289,7 @@ __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) > if (slot) > return slot; > > - slot = search_memslots(slots, gfn, &slot_index); > + slot = search_memslots(slots, gfn, &slot_index, approx); > if (slot) { > atomic_set(&slots->last_used_slot, slot_index); > return slot; > @@ -1285,6 +1298,12 @@ __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) > return NULL; > } > There's a comment that doesn't show up in this diff that should also be moved, and opportunistically updated. > +static inline struct kvm_memory_slot * > +__gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) > +{ > + return __gfn_to_memslot_approx(slots, gfn, false); > +} > + > static inline unsigned long > __gfn_to_hva_memslot(const struct kvm_memory_slot *slot, gfn_t gfn) > { E.g. this as fixup? diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 540fa948baa5..2964c773b36c 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1964,10 +1964,15 @@ static int kvm_s390_peek_cmma(struct kvm *kvm, struct kvm_s390_cmma_log *args, return 0; } +static int gfn_to_memslot_approx(struct kvm_memslots *slots, gfn_t gfn) +{ + return ____gfn_to_memslot(slots, cur_gfn, true); +} + static unsigned long kvm_s390_next_dirty_cmma(struct kvm_memslots *slots, unsigned long cur_gfn) { - struct kvm_memory_slot *ms = __gfn_to_memslot_approx(slots, cur_gfn, true); + struct kvm_memory_slot *ms = gfn_to_memslot_approx(slots, cur_gfn); int slotidx = ms - slots->memslots; unsigned long ofs = cur_gfn - ms->base_gfn; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 8fd9644f40b2..ec1a074c2f6e 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1274,13 +1274,8 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn, int *index, bool approx) return NULL; } -/* - * __gfn_to_memslot() and its descendants are here because it is called from - * non-modular code in arch/powerpc/kvm/book3s_64_vio{,_hv}.c. gfn_to_memslot() - * itself isn't here as an inline because that would bloat other code too much. - */ static inline struct kvm_memory_slot * -__gfn_to_memslot_approx(struct kvm_memslots *slots, gfn_t gfn, bool approx) +____gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn, bool approx) { struct kvm_memory_slot *slot; int slot_index = atomic_read(&slots->last_used_slot); @@ -1298,10 +1293,15 @@ __gfn_to_memslot_approx(struct kvm_memslots *slots, gfn_t gfn, bool approx) return NULL; } +/* + * __gfn_to_memslot() and its descendants are here to allow arch code to inline + * the lookups in hot paths. gfn_to_memslot() itself isn't here as an inline + * because that would bloat other code too much. + */ static inline struct kvm_memory_slot * __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) { - return __gfn_to_memslot_approx(slots, gfn, false); + return ____gfn_to_memslot(slots, gfn, false); } static inline unsigned long