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] [day] [month] [year] [list]
Message-ID: <Yvsq3CPf3+ZjYyat@kroah.com>
Date:   Tue, 16 Aug 2022 07:27:56 +0200
From:   Greg KH <greg@...ah.com>
To:     Jiaxun Yang <jiaxun.yang@...goat.com>
Cc:     linux-mips@...r.kernel.org, linux-kernel@...r.kernel.org,
        tsbogend@...ha.franken.de, linux-api@...r.kernel.org,
        f.fainelli@...il.com
Subject: Re: [PATCH v3] MIPS: Expose prid and globalnumber to sysfs

On Mon, Aug 15, 2022 at 04:56:58PM +0000, Jiaxun Yang wrote:
> Some application would like to know precise model and rev of processor
> to do errata workaround or optimization.
> 
> Expose them in sysfs as:
> /sys/devices/system/cpu/cpuX/regs/identification/prid
> /sys/devices/system/cpu/cpuX/regs/identification/globalnumber
> 
> Reusing AArch64 CPU registers directory.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@...goat.com>
> ---
> v2: Drop static qualifier for kobj (gregkh)
> v3: Use kzalloc to allocate struct cpuregs.
>     note: When Greg mentioned about static I was thinking about
>     static qualifier of percpu variable. After reading documents
>     again it turns out kobjs should be allocated at runtime. Arm64's
>     cpuinfo kobj is also on a percpu variable... I guess that was a
>     intentional use?
> ---
>  .../ABI/testing/sysfs-devices-system-cpu      |  11 ++
>  arch/mips/kernel/topology.c                   | 103 ++++++++++++++++++
>  2 files changed, 114 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
> index 5bf61881f012..adf855e7bb9b 100644
> --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
> +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
> @@ -512,6 +512,17 @@ Description:	information about CPUs heterogeneity.
>  
>  		cpu_capacity: capacity of cpuX.
>  
> +What:		/sys/devices/system/cpu/cpuX/regs/
> +		/sys/devices/system/cpu/cpuX/regs/identification/
> +		/sys/devices/system/cpu/cpuX/regs/identification/prid
> +		/sys/devices/system/cpu/cpuX/regs/identification/globalnumber
> +Date:		Augest 2022
> +Contact:	Linux MIPS Kernel Mailing list <linux-mips@...r.kernel.org>
> +Description:	MIPS CPU registers
> +
> +		'identification' directory exposes the Processor ID and Global Number
> +		registers for identifying model and revision of the CPU.
> +
>  What:		/sys/devices/system/cpu/vulnerabilities
>  		/sys/devices/system/cpu/vulnerabilities/meltdown
>  		/sys/devices/system/cpu/vulnerabilities/spectre_v1
> diff --git a/arch/mips/kernel/topology.c b/arch/mips/kernel/topology.c
> index 9429d85a4703..bbb7d4b51ffe 100644
> --- a/arch/mips/kernel/topology.c
> +++ b/arch/mips/kernel/topology.c
> @@ -5,6 +5,8 @@
>  #include <linux/node.h>
>  #include <linux/nodemask.h>
>  #include <linux/percpu.h>
> +#include <linux/seq_file.h>
> +#include <linux/smp.h>
>  
>  static DEFINE_PER_CPU(struct cpu, cpu_devices);
>  
> @@ -26,3 +28,104 @@ static int __init topology_init(void)
>  }
>  
>  subsys_initcall(topology_init);
> +
> +static struct kobj_type cpuregs_kobj_type = {
> +	.sysfs_ops = &kobj_sysfs_ops,
> +};
> +
> +struct cpureg {
> +	struct kobject kobj;
> +	struct cpuinfo_mips *info;
> +};
> +static DEFINE_PER_CPU(struct cpureg *, cpuregs);
> +
> +#define kobj_to_cpureg(kobj)	container_of(kobj, struct cpureg, kobj)
> +#define CPUREGS_ATTR_RO(_name, _field)						\
> +	static ssize_t _name##_show(struct kobject *kobj,			\
> +			struct kobj_attribute *attr, char *buf)			\
> +	{									\
> +		struct cpuinfo_mips *info = kobj_to_cpureg(kobj)->info;		\
> +										\
> +		return sprintf(buf, "0x%08x\n", info->_field);	\
> +	}									\
> +	static struct kobj_attribute cpuregs_attr_##_name = __ATTR_RO(_name)
> +
> +CPUREGS_ATTR_RO(prid, processor_id);
> +CPUREGS_ATTR_RO(globalnumber, globalnumber);
> +
> +static struct attribute *cpuregs_id_attrs[] = {
> +	&cpuregs_attr_prid.attr,
> +	&cpuregs_attr_globalnumber.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group cpuregs_attr_group = {
> +	.attrs = cpuregs_id_attrs,
> +	.name = "identification"
> +};
> +
> +static int cpuregs_cpu_online(unsigned int cpu)
> +{
> +	int rc;
> +	struct device *dev;
> +	struct cpureg *reg;
> +
> +	dev = get_cpu_device(cpu);
> +	if (!dev) {
> +		rc = -ENODEV;
> +		goto out;
> +	}
> +	reg = kzalloc(sizeof(struct cpureg), GFP_KERNEL);
> +	if (!reg) {
> +		rc = -ENOMEM;
> +		goto out;
> +	}
> +	rc = kobject_init_and_add(&reg->kobj, &cpuregs_kobj_type,
> +					&dev->kobj, "regs");
> +	if (rc)
> +		goto out_kfree;

No, please read the documentation for kobject_init_and_add() for what to
properly do in a failure of this function.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