#include <linux/highmem.h>
 #include <linux/kthread.h>
 #include <linux/miscdevice.h>
+#include <linux/node.h>
 #include <linux/pagemap.h>
 #include <linux/ratelimit.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/signal.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <asm/sgx.h>
 #include "driver.h"
 #include "encl.h"
               ((high & GENMASK_ULL(19, 0)) << 32);
 }
 
+#ifdef CONFIG_NUMA
+static ssize_t sgx_total_bytes_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       return sysfs_emit(buf, "%lu\n", sgx_numa_nodes[dev->id].size);
+}
+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,
+};
+
+const struct attribute_group arch_node_dev_group = {
+       .name = "x86",
+       .attrs = arch_node_dev_attrs,
+       .is_visible = arch_node_attr_is_visible,
+};
+
+static void __init arch_update_sysfs_visibility(int nid)
+{
+       struct node *node = node_devices[nid];
+       int ret;
+
+       ret = sysfs_update_group(&node->dev.kobj, &arch_node_dev_group);
+
+       if (ret)
+               pr_err("sysfs update failed (%d), files may be invisible", ret);
+}
+#else /* !CONFIG_NUMA */
+static void __init arch_update_sysfs_visibility(int nid) {}
+#endif
+
 static bool __init sgx_page_cache_init(void)
 {
        u32 eax, ebx, ecx, edx, type;
                        INIT_LIST_HEAD(&sgx_numa_nodes[nid].sgx_poison_page_list);
                        node_set(nid, sgx_numa_mask);
                        sgx_numa_nodes[nid].size = 0;
+
+                       /* Make SGX-specific node sysfs files visible: */
+                       arch_update_sysfs_visibility(nid);
                }
 
                sgx_epc_sections[i].node =  &sgx_numa_nodes[nid];
 }
 EXPORT_SYMBOL_GPL(sgx_set_attribute);
 
-#ifdef CONFIG_NUMA
-static ssize_t sgx_total_bytes_show(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       return sysfs_emit(buf, "%lu\n", sgx_numa_nodes[dev->id].size);
-}
-static DEVICE_ATTR_RO(sgx_total_bytes);
-
-static struct attribute *arch_node_dev_attrs[] = {
-       &dev_attr_sgx_total_bytes.attr,
-       NULL,
-};
-
-const struct attribute_group arch_node_dev_group = {
-       .name = "x86",
-       .attrs = arch_node_dev_attrs,
-};
-#endif /* CONFIG_NUMA */
-
 static int __init sgx_init(void)
 {
        int ret;