diff mbox series

[v2,2/7] firmware: coreboot: Generate aliases for coreboot modules

Message ID 20240112131857.900734-3-nfraprado@collabora.com (mailing list archive)
State Superseded
Headers show
Series Allow coreboot modules to autoload and enable cbmem in the arm64 defconfig | expand

Commit Message

Nícolas F. R. A. Prado Jan. 12, 2024, 1:18 p.m. UTC
Generate aliases for coreboot modules to allow automatic module probing.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---

(no changes since v1)

 include/linux/mod_devicetable.h   |  8 ++++++++
 scripts/mod/devicetable-offsets.c |  3 +++
 scripts/mod/file2alias.c          | 10 ++++++++++
 3 files changed, 21 insertions(+)

Comments

Andy Shevchenko Jan. 14, 2024, 5:09 p.m. UTC | #1
On Fri, Jan 12, 2024 at 10:18:31AM -0300, Nícolas F. R. A. Prado wrote:
> Generate aliases for coreboot modules to allow automatic module probing.

...

> (no changes since v1)

Same Q as per v1.
Brian Norris Jan. 23, 2024, 10:06 p.m. UTC | #2
On Sun, Jan 14, 2024 at 07:09:29PM +0200, Andy Shevchenko wrote:
> On Fri, Jan 12, 2024 at 10:18:31AM -0300, Nícolas F. R. A. Prado wrote:
> > Generate aliases for coreboot modules to allow automatic module probing.
> 
> ...
> 
> > (no changes since v1)
> 
> Same Q as per v1.

I don't have v1 in my inbox, and this wasn't addressed in v3 either. But
copy/pasted off the archives:

"Don't you want to have a driver data or so associated with this?"

These drivers are super simple, and I doubt they will end up with
multiple tags per driver, so it seems unlikely we'd ever need it.
Additionally, struct coreboot_device already includes the tag
information, so anything that could be included in driver data could be
parsed out by the driver at probe time, if absolutely needed.

Brian
Greg KH Jan. 30, 2024, 11:51 p.m. UTC | #3
On Tue, Jan 23, 2024 at 02:06:14PM -0800, Brian Norris wrote:
> On Sun, Jan 14, 2024 at 07:09:29PM +0200, Andy Shevchenko wrote:
> > On Fri, Jan 12, 2024 at 10:18:31AM -0300, Nícolas F. R. A. Prado wrote:
> > > Generate aliases for coreboot modules to allow automatic module probing.
> > 
> > ...
> > 
> > > (no changes since v1)
> > 
> > Same Q as per v1.
> 
> I don't have v1 in my inbox, and this wasn't addressed in v3 either. But
> copy/pasted off the archives:
> 
> "Don't you want to have a driver data or so associated with this?"
> 
> These drivers are super simple, and I doubt they will end up with
> multiple tags per driver, so it seems unlikely we'd ever need it.
> Additionally, struct coreboot_device already includes the tag
> information, so anything that could be included in driver data could be
> parsed out by the driver at probe time, if absolutely needed.

But why limit yourself to 32bits now?  Why not make it 64?  It is going
to be sent to userspace, so you have to be very careful about it.

thanks,

greg k-h
Brian Norris Jan. 31, 2024, 12:01 a.m. UTC | #4
On Tue, Jan 30, 2024 at 3:51 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> On Tue, Jan 23, 2024 at 02:06:14PM -0800, Brian Norris wrote:
> > "Don't you want to have a driver data or so associated with this?"
...
> But why limit yourself to 32bits now?  Why not make it 64?  It is going
> to be sent to userspace, so you have to be very careful about it.

Is that question related to the question I pasted/replied to, about
driver data? Or a new topic? Sorry if I'm misunderstanding.

Anyway, for the size of the tag field: I don't have a strong opinion.
But FWIW, they're coming from this project:

https://review.coreboot.org/plugins/gitiles/coreboot/+/269b23280f928510bcadd23182294e5b9dad11ec/payloads/libpayload/include/coreboot_tables.h#36

As you can see there, we're extremely far from exhausting 16 bits, let alone 32.

Brian
Greg KH Jan. 31, 2024, 12:23 a.m. UTC | #5
On Tue, Jan 30, 2024 at 04:01:57PM -0800, Brian Norris wrote:
> On Tue, Jan 30, 2024 at 3:51 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> > On Tue, Jan 23, 2024 at 02:06:14PM -0800, Brian Norris wrote:
> > > "Don't you want to have a driver data or so associated with this?"
> ...
> > But why limit yourself to 32bits now?  Why not make it 64?  It is going
> > to be sent to userspace, so you have to be very careful about it.
> 
> Is that question related to the question I pasted/replied to, about
> driver data? Or a new topic? Sorry if I'm misunderstanding.

Same question, driver data, you make it 32 bits.

> Anyway, for the size of the tag field: I don't have a strong opinion.
> But FWIW, they're coming from this project:
> 
> https://review.coreboot.org/plugins/gitiles/coreboot/+/269b23280f928510bcadd23182294e5b9dad11ec/payloads/libpayload/include/coreboot_tables.h#36
> 
> As you can see there, we're extremely far from exhausting 16 bits, let alone 32.

