linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch
@ 2022-09-01 19:44 Petr Vorel
  2022-09-01 20:15 ` Andrew Morton
  2022-09-02  5:55 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Vorel @ 2022-09-01 19:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: Petr Vorel, Andrew Morton, Eric Biederman, Greg Kroah-Hartman,
	Rafael J. Wysocki, David Sterba

Print the machine hardware name (UTS_MACHINE) in /proc/sys/kernel/arch.

This helps people who debug kernel with initramfs with minimal
environment (i.e. without coreutils or even busybox) or allow to open
sysfs file instead of run 'uname -m' in high level languages.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v2->v3:
* fix title in the subject

@Andrew @Eric: FYI previously the sysfs file was in
/sys/devices/system/cpu/, that's why I sent previous versions to Greg.

 Documentation/admin-guide/sysctl/kernel.rst | 5 +++++
 kernel/utsname_sysctl.c                     | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index ee6572b1edad..bbaa85194695 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -65,6 +65,11 @@ combining the following values:
 4 s3_beep
 = =======
 
+arch
+====
+
+The machine hardware name, the same output as ``uname -m``
+(e.g. ``x86_64`` or ``aarch64``).
 
 auto_msgmni
 ===========
diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
index 4ca61d49885b..7ffdd2cd5ff9 100644
--- a/kernel/utsname_sysctl.c
+++ b/kernel/utsname_sysctl.c
@@ -73,6 +73,13 @@ static DEFINE_CTL_TABLE_POLL(hostname_poll);
 static DEFINE_CTL_TABLE_POLL(domainname_poll);
 
 static struct ctl_table uts_kern_table[] = {
+	{
+		.procname	= "arch",
+		.data		= init_uts_ns.name.machine,
+		.maxlen		= sizeof(init_uts_ns.name.machine),
+		.mode		= 0444,
+		.proc_handler	= proc_do_uts_string,
+	},
 	{
 		.procname	= "ostype",
 		.data		= init_uts_ns.name.sysname,
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch
  2022-09-01 19:44 [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch Petr Vorel
@ 2022-09-01 20:15 ` Andrew Morton
  2022-09-01 21:25   ` Petr Vorel
  2022-09-02  5:55 ` Greg Kroah-Hartman
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2022-09-01 20:15 UTC (permalink / raw)
  To: Petr Vorel
  Cc: linux-kernel, Eric Biederman, Greg Kroah-Hartman,
	Rafael J. Wysocki, David Sterba

On Thu,  1 Sep 2022 21:44:03 +0200 Petr Vorel <pvorel@suse.cz> wrote:

> Print the machine hardware name (UTS_MACHINE) in /proc/sys/kernel/arch.
> 
> This helps people who debug kernel with initramfs with minimal
> environment (i.e. without coreutils or even busybox) or allow to open
> sysfs file instead of run 'uname -m' in high level languages.

If they're this constrained, why not run sys_uname() directly?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch
  2022-09-01 20:15 ` Andrew Morton
@ 2022-09-01 21:25   ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2022-09-01 21:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Eric Biederman, Greg Kroah-Hartman,
	Rafael J. Wysocki, David Sterba

> On Thu,  1 Sep 2022 21:44:03 +0200 Petr Vorel <pvorel@suse.cz> wrote:

> > Print the machine hardware name (UTS_MACHINE) in /proc/sys/kernel/arch.

> > This helps people who debug kernel with initramfs with minimal
> > environment (i.e. without coreutils or even busybox) or allow to open
> > sysfs file instead of run 'uname -m' in high level languages.

> If they're this constrained, why not run sys_uname() directly?

Hi Andrew,

of course you're right that in C is the most straightforward way to use uname(2).
I was more concerned about userspace, but I have to admit uname is probably
everywhere, therefore this is probably useless.

The background of this was my colleague while writing software running LTP tests
with qemu (using whole systems on qcow image or minimal dracut initramfs) or over SSH
got all info about running kernel from proc / sysfs, just architecture was
missing.

/proc/cpuinfo and /sys/devices/system/cpu/ are full of details about CPU, but
surprisingly no info about the architecture. Understand, this info is in struct
utsname and there is uname binary, OTOH there are
/proc/sys/kernel/{osrelease,ostype,version}, which are also in struct utsname.

Kind regards,
Petr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch
  2022-09-01 19:44 [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch Petr Vorel
  2022-09-01 20:15 ` Andrew Morton
@ 2022-09-02  5:55 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2022-09-02  5:55 UTC (permalink / raw)
  To: Petr Vorel
  Cc: linux-kernel, Andrew Morton, Eric Biederman, Rafael J. Wysocki,
	David Sterba

On Thu, Sep 01, 2022 at 09:44:03PM +0200, Petr Vorel wrote:
> Print the machine hardware name (UTS_MACHINE) in /proc/sys/kernel/arch.
> 
> This helps people who debug kernel with initramfs with minimal
> environment (i.e. without coreutils or even busybox) or allow to open
> sysfs file instead of run 'uname -m' in high level languages.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-02  5:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-01 19:44 [PATCH v3 1/1] kernel/utsname_sysctl.c: Print kernel arch Petr Vorel
2022-09-01 20:15 ` Andrew Morton
2022-09-01 21:25   ` Petr Vorel
2022-09-02  5:55 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).