Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3982411pxb; Tue, 25 Jan 2022 00:37:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJQ9huX1UqSPbnXhdsCbETLeERvsEz5FP/gOsNnMpeRWOb9Eii9lyETezydUfMLwDs0kjm X-Received: by 2002:a05:6402:2994:: with SMTP id eq20mr19324970edb.281.1643099843911; Tue, 25 Jan 2022 00:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099843; cv=none; d=google.com; s=arc-20160816; b=A9LoBdwUfAjZZI62N8AcMjw+RIoL1eEqF0VKdX1um2K22RejkJg4KeZUQEkafzvx5Q LkN+h/rNMdz/0O0K4JyN9/7rzEMxibxDmkBBmHm2O874Squ3OVQsIeY/SQB95JjW5Cdv D2WFTmDsMfYKkWVCAA1ekEgC4LhvHr9VSn+rA+WgQRa+R5m8ylIcshl713VLEdBDcaFO 5umQAQf4jj5gE+u6YTWV7kVHl7ejCa7j6jiZusYlMGvQFIAfov3oDX7Dmy74dCZF861Q OA4tGgJPHsA9Owy5NF4LbV+jmHEh1ibqXM9m1MevfvACnx7X795Qw8uws9ufVjUrbxAL y6pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b8BjAZhV9k0nuPpOAQTjPOJPI03snYx9r32k/A4vVW0=; b=cKEG4/h96k5pPvqC8K0hJjA+jaGoUlOWaokFeUzoqT0Tv3ieL/tzIWUg/mIuRB2DLX TzLIFMQ658aNIOUQ6ZfE4D2S53Hed/0tS/O36VKG314EGBDQ10fTPP7aTrSvAXpRFNjf jAolw1IB5ne6veO6hmDtSGtyO9B8fXm8WZJ3thIzir79iLG6Q0iRWFDwXmthiC8jb0ue FLxPkawaJb3Slwah3TAwdL8++WsLyehg1sDQfIrU5DpqmOIgbxxOxv+ivvVLwo2RBRVC aQbmyv7BY6s2cYURMrPF47GXzkJCtez4eiEbrS0loEkRiQc9FiRsIl+Q+MwlAgl0CRbv kBzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UWrrlVXv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cr17si9752424ejc.951.2022.01.25.00.36.59; Tue, 25 Jan 2022 00:37:23 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UWrrlVXv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1314477AbiAYCvE (ORCPT + 99 others); Mon, 24 Jan 2022 21:51:04 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:55086 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445674AbiAXVEm (ORCPT ); Mon, 24 Jan 2022 16:04:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 32AFB60916; Mon, 24 Jan 2022 21:04:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DAA9C340E5; Mon, 24 Jan 2022 21:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058278; bh=0s33lcfy4P2jFzKILFRE4pEzm1ozOlLG3JQ6R6GELwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWrrlVXvWikm81fC6mbwm1uu1cbEGRaX5jJrz8HAge+Hm8hCNnzBx9J2eqEI7cpnv l4wL3y+mGSnFooDMrsuDeECbW7T5oy6LKzmOFXeAbpjfct7o4Plpoim4HQlSucLkA/ +OlJnlv5tr84gG5YTxzFpyOnoVjmUjGr4LD1tqgw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Reiji Watanabe , Catalin Marinas , Sasha Levin Subject: [PATCH 5.16 0238/1039] arm64: mte: DC {GVA,GZVA} shouldnt be used when DCZID_EL0.DZP == 1 Date: Mon, 24 Jan 2022 19:33:47 +0100 Message-Id: <20220124184133.321609644@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Reiji Watanabe [ Upstream commit 685e2564daa1493053fcd7f1dbed38b35ee2f3cb ] Currently, mte_set_mem_tag_range() and mte_zero_clear_page_tags() use DC {GVA,GZVA} unconditionally. But, they should make sure that DCZID_EL0.DZP, which indicates whether or not use of those instructions is prohibited, is zero when using those instructions. Use ST{G,ZG,Z2G} instead when DCZID_EL0.DZP == 1. Fixes: 013bb59dbb7c ("arm64: mte: handle tags zeroing at page allocation time") Fixes: 3d0cca0b02ac ("kasan: speed up mte_set_mem_tag_range") Signed-off-by: Reiji Watanabe Link: https://lore.kernel.org/r/20211206004736.1520989-3-reijiw@google.com Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- arch/arm64/include/asm/mte-kasan.h | 8 +++++--- arch/arm64/lib/mte.S | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h index 478b9bcf69ad1..e4704a403237e 100644 --- a/arch/arm64/include/asm/mte-kasan.h +++ b/arch/arm64/include/asm/mte-kasan.h @@ -84,10 +84,12 @@ static inline void __dc_gzva(u64 p) static inline void mte_set_mem_tag_range(void *addr, size_t size, u8 tag, bool init) { - u64 curr, mask, dczid_bs, end1, end2, end3; + u64 curr, mask, dczid, dczid_bs, dczid_dzp, end1, end2, end3; /* Read DC G(Z)VA block size from the system register. */ - dczid_bs = 4ul << (read_cpuid(DCZID_EL0) & 0xf); + dczid = read_cpuid(DCZID_EL0); + dczid_bs = 4ul << (dczid & 0xf); + dczid_dzp = (dczid >> 4) & 1; curr = (u64)__tag_set(addr, tag); mask = dczid_bs - 1; @@ -106,7 +108,7 @@ static inline void mte_set_mem_tag_range(void *addr, size_t size, u8 tag, */ #define SET_MEMTAG_RANGE(stg_post, dc_gva) \ do { \ - if (size >= 2 * dczid_bs) { \ + if (!dczid_dzp && size >= 2 * dczid_bs) {\ do { \ curr = stg_post(curr); \ } while (curr < end1); \ diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index e83643b3995f4..f531dcb95174a 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -43,17 +43,23 @@ SYM_FUNC_END(mte_clear_page_tags) * x0 - address to the beginning of the page */ SYM_FUNC_START(mte_zero_clear_page_tags) + and x0, x0, #(1 << MTE_TAG_SHIFT) - 1 // clear the tag mrs x1, dczid_el0 + tbnz x1, #4, 2f // Branch if DC GZVA is prohibited and w1, w1, #0xf mov x2, #4 lsl x1, x2, x1 - and x0, x0, #(1 << MTE_TAG_SHIFT) - 1 // clear the tag 1: dc gzva, x0 add x0, x0, x1 tst x0, #(PAGE_SIZE - 1) b.ne 1b ret + +2: stz2g x0, [x0], #(MTE_GRANULE_SIZE * 2) + tst x0, #(PAGE_SIZE - 1) + b.ne 2b + ret SYM_FUNC_END(mte_zero_clear_page_tags) /* -- 2.34.1