All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Jarkko Sakkinen <jarkko@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	reinette.chatre@intel.com, linux-kernel@vger.kernel.org,
	linux-sgx@vger.kernel.org
Subject: Re: [PATCH v13 2/2] x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node
Date: Sat, 1 Jan 2022 20:54:51 -0800	[thread overview]
Message-ID: <c857c964-89b9-d827-74ec-32cf874e8d8b@intel.com> (raw)
In-Reply-To: <YcuhhI2+k0XVuTb1@iki.fi>

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

On 12/28/21 3:45 PM, Jarkko Sakkinen wrote:
>> If I can provide any further information or testing, let me know!
> Dave, when is the fix going to be applied [*]?
> 
>> Cheers,
>> Nathan
> [*] https://lore.kernel.org/linux-sgx/YcGTePmWDMOQU1pn@iki.fi/T/#m831a01bdde347f9e0af2c973986fae0499718201

Greg preferred hiding the file as opposed to faking a number in there.
Any testing of the attached would be appreciated.

[-- Attachment #2: sgx-null-ptr.patch --]
[-- Type: text/x-patch, Size: 2009 bytes --]


From: Dave Hansen <dave.hansen@linux.intel.com>

Nathan Chancellor reported an oops when aceessing the
'sgx_total_bytes' sysfs file:

	https://lore.kernel.org/all/YbzhBrimHGGpddDM@archlinux-ax161/

The sysfs output code accesses the sgx_numa_nodes[] array
unconditionally.  However, this array is allocated during SGX
initialization, which only occurs on systems where SGX is
supported.

If the sysfs file is accessed on systems without SGX support,
sgx_numa_nodes[] is NULL and an oops occurs.

To fix this, hide the entire nodeX/x86/ attribute group on
systems without SGX support using the ->is_visible attribute
group callback.

Fixes: 50468e431335 ("x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node")
Reported-by: Nathan Chancellor <nathan@kernel.org>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: linux-sgx@vger.kernel.org
Cc: x86@kernel.org
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/arch/x86/kernel/cpu/sgx/main.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff -puN arch/x86/kernel/cpu/sgx/main.c~sgx-null-ptr arch/x86/kernel/cpu/sgx/main.c
--- a/arch/x86/kernel/cpu/sgx/main.c~sgx-null-ptr	2021-12-20 07:56:38.309584807 -0800
+++ b/arch/x86/kernel/cpu/sgx/main.c	2021-12-20 08:17:28.997705149 -0800
@@ -910,6 +910,16 @@ static ssize_t sgx_total_bytes_show(stru
 }
 static DEVICE_ATTR_RO(sgx_total_bytes);
 
+static umode_t arch_node_attr_is_visible(struct kobject * kobj,
+		struct attribute * attr, int idx)
+{
+	/* Make all x86/ attributes invisible when SGX is not initialized: */
+	if (nodes_empty(sgx_numa_mask))
+		return 0;
+
+	return attr->mode;
+}
+
 static struct attribute *arch_node_dev_attrs[] = {
 	&dev_attr_sgx_total_bytes.attr,
 	NULL,
@@ -918,6 +928,7 @@ static struct attribute *arch_node_dev_a
 const struct attribute_group arch_node_dev_group = {
 	.name = "x86",
 	.attrs = arch_node_dev_attrs,
+	.is_visible = arch_node_attr_is_visible,
 };
 #endif /* CONFIG_NUMA */
 
_

  reply	other threads:[~2022-01-02  4:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 16:21 [PATCH v13 1/2] x86/sgx: Rename fallback labels in sgx_init() Jarkko Sakkinen
2021-11-16 16:21 ` [PATCH v13 2/2] x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node Jarkko Sakkinen
2021-12-04 23:51   ` Jarkko Sakkinen
2021-12-07 19:36   ` Dave Hansen
2021-12-08 10:10     ` Borislav Petkov
2021-12-08 19:38       ` Dave Hansen
2021-12-09 12:08         ` Borislav Petkov
2021-12-11 15:37         ` Jarkko Sakkinen
2021-12-11 15:36     ` Jarkko Sakkinen
2021-12-09 15:35   ` [tip: x86/sgx] " tip-bot2 for Jarkko Sakkinen
2021-12-17 19:12   ` [PATCH v13 2/2] " Nathan Chancellor
2021-12-17 21:17     ` Dave Hansen
2021-12-17 22:04       ` Nathan Chancellor
2021-12-28 23:45     ` Jarkko Sakkinen
2022-01-02  4:54       ` Dave Hansen [this message]
2022-01-02 23:20         ` Nathan Chancellor
2022-01-04 16:52         ` Dave Hansen
2022-01-06 19:18         ` Jarkko Sakkinen
2022-01-07 11:42           ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c857c964-89b9-d827-74ec-32cf874e8d8b@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jarkko@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=rafael@kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.