From patchwork Tue Jan 30 08:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 193887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1080339dyb; Tue, 30 Jan 2024 00:43:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDINMuVbFKM/aI3nNTozkDvSX7wWUmKTZj0XTue0t1yrzQeGHMZ//K9i/3a6kSRyeA0Uvh X-Received: by 2002:a05:620a:386:b0:783:d7af:63c6 with SMTP id q6-20020a05620a038600b00783d7af63c6mr6050022qkm.28.1706604184536; Tue, 30 Jan 2024 00:43:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706604184; cv=pass; d=google.com; s=arc-20160816; b=ahFRWZiCM1YNT6iFX+g+qY0A1Hld5XSB7jNH7lbqSLog7UWiobP1Z3S0UmlO9jJZq3 EvMOxL1g2BSjJ09T+sLwXJxihWlnHHLOV7iymK7STD4cP868LHRY0+r15Q9fC+Db/QW7 oZ9v3MyXY4TAwZMD8mGp1FURcrwp3nLnaLqqp4cGkVAsnOMTonbvAXO/V+NZhA5mtJb1 N9q9zwilKe+mkhpdzrX9enJ/DvzBi6Hju/aIZWw0e95hAgat0BCfudMLtAZnISCF2r0x RxwA/VyTWbo4db/Vtw0OEXaNtSCDiJTXOzKoP5BMx0csgq8fPPqfAbjDXDPJg+IYvRbu lT8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dO1lu7mTt2Z5I540dnIACd6uZE/pOpssk6saKJ+PaEA=; fh=s/vkN0CKwCHxl3xiysg2b4K3AQjMb0Me6zHwb/HBGyI=; b=IS6utfTZYG052w0Qwgr68J4P7rCBNtlW/xcD35HJ4RKG3dCJircCrQSwcqLJhkk4e7 YV/qwFAilHxD4hnpwSgX86AbCimUrpMKhoyR98UvjSvC5EjaMhOzTaireMHhf721gj0v zXuRmHEYU6RHIWHwnpjCU6oSBk5sy4ryKilAHkReAZ5oWHm/AQI7CQUZaIEkuTEe604K yXyKdwv0fRuRibZjojbTBIILXN5UNR5h7b2bYXiAwmRFGuBIlfpp1USvr/9FrMwfBMQv qobQsCqURCFyHqbFWsXmTJnTA60fssaT78D/pV0eZceKI+CTGjd2DeeWOmTKGD8UH9AO 5IJg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=NWQvtLk5; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-44157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44157-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l11-20020a05620a28cb00b00783dfe9f7e4si8563904qkp.464.2024.01.30.00.43.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 00:43:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=NWQvtLk5; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-44157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44157-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DFC281C2495A for ; Tue, 30 Jan 2024 08:42:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA17B60DC0; Tue, 30 Jan 2024 08:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="NWQvtLk5" Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C005454670; Tue, 30 Jan 2024 08:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706604058; cv=none; b=ls9BITbKU8lkKVlhgW1g0AEoJYu2WrC/o/Ygu0NGXfM+ggabWQLMPa8i0tTEnzjA44QDRnEDxrC1tmcmXiH7g6saTp4XpWwOC9o7V+OHo2g042chj4PmuVfhT1/m1flqHaI01/wv/P32x6QQnytQO81gdPPiVBHqpDHEx94xdcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706604058; c=relaxed/simple; bh=o3GCbQ0HDcwCxhsdiMaIWoSqnIsvjGA8R22JTLCknSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RavkWNWKRh8hoGLv+8frQJ64IT3h/Osdc3kjZuSPJKJw1HtV0yN6T7tBxdV2njAg0yfduBwxz2pb9N2dF5bnUNazq0WvbuiehyEKeVpPWkzSBnTvNFMD0p9SncTuRhiovc5JqipKmq3zWg1thmad02YhAzpcqPGta63oYOBxr+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=NWQvtLk5; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 86B506000F; Tue, 30 Jan 2024 08:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1706604049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dO1lu7mTt2Z5I540dnIACd6uZE/pOpssk6saKJ+PaEA=; b=NWQvtLk5OLX0vZs2YGAsz/nl2hB9WFKgCSA7hI1iBwPdy8lPm7XqaoD84J6jU6/HQTeylc +kjLGWSyFa2P7EDj8wMACofF8gGJlZAsxCb6AQ6Il0GyHXFHr5YM29KhYnqw6nKK6Fbhjp 20A3RHvPqs0veEfkFaJPEJWfprIXn5YPLGv+30jgaL2vd94q52TvpspdkdRzPh0ZqZre86 ldkbn/s6mEDdGrrfcQ2ZZtcqTLL5icJSly74qt7dF2PC9AgPplOiOtyrfN//tKCIAiKj95 HSdw1CYPo2QNDbFf7ZdNZYWRe8tNMyo9QsHxQgItt/9wn80Y9aYt7za1nxmr6A== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v2 4/6] bitmap: Introduce bitmap_off() Date: Tue, 30 Jan 2024 09:40:19 +0100 Message-ID: <20240130084035.115086-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130084035.115086-1-herve.codina@bootlin.com> References: <20240130084035.115086-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789504189370981733 X-GMAIL-MSGID: 1789504189370981733 The bitmap_onto() function translates one bitmap relative to another but no function are present to perform the reverse translation. Introduce bitmap_off() to fill this hole. Signed-off-by: Herve Codina --- include/linux/bitmap.h | 3 +++ lib/bitmap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 99451431e4d6..5ecfcbbc91f4 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -65,6 +65,7 @@ struct device; * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap + * bitmap_off(dst, orig, relmap, nbits) *dst = bitmap_onto() reverse operation * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf @@ -208,6 +209,8 @@ int bitmap_bitremap(int oldbit, const unsigned long *old, const unsigned long *new, int bits); void bitmap_onto(unsigned long *dst, const unsigned long *orig, const unsigned long *relmap, unsigned int bits); +void bitmap_off(unsigned long *dst, const unsigned long *orig, + const unsigned long *relmap, unsigned int bits); void bitmap_fold(unsigned long *dst, const unsigned long *orig, unsigned int sz, unsigned int nbits); diff --git a/lib/bitmap.c b/lib/bitmap.c index 2feccb5047dc..71343967335e 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -682,6 +682,48 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig, } EXPORT_SYMBOL(bitmap_onto); +/** + * bitmap_off - revert operation done by bitmap_onto() + * @dst: resulting translated bitmap + * @orig: original untranslated bitmap + * @relmap: bitmap relative to which translated + * @bits: number of bits in each of these bitmaps + * + * Suppose onto computed using bitmap_onto(onto, src, relmap, n) + * The operation bitmap_off(result, onto, relmap, n) leads to a + * result equal or equivalent to src. + * + * The result can be 'equivalent' because bitmap_onto() and + * bitmap_off() are not bijective. + * The result and src values are equivalent in that sense that a + * call to bitmap_onto(onto, src, relmap, n) and a call to + * bitmap_onto(onto, result, relmap, n) will lead to the same onto + * value. + * + * If either of @orig or @relmap is empty (no set bits), then @dst + * will be returned empty. + * + * All bits in @dst not set by the above rule are cleared. + */ +void bitmap_off(unsigned long *dst, const unsigned long *orig, + const unsigned long *relmap, unsigned int bits) +{ + unsigned int n, m; /* same meaning as in above comment */ + + if (dst == orig) /* following doesn't handle inplace mappings */ + return; + bitmap_zero(dst, bits); + + m = 0; + for_each_set_bit(n, relmap, bits) { + /* m == bitmap_pos_to_ord(relmap, n, bits) */ + if (test_bit(n, orig)) + set_bit(m, dst); + m++; + } +} +EXPORT_SYMBOL(bitmap_off); + #ifdef CONFIG_NUMA /** * bitmap_fold - fold larger bitmap into smaller, modulo specified size