Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2317185rdb; Mon, 12 Feb 2024 00:00:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpLF2xUi4zEbf8wmwRycZw9/sYJ7Yp5OynPF1ZBNH/97nyh1bLMas+Ll7o8V2PGKg+Xsi8 X-Received: by 2002:a05:6a00:390c:b0:6e0:a30c:8c84 with SMTP id fh12-20020a056a00390c00b006e0a30c8c84mr5581224pfb.1.1707724800913; Mon, 12 Feb 2024 00:00:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724800; cv=pass; d=google.com; s=arc-20160816; b=KmSwEUiueblnm5oPjOgdQ3XZgfVfBvMV7OCfvU0Va3ahNkausXGKGzjShixFqfU8Oi 93u6mJbEGCzDEz3hSMoAf8S5bgqgU/Tn2EqQiZr1HWLt6GagSA2jFpHjUiJN4OO6OFXO RfR37myaEdmnnqFPCttAH8wEQZojfoCd5dbP5RTI4b38+BYOLkB9B4FPlMAJCqoorhn5 tm+f//VFholRTK5LW4vhqQHQuLkSjKDkYW7GXcycFEzc2oKN8H19UusAI1Z2osniZnLb h1n/Ubosnpz3DVSIyOWY0Zc805QpxHKoGnVb1soE7yNGFwDZpDThlvhzkha8TISrlk0p XGoA== 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=syFmHk99f85h9SfNjjgs3oXmKVrM+ehH4MyWcsNjIcs=; b=h3j2R4+KpdH3V6zLSQr2HvcBOXLUIjLmESietGDogUcrwOH5vef9kz1psUh69mwOf8 vI1x96Dam/HabXtPyi89PF1Rrs8kyOp78b0+JPLvmWKOcRVwYe5qvbhpgMHFrWqHMiae VF9GaWwT5Qw1juXwfS8pjQHGjSE4O7e3pUSg/jVDfK7gBET4jftGuJstcT4vYJmAYisU v6kN0Poxr6uwo6OtRlnfhlhXAez+zTt9r6vLr7m9v+QobYq/KfPbJjfg+bGOHDQrJwz2 MMCRC32garYubUlFfySiB4x8KDAH2TzNjBxcjfIyctzSshNMr9PM7wqHXt6hb4WQTd+R wQdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CpLaACsQ; 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-61169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61169-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCVSpHLvH3eMfxc16VGrU3jwgNswndfj76DfMK5FXyBcUahqKvksswvqAF2SSL0luzhGwwqzyeXVSKz6rrGOWtzo07DS+rRlaV91khy6Bg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cf10-20020a056a02084a00b005dc47dd5dccsi6267241pgb.893.2024.02.12.00.00.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:00:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CpLaACsQ; 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-61169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61169-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 891D0284F40 for ; Mon, 12 Feb 2024 08:00:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB10C17C73; Mon, 12 Feb 2024 07:57:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="CpLaACsQ" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 3CD408C11; Mon, 12 Feb 2024 07:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; cv=none; b=l/+hlOGMwceT3tB+YUL9wMWVOWzrDZZt6MesO7LE1C3AUgOXVn8eSt2PatlReAXXbBnR9unFhlHFW0yXW1dCHKWYXvMd04lkFpP32thIqkOosQ7odbreLX42qZFxpH4enhZteralwC1siG0LBJG91sIIFFOWOlX6RfzvOBVBfxc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; c=relaxed/simple; bh=o3GCbQ0HDcwCxhsdiMaIWoSqnIsvjGA8R22JTLCknSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YD6tRNyU/fleZuj4d8QRJDnbQMI3xKsYbwpXhzq4332ukeykdwqNK4pPKl3CReEvJk37ognVVzFqPP74UpFGMWkMDfxAZidoq87mP6/+zUGzFRt9HC3ppV7olD7LipI1Tx5kK29s+X2f/vSZ7UazFSc6KZKYwZa6T0j2rOQeXUQ= 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=CpLaACsQ; arc=none smtp.client-ip=217.70.183.194 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 C9FF840004; Mon, 12 Feb 2024 07:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724625; 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=CpLaACsQqjVCxN1nDvdqzfPxoK1c54PfXjzOH48eWawocztOZXx2gYfUdXnPtLJfD/zwbW HyNy8ENJ/CsO/jjE3/roWYzZWWBqapfQ4ba+cUGTsffzeTPu1l2+H1emZR94NdNXOHqAdF FwqB2GWmv4+usRkdeDTaCDuVVHo48aC3MAS9Ybi5ZljBc3hWkKzsfQRhQdOqq+F1Q38H3k uIKQJ9rAMvXwGYyUDVmR9LgSAbEsR6cts4SuZ7nno8mfI88IyCOc4sgts7peljBefZ0NGC PlgY7J8bO7GSPUtos5sLZGQ8tW6OALCQPUlJVdmAt9LD0zo2hpVLc3C/xQVn6Q== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes 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 v3 RESEND 4/6] bitmap: Introduce bitmap_off() Date: Mon, 12 Feb 2024 08:56:32 +0100 Message-ID: <20240212075646.19114-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-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 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com 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 -- 2.43.0