Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3575010rdh; Thu, 28 Sep 2023 16:31:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0cXN6cc3zMISNCFE7wQUfoVi38DEBUdHE/lYlHKHK2F5j8oyvCkASJag3P+vfAgihtu96 X-Received: by 2002:a05:6a20:ce83:b0:13d:6c5a:1887 with SMTP id if3-20020a056a20ce8300b0013d6c5a1887mr2411630pzb.20.1695943892634; Thu, 28 Sep 2023 16:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695943892; cv=none; d=google.com; s=arc-20160816; b=K2s453ock1Q9iBtwASE1KpBAQhFuoLOVWDpTQ5kc/nKiGzJUU/WXaft7Ni+jCuD2Rj UoY8nw65WAHESCL0EkvtvvxdPD/JJ+2FkWgyez1N0Nzh7iSXIM1+b5MWHsFiRvKYeJAd U1N36NuvWdNez0I5cjc5Wt6LKxIjPMk/wwl8kig5Sf3fe4PkpFJUH6oqAt6ruNiBncjq +o+QMQlqXo53qC1/jvppY/1kwdZZNaUcKrsPw8YF4WLiPCg6kp4KxP1lT/Jf7vTc2cW0 1J47Fhi0Lh2Beqxfj7DUs3RF0nNQ2yLgY1GQUxTclDadxqo5SyiRaCrir3yp8zCbZvC9 DSHA== 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=BQIXs+qq48cDvCc1t0NQ5MJGV2EjrkwfbJepFnNhtqs=; fh=rxe62e+8PHDvUistH8GWyXp9gA6ln/eOWmhCmPEkpTQ=; b=yfYvagPaN8TEOSQSvR8YXKa2vvc8P7yNOrRVO65f17Ps7Ur2Vv1v+R2D1/RH1971hw NS5wqA24e+LfZscvEn8BaLqiizALLRmo2zHcEnhB0qwq2LKtgdcSbMNIhrYqtwibFson DSMbMuVHhx6nSOuOvvxMdwAm+jo1pc/dJYj8AMsiiYe/QNKXxLcOs2CR+eU+YXOH2HN9 RnBk+zOAb0uUkJ048zO3BNJM+eZF1HSNduWT4DSJk1AlZDjJoeSaGyC2ue8pnidAyrVs Gjs3jHy1iRqRRU91XDI/O7QMf9ZVZl6QRRxEOv1aIl0Lo/9AAGKo8WLtUIdBIwDeS7r1 Ferw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Vg1l1V2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x42-20020a056a0018aa00b00691004e7db0si21271417pfh.170.2023.09.28.16.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 16:31:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Vg1l1V2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id C9308833D554; Thu, 28 Sep 2023 08:15:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbjI1PPn (ORCPT + 99 others); Thu, 28 Sep 2023 11:15:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231206AbjI1PPm (ORCPT ); Thu, 28 Sep 2023 11:15:42 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C84D5195 for ; Thu, 28 Sep 2023 08:15:36 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-65afae9e51fso56757166d6.0 for ; Thu, 28 Sep 2023 08:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695914136; x=1696518936; 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=BQIXs+qq48cDvCc1t0NQ5MJGV2EjrkwfbJepFnNhtqs=; b=Vg1l1V2Pwso3KfnK72QbKfGw+w7xCGXC8mffztVQe16pQsewCcuGhmoKS0wB++6SFb kHhbmSaV3idtOBVklbx6X72kJWqV67Aw2q+o+dGlIYpJSzYhZv77ocfp1Pso+p4kxILn tEF/voBrnIX4tT2FMPtfOSWVteX09YNAVMe2f7nuddBF4DoV76VWuqLoQgw7tP211Rwr e+OGMVnkoUFJbLRC9IbCl7+rjRMKNPBQ+gDY+/Ufkb7SRHfTm0qWJJ2tZF6pizbSCJTB 47hmi6fskwT9zjivwa3BgLdpN6NyxPblgbD9ePX0EEReCYH6x0Y7MqLkvUTvZpAzLdo3 9+pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695914136; x=1696518936; 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=BQIXs+qq48cDvCc1t0NQ5MJGV2EjrkwfbJepFnNhtqs=; b=vgnIEzIV2YuEVViPQfnFBNwwk4tVHgeSSBxgpUBWONXCXvMN1Ozz3IHfnP0U2R1EnM gDRViwS1eNS08IJus/Gxr5eIktZAqPu/Hy4cdgvKitTC9wuj6laoq2JF22K4RdvgoRGW 8De4riA1goWMRKkERbScU9MJMWWyWQ7NRS7jWy+l9QD4r3yfotFqufY+Nkgu05Y9DK8E 6hZezb2OiskJyLvxmjH7/o5+aUmPnN5C/Xk0YdK2B1CgJ9DbrR6aa+JhreHfQp61OxIm a+pITJ+U3KqOcgCSrst4ncnJ6cTxUKIMWwguzpmm7CPBbs3LaXkYpGrPO1cQCMuOVFYY A7qA== X-Gm-Message-State: AOJu0YybNlRVw8T13EP0GXchpyCFdmA5xlDWl/QcilGBXD7nE0SIROOV uJiwnpIE01kGiy6HBy2Tup1kEF5i4gYUz+yuIlcbyA== X-Received: by 2002:ad4:58ac:0:b0:65b:8ef:e4ea with SMTP id ea12-20020ad458ac000000b0065b08efe4eamr1271556qvb.56.1695914135738; Thu, 28 Sep 2023 08:15:35 -0700 (PDT) MIME-Version: 1.0 References: <20230922080848.1261487-1-glider@google.com> <20230922080848.1261487-3-glider@google.com> <3bc8fda47dc04e3b8cfd0e3f6fc7bbee@AcuMS.aculab.com> In-Reply-To: From: Alexander Potapenko Date: Thu, 28 Sep 2023 17:14:55 +0200 Message-ID: Subject: Re: [PATCH v5 2/5] lib/test_bitmap: add tests for bitmap_{read,write}() To: Yury Norov Cc: David Laight , Andy Shevchenko , Catalin Marinas , Will Deacon , pcc@google.com, Andrey Konovalov , Rasmus Villemoes , Linux Kernel Mailing List , linux-arm-kernel , eugenis@google.com, Syed Nayyar Waris , 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 08:15:59 -0700 (PDT) On Thu, Sep 28, 2023 at 4:43=E2=80=AFPM Yury Norov w= rote: > > > > On Thu, Sep 28, 2023, 10:20 AM Alexander Potapenko wr= ote: >> >> On Wed, Sep 27, 2023 at 9:51=E2=80=AFAM David Laight wrote: >> > >> > ... >> > > Overall, unless allocating and initializing bitmaps with size >> > > divisible by sizeof(long), most of bitmap.c is undefined behavior, s= o >> > > I don't think it makes much sense to specifically test this case her= e >> > > (given that we do not extend bitmap_equal() in the patch set). >> > >> > Bitmaps are arrays of unsigned long. >> > Using any of the APIs on anything else is a bug. >> > So it is always wrong to try to initialise 'a number of bytes'. >> > The size used in the definition need not be a multiple of 8 (on 64bit) >> > but the allocated data is always a multiple of 8. >> > >> > Any calls to the functions that have a cast of the bitmap >> > parameter are likely to be buggy. >> > And yes, there are loads of them, and many are buggy. >> >> I got rid of the casts in the bitmap test, but they remain in >> mtecomp.c, where 16-, 32-, 64-byte buffers allocated by >> kmem_cache_alloc() are treated as bitmaps: >> https://lore.kernel.org/linux-arm-kernel/20230922080848.1261487-6-glider= @google.com/T/#mdb0d636d2d357f8ffe6ac79cef1145df3440f659 >> >> Having them allocated by bitmap_alloc() won't work, because on Android >> bitmap_alloc() will allocate the buffers from the kmalloc-64 cache, >> defeating the purpose of the compression. >> >> Would it be better to extend the bitmap.h API so that it is possible >> to allocate from a kmem cache (which would in turn require >> bitmap_kmem_cache_create() to ensure the alignment requirements)? > > > So all that is wrong then. Bad on me, I'd spend more time looking into yo= ur driver code... > > We already have bitmap_(from,to)_u(64,32), > And you can use them. For 16-bit you have to add helpers yourself. But it= 's not a rocket science. > So e.g. for compressing something into a 16-byte buffer using bitmaps I'd need to: 1) Allocate the buffer: buf =3D kmem_cache_alloc(...) 2) Allocate the bitmap: bitmap =3D bitmap_alloc(16*8, ...) 3) Fill the bitmap: mte_compress_to_buf(..., bitmap, 16) 4) Copy the bitmap contents to the buffer: bitmap_to_arr64(buf, bitmap, 16*= 8) 5) Deallocate the bitmap: bitmap_free(bitmap) instead of: buf =3D kmem_cache_alloc(...) mte_compress_to_buf(..., (unsigned long *)buf, 16) , correct? Given that the buffer contents are opaque and its size is aligned on 8 bytes, could it be possible to somehow adopt the `buf` pointer instead? > I'm AFK at the moment. I'll take a close look at your machinery at the we= ekend. Thanks and take your time!