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=-8.2 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,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 9392FC43461 for ; Thu, 17 Sep 2020 15:00:59 +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 12A61206DB for ; Thu, 17 Sep 2020 15:00:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Zw9fQK/E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12A61206DB Authentication-Results: mail.kernel.org; dmarc=none (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=DoZK9d0YDVQKtDX2mlW8Ao2p18wPRkgeAM3cBYZq2Gs=; b=Zw9fQK/EFQY7BQnxJfbnSlOqv BKx90yWP0odw0VMPmhlrm6985g8tn+mHcENxvl3dZCxIewxfsjI6OwnPLjzMRbHnOcUTFq6iJnBSr 7hACTXixDCieE7y+A4pxikgoK99MH+mxV76qVkp2RUtqLyTgZcswB58UbxiotT9z07U90sBdHdXSi /Kh0GOCXa8b/2dJ8m9S+TqrZCkRHyNUfZEiNCzlHKVOCLklJugsED4eQ9AaIIfgMq8Q7cjv/H91wA G/+kc8SGat9sROEygpqL68K4XF2M7j+2u2y62gEtFmV6Ma2LYKBZ4PNIgKNDeItpLvReOH0BZZ/jq 9kT5QEX6w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIvNY-0007BN-UP; Thu, 17 Sep 2020 14:59:20 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIvNV-0007AX-O8 for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 14:59:18 +0000 Received: from gaia (unknown [31.124.44.166]) (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 61ED1206E6; Thu, 17 Sep 2020 14:59:13 +0000 (UTC) Date: Thu, 17 Sep 2020 15:59:10 +0100 From: Catalin Marinas To: Andrey Konovalov Subject: Re: [PATCH v2 24/37] arm64: mte: Add in-kernel tag fault handler Message-ID: <20200917145910.GD10662@gaia> References: <7866d9e6f11f12f1bad42c895bf4947addba71c2.1600204505.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7866d9e6f11f12f1bad42c895bf4947addba71c2.1600204505.git.andreyknvl@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_105917_867657_1210AD03 X-CRM114-Status: GOOD ( 16.82 ) 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: linux-arm-kernel@lists.infradead.org, Marco Elver , Elena Petrova , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , 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 Tue, Sep 15, 2020 at 11:16:06PM +0200, Andrey Konovalov wrote: > static int do_tag_check_fault(unsigned long addr, unsigned int esr, > struct pt_regs *regs) > { > - do_bad_area(addr, esr, regs); > + /* The tag check fault (TCF) is per TTBR */ > + if (is_ttbr0_addr(addr)) > + do_bad_area(addr, esr, regs); > + else > + do_tag_recovery(addr, esr, regs); > + > return 0; > } I had forgotten the details here. The TCF mode is per EL, so TCF0 affects EL0, TCF affects EL1 irrespective of which TTBR is used. Now, we know the kernel accesses TTBR0 usually with LDTR/STTR instructions if UAO is available (soon to get rid of), so these would act as EL0 accesses using TCF0. However, we have the futex.h code which uses exclusives and they'd be executed as EL1, so you can potentially get a tag check fault for such uaccess even if the user disabled it in TCF0. The solution here I think is for uaccess_enable() to set PSTATE.TCO, restore it in uaccess_disable(). We get away with not toggling PSTATE.TCO in the user MTE patches since the TCF is always 0 for the kernel. The do_tag_check_fault() above is still correct, apart from the comment which needs a better explanation on why we do a is_ttbr0_addr() check. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 82129C43461 for ; Thu, 17 Sep 2020 14:59:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C434E206DC for ; Thu, 17 Sep 2020 14:59:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C434E206DC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EFF6A6B0003; Thu, 17 Sep 2020 10:59:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EAF7D6B0037; Thu, 17 Sep 2020 10:59:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC6046B0055; Thu, 17 Sep 2020 10:59:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id C73626B0003 for ; Thu, 17 Sep 2020 10:59:17 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 760E68249980 for ; Thu, 17 Sep 2020 14:59:17 +0000 (UTC) X-FDA: 77272861554.08.screw54_3b0634527123 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 458BA1819E890 for ; Thu, 17 Sep 2020 14:59:17 +0000 (UTC) X-HE-Tag: screw54_3b0634527123 X-Filterd-Recvd-Size: 2912 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Sep 2020 14:59:16 +0000 (UTC) Received: from gaia (unknown [31.124.44.166]) (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 61ED1206E6; Thu, 17 Sep 2020 14:59:13 +0000 (UTC) Date: Thu, 17 Sep 2020 15:59:10 +0100 From: Catalin Marinas To: Andrey Konovalov Cc: Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 24/37] arm64: mte: Add in-kernel tag fault handler Message-ID: <20200917145910.GD10662@gaia> References: <7866d9e6f11f12f1bad42c895bf4947addba71c2.1600204505.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7866d9e6f11f12f1bad42c895bf4947addba71c2.1600204505.git.andreyknvl@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 458BA1819E890 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 15, 2020 at 11:16:06PM +0200, Andrey Konovalov wrote: > static int do_tag_check_fault(unsigned long addr, unsigned int esr, > struct pt_regs *regs) > { > - do_bad_area(addr, esr, regs); > + /* The tag check fault (TCF) is per TTBR */ > + if (is_ttbr0_addr(addr)) > + do_bad_area(addr, esr, regs); > + else > + do_tag_recovery(addr, esr, regs); > + > return 0; > } I had forgotten the details here. The TCF mode is per EL, so TCF0 affects EL0, TCF affects EL1 irrespective of which TTBR is used. Now, we know the kernel accesses TTBR0 usually with LDTR/STTR instructions if UAO is available (soon to get rid of), so these would act as EL0 accesses using TCF0. However, we have the futex.h code which uses exclusives and they'd be executed as EL1, so you can potentially get a tag check fault for such uaccess even if the user disabled it in TCF0. The solution here I think is for uaccess_enable() to set PSTATE.TCO, restore it in uaccess_disable(). We get away with not toggling PSTATE.TCO in the user MTE patches since the TCF is always 0 for the kernel. The do_tag_check_fault() above is still correct, apart from the comment which needs a better explanation on why we do a is_ttbr0_addr() check. -- Catalin