Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp938484pxb; Tue, 19 Oct 2021 16:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2TDXIS6ODV1/a+/AJz4F2uNYNAZg8UPzLnmUk2AJbk4X5QAJYkXuxcysc77JAwUx3d/c4 X-Received: by 2002:aa7:8d09:0:b0:44b:fd25:dd8a with SMTP id j9-20020aa78d09000000b0044bfd25dd8amr2877118pfe.41.1634686921818; Tue, 19 Oct 2021 16:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634686921; cv=none; d=google.com; s=arc-20160816; b=zzDkZFClGrP3H/0VtjqSS0VkhduOLQRwjFrQmobRHaz7lOf4gjH/e3PfApiPRRErOA 6T73jK0MKzIlfAPs2yk3xWCu+TfwG6/maIXg7IH2OkoTNtirrpouO1amXIsORYdlnoj/ brXXQgL4JRvjMiOz0tJGaJzDPg8Zn5vOvHB+YEBDmgujIhgV6w2NjaiqJ9VC1h7jcXnT yT8DCjVZBUszPzsnIpU6kN29oC72QR3eY60GZD/fJ93P+i3CcCb9XSIEklcz51SjXjeA /lvIdzt+K5UZWhsghCvR1xqZPuqvJsWwA5U2FJgw+n1/tJHUn37fRVw0KHLYukKVaBCb oSVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2QsW5fKhp22EmYwLesRxP1OLU4KgoBD8JpSEUKHaa7U=; b=XueARO24bN+CBi1m1YS7I6jZFjlBf0ak3mzzsNQ5vwe6/LzcyT0w7xQAikhFmOf7YO 5aJsc6RDoZvHGLphR0BG2g5nZ6QC/AEo6skggfXr7d1WD75G5r0T8tFvxZ9b3SCPoYSd AtHIRnLjjlKCenP9i+JCmdUGYjdKpaBFB/D7yEPuGXifCu6aS9dCtX0xr7oL+p4m0zle KvyvbpuiKvAzhFW4JV+FpLaU6XtTnn5IXCJEujeBPjS7s4Exbepbn9E9fGo1c77bEnpP OdDiv1FZ87MtFij+unctjqwLbovDWVku5kl2chFojkZ/ujlJzSZ5iLW4FmxPQd8VYTpe pYkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FF+oKNuX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o13si6178385pji.10.2021.10.19.16.41.44; Tue, 19 Oct 2021 16:42:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FF+oKNuX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230020AbhJSXlK (ORCPT + 99 others); Tue, 19 Oct 2021 19:41:10 -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-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