lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YYjkOkFmDG9IMPHu@hirez.programming.kicks-ass.net>
Date:   Mon, 8 Nov 2021 09:47:54 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Ricardo Neri <ricardo.neri-calderon@...ux.intel.com>
Cc:     "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
        Daniel Lezcano <daniel.lezcano@...aro.org>,
        linux-pm@...r.kernel.org, x86@...nel.org,
        linux-doc@...r.kernel.org, Len Brown <len.brown@...el.com>,
        Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
        Aubrey Li <aubrey.li@...ux.intel.com>,
        Amit Kucheria <amitk@...nel.org>,
        Andi Kleen <ak@...ux.intel.com>,
        Tim Chen <tim.c.chen@...ux.intel.com>,
        "Ravi V. Shankar" <ravi.v.shankar@...el.com>,
        Ricardo Neri <ricardo.neri@...el.com>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 3/7] thermal: intel: hfi: Minimally initialize the
 Hardware Feedback Interface

On Fri, Nov 05, 2021 at 06:33:08PM -0700, Ricardo Neri wrote:
> +static __init int hfi_parse_features(void)
> +{
> +	unsigned int nr_capabilities, reg;
> +

> +	/*
> +	 * If we are here we know that CPUID_HFI_LEAF exists. Parse the
> +	 * supported capabilities and the size of the HFI table.
> +	 */
> +	reg = cpuid_edx(CPUID_HFI_LEAF);
> +
> +	hfi_features.capabilities = reg & HFI_CAPABILITIES_MASK;
> +	if (!(hfi_features.capabilities & HFI_CAPABILITIES_PERFORMANCE)) {
> +		pr_err("Performance reporting not supported! Not using HFI\n");
> +		return -ENODEV;
> +	}
> +
> +	/* The number of 4KB pages required by the table */
> +	hfi_features.nr_table_pages = ((reg & CPUID_HFI_TABLE_SIZE_MASK) >>
> +				      CPUID_HFI_TABLE_SIZE_SHIFT) + 1;
> +

> +/* Hardware Feedback Interface Enumeration */
> +#define CPUID_HFI_LEAF			6
> +#define CPUID_HFI_CAP_MASK		0xff
> +#define CPUID_HFI_TABLE_SIZE_MASK	0x0f00
> +#define CPUID_HFI_TABLE_SIZE_SHIFT	8
> +#define CPUID_HFI_CPU_INDEX_MASK	0xffff0000

Also, *if* you're going to do something like this, then at least write
out the masks in full so you can easily see how they relate. The above
is crap.

> +#define CPUID_HFI_CPU_INDEX_SHIFT	16
> +
> +/* Hardware Feedback Interface Pointer */
> +#define HFI_PTR_VALID_BIT		BIT(0)
> +#define HFI_PTR_ADDR_SHIFT		12
> +
> +/* Hardware Feedback Interface Configuration */
> +#define HFI_CONFIG_ENABLE_BIT		BIT(0)
> +
> +/* Hardware Feedback Interface Capabilities */
> +#define HFI_CAPABILITIES_MASK		0xff
> +#define HFI_CAPABILITIES_NR		8
> +#define HFI_CAPABILITIES_PERFORMANCE	BIT(0)
> +#define HFI_CAPABILITIES_ENERGY_EFF	BIT(1)


So personally I prefer a bitfield union a-la cpuid10_eax, cpuid10_ebx
cpuid10_edx etc.. Barring that, the above can also be written more
concise using FIELD_GET() from bitfields.

union cpuid6_edx {
	struct {
		unsigned int capabilities :  8;
		unsigned int table_size   :  4;
		unsigned int __reserved   :  4;
		unsigned int cpu_index    : 16;
	};
	unsigned int full;
};

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