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.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 0E706C433DF for ; Mon, 29 Jun 2020 10:39:33 +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 C7E7D23770 for ; Mon, 29 Jun 2020 10:39:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LFPQMp53" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7E7D23770 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-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=blu0xi/+OJWFMLcBcBJVE3V5neXr6PIYKDZqLWV2ftg=; b=LFPQMp53Vs1Ikvtx+58sM2EXS I3jRyukh0zUD2kEjTV/0HKsgYekfdaOIWXx3cUecQLy1R6SRMUyZhLfiPwkCH/2s+0vFWJ86EK3+r 9vr8iIgBlYWLJHf1nclZH8Tk02gPi8FzfD8qtPWaR3O9byuplFmSDNeSEgffslbyBqB+d8Mp3+/cq 3dPDKIG3s5DvU2YZPjt505dyXON22is2RqpNaV6U4qkZiQjwNlmQYmNIfAibGlzp9xTgdK5MfQgy+ 7QjhVXT7h8MnC/6yod2g5xzXy/63nPX95QMTnFFVkQyKlNc0hTkoWDRI7+XWme+d3MIk2oF9dEyLz Y2jTQ7wWA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jprAq-0000Da-8s; Mon, 29 Jun 2020 10:38:04 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jprAo-0000DA-6G for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 10:38:03 +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 E64061042; Mon, 29 Jun 2020 03:37:58 -0700 (PDT) Received: from [10.37.12.90] (unknown [10.37.12.90]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4DCCC3F71E; Mon, 29 Jun 2020 03:37:57 -0700 (PDT) Subject: Re: [PATCH] arm64/cpufeature: Validate feature bits spacing in arm64_ftr_regs[] To: anshuman.khandual@arm.com, linux-arm-kernel@lists.infradead.org References: <1592274331-19006-1-git-send-email-anshuman.khandual@arm.com> From: Suzuki K Poulose Message-ID: Date: Mon, 29 Jun 2020 11:42:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1592274331-19006-1-git-send-email-anshuman.khandual@arm.com> Content-Language: en-US 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@arm.com, catalin.marinas@arm.com, broonie@kernel.org, will@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 06/16/2020 03:25 AM, Anshuman Khandual wrote: > arm64_feature_bits for a register in arm64_ftr_regs[] are in a descending > order as per their shift values. Validate that these features bits are > defined correctly and do not overlap with each other. This check protects > against any inadvertent erroneous changes to the register definitions. > > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Suzuki K Poulose > Cc: Mark Brown > Cc: Mark Rutland > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Anshuman Khandual > --- > Applies on 5.8-rc1. > > arch/arm64/kernel/cpufeature.c | 45 +++++++++++++++++++++++++++++++--- > 1 file changed, 42 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 4ae41670c2e6..2270eda9a7fb 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -697,11 +697,50 @@ static s64 arm64_ftr_safe_value(const struct arm64_ftr_bits *ftrp, s64 new, > > static void __init sort_ftr_regs(void) > { > - int i; > + const struct arm64_ftr_reg *ftr_reg; > + const struct arm64_ftr_bits *ftr_bits; > + unsigned int i, j, width, shift, prev_shift; > + > + for (i = 0; i < ARRAY_SIZE(arm64_ftr_regs); i++) { > + /* > + * Features here must be sorted in descending order with respect > + * to their shift values and should not overlap with each other. > + */ > + ftr_reg = arm64_ftr_regs[i].reg; > + for (ftr_bits = ftr_reg->ftr_bits, j = 0; > + ftr_bits->width != 0; ftr_bits++, j++) { > + if (WARN_ON(ftr_bits->shift + ftr_bits->width > 64)) > + pr_err("%s has invalid feature at shift %d\n", > + ftr_reg->name, ftr_bits->shift); nit: WARN((ftr_bits->shift + ftr_bits->width) > 64, "%s......);? > + > + /* > + * Skip the first feature. There is nothing to > + * compare against for now. > + */ > + if (j == 0) > + continue; > + > + prev_shift = ftr_reg->ftr_bits[j - 1].shift; > + width = ftr_reg->ftr_bits[j].width; > + shift = ftr_reg->ftr_bits[j].shift; > + if (WARN_ON(prev_shift < shift + width)) > + pr_err("%s has feature overlap at shift %d\n", > + ftr_reg->name, ftr_bits->shift); same as above ? > + } > > - /* Check that the array is sorted so that we can do the binary search */ > - for (i = 1; i < ARRAY_SIZE(arm64_ftr_regs); i++) > + /* > + * Skip the first register. There is nothing to > + * compare against for now. > + */ > + if (i == 0) > + continue; You are starting at 1 already, so you may skip this check. > + /* > + * Registers here must be sorted in ascending order with respect > + * to sys_id for subsequent binary search in get_arm64_ftr_reg() > + * to work correctly. > + */ > BUG_ON(arm64_ftr_regs[i].sys_id < arm64_ftr_regs[i - 1].sys_id); > + } > } > > /* Otherwise looks good to me. Suzuki _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel