Merge tag 'bitmap-for-5.19-rc1' of https://github.com/norov/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 4 Jun 2022 21:04:27 +0000 (14:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 4 Jun 2022 21:04:27 +0000 (14:04 -0700)
Pull bitmap updates from Yury Norov:

 - bitmap: optimize bitmap_weight() usage, from me

 - lib/bitmap.c make bitmap_print_bitmask_to_buf parseable, from Mauro
   Carvalho Chehab

 - include/linux/find: Fix documentation, from Anna-Maria Behnsen

 - bitmap: fix conversion from/to fix-sized arrays, from me

 - bitmap: Fix return values to be unsigned, from Kees Cook

It has been in linux-next for at least a week with no problems.

* tag 'bitmap-for-5.19-rc1' of https://github.com/norov/linux: (31 commits)
  nodemask: Fix return values to be unsigned
  bitmap: Fix return values to be unsigned
  KVM: x86: hyper-v: replace bitmap_weight() with hweight64()
  KVM: x86: hyper-v: fix type of valid_bank_mask
  ia64: cleanup remove_siblinginfo()
  drm/amd/pm: use bitmap_{from,to}_arr32 where appropriate
  KVM: s390: replace bitmap_copy with bitmap_{from,to}_arr64 where appropriate
  lib/bitmap: add test for bitmap_{from,to}_arr64
  lib: add bitmap_{from,to}_arr64
  lib/bitmap: extend comment for bitmap_(from,to)_arr32()
  include/linux/find: Fix documentation
  lib/bitmap.c make bitmap_print_bitmask_to_buf parseable
  MAINTAINERS: add cpumask and nodemask files to BITMAP_API
  arch/x86: replace nodes_weight with nodes_empty where appropriate
  mm/vmstat: replace cpumask_weight with cpumask_empty where appropriate
  clocksource: replace cpumask_weight with cpumask_empty in clocksource.c
  genirq/affinity: replace cpumask_weight with cpumask_empty where appropriate
  irq: mips: replace cpumask_weight with cpumask_empty where appropriate
  drm/i915/pmu: replace cpumask_weight with cpumask_empty where appropriate
  arch/x86: replace cpumask_weight with cpumask_empty where appropriate
  ...

27 files changed:
MAINTAINERS
arch/alpha/kernel/process.c
arch/ia64/kernel/setup.c
arch/ia64/kernel/smpboot.c
arch/riscv/kernel/cpufeature.c
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/hyperv.c
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
drivers/gpu/drm/i915/i915_pmu.c
drivers/iio/dummy/iio_simple_dummy_buffer.c
drivers/net/dsa/b53/b53_common.c
drivers/net/ethernet/broadcom/bcmsysport.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
drivers/net/ethernet/mellanox/mlx4/cmd.c
drivers/net/ethernet/qlogic/qed/qed_rdma.c
drivers/net/ethernet/qlogic/qed/qed_roce.c
include/linux/bitmap.h
include/linux/find.h
include/linux/nodemask.h
lib/bitmap.c
lib/nodemask.c
lib/test_bitmap.c
mm/vmstat.c
tools/include/linux/bitmap.h
tools/lib/bitmap.c

index b951e4d4be90f2c8af411b77c9b2e25a9baf6f26..76c221313a431116708629950c77c6188495b354 100644 (file)
@@ -3533,10 +3533,14 @@ R:      Andy Shevchenko <andriy.shevchenko@linux.intel.com>
 R:     Rasmus Villemoes <linux@rasmusvillemoes.dk>
 S:     Maintained
 F:     include/linux/bitmap.h
+F:     include/linux/cpumask.h
 F:     include/linux/find.h
+F:     include/linux/nodemask.h
 F:     lib/bitmap.c
+F:     lib/cpumask.c
 F:     lib/find_bit.c
 F:     lib/find_bit_benchmark.c
+F:     lib/nodemask.c
 F:     lib/test_bitmap.c
 F:     tools/include/linux/bitmap.h
 F:     tools/include/linux/find.h
index 6cbba7370b4e2ce875391354ce53203c230d3204..e2e25f8b5e76c7285ec07c704b8c4887b5f3718b 100644 (file)
@@ -125,7 +125,7 @@ common_shutdown_1(void *generic_ptr)
        /* Wait for the secondaries to halt. */
        set_cpu_present(boot_cpuid, false);
        set_cpu_possible(boot_cpuid, false);
-       while (cpumask_weight(cpu_present_mask))
+       while (!cpumask_empty(cpu_present_mask))
                barrier();
 #endif
 
index 5010348fa21be0aa33114221d4e834707f6b9eee..fd6301eafa9d58a2d01ce240dda907a2cb601268 100644 (file)
@@ -572,7 +572,7 @@ setup_arch (char **cmdline_p)
 #ifdef CONFIG_ACPI_HOTPLUG_CPU
        prefill_possible_map();
 #endif
