From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 845FBEB64DC for ; Fri, 21 Jul 2023 11:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=T6n6QRVkUz45S3312Mg4m3QRu2oKi4irJNxgbJAxxhY=; b=Qe1GWVcSpZr/AI HP+Zb+bqoRwKh69GbPln1Y0i6+r2O1PUQHlO4WETAesd4u1424vOwaq5sOBLQEwYTekNIIEG+0TSi Yxc6im/XcU9Pf4sG0xLGjj6woEZhrHRV/L0yCW31PMElpHOAh34eYxnqhkif9XoQaCEEclVINZhjL vyWF2ZY6OurNtQFIxn9DXOnivMJ693OSajYZ6O8K522hD4izuYDGJ9hi7/Ka3KzB8MapgLlb/h+Fe ozPEpoPXhyiIWjF29QnNQsijlbv1nKRlGT2WuQcM3OMvWYksYbeoOYK1d8bT8GM15u5DORqnoEIXA OeejDuLqau0bPXOkg7jQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qMoD9-00Dux6-0q; Fri, 21 Jul 2023 11:22:15 +0000 Received: from mga07.intel.com ([134.134.136.100]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMoD7-00DuwM-0T for linux-arm-kernel@lists.infradead.org; Fri, 21 Jul 2023 11:22:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689938532; x=1721474532; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=57KU9BS+4WtXtGFaL6wZCWV3ud+hpdZFulKGMvMZrP8=; b=XKQYjDfiq5V66+yQjTWiMF7faufqUAe9FhtPBhz0oFKxxssVSNksjPrp OUw7ZA8w1mZ2W99PdSz1ULvXtLufNfMUtcRn0MVs4YQ21rDLvz4G/UU/q xqlqg088IywZ7ynbPp/Y6P6euLeAR2fD+0fe3A2hEz749RCMhmV39gyg5 VYBbF7nxXb+i3ejVyztWgZDfxiKcdvhshHihiFeddb+NocKyjoKhut1D/ NFs3mmkZ6S5QNuA/lRFYfaFHp56t2NKKZYA5iH2A4ptTbQI0DpRB30n8S NTfmmkjAcpFGxIbDVmHTi3nT6/RNLcvSe+RQcGNNxTUNfeIk65bLrjb+t A==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="433229018" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="433229018" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 04:22:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="971411749" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="971411749" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga006.fm.intel.com with ESMTP; 21 Jul 2023 04:22:07 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qMoCz-001tP1-1g; Fri, 21 Jul 2023 14:22:05 +0300 Date: Fri, 21 Jul 2023 14:22:05 +0300 From: Andy Shevchenko To: Alexander Potapenko 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 Subject: Re: [PATCH v4 3/5] arm64: mte: implement CONFIG_ARM64_MTE_COMP Message-ID: References: <20230720173956.3674987-1-glider@google.com> <20230720173956.3674987-4-glider@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230720173956.3674987-4-glider@google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230721_042213_226586_70113577 X-CRM114-Status: GOOD ( 26.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 > +===================== > + > + .. kernel-doc:: arch/arm64/mm/mtecomp.c :export: > + Is it dangling trailing blank line? Drop it. ... > +#include > +#include This is guaranteed to be included by bitmap.h. > +#include > +#include > +#include > +#include > +#include > +#include ... > +/* > + * Sizes of compressed values. These depend on MTE_TAG_SIZE and of the > + * MTE_GRANULES_PER_PAGE. > + */ ... > + u8 prev_tag = tags[0] / 16; /* First tag in the array. */ > + unsigned int cur_idx = 0, i, j; > + u8 cur_tag; > + out_tags[0] = prev_tag; out_tags[cur_idx] ? > + for (i = 0; i < MTE_PAGE_TAG_STORAGE; i++) { > + for (j = 0; j < 2; j++) { > + cur_tag = j ? (tags[i] % 16) : (tags[i] / 16); > + if (cur_tag == prev_tag) { > + out_sizes[cur_idx]++; > + } else { > + cur_idx++; > + prev_tag = cur_tag; > + out_tags[cur_idx] = prev_tag; > + out_sizes[cur_idx] = 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. > + } > + } > + } ... > +static size_t mte_size_to_ranges(size_t size) > +{ > + size_t largest_bits; > + size_t ret = 0; Redundant assignment. Please, check again all of them. > + > + largest_bits = (size == 8) ? MTE_BITS_PER_LARGEST_IDX_INLINE : > + MTE_BITS_PER_LARGEST_IDX; > + ret = (size * 8 + MTE_BITS_PER_SIZE - largest_bits) / Hmm... I thought that we moved BYTES_TO_BITS() to the generic header... Okay, never mind. > + (MTE_BITS_PER_TAG + MTE_BITS_PER_SIZE); > + return ret; return (...) / ...; > +} ... > +static size_t mte_alloc_size(unsigned int num_ranges) > +{ > + size_t sizes[4] = { 8, 16, 32, 64 }; Hooray! And now it's not needed anymore... > + unsigned int i; > + > + for (i = 0; i < ARRAY_SIZE(sizes); i++) { ...as sizes[i] is equivalent of (8 << i). > + if (num_ranges <= mte_size_to_ranges(sizes[i])) > + return sizes[i]; > + } > + return 128; > +} > +} ... > +/** > + * 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_handle(). + blank line here. > + * Returns: 64-bit tag storage handle. > + */ ... > + /* > + * mte_compress_to_buf() only initializes the bits that mte_decompress() > + * will read. But when the tags are stored in the handle itself, it must > + * have all its bits initialized. > + */ > + unsigned long result = 0; // Actually it's interesting how it's supposed to work on 32-bit // builds... DECLARE_BITMAP(result, BITS_PER_LONG); and then bitmap_zero(); ? ... > +static unsigned long mte_bitmap_read(const unsigned long *bitmap, > + unsigned long *pos, unsigned long bits) > +{ > + unsigned long result; > + > + result = bitmap_read(bitmap, *pos, bits); > + *pos += bits; > + return result; unsigned long start = *pos; *pos += bits; return bitmap_read(bitmap, start, bits); > +} ... > + unsigned short r_sizes[46], sum = 0; See below. ... It's cleaner and more robust to have sum = 0; here. > + for (i = 0; i < max_ranges; i++) { > + if (i == largest_idx) > + continue; > + r_sizes[i] = > + mte_bitmap_read(bitmap, &bit_pos, MTE_BITS_PER_SIZE); > + if (!r_sizes[i]) { > + max_ranges = i; > + break; > + } > + sum += r_sizes[i]; > + } > + if (sum >= 256) > + return false; -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel