From nobody Sun Dec 24 08:23:13 2023 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 4SyYvP6Zxhz54HB0; Sun, 24 Dec 2023 08:23:13 +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 4SyYvP51bmz4XlK; Sun, 24 Dec 2023 08:23:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406193; 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=el3TbGpsAQaHdR0JfT3U+2et+BS1ogEnQMbmG/mxa9A=; b=WO0/IqB+QPDzG/ojMAo8vzOdFWl66e3Y0xV+D2pXEdKYKnMbnxkE6PqM+TQHIbipQWQMWP VVDF3enRL/bYc/f7sQ0AGZKqnsmzxzfrsdABrT4zqogfMxUapU3IN0FkG43pq93gLhqxVr pyvG0rNqsZ6w2VxhorRtLLho9eUhtZKJuoS1NHZEH6OTQp9/MW9YvAPgwU0j/hKGUGs0Bm zth0JWpj3w1xsqtMaqwUxNYIEN7WSAfISXvJkAnzVXI24r2vMEminci/pSHVmAS/yQv4dg A9K4le99yPGjehT6zkhgnSfDUZTNfteUW0A1n4/7ZbGgaiNBdaT6ShuqMsim6w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703406193; a=rsa-sha256; cv=none; b=hOIjGNH8nRUlOCYlp4PKLbqmsYPnYvTEjsL6Mn0cDJ05XLl+OLlc//G8+P2Sq/akpRc3t9 Zviam/zF2b8uPuAr0MoxoexdN+AgvQZnkQgVRg4RGNCg276Jn42XFPHkg8tDXuuIkKGjwJ RSv8SAKn8EZrq7edGuiGIFifAnFd4ePRhvmnIuOI1F1TqFWXOwCo5gakvGiDNVFSMwjCrd WqEnXv0QBfLC9hrbwiyMmPaoPPb8/Kri1E3Pwf1GyWdXqJ3s705fCAf0W9HihaaCuzo3i3 cNrnwZJQpmktXYCFL5eEKdUtSR808qh9bM6ukGl9f1w+06/4uAfH0hz9qs0AlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406193; 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=el3TbGpsAQaHdR0JfT3U+2et+BS1ogEnQMbmG/mxa9A=; b=rkRFSWECmKtzcPRKkTznF5Dfxe/OCzEgRkkIERYOL7ncxfsJhrMuxZGm5u50dE1DsAydfM 6J83mJ2BISJnexpHjbtJNIiVC35dXV8U5mwAZIqqVpIUh6bJ0M+YVsGRSXWyavj0xeq9g9 tA/I0TPLemFc8PGHm4piCe62MBtrzAJYqtNa/kZX/9aZWII+NpqcUZe59EW5X+s8syNJ1r CJtcVfWvUslGSfc48W2EtkNKeV4YB7Bls0jmDFUVtZXOwGzgOAiIiqjJxOi6epeqk2cspD DOTsK/B/y7oOtiQenGcXzM2rjsm2RydeY8lTWd4/FYejFocr11m9hIGRvYS/Pw== 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 4SyYvP43nMz5Tf; Sun, 24 Dec 2023 08:23:13 +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 3BO8NDLY087344; Sun, 24 Dec 2023 08:23:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BO8NDYV087341; Sun, 24 Dec 2023 08:23:13 GMT (envelope-from git) Date: Sun, 24 Dec 2023 08:23:13 GMT Message-Id: <202312240823.3BO8NDYV087341@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 5ae2e6f913fa - main - 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/main X-Git-Reftype: branch X-Git-Commit: 5ae2e6f913fa1df5f3262255558b76af05409a09 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=5ae2e6f913fa1df5f3262255558b76af05409a09 commit 5ae2e6f913fa1df5f3262255558b76af05409a09 Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:59 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-12-24 08:19:59 +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 --- 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) {