Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1409027rdh; Mon, 25 Sep 2023 11:49:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuf299JL7F8AmaiZxRRV+Vd1Q5EvPuXZsLtLOjOTZ5jGvE4lZulJLDWcMGsaYAOWQI3oEE X-Received: by 2002:a05:6a00:a01:b0:690:1720:aa92 with SMTP id p1-20020a056a000a0100b006901720aa92mr6744539pfh.10.1695667783841; Mon, 25 Sep 2023 11:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695667783; cv=none; d=google.com; s=arc-20160816; b=zcGOguNX+P67vH/cLIGs4jVW9c/DjKtZsaDLaUsyHoZ9+uVqdBg5eJos3dcD6vgzh+ aEd1RIj0+JIB2UCjmc+yCAgDyhILMatV3mJwpOYquAOSLsXg69bb9oIxUSkRJEP5Sonu GP4p18Tt8Icy937qLM4lB8rfmmBK00T28SjSAM9Pm85LeplAPNPcQj5v/nwT2KJX/Cpq 5FcgCeTk5KFnrdJY+MytYeyIp/iMZCpiAGIz8NxuMTd3ZEFfeSRw8XdntZ1gU9+UquMY +uYGmPPP9B4y7nce2H9PbeKdPOa0E9ecUq8xMbxnu9TTvM9zDhJo8yRGIcrSJRwHIVvd Vstw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Q6WHvOjAcf/c5Ip/HyecTcRYeWcZLGwYjO1msnpDojU=; fh=Rq8uwEAOUKcATGtAJHR2kxEFaQ8bNbJAyN5jJ90W1yQ=; b=Ynbj6VmJwteKsYYSxfXaibeR8eNCxg+nVLWVncG99tLXcviLgq7fBjBcOWzNrGAnll QjK6wbAHFyZALRGEkOvyF+M3whBkb0euV0cXosIaPPiD94/H+ixwIkzdk2OOIbBIQoUj lwfRUerTaE+nTQCW1+Ex9w36cuRJ1pBG5WeaQ1b/YDlK4tjThhUogkegdZ6b0rBjkqEg 9AX6aAPZ7OSm9J49BEFBJp2D+RnQF8m9ggyCSs51jo+y4cPzTIqVS0a6ZMyQrek40Mdu niwsFALWH6RJwqf4A5QNbhInkk9xzM8QSywFosxeLzciTSJr2YI6XXb4G4PK+SzYwh6t iiww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Vv4SorPA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o31-20020a635d5f000000b00565cc12ee24si10307056pgm.874.2023.09.25.11.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:49:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Vv4SorPA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 85B9780BB3F3; Mon, 25 Sep 2023 10:17:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233011AbjIYRRG (ORCPT + 99 others); Mon, 25 Sep 2023 13:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232870AbjIYRRF (ORCPT ); Mon, 25 Sep 2023 13:17:05 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198BE112 for ; Mon, 25 Sep 2023 10:16:56 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-65b179b9baeso8521396d6.2 for ; Mon, 25 Sep 2023 10:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695662215; x=1696267015; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Q6WHvOjAcf/c5Ip/HyecTcRYeWcZLGwYjO1msnpDojU=; b=Vv4SorPALn8zsbFYRJxwgK2mQjB+wA4DE/V5fOFS8h80+/1qG7dV0q6WaEebvqIvh5 5UXiQsUhCMalOAnYwzVC3z5VZazUenxPdHIRdtxwCZgb9shaQx2SvnkTAZgnTrCfbUOz Uoy7JWgWyBW0ouJjelEhmyh1eSlON3itU05qmKV2cMKKQbqT/yU0sU9O4M9U7wj/KEz1 L1W7CvQHuebZlABA+zqWVlc3Q749xHAovCs10yc+LLRljOtoU+6ivKpM441/nGIXXcZr EpM1H4By3XUoJaVZu3RfBipvoDrXoAtuMHJ1Khq/4xUy81DZmNlxuYjZvAGiwQDW9HY8 G2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695662215; x=1696267015; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q6WHvOjAcf/c5Ip/HyecTcRYeWcZLGwYjO1msnpDojU=; b=p0Qlgy8Bct76Cpo2o2rXM5ij80OZjXkMg8zvuSjfl4qsIE+vzljPqrF183ZIEHvAG4 mPj9+xCZq11kcNvLQyS2rwfwQdmatPoMXd6GzfRL002ib4Fb6iiNrGsoq4pcM/j3kgp3 fL48JWc+yPfORPZaPfQky5oWhCMtwONvw6VaGSG/uYqoUbwG5emQRMU4ic+KlgoGv6o+ M0EkghWrvZZdXtJWlTok0VyAm+s0GLH0E4HWqxEOXCr32/bGIaAU8q/4h/Kgakh9RPFW B9bR3mipPISjR6ZHzqXPcqvtLCf5edkFco7tPwcPJ1pq94oImtWFqXjTrwXoZSN+lUBC xoFA== X-Gm-Message-State: AOJu0YzhknNkHFX392Mgksj/AQ8ELEp693hkQQskp1YCwy9IyTVWCGvx P81Nji9QfKf+OR/hhPkjQTDmkR7bCTKJj2vVo1j3oQ== X-Received: by 2002:a0c:b44a:0:b0:656:4ff8:691e with SMTP id e10-20020a0cb44a000000b006564ff8691emr6868611qvf.46.1695662215027; Mon, 25 Sep 2023 10:16:55 -0700 (PDT) MIME-Version: 1.0 References: <20230922080848.1261487-1-glider@google.com> <20230922080848.1261487-3-glider@google.com> In-Reply-To: From: Alexander Potapenko Date: Mon, 25 Sep 2023 19:16:14 +0200 Message-ID: Subject: Re: [PATCH v5 2/5] lib/test_bitmap: add tests for bitmap_{read,write}() To: Yury Norov Cc: Andy Shevchenko , catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, syednwaris@gmail.com, william.gray@linaro.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 10:17:08 -0700 (PDT) On Mon, Sep 25, 2023 at 6:06=E2=80=AFPM Yury Norov w= rote: > > On Mon, Sep 25, 2023 at 04:54:00PM +0200, Alexander Potapenko wrote: > > On Mon, Sep 25, 2023 at 3:09=E2=80=AFPM Alexander Potapenko wrote: > > > > > > On Mon, Sep 25, 2023 at 2:23=E2=80=AFPM Andy Shevchenko > > > wrote: > > > > > > > > On Mon, Sep 25, 2023 at 02:16:37PM +0200, Alexander Potapenko wrote= : > > > > > > > > ... > > > > > > > > > > +/* > > > > > > + * Test bitmap should be big enough to include the cases when = start is not in > > > > > > + * the first word, and start+nbits lands in the following word= . > > > > > > + */ > > > > > > +#define TEST_BIT_LEN (1000) > > > > > > > > > > Dunno why this didn't fire previously, but CONFIG_CPU_BIG_ENDIAN= =3Dy > > > > > kernel reports mismatches here, presumably because the last quad = word > > > > > ends up partially initialized. > > > > > > > > Hmm... But if designed and used correctly it shouldn't be the issue= , > > > > and 1000, I believe, is carefully chosen to be specifically not div= idable > > > > by pow-of-2 value. > > > > > > > > > > The problem manifests already right after initialization: > > > > > > static void __init test_bit_len_1000(void) > > > { > > > DECLARE_BITMAP(bitmap, TEST_BIT_LEN); > > > DECLARE_BITMAP(exp_bitmap, TEST_BIT_LEN); > > > memset(bitmap, 0x00, TEST_BYTE_LEN); > > > memset(exp_bitmap, 0x00, TEST_BYTE_LEN); > > > expect_eq_bitmap(exp_bitmap, bitmap, TEST_BIT_LEN); > > > } > > > > The problem is that there's no direct analog of memset() that can be > > used to initialize bitmaps on both BE and LE systems. > > memset fills an array of chars with the same value. In bitmap world we op= erate > on array of bits, and there are only 2 possible values: '0' and '1'. For = those > we've got bitmap_zero() and bitmap_fill(). > > > bitmap_zero() and bitmap_set() work by rounding up the bitmap size to > > BITS_TO_LONGS(nbits), but there's no bitmap_memset() that would do the > > same for an arbitrary byte pattern. > > We could call memset(..., ..., BITS_TO_LONGS(TEST_BIT_LEN)), but that > > would be similar to declaring a bigger bitmap and not testing the last > > 24 bits. > > No, you couldn't. On the test level, bitmap should be considered as a > black box. memset()'ing it may (and did) damage internal structure. You are right about this. bitmap_zero() and bitmap_fill() are calling memset() under the hood, but I shouldn't have assumed doing raw memset is safe. Unfortunately lib/test_bitmap.c does a bunch of memsets already, which probably led to the confusion. > If you have some pattern in mind, you can use bitmap_parselist(). For exa= mple, > you can set every 2nd bit in your bitmap like this: > > bitmap_parselist("all:1/2", bitmap, 1000); > > Check for almost 100 examples of bitmap_parselist usage in the test for > bitmap_parselist in the same file. Thanks! This solves my problem. I am planning to use an intermediate bitmap to avoid parsing the pattern multiple times. > > > Overall, unless allocating and initializing bitmaps with size > > divisible by sizeof(long), most of bitmap.c is undefined behavior, so > > I don't think it makes much sense to specifically test this case here > > (given that we do not extend bitmap_equal() in the patch set). > > This is wrong statement. People spent huge amount of time making bitmap > API working well for all combinations of lengths and endiannesses, > including Andy and me. Please accept my apologies for that, I didn't mean to insult you, Andy, or anyone else. My understanding of the comment at the top of lib/bitmap.c was that the bitmap API is expected to work in the presence of uninitialized values, which is actually not what the comment says. bitmap_zero() and such do ensure that none of the tail bytes remain uninitialized, so we are safe as long as those functions are used. > > NAK for this and for ignoring my other comment to v4. If you are talking about this comment: https://lore.kernel.org/lkml/ZQ2WboApqYyEkjjG@yury-ThinkPad/, I was going to incorporate it in v6 (as it was sent after I published v5). I am fine with not mandating the return value for reading/writing zero byte= s.