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 X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60DF6C43381 for ; Mon, 18 Jan 2021 10:59:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2044A223E4 for ; Mon, 18 Jan 2021 10:59:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388388AbhARK7e (ORCPT ); Mon, 18 Jan 2021 05:59:34 -0500 Received: from foss.arm.com ([217.140.110.172]:32920 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389652AbhARK5k (ORCPT ); Mon, 18 Jan 2021 05:57:40 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 907681FB; Mon, 18 Jan 2021 02:56:53 -0800 (PST) Received: from [10.37.8.29] (unknown [10.37.8.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EF5F33F68F; Mon, 18 Jan 2021 02:56:50 -0800 (PST) Subject: Re: [PATCH v3 4/4] arm64: mte: Optimize mte_assign_mem_tag_range() To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Catalin Marinas , Will Deacon , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Andrey Konovalov References: <20210115120043.50023-1-vincenzo.frascino@arm.com> <20210115120043.50023-5-vincenzo.frascino@arm.com> <20210115154520.GD44111@C02TD0UTHF1T.local> <4b1a5cdf-e1bf-3a7e-593f-0089cedbbc03@arm.com> <0c1b9a6b-0326-a24f-6418-23a0723adecf@arm.com> <20210118104116.GB29688@C02TD0UTHF1T.local> From: Vincenzo Frascino Message-ID: Date: Mon, 18 Jan 2021 11:00:38 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210118104116.GB29688@C02TD0UTHF1T.local> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/18/21 10:41 AM, Mark Rutland wrote: > On Sun, Jan 17, 2021 at 12:27:08PM +0000, Vincenzo Frascino wrote: >> Hi Mark, >> >> On 1/16/21 2:22 PM, Vincenzo Frascino wrote: >>>> Is there any chance that this can be used for the last bytes of the >>>> virtual address space? This might need to change to `_addr == _end` if >>>> that is possible, otherwise it'll terminate early in that case. >>>> >>> Theoretically it is a possibility. I will change the condition and add a note >>> for that. >>> >> >> I was thinking to the end of the virtual address space scenario and I forgot >> that if I use a condition like `_addr == _end` the tagging operation overflows >> to the first granule of the next allocation. This disrupts tagging accesses for >> that memory area hence I think that `_addr < _end` is the way to go. > > I think it implies `_addr != _end` is necessary. Otherwise, if `addr` is > PAGE_SIZE from the end of memory, and `size` is PAGE_SIZE, `_end` will > be 0, so using `_addr < _end` will mean the loop will terminate after a > single MTE tag granule rather than the whole page. > > Generally, for some addr/increment/size combination (where all are > suitably aligned), you need a pattern like: > > | do { > | thing(addr); > | addr += increment; > | } while (addr != end); > > ... or: > > | for (addr = start; addr != end; addr += increment) { > | thing(addr); > | } > > ... to correctly handle working at the very end of the VA space. > > We do similar for page tables, e.g. when we use pmd_addr_end(). > Good point! I agree it wraps around otherwise. I will change it accordingly. Thanks! > Thanks, > Mark. > -- Regards, Vincenzo