-       per_cpu_scan_finalize((cpumask_weight(&early_cpu_possible_map) == 0 ?
+       per_cpu_scan_finalize((cpumask_empty(&early_cpu_possible_map) ?
                32 : cpumask_weight(&early_cpu_possible_map)),
                additional_cpus > 0 ? additional_cpus : 0);
 #endif /* CONFIG_ACPI_NUMA */
index d10f780c13b9eca3d91b55e2249bc5b50da3302e..d0e935cf2093af382509ef440fd990ed85d4132f 100644 (file)
@@ -576,8 +576,6 @@ clear_cpu_sibling_map(int cpu)
 static void
 remove_siblinginfo(int cpu)
 {
-       int last = 0;
-
        if (cpu_data(cpu)->threads_per_core == 1 &&
            cpu_data(cpu)->cores_per_socket == 1) {
                cpumask_clear_cpu(cpu, &cpu_core_map[cpu]);
@@ -585,8 +583,6 @@ remove_siblinginfo(int cpu)
                return;
        }
 
-       last = (cpumask_weight(&cpu_core_map[cpu]) == 1 ? 1 : 0);
-
        /* remove it from all sibling map's */
        clear_cpu_sibling_map(cpu);
 }
index dea3ea19deeefec89c74af2255fd19aaf32f4717..a6f62a6d1edd92ca1cade5fd802daf718b08f35c 100644 (file)
@@ -213,11 +213,10 @@ void __init riscv_fill_hwcap(void)
                else
                        elf_hwcap = this_hwcap;
 
-               if (bitmap_weight(riscv_isa, RISCV_ISA_EXT_MAX))
-                       bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
-               else
+               if (bitmap_empty(riscv_isa, RISCV_ISA_EXT_MAX))
                        bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
-
+               else
+                       bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
        }
 
        /* We don't support systems with F but without D, so mask those out
index 76ad6408cb2cd0c2a4f5e91cbc3f735a7721e416..8fcb561416893fa2292e00cf99ff3ec872816f91 100644 (file)
@@ -1332,8 +1332,7 @@ static int kvm_s390_set_processor_feat(struct kvm *kvm,
                mutex_unlock(&kvm->lock);
                return -EBUSY;
        }
-       bitmap_copy(kvm->arch.cpu_feat, (unsigned long *) data.feat,
-                   KVM_S390_VM_CPU_FEAT_NR_BITS);
+       bitmap_from_arr64(kvm->arch.cpu_feat, data.feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
        mutex_unlock(&kvm->lock);
        VM_EVENT(kvm, 3, "SET: guest feat: 0x%16.16llx.0x%16.16llx.0x%16.16llx",
                         data.feat[0],
@@ -1504,8 +1503,7 @@ static int kvm_s390_get_processor_feat(struct kvm *kvm,
 {
        struct kvm_s390_vm_cpu_feat data;
 
-       bitmap_copy((unsigned long *) data.feat, kvm->arch.cpu_feat,
-                   KVM_S390_VM_CPU_FEAT_NR_BITS);
+       bitmap_to_arr64(data.feat, kvm->arch.cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
        if (copy_to_user((void __user *)attr->addr, &data, sizeof(data)))
                return -EFAULT;
        VM_EVENT(kvm, 3, "GET: guest feat: 0x%16.16llx.0x%16.16llx.0x%16.16llx",
@@ -1520,9 +1518,7 @@ static int kvm_s390_get_machine_feat(struct kvm *kvm,
 {
        struct kvm_s390_vm_cpu_feat data;
 
-       bitmap_copy((unsigned long *) data.feat,
-                   kvm_s390_available_cpu_feat,
-                   KVM_S390_VM_CPU_FEAT_NR_BITS);
+       bitmap_to_arr64(data.feat, kvm_s390_available_cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
        if (copy_to_user((void __user *)attr->addr, &data, sizeof(data)))
                return -EFAULT;
        VM_EVENT(kvm, 3, "GET: host feat:  0x%16.16llx.0x%16.16llx.0x%16.16llx",
index a0702b6be3e8979b894ce33c070bc613411b4adc..e2e95a6fccfde0f60f78bafb78cef40d48c23904 100644 (file)
@@ -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);
 
        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);
 
-       if (!!auto_eoi_old == !!auto_eoi_new)
+       if (auto_eoi_old == auto_eoi_new)
                return;
 
        if (!enable_apicv)
@@ -1855,7 +1855,7 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
                all_cpus = flush_ex.hv_vp_set.format !=
                        HV_GENERIC_SET_SPARSE_4K;
 
-               if (hc->var_cnt != bitmap_weight((unsigned long *)&valid_bank_mask, 64))
+               if (hc->var_cnt != hweight64(valid_bank_mask))
                        return HV_STATUS_INVALID_HYPERCALL_INPUT;
 
                if (all_cpus)
@@ -1956,7 +1956,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
                valid_bank_mask = send_ipi_ex.vp_set.valid_bank_mask;
                all_cpus = send_ipi_ex.vp_set.format == HV_GENERIC_SET_ALL;
 
-               if (hc->var_cnt != bitmap_weight((unsigned long *)&valid_bank_mask, 64))
+               if (hc->var_cnt != hweight64(valid_bank_mask))
                        return HV_STATUS_INVALID_HYPERCALL_INPUT;
 
                if (all_cpus)
index b87f550af26bae9661432e844c669089caf5adbf..5f8809f6990dd12a323fbedc3f810848f5ea9bb9 100644 (file)
@@ -781,7 +781,7 @@ int smu_v11_0_set_allowed_mask(struct smu_context *smu)
                goto failed;
        }
 
-       bitmap_copy((unsigned long *)feature_mask, feature->allowed, 64);
+       bitmap_to_arr32(feature_mask, feature->allowed, 64);
 
        ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskHigh,
                                          feature_mask[1], NULL);
index 7be4f6875a7bc57466785a08dd298b790b5ebbb2..ef9b56de143bbe620eaa4460762d2f5f44bd2591 100644 (file)
@@ -837,7 +837,7 @@ int smu_v13_0_set_allowed_mask(struct smu_context *smu)
            feature->feature_num < 64)
                return -EINVAL;
 
-       bitmap_copy((unsigned long *)feature_mask, feature->allowed, 64);
+       bitmap_to_arr32(feature_mask, feature->allowed, 64);
 
        ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskHigh,
                                              feature_mask[1], NULL);
index 3e3b09588fd37d4a0815edd7ed6daf6443985991..958b37123bf12bc9a5f96d09c24d6a81574dc0ad 100644 (file)
@@ -1047,7 +1047,7 @@ static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
        GEM_BUG_ON(!pmu->base.event_init);
 
        /* Select the first online CPU as a designated reader. */
-       if (!cpumask_weight(&i915_pmu_cpumask))
+       if (cpumask_empty(&i915_pmu_cpumask))
                cpumask_set_cpu(cpu, &i915_pmu_cpumask);
 
        return 0;
index d81c2b2dad82a51cc8cdd10d243c6ba60f2120f5..9b2f99449a8292c1ba59d847bce37576bc1c6522 100644 (file)
@@ -45,41 +45,31 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 {
        struct iio_poll_func *pf = p;
        struct iio_dev *indio_dev = pf->indio_dev;
+       int i = 0, j;
        u16 *data;
 
        data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
        if (!data)
                goto done;
 
-       if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) {
-               /*
-                * Three common options here:
-                * hardware scans: certain combinations of channels make
-                *   up a fast read.  The capture will consist of all of them.
-                *   Hence we just call the grab data function and fill the
-                *   buffer without processing.
-                * software scans: can be considered to be random access
-                *   so efficient reading is just a case of minimal bus
-                *   transactions.
-                * software culled hardware scans:
-                *   occasionally a driver may process the nearest hardware
-                *   scan to avoid storing elements that are not desired. This
-                *   is the fiddliest option by far.
-                * Here let's pretend we have random access. And the values are
-                * in the constant table fakedata.
-                */
-               int i, j;
-
-               for (i = 0, j = 0;
-                    i < bitmap_weight(indio_dev->active_scan_mask,
-                                      indio_dev->masklength);
-                    i++, j++) {
-                       j = find_next_bit(indio_dev->active_scan_mask,
-                                         indio_dev->masklength, j);
-                       /* random access read from the 'device' */
-                       data[i] = fakedata[j];
-               }
-       }
+       /*
+        * Three common options here:
+        * hardware scans:
+        *   certain combinations of channels make up a fast read. The capture
+        *   will consist of all of them. Hence we just call the grab data
+        *   function and fill the buffer without processing.
+        * software scans:
+        *   can be considered to be random access so efficient reading is just
+        *   a case of minimal bus transactions.
+        * software culled hardware scans:
+        *   occasionally a driver may process the nearest hardware scan to avoid
+        *   storing elements that are not desired. This is the fiddliest option
+        *   by far.
+        * Here let's pretend we have random access. And the values are in the
+        * constant table fakedata.
+        */
+       for_each_set_bit(j, indio_dev->active_scan_mask, indio_dev->masklength)
+               data[i++] = fakedata[j];
 
        iio_push_to_buffers_with_timestamp(indio_dev, data,
                                           iio_get_time_ns(indio_dev));
index fbb32aa49b2412fcbfbb03c50cd1b7035df1fa07..48cf344750ffdfce53704de46927bea24d10fd7a 100644 (file)
@@ -1603,12 +1603,8 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
                return 0;
        }
 
