[EXTERNAL] [PATCH v3 1/2] cryptodev: fix crypto callbacks on unsetting callbacks macro

Kundapura, Ganapati ganapati.kundapura at intel.com
Thu Jun 27 12:15:09 CEST 2024


Hi Akhil,

> -----Original Message-----
> From: Akhil Goyal <gakhil at marvell.com>
> Sent: Thursday, June 27, 2024 11:50 AM
> To: Kundapura, Ganapati <ganapati.kundapura at intel.com>;
> ferruh.yigit at amd.com; Richardson, Bruce <bruce.richardson at intel.com>;
> mb at smartsharesystems.com; thomas at monjalon.net
> Cc: fanzhang.oss at gmail.com; Senthil, Bala <bala.senthil at intel.com>; Gujjar,
> Abhinandan S <abhinandan.gujjar at intel.com>; Mcnamara, John
> <john.mcnamara at intel.com>; dev at dpdk.org
> Subject: RE: [EXTERNAL] [PATCH v3 1/2] cryptodev: fix crypto callbacks on
> unsetting callbacks macro
> 
> > Crypto callbacks APIs are available in header files but when the macro
> > RTE_CRYPTO_CALLBACKS unset, test application need to put #ifdef in its
> > code.
> >
> > The test application should be able to build and run, regardless DPDK
> > library is built with RTE_CRYPTO_CALLBACKS defined or not.
> >
> > Added ENOTSUP from the beginning of the APIs implementation if
> > RTE_CRYPTO_CALLBACKS macro is unset/undefined.
> >
> > Fixes: 1c3ffb95595e ("cryptodev: add enqueue and dequeue callbacks")
> > Fixes: 5523a75af539 ("test/crypto: add case for enqueue/dequeue
> > callbacks")
> >
> > Signed-off-by: Ganapati Kundapura <ganapati.kundapura at intel.com>
> >
> > ---
> > v3:
> > * Added NOTSUP from the beginning of the APIs
> >
> > diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
> > index 94438c5..7dca2c9 100644
> > --- a/app/test/test_cryptodev.c
> > +++ b/app/test/test_cryptodev.c
> > @@ -118,6 +118,18 @@ struct crypto_unittest_params {
> >  	for (j = index; j < index + num_blk_types; j++)
> > 	\
> >  		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
> >
> > +#define TEST_SKIP_LOG(cond, msg, ...) do {				\
> > +	if ((cond)) {							\
> > +		RTE_LOG(ERR, CRYPTODEV, "%s line %d: "
> > 	\
> > +			msg "\n", __func__, __LINE__, ##__VA_ARGS__);
> > 	\
> > +		RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);
> > 	\
> > +		return TEST_SKIPPED;					\
> > +	}								\
> > +} while (0)
> > +
> > +#define TEST_SKIP(a, b, msg, ...) \
> > +	TEST_SKIP_LOG(a == b, msg, ##__VA_ARGS__)
> > +
> 
> This can be moved to app/test/test.h
> Also can we rename it to TEST_ASSERT_SKIP?
Removed this macro
> 
> >  /*
> >   * Forward declarations.
> >   */
> > @@ -14754,7 +14766,7 @@ test_enq_callback_setup(void)
> >
> >  	struct rte_cryptodev_cb *cb;
> >  	uint16_t qp_id = 0;
> > -	int j = 0;
> > +	int j = 0, ret;
> >
> >  	/* Verify the crypto capabilities for which enqueue/dequeue is done.
> > */
> >  	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; @@ -14794,6
> +14806,7 @@
> > test_enq_callback_setup(void)
> >  	/* Test with invalid crypto device */
> >  	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
> >  			qp_id, test_enq_callback, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
> >  			"cryptodev %u did not fail",
> >  			qp_id, RTE_CRYPTO_MAX_DEVS);
> > @@ -14802,6 +14815,7 @@ test_enq_callback_setup(void)
> >  	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
> >  			dev_info.max_nb_queue_pairs + 1,
> >  			test_enq_callback, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> 
> Why do we need to check for ENOTSUP at multiple places in the same
> function?
> This can be checked at the first usage only.
Checked for ENOTSUP only for first usage
> 
> >  	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
> >  			"cryptodev %u did not fail",
> >  			dev_info.max_nb_queue_pairs + 1,
> > @@ -14810,6 +14824,7 @@ test_enq_callback_setup(void)
> >  	/* Test with NULL callback */
> >  	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
> >  			qp_id, NULL, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
> >  			"cryptodev %u did not fail",
> >  			qp_id, ts_params->valid_devs[0]);
> > @@ -14817,6 +14832,7 @@ test_enq_callback_setup(void)
> >  	/* Test with valid configuration */
> >  	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
> >  			qp_id, test_enq_callback, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
> >  			"qp %u on cryptodev %u",
> >  			qp_id, ts_params->valid_devs[0]);
> > @@ -14830,24 +14846,35 @@ test_enq_callback_setup(void)
> >  		rte_delay_ms(10);
> >
> >  	/* Test with invalid crypto device */
> > -	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
> > -			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
> > +	ret = rte_cryptodev_remove_enq_callback(RTE_CRYPTO_MAX_DEVS,
> > +					qp_id,
> > +					cb);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_FAIL(ret,
> >  			"Expected call to fail as crypto device is invalid");
> >
> >  	/* Test with invalid queue pair */
> > -	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
> > -			ts_params->valid_devs[0],
> > -			dev_info.max_nb_queue_pairs + 1, cb),
> > +	ret = rte_cryptodev_remove_enq_callback(ts_params->valid_devs[0],
> > +					dev_info.max_nb_queue_pairs + 1,
> > +					cb);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_FAIL(ret,
> >  			"Expected call to fail as queue pair is invalid");
> >
> >  	/* Test with NULL callback */
> > -	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
> > -			ts_params->valid_devs[0], qp_id, NULL),
> > +	ret = rte_cryptodev_remove_enq_callback(ts_params->valid_devs[0],
> > +					qp_id,
> > +					NULL);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_FAIL(ret,
> >  			"Expected call to fail as callback is NULL");
> >
> >  	/* Test with valid configuration */
> > -	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
> > -			ts_params->valid_devs[0], qp_id, cb),
> > +	ret = rte_cryptodev_remove_enq_callback(ts_params->valid_devs[0],
> > +					qp_id,
> > +					cb);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_SUCCESS(ret,
> >  			"Failed test to remove callback on "
> >  			"qp %u on cryptodev %u",
> >  			qp_id, ts_params->valid_devs[0]);
> > @@ -14869,7 +14896,7 @@ test_deq_callback_setup(void)
> >
> >  	struct rte_cryptodev_cb *cb;
> >  	uint16_t qp_id = 0;
> > -	int j = 0;
> > +	int j = 0, ret;
> >
> >  	/* Verify the crypto capabilities for which enqueue/dequeue is done.
> > */
> >  	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; @@ -14909,6
> +14936,7 @@
> > test_deq_callback_setup(void)
> >  	/* Test with invalid crypto device */
> >  	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
> >  			qp_id, test_deq_callback, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
> >  			"cryptodev %u did not fail",
> >  			qp_id, RTE_CRYPTO_MAX_DEVS);
> > @@ -14917,6 +14945,7 @@ test_deq_callback_setup(void)
> >  	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
> >  			dev_info.max_nb_queue_pairs + 1,
> >  			test_deq_callback, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
> >  			"cryptodev %u did not fail",
> >  			dev_info.max_nb_queue_pairs + 1,
> > @@ -14925,6 +14954,7 @@ test_deq_callback_setup(void)
> >  	/* Test with NULL callback */
> >  	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
> >  			qp_id, NULL, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
> >  			"cryptodev %u did not fail",
> >  			qp_id, ts_params->valid_devs[0]);
> > @@ -14932,6 +14962,7 @@ test_deq_callback_setup(void)
> >  	/* Test with valid configuration */
> >  	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
> >  			qp_id, test_deq_callback, NULL);
> > +	TEST_SKIP(rte_errno, ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
> >  			"qp %u on cryptodev %u",
> >  			qp_id, ts_params->valid_devs[0]);
> > @@ -14945,24 +14976,36 @@ test_deq_callback_setup(void)
> >  		rte_delay_ms(10);
> >
> >  	/* Test with invalid crypto device */
> > +	ret = rte_cryptodev_remove_deq_callback(RTE_CRYPTO_MAX_DEVS,
> > +					qp_id,
> > +					cb);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> >  	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
> >  			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
> >  			"Expected call to fail as crypto device is invalid");
> >
> >  	/* Test with invalid queue pair */
> > -	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
> > -			ts_params->valid_devs[0],
> > -			dev_info.max_nb_queue_pairs + 1, cb),
> > +	ret = rte_cryptodev_remove_deq_callback(ts_params->valid_devs[0],
> > +					dev_info.max_nb_queue_pairs + 1,
> > +					cb);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_FAIL(ret,
> >  			"Expected call to fail as queue pair is invalid");
> >
> >  	/* Test with NULL callback */
> > -	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
> > -			ts_params->valid_devs[0], qp_id, NULL),
> > +	ret = rte_cryptodev_remove_deq_callback(ts_params->valid_devs[0],
> > +					qp_id,
> > +					NULL);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_FAIL(ret,
> >  			"Expected call to fail as callback is NULL");
> >
> >  	/* Test with valid configuration */
> > -	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
> > -			ts_params->valid_devs[0], qp_id, cb),
> > +	ret = rte_cryptodev_remove_deq_callback(ts_params->valid_devs[0],
> > +					qp_id,
> > +					cb);
> > +	TEST_SKIP(ret, -ENOTSUP, "Not supported, skipped");
> > +	TEST_ASSERT_SUCCESS(ret,
> >  			"Failed test to remove callback on "
> >  			"qp %u on cryptodev %u",
> >  			qp_id, ts_params->valid_devs[0]);
> > diff --git a/lib/cryptodev/rte_cryptodev.c
> > b/lib/cryptodev/rte_cryptodev.c index 886eb7a..8a45ad7 100644
> > --- a/lib/cryptodev/rte_cryptodev.c
> > +++ b/lib/cryptodev/rte_cryptodev.c
> > @@ -1491,6 +1491,10 @@ rte_cryptodev_add_enq_callback(uint8_t
> dev_id,
> >  			       rte_cryptodev_callback_fn cb_fn,
> >  			       void *cb_arg)
> >  {
> > +#ifdef RTE_CRYPTO_CALLBACKS
> > +	rte_errno = ENOTSUP;
> > +	return NULL;
> > +#endif
> 
> This should be ifndef at all places.
> Did you test this?
> 
Updated that for testing but missed to restore it while posting.
Yes, tested and retested with the latest patch(v4)

+ Test Suite : Crypto General Unit Test Suite
 + ------------------------------------------------------- +
CRYPTODEV: rte_cryptodev_configure() line 1148: Invalid dev_id=7
CRYPTODEV: rte_cryptodev_configure() line 1148: Invalid dev_id=255
CRYPTODEV: rte_cryptodev_stop() line 1241: Device with dev_id=0 already stopped
 + TestCase [ 0] : test_device_configure_invalid_dev_id succeeded
CRYPTODEV: rte_cryptodev_queue_pair_setup() line 1364: Invalid queue_pair_id=1
CRYPTODEV: rte_cryptodev_queue_pair_setup() line 1364: Invalid queue_pair_id=65535
CRYPTODEV: rte_cryptodev_stop() line 1241: Device with dev_id=0 already stopped
 + TestCase [ 1] : test_queue_pair_descriptor_setup succeeded
CRYPTODEV: rte_cryptodev_queue_pairs_config() line 1086: invalid param: dev 0x7ffbd873e940, nb_queues 0
CRYPTODEV: rte_cryptodev_configure() line 1171: dev0 rte_crypto_dev_queue_pairs_config = -22
CRYPTODEV: rte_cryptodev_queue_pairs_config() line 1101: Invalid num queue_pairs (65535) for dev 0
CRYPTODEV: rte_cryptodev_configure() line 1171: dev0 rte_crypto_dev_queue_pairs_config = -22
CRYPTODEV: rte_cryptodev_queue_pairs_config() line 1101: Invalid num queue_pairs (2) for dev 0
CRYPTODEV: rte_cryptodev_configure() line 1171: dev0 rte_crypto_dev_queue_pairs_config = -22
CRYPTODEV: rte_cryptodev_stop() line 1241: Device with dev_id=0 already stopped
 + TestCase [ 2] : test_device_configure_invalid_queue_pair_ids succeeded
CRYPTODEV: rte_cryptodev_stats_get() line 1701: Invalid dev_id=88
CRYPTODEV: rte_cryptodev_stats_get() line 1706: Invalid stats ptr
CRYPTODEV: rte_cryptodev_stats_reset() line 1729: Invalid dev_id=44
 + TestCase [ 3] : test_stats succeeded
USER1: test_enq_callback_setup line 12993: rte_cryptodev_add_enq_callback() Not supported, skipped
+ TestCase [ 4] : test_enq_callback_setup skipped
USER1: test_deq_callback_setup line 13098: rte_cryptodev_add_deq_callback()  Not supported, skipped
+ TestCase [ 5] : test_deq_callback_setup skipped
 + ------------------------------------------------------- +
 + Test Suite Summary : Crypto General Unit Test Suite
 + ------------------------------------------------------- +
 + Tests Total :        6
 + Tests Skipped :      2
 + Tests Executed :     6
 + Tests Unsupported:   0
 + Tests Passed :       4
 + Tests Failed :       0
 + ------------------------------------------------------- +
> 
> >  	struct rte_cryptodev *dev;
> >  	struct rte_cryptodev_cb_rcu *list;
> >  	struct rte_cryptodev_cb *cb, *tail;
> > @@ -1556,6 +1560,9 @@ rte_cryptodev_remove_enq_callback(uint8_t
> > dev_id,
> >  				  uint16_t qp_id,
> >  				  struct rte_cryptodev_cb *cb)
> >  {
> > +#ifdef RTE_CRYPTO_CALLBACKS
> > +	return -ENOTSUP;
> > +#endif
> >  	struct rte_cryptodev *dev;
> >  	RTE_ATOMIC(struct rte_cryptodev_cb *) *prev_cb;
> >  	struct rte_cryptodev_cb *curr_cb;
> > @@ -1630,6 +1637,10 @@ rte_cryptodev_add_deq_callback(uint8_t
> dev_id,
> >  			       rte_cryptodev_callback_fn cb_fn,
> >  			       void *cb_arg)
> >  {
> > +#ifdef RTE_CRYPTO_CALLBACKS
> > +	rte_errno = ENOTSUP;
> > +	return NULL;
> > +#endif
> >  	struct rte_cryptodev *dev;
> >  	struct rte_cryptodev_cb_rcu *list;
> >  	struct rte_cryptodev_cb *cb, *tail;
> > @@ -1696,6 +1707,9 @@ rte_cryptodev_remove_deq_callback(uint8_t
> > dev_id,
> >  				  uint16_t qp_id,
> >  				  struct rte_cryptodev_cb *cb)
> >  {
> > +#ifdef RTE_CRYPTO_CALLBACKS
> > +	return -ENOTSUP;
> > +#endif
> >  	struct rte_cryptodev *dev;
> >  	RTE_ATOMIC(struct rte_cryptodev_cb *) *prev_cb;
> >  	struct rte_cryptodev_cb *curr_cb;
> > --
> > 2.6.4



More information about the dev mailing list