Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1120614rwb; Fri, 7 Oct 2022 08:21:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4l4HKz1P7naxtD76HU6a2XVDoz07zt4E5fi0Y5hE8m4ybTkLdGPFcGQQADR+AyijgYETBM X-Received: by 2002:a05:6402:2d8:b0:458:c152:67bd with SMTP id b24-20020a05640202d800b00458c15267bdmr4985533edx.308.1665156096340; Fri, 07 Oct 2022 08:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665156096; cv=none; d=google.com; s=arc-20160816; b=wFjOSff5O9MGBbAdTTf7nuDgLxf1AqkKfS3ZaQbqm7ZTKzxcFz2WSiYwnWhcbxBZa9 jbJM6c0l6SQmic8yDMwWQ0v6hTldcsFioguGyfrieQYtr2B8Qrq8L3sUJLYiVWJGIgNe i+qZn96gwAYy7Gp3nPxU7xI0XGl5rGyChSW6I8z46OXAxCPEFnheY5DRuSWOMl4FLrAK tfbS5jCqYQz9aBgRdBJUi4XdzIaSIdeKV777iZFdk0/SyUWsexxAPtCH9hOrUbFmHA1u iZn59yaKSaZ/z2csFwRYjT+LbxCc+vl/MsDrb6QtDFDoOf2LwXDo7hbd+w1IjwlPVd9y /ZIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=cbXxlpgk38Og2OSP3BeodMmIhEyN7me626e1pixIS0A=; b=z35Revk/EesRfXEL0haxCbRO9iNkezqGFUoP/xukD0UEVRI8C6m98ybXuBPnoUkg2G eAkh2pDoPYP9TZshphJsvVxpMK/C0UvIeTbTNRS/MJowguaY4FVZEQQypllWdVuw8j/Q h11QoaSbHp2/CJdAIT4oYJgwYE+zbMyNxpZl4F5gcK09StNQok4jFvSj+ZLrtHsgZCVh D4DfwLozAGAPl+Tka24iDPtPtKvrMFk6YU285qua4AgPyt24YW7Pp9StfIIa+xpfpkOY K1m36Y2WaywE3xUCNh/JdBJ5DxUOPPIfrPqv9ATZkRss5gUXgwvyC9AuCLdsPi5Vkfud Mpng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kroah.com header.s=fm3 header.b=aIPzan2K; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=snGjR8CI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga10-20020a1709070c0a00b0078d85777c4fsi1553233ejc.700.2022.10.07.08.21.08; Fri, 07 Oct 2022 08:21:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kroah.com header.s=fm3 header.b=aIPzan2K; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=snGjR8CI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbiJGOwI (ORCPT + 99 others); Fri, 7 Oct 2022 10:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbiJGOwF (ORCPT ); Fri, 7 Oct 2022 10:52:05 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09C1766865; Fri, 7 Oct 2022 07:51:52 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 779EE320025E; Fri, 7 Oct 2022 10:51:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 07 Oct 2022 10:51:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1665154309; x=1665240709; bh=cbXxlpgk38 Og2OSP3BeodMmIhEyN7me626e1pixIS0A=; b=aIPzan2K/5vwQr3WnGbKft/MgW JPGZlxE2o0tOeKglTTMczDdDL7JbYv9rOKwG/XlKMVhd0Ux97xTInMITTUI12vZj Vs/ZOPTYVzrGvDTig+9cFE/h0mL5blPZbQlu3wiu6G1LabZLDjmYLWgnn2FaRgFY gt8h3HXClEx/HULvjWErDnGBTOrX2vbhYFfFaLvZpDkImZrirbA+nEfRAOpy3yIK azG8KOWEjENV5M9d/wSEM7QVSNMJOKj44IesruQluxpdtZlcleN7mAk5/PKAgdVF sK0u7si7JPPNFVQFLS9CIKvCpQkI4RWFdzp94LyC9ir8cU2vaZ8Q9ko56OOw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1665154309; x=1665240709; bh=cbXxlpgk38Og2OSP3BeodMmIhEyN 7me626e1pixIS0A=; b=snGjR8CIxyRDi1bd8qkxVdrIhI15r1WXpAvJPKxKG4q4 /F6y1Jdd7P+3JQjYs397XarlQoA7MdNHxLd/EN5Ad5OrFOUBLwyS5QD4A4JjhHQR kjlCk9J6+Sbr5oqrxAmOUAqFZagh7+PUIhgN9atbrmm/2hIZS7uALcx+ikIaz8TM 986ouMn+UJS3/5ZVGKBjtmR1KTYNXAtFZTYgEEEBasgqEjTlK7ivfzzOukJV6UMl X9/9ABpgJSDm0bv25BKWU6YCwc16Cc5WHnjCFWKZfUxhZM9wlpNirqCO6B+04HoZ eXJK9TuDzAEjLESKDZj40vS09DdZe+FM4czuRnReGw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeijedgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepifhrvghg ucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheqnecuggftrfgrthhtvghrnhepheegvd evvdeljeeugfdtudduhfekledtiefhveejkeejuefhtdeufefhgfehkeetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsehkrhhorg hhrdgtohhm X-ME-Proxy: Feedback-ID: i787e41f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Oct 2022 10:51:48 -0400 (EDT) Date: Fri, 7 Oct 2022 16:52:31 +0200 From: Greg KH To: Jiaxun Yang Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, tsbogend@alpha.franken.de, linux-api@vger.kernel.org, f.fainelli@gmail.com Subject: Re: [PATCH v5] MIPS: Expose prid and globalnumber to sysfs Message-ID: References: <20221007141207.30635-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221007141207.30635-1-jiaxun.yang@flygoat.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 07, 2022 at 03:12:07PM +0100, 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 > --- > 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? > v4: Properly handle err of kobj creation. (gregkh) > v5: Drop invalid kfree > --- > .../ABI/testing/sysfs-devices-system-cpu | 11 +++ > arch/mips/kernel/topology.c | 99 +++++++++++++++++++ > 2 files changed, 110 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu > index 5bf61881f012..9fdfe2de0f76 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: October 2022 > +Contact: Linux MIPS Kernel Mailing list > +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..80aaaca3cfbc 100644 > --- a/arch/mips/kernel/topology.c > +++ b/arch/mips/kernel/topology.c > @@ -5,6 +5,8 @@ > #include > #include > #include > +#include > +#include > > static DEFINE_PER_CPU(struct cpu, cpu_devices); > > @@ -26,3 +28,100 @@ 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); \ sysfs_emit() please. > + } \ > + 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(®->kobj, &cpuregs_kobj_type, > + &dev->kobj, "regs"); > + if (rc) > + goto out_kobj; > + rc = sysfs_create_group(®->kobj, &cpuregs_attr_group); > + if (rc) > + goto out_kobj; > + > + return 0; > +out_kobj: > + kobject_put(®->kobj); > +out: > + return rc; > +} > + > +static int cpuregs_cpu_offline(unsigned int cpu) > +{ > + struct device *dev; > + struct cpureg *reg = per_cpu(cpuregs, cpu); > + > + dev = get_cpu_device(cpu); > + if (!dev || !reg) > + return -ENODEV; > + if (reg->kobj.parent) { Why are you looking at the parent of a kobject? Why not just always remove the kobject if you have a reference to it now? How does the parent matter? thanks, greg k-h