We've run into running out of bits in other subsystems before, it's
"free" now, just be safe and make it 64 like I think Andy is suggesting.

thanks,

greg k-h
Nícolas F. R. A. Prado Feb. 1, 2024, 10:45 p.m. UTC | #6
On Tue, Jan 30, 2024 at 04:23:02PM -0800, Greg Kroah-Hartman wrote:
> On Tue, Jan 30, 2024 at 04:01:57PM -0800, Brian Norris wrote:
> > On Tue, Jan 30, 2024 at 3:51 PM Greg Kroah-Hartman
> > <gregkh@linuxfoundation.org> wrote:
> > > On Tue, Jan 23, 2024 at 02:06:14PM -0800, Brian Norris wrote:
> > > > "Don't you want to have a driver data or so associated with this?"
> > ...
> > > But why limit yourself to 32bits now?  Why not make it 64?  It is going
> > > to be sent to userspace, so you have to be very careful about it.
> > 
> > Is that question related to the question I pasted/replied to, about
> > driver data? Or a new topic? Sorry if I'm misunderstanding.
> 
> Same question, driver data, you make it 32 bits.
> 
> > Anyway, for the size of the tag field: I don't have a strong opinion.
> > But FWIW, they're coming from this project:
> > 
> > https://review.coreboot.org/plugins/gitiles/coreboot/+/269b23280f928510bcadd23182294e5b9dad11ec/payloads/libpayload/include/coreboot_tables.h#36
> > 
> > As you can see there, we're extremely far from exhausting 16 bits, let alone 32.
> 
> We've run into running out of bits in other subsystems before, it's
> "free" now, just be safe and make it 64 like I think Andy is suggesting.

Either you and Andy are suggesting different things, or I still don't quite get
what you mean.

Andy was suggesting we added a driver_data field, that is:

struct coreboot_device_id {
	__u32 tag;
	kernel_ulong_t driver_data;
};

You're suggesting we make the tag 64 bits long:

struct coreboot_device_id {
	__u64 tag;
};

Like Brian, I'm not sure I see the benefit of either change. As he said, it's
unlikely that having a driver_data would provide any benefit and won't ever be
required anyway, and 32 bits is already a generous space to give to coreboot
tags. That said, I'm also not against either change, and can apply both of them
to the next version if that's indeed what your experience says will work best.
I'll wait another week or so before following up though to make sure we're all
on the same page.

(To be honest I also still don't see how this struct makes it to userspace and
is considered ABI, I only see the generated modalias being ABI and hence 32 vs
64 bit tag is ABI breakage but not adding driver_data, but I'll take your word
for it for now)

Thanks,
Nícolas
Greg KH Feb. 2, 2024, 2:21 a.m. UTC | #7
On Thu, Feb 01, 2024 at 05:45:19PM -0500, Nícolas F. R. A. Prado wrote:
> On Tue, Jan 30, 2024 at 04:23:02PM -0800, Greg Kroah-Hartman wrote:
> > On Tue, Jan 30, 2024 at 04:01:57PM -0800, Brian Norris wrote:
> > > On Tue, Jan 30, 2024 at 3:51 PM Greg Kroah-Hartman
> > > <gregkh@linuxfoundation.org> wrote:
> > > > On Tue, Jan 23, 2024 at 02:06:14PM -0800, Brian Norris wrote:
> > > > > "Don't you want to have a driver data or so associated with this?"
> > > ...
> > > > But why limit yourself to 32bits now?  Why not make it 64?  It is going
> > > > to be sent to userspace, so you have to be very careful about it.
> > > 
> > > Is that question related to the question I pasted/replied to, about
> > > driver data? Or a new topic? Sorry if I'm misunderstanding.
> > 
> > Same question, driver data, you make it 32 bits.
> > 
> > > Anyway, for the size of the tag field: I don't have a strong opinion.
> > > But FWIW, they're coming from this project:
> > > 
> > > https://review.coreboot.org/plugins/gitiles/coreboot/+/269b23280f928510bcadd23182294e5b9dad11ec/payloads/libpayload/include/coreboot_tables.h#36
> > > 
> > > As you can see there, we're extremely far from exhausting 16 bits, let alone 32.
> > 
> > We've run into running out of bits in other subsystems before, it's
> > "free" now, just be safe and make it 64 like I think Andy is suggesting.
> 
> Either you and Andy are suggesting different things, or I still don't quite get
> what you mean.
> 
> Andy was suggesting we added a driver_data field, that is:
> 
> struct coreboot_device_id {
> 	__u32 tag;
> 	kernel_ulong_t driver_data;
> };
> 
> You're suggesting we make the tag 64 bits long:
> 
> struct coreboot_device_id {
> 	__u64 tag;
> };

Yeah, I'm confused, sorry.

Yes, add some driver_data, and if you are SURE your tag will NEVER be
larger than 32 bits, stick with that, but really, you are using the
space in empty padding anyway, so just make it 64bits please.

thanks,

greg k-h
Nícolas F. R. A. Prado Feb. 6, 2024, 8:53 p.m. UTC | #8
On Thu, Feb 01, 2024 at 06:21:03PM -0800, Greg Kroah-Hartman wrote:
> On Thu, Feb 01, 2024 at 05:45:19PM -0500, Nícolas F. R. A. Prado wrote:
> > On Tue, Jan 30, 2024 at 04:23:02PM -0800, Greg Kroah-Hartman wrote:
> > > On Tue, Jan 30, 2024 at 04:01:57PM -0800, Brian Norris wrote:
> > > > On Tue, Jan 30, 2024 at 3:51 PM Greg Kroah-Hartman
> > > > <gregkh@linuxfoundation.org> wrote:
> > > > > On Tue, Jan 23, 2024 at 02:06:14PM -0800, Brian Norris wrote:
> > > > > > "Don't you want to have a driver data or so associated with this?"
> > > > ...
> > > > > But why limit yourself to 32bits now?  Why not make it 64?  It is going
> > > > > to be sent to userspace, so you have to be very careful about it.
> > > > 
> > > > Is that question related to the question I pasted/replied to, about
> > > > driver data? Or a new topic? Sorry if I'm misunderstanding.
> > > 
> > > Same question, driver data, you make it 32 bits.
> > > 
> > > > Anyway, for the size of the tag field: I don't have a strong opinion.
> > > > But FWIW, they're coming from this project:
> > > > 
> > > > https://review.coreboot.org/plugins/gitiles/coreboot/+/269b23280f928510bcadd23182294e5b9dad11ec/payloads/libpayload/include/coreboot_tables.h#36
> > > > 
> > > > As you can see there, we're extremely far from exhausting 16 bits, let alone 32.
> > > 
> > > We've run into running out of bits in other subsystems before, it's
> > > "free" now, just be safe and make it 64 like I think Andy is suggesting.
> > 
> > Either you and Andy are suggesting different things, or I still don't quite get
> > what you mean.
> > 
> > Andy was suggesting we added a driver_data field, that is:
> > 
> > struct coreboot_device_id {
> > 	__u32 tag;
> > 	kernel_ulong_t driver_data;
> > };
> > 
> > You're suggesting we make the tag 64 bits long:
> > 
> > struct coreboot_device_id {
> > 	__u64 tag;
> > };
> 
> Yeah, I'm confused, sorry.
> 
> Yes, add some driver_data, and if you are SURE your tag will NEVER be
> larger than 32 bits, stick with that, but really, you are using the
> space in empty padding anyway, so just make it 64bits please.

Ok, after giving it a closer look, I've decided we really should just stick with
32 bits.

More fundamental than the previous argument that we aren't close to exhausting
32 bits for the tag in coreboot, is the fact that tags are literally defined as
32 bits long for the table entries [1]. Meaning, a tag being 32 bits long is
part of the coreboot ABI. We have to parse it as 32bits from memory.
Representing it as 64 bits internally and exposing it as 64 bits to userspace
would not only be unecessarily complicating things, but also misrepresenting the
data that we're getting from the firmware.

I can add driver_data for v4 no problem, as we can simply not use it while we
don't need it, but having tags be 64 bits actively complicates things for no
real gain, so it's a no-go.

Thanks,
Nícolas

[1] https://review.coreboot.org/plugins/gitiles/coreboot/+/refs/heads/main/src/commonlib/include/commonlib/coreboot_tables.h#128
diff mbox series

Patch

diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index f458469c5ce5..24e0dcfde809 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -960,4 +960,12 @@  struct vchiq_device_id {
 	char name[32];
 };
 
+/**
+ * struct coreboot_device_id - Identifies a coreboot table entry
+ * @tag: tag ID
+ */
+struct coreboot_device_id {
+	__u32 tag;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index e91a3c38143b..518200813d4e 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -274,5 +274,8 @@  int main(void)
 	DEVID(vchiq_device_id);
 	DEVID_FIELD(vchiq_device_id, name);
 
+	DEVID(coreboot_device_id);
+	DEVID_FIELD(coreboot_device_id, tag);
+
 	return 0;
 }
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 4829680a0a6d..5d1c61fa5a55 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1494,6 +1494,15 @@  static int do_vchiq_entry(const char *filename, void *symval, char *alias)
 	return 1;
 }
 
+/* Looks like: coreboot:tN */
+static int do_coreboot_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD(symval, coreboot_device_id, tag);
+	sprintf(alias, "coreboot:t%08X", tag);
+
+	return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1575,6 +1584,7 @@  static const struct devtable devtable[] = {
 	{"ishtp", SIZE_ishtp_device_id, do_ishtp_entry},
 	{"cdx", SIZE_cdx_device_id, do_cdx_entry},
 	{"vchiq", SIZE_vchiq_device_id, do_vchiq_entry},
+	{"coreboot", SIZE_coreboot_device_id, do_coreboot_entry},
 };
 
 /* Create MODULE_ALIAS() statements.