From nobody Wed Nov 5 02:29:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532936613040779.405947386217; Mon, 30 Jul 2018 00:43:33 -0700 (PDT) Received: from localhost ([::1]:50941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fk2pz-0006Hd-0F for importer@patchew.org; Mon, 30 Jul 2018 03:43:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fk2oS-0005Sr-1F for qemu-devel@nongnu.org; Mon, 30 Jul 2018 03:41:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fk2oP-0001KT-AY for qemu-devel@nongnu.org; Mon, 30 Jul 2018 03:41:52 -0400 Received: from mga05.intel.com ([192.55.52.43]:40268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fk2oP-0001K9-2Y for qemu-devel@nongnu.org; Mon, 30 Jul 2018 03:41:49 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jul 2018 00:41:48 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by fmsmga004.fm.intel.com with ESMTP; 30 Jul 2018 00:41:46 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,422,1526367600"; d="scan'208";a="75663664" From: Wei Wang To: qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, quintela@redhat.com Date: Mon, 30 Jul 2018 15:13:56 +0800 Message-Id: <1532934837-5966-2-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532934837-5966-1-git-send-email-wei.w.wang@intel.com> References: <1532934837-5966-1-git-send-email-wei.w.wang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH 1/2] bitmap.h: add comments to BITMAP_LAST_WORD_MASK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This macro was ported from Linux and we've reached an aggreement there that the corner case "nbits =3D 0" is not applicable to this macro, because when "nbits =3D 0", which means no bits to mask, this macro is expected to return 0, instead of 0xffffffff. This patch simply adds a comment above the macro as a note to users about the corner case. Signed-off-by: Wei Wang CC: Dr. David Alan Gilbert CC: Juan Quintela CC: Peter Xu --- include/qemu/bitmap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 509eedd..f53c640 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -60,6 +60,7 @@ */ =20 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG -= 1))) +/* "nbits =3D 0" is not applicable to this macro. Callers should avoid tha= t. */ #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG -= 1))) =20 #define DECLARE_BITMAP(name,bits) \ --=20 2.7.4 From nobody Wed Nov 5 02:29:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532936612200795.9535238522974; Mon, 30 Jul 2018 00:43:32 -0700 (PDT) Received: from localhost ([::1]:50942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fk2q3-0006Kx-6H for importer@patchew.org; Mon, 30 Jul 2018 03:43:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fk2oT-0005T6-V6 for qemu-devel@nongnu.org; Mon, 30 Jul 2018 03:41:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fk2oT-0001Li-8Z for qemu-devel@nongnu.org; Mon, 30 Jul 2018 03:41:53 -0400 Received: from mga05.intel.com ([192.55.52.43]:40271) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fk2oS-0001LU-VT for qemu-devel@nongnu.org; Mon, 30 Jul 2018 03:41:53 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jul 2018 00:41:51 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by fmsmga004.fm.intel.com with ESMTP; 30 Jul 2018 00:41:48 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,422,1526367600"; d="scan'208";a="75663665" From: Wei Wang To: qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, quintela@redhat.com Date: Mon, 30 Jul 2018 15:13:57 +0800 Message-Id: <1532934837-5966-3-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532934837-5966-1-git-send-email-wei.w.wang@intel.com> References: <1532934837-5966-1-git-send-email-wei.w.wang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH 2/2] bitmap: fix bitmap_count_one X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since "nbits =3D 0" is not applicable to the BITMAP_LAST_WORD_MASK macro, callers need to avoid passing "nbits =3D 0" to this macro, which generates incorrect results. Signed-off-by: Wei Wang CC: Dr. David Alan Gilbert CC: Juan Quintela CC: Peter Xu --- include/qemu/bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index f53c640..e45e9c0 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -223,7 +223,7 @@ static inline int bitmap_intersects(const unsigned long= *src1, static inline long bitmap_count_one(const unsigned long *bitmap, long nbit= s) { if (small_nbits(nbits)) { - return ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits)); + return nbits ? ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits)) : 0; } else { return slow_bitmap_count_one(bitmap, nbits); } --=20 2.7.4