Page MenuHomeFreeBSD

bnxt_en: Improve sysctl handler bnxt_dcb_list_app()
ClosedPublic

Authored by zlei on Jan 17 2025, 11:24 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Feb 11, 3:49 PM
Unknown Object (File)
Mon, Feb 10, 9:02 PM
Unknown Object (File)
Wed, Feb 5, 8:36 PM
Unknown Object (File)
Tue, Feb 4, 1:56 AM
Unknown Object (File)
Fri, Jan 31, 8:05 AM
Unknown Object (File)
Sat, Jan 25, 9:18 AM
Unknown Object (File)
Jan 20 2025, 5:10 PM
Subscribers
None

Details

Summary

Prefer sbuf_new_for_sysctl() over error-prone manually managed buf.

No functional change intended.

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

zlei requested review of this revision.Jan 17 2025, 11:24 AM
zlei created this revision.

I'm not sure if this helps 284073 but it appears that the buf is unlikely to overflow.

sys/dev/bnxt/bnxt_en/bnxt_sysctl.c
1941–1942

We can avoid imposing an arbitrary limit by using sbuf_new_for_sysctl() here. Is there some reason you didn't use that?

sys/dev/bnxt/bnxt_en/bnxt_sysctl.c
1941–1942

I've ever considered sbuf_new_for_sysctl(), but it lacks the ability to pass in SBUF_NOWAIT .

Well M_WAITOK is probably OK within sysctl call, but I'd prefer to keep the behavior unchanged.

markj added inline comments.
sys/dev/bnxt/bnxt_en/bnxt_sysctl.c
1941–1942

Yes, it's always ok to use M_WAITOK in sysctl handlers, and in syscall handlers more generally, so long as the thread isn't holding non-sleepable locks.

I don't feel too strongly about it, but IMHO if you're going to improve the handler, you might as well fix this aspect of it as well.

1945–1947

If you want to report truncation as an error, the return value of sbuf_finish() should be checked.

This revision is now accepted and ready to land.Jan 18 2025, 3:51 PM
zlei edited the summary of this revision. (Show Details)

Prefer sbuf_new_for_sysctl(), and calculate the buf size according to num of apps.

After a carefully calculating, with maximum apps, i.e. 128 apps, the 4096 bytes buf is still not sufficent. A hand crafted test shows that it requires about 5907 bytes. To make the buf aligned, choose 64 bytes per app.

Ideally I want a sbuf_new_for_sysctl_flag() which can pass in SBUF_AUTOEXTEND. That will be much more flexible, but probably not in this context. As that requires new KPI. User may request ERRTA fix in releng branch so just use sbuf_new_for_sysctl() right now.

This revision now requires review to proceed.Jan 20 2025, 1:04 PM

Prefer sbuf_new_for_sysctl(), and calculate the buf size according to num of apps.

After a carefully calculating, with maximum apps, i.e. 128 apps, the 4096 bytes buf is still not sufficent. A hand crafted test shows that it requires about 5907 bytes. To make the buf aligned, choose 64 bytes per app.

Ideally I want a sbuf_new_for_sysctl_flag() which can pass in SBUF_AUTOEXTEND. That will be much more flexible, but probably not in this context. As that requires new KPI. User may request ERRTA fix in releng branch so just use sbuf_new_for_sysctl() right now.

Note that sbuf_new_for_sysctl() creates a stream: the sbuf has a drain function, sbuf_sysctl_drain(), which uses SYSCTL_OUT to copy out the buffer, so once the buffer is full, sbuf_putc() can drain the buffer and keep going. So, the buffer size is not too important, and SBUF_AUTOEXTEND shouldn't be needed.

Prefer sbuf_new_for_sysctl(), and calculate the buf size according to num of apps.

After a carefully calculating, with maximum apps, i.e. 128 apps, the 4096 bytes buf is still not sufficent. A hand crafted test shows that it requires about 5907 bytes. To make the buf aligned, choose 64 bytes per app.

Ideally I want a sbuf_new_for_sysctl_flag() which can pass in SBUF_AUTOEXTEND. That will be much more flexible, but probably not in this context. As that requires new KPI. User may request ERRTA fix in releng branch so just use sbuf_new_for_sysctl() right now.

Note that sbuf_new_for_sysctl() creates a stream: the sbuf has a drain function, sbuf_sysctl_drain(), which uses SYSCTL_OUT to copy out the buffer, so once the buffer is full, sbuf_putc() can drain the buffer and keep going. So, the buffer size is not too important, and SBUF_AUTOEXTEND shouldn't be needed.

Ahh, you're right ! I only looked into sbuf_finish() but not sbuf_printf(). So a small buffer is OK for sbuf_new_for_sysctl(). I'm going to choose a buffer size, say 128. Does that look good to you ?

Note that sbuf_new_for_sysctl() creates a stream: the sbuf has a drain function, sbuf_sysctl_drain(), which uses SYSCTL_OUT to copy out the buffer, so once the buffer is full, sbuf_putc() can drain the buffer and keep going. So, the buffer size is not too important, and SBUF_AUTOEXTEND shouldn't be needed.

Ahh, you're right ! I only looked into sbuf_finish() but not sbuf_printf(). So a small buffer is OK for sbuf_new_for_sysctl(). I'm going to choose a buffer size, say 128. Does that look good to you ?

I think that's fine, the buffer size is mostly arbitrary in this case. 128 bytes should work.

Use a small buffer size 128.

This revision is now accepted and ready to land.Jan 20 2025, 4:42 PM