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.4 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, 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 3000CC433E0 for ; Tue, 19 Jan 2021 15:46:34 +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 E21132070C for ; Tue, 19 Jan 2021 15:46:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E21132070C 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=OjrgjpJVTzYApSXGaLImmTxK01SIWEHs/NTgMJoIqEA=; b=k8PpownhBlPuDgI7QwXsvEoD7 nQ5NI0Gh+qE1KjoV5CIeMrJELqJelFKvpRdKaCEwqfni9939QczS3f7/W5ZkLEpLIYYRTMkwFwXc9 29IiGqF2ayv7/853W2wiLvt/PHciu9QHRpGbYl7f0kM0zTjkJq4vmN+n7fycaq13CidUYVG8CVE9P 6li5H/AcgleoiyNhbLzBjPBkd6JYfO+w7m96XjLoXWnWDDFTjXdb1C93swCKYaD5ODMWvP0MnpcNt AGnDCfHV/H3K9Yjvbs4C2QgWbRtfgbjwBrlZJ1uMcLig7jljtQrMPLFmmPQ4QtbLqT2hm5zSaYwbI AtUwFQBqQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1tC0-0004eV-Ff; Tue, 19 Jan 2021 15:45:16 +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 1l1tBx-0004e8-FU for linux-arm-kernel@lists.infradead.org; Tue, 19 Jan 2021 15:45:14 +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 42A7BD6E; Tue, 19 Jan 2021 07:45:10 -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 B62A03F66E; Tue, 19 Jan 2021 07:45:07 -0800 (PST) Subject: Re: [PATCH v4 5/5] arm64: mte: Inline mte_assign_mem_tag_range() To: Catalin Marinas References: <20210118183033.41764-1-vincenzo.frascino@arm.com> <20210118183033.41764-6-vincenzo.frascino@arm.com> <20210119144459.GE17369@gaia> From: Vincenzo Frascino Message-ID: <1bb4355f-4341-21a7-0a53-a4a27840adee@arm.com> Date: Tue, 19 Jan 2021 15:48:56 +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: <20210119144459.GE17369@gaia> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210119_104513_607305_E4F24D2B X-CRM114-Status: GOOD ( 27.79 ) 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 , Andrey Konovalov , Evgenii Stepanov , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Alexander Potapenko , linux-arm-kernel@lists.infradead.org, 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 Catalin, On 1/19/21 2:45 PM, Catalin Marinas wrote: > On Mon, Jan 18, 2021 at 06:30:33PM +0000, Vincenzo Frascino wrote: >> mte_assign_mem_tag_range() is called on production KASAN HW hot >> paths. It makes sense to inline it in an attempt to reduce the >> overhead. >> >> Inline mte_assign_mem_tag_range() based on the indications provided at >> [1]. >> >> [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 237bb2f7309d..1a6fd53f82c3 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); >> +} > > While I'm ok with moving this function to C, I don't think it solves the > inlining in the kasan code. The only interface we have to kasan is via > mte_{set,get}_mem_tag_range(), so the above function doesn't need to > live in a header. > > If you do want inlining all the way to the kasan code, we should > probably move the mte_{set,get}_mem_tag_range() functions to the header > as well (and ideally backed by some numbers to show that it matters). > > Moving it to mte.c also gives us more control on how it's called (we > have the WARN_ONs in place in the callers). > Based on the thread [1] this patch contains only an intermediate step to allow KASAN to call directly mte_assign_mem_tag_range() in future. At that point I think that mte_set_mem_tag_range() can be removed. If you agree, I would live the things like this to give to Andrey a chance to execute on the original plan with a separate series. I agree though that this change alone does not bring huge benefits but regressions neither. If you want I can add something to the commit message in the next version to make this more explicit. Let me know how do you want me to proceed. -- Regards, Vincenzo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel