Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9463275rwp; Thu, 20 Jul 2023 05:29:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlHUhQLsF90OAVOpXIHGugVS0avQ7XVWO7eknqWPgfxTzOniDF7+9Hj5iXRtiHJO2+0df9Rc X-Received: by 2002:a05:6a20:1c5:b0:128:f513:55ed with SMTP id 5-20020a056a2001c500b00128f51355edmr13941301pzz.54.1689856174184; Thu, 20 Jul 2023 05:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689856174; cv=none; d=google.com; s=arc-20160816; b=aqIOlFP6JVZVZ2rQlCKLX0CA54oUQ+DgKRy3gHyZHNIjmKN6Aq189xJv0nTtQ0hLDp 9k97ETlMZWfCz2uOwnE7+1GbLfO0kV/KW9NGXIorj0gvA5DxlGfzhe4vc7i7r44o5sT4 AxCBVJ+x1cgPVvCWAvfs+rH0HkxGuTGz694VjtFjMhXPBdTjY1ce8ta4dEeM/LR0UChy OonPdqQgAgYmkg/wFtIPIJQsVciS7VbpbPn1HYCDlVqD3uDosqHQnNU9KPYwJdzvPf36 WFYhjRh+EUh9cPHt42p8gsFHza3xEn5VzF6lVVqeJ39Ag5h8v48p2Ja41/wK4lL+5qrj pqXQ== 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=/tPgRTBCM977gv6ppD9dyp6sm3R1el/53OCuH7O8kZs=; fh=1meZCg+wFvwHgqAQwPym5i3Nv8UZ10Lc2adI75c/Klg=; b=jL7wBbskj0jv3JLMvKxi7i+ATlrjgSH/paB+hc//B/vAuDeEnY3+2wxCBqqT4at1Tl l3MXfpwNir/XOjPevUDihAbIszXTSa69D3diwTUw+p+G7k8D3qaJxqaIF+/nJUrbRf9r pYCPuNTpmkxyNNSj8pK/i7rf53CN56YdMVU4ZYnqb0me0q8uE/75IVw+UuVRk+86Jt4M WyGhwcsvhhZGFqzyFxQd2QPZiFlEJNDfQ9ZaafXI+YN3QP8CGVXXwm+24iQX8lfB3hTA CM2Wm/y8OJ5bxBl9DoxOXttRZv+KDcrEhBDUkyZhVJ3ePv6VSF7pAqB7GsfeKT/fA7Zg Gugg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=HCCWLsdM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a637516000000b0054f96f7bcf3si782758pgc.105.2023.07.20.05.29.21; Thu, 20 Jul 2023 05:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=HCCWLsdM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231596AbjGTMB0 (ORCPT + 99 others); Thu, 20 Jul 2023 08:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjGTMBZ (ORCPT ); Thu, 20 Jul 2023 08:01:25 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044AD10F5 for ; Thu, 20 Jul 2023 05:01:24 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-78654448524so28777139f.2 for ; Thu, 20 Jul 2023 05:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689854483; x=1690459283; 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=/tPgRTBCM977gv6ppD9dyp6sm3R1el/53OCuH7O8kZs=; b=HCCWLsdMHVrRSRmcWQZ1gyQhIQ8PnZKEgxRhbxB4rzrssUNXiyiEHCiQTy9m2CaVUD UC7hMy9bDCXQitgt9kEW40HmaobypIsgcOh6dTaLhUsRdXEy0UgQhdarWl8nEjesiMqu wf94a8jLEFk04/WCVqYe6tapDFuSVjBgyS5OpZt/0oZOve7cYVpEGottkxqZGBzX47Ql w6+gDTrOSXAZ/BcABN30IDbdfi2r1U2qys6+Rp5M2yNZMw4/Xo3rJ1QslrUhF1tmwhFN NLdvGC4WoKZU1q2yrX1bWPUXS9Vfb3rlVxqYSlyxiDcpYPUfzkOQyZvICHSD0tGzVZbq /jOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689854483; x=1690459283; 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=/tPgRTBCM977gv6ppD9dyp6sm3R1el/53OCuH7O8kZs=; b=M3pkjmP+w8+FDOVji+jHE2OOrKQl48u56ehyAzKEVnsfE3m9/51QpHht4xmvcye7SA ox6HQJmQB4HdK37GsphkXKujY88LZo0NKoQxP6z8iFRCBF/jM42dDKgmoBdNZCvkvAlF I002whqepcvDic/TEmAPIRAJFuDs/4Foil1ecd732Ym4kSofYudxV81gS0P4ffHqi071 vBUMuHQjd2e0bm/bGSbfvuX25TOrfKZhwA96CIIvGktSkAwOHn5NBdl96QYnv/inIHhl XnAAuwWdM/MIXA1JwVn4NN4bSj/hF9pAUW54pVvQio8F3tnRO2oxyGTTGEMkl8fTQshD FnNQ== X-Gm-Message-State: ABy/qLbJD2Iv4nr8JPOFtrAslEzxpxZxunR6gjHV2T+YS+9myX0NvCxI tWfm0W07MTBIeZtZc4JibO1iVNTt5P/nNpBFQMiwDyWsHwueN8W6ODJSsQ== X-Received: by 2002:a5e:9403:0:b0:784:314f:8d68 with SMTP id q3-20020a5e9403000000b00784314f8d68mr8639142ioj.1.1689854483201; Thu, 20 Jul 2023 05:01:23 -0700 (PDT) MIME-Version: 1.0 References: <20230717113709.328671-1-glider@google.com> <20230717113709.328671-4-glider@google.com> In-Reply-To: From: Alexander Potapenko Date: Thu, 20 Jul 2023 14:00:42 +0200 Message-ID: Subject: Re: [PATCH v3 3/5] arm64: mte: implement CONFIG_ARM64_MTE_COMP To: Yury Norov Cc: catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, 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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 19, 2023 at 11:06=E2=80=AFPM Yury Norov = wrote: > > > Would it help if I add a comment explaining that iN is an N-bit > > integer? Or do you prefer something like > > > > r_sizes[0..4] : 5 x 7 bits > > > > ? > > Yes, that would help. Ok. > > > 7 : Invalid handler > > > > No, 7 means "treat this handle as an out-of-line one". It is still > > valid, but instead of tag data it contains a pointer. > > So, it's invalid combination for _inline_ handler, right? Yes, that's right. > Anyways, I'm > waiting for an updated docs, so it will hopefully bring some light. It's on the way. > > > > + > > > > +/* Transform tag ranges back into tags. */ > > > > +void ea0_ranges_to_tags(u8 *r_tags, short *r_sizes, int r_len, u8 = *tags) > > > > +{ > > > > + int i, j, pos =3D 0; > > > > + u8 prev; > > > > + > > > > + for (i =3D 0; i < r_len; i++) { > > > > + for (j =3D 0; j < r_sizes[i]; j++) { > > > > + if (pos % 2) > > > > + tags[pos / 2] =3D (prev << 4) | r_tag= s[i]; > > > > + else > > > > + prev =3D r_tags[i]; > > > > + pos++; > > This code flushes tags at every 2nd iteration. Is that true that > there's always an even number of iterations, i.e. rsizes is always > even, assuming r_len can be 1? > > If not, it's possible to loose a tag, consider rlen =3D=3D 1 and > rsizes[0] =3D=3D 1. By design, ea0_ranges_to_tags() only accepts ranges that sum up to 256 (as produced by ea0_tags_to_ranges()) We could add a check for that, but given that it is an internal helper, a comment should suffice. But r_sizes[i] does not have to be even (otherwise we could've used this fact for a more efficient compression). For example, if the array of tags is {0xab, 0x0, 0x0, 0x0...}, then r_len =3D 3, r_sizes[] =3D {1, 1, 254}, r_tags =3D {0x0a, 0x0b, 0x0}. > > If yes, you can simplify: > > for (i =3D 0; i < r_len; i++) > for (j =3D 0; j < r_sizes[i]; j++) > tags[pos++] =3D (r_tags[i] << 4) | r_tags[i]; > > Anyways, in the test can you run all possible combinations? I will extract code from compress_range_helper() to generate different numbers of ranges and test against those. > > > > +/* Translate allocation size into maximum number of ranges that it= can hold. */ > > > > +static int ea0_size_to_ranges(int size) > > > > +{ > > > > + switch (size) { > > > > + case 8: > > > > + return 6; > > > > + case 16: > > > > + return 11; > > > > + case 32: > > > > + return 23; > > > > + case 64: > > > > + return 46; > > > > + default: > > > > + return 0; > > > > + } > > > > +} > > > > > > I wonder if there's a math formula here? Can you explain where from > > > those numbers come? > > > > I'll add a comment there. > > Basically, for the inline case it is the biggest N such as 4 + 4*N + > > 7*(N-1) <=3D 63 > > > > (not 64, because Xarray steals one bit from us) > > > > For the out-of-line case it is the biggest N such as 6+4*N + 7*(N-1) > > <=3D array size in bits (128, 256, or 512). > > So it's: N <=3D (BIT_CAPACITY + NUM4 - NUM7) / (TAGSZ + SZ) > > Doesn't look like a rocket science... Note that the size of largest_idx is picked based on the largest N for 64-byte buffers. And the size of r_sizes[] depends on the number of tags that fit into 128 bytes: if we throw away the largest range, each of the remaining ones will fit into 7 bits. But this will not be the case for e.g. 3-bit tags (we'll need 8-bit sizes t= hen). Changing mte_size_to_ranges() to "(size * 8 + MTE_BITS_PER_SIZE - largest_bits) / (MTE_BITS_PER_TAG + MTE_BITS_PER_SIZE)" indeed looks better than hardcoded numbers, but we should keep in mind that the parameters depend on each other and cannot be easily changed. > > Why don't you code the formula instead of results? Are there any > difficulties? Things may change. For example, in next spec they > may bring 3- or 5-bit tags, and your compressor will crack loudly > with hardcoded numbers. The main reason for the compressor to crack loudly would be the hardcoded assumption of the tags consisting of 4 bits. I don't think it is practical to account on that number to change (and e.g. use bitmap_read/bitmap_write to convert tags into ranges) - we'd rather have a static assert for that. --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Liana Sebastian Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg