git: 95e956722a2e - stable/14 - mbuf: add mbuf information to KASSERTs
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 29 Apr 2025 11:41:36 UTC
The branch stable/14 has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=95e956722a2ea2d9254456ccf29a42cded71927c
commit 95e956722a2ea2d9254456ccf29a42cded71927c
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-04-13 13:25:12 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-04-29 10:49:27 +0000
mbuf: add mbuf information to KASSERTs
Be more consistent about printing the mbuf pointer in KASSERT messages.
This massively helps debugging and we were already doing a good job at
it.
Also replace some handrolled KASSERTs with M_ASSERTPKTHDR() for fewer
copies of the check logic.
In m_align() move the msg into the KASSERT given after it was moved
here in ed6a66ca6c206 the msg is only used in one place.
Sponsored by: The FreeBSD Foundation
Reviewed by: glebius, zlei
Differential Revision: https://reviews.freebsd.org/D49817
(cherry picked from commit 22d5d61f91eb70ced6a010d9a1d60f0ff33fff2f)
---
sys/sys/mbuf.h | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 941c907e903b..c17fc9dec9a4 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1110,7 +1110,7 @@ static inline u_int
m_extrefcnt(struct mbuf *m)
{
- KASSERT(m->m_flags & M_EXT, ("%s: M_EXT missing", __func__));
+ KASSERT(m->m_flags & M_EXT, ("%s: M_EXT missing for %p", __func__, m));
return ((m->m_ext.ext_flags & EXT_FLAG_EMBREF) ? m->m_ext.ext_count :
*m->m_ext.ext_cnt);
@@ -1142,13 +1142,13 @@ m_extrefcnt(struct mbuf *m)
/* Check if the supplied mbuf has a packet header, or else panic. */
#define M_ASSERTPKTHDR(m) \
KASSERT((m) != NULL && (m)->m_flags & M_PKTHDR, \
- ("%s: no mbuf packet header!", __func__))
+ ("%s: no mbuf %p packet header!", __func__, (m)))
/* Check if the supplied mbuf has no send tag, or else panic. */
#define M_ASSERT_NO_SND_TAG(m) \
KASSERT((m) != NULL && (m)->m_flags & M_PKTHDR && \
((m)->m_pkthdr.csum_flags & CSUM_SND_TAG) == 0, \
- ("%s: receive mbuf has send tag!", __func__))
+ ("%s: receive mbuf %p has send tag!", __func__, (m)))
/* Check if mbuf is multipage. */
#define M_ASSERTEXTPG(m) \
@@ -1162,7 +1162,7 @@ m_extrefcnt(struct mbuf *m)
*/
#define M_ASSERTVALID(m) \
KASSERT((((struct mbuf *)m)->m_flags & 0) == 0, \
- ("%s: attempted use of a free mbuf!", __func__))
+ ("%s: attempted use of a free mbuf %p!", __func__, (m)))
/* Check whether any mbuf in the chain is unmapped. */
#ifdef INVARIANTS
@@ -1207,12 +1207,9 @@ m_extrefcnt(struct mbuf *m)
static __inline void
m_align(struct mbuf *m, int len)
{
-#ifdef INVARIANTS
- const char *msg = "%s: not a virgin mbuf";
-#endif
int adjust;
-
- KASSERT(m->m_data == M_START(m), (msg, __func__));
+ KASSERT(m->m_data == M_START(m),
+ ("%s: not a virgin mbuf %p", __func__, m));
adjust = M_SIZE(m) - len;
m->m_data += adjust &~ (sizeof(long)-1);
@@ -1530,14 +1527,16 @@ m_free(struct mbuf *m)
static __inline int
rt_m_getfib(struct mbuf *m)
{
- KASSERT(m->m_flags & M_PKTHDR , ("Attempt to get FIB from non header mbuf."));
+ KASSERT(m->m_flags & M_PKTHDR,
+ ("%s: Attempt to get FIB from non header mbuf %p", __func__, m));
return (m->m_pkthdr.fibnum);
}
#define M_GETFIB(_m) rt_m_getfib(_m)
#define M_SETFIB(_m, _fib) do { \
- KASSERT((_m)->m_flags & M_PKTHDR, ("Attempt to set FIB on non header mbuf.")); \
+ KASSERT((_m)->m_flags & M_PKTHDR, \
+ ("%s: Attempt to set FIB on non header mbuf %p", __func__, (_m))); \
((_m)->m_pkthdr.fibnum) = (_fib); \
} while (0)
@@ -1681,9 +1680,9 @@ static inline void
mbuf_tstmp2timespec(struct mbuf *m, struct timespec *ts)
{
- KASSERT((m->m_flags & M_PKTHDR) != 0, ("mbuf %p no M_PKTHDR", m));
+ M_ASSERTPKTHDR(m);
KASSERT((m->m_flags & (M_TSTMP|M_TSTMP_LRO)) != 0,
- ("mbuf %p no M_TSTMP or M_TSTMP_LRO", m));
+ ("%s: mbuf %p no M_TSTMP or M_TSTMP_LRO", __func__, m));
ts->tv_sec = m->m_pkthdr.rcv_tstmp / 1000000000;
ts->tv_nsec = m->m_pkthdr.rcv_tstmp % 1000000000;
}
@@ -1693,9 +1692,9 @@ static inline void
mbuf_tstmp2timeval(struct mbuf *m, struct timeval *tv)
{
- KASSERT((m->m_flags & M_PKTHDR) != 0, ("mbuf %p no M_PKTHDR", m));
+ M_ASSERTPKTHDR(m);
KASSERT((m->m_flags & (M_TSTMP|M_TSTMP_LRO)) != 0,
- ("mbuf %p no M_TSTMP or M_TSTMP_LRO", m));
+ ("%s: mbuf %p no M_TSTMP or M_TSTMP_LRO", __func__, m));
tv->tv_sec = m->m_pkthdr.rcv_tstmp / 1000000000;
tv->tv_usec = (m->m_pkthdr.rcv_tstmp % 1000000000) / 1000;
}