|
6 | 6 | #include <linux/highmem.h>
|
7 | 7 | #include <linux/kthread.h>
|
8 | 8 | #include <linux/miscdevice.h>
|
| 9 | +#include <linux/node.h> |
9 | 10 | #include <linux/pagemap.h>
|
10 | 11 | #include <linux/ratelimit.h>
|
11 | 12 | #include <linux/sched/mm.h>
|
12 | 13 | #include <linux/sched/signal.h>
|
13 | 14 | #include <linux/slab.h>
|
| 15 | +#include <linux/sysfs.h> |
14 | 16 | #include <asm/sgx.h>
|
15 | 17 | #include "driver.h"
|
16 | 18 | #include "encl.h"
|
@@ -780,6 +782,48 @@ static inline u64 __init sgx_calc_section_metric(u64 low, u64 high)
|
780 | 782 | ((high & GENMASK_ULL(19, 0)) << 32);
|
781 | 783 | }
|
782 | 784 |
|
| 785 | +#ifdef CONFIG_NUMA |
| 786 | +static ssize_t sgx_total_bytes_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 787 | +{ |
| 788 | + return sysfs_emit(buf, "%lu\n", sgx_numa_nodes[dev->id].size); |
| 789 | +} |
| 790 | +static DEVICE_ATTR_RO(sgx_total_bytes); |
| 791 | + |
| 792 | +static umode_t arch_node_attr_is_visible(struct kobject *kobj, |
| 793 | + struct attribute *attr, int idx) |
| 794 | +{ |
| 795 | + /* Make all x86/ attributes invisible when SGX is not initialized: */ |
| 796 | + if (nodes_empty(sgx_numa_mask)) |
| 797 | + return 0; |
| 798 | + |
| 799 | + return attr->mode; |
| 800 | +} |
| 801 | + |
| 802 | +static struct attribute *arch_node_dev_attrs[] = { |
| 803 | + &dev_attr_sgx_total_bytes.attr, |
| 804 | + NULL, |
| 805 | +}; |
| 806 | + |
| 807 | +const struct attribute_group arch_node_dev_group = { |
| 808 | + .name = "x86", |
| 809 | + .attrs = arch_node_dev_attrs, |
| 810 | + .is_visible = arch_node_attr_is_visible, |
| 811 | +}; |
| 812 | + |
| 813 | +static void __init arch_update_sysfs_visibility(int nid) |
| 814 | +{ |
| 815 | + struct node *node = node_devices[nid]; |
| 816 | + int ret; |
| 817 | + |
| 818 | + ret = sysfs_update_group(&node->dev.kobj, &arch_node_dev_group); |
| 819 | + |
| 820 | + if (ret) |
| 821 | + pr_err("sysfs update failed (%d), files may be invisible", ret); |
| 822 | +} |
| 823 | +#else /* !CONFIG_NUMA */ |
| 824 | +static void __init arch_update_sysfs_visibility(int nid) {} |
| 825 | +#endif |
| 826 | + |
783 | 827 | static bool __init sgx_page_cache_init(void)
|
784 | 828 | {
|
785 | 829 | u32 eax, ebx, ecx, edx, type;
|
@@ -826,6 +870,9 @@ static bool __init sgx_page_cache_init(void)
|
826 | 870 | INIT_LIST_HEAD(&sgx_numa_nodes[nid].sgx_poison_page_list);
|
827 | 871 | node_set(nid, sgx_numa_mask);
|
828 | 872 | sgx_numa_nodes[nid].size = 0;
|
| 873 | + |
| 874 | + /* Make SGX-specific node sysfs files visible: */ |
| 875 | + arch_update_sysfs_visibility(nid); |
829 | 876 | }
|
830 | 877 |
|
831 | 878 | sgx_epc_sections[i].node = &sgx_numa_nodes[nid];
|
@@ -903,24 +950,6 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
|
903 | 950 | }
|
904 | 951 | EXPORT_SYMBOL_GPL(sgx_set_attribute);
|
905 | 952 |
|
906 |
| -#ifdef CONFIG_NUMA |
907 |
| -static ssize_t sgx_total_bytes_show(struct device *dev, struct device_attribute *attr, char *buf) |
908 |
| -{ |
909 |
| - return sysfs_emit(buf, "%lu\n", sgx_numa_nodes[dev->id].size); |
910 |
| -} |
911 |
| -static DEVICE_ATTR_RO(sgx_total_bytes); |
912 |
| - |
913 |
| -static struct attribute *arch_node_dev_attrs[] = { |
914 |
| - &dev_attr_sgx_total_bytes.attr, |
915 |
| - NULL, |
916 |
| -}; |
917 |
| - |
918 |
| -const struct attribute_group arch_node_dev_group = { |
919 |
| - .name = "x86", |
920 |
| - .attrs = arch_node_dev_attrs, |
921 |
| -}; |
922 |
| -#endif /* CONFIG_NUMA */ |
923 |
| - |
924 | 953 | static int __init sgx_init(void)
|
925 | 954 | {
|
926 | 955 | int ret;
|
|
0 commit comments