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=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 80722C33CB1 for ; Wed, 15 Jan 2020 16:02:08 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4F291222C3 for ; Wed, 15 Jan 2020 16:02:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Phw11uNC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F291222C3 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+infradead-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=bombadil.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=3uf5b1olPJ5LKePwDe0E4lv2bb/aCNmfd3Ha4W9ZdY8=; b=Phw11uNComw4mk xBPV7sO8Zx95Hb6f9bvB2MSTG76SH5ifVs869YPrRGdKaeu+XldiNcVznRMG5kDUip4jDnmsOdYz4 oxbM14w+3ZY/d2hjBUhrmKvzk47Hl6rBeHV1PtRzj6UWz+Qqel8qiAY8lJVLIAO3fleQO72DOY9v5 5mQnt6tMr1YpTDcoki1TTjyGJ0mZ0NMYOGoeu4LRyiXZIifau5TsOcSodsjOLwVXTqqZSvAg7AATf wKiChap71gDHkVV/eToerHX+qiAUSTH4Jr5+rUtk5lT7haSi7okgnyRShKhG/Z5jZZipRSWzhY78u bIM3QLPqpnqKfAIPAkEQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1irl7P-0000X5-TE; Wed, 15 Jan 2020 16:02:07 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1irl7H-0000WE-Iv for linux-arm-kernel@lists.infradead.org; Wed, 15 Jan 2020 16:02:05 +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 C2463328; Wed, 15 Jan 2020 08:01:58 -0800 (PST) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.197.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 07B8B3F718; Wed, 15 Jan 2020 08:01:56 -0800 (PST) Date: Wed, 15 Jan 2020 16:01:54 +0000 From: Catalin Marinas To: Suzuki Kuruppassery Poulose Subject: Re: [PATCH v3 01/16] arm64: cpufeature: add pointer auth meta-capabilities Message-ID: <20200115160154.GE3429@arrakis.emea.arm.com> References: <1576486038-9899-1-git-send-email-amit.kachhap@arm.com> <1576486038-9899-2-git-send-email-amit.kachhap@arm.com> <20200115122657.GB3429@arrakis.emea.arm.com> <4aac989f-3d9e-53e0-e2c9-1aa163e6baa0@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4aac989f-3d9e-53e0-e2c9-1aa163e6baa0@arm.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-20200115_080159_710053_5DFA083D X-CRM114-Status: GOOD ( 22.31 ) 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: Mark Rutland , Kees Cook , Ard Biesheuvel , Richard Henderson , Kristina Martsenko , James Morse , Ramana Radhakrishnan , Amit Kachhap , Mark Brown , Vincenzo Frascino , Will Deacon , Dave P Martin , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jan 15, 2020 at 01:52:24PM +0000, Suzuki K Poulose wrote: > On 15/01/2020 12:26, Catalin Marinas wrote: > > On Mon, Dec 16, 2019 at 02:17:03PM +0530, Amit Daniel Kachhap wrote: > > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > > index 04cf64e..cf42c46 100644 > > > --- a/arch/arm64/kernel/cpufeature.c > > > +++ b/arch/arm64/kernel/cpufeature.c > > > @@ -1249,6 +1249,20 @@ static void cpu_enable_address_auth(struct arm64_cpu_capabilities const *cap) > > > sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | > > > SCTLR_ELx_ENDA | SCTLR_ELx_ENDB); > > > } > > > + > > > +static bool has_address_auth(const struct arm64_cpu_capabilities *entry, > > > + int __unused) > > > +{ > > > + return cpus_have_const_cap(ARM64_HAS_ADDRESS_AUTH_ARCH) || > > > + cpus_have_const_cap(ARM64_HAS_ADDRESS_AUTH_IMP_DEF); > > > +} > > > + > > > +static bool has_generic_auth(const struct arm64_cpu_capabilities *entry, > > > + int __unused) > > > +{ > > > + return cpus_have_const_cap(ARM64_HAS_GENERIC_AUTH_ARCH) || > > > + cpus_have_const_cap(ARM64_HAS_GENERIC_AUTH_IMP_DEF); > > > +} > > > > Do these rely on the order in which the entries are listed in the > > arm64_features[] array? It looks like we do the same for PAN_NOT_UAO but > > that's pretty fragile. > > Yes, it surely depends on the order in which they are listed. > > > I'd prefer if we invoked the > > cpu_hwcaps_ptrs[ARM64_HAS_ADDRESS_AUTH]->matches() directly here, maybe > > Yes, calling the matches(cap, SYSTEM_SCOPE), that should work and is much > better. > > > hidden behind a helper (I couldn't find one at a quick look). > > > > There are no helpers for this operation to do it on a SYSTEM_SCOPE > and this is only needed for caps dependent on the other caps. > > May be we could hide the conversion of the number to "cap" as: > > static inline struct arm64_cpu_capabilities *cpu_cap_from_number(int n) > { > if (n < ARM64_NCAPS) > return cpu_hwcaps_ptr[n]; > return NULL; > } > > And use this for "this_cpu_has_cap()" too. I'm not bothered about the cpu_cap_from_number() part. I was actually thinking of something like the diff below: -----------8<------------------------- diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 2595c2886d3f..2ea4c84fcc8a 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2008,6 +2008,18 @@ bool this_cpu_has_cap(unsigned int n) return false; } +static bool system_has_cap(unsigned int n) +{ + if (n < ARM64_NCAPS) { + const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[n]; + + if (cap) + return cap->matches(cap, SCOPE_SYSTEM); + } + + return false; +} + void cpu_set_feature(unsigned int num) { WARN_ON(num >= MAX_CPU_FEATURES); @@ -2081,7 +2093,7 @@ void __init setup_cpu_features(void) static bool __maybe_unused cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused) { - return (cpus_have_const_cap(ARM64_HAS_PAN) && !cpus_have_const_cap(ARM64_HAS_UAO)); + return system_has_cap(ARM64_HAS_PAN) && !system_has_cap(ARM64_HAS_UAO); } static void __maybe_unused cpu_enable_cnp(struct arm64_cpu_capabilities const *cap) -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel