Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1291671pxb; Fri, 22 Jan 2021 11:41:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXaGwAW3ZNyuF0jiPQQoOHIWFOQSbQcqEGRhJMfz1FGxr7Y+oZ8uHYwVAGeCuA167oZvql X-Received: by 2002:a17:906:c5b:: with SMTP id t27mr4136516ejf.129.1611344365040; Fri, 22 Jan 2021 11:39:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611344365; cv=none; d=google.com; s=arc-20160816; b=At15xNXHxTCPFmNjF4EjnzqB+jW5jczN1PvG6Ph8NL1XDk8nEOXDGD1RjTiDpDyZft mbBxUruiEBGJc6rq1Jgd51x8yNOVHK1U0byyGwrhxyvElysUpXDiGNZZ2wPgKe/DnQz0 MRPiy/nXLxSjrm0RGVJTSOhwP31DbmZhIcTWegt0wkXl2mggg95YmtheCNOltmX1ZHqP eyDpB2h6gQ0+2sFuOdjlpZbRv84MYwewfwU2UDlmjzJ2S1ZU2wtV6A9nxP8HzIg1a1Bb K6YtBNuwFlBLV7G7AXSoFTzQINsX2FIDzi1RUyiXCCBfOWHJdWdpHwB/zQKGaedGYg9q us2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=a1RHPUpvUT+j6d7cnKDOTJlMDKpD+NfqxNsr5OZERcQ=; b=I/FfJAxne7jaQPdiWSXdviJcFqHtED8xCixZdoFzfm2LU2rl4ROAO0Wzso1AlVrqSM /5cd/Upt7bIFjLDA/cSkkqxQ3cTswzzwQ3aJFYivo8Z9wHNt9BnWlQznzh7iXcC4ggEQ T5XDfjyNX3/L1c6z212qpkewVo1crYoh9ZJLYRszvsWu/KbkIZRMi/aFeaNb5loG4VBj fEdjwvQ7orOM+Y7WbUEixpYJAJtsBeDbC8VoGjQ3oaC0dd8l/g6HQaJqZF6Mnhn/R5bQ PsQXAjUDeb9z5oX4wZe9Wkd8pazbvk1fJ+iLPK4+kCRGP4qOCXQ58td70p/SadsCNuqM oiYw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r14si3836860edw.540.2021.01.22.11.39.01; Fri, 22 Jan 2021 11:39:25 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730588AbhAVT0N (ORCPT + 99 others); Fri, 22 Jan 2021 14:26:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:39002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729531AbhAVSm0 (ORCPT ); Fri, 22 Jan 2021 13:42:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BBCB82376F; Fri, 22 Jan 2021 18:41:42 +0000 (UTC) Date: Fri, 22 Jan 2021 18:41:40 +0000 From: Catalin Marinas To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , David Brazdil , Alexandru Elisei , Ard Biesheuvel , Jing Zhang , Ajay Patil , Prasad Sodagudi , Srinivas Ramana , James Morse , Julien Thierry , Suzuki K Poulose , kernel-team@android.com Subject: Re: [PATCH v4 09/21] arm64: cpufeature: Add global feature override facility Message-ID: <20210122184139.GG8567@gaia> References: <20210118094533.2874082-1-maz@kernel.org> <20210118094533.2874082-10-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210118094533.2874082-10-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 09:45:21AM +0000, Marc Zyngier wrote: > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 9a555809b89c..465d2cb63bfc 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -75,6 +75,8 @@ struct arm64_ftr_reg { > u64 sys_val; > u64 user_val; > const struct arm64_ftr_bits *ftr_bits; > + u64 *override_val; > + u64 *override_mask; > }; > > extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0; > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index e99eddec0a46..aaa075c6f029 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -544,13 +544,17 @@ static const struct arm64_ftr_bits ftr_raz[] = { > ARM64_FTR_END, > }; > > -#define ARM64_FTR_REG(id, table) { \ > - .sys_id = id, \ > - .reg = &(struct arm64_ftr_reg){ \ > - .name = #id, \ > - .ftr_bits = &((table)[0]), \ > +#define ARM64_FTR_REG_OVERRIDE(id, table, v, m) { \ > + .sys_id = id, \ > + .reg = &(struct arm64_ftr_reg){ \ > + .name = #id, \ > + .ftr_bits = &((table)[0]), \ > + .override_val = v, \ > + .override_mask = m, \ > }} > > +#define ARM64_FTR_REG(id, table) ARM64_FTR_REG_OVERRIDE(id, table, NULL, NULL) > + > static const struct __ftr_reg_entry { > u32 sys_id; > struct arm64_ftr_reg *reg; > @@ -760,6 +764,7 @@ static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new) > u64 strict_mask = ~0x0ULL; > u64 user_mask = 0; > u64 valid_mask = 0; > + u64 override_val = 0, override_mask = 0; > > const struct arm64_ftr_bits *ftrp; > struct arm64_ftr_reg *reg = get_arm64_ftr_reg(sys_reg); > @@ -767,9 +772,38 @@ static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new) > if (!reg) > return; > > + if (reg->override_mask && reg->override_val) { > + override_mask = *reg->override_mask; > + override_val = *reg->override_val; > + } > + > for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) { > u64 ftr_mask = arm64_ftr_mask(ftrp); > s64 ftr_new = arm64_ftr_value(ftrp, new); > + s64 ftr_ovr = arm64_ftr_value(ftrp, override_val); > + > + if ((ftr_mask & override_mask) == ftr_mask) { > + s64 tmp = arm64_ftr_safe_value(ftrp, ftr_ovr, ftr_new); > + char *str = NULL; > + > + if (ftr_ovr != tmp) { > + /* Unsafe, remove the override */ > + *reg->override_mask &= ~ftr_mask; > + *reg->override_val &= ~ftr_mask; Do we need such clearing here? I don't think that's ever called again for this feature/reg. > + tmp = ftr_ovr; > + str = "ignoring override"; > + } else if (ftr_new != tmp) { > + /* Override was valid */ > + ftr_new = tmp; > + str = "forced"; > + } > + > + if (str) > + pr_warn("%s[%d:%d]: %s to %llx\n", > + reg->name, > + ftrp->shift + ftrp->width - 1, > + ftrp->shift, str, tmp); > + } > > val = arm64_ftr_set_value(ftrp, val, ftr_new); I wonder whether we could call, after init_cpu_ftr_reg(), a new function similar to update_cpu_ftr_reg() that takes a mask and value and leave init_cpu_ftr_reg() unchanged. The only advantage would be if we can get rid of the reg->override* fields. Anyway, I need to read the rest of the series to see whether it's possible. Otherwise this patch looks fine. -- Catalin