From patchwork Fri Aug 26 17:15:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 74824 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp471352qga; Fri, 26 Aug 2016 10:19:02 -0700 (PDT) X-Received: by 10.98.11.86 with SMTP id t83mr7840658pfi.51.1472231942760; Fri, 26 Aug 2016 10:19:02 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id k69si22110997pfa.207.2016.08.26.10.19.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Aug 2016 10:19:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bdKlc-0007Nl-9k; Fri, 26 Aug 2016 17:18:08 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bdKlI-00074Q-IP for linux-arm-kernel@lists.infradead.org; Fri, 26 Aug 2016 17:17:51 +0000 Received: by mail-wm0-x236.google.com with SMTP id o80so1535770wme.1 for ; Fri, 26 Aug 2016 10:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2LPTUTkO7IVqbYzWKF2DnlN+Yt5xZmL1/wToqYfqvTA=; b=STk6HaayCFQ1+0IH9faxKSYRN7TrhhSdiACOyCiG7NaGAB7Ov9nlS5xYxltda50gdK 9HZDD+AU0BAz029Ce7JVIXpJ3PQsKna2QLgzVASjVUVUhFZ/W5p3UjgtF6pW9Zbr2a/E /zgYjqlPtH18evwy9c0hHK3yntwbAtSWEBIWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2LPTUTkO7IVqbYzWKF2DnlN+Yt5xZmL1/wToqYfqvTA=; b=ikBRI1rheFfhpWF8eEwXX+5/RpFBHpVLkyjmF1TeFBy7tq6DQH9+fbDuv2QBskoUWz DthUCFrjOHVgejPu3wzXBg7TfpP8T9cbk6uLSSbtpkcccMI6XFVozqmhWlfGaYsQroxe Z1iVOMLweiCdoiemM0Y//CGep4R+QSDqocB4KY83owYLCV31SQIeTvcBJ4tI56TN0B9P xfnh/yOkBN1jK11ReJQAHMlDpdyjiCs5SMgxyeAVXwnwlOEmFzIB5oU9hq7iH8jOYvlu CEgaTNwwevDdqMTeg1+7DsEc3cRZZ1HiLtsu1xbSjJ4YbeLY7vxd7nU6q/b1CB4zVPXe HguA== X-Gm-Message-State: AE9vXwMYG3nvhTwADOpoI3UHwKOl2t0qEXaotrO9AXLRiKydLUBNJPxKNtANXKDaI+6rPGGX X-Received: by 10.194.87.101 with SMTP id w5mr5842553wjz.94.1472231846265; Fri, 26 Aug 2016 10:17:26 -0700 (PDT) Received: from localhost.localdomain (dynrak234g-133-134-67-105.inwitelecom.net. [105.67.134.133]) by smtp.gmail.com with ESMTPSA id b130sm21504823wmg.19.2016.08.26.10.16.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Aug 2016 10:17:25 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, catalin.marinas@arm.com, suzuki.poulose@arm.com Subject: [RFC PATCH 2/3] arm64: cpufeature: constify arm64_ftr_regs array Date: Fri, 26 Aug 2016 18:15:41 +0100 Message-Id: <1472231742-13387-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472231742-13387-1-git-send-email-ard.biesheuvel@linaro.org> References: <1472231742-13387-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160826_101748_917250_759D6E34 X-CRM114-Status: GOOD ( 17.84 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:236 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Constify the arm64_ftr_regs array, by moving the mutable arm64_ftr_reg fields out of the array itself. This also streamlines the bsearch, since the entire array can be covered by fewer cachelines. Moving the payload out of the array also allows us to have special explicitly defined struct instance in case other code needs to refer to it directly. Note that this replaces the runtime sorting of the array with a runtime BUG() check whether the array is sorted correctly in the code. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 1 - arch/arm64/kernel/cpufeature.c | 45 +++++++++----------- 2 files changed, 19 insertions(+), 27 deletions(-) -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 7c0b7cff17df..8bb4f1527b26 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -72,7 +72,6 @@ struct arm64_ftr_bits { * @sys_val Safe value across the CPUs (system view) */ struct arm64_ftr_reg { - u32 sys_id; const char *name; u64 strict_mask; u64 sys_val; diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index eac76cb3a206..35a17487ffb9 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -265,14 +265,17 @@ static const struct arm64_ftr_bits ftr_aa64raz[] = { ARM64_FTR_END, }; -#define ARM64_FTR_REG(id, table) \ - { \ - .sys_id = id, \ +#define ARM64_FTR_REG(id, table) { \ + .sys_id = id, \ + .reg = &(struct arm64_ftr_reg){ \ .name = #id, \ .ftr_bits = &((table)[0]), \ - } + }} -static struct arm64_ftr_reg arm64_ftr_regs[] = { +static const struct __ftr_reg_entry { + u32 sys_id; + struct arm64_ftr_reg *reg; +} arm64_ftr_regs[] = { /* Op1 = 0, CRn = 0, CRm = 1 */ ARM64_FTR_REG(SYS_ID_PFR0_EL1, ftr_id_pfr0), @@ -324,7 +327,7 @@ static struct arm64_ftr_reg arm64_ftr_regs[] = { static int search_cmp_ftr_reg(const void *id, const void *regp) { - return (int)(unsigned long)id - (int)((const struct arm64_ftr_reg *)regp)->sys_id; + return (int)(unsigned long)id - (int)((const struct __ftr_reg_entry *)regp)->sys_id; } /* @@ -339,11 +342,14 @@ static int search_cmp_ftr_reg(const void *id, const void *regp) */ static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id) { - return bsearch((const void *)(unsigned long)sys_id, + const struct __ftr_reg_entry *ret; + + ret = bsearch((const void *)(unsigned long)sys_id, arm64_ftr_regs, ARRAY_SIZE(arm64_ftr_regs), sizeof(arm64_ftr_regs[0]), search_cmp_ftr_reg); + return ret->reg; } static u64 arm64_ftr_set_value(const struct arm64_ftr_bits *ftrp, s64 reg, @@ -378,27 +384,14 @@ static s64 arm64_ftr_safe_value(const struct arm64_ftr_bits *ftrp, s64 new, return ret; } -static int __init sort_cmp_ftr_regs(const void *a, const void *b) -{ - return ((const struct arm64_ftr_reg *)a)->sys_id - - ((const struct arm64_ftr_reg *)b)->sys_id; -} - -static void __init swap_ftr_regs(void *a, void *b, int size) -{ - struct arm64_ftr_reg tmp = *(struct arm64_ftr_reg *)a; - *(struct arm64_ftr_reg *)a = *(struct arm64_ftr_reg *)b; - *(struct arm64_ftr_reg *)b = tmp; -} - static void __init sort_ftr_regs(void) { - /* Keep the array sorted so that we can do the binary search */ - sort(arm64_ftr_regs, - ARRAY_SIZE(arm64_ftr_regs), - sizeof(arm64_ftr_regs[0]), - sort_cmp_ftr_regs, - swap_ftr_regs); + int i; + + /* Check that the array is sorted so that we can do the binary search */ + for (i = 1; i < ARRAY_SIZE(arm64_ftr_regs); i++) + if (arm64_ftr_regs[i].sys_id < arm64_ftr_regs[i - 1].sys_id) + BUG(); } /*