From patchwork Tue Jan 23 14:53:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C3AFC47258 for ; Tue, 23 Jan 2024 16:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Qgknm07jsIAYXLcjSUCdNPgiShxZqiwf2KE+a4a/4+8=; b=lRrJGBOLfj6OAs7BDmp5MYKgHl YUGvjM+kFws0f72QrTzedczcL60Q8pZWHDsfkOX3KH3l68SDxx7V4TumH5lXJl613TIfX50zgPq5V 3d3tYSpr1h9oLlWQMnK5ff2pvCVfVZY9mQ1PrxgIa7Q8xg4Y/X97JFGe4sLduCkvNTBbfcH/xGFJh tRbnqptujEZA7U37Ct7Uha+8TDg29Q//oVKDE2B2GJhg8Xh015IU8RBUPt1ec5spP0DMWZH/X8SYa Gj0D+B142lihLBGIeVw+AGrs47HIEusciCf8uSp6DCHw1LdjXTS+hI6TZRJXLRJCS+NS5YpQzW2Lg XIUIwhaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSJCV-00HAu6-0T; Tue, 23 Jan 2024 16:00:35 +0000 Received: from mail-wm1-f73.google.com ([209.85.128.73]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIBG-00Gtx6-18 for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:55:21 +0000 Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-40e6f3c5730so41432175e9.1 for ; Tue, 23 Jan 2024 06:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021708; x=1706626508; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Yp7yk/Cag4dYbspz2hNgNv5OLTeWFwTs8/hp9F7aYHY=; b=bf1xo1ZjXsDOw4ELoP0CcUqBWI3lHnwF2miJzhAiNU7pduagvDnAEDBiVNP4A8lSF+ OUDCQj+Br23ImO7ONga5f7tvAqwA80AoH+JY/eoBCHG4klgRrmpAt8kuB1ZC6pevWpGh Cd2s2x7+a/k99+/uMsS9b9QQQ16SzvEkXJZenzv3m4nHWjE3TaP0Bebj0bsv7/gblAN2 9OYHwmJSZfajXGAg/KpQiQNNGNlkv6GzO801p4Sh/602pYBwgXlLMfVrk0zd9P3toRoS MzDQYmA1eSZUJs3YCGjNLfF1CcHL23idDnbsPt7eja8ddY1H7SIU7pzG5ZhZIZbHIRjK xhIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021708; x=1706626508; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yp7yk/Cag4dYbspz2hNgNv5OLTeWFwTs8/hp9F7aYHY=; b=mxDoQ+RjSMxHo6azbhM4aHyIdouZV09DX/+dckmnCK+4c+LcU5gIrQuG0ERwewNYKO 4IxPc4+yR1CPQVv71fJNbbawwUPMdL0zd94R/glxo1rU/6ulNvfLeQRC+VCueQuxC5R3 JdaYH2AFywF6zAURdO6c6ec7iv/dxYvEe+TN/JoZnJFfO3GfOGZNauvfE+emxulUJm/t 2SJe7odNteCdzw6+ibztlcQCne7JWb+KpzOXTNSBDjiQLjDkC96kSG223Ih9Qn758gR/ jiyYIundgGiFV3t1iJRmjpo5IrruOnl+hocU6KBRMKyqFQhZ0PQGwFcPjtUsTWHRzobE aALw== X-Gm-Message-State: AOJu0YwN3HHElRSXWhbD8tIeOg03FLIxOOfy1qZay0AYCdWkMc2qrGwc W+lRPfODNKpbjqciHNu+jFalP+vNdHwpdhJliVUcF3DOXlJymbV629f7/TqeZV33NOxuLLNyyKm VHT0BzRHTKTWCqb+7ElJv9kZ9S4CDztBoM0W/Xq/irZEjPmo+HEo4DlN//CJUoEhfotC2ECS3u7 dbVTacJpTedEmrW2WZ7nVqqk43X1zcOBE2krQkYIWS X-Google-Smtp-Source: AGHT+IHFVV3f/zpQo6hbo7JSX//vYpTjJ6oNZh6Uae3un0U5ERIBnjMN7Lngk8jj8Wr8GGf3sJ1NM/Fl X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:b8e:b0:40e:bf34:46b8 with SMTP id fl14-20020a05600c0b8e00b0040ebf3446b8mr6413wmb.5.1706021708519; Tue, 23 Jan 2024 06:55:08 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:19 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1676; i=ardb@kernel.org; h=from:subject; bh=Tss2ysfkGPhsFex5mRbRurkjoHKWotU+L9jnR8SQpAE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pQePNW7IvTslyGZbpr4xlvcb88Y/v6Ru/rxz80nd6 VNZ7+z/dZSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJ3P3B8N8tnrmgrHVnwvkl 7u9Pz6sUXnCMVUve9pRLafxsp4wPr18w/GQ8c3bNV9+M5xKPcr7lXT395L3Q1XxRRqMwnheyRYs TDrEDAA== X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-72-ardb+git@google.com> Subject: [PATCH v7 20/50] arm64: Add helpers to probe local CPU for PAC and BTI support From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_065514_426603_74FE3A10 X-CRM114-Status: GOOD ( 12.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel Add some helpers that will be used by the early kernel mapping code to check feature support on the local CPU. This permits the early kernel mapping to be created with the right attributes, removing the need for tearing it down and recreating it. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 03c34242bfc7..e3edae1825f3 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -963,6 +963,38 @@ static inline bool kaslr_disabled_cmdline(void) u32 get_kvm_ipa_limit(void); void dump_cpu_features(void); +static inline bool cpu_has_bti(void) +{ + if (!IS_ENABLED(CONFIG_ARM64_BTI)) + return false; + + return arm64_apply_feature_override(read_cpuid(ID_AA64PFR1_EL1), + ID_AA64PFR1_EL1_BT_SHIFT, 4, + &id_aa64pfr1_override); +} + +static inline bool cpu_has_pac(void) +{ + u64 isar1, isar2; + + if (!IS_ENABLED(CONFIG_ARM64_PTR_AUTH)) + return false; + + isar1 = read_cpuid(ID_AA64ISAR1_EL1); + isar2 = read_cpuid(ID_AA64ISAR2_EL1); + + if (arm64_apply_feature_override(isar1, ID_AA64ISAR1_EL1_APA_SHIFT, 4, + &id_aa64isar1_override)) + return true; + + if (arm64_apply_feature_override(isar1, ID_AA64ISAR1_EL1_API_SHIFT, 4, + &id_aa64isar1_override)) + return true; + + return arm64_apply_feature_override(isar2, ID_AA64ISAR2_EL1_APA3_SHIFT, 4, + &id_aa64isar2_override); +} + #endif /* __ASSEMBLY__ */ #endif