Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3503594pxb; Mon, 24 Jan 2022 10:56:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRrfjN+fbRSguit87GsaBySduk/4pePRG2QfjJJ7EF7wHqEAFvZG0fl6WvzLObNNrsvx9/ X-Received: by 2002:a17:902:6b06:b0:14b:550b:4caa with SMTP id o6-20020a1709026b0600b0014b550b4caamr4996443plk.111.1643050573922; Mon, 24 Jan 2022 10:56:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643050573; cv=none; d=google.com; s=arc-20160816; b=e1hbosrEUuRGM6MZrXgUehiMNAhoroxH/pvhXialcCYSL+frmoE8DeCQi7cBUORZfJ KxHsmIB+giuRcA2xCLJ8PTkzcYUohvu5rTcYn90Ejwzs7Zw0TFehYtDr3ZXA1AwKYCMt CWItnt683NXk6sW8EDApX05c9pbhFw39HIAr5m2kqVe4nYG0XcjmKyRHMka+ZSwa+0Tz VX0xCvOX3bu4syD9j7a+EtCsslFNqCfWbm1FmE02SGZLA+c3I5NjJyVdHMf5qv3kooHb r6JlU8AdfWJGrb03zkytqC3pHkXDLiCZEexTozFzPube1nyc2QabUgy0uTIURGXCnAjj ht8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=OMYGpin1GmNWwbbojqUVpe990D8pktHZFFcCMALRStg=; b=0Vp6jMD3KU3nAUSND4ZrctLIbuRkcFzPoIej9PiODDNjZDSt2UXhsYQImS/EwGo7vo Q+4fXuwWgEsT3CuG/u41R78UoQBebdszHF5hg7DIl3MFWUz2jjxyM6cTuVWDTu7V6JFB 5dWBmmNB+1Y6chfq3Gm6c9cKm1H8FqBMnl77m5DWHLfhSjerM8odk8I6B6E2JyUvI9vt OQ+WLuEDs47jbFVvnWr8LzSovqCuGvwu1Ny2v9Cnt5K0/qdf/g+I2k2nsbM9aaC+qHI5 0UmexTas1QTeKrQy4SMjwZy1N2EzB3O2RXoMKYmw2yMoQ0vRA/xJiZmt2Ylfbj+zQiKy in9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Qxf+qyNb; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s3si13472244plr.259.2022.01.24.10.56.02; Mon, 24 Jan 2022 10:56:13 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=Qxf+qyNb; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242589AbiAXJLT (ORCPT + 99 others); Mon, 24 Jan 2022 04:11:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48871 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242495AbiAXJLT (ORCPT ); Mon, 24 Jan 2022 04:11:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643015478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OMYGpin1GmNWwbbojqUVpe990D8pktHZFFcCMALRStg=; b=Qxf+qyNbCFwzV0dDYx0RHHaSgsE8BSOZQvwNZNfSoARuSg0oad6ALkFwndvWdyqbFmv5EF 6mlvDKwFS76vkP4NTQ6QUK5tj3uu5Yx/P0FAWLTf7L637ICetVF7t/2CVJBU+zdmmvcMn2 vG3/d7qMgnOzUK23cpCV3XWzvsYz25A= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-r0nWPPzbMRelsuvEWwVEzw-1; Mon, 24 Jan 2022 04:11:16 -0500 X-MC-Unique: r0nWPPzbMRelsuvEWwVEzw-1 Received: by mail-wr1-f69.google.com with SMTP id j26-20020adfb31a000000b001d8e22f75fbso1594766wrd.20 for ; Mon, 24 Jan 2022 01:11:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=OMYGpin1GmNWwbbojqUVpe990D8pktHZFFcCMALRStg=; b=miSC4PXm2AHGJlvukUyqs7XNLVrfbtTq/QV1kszal9eSCi/vyfCHExDyxqMdBsOxz7 f2kmDPmg5T6W1vT69NFGpltlC5Q5PFmZb8X+BPThZpcLJ68rsmpnVhHvXpipqtzRt1oj YrcbIsDYzPnuddkmpBAg+AkUuDgn1VVwBHWElEuRmnv8hczT6iz71+M5P7a7ucChKQRy ocC6NmY7jRRobFf7hPDoBNJDJkgadq+1yreP5K7qZzBnJ1Me2j/AWmYqvvlit7dmNq2L px28mlxSV6/mGMOqEdBqYr2D2kcJn0hyCwd48VFt0EJO0vukO0sl/dCnqoGy/N8Wk5fs /7Tw== X-Gm-Message-State: AOAM533D/6sFTDwfyGLtK/v2fAaWoB15pYjvAP7HGUeg14KVpDgiYUQR lljjD9onE3um7wu5rMW5lEQwi1R/JDaMGgoVyScDu8lavE368Wjz1dfEjt+Cz/U1PCqWIHOpo9z trFO04D4WPEhL1xDoTIhNdnfE X-Received: by 2002:a5d:598a:: with SMTP id n10mr13089714wri.582.1643015475062; Mon, 24 Jan 2022 01:11:15 -0800 (PST) X-Received: by 2002:a5d:598a:: with SMTP id n10mr13089684wri.582.1643015474784; Mon, 24 Jan 2022 01:11:14 -0800 (PST) Received: from fedora (nat-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id v5sm18175419wmh.19.2022.01.24.01.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 01:11:14 -0800 (PST) From: Vitaly Kuznetsov To: Yury Norov Cc: Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?utf-8?Q?Micha=C5=82_Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH 06/54] x86/kvm: replace bitmap_weight with bitmap_empty where appropriate In-Reply-To: <20220123183925.1052919-7-yury.norov@gmail.com> References: <20220123183925.1052919-1-yury.norov@gmail.com> <20220123183925.1052919-7-yury.norov@gmail.com> Date: Mon, 24 Jan 2022 10:11:12 +0100 Message-ID: <87y235ijm7.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yury Norov writes: > In some places kvm/hyperv.c code calls bitmap_weight() to check if any bit > of a given bitmap is set. It's better to use bitmap_empty() in that case > because bitmap_empty() stops traversing the bitmap as soon as it finds > first set bit, while bitmap_weight() counts all bits unconditionally. > > Signed-off-by: Yury Norov > --- > arch/x86/kvm/hyperv.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index 6e38a7d22e97..2c3400dea4b3 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -90,7 +90,7 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, > { > struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic); > struct kvm_hv *hv = to_kvm_hv(vcpu->kvm); > - int auto_eoi_old, auto_eoi_new; > + bool auto_eoi_old, auto_eoi_new; > > if (vector < HV_SYNIC_FIRST_VALID_VECTOR) > return; > @@ -100,16 +100,16 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, > else > __clear_bit(vector, synic->vec_bitmap); > > - auto_eoi_old = bitmap_weight(synic->auto_eoi_bitmap, 256); > + auto_eoi_old = bitmap_empty(synic->auto_eoi_bitmap, 256); I would've preferred this written as auto_eoi_old = !bitmap_empty(synic->auto_eoi_bitmap, 256); so the variable would indicate wether AutoEOI was previosly enabled, not disabled. > > if (synic_has_vector_auto_eoi(synic, vector)) > __set_bit(vector, synic->auto_eoi_bitmap); > else > __clear_bit(vector, synic->auto_eoi_bitmap); > > - auto_eoi_new = bitmap_weight(synic->auto_eoi_bitmap, 256); > + auto_eoi_new = bitmap_empty(synic->auto_eoi_bitmap, 256); Same here, of course. "auto_eoi_new = true" sounds like "AutoEOI is now enabled". > > - if (!!auto_eoi_old == !!auto_eoi_new) > + if (auto_eoi_old == auto_eoi_new) > return; > > down_write(&vcpu->kvm->arch.apicv_update_lock); The change look good to me otherwise, feel free to add Reviewed-by: Vitaly Kuznetsov -- Vitaly