-       if (bitmap_weight(free_bins, dev->num_arl_bins) == 0)
-               return -ENOSPC;
-
        *idx = find_first_bit(free_bins, dev->num_arl_bins);
-
-       return -ENOENT;
+       return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
 }
 
 static int b53_arl_op(struct b53_device *dev, int op, int port,
index 3272aca496dc318d44612443b098e17d74db2c1e..47fc8e6963d599c5712c8102f7403999ba795984 100644 (file)
@@ -2180,13 +2180,9 @@ static int bcm_sysport_rule_set(struct bcm_sysport_priv *priv,
        if (nfc->fs.ring_cookie != RX_CLS_FLOW_WAKE)
                return -EOPNOTSUPP;
 
-       /* All filters are already in use, we cannot match more rules */
-       if (bitmap_weight(priv->filters, RXCHK_BRCM_TAG_MAX) ==
-           RXCHK_BRCM_TAG_MAX)
-               return -ENOSPC;
-
        index = find_first_zero_bit(priv->filters, RXCHK_BRCM_TAG_MAX);
        if (index >= RXCHK_BRCM_TAG_MAX)
+               /* All filters are already in use, we cannot match more rules */
                return -ENOSPC;
 
        /* Location is the classification ID, and index is the position
index 54f235c216a96520907d070afd60d73b5ef93128..2dd192b5e4e081b02c3f99feecf424b53f571431 100644 (file)
@@ -355,7 +355,7 @@ int otx2_add_macfilter(struct net_device *netdev, const u8 *mac)
 {
        struct otx2_nic *pf = netdev_priv(netdev);
 
-       if (bitmap_weight(&pf->flow_cfg->dmacflt_bmap,
+       if (!bitmap_empty(&pf->flow_cfg->dmacflt_bmap,
                          pf->flow_cfg->dmacflt_max_flows))
                netdev_warn(netdev,
                            "Add %pM to CGX/RPM DMAC filters list as well\n",
@@ -438,7 +438,7 @@ int otx2_get_maxflows(struct otx2_flow_config *flow_cfg)
                return 0;
 
        if (flow_cfg->nr_flows == flow_cfg->max_flows ||
-           bitmap_weight(&flow_cfg->dmacflt_bmap,
+           !bitmap_empty(&flow_cfg->dmacflt_bmap,
                          flow_cfg->dmacflt_max_flows))
                return flow_cfg->max_flows + flow_cfg->dmacflt_max_flows;
        else
index fe3472e04c231ff96a998b51d0f9c21b6feca0f1..9106c359e64c611eb9c271bf5b4af618a4f7ce28 100644 (file)
@@ -1120,7 +1120,7 @@ static int otx2_cgx_config_loopback(struct otx2_nic *pf, bool enable)
        struct msg_req *msg;
        int err;
 
-       if (enable && bitmap_weight(&pf->flow_cfg->dmacflt_bmap,
+       if (enable && !bitmap_empty(&pf->flow_cfg->dmacflt_bmap,
                                    pf->flow_cfg->dmacflt_max_flows))
                netdev_warn(pf->netdev,
                            "CGX/RPM internal loopback might not work as DMAC filters are active\n");
index e10b7b04b8941022e2103a93ed209e265d1da5ec..c56d2194cbfcd0bba24f4e87d673e8dbb205abb1 100644 (file)
@@ -1994,21 +1994,16 @@ static void mlx4_allocate_port_vpps(struct mlx4_dev *dev, int port)
 
 static int mlx4_master_activate_admin_state(struct mlx4_priv *priv, int slave)
 {
-       int port, err;
+       int p, port, err;
        struct mlx4_vport_state *vp_admin;
        struct mlx4_vport_oper_state *vp_oper;
        struct mlx4_slave_state *slave_state =
                &priv->mfunc.master.slave_state[slave];
        struct mlx4_active_ports actv_ports = mlx4_get_active_ports(
                        &priv->dev, slave);
-       int min_port = find_first_bit(actv_ports.ports,
-                                     priv->dev.caps.num_ports) + 1;
-       int max_port = min_port - 1 +
-               bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports);
 
-       for (port = min_port; port <= max_port; port++) {
-               if (!test_bit(port - 1, actv_ports.ports))
-                       continue;
+       for_each_set_bit(p, actv_ports.ports, priv->dev.caps.num_ports) {
+               port = p + 1;
                priv->mfunc.master.vf_oper[slave].smi_enabled[port] =
                        priv->mfunc.master.vf_admin[slave].enable_smi[port];
                vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port];
@@ -2063,19 +2058,13 @@ static int mlx4_master_activate_admin_state(struct mlx4_priv *priv, int slave)
 
 static void mlx4_master_deactivate_admin_state(struct mlx4_priv *priv, int slave)
 {
-       int port;
+       int p, port;
        struct mlx4_vport_oper_state *vp_oper;
        struct mlx4_active_ports actv_ports = mlx4_get_active_ports(
                        &priv->dev, slave);
-       int min_port = find_first_bit(actv_ports.ports,
-                                     priv->dev.caps.num_ports) + 1;
-       int max_port = min_port - 1 +
-               bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports);
 
-
-       for (port = min_port; port <= max_port; port++) {
-               if (!test_bit(port - 1, actv_ports.ports))
-                       continue;
+       for_each_set_bit(p, actv_ports.ports, priv->dev.caps.num_ports) {
+               port = p + 1;
                priv->mfunc.master.vf_oper[slave].smi_enabled[port] =
                        MLX4_VF_SMI_DISABLED;
                vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port];
index 23b668de46402e570f56ecd6b37b6cc71c3d0fe6..69b0ede75cae3161fb5ae61813042697cd0c8873 100644 (file)
@@ -319,44 +319,27 @@ free_rdma_dev:
 void qed_rdma_bmap_free(struct qed_hwfn *p_hwfn,
                        struct qed_bmap *bmap, bool check)
 {
-       int weight = bitmap_weight(bmap->bitmap, bmap->max_count);
-       int last_line = bmap->max_count / (64 * 8);
-       int last_item = last_line * 8 +
-           DIV_ROUND_UP(bmap->max_count % (64 * 8), 64);
-       u64 *pmap = (u64 *)bmap->bitmap;
-       int line, item, offset;
-       u8 str_last_line[200] = { 0 };
-
-       if (!weight || !check)
+       unsigned int bit, weight, nbits;
+       unsigned long *b;
+
+       if (!check)
+               goto end;
+
+       weight = bitmap_weight(bmap->bitmap, bmap->max_count);
+       if (!weight)
                goto end;
 
        DP_NOTICE(p_hwfn,
                  "%s bitmap not free - size=%d, weight=%d, 512 bits per line\n",
                  bmap->name, bmap->max_count, weight);
 
-       /* print aligned non-zero lines, if any */
-       for (item = 0, line = 0; line < last_line; line++, item += 8)
-               if (bitmap_weight((unsigned long *)&pmap[item], 64 * 8))
+       for (bit = 0; bit < bmap->max_count; bit += 512) {
+               b =  bmap->bitmap + BITS_TO_LONGS(bit);
+               nbits = min(bmap->max_count - bit, 512U);
+
+               if (!bitmap_empty(b, nbits))
                        DP_NOTICE(p_hwfn,
-                                 "line 0x%04x: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
-                                 line,
-                                 pmap[item],
-                                 pmap[item + 1],
-                                 pmap[item + 2],
-                                 pmap[item + 3],
-                                 pmap[item + 4],
-                                 pmap[item + 5],
-                                 pmap[item + 6], pmap[item + 7]);
-
-       /* print last unaligned non-zero line, if any */
-       if ((bmap->max_count % (64 * 8)) &&
-           (bitmap_weight((unsigned long *)&pmap[item],
-                          bmap->max_count - item * 64))) {
-               offset = sprintf(str_last_line, "line 0x%04x: ", line);
-               for (; item < last_item; item++)
-                       offset += sprintf(str_last_line + offset,
-                                         "0x%016llx ", pmap[item]);
-               DP_NOTICE(p_hwfn, "%s\n", str_last_line);
+                                 "line 0x%04x: %*pb\n", bit / 512, nbits, b);
        }
 
 end:
index 071b4aeaddf286f7b8943af9ca70b4745c843934..134ecfca96a3e83c0dcb7edc071b613ad46d6ffb 100644 (file)
@@ -76,7 +76,7 @@ void qed_roce_stop(struct qed_hwfn *p_hwfn)
         * We delay for a short while if an async destroy QP is still expected.
         * Beyond the added delay we clear the bitmap anyway.
         */
-       while (bitmap_weight(rcid_map->bitmap, rcid_map->max_count)) {
+       while (!bitmap_empty(rcid_map->bitmap, rcid_map->max_count)) {
                /* If the HW device is during recovery, all resources are
                 * immediately reset without receiving a per-cid indication
                 * from HW. In this case we don't expect the cid bitmap to be
index 7dba0847510ca56af8b50f3956db0634045ec4dd..2e6cd5681040918a2d7a5923e4fd75c3c3ed179e 100644 (file)
@@ -72,6 +72,8 @@ struct device;
  *  bitmap_allocate_region(bitmap, pos, order)  Allocate specified bit region
  *  bitmap_from_arr32(dst, buf, nbits)          Copy nbits from u32[] buf to dst
  *  bitmap_to_arr32(buf, src, nbits)            Copy nbits from buf to u32[] dst
+ *  bitmap_to_arr64(buf, src, nbits)            Copy nbits from buf to u64[] dst
+ *  bitmap_to_arr64(buf, src, nbits)            Copy nbits from buf to u64[] dst
  *  bitmap_get_value8(map, start)               Get 8bit value from map at start
  *  bitmap_set_value8(map, value, start)        Set 8bit value to map at start
  *
@@ -132,8 +134,8 @@ unsigned long *devm_bitmap_zalloc(struct device *dev,
  * lib/bitmap.c provides these functions:
  */
 
-int __bitmap_equal(const unsigned long *bitmap1,
-                  const unsigned long *bitmap2, unsigned int nbits);
+bool __bitmap_equal(const unsigned long *bitmap1,
+                   const unsigned long *bitmap2, unsigned int nbits);
 bool __pure __bitmap_or_equal(const unsigned long *src1,
                              const unsigned long *src2,
                              const unsigned long *src3,
@@ -157,10 +159,10 @@ int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
 void __bitmap_replace(unsigned long *dst,
                      const unsigned long *old, const unsigned long *new,
                      const unsigned long *mask, unsigned int nbits);
-int __bitmap_intersects(const unsigned long *bitmap1,
-                       const unsigned long *bitmap2, unsigned int nbits);
-int __bitmap_subset(const unsigned long *bitmap1,
-                   const unsigned long *bitmap2, unsigned int nbits);
+bool __bitmap_intersects(const unsigned long *bitmap1,
+                        const unsigned long *bitmap2, unsigned int nbits);
+bool __bitmap_subset(const unsigned long *bitmap1,
+                    const unsigned long *bitmap2, unsigned int nbits);
 int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
 void __bitmap_set(unsigned long *map, unsigned int start, int len);
 void __bitmap_clear(unsigned long *map, unsigned int start, int len);
@@ -264,8 +266,12 @@ static inline void bitmap_copy_clear_tail(unsigned long *dst,
 }
 
 /*
- * On 32-bit systems bitmaps are represented as u32 arrays internally, and
- * therefore conversion is not needed when copying data from/to arrays of u32.
+ * On 32-bit systems bitmaps are represented as u32 arrays internally. On LE64
+ * machines the order of hi and lo parts of numbers match the bitmap structure.
+ * In both cases conversion is not needed when copying data from/to arrays of
+ * u32. But in LE64 case, typecast in bitmap_copy_clear_tail() may lead
+ * to out-of-bound access. To avoid that, both LE and BE variants of 64-bit
+ * architectures are not using bitmap_copy_clear_tail().
  */
 #if BITS_PER_LONG == 64
 void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf,
@@ -281,6 +287,22 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap,
                        (const unsigned long *) (bitmap), (nbits))
 #endif
 
+/*
+ * On 64-bit systems bitmaps are represented as u64 arrays internally. On LE32
+ * machines the order of hi and lo parts of numbers match the bitmap structure.
+ * In both cases conversion is not needed when copying data from/to arrays of
+ * u64.
+ */
+#if (BITS_PER_LONG == 32) && defined(__BIG_ENDIAN)
+void bitmap_from_arr64(unsigned long *bitmap, const u64 *buf, unsigned int nbits);
+void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits);
+#else
+#define bitmap_from_arr64(bitmap, buf, nbits)                  \
+       bitmap_copy_clear_tail((unsigned long *)(bitmap), (const unsigned long *)(buf), (nbits))
+#define bitmap_to_arr64(buf, bitmap, nbits)                    \
+       bitmap_copy_clear_tail((unsigned long *)(buf), (const unsigned long *)(bitmap), (nbits))
+#endif
+
 static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
                        const unsigned long *src2, unsigned int nbits)
 {
@@ -331,8 +353,8 @@ static inline void bitmap_complement(unsigned long *dst, const unsigned long *sr
 #endif
 #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1)
 
-static inline int bitmap_equal(const unsigned long *src1,
-                       const unsigned long *src2, unsigned int nbits)
+static inline bool bitmap_equal(const unsigned long *src1,
+                               const unsigned long *src2, unsigned int nbits)
 {
        if (small_const_nbits(nbits))
                return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
@@ -362,8 +384,9 @@ static inline bool bitmap_or_equal(const unsigned long *src1,
        return !(((*src1 | *src2) ^ *src3) & BITMAP_LAST_WORD_MASK(nbits));
 }
 
-static inline int bitmap_intersects(const unsigned long *src1,
-                       const unsigned long *src2, unsigned int nbits)
+static inline bool bitmap_intersects(const unsigned long *src1,
+                                    const unsigned long *src2,
+                                    unsigned int nbits)
 {
        if (small_const_nbits(nbits))
                return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
@@ -371,8 +394,8 @@ static inline int bitmap_intersects(const unsigned long *src1,
                return __bitmap_intersects(src1, src2, nbits);
 }
 
-static inline int bitmap_subset(const unsigned long *src1,
-                       const unsigned long *src2, unsigned int nbits)
+static inline bool bitmap_subset(const unsigned long *src1,
+                                const unsigned long *src2, unsigned int nbits)
 {
        if (small_const_nbits(nbits))
                return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits));
@@ -514,10 +537,7 @@ static inline void bitmap_next_set_region(unsigned long *bitmap,
  */
 static inline void bitmap_from_u64(unsigned long *dst, u64 mask)
 {
-       dst[0] = mask & ULONG_MAX;
-
-       if (sizeof(mask) > sizeof(unsigned long))
-               dst[1] = mask >> 32;
+       bitmap_from_arr64(dst, &mask, 64);
 }
 
 /**
index 5bb6db213bcb84a38be466136b9e8eb5c6932fc3..424ef67d4a426837eb49524634badbca72b07b3b 100644 (file)
@@ -21,8 +21,8 @@ extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long siz
 /**
  * find_next_bit - find the next set bit in a memory region
  * @addr: The address to base the search on
- * @offset: The bitnumber to start searching at
  * @size: The bitmap size in bits
+ * @offset: The bitnumber to start searching at
  *
  * Returns the bit number for the next set bit
  * If no bits are set, returns @size.
@@ -50,8 +50,8 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
  * find_next_and_bit - find the next set bit in both memory regions
  * @addr1: The first address to base the search on
  * @addr2: The second address to base the search on
- * @offset: The bitnumber to start searching at
  * @size: The bitmap size in bits
+ * @offset: The bitnumber to start searching at
  *
  * Returns the bit number for the next set bit
  * If no bits are set, returns @size.
@@ -79,8 +79,8 @@ unsigned long find_next_and_bit(const unsigned long *addr1,
 /**
  * find_next_zero_bit - find the next cleared bit in a memory region
  * @addr: The address to base the search on
- * @offset: The bitnumber to start searching at
  * @size: The bitmap size in bits
+ * @offset: The bitnumber to start searching at
  *
  * Returns the bit number of the next zero bit
  * If no bits are zero, returns @size.
index c6199dbe25913b6c3389d49be0b5b47f34455e10..0f233b76c9cec74996ddc4fd25ab59d1e92dba9c 100644 (file)
  * void nodes_shift_right(dst, src, n) Shift right
  * void nodes_shift_left(dst, src, n)  Shift left
  *
- * int first_node(mask)                        Number lowest set bit, or MAX_NUMNODES
- * int next_node(node, mask)           Next node past 'node', or MAX_NUMNODES
- * int next_node_in(node, mask)                Next node past 'node', or wrap to first,
+ * unsigned int first_node(mask)       Number lowest set bit, or MAX_NUMNODES
+ * unsigend int next_node(node, mask)  Next node past 'node', or MAX_NUMNODES
+ * unsigned int next_node_in(node, mask) Next node past 'node', or wrap to first,
  *                                     or MAX_NUMNODES
- * int first_unset_node(mask)          First node not set in mask, or 
+ * unsigned int first_unset_node(mask) First node not set in mask, or
  *                                     MAX_NUMNODES
  *
  * nodemask_t nodemask_of_node(node)   Return nodemask with bit 'node' set
@@ -153,7 +153,7 @@ static inline void __nodes_clear(nodemask_t *dstp, unsigned int nbits)
 
 #define node_test_and_set(node, nodemask) \
                        __node_test_and_set((node), &(nodemask))
-static inline int __node_test_and_set(int node, nodemask_t *addr)
+static inline bool __node_test_and_set(int node, nodemask_t *addr)
 {
        return test_and_set_bit(node, addr->bits);
 }
@@ -200,7 +200,7 @@ static inline void __nodes_complement(nodemask_t *dstp,
 
 #define nodes_equal(src1, src2) \
                        __nodes_equal(&(src1), &(src2), MAX_NUMNODES)
-static inline int __nodes_equal(const nodemask_t *src1p,
+static inline bool __nodes_equal(const nodemask_t *src1p,
                                        const nodemask_t *src2p, unsigned int nbits)
 {
        return bitmap_equal(src1p->bits, src2p->bits, nbits);
@@ -208,7 +208,7 @@ static inline int __nodes_equal(const nodemask_t *src1p,
 
 #define nodes_intersects(src1, src2) \
                        __nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
-static inline int __nodes_intersects(const nodemask_t *src1p,
+static inline bool __nodes_intersects(const nodemask_t *src1p,
                                        const nodemask_t *src2p, unsigned int nbits)
 {
        return bitmap_intersects(src1p->bits, src2p->bits, nbits);
@@ -216,20 +216,20 @@ static inline int __nodes_intersects(const nodemask_t *src1p,
 
 #define nodes_subset(src1, src2) \
                        __nodes_subset(&(src1), &(src2), MAX_NUMNODES)
-static inline int __nodes_subset(const nodemask_t *src1p,
+static inline bool __nodes_subset(const nodemask_t *src1p,
                                        const nodemask_t *src2p, unsigned int nbits)
 {
        return bitmap_subset(src1p->bits, src2p->bits, nbits);
 }
 
 #define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
-static inline int __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
+static inline bool __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
 {
        return bitmap_empty(srcp->bits, nbits);
 }
 
 #define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
-static inline int __nodes_full(const nodemask_t *srcp, unsigned int nbits)
+static inline bool __nodes_full(const nodemask_t *srcp, unsigned int nbits)
 {
        return bitmap_full(srcp->bits, nbits);
 }
@@ -260,15 +260,15 @@ static inline void __nodes_shift_left(nodemask_t *dstp,
           > MAX_NUMNODES, then the silly min_ts could be dropped. */
 
 #define first_node(src) __first_node(&(src))
-static inline int __first_node(const nodemask_t *srcp)
+static inline unsigned int __first_node(const nodemask_t *srcp)
 {
-       return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
+       return min_t(unsigned int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
 }
 
 #define next_node(n, src) __next_node((n), &(src))
-static inline int __next_node(int n, const nodemask_t *srcp)
+static inline unsigned int __next_node(int n, const nodemask_t *srcp)
 {
-       return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
+       return min_t(unsigned int, MAX_NUMNODES, find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
 }
 
 /*
@@ -276,7 +276,7 @@ static inline int __next_node(int n, const nodemask_t *srcp)
  * the first node in src if needed.  Returns MAX_NUMNODES if src is empty.
  */
 #define next_node_in(n, src) __next_node_in((n), &(src))
-int __next_node_in(int node, const nodemask_t *srcp);
+unsigned int __next_node_in(int node, const nodemask_t *srcp);
 
 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 {
@@ -296,9 +296,9 @@ static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 })
 
 #define first_unset_node(mask) __first_unset_node(&(mask))
-static inline int __first_unset_node(const nodemask_t *maskp)
+static inline unsigned int __first_unset_node(const nodemask_t *maskp)
 {
-       return min_t(int,MAX_NUMNODES,
+       return min_t(unsigned int, MAX_NUMNODES,
                        find_first_zero_bit(maskp->bits, MAX_NUMNODES));
 }
 
@@ -435,11 +435,11 @@ static inline int num_node_state(enum node_states state)
 
 #define first_online_node      first_node(node_states[N_ONLINE])
 #define first_memory_node      first_node(node_states[N_MEMORY])
-static inline int next_online_node(int nid)
+static inline unsigned int next_online_node(int nid)
 {
        return next_node(nid, node_states[N_ONLINE]);
 }
-static inline int next_memory_node(int nid)
+static inline unsigned int next_memory_node(int nid)
 {
        return next_node(nid, node_states[N_MEMORY]);
 }
index 0d5c2ece0bcb463a1d916ae4f1825a9a0bb7ddd9..b18e31ea6e66406efd0fc2329b8d7f2302d62ab5 100644 (file)
  * for the best explanations of this ordering.
  */
 
-int __bitmap_equal(const unsigned long *bitmap1,
-               const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_equal(const unsigned long *bitmap1,
+                   const unsigned long *bitmap2, unsigned int bits)
 {
        unsigned int k, lim = bits/BITS_PER_LONG;
        for (k = 0; k < lim; ++k)
                if (bitmap1[k] != bitmap2[k])
-                       return 0;
+                       return false;
 
        if (bits % BITS_PER_LONG)
                if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
-                       return 0;
+                       return false;
 
-       return 1;
+       return true;
 }
 EXPORT_SYMBOL(__bitmap_equal);
 
@@ -303,33 +303,33 @@ void __bitmap_replace(unsigned long *dst,
 }
 EXPORT_SYMBOL(__bitmap_replace);
 
-int __bitmap_intersects(const unsigned long *bitmap1,
-                       const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_intersects(const unsigned long *bitmap1,
+                        const unsigned long *bitmap2, unsigned int bits)
 {
        unsigned int k, lim = bits/BITS_PER_LONG;
        for (k = 0; k < lim; ++k)
                if (bitmap1[k] & bitmap2[k])
-                       return 1;
+                       return true;
 
        if (bits % BITS_PER_LONG)
                if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
-                       return 1;
-       return 0;
+                       return true;
+       return false;
 }
 EXPORT_SYMBOL(__bitmap_intersects);
 
-int __bitmap_subset(const unsigned long *bitmap1,
-                   const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_subset(const unsigned long *bitmap1,
+                    const unsigned long *bitmap2, unsigned int bits)
 {
        unsigned int k, lim = bits/BITS_PER_LONG;
        for (k = 0; k < lim; ++k)
                if (bitmap1[k] & ~bitmap2[k])
-                       return 0;
+                       return false;
 
        if (bits % BITS_PER_LONG)
                if ((bitmap1[k] & ~bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
-                       return 0;
-       return 1;
+                       return false;
+       return true;
 }
 EXPORT_SYMBOL(__bitmap_subset);
 
@@ -527,33 +527,39 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
  * cpumap_print_to_pagebuf() or directly by drivers to export hexadecimal
  * bitmask and decimal list to userspace by sysfs ABI.
  * Drivers might be using a normal attribute for this kind of ABIs. A
- * normal attribute typically has show entry as below:
- * static ssize_t example_attribute_show(struct device *dev,
+ * normal attribute typically has show entry as below::
+ *
+ *   static ssize_t example_attribute_show(struct device *dev,
  *             struct device_attribute *attr, char *buf)
- * {
+ *   {
  *     ...
  *     return bitmap_print_to_pagebuf(true, buf, &mask, nr_trig_max);
- * }
+ *   }
+ *
  * show entry of attribute has no offset and count parameters and this
  * means the file is limited to one page only.
  * bitmap_print_to_pagebuf() API works terribly well for this kind of
- * normal attribute with buf parameter and without offset, count:
- * bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
+ * normal attribute with buf parameter and without offset, count::
+ *
+ *   bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
  *                        int nmaskbits)
- * {
- * }
+ *   {
+ *   }
+ *
  * The problem is once we have a large bitmap, we have a chance to get a
  * bitmask or list more than one page. Especially for list, it could be
  * as complex as 0,3,5,7,9,... We have no simple way to know it exact size.
  * It turns out bin_attribute is a way to break this limit. bin_attribute
- * has show entry as below:
- * static ssize_t
- * example_bin_attribute_show(struct file *filp, struct kobject *kobj,
+ * has show entry as below::
+ *
+ *   static ssize_t
+ *   example_bin_attribute_show(struct file *filp, struct kobject *kobj,
  *             struct bin_attribute *attr, char *buf,
  *             loff_t offset, size_t count)
- * {
+ *   {
  *     ...
- * }
+ *   }
+ *
  * With the new offset and count parameters, this makes sysfs ABI be able
  * to support file size more than one page. For example, offset could be
  * >= 4096.
@@ -577,6 +583,7 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
  * This function is not a replacement for sprintf() or bitmap_print_to_pagebuf().
  * It is intended to workaround sysfs limitations discussed above and should be
  * used carefully in general case for the following reasons:
+ *
  *  - Time complexity is O(nbits^2/count), comparing to O(nbits) for snprintf().
  *  - Memory complexity is O(nbits), comparing to O(1) for snprintf().
  *  - @off and @count are NOT offset and number of bits to print.
@@ -1505,5 +1512,59 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits)
                buf[halfwords - 1] &= (u32) (UINT_MAX >> ((-nbits) & 31));
 }
 EXPORT_SYMBOL(bitmap_to_arr32);
+#endif
+
+#if (BITS_PER_LONG == 32) && defined(__BIG_ENDIAN)
+/**
+ * bitmap_from_arr64 - copy the contents of u64 array of bits to bitmap
+ *     @bitmap: array of unsigned longs, the destination bitmap
+ *     @buf: array of u64 (in host byte order), the source bitmap
+ *     @nbits: number of bits in @bitmap
+ */
+void bitmap_from_arr64(unsigned long *bitmap, const u64 *buf, unsigned int nbits)
+{
+       int n;
+
+       for (n = nbits; n > 0; n -= 64) {
+               u64 val = *buf++;
 
+               *bitmap++ = val;
+               if (n > 32)
+                       *bitmap++ = val >> 32;
+       }
+
+       /*
+        * Clear tail bits in the last word beyond nbits.
+        *
+        * Negative index is OK because here we point to the word next
+        * to the last word of the bitmap, except for nbits == 0, which
+        * is tested implicitly.
+        */
+       if (nbits % BITS_PER_LONG)
+               bitmap[-1] &= BITMAP_LAST_WORD_MASK(nbits);
+}
+EXPORT_SYMBOL(bitmap_from_arr64);
+
+/**
+ * bitmap_to_arr64 - copy the contents of bitmap to a u64 array of bits
+ *     @buf: array of u64 (in host byte order), the dest bitmap
+ *     @bitmap: array of unsigned longs, the source bitmap
+ *     @nbits: number of bits in @bitmap
+ */
+void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits)
+{
+       const unsigned long *end = bitmap + BITS_TO_LONGS(nbits);
+
+       while (bitmap < end) {
+               *buf = *bitmap++;
+               if (bitmap < end)
+                       *buf |= (u64)(*bitmap++) << 32;
+               buf++;
+       }
+
+       /* Clear tail bits in the last element of array beyond nbits. */
+       if (nbits % 64)
+               buf[-1] &= GENMASK_ULL(nbits % 64, 0);
+}
+EXPORT_SYMBOL(bitmap_to_arr64);
 #endif
index 3aa454c54c0de676be2d10cd62603d30d88f3253..e22647f5181b366d5b4d52de9db276d027e5bf1b 100644 (file)
@@ -3,9 +3,9 @@
 #include <linux/module.h>
 #include <linux/random.h>
 
-int __next_node_in(int node, const nodemask_t *srcp)
+unsigned int __next_node_in(int node, const nodemask_t *srcp)
 {
-       int ret = __next_node(node, srcp);
+       unsigned int ret = __next_node(node, srcp);
 
        if (ret == MAX_NUMNODES)
                ret = __first_node(srcp);
index 0c82f07f74fcba6ae31ea7603da7c57a111339ad..d5923a640457d01a40fba3cc9d1daf31a928e765 100644 (file)
@@ -585,6 +585,30 @@ static void __init test_bitmap_arr32(void)
        }
 }
 
+static void __init test_bitmap_arr64(void)
+{
+       unsigned int nbits, next_bit;
+       u64 arr[EXP1_IN_BITS / 64];
+       DECLARE_BITMAP(bmap2, EXP1_IN_BITS);
+
+       memset(arr, 0xa5, sizeof(arr));
+
+       for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) {
+               memset(bmap2, 0xff, sizeof(arr));
+               bitmap_to_arr64(arr, exp1, nbits);
+               bitmap_from_arr64(bmap2, arr, nbits);
+               expect_eq_bitmap(bmap2, exp1, nbits);
+
+               next_bit = find_next_bit(bmap2, round_up(nbits, BITS_PER_LONG), nbits);
+               if (next_bit < round_up(nbits, BITS_PER_LONG))
+                       pr_err("bitmap_copy_arr64(nbits == %d:"
+                               " tail is not safely cleared: %d\n", nbits, next_bit);
+
+               if (nbits < EXP1_IN_BITS - 64)
+                       expect_eq_uint(arr[DIV_ROUND_UP(nbits, 64)], 0xa5a5a5a5);
+       }
+}
+
 static void noinline __init test_mem_optimisations(void)
 {
        DECLARE_BITMAP(bmap1, 1024);
@@ -852,6 +876,7 @@ static void __init selftest(void)
        test_copy();
        test_replace();
        test_bitmap_arr32();
+       test_bitmap_arr64();
        test_bitmap_parse();
        test_bitmap_parselist();
        test_bitmap_printlist();
index da525bfb6f4ab6ddf46cbd76a93091ea7e41c2ee..373d2730fcf2157562f343ec4b3160e8f4f49eac 100644 (file)
@@ -2049,7 +2049,7 @@ static void __init init_cpu_node_state(void)
        int node;
 
        for_each_online_node(node) {
-               if (cpumask_weight(cpumask_of_node(node)) > 0)
+               if (!cpumask_empty(cpumask_of_node(node)))
                        node_set_state(node, N_CPU);
        }
 }
@@ -2081,7 +2081,7 @@ static int vmstat_cpu_dead(unsigned int cpu)
 
        refresh_zone_stat_thresholds();
        node_cpus = cpumask_of_node(node);
-       if (cpumask_weight(node_cpus) > 0)
+       if (!cpumask_empty(node_cpus))
                return 0;
 
        node_clear_state(node, N_CPU);
index ea97804d04d4ac9ef6818d35cea88b1404c75c5b..afdf93bebaaf1a8841dd08d945b0e6b858dc527a 100644 (file)
@@ -16,11 +16,11 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
                 const unsigned long *bitmap2, int bits);
 int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
                 const unsigned long *bitmap2, unsigned int bits);
-int __bitmap_equal(const unsigned long *bitmap1,
-                  const unsigned long *bitmap2, unsigned int bits);
+bool __bitmap_equal(const unsigned long *bitmap1,
+                   const unsigned long *bitmap2, unsigned int bits);
 void bitmap_clear(unsigned long *map, unsigned int start, int len);
-int __bitmap_intersects(const unsigned long *bitmap1,
-                       const unsigned long *bitmap2, unsigned int bits);
+bool __bitmap_intersects(const unsigned long *bitmap1,
+                        const unsigned long *bitmap2, unsigned int bits);
 
 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
 #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
@@ -162,8 +162,8 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
 #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1)
 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
 
-static inline int bitmap_equal(const unsigned long *src1,
-                       const unsigned long *src2, unsigned int nbits)
+static inline bool bitmap_equal(const unsigned long *src1,
+                               const unsigned long *src2, unsigned int nbits)
 {
        if (small_const_nbits(nbits))
                return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
@@ -173,8 +173,9 @@ static inline int bitmap_equal(const unsigned long *src1,
        return __bitmap_equal(src1, src2, nbits);
 }
 
-static inline int bitmap_intersects(const unsigned long *src1,
-                       const unsigned long *src2, unsigned int nbits)
+static inline bool bitmap_intersects(const unsigned long *src1,
+                                    const unsigned long *src2,
+                                    unsigned int nbits)
 {
        if (small_const_nbits(nbits))
                return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
index db466ef7be9d13dd27a03619c3e8bac834c89b32..354f8cdc088037a3044d2a28f8af998c32f12370 100644 (file)
@@ -72,31 +72,31 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
        return result != 0;
 }
 
-int __bitmap_equal(const unsigned long *bitmap1,
-               const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_equal(const unsigned long *bitmap1,
+                   const unsigned long *bitmap2, unsigned int bits)
 {
        unsigned int k, lim = bits/BITS_PER_LONG;
        for (k = 0; k < lim; ++k)
                if (bitmap1[k] != bitmap2[k])
-                       return 0;
+                       return false;
 
        if (bits % BITS_PER_LONG)
                if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
-                       return 0;
+                       return false;
 
-       return 1;
+       return true;
 }
 
-int __bitmap_intersects(const unsigned long *bitmap1,
-                       const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_intersects(const unsigned long *bitmap1,
+                        const unsigned long *bitmap2, unsigned int bits)
 {
        unsigned int k, lim = bits/BITS_PER_LONG;
        for (k = 0; k < lim; ++k)
                if (bitmap1[k] & bitmap2[k])
-                       return 1;
+                       return true;
 
        if (bits % BITS_PER_LONG)
                if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
-                       return 1;
-       return 0;
+                       return true;
+       return false;
 }