Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1151081rdb; Mon, 2 Oct 2023 00:01:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLSNBfoEE3jVpEmxM26lX0ueG3Em6v2HTX232iJ+SvVcQTf4vpFZ3nchdjDuxmifOiBlbb X-Received: by 2002:a05:6358:4187:b0:143:4fd:6001 with SMTP id w7-20020a056358418700b0014304fd6001mr11292316rwc.21.1696230075260; Mon, 02 Oct 2023 00:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696230075; cv=none; d=google.com; s=arc-20160816; b=ybqKD4bYjeJWbayOs9nKNRICeQU2LZHI6KFp/qYUjAlHFmkz9S7DV+vZH5+I1hbRls h6mNk6LOz+6LhZcs/ufP+u/UTsk0923T9vfay8eGkdHd9leG5UiPjlc/czkRtqfClLx0 VSPY541wBtZyHdhuEXn+sJg7uVaf/6wxR0VOw9/yDZmMZtQzjoyeDFsAxfhRQCoSGP27 GP6fitknTqdLkEpALMdVUSr7I0kZko5qAS/R5QTlplS7LEkgPbGyvDmnC/mICaGi3vfO ohAHedy7FuuUgoT4nYagMHmuIhH12bbGGFe/AcgXvYEfTCYzszMBJMd4Qf4JzUcW8o30 BxpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WLjWMNFAWqDPTKvhc5gdR9AFU5XRTZ7GYfHifI1+etw=; fh=PfSJyJeF567qPY5wkPalmDvrQ9Rt5BDgyw3QE7Rz0hY=; b=wSOSNSC2c9xxNcWyBxVqotXj0qZC/vYk2UpObAxZncqDm5PVW+9pgmPdeelOF6cJ9v t2kxmg1eAQ934Qn6QBGDqSvxpGJfdEjqWa5RUxGLEkpnXmCha+LLzkspVHMaXCrSv0o8 EWlFoH05x41f2KMIKubeYoJcfleKZ90vgmXLGZHSIjw0BkjhaXop6K6HxVjichW1qKer HeQj+SQvZGtepP2JMFmPFQhCbdUn03Xi366c0SI05XfhwSaPQqNjhyQe2fLwN5VA5L66 cpGSdv9HtWw+EBXoza1IFQS0v7PTEVudSjeIo4xRwpKI3Vzdf/BMcEtdftfC0KGLfyTx pOyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EfoFq1fn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h11-20020a65480b000000b005859c1e41a0si7192849pgs.201.2023.10.02.00.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 00:01:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EfoFq1fn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C797D806E3F8; Sun, 1 Oct 2023 19:45:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235120AbjJBCo4 (ORCPT + 99 others); Sun, 1 Oct 2023 22:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbjJBCoz (ORCPT ); Sun, 1 Oct 2023 22:44:55 -0400 Received: from mail-vk1-xa34.google.com (mail-vk1-xa34.google.com [IPv6:2607:f8b0:4864:20::a34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00B0BB8 for ; Sun, 1 Oct 2023 19:44:52 -0700 (PDT) Received: by mail-vk1-xa34.google.com with SMTP id 71dfb90a1353d-49b289adca9so1338061e0c.3 for ; Sun, 01 Oct 2023 19:44:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696214692; x=1696819492; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=WLjWMNFAWqDPTKvhc5gdR9AFU5XRTZ7GYfHifI1+etw=; b=EfoFq1fndvrK7tNrKc4xPFBUgYAwMhTbot52A1SMElqCKIoTiFflH3qInGsPFdAPZP +ucd0xEJpSmwGa9D8nvxriucHnKIVNP9SgPH1fviOe2AQIayF5kJ+e6Tlw626/NIMn2e +9NM5AHTbCdpP+VTUL4VAhMMLCesqjSeW5BJIIsMLbhpBIYL7bijKr4HTInlNy2E+P6e qGAtYqfZOYvhJUKGqVxFuCdRr0EXLdKiXPlucCmxKebGl6kqR3VDd3Ts0ADtWaw+1ml1 HdTLYkwDE1EjslktmbPWQNbffg+32sFl4njH8qIh0XGaYvRNrK6/OcZ4mi2jDs0OTe4I cJ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696214692; x=1696819492; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WLjWMNFAWqDPTKvhc5gdR9AFU5XRTZ7GYfHifI1+etw=; b=dpbwsEhG0kXBoBkn8jcR28GruXK0gz+hKpO3YXrPComzQ8NPt04CVd46syE7ejdqyG 8TMEFmPkJn/zkqTb9qKvbpgNVBPD2EdON70+b7zmuQaKMiKUCMn/jkaHJTmN0GMEGmRl L5jBKfaMwnjACx7eq+CNfHiLrCn+RctJ7eKcf7MdbhWyett95EjTUdbTpL103noTg7rC 8CgLhr1fvmqK/MN4yNdhMsh6cVrCQSfAnW7zqG0XAJU3uJ/sRyRzkVRM+D+qnIqwPJ8O xQ+Y6JboP8m18XAe9u1f8oyOIg/q9+vIb8qPuosGbvxb8N+m0wlfi/oVi4Qpw0jpqR7Z CGCA== X-Gm-Message-State: AOJu0YwAPCenUPhKr5FiHdVwZIdFQ21sekc35exZAGBOcy0ekiaLnpPn +TXaQk+cYX7Asuy0P3/tpp5ME3Xi3zhvJg== X-Received: by 2002:a1f:ec43:0:b0:496:2e22:29e3 with SMTP id k64-20020a1fec43000000b004962e2229e3mr7910406vkh.1.1696214691579; Sun, 01 Oct 2023 19:44:51 -0700 (PDT) Received: from localhost ([2607:fb90:beca:c7a7:dba8:3746:709f:6151]) by smtp.gmail.com with ESMTPSA id bj48-20020a0561220e7000b0049ab3a5160bsm1293593vkb.23.2023.10.01.19.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 19:44:51 -0700 (PDT) Date: Sun, 1 Oct 2023 19:44:49 -0700 From: Yury Norov To: Alexander Potapenko 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 Subject: Re: [PATCH v5 2/5] lib/test_bitmap: add tests for bitmap_{read,write}() Message-ID: References: <3bc8fda47dc04e3b8cfd0e3f6fc7bbee@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Sun, 01 Oct 2023 19:45:07 -0700 (PDT) On Fri, Sep 29, 2023 at 10:54:59AM +0200, Alexander Potapenko wrote: > On Thu, Sep 28, 2023 at 10:02 PM 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 bitmaps > > > I'd need to: > > > > > > 1) Allocate the buffer: buf = kmem_cache_alloc(...) > > > 2) Allocate the bitmap: bitmap = 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 = 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 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 would > > 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 = kmem_cache_alloc(cache, GFP_KERNEL); > > mte_compress_to_buf(r_len, r_tags, r_sizes, tmp, alloc_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==8 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. Sorry again.