diff options
author | Matias Elo <matias.elo@nokia.com> | 2022-12-28 08:49:16 +0200 |
---|---|---|
committer | Matias Elo <matias.elo@nokia.com> | 2023-01-18 10:12:09 +0200 |
commit | 85d0d642154a15ea46dd1a1fcbcde3c4bdeffa49 (patch) | |
tree | 23d0bd5f8b279d48d72931a7be879fe1cd3e9c93 /platform | |
parent | a735a7131bceadb87c25b553446e4829923bcc1c (diff) |
linux-gen: event: add event validation support for queue enq operations
Add event validation support to following queue enqueue functions:
- odp_queue_enq()
- odp_queue_enq_multi()
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com>
Diffstat (limited to 'platform')
3 files changed, 55 insertions, 1 deletions
diff --git a/platform/linux-generic/include/odp/api/plat/event_validation_external.h b/platform/linux-generic/include/odp/api/plat/event_validation_external.h index 2d6c8613a..5a939402f 100644 --- a/platform/linux-generic/include/odp/api/plat/event_validation_external.h +++ b/platform/linux-generic/include/odp/api/plat/event_validation_external.h @@ -42,12 +42,18 @@ typedef enum { _ODP_EV_PACKET_FREE_MULTI, _ODP_EV_PACKET_FREE_SP, _ODP_EV_PACKET_IS_VALID, + _ODP_EV_QUEUE_ENQ, + _ODP_EV_QUEUE_ENQ_MULTI, _ODP_EV_MAX } _odp_ev_id_t; /* Implementation internal event validation functions */ #if _ODP_EVENT_VALIDATION +int _odp_event_validate(odp_event_t event, _odp_ev_id_t id); + +int _odp_event_validate_multi(const odp_event_t event[], int num, _odp_ev_id_t id); + int _odp_buffer_validate(odp_buffer_t buf, _odp_ev_id_t ev_id); int _odp_buffer_validate_multi(const odp_buffer_t buf[], int num, _odp_ev_id_t ev_id); @@ -58,6 +64,18 @@ int _odp_packet_validate_multi(const odp_packet_t pkt[], int num, _odp_ev_id_t e #else +static inline int _odp_event_validate(odp_event_t event ODP_UNUSED, _odp_ev_id_t ev_id ODP_UNUSED) +{ + return 0; +} + +static inline int _odp_event_validate_multi(const odp_event_t event[] ODP_UNUSED, + int num ODP_UNUSED, + _odp_ev_id_t ev_id ODP_UNUSED) +{ + return 0; +} + static inline int _odp_buffer_validate(odp_buffer_t buf ODP_UNUSED, _odp_ev_id_t ev_id ODP_UNUSED) { return 0; diff --git a/platform/linux-generic/include/odp/api/plat/queue_inlines.h b/platform/linux-generic/include/odp/api/plat/queue_inlines.h index 22673a887..609c0c9e4 100644 --- a/platform/linux-generic/include/odp/api/plat/queue_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/queue_inlines.h @@ -1,4 +1,5 @@ /* Copyright (c) 2018, Linaro Limited + * Copyright (c) 2023, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -7,6 +8,9 @@ #ifndef ODP_PLAT_QUEUE_INLINES_H_ #define ODP_PLAT_QUEUE_INLINES_H_ +#include <odp/api/hints.h> + +#include <odp/api/plat/event_validation_external.h> #include <odp/api/plat/queue_inline_types.h> /** @cond _ODP_HIDE_FROM_DOXYGEN_ */ @@ -37,12 +41,18 @@ _ODP_INLINE void *odp_queue_context(odp_queue_t handle) _ODP_INLINE int odp_queue_enq(odp_queue_t queue, odp_event_t ev) { + if (odp_unlikely(_odp_event_validate(ev, _ODP_EV_QUEUE_ENQ))) + return -1; + return _odp_queue_api->queue_enq(queue, ev); } _ODP_INLINE int odp_queue_enq_multi(odp_queue_t queue, const odp_event_t events[], int num) { + if (odp_unlikely(_odp_event_validate_multi(events, num, _ODP_EV_QUEUE_ENQ_MULTI))) + return -1; + return _odp_queue_api->queue_enq_multi(queue, events, num); } diff --git a/platform/linux-generic/odp_event_validation.c b/platform/linux-generic/odp_event_validation.c index 8dd8d7b8e..c2d430f1a 100644 --- a/platform/linux-generic/odp_event_validation.c +++ b/platform/linux-generic/odp_event_validation.c @@ -57,7 +57,9 @@ static const _odp_ev_info_t ev_info_tbl[] = { [_ODP_EV_PACKET_FREE] = {.str = "odp_packet_free()"}, [_ODP_EV_PACKET_FREE_MULTI] = {.str = "odp_packet_free_multi()"}, [_ODP_EV_PACKET_FREE_SP] = {.str = "odp_packet_free_sp()"}, - [_ODP_EV_PACKET_IS_VALID] = {.str = "odp_packet_is_valid()"} + [_ODP_EV_PACKET_IS_VALID] = {.str = "odp_packet_is_valid()"}, + [_ODP_EV_QUEUE_ENQ] = {.str = "odp_queue_enq()"}, + [_ODP_EV_QUEUE_ENQ_MULTI] = {.str = "odp_queue_enq_multi()"} }; ODP_STATIC_ASSERT(_ODP_ARRAY_SIZE(ev_info_tbl) == _ODP_EV_MAX, "ev_info_tbl missing entries"); @@ -147,6 +149,15 @@ static inline int packet_validate(odp_packet_t pkt, _odp_ev_id_t id) return validate_event_endmark(odp_packet_to_event(pkt), id, ODP_EVENT_PACKET); } +static inline int event_validate(odp_event_t event, int id) +{ + if (odp_event_type(event) == ODP_EVENT_BUFFER) + return buffer_validate(odp_buffer_from_event(event), id); + if (odp_event_type(event) == ODP_EVENT_PACKET) + return packet_validate(odp_packet_from_event(event), id); + return 0; +} + /* Enable usage from API inline files */ #include <odp/visibility_begin.h> @@ -180,6 +191,21 @@ int _odp_packet_validate_multi(const odp_packet_t pkt[], int num, return 0; } +int _odp_event_validate(odp_event_t event, _odp_ev_id_t id) +{ + return event_validate(event, id); +} + +int _odp_event_validate_multi(const odp_event_t event[], int num, + _odp_ev_id_t id) +{ + for (int i = 0; i < num; i++) { + if (odp_unlikely(event_validate(event[i], id))) + return -1; + } + return 0; +} + #include <odp/visibility_end.h> #endif /* _ODP_EVENT_VALIDATION */ |