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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 42927C433E6 for ; Mon, 18 Jan 2021 20:30:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00BC222CAD for ; Mon, 18 Jan 2021 20:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394326AbhARU3u (ORCPT ); Mon, 18 Jan 2021 15:29:50 -0500 Received: from foss.arm.com ([217.140.110.172]:60674 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389071AbhARKmH (ORCPT ); Mon, 18 Jan 2021 05:42:07 -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 F3DDD1FB; Mon, 18 Jan 2021 02:41:20 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.39.202]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D6733F66E; Mon, 18 Jan 2021 02:41:18 -0800 (PST) Date: Mon, 18 Jan 2021 10:41:16 +0000 From: Mark Rutland To: Vincenzo Frascino 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 Subject: Re: [PATCH v3 4/4] arm64: mte: Optimize mte_assign_mem_tag_range() Message-ID: <20210118104116.GB29688@C02TD0UTHF1T.local> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c1b9a6b-0326-a24f-6418-23a0723adecf@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). Thanks, Mark. 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=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 55042C433E0 for ; Mon, 18 Jan 2021 10:42:38 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D1F14229C6 for ; Mon, 18 Jan 2021 10:42:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1F14229C6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=tOcDK2PWp5GSKrqTozXjpyRExj1/n2A2MyXjU1nSAGw=; b=gWsjvYh4Fblr+BHXtOF3KmGbv cilZ1VcH1AeKpB4O38yUfTla7hbsud8ggbsvgnxfrLDuFRdIUHSJ0suhNdvz4Qx4Wa19E8VuiUXnC v3WF53uoH8aGVeoeNCgKxsdZhXz1qouAflns1tYPF/hy5Q4cPiP+MIiD78mxpkQid7hjHwCsUZsqv yZJBnYxi4IsPgiVS991ZsX+c24uAU8g8Pf3V1K7q+YArazeOhvBzAI+D+5nd/+FNen4Ug92j4C2xT FFifm9kmVnx2ZSpSNCFwF00wtDXFZYDw/DOxHod2XtebkbUEgw9npQyiaYOM5Xz711BB5uzkptc2Z SO2UVJ30g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1RyQ-0006zx-Cf; Mon, 18 Jan 2021 10:41:26 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1RyN-0006zY-9R for linux-arm-kernel@lists.infradead.org; Mon, 18 Jan 2021 10:41:24 +0000 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 F3DDD1FB; Mon, 18 Jan 2021 02:41:20 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.39.202]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D6733F66E; Mon, 18 Jan 2021 02:41:18 -0800 (PST) Date: Mon, 18 Jan 2021 10:41:16 +0000 From: Mark Rutland To: Vincenzo Frascino Subject: Re: [PATCH v3 4/4] arm64: mte: Optimize mte_assign_mem_tag_range() Message-ID: <20210118104116.GB29688@C02TD0UTHF1T.local> 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0c1b9a6b-0326-a24f-6418-23a0723adecf@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210118_054123_408407_6F85DDC7 X-CRM114-Status: GOOD ( 20.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Marco Elver , Catalin Marinas , Evgenii Stepanov , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Alexander Potapenko , linux-arm-kernel@lists.infradead.org, Andrey Konovalov , Andrey Ryabinin , Will Deacon , Dmitry Vyukov 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 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(). Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel