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=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 42CFFC433E0 for ; Sat, 16 Jan 2021 14:21:28 +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 D9BCD23117 for ; Sat, 16 Jan 2021 14:21:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9BCD23117 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:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1PP4HJ1w5gIPRUkq8PhwLaER03hrCuSooTHmo8Jrq0k=; b=3T8sQWNPYBoVYrmi5i/tKZyZ3 nftMCrfnLuqL8F8KqZ15bp6+tOWba1/Q21GdI7ARWtHCZ5W8t/jZNst8zOhM3gpOoajXe+XUfSofd Wp8gdKBllJKyo0YoZZ+Xni6hKahhmvsFWD8Rh4gyfyVe3f9adQaF8+v/wbYeYsdqG91m/eNtJ9wMc AYofCwixtFmBXwa1BF+7LG0uvcP90NvMEDAY/kGZWQSZLlE1jmiJ1xK5EjifJHc6JbH8/OYGZtbrD IaxyfByrQQPqEaz5Yqz/OABFUGQlNjG37+Wo1KhaH6Ut0ad4rt+l88mhQvnrlfVqUyzanPP+TgrQ7 TvzZInQlA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0mPO-0003Nb-Du; Sat, 16 Jan 2021 14:18:30 +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 1l0mPI-0003N9-QR for linux-arm-kernel@lists.infradead.org; Sat, 16 Jan 2021 14:18:25 +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 57E6712FC; Sat, 16 Jan 2021 06:18:23 -0800 (PST) Received: from [10.37.8.30] (unknown [10.37.8.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A19953F719; Sat, 16 Jan 2021 06:18:20 -0800 (PST) Subject: Re: [PATCH v3 4/4] arm64: mte: Optimize mte_assign_mem_tag_range() To: Mark Rutland References: <20210115120043.50023-1-vincenzo.frascino@arm.com> <20210115120043.50023-5-vincenzo.frascino@arm.com> <20210115154520.GD44111@C02TD0UTHF1T.local> From: Vincenzo Frascino Message-ID: <4b1a5cdf-e1bf-3a7e-593f-0089cedbbc03@arm.com> Date: Sat, 16 Jan 2021 14:22:08 +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: <20210115154520.GD44111@C02TD0UTHF1T.local> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210116_091825_056044_80CBDA90 X-CRM114-Status: GOOD ( 28.42 ) 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 Hi Mark, On 1/15/21 3:45 PM, Mark Rutland wrote: > On Fri, Jan 15, 2021 at 12:00:43PM +0000, Vincenzo Frascino wrote: >> mte_assign_mem_tag_range() is called on production KASAN HW hot >> paths. It makes sense to optimize it in an attempt to reduce the >> overhead. >> >> Optimize mte_assign_mem_tag_range() based on the indications provided at >> [1]. > > ... what exactly is the optimization? > > I /think/ you're just trying to have it inlined, but you should mention > that explicitly. > Good point, I will change it in the next version. I used "Optimize" as a continuation of the topic in the previous thread but you are right it is not immediately obvious. >> >> [1] https://lore.kernel.org/r/CAAeHK+wCO+J7D1_T89DG+jJrPLk3X9RsGFKxJGd0ZcUFjQT-9Q@mail.gmail.com/ >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Signed-off-by: Vincenzo Frascino >> --- >> arch/arm64/include/asm/mte.h | 26 +++++++++++++++++++++++++- >> arch/arm64/lib/mte.S | 15 --------------- >> 2 files changed, 25 insertions(+), 16 deletions(-) >> >> diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h >> index 1a715963d909..9730f2b07b79 100644 >> --- a/arch/arm64/include/asm/mte.h >> +++ b/arch/arm64/include/asm/mte.h >> @@ -49,7 +49,31 @@ long get_mte_ctrl(struct task_struct *task); >> int mte_ptrace_copy_tags(struct task_struct *child, long request, >> unsigned long addr, unsigned long data); >> >> -void mte_assign_mem_tag_range(void *addr, size_t size); >> +static inline void mte_assign_mem_tag_range(void *addr, size_t size) >> +{ >> + u64 _addr = (u64)addr; >> + u64 _end = _addr + size; >> + >> + /* >> + * This function must be invoked from an MTE enabled context. >> + * >> + * Note: The address must be non-NULL and MTE_GRANULE_SIZE aligned and >> + * size must be non-zero and MTE_GRANULE_SIZE aligned. >> + */ >> + do { >> + /* >> + * 'asm volatile' is required to prevent the compiler to move >> + * the statement outside of the loop. >> + */ >> + asm volatile(__MTE_PREAMBLE "stg %0, [%0]" >> + : >> + : "r" (_addr) >> + : "memory"); >> + >> + _addr += MTE_GRANULE_SIZE; >> + } while (_addr < _end); > > 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. >> +} > > What does the code generation look like for this, relative to the > assembly version? > The assembly looks like this: 390: 8b000022 add x2, x1, x0 394: aa0003e1 mov x1, x0 398: d9200821 stg x1, [x1] 39c: 91004021 add x1, x1, #0x10 3a0: eb01005f cmp x2, x1 3a4: 54ffffa8 b.hi 398 You can see the handcrafted one below. > Thanks, > Mark. > >> + >> >> #else /* CONFIG_ARM64_MTE */ >> >> diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S >> index 9e1a12e10053..a0a650451510 100644 >> --- a/arch/arm64/lib/mte.S >> +++ b/arch/arm64/lib/mte.S >> @@ -150,18 +150,3 @@ SYM_FUNC_START(mte_restore_page_tags) >> ret >> SYM_FUNC_END(mte_restore_page_tags) >> >> -/* >> - * Assign allocation tags for a region of memory based on the pointer tag >> - * x0 - source pointer >> - * x1 - size >> - * >> - * Note: The address must be non-NULL and MTE_GRANULE_SIZE aligned and >> - * size must be non-zero and MTE_GRANULE_SIZE aligned. >> - */ >> -SYM_FUNC_START(mte_assign_mem_tag_range) >> -1: stg x0, [x0] >> - add x0, x0, #MTE_GRANULE_SIZE >> - subs x1, x1, #MTE_GRANULE_SIZE >> - b.gt 1b >> - ret >> -SYM_FUNC_END(mte_assign_mem_tag_range) >> -- >> 2.30.0 >> -- Regards, Vincenzo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel