Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4174028pxk; Tue, 8 Sep 2020 12:35:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYsBPoF/0y5Wj0XXeLcBIhf136oGTlxpmcPiNh/tdrkFPwlqaXcKAc6cNaYTqhsrs5K/TH X-Received: by 2002:a17:906:8399:: with SMTP id p25mr27167843ejx.243.1599593728958; Tue, 08 Sep 2020 12:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599593728; cv=none; d=google.com; s=arc-20160816; b=yQFtsCX7F0OWfde3Imm1GuKsCxYTCDvzLIk8WYkhUPqs3oPE7+PtArX7fCnNl3Ursj puLuPc/7QTKSHJ9qj5pjlAQ6imyhilHBCW8mG8WNJ8YzQfng8rAc5RT/OMj1cg3JrIHD qAxcK9jZ8PjpoqXWDc7jwHDw9cI2cpAwehth6Am+VlwspJqj45frQ6B8mQwIhBbueOih 0r9WWOCIJaDOsxbLV9y0ahDBQn0feROfLbC73a2BDkcjBE9qc80XL5mXtanZwNGRozmZ zglXIBHFfvRC8YoOcOFsd/RD/NcNNJ0SR3xJcCuWTIhPC4SDi84UoOhjk+g57/xrjcQs /swg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=CzeQ9DdrbquynWH3MRxVx2h7XesAlGjIoWK9Q/P/Yxw=; b=ZSe6TjaWGyCcfSDFUHW5waON9uSD2Y+XycJM0QyQCSueYyK41Nkvkl8UNlkgmo8zZd TpEUkpVzGloHZMCdACYltQKGsi/Gm1A71sesEzY4mII7A/tmKRDnBnW0A01azJizAysn qEU683r95/6BwG+uk+TVATFbImpbOOwUT0cFiJJHWTzs9S/CK8GTnUthFLElzU1Rdnx2 0IE638Aji+XJrn0j0uGna+fhpFK3pjhqtERDZ5oxVYLh5ySFJNhvt+m/bdxcw0VLRWLl +7T3yvna9/zkhwiIjE2ADIPIs602nyBFYipFWdbDXyKG2MAOIkJj7MhkYbw0T1GFCMzD 6ylQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si13598edr.143.2020.09.08.12.35.05; Tue, 08 Sep 2020 12:35:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732208AbgIHTdK (ORCPT + 99 others); Tue, 8 Sep 2020 15:33:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:47724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731014AbgIHP6F (ORCPT ); Tue, 8 Sep 2020 11:58:05 -0400 Received: from gaia (unknown [46.69.195.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D6EA92463B; Tue, 8 Sep 2020 15:39:13 +0000 (UTC) Date: Tue, 8 Sep 2020 16:39:11 +0100 From: Catalin Marinas To: Andrey Konovalov Cc: Vincenzo Frascino , Dmitry Vyukov , kasan-dev , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , Linux ARM , Linux Memory Management List , LKML Subject: Re: [PATCH 24/35] arm64: mte: Switch GCR_EL1 in kernel entry and exit Message-ID: <20200908153910.GK25591@gaia> References: <20200827103819.GE29264@gaia> <8affcfbe-b8b4-0914-1651-368f669ddf85@arm.com> <20200827121604.GL29264@gaia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 08, 2020 at 04:02:06PM +0200, Andrey Konovalov wrote: > On Thu, Aug 27, 2020 at 2:16 PM Catalin Marinas wrote: > > On Thu, Aug 27, 2020 at 11:56:49AM +0100, Vincenzo Frascino wrote: > > > On 8/27/20 11:38 AM, Catalin Marinas wrote: > > > > On Fri, Aug 14, 2020 at 07:27:06PM +0200, Andrey Konovalov wrote: > > > >> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c > > > >> index 7717ea9bc2a7..cfac7d02f032 100644 > > > >> --- a/arch/arm64/kernel/mte.c > > > >> +++ b/arch/arm64/kernel/mte.c > > > >> @@ -18,10 +18,14 @@ > > > >> > > > >> #include > > > >> #include > > > >> +#include > > > >> +#include > > > >> #include > > > >> #include > > > >> #include > > > >> > > > >> +u64 gcr_kernel_excl __read_mostly; > > > > > > > > Could we make this __ro_after_init? > > > > > > Yes, it makes sense, it should be updated only once through mte_init_tags(). > > > > > > Something to consider though here is that this might not be the right approach > > > if in future we want to add stack tagging. In such a case we need to know the > > > kernel exclude mask before any C code is executed. Initializing the mask via > > > mte_init_tags() it is too late. > > > > It depends on how stack tagging ends up in the kernel, whether it uses > > ADDG/SUBG or not. If it's only IRG, I think it can cope with changing > > the GCR_EL1.Excl in the middle of a function. > > > > > I was thinking to add a compilation define instead of having gcr_kernel_excl in > > > place. This might not work if the kernel excl mask is meant to change during the > > > execution. > > > > A macro with the default value works for me. That's what it basically is > > currently, only that it ends up in a variable. > > Some thoughts on the topic: gcr_kernel_excl is currently initialized > in mte_init_tags() and depends on the max_tag value dynamically > provided to it, so it's not something that can be expressed with a > define. In the case of KASAN the max_tag value is static, but if we > rely on that we make core MTE code depend on KASAN, which doesn't seem > right from the design perspective. The design is debatable. If we want MTE to run on production devices, we either (1) optimise out some bits of KASAN (configurable) or (2) we decouple MTE and KASAN completely and add new callbacks in the core code (slab allocator etc.) specific to MTE. My first choice is (1), unless there is a strong technical argument why it is not possible. -- Catalin