* [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf
@ 2018-01-08 15:34 Keith Wiles
2018-01-08 15:39 ` Stephen Hemminger
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Keith Wiles @ 2018-01-08 15:34 UTC (permalink / raw)
To: dev
The rte_pktmbuf_free() allows for NULL mbuf pointer, but
when sanity check is enabled it will panic with null pointer.
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
---
lib/librte_mbuf/rte_mbuf.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index 7543662f7..58184c4f4 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
const struct rte_mbuf *m_seg;
unsigned int nb_segs;
- if (m == NULL)
- rte_panic("mbuf is NULL\n");
+ /* Calling with NULL is valid in the API */
+ if (!m)
+ return;
/* generic checks */
if (m->pool == NULL)
@@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)
__rte_mbuf_sanity_check(m, 1);
+ if (!m || !f) {
+ fprintf(stderr, "MBUF and/or FILE pointer is NULL\n");
+ return;
+ }
+
fprintf(f, "dump mbuf at %p, iova=%"PRIx64", buf_len=%u\n",
m, (uint64_t)m->buf_iova, (unsigned)m->buf_len);
fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "
--
2.14.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf
2018-01-08 15:34 [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf Keith Wiles
@ 2018-01-08 15:39 ` Stephen Hemminger
2018-01-08 15:41 ` Wiles, Keith
2018-01-09 4:39 ` Jerin Jacob
2018-01-09 14:29 ` [dpdk-dev] [PATCH v2] " Keith Wiles
2 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2018-01-08 15:39 UTC (permalink / raw)
To: Keith Wiles; +Cc: dev
On Mon, 8 Jan 2018 09:34:23 -0600
Keith Wiles <keith.wiles@intel.com> wrote:
> + if (!m || !f) {
> + fprintf(stderr, "MBUF and/or FILE pointer is NULL\n");
> + return;
> + }
Calling with f of NULL is user error, let it still die in fprintf.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf
2018-01-08 15:39 ` Stephen Hemminger
@ 2018-01-08 15:41 ` Wiles, Keith
0 siblings, 0 replies; 9+ messages in thread
From: Wiles, Keith @ 2018-01-08 15:41 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
> On Jan 8, 2018, at 9:39 AM, Stephen Hemminger <stephen@networkplumber.org> wrote:
>
> On Mon, 8 Jan 2018 09:34:23 -0600
> Keith Wiles <keith.wiles@intel.com> wrote:
>
>> + if (!m || !f) {
>> + fprintf(stderr, "MBUF and/or FILE pointer is NULL\n");
>> + return;
>> + }
>
> Calling with f of NULL is user error, let it still die in fprintf.
I thought about that too, but this routine is a debug routine does it really matter?
Regards,
Keith
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf
2018-01-08 15:34 [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf Keith Wiles
2018-01-08 15:39 ` Stephen Hemminger
@ 2018-01-09 4:39 ` Jerin Jacob
2018-01-09 14:29 ` [dpdk-dev] [PATCH v2] " Keith Wiles
2 siblings, 0 replies; 9+ messages in thread
From: Jerin Jacob @ 2018-01-09 4:39 UTC (permalink / raw)
To: Keith Wiles; +Cc: dev
-----Original Message-----
> Date: Mon, 8 Jan 2018 09:34:23 -0600
> From: Keith Wiles <keith.wiles@intel.com>
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null
> mbuf
> X-Mailer: git-send-email 2.10.1
>
> The rte_pktmbuf_free() allows for NULL mbuf pointer, but
> when sanity check is enabled it will panic with null pointer.
>
> Signed-off-by: Keith Wiles <keith.wiles@intel.com>
mbuf autotest is failing with this change.
# echo "mbuf_autotest" | sudo ./build/app/test
<snip>
Checking rte_mbuf_sanity_check for failure conditions
Checking good mbuf initially
Now checking for error conditions
Error with NULL mbuf test
test_failing_mbuf_sanity_check() failed
Test Failed
^ permalink raw reply [flat|nested] 9+ messages in thread
* [dpdk-dev] [PATCH v2] mbuf:using sanity checks do not panic on null mbuf
2018-01-08 15:34 [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf Keith Wiles
2018-01-08 15:39 ` Stephen Hemminger
2018-01-09 4:39 ` Jerin Jacob
@ 2018-01-09 14:29 ` Keith Wiles
2018-01-16 14:04 ` Olivier Matz
2018-01-29 9:39 ` [dpdk-dev] [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled Olivier Matz
2 siblings, 2 replies; 9+ messages in thread
From: Keith Wiles @ 2018-01-09 14:29 UTC (permalink / raw)
To: dev; +Cc: stephen, jerin.jacob
The rte_pktmbuf_free() allows for NULL mbuf pointer, but
when sanity check is enabled it will panic with null pointer.
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
---
lib/librte_mbuf/rte_mbuf.c | 10 ++++++++--
test/test/test_mbuf.c | 4 +---
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index 7543662f7..621679c92 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
const struct rte_mbuf *m_seg;
unsigned int nb_segs;
- if (m == NULL)
- rte_panic("mbuf is NULL\n");
+ /* Calling with NULL is valid in the API */
+ if (!m)
+ return;
/* generic checks */
if (m->pool == NULL)
@@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)
__rte_mbuf_sanity_check(m, 1);
+ if (!m) {
+ fprintf(stderr, "MBUF pointer is NULL\n");
+ return;
+ }
+
fprintf(f, "dump mbuf at %p, iova=%"PRIx64", buf_len=%u\n",
m, (uint64_t)m->buf_iova, (unsigned)m->buf_len);
fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "
diff --git a/test/test/test_mbuf.c b/test/test/test_mbuf.c
index 9e82a20be..146eaf0e5 100644
--- a/test/test/test_mbuf.c
+++ b/test/test/test_mbuf.c
@@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)
printf("Now checking for error conditions\n");
- if (verify_mbuf_check_panics(NULL)) {
- printf("Error with NULL mbuf test\n");
+ if (verify_mbuf_check_panics(NULL) != -1)
return -1;
- }
badbuf = *buf;
badbuf.pool = NULL;
--
2.14.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mbuf:using sanity checks do not panic on null mbuf
2018-01-09 14:29 ` [dpdk-dev] [PATCH v2] " Keith Wiles
@ 2018-01-16 14:04 ` Olivier Matz
2018-01-16 14:19 ` Wiles, Keith
2018-01-29 9:39 ` [dpdk-dev] [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled Olivier Matz
1 sibling, 1 reply; 9+ messages in thread
From: Olivier Matz @ 2018-01-16 14:04 UTC (permalink / raw)
To: Keith Wiles; +Cc: dev, stephen, jerin.jacob
On Tue, Jan 09, 2018 at 08:29:28AM -0600, Keith Wiles wrote:
> The rte_pktmbuf_free() allows for NULL mbuf pointer, but
> when sanity check is enabled it will panic with null pointer.
>
> Signed-off-by: Keith Wiles <keith.wiles@intel.com>
> ---
> lib/librte_mbuf/rte_mbuf.c | 10 ++++++++--
> test/test/test_mbuf.c | 4 +---
> 2 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
> index 7543662f7..621679c92 100644
> --- a/lib/librte_mbuf/rte_mbuf.c
> +++ b/lib/librte_mbuf/rte_mbuf.c
> @@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
> const struct rte_mbuf *m_seg;
> unsigned int nb_segs;
>
> - if (m == NULL)
> - rte_panic("mbuf is NULL\n");
> + /* Calling with NULL is valid in the API */
> + if (!m)
> + return;
>
> /* generic checks */
> if (m->pool == NULL)
> @@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)
>
> __rte_mbuf_sanity_check(m, 1);
>
> + if (!m) {
> + fprintf(stderr, "MBUF pointer is NULL\n");
> + return;
> + }
> +
> fprintf(f, "dump mbuf at %p, iova=%"PRIx64", buf_len=%u\n",
> m, (uint64_t)m->buf_iova, (unsigned)m->buf_len);
> fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "
> diff --git a/test/test/test_mbuf.c b/test/test/test_mbuf.c
> index 9e82a20be..146eaf0e5 100644
> --- a/test/test/test_mbuf.c
> +++ b/test/test/test_mbuf.c
> @@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)
>
> printf("Now checking for error conditions\n");
>
> - if (verify_mbuf_check_panics(NULL)) {
> - printf("Error with NULL mbuf test\n");
> + if (verify_mbuf_check_panics(NULL) != -1)
> return -1;
> - }
>
> badbuf = *buf;
> badbuf.pool = NULL;
> --
> 2.14.1
>
The problem is a panic when rte_pktmbuf_free(NULL) when mbuf debug is enabled,
right?
A NULL mbuf is only valid in case of a free because it is convenient, but for
most (all ?) other mbuf functions, the mbuf must not be NULL.
What about this patch instead:
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1413,13 +1413,14 @@ rte_pktmbuf_free_seg(struct rte_mbuf *m)
* segment is added back into its original mempool.
*
* @param m
- * The packet mbuf to be freed.
+ * The packet mbuf to be freed. If NULL, the function does nothing.
*/
static inline void rte_pktmbuf_free(struct rte_mbuf *m)
{
struct rte_mbuf *m_next;
- __rte_mbuf_sanity_check(m, 1);
+ if (m != NULL)
+ __rte_mbuf_sanity_check(m, 1);
while (m != NULL) {
m_next = m->next;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mbuf:using sanity checks do not panic on null mbuf
2018-01-16 14:04 ` Olivier Matz
@ 2018-01-16 14:19 ` Wiles, Keith
0 siblings, 0 replies; 9+ messages in thread
From: Wiles, Keith @ 2018-01-16 14:19 UTC (permalink / raw)
To: Olivier Matz; +Cc: dev, stephen, jerin.jacob
> On Jan 16, 2018, at 8:04 AM, Olivier Matz <olivier.matz@6wind.com> wrote:
>
> On Tue, Jan 09, 2018 at 08:29:28AM -0600, Keith Wiles wrote:
>> The rte_pktmbuf_free() allows for NULL mbuf pointer, but
>> when sanity check is enabled it will panic with null pointer.
>>
>> Signed-off-by: Keith Wiles <keith.wiles@intel.com>
>> ---
>> lib/librte_mbuf/rte_mbuf.c | 10 ++++++++--
>> test/test/test_mbuf.c | 4 +---
>> 2 files changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
>> index 7543662f7..621679c92 100644
>> --- a/lib/librte_mbuf/rte_mbuf.c
>> +++ b/lib/librte_mbuf/rte_mbuf.c
>> @@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
>> const struct rte_mbuf *m_seg;
>> unsigned int nb_segs;
>>
>> - if (m == NULL)
>> - rte_panic("mbuf is NULL\n");
>> + /* Calling with NULL is valid in the API */
>> + if (!m)
>> + return;
>>
>> /* generic checks */
>> if (m->pool == NULL)
>> @@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)
>>
>> __rte_mbuf_sanity_check(m, 1);
>>
>> + if (!m) {
>> + fprintf(stderr, "MBUF pointer is NULL\n");
>> + return;
>> + }
>> +
>> fprintf(f, "dump mbuf at %p, iova=%"PRIx64", buf_len=%u\n",
>> m, (uint64_t)m->buf_iova, (unsigned)m->buf_len);
>> fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "
>> diff --git a/test/test/test_mbuf.c b/test/test/test_mbuf.c
>> index 9e82a20be..146eaf0e5 100644
>> --- a/test/test/test_mbuf.c
>> +++ b/test/test/test_mbuf.c
>> @@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)
>>
>> printf("Now checking for error conditions\n");
>>
>> - if (verify_mbuf_check_panics(NULL)) {
>> - printf("Error with NULL mbuf test\n");
>> + if (verify_mbuf_check_panics(NULL) != -1)
>> return -1;
>> - }
>>
>> badbuf = *buf;
>> badbuf.pool = NULL;
>> --
>> 2.14.1
>>
>
> The problem is a panic when rte_pktmbuf_free(NULL) when mbuf debug is enabled,
> right?
>
> A NULL mbuf is only valid in case of a free because it is convenient, but for
> most (all ?) other mbuf functions, the mbuf must not be NULL.
>
> What about this patch instead:
>
> --- a/lib/librte_mbuf/rte_mbuf.h
> +++ b/lib/librte_mbuf/rte_mbuf.h
> @@ -1413,13 +1413,14 @@ rte_pktmbuf_free_seg(struct rte_mbuf *m)
> * segment is added back into its original mempool.
> *
> * @param m
> - * The packet mbuf to be freed.
> + * The packet mbuf to be freed. If NULL, the function does nothing.
> */
> static inline void rte_pktmbuf_free(struct rte_mbuf *m)
> {
> struct rte_mbuf *m_next;
>
> - __rte_mbuf_sanity_check(m, 1);
> + if (m != NULL)
> + __rte_mbuf_sanity_check(m, 1);
>
> while (m != NULL) {
> m_next = m->next;
Looks good to me I would ack that one. :-)
>
Regards,
Keith
^ permalink raw reply [flat|nested] 9+ messages in thread
* [dpdk-dev] [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled
2018-01-09 14:29 ` [dpdk-dev] [PATCH v2] " Keith Wiles
2018-01-16 14:04 ` Olivier Matz
@ 2018-01-29 9:39 ` Olivier Matz
2018-01-29 15:58 ` Thomas Monjalon
1 sibling, 1 reply; 9+ messages in thread
From: Olivier Matz @ 2018-01-29 9:39 UTC (permalink / raw)
To: dev; +Cc: Keith Wiles, stephen, jerin.jacob, stable
Do not panic when calling rte_pktmbuf_free(NULL) with mbuf debug
enabled, it is a valid operation.
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org
Reported-by: Keith Wiles <keith.wiles@intel.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
lib/librte_mbuf/rte_mbuf.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 4519fb303..719d04dda 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1439,13 +1439,14 @@ rte_pktmbuf_free_seg(struct rte_mbuf *m)
* segment is added back into its original mempool.
*
* @param m
- * The packet mbuf to be freed.
+ * The packet mbuf to be freed. If NULL, the function does nothing.
*/
static inline void rte_pktmbuf_free(struct rte_mbuf *m)
{
struct rte_mbuf *m_next;
- __rte_mbuf_sanity_check(m, 1);
+ if (m != NULL)
+ __rte_mbuf_sanity_check(m, 1);
while (m != NULL) {
m_next = m->next;
--
2.11.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled
2018-01-29 9:39 ` [dpdk-dev] [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled Olivier Matz
@ 2018-01-29 15:58 ` Thomas Monjalon
0 siblings, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2018-01-29 15:58 UTC (permalink / raw)
To: Olivier Matz; +Cc: dev, Keith Wiles, stephen, jerin.jacob, stable
29/01/2018 10:39, Olivier Matz:
> Do not panic when calling rte_pktmbuf_free(NULL) with mbuf debug
> enabled, it is a valid operation.
>
> Fixes: af75078fece3 ("first public release")
> Cc: stable@dpdk.org
>
> Reported-by: Keith Wiles <keith.wiles@intel.com>
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Applied, thanks
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-01-29 15:59 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-08 15:34 [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null mbuf Keith Wiles
2018-01-08 15:39 ` Stephen Hemminger
2018-01-08 15:41 ` Wiles, Keith
2018-01-09 4:39 ` Jerin Jacob
2018-01-09 14:29 ` [dpdk-dev] [PATCH v2] " Keith Wiles
2018-01-16 14:04 ` Olivier Matz
2018-01-16 14:19 ` Wiles, Keith
2018-01-29 9:39 ` [dpdk-dev] [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled Olivier Matz
2018-01-29 15:58 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).