Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1802870pxj; Wed, 19 May 2021 14:25:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbH2a6BtBe4VZpUTnv5M6j9iSfnzQL3XxkLDTUYfZwKS7K4RmC7L1p/xDx/dGhiHfBx36s X-Received: by 2002:a05:6e02:1a04:: with SMTP id s4mr1247800ild.125.1621459536338; Wed, 19 May 2021 14:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621459536; cv=none; d=google.com; s=arc-20160816; b=fNilG8OUy+kMUQEsoJRGcHvn6XW5mHJoOR6sHt3uGM79Ec/8IoXvGncv4dXOWQ6heY ikrmkoOIkHd8PWAdafVXxIziPNHIiVnASKex+3keRR140Ew21O/dY6kJCCN0nAAFbd9X 5cKfNrcRmm4sQfaHMsRWPIQuI2c2dFyRl5oeezxKteLd3pLhOHlSxkPbiQqRJrduaKMu IYjvJqk5oNZ0blYvUyjkJKyvfmxJqsBmEZ4m3DdVQNyrgzCtzm8NFMl3CliPW4EvZdor kHCteZ/ND5mwJ2DeZ7tF9WD2S0BHYPqYkQpDxPWQia5qXSHaXjsK8+i4RM5sWUz4+/aR Gvvg== 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=N3dW/ATcWO3PY6v2BY4HSFEQmmBCUs+/OWJJEnN9Srk=; b=FdfU7aD7uAwhxlci1EmxOoswMOChRt4hJGfonpa85MZ20dQvZMmCjB5gNZjPZVudhS 8Ramq6lgjcbTBL13kOXULTwjFaLhId6S2WCbMq2OuRUJwz8jSIOfo+po488Nk7VY4822 FQWVPO4kWy8ogOYhbK4NrpNMoRajZsIr1dFQcGmQZte7ZUkDuLIAhGnA6hOYrIf69R73 xAmISulAheQ4baQSa9Ti++I70GYpR6OS4DynTcmBjN9W5JX49fYzgA7OStkfiq6OKDmh f3OAKF9tIMNJvWJkCNFXKX7Vtm1MhX5DoSLAC5WW0dcaBDfqhmlQjZH01Fz1ykiQ/rJr qeag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CeeodCR0; 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 5si967633ilx.117.2021.05.19.14.25.23; Wed, 19 May 2021 14:25:36 -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=20161025 header.b=CeeodCR0; 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 S229464AbhESVZb (ORCPT + 99 others); Wed, 19 May 2021 17:25:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbhESVZa (ORCPT ); Wed, 19 May 2021 17:25:30 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70CE8C06175F for ; Wed, 19 May 2021 14:24:10 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id m124so10341718pgm.13 for ; Wed, 19 May 2021 14:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=N3dW/ATcWO3PY6v2BY4HSFEQmmBCUs+/OWJJEnN9Srk=; b=CeeodCR0FxrR09xkryZqzSbIZOBk/0Oj2AxolLq4hJHYw2ZUIoRQL800ilJbQlJAvZ DwyjP0YDXa+V4mOt0fb0uPYLnysNRf/IYlZg5rN/trEG2zvIUnulTsI4YLG8iadSTeML pWlhklwtfesO0K05zO+pumkh733cZPEEmfD6Ux4Qp7LC2UlJhqeUejQYKcHlFpwH001j zhPYs1kj5VOTVDUjJUGsD9HHbAj9XPum73dibf2FWrUvc1e7EDjr+dWOEL276oPxQOJq TxMoA9UsZKLAn5/TeaasOkI/PGe8a2a+rhB8p1r9HGUtIjvOKryy4zq/zaj8nxu4QEP0 4F+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=N3dW/ATcWO3PY6v2BY4HSFEQmmBCUs+/OWJJEnN9Srk=; b=dBWcBh4J4taxpDjlYMCL2jK3bTiqL8r1nMO3C6VjtAR3m49fF92zV0kMFKvmhMEINK A6kJ3eGHi6Q0BaF2sp+ZIRa/1wU2H7dYsq8FxyxiRpYSjUCU9IUGvEq8b0VbUmeAKFsp ZCnZlWUasgiSbaljwgu8qpQDNjHQzxftH5C33zGQGd2mdCHgYxK0bqcETB1GyPqrL2lM 7H64kATQRMixg+PYlLOg/aI0N075Ddgc03MP9U6nvcxMc43sLpl7Iy32k2DvSPSSPAK2 li9WLX/kH6wnbEWzPliHDbaKnLPk/CGn9P8T55hpwlI3Zd1B/HqpLElsyaemp0z2Yt+B uEZw== X-Gm-Message-State: AOAM532UPS0PvCzI2gSq8y5FbVD5TuQbe2K4YxdM/Buquvc46H6giNjj iGtWrVFc3UeBEdNxmcsO7zbyqA== X-Received: by 2002:a62:d411:0:b029:2b5:fce4:7e64 with SMTP id a17-20020a62d4110000b02902b5fce47e64mr1328219pfh.15.1621459449756; Wed, 19 May 2021 14:24:09 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id x13sm314784pjl.22.2021.05.19.14.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 14:24:09 -0700 (PDT) Date: Wed, 19 May 2021 21:24:05 +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 v3 2/8] 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 Sun, May 16, 2021, Maciej S. Szmigiero wrote: > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 8895b95b6a22..3c40c7d32f7e 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1091,10 +1091,14 @@ bool kvm_arch_irqfd_allowed(struct kvm *kvm, struct kvm_irqfd *args); > * gfn_to_memslot() itself isn't here as an inline because that would > * bloat other code too much. > * > + * With "approx" set returns the memslot also when the address falls > + * in a hole. In that case one of the memslots bordering the hole is > + * returned. > + * > * IMPORTANT: Slots are sorted from highest GFN to lowest GFN! > */ > static inline struct kvm_memory_slot * > -search_memslots(struct kvm_memslots *slots, gfn_t gfn) > +search_memslots(struct kvm_memslots *slots, gfn_t gfn, bool approx) An alternative to modifying the PPC code would be to make the existing search_memslots() a wrapper to __search_memslots(), with the latter taking @approx. We might also want to make this __always_inline to improve the likelihood of the compiler optimizing away @approx. I doubt it matters in practice... > { > int start = 0, end = slots->used_slots; > int slot = atomic_read(&slots->lru_slot); > @@ -1116,19 +1120,22 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn) > start = slot + 1; > } > > + if (approx && start >= slots->used_slots) > + return &memslots[slots->used_slots - 1]; > + > if (start < slots->used_slots && gfn >= memslots[start].base_gfn && > gfn < memslots[start].base_gfn + memslots[start].npages) { > atomic_set(&slots->lru_slot, start); > return &memslots[start]; > } > > - return NULL; > + return approx ? &memslots[start] : NULL; > } > > static inline struct kvm_memory_slot * > __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) > { > - return search_memslots(slots, gfn); > + return search_memslots(slots, gfn, false); > } > > static inline unsigned long