From patchwork Mon Feb 12 07:56:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2289799dyd; Mon, 12 Feb 2024 00:01:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkrElpSOwinGMGTI7KxzFYSKbAPyd14EhhGBoYS9yBFCI2+pea9EvrDVc/k3F+SVWAY3uDGbh3Tn9YwvpUVfO3IztMZQ== X-Google-Smtp-Source: AGHT+IH9Aika3YWJ589ElaWQ+m0N9VOXRjP81/IiBFq61gnr42628v1CgVAPX8JadsahLxhtQg06 X-Received: by 2002:a05:622a:284:b0:42c:113a:25ec with SMTP id z4-20020a05622a028400b0042c113a25ecmr8823685qtw.32.1707724870289; Mon, 12 Feb 2024 00:01:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724870; cv=pass; d=google.com; s=arc-20160816; b=SxL16B1xeMyZqoG2B/NNxoTbjhEhPceVFLvRi+eunmFsRcIR6nRxlJcWFBTj92kCgQ AgujwJnBYuqIN9ztHa/AAoQGwouz57s2kq4Hh2dvWdBl17nASEAFnrbbxRUuVYiCLwqI AQBy/cZdp0Tbe/82j6WGlJyijo3xj73Ve8KS8J0aBPoEE5fl+XFSp0cbKGV5rN6q88un dWlZ8k9hbB9IxSYZjrFlp0Yr1YtqIi30eO5iWZqzqc9H/HAAN6OSC2A3nkjbHEWujdzl ftkGIQRsRPgXiqNRZvics0H8IKOhkiZ2h/F1QuZxthRoTU+84s7hGsp1kRWvfUGxkEky mwsw== 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=fyi/dqKzXxx8/aMLXK7VAZd7qbgQYLs/DnHV5Hw8Yfw=; b=LFootDfmahUZwSHUtChjcBZ6GnwHTZ//6bw8XMJM4/XCWdCRCpMym50qT7CrSHAwf1 DjHaCYkrLgzvfW77wfX5MXlDXEva61j+j9Q1kZkYFkJSEbDROasfD4S2qz9lAn0LwrHB rOWR3kadmQ+OndvvIGRxTRnOUHbr/1Yj1fICStdw1jsdOmCJzaghmhxFJ6T8++QDCUn8 TyPQtrOy1ULJE40TcyDd4+z2ERecXye8sZS34jBvUGvffijPirayLZDBO2lhq9EBFiwD sXO1KmYAeMvfUAybIqdCmLDRLoVTY3fr63oojgSfpCLmfi0hidpyw9S4W3YzWo32e5jB M26Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dTj0L8CU; 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-61172-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61172-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCUt9/uZtbo8HtsTomOFRDsS4KOTISnSpYXjBcfIl8smhS757yjbgbKwPbqZtlz8i4quRkuyz+roa97J2KCzqLVZ3cKuwA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b15-20020ac8540f000000b0042c2ce2fb2dsi1855287qtq.428.2024.02.12.00.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:01:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61172-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dTj0L8CU; 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-61172-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61172-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 187221C215AA for ; Mon, 12 Feb 2024 08:01:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57028208DD; Mon, 12 Feb 2024 07:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="dTj0L8CU" 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 6BF14FC16; Mon, 12 Feb 2024 07:57:14 +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=1707724636; cv=none; b=C2YoAALDKFOeza073flVq09NfNaxXZ+fQIveStQE2bjLypjmVIfna+3vrGQTqfaAYXYmuhmEGoFAyWRhIvFblk7pekG7P6uOgK5wQvH48rn+FtMMiDlH7jfoOU8BoNWj99kPeJ6T2ZwT3oPZ1UrvpUh/aj5NbcMATLZNl1nW5+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724636; c=relaxed/simple; bh=o3GCbQ0HDcwCxhsdiMaIWoSqnIsvjGA8R22JTLCknSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zg4tTCacd8lAQxX15M+Lh/219jPN9amJGJRgUDhXKrPsFENivOz/j8u6qxrbGSPgXlFYZSA5DLk8fueAZuJDcb2CB5+l3/6ZpcpUCGViUDsv2tJzTKLmnidr1N7wtPd7feBMNhgus+su4UCxM+/fveOlP+AP110931fcJbghfkA= 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=dTj0L8CU; 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 89FA640013; Mon, 12 Feb 2024 07:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724631; 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=dTj0L8CUPn2xJHC/hWxnBaRNxEwVgoRfzQnMxFRgwd/yOia4U4+FtVuXb3r4d21WVoWnwJ s4oHRXy4yAcxKfXMeD+GT7Vt7wdJIxB2kBQQbYDaMBijGqh6gNPOBq0zsFLYMVkQwUB20u seFbF09SmNRgT3KZtBvZcj3u081a4q7Q87NINExrU+4R5iftejtlX6nGn2Hczdij/MQGN8 1BYkC8dY6UpyNf/q6q+c1Z36Q69Fg7FuP29o0nkmqlg/ibfIuqCm0Hhh8yofq8A7oaKvgz T2i/gNrfa7sLBmuA0sC5vysK6GKgtYC8kVP7W57/I8XYXyoRt8JVnA36/pBazQ== 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: [RESEND PATCH v3 4/6] bitmap: Introduce bitmap_off() Date: Mon, 12 Feb 2024 08:56:39 +0100 Message-ID: <20240212075646.19114-12-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 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790679311357425009 X-GMAIL-MSGID: 1790679313900529450 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