OpenCloudOS-Kernel/drivers/base
Jarkko Sakkinen f7a1f67867 x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node
commit 50468e4313 upstream.

== Problem ==

The amount of SGX memory on a system is determined by the BIOS and it
varies wildly between systems.  It can be as small as dozens of MB's
and as large as many GB's on servers.  Just like how applications need
to know how much regular RAM is available, enclave builders need to
know how much SGX memory an enclave can consume.

== Solution ==

Introduce a new sysfs file:

	/sys/devices/system/node/nodeX/x86/sgx_total_bytes

to enumerate the amount of SGX memory available in each NUMA node.
This serves the same function for SGX as /proc/meminfo or
/sys/devices/system/node/nodeX/meminfo does for normal RAM.

'sgx_total_bytes' is needed today to help drive the SGX selftests.
SGX-specific swap code is exercised by creating overcommitted enclaves
which are larger than the physical SGX memory on the system.  They
currently use a CPUID-based approach which can diverge from the actual
amount of SGX memory available.  'sgx_total_bytes' ensures that the
selftests can work efficiently and do not attempt stupid things like
creating a 100,000 MB enclave on a system with 128 MB of SGX memory.

== Implementation Details ==

Introduce CONFIG_HAVE_ARCH_NODE_DEV_GROUP opt-in flag to expose an
arch specific attribute group, and add an attribute for the amount of
SGX memory in bytes to each NUMA node:

== ABI Design Discussion ==

As opposed to the per-node ABI, a single, global ABI was considered.
However, this would prevent enclaves from being able to size
themselves so that they fit on a single NUMA node.  Essentially, a
single value would rule out NUMA optimizations for enclaves.

Create a new "x86/" directory inside each "nodeX/" sysfs directory.
'sgx_total_bytes' is expected to be the first of at least a few
sgx-specific files to be placed in the new directory.  Just scanning
/proc/meminfo, these are the no-brainers that we have for RAM, but we
need for SGX:

	MemTotal:       xxxx kB // sgx_total_bytes (implemented here)
	MemFree:        yyyy kB // sgx_free_bytes
	SwapTotal:      zzzz kB // sgx_swapped_bytes

So, at *least* three.  I think we will eventually end up needing
something more along the lines of a dozen.  A new directory (as
opposed to being in the nodeX/ "root") directory avoids cluttering the
root with several "sgx_*" files.

Place the new file in a new "nodeX/x86/" directory because SGX is
highly x86-specific.  It is very unlikely that any other architecture
(or even non-Intel x86 vendor) will ever implement SGX.  Using "sgx/"
as opposed to "x86/" was also considered.  But, there is a real chance
this can get used for other arch-specific purposes.

[ dhansen: rewrite changelog ]

Intel-SIG: commit 50468e4313 x86/sgx: Add an attribute for the amount
of SGX memory in a NUMA node.
Backport for SGX EDMM support.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211116162116.93081-2-jarkko@kernel.org
[ Zhiquan:
  This patch adds a new element into array node_dev_groups[],
  however, in 5.4 code the array is defined by macro
  ATTRIBUTE_GROUPS(node_dev).

  Upstream expands this macro at commit 75bd50fa84
  ("drivers/base/node.c: use bin_attribute to break the size limitation
  of cpumap ABI"), it's one of series
  https://lore.kernel.org/all/20210806110251.560-1-song.bao.hua@hisilicon.com
  which involves a lot of additional changes. Unfortunately, this series
  need some fixes that involves more and more dependencies.

  To keep the thing simple, just expand the macro without functional
  changes. ]
Signed-off-by: Zhiquan Li <zhiquan1.li@intel.com>
2024-06-11 21:24:07 +08:00
..
firmware_loader ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
power ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
regmap ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
test tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
Kconfig base: arch_topology: update Kconfig help description 2019-07-22 09:36:44 -07:00
Makefile drivers: base: Introducing software nodes to the firmware node framework 2018-11-26 18:19:11 +01:00
arch_topology.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
attribute_container.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
base.h driver core: Export device_driver_attach() 2024-06-11 21:15:31 +08:00
bus.c driver core: Flow the return code from ->probe() through to sysfs bind 2024-06-11 21:15:30 +08:00
cacheinfo.c Driver Core and debugfs changes for 5.3-rc1 2019-07-12 12:24:03 -07:00
class.c driver core: move device->knode_class to device_private 2019-01-18 16:55:48 +01:00
component.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
container.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
core.c msi: dynamic dev_msi 2024-06-11 21:16:19 +08:00
cpu.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dd.c driver core: Export device_driver_attach() 2024-06-11 21:15:31 +08:00
devcon.c Merge generic_lookup_helpers into usb-next 2019-09-03 17:11:07 +02:00
devcoredump.c devcoredump: fix typo in comment 2019-08-15 17:38:11 +02:00
devres.c drivers/base/devres: introduce devm_release_action() 2019-06-13 17:34:56 -10:00
devtmpfs.c vfs: Convert ramfs, shmem, tmpfs, devtmpfs, rootfs to use the new mount API 2019-09-12 21:05:34 -04:00
driver.c driver_find_device: Unify the match function with class_find_device() 2019-06-24 05:22:31 +02:00
firmware.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
hypervisor.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
init.c base: fix order of OF initialization 2018-07-07 17:54:29 +02:00
isa.c Merge 4.15-rc3 into driver-core-next 2017-12-11 08:50:05 +01:00
map.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
memory.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
module.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
node.c x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node 2024-06-11 21:24:07 +08:00
pinctrl.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
platform-msi.c msi: dynamic dev_msi 2024-06-11 21:16:19 +08:00
platform.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
property.c device property: Add functions for accessing node's parents 2024-06-11 21:11:43 +08:00
soc.c base: soc: Export soc_device_register/unregister APIs 2019-08-05 14:56:31 -07:00
swnode.c software node: Make argument to to_software_node const 2024-06-11 21:11:42 +08:00
syscore.c treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively 2019-04-09 14:19:06 +02:00
topology.c topology: Create core_cpus and die_cpus sysfs attributes 2019-05-23 10:08:34 +02:00
transport_class.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00