Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1243509rdb; Mon, 2 Oct 2023 04:00:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTCB+HL6E20sIksMKSJxyBIGIkLiEUVHaV1E0alv5h59QsAibx+HyRV5chbvfn1TN1ZbF0 X-Received: by 2002:a17:902:744c:b0:1c3:c687:4793 with SMTP id e12-20020a170902744c00b001c3c6874793mr9094563plt.63.1696244418714; Mon, 02 Oct 2023 04:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696244418; cv=none; d=google.com; s=arc-20160816; b=PLV9C+FpPuhpaDCO5BSRl+0gRax2df7BKrNcQRQnc4aML0fy1mZOmglmC9zC//wMj9 Xk33fe6ZUgCzSiufL+oRYvqGlX5y+SptVJzmZGJhrBq6M4Gg48pCrwTuOCxkvMNxc0l9 uweDNY9kCWoKSzmAlS4xsaXbHXzWQcRSxVUePuQD0PlWHUUTMFN9BjEELJjTIopeLmJ9 tdi2PREJzlij/xuRv8Z+AuoCVr5afYIvV6Hee9+a8DzHS/BkASatLw/lyMuA5f2NkfHC RAwx3oo/ek+9P4zdB0aIX43gu9noe3jCJnxJyrEDNJU2hWQUUrpj1QZgdjz46eTLiVFH TMcw== 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=hxS5zIJtibRbCh5vK1xQq6wWfoxr2oLcV1k3s8vlyNA=; fh=rxe62e+8PHDvUistH8GWyXp9gA6ln/eOWmhCmPEkpTQ=; b=O15+wNySm7Ve/SCq8nAERa8379XaGDY0SHetpjrgHMxWx6d3vdIYeVb9WyWxMBeZm/ TP4VxFdO1Nv0PxZb5tEfL0Bw51PM5KpkYQPWlpQPXcdIGAcwguIVfZbfzh7FElM5SxD2 Kz/D88D+malxgc9y/8edG2PqzWqDUUSfvHBwGRKlxDIIC/+0iUqOruPeh0u0YNlT+H75 8row+Y6EtM0+KVRz+ThaTYlw6AWEkpicfDkr8SwBve/6pYWJcUXyVbbQ8PmYyLUpMNdP VTfm6cxDxJwSSmZC0GWI07/fqqS1aNCg89rBDAaPS7/rP0oBejDvrmzJoWNYu9IVm3hB AZVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=un5UBiwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id i5-20020a170902c94500b001bdebddc2f7si29789662pla.257.2023.10.02.04.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 04:00:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=un5UBiwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 7D9BF807CF46; Mon, 2 Oct 2023 00:35:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235729AbjJBHfL (ORCPT + 99 others); Mon, 2 Oct 2023 03:35:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235630AbjJBHfK (ORCPT ); Mon, 2 Oct 2023 03:35:10 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF4A83 for ; Mon, 2 Oct 2023 00:35:06 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-664bd97692dso14215276d6.0 for ; Mon, 02 Oct 2023 00:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696232106; x=1696836906; 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=hxS5zIJtibRbCh5vK1xQq6wWfoxr2oLcV1k3s8vlyNA=; b=un5UBiwXqyrE+EJRcT5lQS5qgBxT53qfxrLv2WyzL5c3sMufs8w75QXWuTKgSogE8i +LLs4+dooT0BWxrRDo+ATadANUrzIKhbrTLzhwswHCpLRzbCjojos1CYDdDQNXkZG6P3 Oij9NDRdMGR9wfZ85SLkFWSf8V9kUFKVFH7h59BbhRLtwUemQ+FMX/Bx9NLEJg/RFNqh ehE/FZ7DCSC1PZHk63m2x/68cMJzo/85wGQ2ad2Z2dP1dtKb5gSp0pC349OkMUzrFvlC /76AOt16e1oIV438YDiyhOw03/Esro54pZgWALcPra5BlCnfLHUUgnsvwR2GTRQxloVK sBgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696232106; x=1696836906; 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=hxS5zIJtibRbCh5vK1xQq6wWfoxr2oLcV1k3s8vlyNA=; b=gZ/gonpV1w809bB6cOKm+2EyhkkSSj7v+BGT9JAuXF+FUgGCV/u8q6wvEOtDy2OIkq xEUVvmf6eLJwV7Xo5CJY/NXWs7kHKmw/lROvpNAFSw2nz955tv9TYE8Ea8IKopmen4yl TzPcM2pZm1Cg1eq5TeW//YXW4iUMc9K686C4iaumRj75lmk0a0e7jjYczJFZbjvTAmsz tiLihMPe3+xQT9MydlAndJoJFiJ1kT6nDSzScjyT/qyMyR+VzFZgroP343cnTxqCbrJe xhWJoVgOp1ztmrHet2GMcL6D/p3z8Q6qc2J3NrY+99jhhaey2NNmtQJCJI7n2oalsAIO 33NQ== X-Gm-Message-State: AOJu0YzG3kcikRmvdAVvCQuFGzBk2nwBwD/awjZX6QClCWAj4GhjFPRb qOehiMmOe4TEqqfy+pZZPPKoCa+bF5IvEXlV6A6rdw== X-Received: by 2002:a0c:db93:0:b0:64f:8d4c:1c0b with SMTP id m19-20020a0cdb93000000b0064f8d4c1c0bmr11335901qvk.43.1696232105529; Mon, 02 Oct 2023 00:35:05 -0700 (PDT) MIME-Version: 1.0 References: <3bc8fda47dc04e3b8cfd0e3f6fc7bbee@AcuMS.aculab.com> In-Reply-To: From: Alexander Potapenko Date: Mon, 2 Oct 2023 09:34:24 +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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 02 Oct 2023 00:35:27 -0700 (PDT) On Mon, Oct 2, 2023 at 4:44=E2=80=AFAM Yury Norov wr= ote: > > On Fri, Sep 29, 2023 at 10:54:59AM +0200, Alexander Potapenko wrote: > > On Thu, Sep 28, 2023 at 10:02=E2=80=AFPM Yury Norov wrote: > > > > > > On Thu, Sep 28, 2023 at 05:14:55PM +0200, Alexander Potapenko wrote: > > > > > > > > So e.g. for compressing something into a 16-byte buffer using bitma= ps > > > > 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, bit= map, 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 o= n 8 > > > > bytes, could it be possible to somehow adopt the `buf` pointer > > > > instead? > > > > > > I didn't find an explicit typecasting where you're using > > > mte_compress_to_buf(), but now after hard 2nd look I see... > > > > > > Firstly, now that in the documentation you are explicitly describing = the > > > return value of mte_compress() as 64-bit frame, the right way to go w= ould > > > be declaring the function as: u64 mte_compress(u8 *tags). > > > > Ack. > > > > > And the general pattern should be like this: > > > > > > unsigned long mte_compress(u8 *tags) > > > { > > > DECLARE_BITMAP(tmp, MTECOMP_CACHES_MAXBITS); > > > void *storage; > > > ... > > > if (alloc_size < MTE_PAGE_TAG_STORAGE) { > > > storage =3D kmem_cache_alloc(cache, GFP_KERNEL); > > > mte_compress_to_buf(r_len, r_tags, r_sizes, tmp, al= loc_size); > > > > > > switch (alloc_size) { > > > case 16: > > > bitmap_to_arr16(storage, tmp, 16); > > > > I might be missing something, but why do we need the switch at all? > > The buffers we are allocating always contain a whole number of u64's - > > cannot we just always call bitmap_to_arr64()? > > > > Note that for cases where alloc_size is > 8 we never make any > > assumptions about the contents of @storage, and don't care much about > > the byte order as long as swap decompression is done with the same > > endianness (which is always the case). > > (The case where alloc_size=3D=3D8 is somewhat special, and needs more > > accurate handling, because we do make assumptions about the bit layout > > there). > > So, this is my fault, and I'm really sorry. I read that 16-byte as > 16-bit, and mistaken everything else. Please scratch the above. > > If you allocate word-aligned memory, and it's a multiple of words, > which is your case, and access it only using bitmap API like > bitmap_read/write, everything should be fine. Ok, fine, I'll stick to the current implementation then.