Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2777542rdb; Fri, 22 Sep 2023 08:08:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbgRu1U8LAeQLUpQMynYlKGf0+TpdFWTGH0q2Ik4NEVaFK9ilz+pM9OIqS8kr684mr9uNo X-Received: by 2002:a05:6e02:3201:b0:34f:1e9c:45d5 with SMTP id cd1-20020a056e02320100b0034f1e9c45d5mr9049539ilb.32.1695395328065; Fri, 22 Sep 2023 08:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695395328; cv=none; d=google.com; s=arc-20160816; b=MxnAqUZCilNUANbKs84MhmoS9IyoQszwFCiZSh3qeVDeMujkRGuz7aj8TPlYPkg1CG EHYfwRQ2s3zoW1JDwCpresFV4lLdAhjBRRGl9vx7kN87q+tjQ7Ohara7mnOlI5LcgeUZ N/T505FKlefsCVepU+KKloh+G/U2LZ/2hgIV/c25NpmXYLX9Mv1brY2jC+0Jve6RI/qH VzVbgXvlVfbaVSI/0xkrOT3+6dg14CxXOqbgaT+RrvhxYaJxpcroQ1tw051enNJUvVJu SA3pyvmMj4YL1bBdN9yfmv1nfBwTuolNcfiL9vJ+fHPSuldJiOUnyIUzovcn3mw8zThY D1EQ== 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=Ef1lz4NaECWVWSkMTH/C2VI1iTg3OW5SLvb2NYIpXHw=; fh=nhpBpTfkR3JxP3JPqe3hyH3pwdO5gxRih5XSdSZX2z0=; b=i44PAmD/PSAfTlVaBztsJBx4qBFq8stuo9AGCJbTIDaC8ygqLiYh533JzYa414ZpIB 4zaigUjeZZrqhf80iNjI1xKTAi2b3MIwMEmT/MxbwRPYx8blvDWznsKpvVCnI0rgKDQm PUni4w2GeyTaFh6WHF2EOzWjB+LGBhqNfGYmXrFHBlsk6iRa9sdJ5KAXoOozVLPJQUOX 3dbJD5Nt3pHjAkeQWHTmz4TINQwUZ18Am3WS/EPJZ9ejBR3bRizGTeoT8uyEA/KJO1RT 1WleFcd0ArGAf6G4V/yB40l1owtWNs75LZ4FC8uvlOCKqrPD8HC17IQvmHwdOLrIo2AO +T3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qftf6imr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l191-20020a6388c8000000b00565eb0b4f33si3974117pgd.224.2023.09.22.08.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 08:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qftf6imr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id A462781CFF3C; Fri, 22 Sep 2023 01:05:36 -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 S232107AbjIVIFe (ORCPT + 99 others); Fri, 22 Sep 2023 04:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232054AbjIVIFS (ORCPT ); Fri, 22 Sep 2023 04:05:18 -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 943071F05 for ; Fri, 22 Sep 2023 01:03:51 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-64cca551ae2so10425276d6.0 for ; Fri, 22 Sep 2023 01:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695369830; x=1695974630; 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=Ef1lz4NaECWVWSkMTH/C2VI1iTg3OW5SLvb2NYIpXHw=; b=qftf6imrqBV0Y3hzXIyLPR1dsR/W2LFIruYgfAAl2PAyPVm4Zt/yJGi/fwhsYrVZHT FCZxfvQKBcaW6X9+Y4de1H+RNfVHbF9kzQ0+3Hr99PeK/lpqbhKjs9mzBE44eB10CQ/y yzyiQTQsjJk5L6DljdIEr9ThVBvmw0lz0OGpjpw1WjTz0HsFzVeX282GbVwH5cpEtdf+ i7w7+9mfii7/yDOVmcCuJcYpTyh4nPcRfyk/CDnk9sKJNT744H7MrDvJ+YrwANgDA99D lYykLDvGOA84Kwg0Nkoj7lCviKdi4O8IjPHkPlKF+MuFZclaUn2rEKzV2fU7P3p3Qcf1 heqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695369830; x=1695974630; 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=Ef1lz4NaECWVWSkMTH/C2VI1iTg3OW5SLvb2NYIpXHw=; b=PV/k1ZZ9kY8LPy1KRmfWtvMVuil6FD06HOg6w8/5WXRoGH86clGOGOxg7Oubcon3O4 X8oH/kwMEBFYfe02WxmUhVaLpSycUGjOuwiPnEGzkT+MEKaHfC5BXaHWPBIoXV2xHVWa ItBSO+CdrQhiIXkVJkdU5PvgzFp7Kq7zhckopHWiV8S/pqQM2Zf02pRjNhE0AT4wuKwX B6JNqiC97ZD3EeTjYIviz0Ro3ngutnrrGWRaNMGa7Aff7WpWcTVERXpb+UqnPb25btIE z6/10xLI927cCcXrwFa+k5/2A7fhPffvzhCbc3PErF2YQW+x2z6xcBJqu9b6lLXozne/ DrCQ== X-Gm-Message-State: AOJu0YyN/oAVkSr0VPXJt72m1q3yx+/2Dfqxqp4Shbr4ZosSN8NVrXYP HIy1aqa3BX5n2ZIX4l9Y7sUCpnkp9xD0flS1zGUQbQ== X-Received: by 2002:a0c:cd02:0:b0:62f:f2f0:2af3 with SMTP id b2-20020a0ccd02000000b0062ff2f02af3mr9041416qvm.41.1695369830373; Fri, 22 Sep 2023 01:03:50 -0700 (PDT) MIME-Version: 1.0 References: <20230720173956.3674987-1-glider@google.com> <20230720173956.3674987-4-glider@google.com> In-Reply-To: From: Alexander Potapenko Date: Fri, 22 Sep 2023 10:03:14 +0200 Message-ID: Subject: Re: [PATCH v4 3/5] arm64: mte: implement CONFIG_ARM64_MTE_COMP To: Andy Shevchenko Cc: catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, linux@rasmusvillemoes.dk, yury.norov@gmail.com, 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 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]); Fri, 22 Sep 2023 01:05:36 -0700 (PDT) On Fri, Jul 21, 2023 at 1:22=E2=80=AFPM Andy Shevchenko wrote: > > On Thu, Jul 20, 2023 at 07:39:54PM +0200, Alexander Potapenko wrote: > > The config implements the algorithm compressing memory tags for ARM MTE > > during swapping. > > > > The algorithm is based on RLE and specifically targets 128-byte buffers > > of tags corresponding to a single page. In the common case a buffer > > can be compressed into 63 bits, making it possible to store it without > > additional memory allocation. > > ... > > > +Programming Interface > > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > + > > + .. kernel-doc:: arch/arm64/mm/mtecomp.c > > :export: Done > > + > > Is it dangling trailing blank line? Drop it. Sorry, it's hard to attribute this comment. I am assuming it is related to Documentation/arch/arm64/mte-tag-compression.rst - done. > ... > > > +#include > > > +#include > > This is guaranteed to be included by bitmap.h. I think we'd better stick to IWYU here. Ingo's patch: https://git.kernel.org/pub/scm/linux/kernel/git/mingo/tip.git= /commit/?id=3D32b1e9e4f5774951a3a80604a39fa1f0674c1833 specifically adds bitmap.h where bits.h is already present, without removing the latter. Although there might not be general consensus on this in the kernel right now, I think Ingo's "Fast Kernel Headers" set out a good direction. > > > +/* > > + * Sizes of compressed values. These depend on MTE_TAG_SIZE and > > of the This comment is gone now > > > + out_tags[0] =3D prev_tag; > > out_tags[cur_idx] ? Yeah, looks more readable. Done. > > > + for (i =3D 0; i < MTE_PAGE_TAG_STORAGE; i++) { > > + for (j =3D 0; j < 2; j++) { > > + cur_tag =3D j ? (tags[i] % 16) : (tags[i] / 16); > > + if (cur_tag =3D=3D prev_tag) { > > + out_sizes[cur_idx]++; > > > + } else { > > + cur_idx++; > > + prev_tag =3D cur_tag; > > + out_tags[cur_idx] =3D prev_tag; > > + out_sizes[cur_idx] =3D 1; > > Looking more at this I think there is still a room for improvement. I can= 't > come up right now with a proposal (lunch time :-), but I would look into > > do { > ... > } while (i < MTE_...); > > approach. We can e.g. get rid of the nested loop and iterate over tags instead of bytes (see v5) > > +static size_t mte_size_to_ranges(size_t size) > > +{ > > + size_t largest_bits; > > > + size_t ret =3D 0; > > Redundant assignment. Please, check again all of them. Done. > > + > > + largest_bits =3D (size =3D=3D 8) ? MTE_BITS_PER_LARGEST_IDX_INLIN= E : > > + MTE_BITS_PER_LARGEST_IDX; > > + ret =3D (size * 8 + MTE_BITS_PER_SIZE - largest_bits) / > > Hmm... I thought that we moved BYTES_TO_BITS() to the generic header... > Okay, never mind. Ack > > + (MTE_BITS_PER_TAG + MTE_BITS_PER_SIZE); > > + return ret; > > return (...) / ...; Done > > +} > > ... > > > +static size_t mte_alloc_size(unsigned int num_ranges) > > +{ > > + size_t sizes[4] =3D { 8, 16, 32, 64 }; > > Hooray! And now it's not needed anymore... > > > + unsigned int i; > > + > > + for (i =3D 0; i < ARRAY_SIZE(sizes); i++) { > > ...as sizes[i] is equivalent of (8 << i). It's gone now. > ... > > > +/** > > + * mte_compress() - compress the given tag array. > > + * @tags: 128-byte array to read the tags from. > > + * > > + * Compresses the tags and returns a 64-bit opaque handle pointing to = the > > + * tag storage. May allocate memory, which is freed by @mte_release_ha= ndle(). > > + blank line here. Done (here and in other places in the file), but I'm wondering why https://docs.kernel.org/doc-guide/kernel-doc.html does not mandate it. > > > + * Returns: 64-bit tag storage handle. > > + */ > > ... > > > + /* > > + * mte_compress_to_buf() only initializes the bits that mte_decom= press() > > + * will read. But when the tags are stored in the handle itself, = it must > > + * have all its bits initialized. > > + */ > > + unsigned long result =3D 0; > > // Actually it's interesting how it's supposed to work on 32-bit > // builds... It is not supposed to work on 32 bit. First, the code is in arch/arm64 :) Second, 32-bit CPUs do not support MTE (which reserves the four upper bits of the address) > > > +static unsigned long mte_bitmap_read(const unsigned long *bitmap, > > + unsigned long *pos, unsigned long bi= ts) > > +{ > > + unsigned long result; > > + > > + result =3D bitmap_read(bitmap, *pos, bits); > > + *pos +=3D bits; > > + return result; > > unsigned long start =3D *pos; > > *pos +=3D bits; > return bitmap_read(bitmap, start, bits); Done, thanks! > > +} > > ... > > > + unsigned short r_sizes[46], sum =3D 0; > > See below. > > ... > > It's cleaner and more robust to have > > sum =3D 0; > > here. Moved it inside the loop init statement > -- > With Best Regards, > Andy Shevchenko > Thank you!