Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1804340pxb; Wed, 20 Oct 2021 12:05:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3WyHFGO1HnxLpAMzkebgyhe+TKJ2SuAoauTkRd9RZCWEaFV8dZJ6LLx9+85KXDyauFFbl X-Received: by 2002:a17:906:a106:: with SMTP id t6mr1438785ejy.170.1634756734651; Wed, 20 Oct 2021 12:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634756734; cv=none; d=google.com; s=arc-20160816; b=vNbo1tt0iIOvzd7PVXecXQ+2xgrKvEJa1xbF7CNinXbqqIq4DxCI2cUYDQNLmYBt4u JUQjqNeLqKncdb4i1AvUUR974eSK9bYAAuN+IghqKAMj/C0jPb2cRgdFMMbmVwZTpS7h 3SsZGnKXV57GmQiQ6BVsZxqWuLKtf6Oo1ao8MjZ5hPYJSSZjgXiU6jTOmTAe8bOBDDmd 6irjWmco1LhU0IU7DibR0noioFvewq01TuaaRrT9WuVVqQnZ1tdJ7aHSn+ox05zbbobA ol8/7SnULSTrd/r+C7NiqWVHXZ0fUHmNCkM+oInEVu8vMjx5f4rf5auy0sbPzDbHsXrD pf2A== 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=DANx3HO6cgPisAl+CHhBZy+n2kHgp44pkICwDmul91Y=; b=t8Rnbp8CXYGsQ0Zq0yMpUSYVbTPW2QmGMJVK/3IbZFwEoiVCuZqSX8BTxmKYMf9C1F /SShVUFAH7sL16FnzV2nRF7PynfeIZw/Ez8GNpcGTlZPi3cqQpvbnQxzzhd7KQjFjW6B EmY4bNuwEZAm2DfhG1H5cjVKrc8ElOPiQbqdx0QIWrxEc1hIWkLov8652zte2WqJ49nL 2mWv/PDkuU6rb6LZ6qw1ocCdkP09OMnF//gImldNyhUujtiofHsLthCqzEdFtu5/GNIp TcgUklyZfNSvbzHx9y2HV/tHAwTeggCU73IEyVOSwYi0GqFFzbALYquJ2njHcR7iaFXb cQHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=T2NpTM70; 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 q18si4006748ejz.555.2021.10.20.12.05.07; Wed, 20 Oct 2021 12:05:34 -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=T2NpTM70; 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 S231397AbhJTTEN (ORCPT + 99 others); Wed, 20 Oct 2021 15:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230290AbhJTTEL (ORCPT ); Wed, 20 Oct 2021 15:04:11 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B14C061749 for ; Wed, 20 Oct 2021 12:01:57 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id oa4so3156583pjb.2 for ; Wed, 20 Oct 2021 12:01:57 -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=DANx3HO6cgPisAl+CHhBZy+n2kHgp44pkICwDmul91Y=; b=T2NpTM70PleU3Fgawia08s/phmB4W9mNfejNL2ZIBKiqj1LnIfPkJ+ajkOUm4p8Y7R yJg0aSR2qHZf4XvVVbHhpfkkoD/wL+gJv6TazBaQGH9k1P9sdh7Pl231jNNfXqq0ruDH wZMWuKyi7HsMW1lnaT5GRWpsVhH2KQWmRxtNTe79CVhjYrTnfcdej/kOgHttUwopLFE3 f/XdT1INFEaMarLdmGz6fIQddAsdZo37xruTpsVsMwQhmW9Z6C4rkSQBfx2bKTBKEmYQ sCjar7V528p8iltu4Z7FeKclr2dmHxuvQ3iXKTSvd3/w+Om0wfpCOQ4/noJJP+52FLO7 B4Tw== 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=DANx3HO6cgPisAl+CHhBZy+n2kHgp44pkICwDmul91Y=; b=Ibklo+9Jc6Nw9ryRSEPyPzOqAPyiS5niM2Ejt2yztr2k0DhcHRSHzUrfsusUbagS3M 9YoAUmTCez4D6AfuwXzcYL7zYHklASOckoIaaCPqbS5m5oyOkdWt0aWwG6V46/QR/VXN 7fCnvjezcXSvb84Hsz0wmqGVRC24WBFK5/4BXp9d6gRpUN6214aUXcpjoiRLeWXWbsO9 V/ZBWSamMFyUsFRg2BvtDJJR7hD05uxdPPl3F7C0ob+vuU509ahoD7N8pCu19KAQfwHm en4T/CZPHnUIlKUfhTqUenaGcjjZ7zIjjhMt4bL34vwSkzn1ApIweEYRa9A0c5Y4b3PC 83Nw== X-Gm-Message-State: AOAM530wZ5Mg7q0lBDTSjcbkib6JbXtoiFPlCZr2nxZgAxDXvr1sdwT1 6sWDvHgEL7FXrL7RByZ9k22eqw== X-Received: by 2002:a17:903:230f:b0:13f:cca9:bf2f with SMTP id d15-20020a170903230f00b0013fcca9bf2fmr821720plh.51.1634756516653; Wed, 20 Oct 2021 12:01:56 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id j198sm3003802pgc.4.2021.10.20.12.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 12:01:55 -0700 (PDT) Date: Wed, 20 Oct 2021 19:01:51 +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 01/13] KVM: x86: Cache total page count to avoid traversing the memslot array 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 Wed, Oct 20, 2021, Maciej S. Szmigiero wrote: > On 20.10.2021 00:24, Sean Christopherson wrote: > > E.g. the whole thing can be > > > > if (!kvm->arch.n_requested_mmu_pages && > > (change == KVM_MR_CREATE || change == KVM_MR_DELETE)) { > > unsigned long nr_mmu_pages; > > > > if (change == KVM_MR_CREATE) { > > kvm->arch.n_memslots_pages += new->npages; > > } else { > > WARN_ON(kvm->arch.n_memslots_pages < old->npages); > > kvm->arch.n_memslots_pages -= old->npages; > > } > > > > nr_mmu_pages = (unsigned long)kvm->arch.n_memslots_pages; > > nr_mmu_pages *= (KVM_PERMILLE_MMU_PAGES / 1000); > > The above line will set nr_mmu_pages to zero since KVM_PERMILLE_MMU_PAGES > is 20, so when integer-divided by 1000 will result in a multiplication > coefficient of zero. Ugh, math. And thus do_div() to avoid the whole 64-bit divide issue on 32-bit KVM. Bummer.