From nobody Sat Feb 17 21:33:07 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TchqS0NpTz59lK9; Sat, 17 Feb 2024 21:33:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TchqR52qVz4hc8; Sat, 17 Feb 2024 21:33:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aGczrjjqdABAiQMSRpf8pBGqfNnwaXnFeADKLyvx/6Y=; b=MrfdGIMTl5XREZYnjdlkjd3yR7xfWu9keU0kiux5nWT+dlEHuh9i/heDc3pkkeZ3Ds3bAY jnPRfoXnLekDELsTfDvVx/g/PoH0V9Q0rx77NsJ/jvf45VfrpLwGC6v0Iytvb46NtJ82Es 6hvdY2m1Kn0apbWQUZTD/LIEXIsn7zDLcV7W2XpW5pTBUlmM5tnHppkkHM1PDD+rbnfzXy iRGm9k5C2sf1bs7JwX1t2FSPEeBRB+2FzeVVkOuphkR8ZrlKAdQrq4TNFmG8Yjqsb1NI6R cVctyrUcxs4TiHb+OWGd6/LmSbhntOJuuf1td5JYGNlzPFaXzsw+4W/yTFk5KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aGczrjjqdABAiQMSRpf8pBGqfNnwaXnFeADKLyvx/6Y=; b=TWs0tgQ+yEfeWHk0l7SXvVcup10srHMS2KaQJSL8bC3p1DPZm4lOMvkd0y+U6m5DSQhTLZ LFl+AjJmxbotoboWKZETOxjpcIX/SoPPcYOSBmb2zKtl/5dukXS+H+/DROa5b3DF7iwsr1 1lViwBL0E8cllBcV7K+MolOzL198Tzv/HSI7esRZmNZumThWsoero4wiQvtxjoXSH3wViZ u/LguCqL1SdNuofQSbJkfT9bYQupZIfWBUhit9477ESB132Bp0NnhXmo5AcSPq0HtdMS33 1852SjVynrr6tR3Mra9X8hDbWYTP1gYG7LUbQ3hfx5PIKD5NvjT1fH32VyUrJA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708205587; a=rsa-sha256; cv=none; b=o4WvSy51ILi3zihs+CrHispUGSCbLZmHl+M3/tT8UwEkPdo5dYi6PMG6MexYXKgkyE6Unr iSN+wo/wXFWq06SDzUtA8XsGskigdZkVj9FBsHdOiTkYIq4F3XSxPrnQdrjK/PaVKfgNzt i9BY39JeMJ0Pq5+ZSN0wjH56xbnZjTGfrUqsudrT8oO6YAKCnn8bVBKUmpr99hrNZ/BD25 UbvcFVyGtN6pmtDXD4zIruhm+JQTdbOWnYMLP9McBB+smI6NIP7pNtt1jHWXxMz4Ga0K5I YKUtmV7X+NPUVFSnI8rrxGD/+GRW5jtrEN8rDxkMYUuQ5zP655DeTZkVsHRW+Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TchqR47stzP5S; Sat, 17 Feb 2024 21:33:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HLX76N021098; Sat, 17 Feb 2024 21:33:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HLX7gJ021095; Sat, 17 Feb 2024 21:33:07 GMT (envelope-from git) Date: Sat, 17 Feb 2024 21:33:07 GMT Message-Id: <202402172133.41HLX7gJ021095@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: edeb8cfad053 - stable/14 - LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: edeb8cfad053bba99fcf35ff66dbe34ea7ee17bc Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=edeb8cfad053bba99fcf35ff66dbe34ea7ee17bc commit edeb8cfad053bba99fcf35ff66dbe34ea7ee17bc Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:59 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-17 20:58:38 +0000 LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32() and bitmap_shift_right() functions to linux/bitmap.h They perform calculation of two bitmaps intersection, copying the contents of u32 array of bits to bitmap and logical right shifting of the bits in a bitmap. Sponsored by: Serenity Cyber Security, LLC Reviewed by: manu MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42812 (cherry picked from commit 5ae2e6f913fa1df5f3262255558b76af05409a09) --- sys/compat/linuxkpi/common/include/linux/bitmap.h | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/bitmap.h b/sys/compat/linuxkpi/common/include/linux/bitmap.h index 85cef18ec14a..84e0ba9c88ca 100644 --- a/sys/compat/linuxkpi/common/include/linux/bitmap.h +++ b/sys/compat/linuxkpi/common/include/linux/bitmap.h @@ -264,6 +264,27 @@ bitmap_subset(const unsigned long *pa, return (1); } +static inline bool +bitmap_intersects(const unsigned long *pa, const unsigned long *pb, + unsigned size) +{ + const unsigned end = BIT_WORD(size); + const unsigned tail = size & (BITS_PER_LONG - 1); + unsigned i; + + for (i = 0; i != end; i++) + if (pa[i] & pb[i]) + return (true); + + if (tail) { + const unsigned long mask = BITMAP_LAST_WORD_MASK(tail); + + if (pa[end] & pb[end] & mask) + return (true); + } + return (false); +} + static inline void bitmap_complement(unsigned long *dst, const unsigned long *src, const unsigned int size) @@ -306,6 +327,29 @@ bitmap_to_arr32(uint32_t *dst, const unsigned long *src, unsigned int size) dst[end - 1] &= (uint32_t)(UINT_MAX >> (32 - (size % 32))); } +static inline void +bitmap_from_arr32(unsigned long *dst, const uint32_t *src, + unsigned int size) +{ + const unsigned int end = BIT_WORD(size); + const unsigned int tail = size & (BITS_PER_LONG - 1); + +#ifdef __LP64__ + const unsigned int end32 = howmany(size, 32); + unsigned int i = 0; + + while (i < end32) { + dst[i++/2] = (unsigned long) *(src++); + if (i < end32) + dst[i++/2] |= ((unsigned long) *(src++)) << 32; + } +#else + bitmap_copy(dst, (unsigned long *)src, size); +#endif + if ((size % BITS_PER_LONG) != 0) + dst[end] &= BITMAP_LAST_WORD_MASK(tail); +} + static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, const unsigned int size) @@ -350,6 +394,40 @@ bitmap_xor(unsigned long *dst, const unsigned long *src1, dst[i] = src1[i] ^ src2[i]; } +static inline void +bitmap_shift_right(unsigned long *dst, const unsigned long *src, + unsigned int shift, unsigned int size) +{ + const unsigned int end = BITS_TO_LONGS(size); + const unsigned int tail = size & (BITS_PER_LONG - 1); + const unsigned long mask = BITMAP_LAST_WORD_MASK(tail); + const unsigned int off = BIT_WORD(shift); + const unsigned int rem = shift & (BITS_PER_LONG - 1); + unsigned long left, right; + unsigned int i, srcpos; + + for (i = 0, srcpos = off; srcpos < end; i++, srcpos++) { + right = src[srcpos]; + left = 0; + + if (srcpos == end - 1) + right &= mask; + + if (rem != 0) { + right >>= rem; + if (srcpos + 1 < end) { + left = src[srcpos + 1]; + if (srcpos + 1 == end - 1) + left &= mask; + left <<= (BITS_PER_LONG - rem); + } + } + dst[i] = left | right; + } + if (off != 0) + memset(dst + end - off, 0, off * sizeof(unsigned long)); +} + static inline unsigned long * bitmap_alloc(unsigned int size, gfp_t flags) {