Re: [PATCH v11 2/2] x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node
From: Jarkko Sakkinen
Date: Fri Nov 05 2021 - 18:14:42 EST
On Thu, 2021-11-04 at 08:25 +0100, Greg Kroah-Hartman wrote:
> > static const struct attribute_group *node_dev_groups[] = {
> > &node_dev_group,
> > #ifdef CONFIG_HAVE_ARCH_NODE_DEV_GROUP
> > &arch_node_dev_group,
> > #endif
> > NULL,
> > };
>
> Yes, that is true for the dev pointer passed to your callback, but what
> about the dev pointers in this random array you are looping over?
Right. I got what you are saying.
I think the most legit place to mark an entry in this array would be
just *before* device_register() in register_node(). It's different from
hugetlb_register_node() because hugetlb code adds its attribute group
with sysfs_create_group().
Similarly, the legit place to unmark an entry would be in
unregister_node(), right after device_unregister().
After writing this I realized something: the device ID is the same
as NUMA node ID. This means that I can rewrite my callback as
static ssize_t sgx_total_bytes_show(struct device *dev, struct device_attribute *attr, char *buf)
{
unsigned long size = 0;
int nid = dev->id;
return sysfs_emit(buf, "%lu\n", sgx_numa_nodes[dev->id].size);
}
I.e no need to maintain a device pointer.
/Jarkko