bdev: Add crypto virtual bdev module
Initial support for softare AESNI_MB DPDK driver only. Have tested (both aesni and QAT seprately and concurrrently) on underlying NVMe devices with bdevio and a bdevperf script that runs IOs from 512B to 128K each with Q depths from 1 to 512 in powers of 2 for 30 seconds each run. QAT can be included in the code (but not makefile) and marked as experimental until we are ready to test in CI. It works well on 2 systems but is a big PITA to get the hardware setup and configured for use with DPDK (IMHO). Change-Id: If518c3df8e74e00efa18afdf194824c5e69778fc Signed-off-by: Paul Luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/403107 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
183d81d0c6
commit
51606ed402
@ -22,6 +22,12 @@ does not at this time confer any SPDK ABI compatibility claims.
|
||||
|
||||
spdk_bdev_alias_del_all() was added to delete all alias from block device.
|
||||
|
||||
A new virtual bdev module has been added to perform at rest data encryption using the DPDK CryptoDev
|
||||
Framework. The module initially uses a software AESNI CBC cipher with experimental support for the
|
||||
Intel QAT hardware accelerator also currently implemented with support for CBC cipher. Future work
|
||||
may include additional ciphers as well as consideration for authentication. NOTE: this module is
|
||||
currently marked as experimental. Do not use in production.
|
||||
|
||||
### Environment Abstraction Layer and Event Framework
|
||||
|
||||
The size parameter of spdk_mem_map_translate is now a pointer. This allows the
|
||||
|
1
configure
vendored
1
configure
vendored
@ -339,6 +339,7 @@ than or equal to 4.14 will see significantly reduced performance.
|
||||
fi
|
||||
|
||||
if [[ "$CONFIG_CRYPTO" = "y" ]]; then
|
||||
echo NOTE: Crypto is currently marked as experimental. Do not use in production.
|
||||
set +e
|
||||
nasm_ver=$(nasm -v | sed 's/[^0-9]*//g' | awk '{print substr ($0, 0, 5)}')
|
||||
ipsec="$(find /usr -name intel-ipsec-mb.h 2>/dev/null)"
|
||||
|
35
doc/bdev.md
35
doc/bdev.md
@ -91,6 +91,41 @@ To remove a block device representation use the delete_rbd_bdev command.
|
||||
|
||||
`rpc.py delete_rbd_bdev Rbd0`
|
||||
|
||||
# Crypto Virtual Bdev Module {#bdev_config_crypto}
|
||||
|
||||
The crypto virtual bdev module can be configured to provide at rest data encryption
|
||||
for any underlying bdev. The module relies on the DPDK CryptoDev Framework to provide
|
||||
all cryptographic functionality. The framework provides support for many different software
|
||||
only cryptographic modules as well hardware assisted support for the Intel QAT board. The
|
||||
framework also provides support for cipher, hash, authentication and AEAD functions. At this
|
||||
time the SPDK virtual bdev module supports cipher only as follows:
|
||||
|
||||
- AESN-NI Multi Buffer Crypto Poll Mode Driver: RTE_CRYPTO_CIPHER_AES128_CBC
|
||||
- Intel(R) QuickAssist (QAT) Crypto Poll Mode Driver: RTE_CRYPTO_CIPHER_AES128_CBC
|
||||
(Note: QAT is functional however is marked as experimental until the hardware has
|
||||
been fully integrated with the SPDK CI system.)
|
||||
|
||||
Support for other DPDK drivers and capabilities may be added programmatically. Existing
|
||||
functionality is configured through a .conf file as shown here:
|
||||
|
||||
[crypto]<br>
|
||||
\# CRY \<bdev name\> \<vbdev name\> \<key\> \<PMD\><br>
|
||||
\# key size depends on cipher<br>
|
||||
\# supported PMD names: crypto_aesni_mb, crypto_qat<br>
|
||||
\# Note: QAT is experimental while test HW is being setup<br>
|
||||
CRY Malloc4 crypto_ram 0123456789123456 crypto_aesni_mb
|
||||
|
||||
In order to support using the bdev block offset (LBA) as the initialization vector (IV),
|
||||
the crypto module break up all I/O into crypto operations of a size equal to the block
|
||||
size of the underlying bdev. For example, a 4K I/O to a bdev with a 512B block size,
|
||||
would result in 8 cryptographic operations.
|
||||
|
||||
For reads, the buffer provided to the crypto module will be used as the destination buffer
|
||||
for unencrypted data. For writes, however, a temporary scratch buffer is used as the
|
||||
destination buffer for encryption which is then passed on to the underlying bdev as the
|
||||
write buffer. This is done to avoid encrypting the data in the original source buffer which
|
||||
may cause problems in some use cases.
|
||||
|
||||
# GPT (GUID Partition Table) {#bdev_config_gpt}
|
||||
|
||||
The GPT virtual bdev driver is enabled by default and does not require any configuration.
|
||||
|
@ -46,10 +46,10 @@ ifneq ($(wildcard $(SPDK_ROOT_DIR)/intel-ipsec-mb/README),)
|
||||
INTEL_IPSEC_MB_LIB=$(SPDK_ROOT_DIR)/intel-ipsec-mb/libIPSec_MB.a
|
||||
IPSEC_MB_CFLAGS = -fPIC
|
||||
CRYPTO_ENABLED = y
|
||||
DPDK_OPTS += AESNI_MULTI_BUFFER_LIB_PATH=$(SPDK_ROOT_DIR)/intel-ipsec-mb
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_CRYPTODEV=y
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_REORDER=y
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_PMD_QAT=n
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@ -58,6 +58,7 @@ ifeq ($(CRYPTO_ENABLED),n)
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_CRYPTODEV=n
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_REORDER=n
|
||||
DPDK_OPTS += CONFIG_RTE_LIBRTE_PMD_QAT=n
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_MACHINE),aarch64)
|
||||
|
@ -44,6 +44,10 @@ LIBNAME = bdev
|
||||
|
||||
DIRS-y += error gpt lvol malloc null nvme passthru rpc split
|
||||
|
||||
ifeq ($(CONFIG_CRYPTO),y)
|
||||
DIRS-y += crypto
|
||||
endif
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
DIRS-y += aio
|
||||
DIRS-$(CONFIG_ISCSI_INITIATOR) += iscsi
|
||||
|
42
lib/bdev/crypto/Makefile
Normal file
42
lib/bdev/crypto/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
CFLAGS += $(ENV_CFLAGS)
|
||||
|
||||
C_SRCS = vbdev_crypto.c vbdev_crypto_rpc.c
|
||||
LIBNAME = vbdev_crypto
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
1506
lib/bdev/crypto/vbdev_crypto.c
Executable file
1506
lib/bdev/crypto/vbdev_crypto.c
Executable file
File diff suppressed because it is too large
Load Diff
66
lib/bdev/crypto/vbdev_crypto.h
Executable file
66
lib/bdev/crypto/vbdev_crypto.h
Executable file
@ -0,0 +1,66 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef SPDK_VBDEV_CRYPTO_H
|
||||
#define SPDK_VBDEV_CRYPTO_H
|
||||
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/util.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
#include "spdk/bdev.h"
|
||||
|
||||
typedef void (*spdk_delete_crypto_complete)(void *cb_arg, int bdeverrno);
|
||||
|
||||
/**
|
||||
* Create new crypto bdev.
|
||||
*
|
||||
* \param bdev_name Bdev on which crypto vbdev will be created.
|
||||
* \param bdev_name Vbdev name crypto_pmd key
|
||||
* \return 0 on success, other on failure.
|
||||
*/
|
||||
int create_crypto_disk(const char *bdev_name, const char *vbdev_name,
|
||||
const char *crypto_pmd, const char *key);
|
||||
|
||||
/**
|
||||
* Delete crypto bdev.
|
||||
*
|
||||
* \param bdev Pointer to crypto bdev.
|
||||
* \param cb_fn Function to call after deletion.
|
||||
* \param cb_arg Argument to pass to cb_fn.
|
||||
*/
|
||||
void delete_crypto_disk(struct spdk_bdev *bdev, spdk_delete_crypto_complete cb_fn,
|
||||
void *cb_arg);
|
||||
|
||||
#endif /* SPDK_VBDEV_CRYPTO_H */
|
163
lib/bdev/crypto/vbdev_crypto_rpc.c
Executable file
163
lib/bdev/crypto/vbdev_crypto_rpc.c
Executable file
@ -0,0 +1,163 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "vbdev_crypto.h"
|
||||
|
||||
/* Structure to hold the parameters for this RPC method. */
|
||||
struct rpc_construct_crypto {
|
||||
char *base_bdev_name;
|
||||
char *crypto_bdev_name;
|
||||
char *crypto_pmd;
|
||||
char *key;
|
||||
};
|
||||
|
||||
/* Free the allocated memory resource after the RPC handling. */
|
||||
static void
|
||||
free_rpc_construct_crypto(struct rpc_construct_crypto *r)
|
||||
{
|
||||
free(r->base_bdev_name);
|
||||
free(r->crypto_bdev_name);
|
||||
free(r->crypto_pmd);
|
||||
free(r->key);
|
||||
}
|
||||
|
||||
/* Structure to decode the input parameters for this RPC method. */
|
||||
static const struct spdk_json_object_decoder rpc_construct_crypto_decoders[] = {
|
||||
{"base_bdev_name", offsetof(struct rpc_construct_crypto, base_bdev_name), spdk_json_decode_string},
|
||||
{"crypto_bdev_name", offsetof(struct rpc_construct_crypto, crypto_bdev_name), spdk_json_decode_string},
|
||||
{"crypto_pmd", offsetof(struct rpc_construct_crypto, crypto_pmd), spdk_json_decode_string},
|
||||
{"key", offsetof(struct rpc_construct_crypto, key), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
/* Decode the parameters for this RPC method and properly construct the crypto
|
||||
* device. Error status returned in the failed cases.
|
||||
*/
|
||||
static void
|
||||
spdk_rpc_construct_crypto_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_crypto req = {NULL};
|
||||
struct spdk_json_write_ctx *w;
|
||||
int rc;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_construct_crypto_decoders,
|
||||
SPDK_COUNTOF(rpc_construct_crypto_decoders),
|
||||
&req)) {
|
||||
SPDK_DEBUGLOG(SPDK_LOG_VBDEV_crypto, "spdk_json_decode_object failed\n");
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
rc = create_crypto_disk(req.base_bdev_name, req.crypto_bdev_name,
|
||||
req.crypto_pmd, req.key);
|
||||
if (rc != 0) {
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
free_rpc_construct_crypto(&req);
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_string(w, req.crypto_bdev_name);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
free_rpc_construct_crypto(&req);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_construct_crypto(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_crypto_bdev", spdk_rpc_construct_crypto_bdev, SPDK_RPC_RUNTIME)
|
||||
|
||||
struct rpc_delete_crypto {
|
||||
char *name;
|
||||
};
|
||||
|
||||
static void
|
||||
free_rpc_delete_crypto(struct rpc_delete_crypto *req)
|
||||
{
|
||||
free(req->name);
|
||||
}
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_delete_crypto_decoders[] = {
|
||||
{"name", offsetof(struct rpc_delete_crypto, name), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
static void
|
||||
_spdk_rpc_delete_crypto_bdev_cb(void *cb_arg, int bdeverrno)
|
||||
{
|
||||
struct spdk_jsonrpc_request *request = cb_arg;
|
||||
struct spdk_json_write_ctx *w;
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, bdeverrno == 0);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_crypto_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_crypto req = {NULL};
|
||||
struct spdk_bdev *bdev;
|
||||
int rc;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_delete_crypto_decoders,
|
||||
SPDK_COUNTOF(rpc_delete_crypto_decoders),
|
||||
&req)) {
|
||||
rc = -EINVAL;
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
bdev = spdk_bdev_get_by_name(req.name);
|
||||
if (bdev == NULL) {
|
||||
rc = -ENODEV;
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
delete_crypto_disk(bdev, _spdk_rpc_delete_crypto_bdev_cb, request);
|
||||
|
||||
free_rpc_delete_crypto(&req);
|
||||
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_delete_crypto(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc));
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_crypto_bdev", spdk_rpc_delete_crypto_bdev, SPDK_RPC_RUNTIME)
|
@ -78,11 +78,18 @@ ifneq (, $(wildcard $(DPDK_ABS_DIR)/lib/librte_bus_pci.*))
|
||||
DPDK_LIB_LIST += rte_bus_pci
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CRYPTO),y)
|
||||
DPDK_LIB_LIST += rte_cryptodev rte_reorder rte_bus_vdev rte_pmd_aesni_mb rte_mbuf
|
||||
endif
|
||||
|
||||
ifneq (, $(wildcard $(DPDK_ABS_DIR)/lib/librte_kvargs.*))
|
||||
DPDK_LIB_LIST += rte_kvargs
|
||||
endif
|
||||
|
||||
DPDK_LIB = $(DPDK_LIB_LIST:%=$(DPDK_ABS_DIR)/lib/lib%$(DPDK_LIB_EXT))
|
||||
ifeq ($(CONFIG_CRYPTO),y)
|
||||
DPDK_LIB += $(SPDK_ROOT_DIR)/intel-ipsec-mb/libIPSec_MB.a
|
||||
endif
|
||||
|
||||
# SPDK memory registration requires experimental (deprecated) rte_memory API for DPDK 18.05
|
||||
ENV_CFLAGS = $(DPDK_INC) -Wno-deprecated-declarations
|
||||
|
@ -38,6 +38,10 @@ LVOL_MODULES_LIST += blob blob_bdev lvol
|
||||
BLOCKDEV_MODULES_LIST = $(LVOL_MODULES_LIST)
|
||||
BLOCKDEV_MODULES_LIST += bdev_malloc bdev_null bdev_nvme nvme vbdev_passthru vbdev_error vbdev_gpt vbdev_split
|
||||
|
||||
ifeq ($(CONFIG_CRYPTO),y)
|
||||
BLOCKDEV_MODULES_LIST += vbdev_crypto
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RDMA),y)
|
||||
BLOCKDEV_MODULES_DEPS += -libverbs -lrdmacm
|
||||
endif
|
||||
|
@ -131,6 +131,30 @@ if __name__ == "__main__":
|
||||
p.add_argument('-c', '--bdev-io-cache-size', help='Maximum number of bdev_io structures cached per thread', type=int)
|
||||
p.set_defaults(func=set_bdev_options)
|
||||
|
||||
@call_cmd
|
||||
def construct_crypto_bdev(args):
|
||||
print(rpc.bdev.construct_crypto_bdev(args.client,
|
||||
base_bdev_name=args.base_bdev_name,
|
||||
crypto_bdev_name=args.crypto_bdev_name,
|
||||
crypto_pmd=args.crypto_pmd,
|
||||
key=args.key))
|
||||
p = subparsers.add_parser('construct_crypto_bdev',
|
||||
help='Add a crypto vbdev')
|
||||
p.add_argument('-b', '--base_bdev_name', help="Name of the base bdev")
|
||||
p.add_argument('-c', '--crypto_bdev_name', help="Name of the crypto vbdev")
|
||||
p.add_argument('-d', '--crypto_pmd', help="Name of the crypto device driver")
|
||||
p.add_argument('-k', '--key', help="Key")
|
||||
p.set_defaults(func=construct_crypto_bdev)
|
||||
|
||||
@call_cmd
|
||||
def delete_crypto_bdev(args):
|
||||
rpc.bdev.delete_crypto_bdev(args.client,
|
||||
name=args.name)
|
||||
|
||||
p = subparsers.add_parser('delete_crypto_bdev', help='Delete a crypto disk')
|
||||
p.add_argument('name', help='crypto bdev name')
|
||||
p.set_defaults(func=delete_crypto_bdev)
|
||||
|
||||
@call_cmd
|
||||
def construct_malloc_bdev(args):
|
||||
num_blocks = (args.total_size * 1024 * 1024) // args.block_size
|
||||
@ -139,7 +163,6 @@ if __name__ == "__main__":
|
||||
block_size=args.block_size,
|
||||
name=args.name,
|
||||
uuid=args.uuid))
|
||||
|
||||
p = subparsers.add_parser('construct_malloc_bdev',
|
||||
help='Add a bdev with malloc backend')
|
||||
p.add_argument('-b', '--name', help="Name of the bdev")
|
||||
|
@ -15,6 +15,33 @@ def set_bdev_options(client, bdev_io_pool_size=None, bdev_io_cache_size=None):
|
||||
return client.call('set_bdev_options', params)
|
||||
|
||||
|
||||
def construct_crypto_bdev(client, base_bdev_name, crypto_bdev_name, crypto_pmd, key):
|
||||
"""Construct a crypto virtual block device.
|
||||
|
||||
Args:
|
||||
base_bdev_name: name of the underlying base bdev
|
||||
crypto_bdev_name: name for the crypto vbdev
|
||||
crypto_pmd: name of of the DPDK crypto driver to use
|
||||
key: key
|
||||
|
||||
Returns:
|
||||
Name of created virtual block device.
|
||||
"""
|
||||
params = {'base_bdev_name': base_bdev_name, 'crypto_bdev_name': crypto_bdev_name, 'crypto_pmd': crypto_pmd, 'key': key}
|
||||
|
||||
return client.call('construct_crypto_bdev', params)
|
||||
|
||||
|
||||
def delete_crypto_bdev(client, name):
|
||||
"""Delete crypto virtual block device.
|
||||
|
||||
Args:
|
||||
bdev_name: name of crypto vbdev to delete
|
||||
"""
|
||||
params = {'name': name}
|
||||
return client.call('delete_crypto_bdev', params)
|
||||
|
||||
|
||||
def construct_malloc_bdev(client, num_blocks, block_size, name=None, uuid=None):
|
||||
"""Construct a malloc block device.
|
||||
|
||||
|
@ -2,8 +2,15 @@
|
||||
# PT <bdev name> <vbdev name>
|
||||
PT Malloc3 TestPT
|
||||
|
||||
[crypto]
|
||||
# CRY <bdev name> <vbdev name> <key> <PMD>
|
||||
# key size depends on cipher
|
||||
# supported PMD names: crypto_aesni_mb, crypto_qat
|
||||
# Note: QAT is experimental while test HW is being setup
|
||||
CRY Malloc6 crypto_ram 0123456789123456 crypto_aesni_mb
|
||||
|
||||
[Malloc]
|
||||
NumberOfLuns 6
|
||||
NumberOfLuns 7
|
||||
LunSizeInMB 64
|
||||
|
||||
[Split]
|
||||
|
@ -58,6 +58,7 @@ fi
|
||||
: ${SPDK_RUN_ASAN=1}; export SPDK_RUN_ASAN
|
||||
: ${SPDK_RUN_UBSAN=1}; export SPDK_RUN_UBSAN
|
||||
: ${SPDK_RUN_INSTALLED_DPDK=1}; export SPDK_RUN_INSTALLED_DPDK
|
||||
: ${SPDK_TEST_CRYPTO=1}; export SPDK_TEST_CRYPTO
|
||||
|
||||
if [ -z "$DEPENDENCY_DIR" ]; then
|
||||
export DEPENDENCY_DIR=/home/sys_sgsw
|
||||
@ -86,6 +87,10 @@ fi
|
||||
# sure it gets built and run against a limited set of use cases for now.
|
||||
config_params+=' --with-raid'
|
||||
|
||||
if [ $SPDK_TEST_CRYPTO -eq 1 ]; then
|
||||
config_params+=' --with-crypto'
|
||||
fi
|
||||
|
||||
export UBSAN_OPTIONS='halt_on_error=1:print_stacktrace=1:abort_on_error=1'
|
||||
|
||||
# On Linux systems, override the default HUGEMEM in scripts/setup.sh to
|
||||
|
@ -87,7 +87,7 @@ if [ `uname` = Linux ]; then
|
||||
fi
|
||||
|
||||
if [ `uname` = Linux ]; then
|
||||
start_stub "-s 2048 -i 0 -m 0xF"
|
||||
start_stub "-s 4096 -i 0 -m 0xF"
|
||||
trap "kill_stub; exit 1" SIGINT SIGTERM EXIT
|
||||
fi
|
||||
|
||||
|
@ -36,6 +36,10 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
DIRS-y = bdev.c part.c scsi_nvme.c gpt vbdev_lvol.c mt bdev_raid.c
|
||||
|
||||
ifeq ($(CONFIG_CRYPTO),y)
|
||||
DIRS-y += crypto.c
|
||||
endif
|
||||
|
||||
DIRS-$(CONFIG_PMDK) += pmem
|
||||
|
||||
.PHONY: all clean $(DIRS-y)
|
||||
|
1
test/unit/lib/bdev/crypto.c/.gitignore
vendored
Normal file
1
test/unit/lib/bdev/crypto.c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
crypto_ut
|
41
test/unit/lib/bdev/crypto.c/Makefile
Normal file
41
test/unit/lib/bdev/crypto.c/Makefile
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
|
||||
|
||||
TEST_FILE = crypto_ut.c
|
||||
CFLAGS += $(ENV_CFLAGS)
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk
|
908
test/unit/lib/bdev/crypto.c/crypto_ut.c
Executable file
908
test/unit/lib/bdev/crypto.c/crypto_ut.c
Executable file
@ -0,0 +1,908 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "spdk_cunit.h"
|
||||
|
||||
#include "common/lib/test_env.c"
|
||||
#include "spdk_internal/mock.h"
|
||||
#include "unit/lib/json_mock.c"
|
||||
|
||||
/* these rte_ headers are our local copies of the DPDK headers hacked to mock some functions
|
||||
* included in them that can't be done with our mock library.
|
||||
*/
|
||||
#include "rte_crypto.h"
|
||||
#include "rte_cryptodev.h"
|
||||
DEFINE_STUB_V(rte_crypto_op_free, (struct rte_crypto_op *op));
|
||||
#include "bdev/crypto/vbdev_crypto.c"
|
||||
|
||||
/* SPDK stubs */
|
||||
DEFINE_STUB(spdk_conf_find_section, struct spdk_conf_section *,
|
||||
(struct spdk_conf *cp, const char *name), NULL);
|
||||
DEFINE_STUB(spdk_conf_section_get_nval, char *,
|
||||
(struct spdk_conf_section *sp, const char *key, int idx), NULL);
|
||||
DEFINE_STUB(spdk_conf_section_get_nmval, char *,
|
||||
(struct spdk_conf_section *sp, const char *key, int idx1, int idx2), NULL);
|
||||
|
||||
DEFINE_STUB_V(spdk_bdev_module_list_add, (struct spdk_bdev_module *bdev_module));
|
||||
DEFINE_STUB_V(spdk_bdev_free_io, (struct spdk_bdev_io *g_bdev_io));
|
||||
DEFINE_STUB(spdk_bdev_io_type_supported, bool, (struct spdk_bdev *bdev,
|
||||
enum spdk_bdev_io_type io_type), 0);
|
||||
DEFINE_STUB_V(spdk_bdev_module_release_bdev, (struct spdk_bdev *bdev));
|
||||
DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc));
|
||||
DEFINE_STUB(spdk_bdev_get_name, const char *, (const struct spdk_bdev *bdev), 0);
|
||||
DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), 0);
|
||||
DEFINE_STUB(spdk_bdev_get_io_channel, struct spdk_io_channel *, (struct spdk_bdev_desc *desc), 0);
|
||||
DEFINE_STUB_V(spdk_bdev_unregister, (struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn,
|
||||
void *cb_arg));
|
||||
DEFINE_STUB(spdk_bdev_open, int, (struct spdk_bdev *bdev, bool write,
|
||||
spdk_bdev_remove_cb_t remove_cb,
|
||||
void *remove_ctx, struct spdk_bdev_desc **_desc), 0);
|
||||
DEFINE_STUB(spdk_bdev_module_claim_bdev, int, (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
|
||||
struct spdk_bdev_module *module), 0);
|
||||
DEFINE_STUB_V(spdk_bdev_module_examine_done, (struct spdk_bdev_module *module));
|
||||
DEFINE_STUB(spdk_vbdev_register, int, (struct spdk_bdev *vbdev, struct spdk_bdev **base_bdevs,
|
||||
int base_bdev_count), 0);
|
||||
DEFINE_STUB(spdk_bdev_get_by_name, struct spdk_bdev *, (const char *bdev_name), NULL);
|
||||
DEFINE_STUB(spdk_env_get_socket_id, uint32_t, (uint32_t core), 0);
|
||||
|
||||
/* DPDK stubs */
|
||||
DEFINE_STUB(rte_cryptodev_count, uint8_t, (void), 0);
|
||||
DEFINE_STUB(rte_eal_get_configuration, struct rte_config *, (void), NULL);
|
||||
DEFINE_STUB_V(rte_mempool_free, (struct rte_mempool *mp));
|
||||
DEFINE_STUB(rte_socket_id, unsigned, (void), 0);
|
||||
DEFINE_STUB(rte_crypto_op_pool_create, struct rte_mempool *,
|
||||
(const char *name, enum rte_crypto_op_type type, unsigned nb_elts,
|
||||
unsigned cache_size, uint16_t priv_size, int socket_id), (struct rte_mempool *)1);
|
||||
DEFINE_STUB(rte_cryptodev_device_count_by_driver, uint8_t, (uint8_t driver_id), 0);
|
||||
DEFINE_STUB(rte_cryptodev_socket_id, int, (uint8_t dev_id), 0);
|
||||
DEFINE_STUB(rte_cryptodev_configure, int, (uint8_t dev_id, struct rte_cryptodev_config *config), 0);
|
||||
DEFINE_STUB(rte_cryptodev_queue_pair_setup, int, (uint8_t dev_id, uint16_t queue_pair_id,
|
||||
const struct rte_cryptodev_qp_conf *qp_conf,
|
||||
int socket_id, struct rte_mempool *session_pool), 0);
|
||||
DEFINE_STUB(rte_cryptodev_start, int, (uint8_t dev_id), 0)
|
||||
DEFINE_STUB_V(rte_cryptodev_stop, (uint8_t dev_id));
|
||||
DEFINE_STUB(rte_cryptodev_sym_session_create, struct rte_cryptodev_sym_session *,
|
||||
(struct rte_mempool *mempool), (struct rte_cryptodev_sym_session *)1);
|
||||
DEFINE_STUB(rte_cryptodev_sym_session_clear, int, (uint8_t dev_id,
|
||||
struct rte_cryptodev_sym_session *sess), 0);
|
||||
DEFINE_STUB(rte_cryptodev_sym_session_free, int, (struct rte_cryptodev_sym_session *sess), 0);
|
||||
DEFINE_STUB(rte_cryptodev_sym_session_init, int, (uint8_t dev_id,
|
||||
struct rte_cryptodev_sym_session *sess,
|
||||
struct rte_crypto_sym_xform *xforms, struct rte_mempool *mempool), 0);
|
||||
DEFINE_STUB(rte_vdev_init, int, (const char *name, const char *args), 0);
|
||||
void __attribute__((noreturn)) __rte_panic(const char *funcname, const char *format, ...)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
struct rte_mempool_ops_table rte_mempool_ops_table;
|
||||
struct rte_cryptodev *rte_cryptodevs;
|
||||
__thread unsigned per_lcore__lcore_id = 0;
|
||||
|
||||
/* global vars and setup/cleanup functions used for all test functions */
|
||||
struct spdk_bdev_io *g_bdev_io;
|
||||
struct crypto_bdev_io *g_io_ctx;
|
||||
struct crypto_io_channel *g_crypto_ch;
|
||||
struct spdk_io_channel *g_io_ch;
|
||||
struct vbdev_dev g_device;
|
||||
struct vbdev_crypto g_crypto_bdev;
|
||||
struct rte_config *g_test_config;
|
||||
struct device_qp g_dev_qp;
|
||||
|
||||
#define MAX_TEST_BLOCKS 8192
|
||||
struct rte_crypto_op *g_test_crypto_ops[MAX_TEST_BLOCKS];
|
||||
struct rte_crypto_op *g_test_dequeued_ops[MAX_TEST_BLOCKS];
|
||||
struct rte_crypto_op *g_test_dev_full_ops[MAX_TEST_BLOCKS];
|
||||
|
||||
/* These globals are externs in our local rte_ header files so we can control
|
||||
* specific functions for mocking.
|
||||
*/
|
||||
uint16_t g_dequeue_mock;
|
||||
uint16_t g_enqueue_mock;
|
||||
unsigned ut_rte_crypto_op_bulk_alloc;
|
||||
int ut_rte_crypto_op_attach_sym_session = 0;
|
||||
|
||||
int ut_rte_cryptodev_info_get = 0;
|
||||
bool ut_rte_cryptodev_info_get_mocked = false;
|
||||
void
|
||||
rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
|
||||
{
|
||||
dev_info->max_nb_queue_pairs = ut_rte_cryptodev_info_get;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
|
||||
{
|
||||
return (unsigned int)dev_id;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, uint64_t len)
|
||||
{
|
||||
cb(g_io_ch, g_bdev_io);
|
||||
}
|
||||
|
||||
/* Mock these functions to call the callback and then return the value we require */
|
||||
int ut_spdk_bdev_readv_blocks = 0;
|
||||
bool ut_spdk_bdev_readv_blocks_mocked = false;
|
||||
int
|
||||
spdk_bdev_readv_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
struct iovec *iov, int iovcnt,
|
||||
uint64_t offset_blocks, uint64_t num_blocks,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
cb(g_bdev_io, !ut_spdk_bdev_readv_blocks, cb_arg);
|
||||
return ut_spdk_bdev_readv_blocks;
|
||||
}
|
||||
|
||||
int ut_spdk_bdev_writev_blocks = 0;
|
||||
bool ut_spdk_bdev_writev_blocks_mocked = false;
|
||||
int
|
||||
spdk_bdev_writev_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
struct iovec *iov, int iovcnt,
|
||||
uint64_t offset_blocks, uint64_t num_blocks,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
cb(g_bdev_io, !ut_spdk_bdev_writev_blocks, cb_arg);
|
||||
return ut_spdk_bdev_writev_blocks;
|
||||
}
|
||||
|
||||
int ut_spdk_bdev_unmap_blocks = 0;
|
||||
bool ut_spdk_bdev_unmap_blocks_mocked = false;
|
||||
int
|
||||
spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
uint64_t offset_blocks, uint64_t num_blocks,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
cb(g_bdev_io, !ut_spdk_bdev_unmap_blocks, cb_arg);
|
||||
return ut_spdk_bdev_unmap_blocks;
|
||||
}
|
||||
|
||||
int ut_spdk_bdev_flush_blocks = 0;
|
||||
bool ut_spdk_bdev_flush_blocks_mocked = false;
|
||||
int
|
||||
spdk_bdev_flush_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
uint64_t offset_blocks, uint64_t num_blocks, spdk_bdev_io_completion_cb cb,
|
||||
void *cb_arg)
|
||||
{
|
||||
cb(g_bdev_io, !ut_spdk_bdev_flush_blocks, cb_arg);
|
||||
return ut_spdk_bdev_flush_blocks;
|
||||
}
|
||||
|
||||
int ut_spdk_bdev_reset = 0;
|
||||
bool ut_spdk_bdev_reset_mocked = false;
|
||||
int
|
||||
spdk_bdev_reset(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
cb(g_bdev_io, !ut_spdk_bdev_reset, cb_arg);
|
||||
return ut_spdk_bdev_reset;
|
||||
}
|
||||
|
||||
bool g_completion_called = false;
|
||||
void
|
||||
spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status status)
|
||||
{
|
||||
bdev_io->internal.status = status;
|
||||
g_completion_called = true;
|
||||
}
|
||||
|
||||
/* Used in testing device full condition */
|
||||
static inline uint16_t
|
||||
rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
|
||||
struct rte_crypto_op **ops, uint16_t nb_ops)
|
||||
{
|
||||
int i;
|
||||
|
||||
CU_ASSERT(nb_ops > 0);
|
||||
|
||||
for (i = 0; i < nb_ops; i++) {
|
||||
/* Use this empty (til now) array of pointers to store
|
||||
* enqueued operations for assertion in dev_full test.
|
||||
*/
|
||||
g_test_dev_full_ops[i] = *ops++;
|
||||
}
|
||||
|
||||
return g_enqueue_mock;
|
||||
}
|
||||
|
||||
/* This is pretty ugly but in order to complete an IO via the
|
||||
* poller in the submit path, we need to first call to this func
|
||||
* to return the dequeued value and also decrement it. On the subsequent
|
||||
* call it needs to return 0 to indicate to the caller that there are
|
||||
* no more IOs to drain.
|
||||
*/
|
||||
int g_test_overflow = 0;
|
||||
static inline uint16_t
|
||||
rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
|
||||
struct rte_crypto_op **ops, uint16_t nb_ops)
|
||||
{
|
||||
CU_ASSERT(nb_ops > 0);
|
||||
|
||||
/* A crypto device can be full on enqueue, the driver is designed to drain
|
||||
* the device at the time by calling the poller until it's empty, then
|
||||
* submitting the remaining crypto ops.
|
||||
*/
|
||||
if (g_test_overflow) {
|
||||
if (g_dequeue_mock == 0) {
|
||||
return 0;
|
||||
}
|
||||
*ops = g_test_crypto_ops[g_enqueue_mock];
|
||||
(*ops)->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
|
||||
g_dequeue_mock -= 1;
|
||||
}
|
||||
return (g_dequeue_mock + 1);
|
||||
}
|
||||
|
||||
/* Instead of allocating real memory, assign the allocations to our
|
||||
* test array for assertion in tests.
|
||||
*/
|
||||
static inline unsigned
|
||||
rte_crypto_op_bulk_alloc(struct rte_mempool *mempool,
|
||||
enum rte_crypto_op_type type,
|
||||
struct rte_crypto_op **ops, uint16_t nb_ops)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nb_ops; i++) {
|
||||
*ops++ = g_test_crypto_ops[i];
|
||||
}
|
||||
return ut_rte_crypto_op_bulk_alloc;
|
||||
}
|
||||
|
||||
static __rte_always_inline void
|
||||
rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table,
|
||||
unsigned int n)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static inline int
|
||||
rte_crypto_op_attach_sym_session(struct rte_crypto_op *op,
|
||||
struct rte_cryptodev_sym_session *sess)
|
||||
{
|
||||
return ut_rte_crypto_op_attach_sym_session;
|
||||
}
|
||||
|
||||
/* Global setup for all tests that share a bunch of preparation... */
|
||||
static int
|
||||
test_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Prepare essential variables for test routines */
|
||||
g_bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct crypto_bdev_io));
|
||||
g_bdev_io->u.bdev.iovs = calloc(1, sizeof(struct iovec) * 128);
|
||||
g_bdev_io->bdev = &g_crypto_bdev.crypto_bdev;
|
||||
g_io_ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct crypto_io_channel));
|
||||
g_crypto_ch = (struct crypto_io_channel *)((uint8_t *)g_io_ch + sizeof(struct spdk_io_channel));
|
||||
g_io_ctx = (struct crypto_bdev_io *)g_bdev_io->driver_ctx;
|
||||
memset(&g_device, 0, sizeof(struct vbdev_dev));
|
||||
memset(&g_crypto_bdev, 0, sizeof(struct vbdev_crypto));
|
||||
g_dev_qp.device = &g_device;
|
||||
g_io_ctx->crypto_ch = g_crypto_ch;
|
||||
g_io_ctx->crypto_bdev = &g_crypto_bdev;
|
||||
g_crypto_ch->device_qp = &g_dev_qp;
|
||||
g_test_config = calloc(1, sizeof(struct rte_config));
|
||||
g_test_config->lcore_count = 1;
|
||||
|
||||
/* Allocate a real mbuf pool so we can test error paths */
|
||||
g_mbuf_mp = spdk_mempool_create("mbuf_mp", NUM_MBUFS, sizeof(struct rte_mbuf),
|
||||
SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
|
||||
SPDK_ENV_SOCKET_ID_ANY);
|
||||
|
||||
/* Instead of allocating real rte mempools for these, it's easier and provides the
|
||||
* same coverage just calloc them here.
|
||||
*/
|
||||
for (i = 0; i < MAX_TEST_BLOCKS; i++) {
|
||||
g_test_crypto_ops[i] = calloc(1, sizeof(struct rte_crypto_op) +
|
||||
sizeof(struct rte_crypto_sym_op));
|
||||
g_test_dequeued_ops[i] = calloc(1, sizeof(struct rte_crypto_op) +
|
||||
sizeof(struct rte_crypto_sym_op));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Global teardown for all tests */
|
||||
static int
|
||||
test_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
free(g_test_config);
|
||||
spdk_mempool_free(g_mbuf_mp);
|
||||
for (i = 0; i < MAX_TEST_BLOCKS; i++) {
|
||||
free(g_test_crypto_ops[i]);
|
||||
free(g_test_dequeued_ops[i]);
|
||||
}
|
||||
free(g_bdev_io->u.bdev.iovs);
|
||||
free(g_bdev_io);
|
||||
free(g_io_ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_error_paths(void)
|
||||
{
|
||||
/* Single element block size write, just to test error paths
|
||||
* in vbdev_crypto_submit_request().
|
||||
*/
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 1;
|
||||
g_bdev_io->u.bdev.num_blocks = 1;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = 512;
|
||||
g_crypto_bdev.crypto_bdev.blocklen = 512;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = 1;
|
||||
|
||||
/* test failure of spdk_mempool_get_bulk() */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
MOCK_SET(spdk_mempool_get, NULL);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
|
||||
/* same thing but switch to reads to test error path in _crypto_complete_io() */
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
/* Now with the read_blocks failing */
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
MOCK_SET(spdk_bdev_readv_blocks, -1);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
MOCK_SET(spdk_bdev_readv_blocks, 0);
|
||||
MOCK_CLEAR(spdk_mempool_get);
|
||||
|
||||
/* test failure of rte_crypto_op_bulk_alloc() */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
ut_rte_crypto_op_bulk_alloc = 0;
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
ut_rte_crypto_op_bulk_alloc = 1;
|
||||
|
||||
/* test failure of rte_cryptodev_sym_session_create() */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
MOCK_SET(rte_cryptodev_sym_session_create, NULL);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
MOCK_SET(rte_cryptodev_sym_session_create, (struct rte_cryptodev_sym_session *)1);
|
||||
|
||||
/* test failure of rte_cryptodev_sym_session_init() */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
MOCK_SET(rte_cryptodev_sym_session_init, -1);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
MOCK_SET(rte_cryptodev_sym_session_init, 0);
|
||||
|
||||
/* test failure of rte_crypto_op_attach_sym_session() */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
ut_rte_crypto_op_attach_sym_session = -1;
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
ut_rte_crypto_op_attach_sym_session = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_simple_write(void)
|
||||
{
|
||||
/* Single element block size write */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 1;
|
||||
g_bdev_io->u.bdev.num_blocks = 1;
|
||||
g_bdev_io->u.bdev.offset_blocks = 0;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = 512;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_simple_write;
|
||||
g_crypto_bdev.crypto_bdev.blocklen = 512;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = 1;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == 1);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT);
|
||||
CU_ASSERT(g_io_ctx->cry_iov.iov_len == 512);
|
||||
CU_ASSERT(g_io_ctx->cry_iov.iov_base != NULL);
|
||||
CU_ASSERT(g_io_ctx->cry_offset_blocks == 0);
|
||||
CU_ASSERT(g_io_ctx->cry_num_blocks == 1);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->buf_addr == &test_simple_write);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->data_len == 512);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->next == NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->cipher.data.length == 512);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->userdata == g_bdev_io);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_dst->buf_addr != NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_dst->data_len == 512);
|
||||
|
||||
spdk_dma_free(g_io_ctx->cry_iov.iov_base);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[0]->sym->m_src);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[0]->sym->m_dst);
|
||||
}
|
||||
|
||||
static void
|
||||
test_simple_read(void)
|
||||
{
|
||||
/* Single element block size read */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 1;
|
||||
g_bdev_io->u.bdev.num_blocks = 1;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = 512;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_simple_read;
|
||||
g_crypto_bdev.crypto_bdev.blocklen = 512;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = 1;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == 1);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->buf_addr == &test_simple_read);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->data_len == 512);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->next == NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->cipher.data.length == 512);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->userdata == g_bdev_io);
|
||||
CU_ASSERT(g_test_crypto_ops[0]->sym->m_dst == NULL);
|
||||
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[0]->sym->m_src);
|
||||
}
|
||||
|
||||
static void
|
||||
test_large_rw(void)
|
||||
{
|
||||
unsigned block_len = 512;
|
||||
unsigned num_blocks = CRYPTO_MAX_IO / block_len;
|
||||
unsigned io_len = block_len * num_blocks;
|
||||
unsigned i;
|
||||
|
||||
/* Multi block size read, multi-element */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 1;
|
||||
g_bdev_io->u.bdev.num_blocks = num_blocks;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = io_len;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_large_rw;
|
||||
g_crypto_bdev.crypto_bdev.blocklen = block_len;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = num_blocks;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == (int)num_blocks);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
|
||||
|
||||
for (i = 0; i < num_blocks; i++) {
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_large_rw + (i * block_len));
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->data_len == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->next == NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.length == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->userdata == g_bdev_io);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_dst == NULL);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_src);
|
||||
}
|
||||
|
||||
/* Multi block size write, multi-element */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 1;
|
||||
g_bdev_io->u.bdev.num_blocks = num_blocks;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = io_len;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_large_rw;
|
||||
g_crypto_bdev.crypto_bdev.blocklen = block_len;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = num_blocks;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == (int)num_blocks);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT);
|
||||
|
||||
for (i = 0; i < num_blocks; i++) {
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_large_rw + (i * block_len));
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->data_len == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->next == NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.length == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->userdata == g_bdev_io);
|
||||
CU_ASSERT(g_io_ctx->cry_iov.iov_len == io_len);
|
||||
CU_ASSERT(g_io_ctx->cry_iov.iov_base != NULL);
|
||||
CU_ASSERT(g_io_ctx->cry_offset_blocks == 0);
|
||||
CU_ASSERT(g_io_ctx->cry_num_blocks == num_blocks);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_dst->buf_addr != NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_dst->data_len == block_len);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_src);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_dst);
|
||||
}
|
||||
spdk_dma_free(g_io_ctx->cry_iov.iov_base);
|
||||
}
|
||||
|
||||
static void
|
||||
test_dev_full(void)
|
||||
{
|
||||
unsigned block_len = 512;
|
||||
unsigned num_blocks = 2;
|
||||
unsigned io_len = block_len * num_blocks;
|
||||
unsigned i;
|
||||
|
||||
g_test_overflow = 1;
|
||||
|
||||
/* Multi block size read, multi-element */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 1;
|
||||
g_bdev_io->u.bdev.num_blocks = num_blocks;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = io_len;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_dev_full;
|
||||
g_crypto_bdev.crypto_bdev.blocklen = block_len;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_enqueue_mock = g_dequeue_mock = 1;
|
||||
ut_rte_crypto_op_bulk_alloc = num_blocks;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
|
||||
/* this test only completes one of the 2 IOs (in the drain path) */
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == 1);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
|
||||
|
||||
for (i = 0; i < num_blocks; i++) {
|
||||
/* One of the src_mbufs was freed because of the device full condition so
|
||||
* we can't assert its value here.
|
||||
*/
|
||||
CU_ASSERT(g_test_dev_full_ops[i]->sym->cipher.data.length == block_len);
|
||||
CU_ASSERT(g_test_dev_full_ops[i]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_dev_full_ops[i]->sym->m_src == g_test_dev_full_ops[i]->sym->m_src);
|
||||
CU_ASSERT(g_test_dev_full_ops[i]->sym->m_dst == NULL);
|
||||
}
|
||||
|
||||
/* Only one of the 2 blocks in the test was freed on completion by design, so
|
||||
* we need to free th other one here.
|
||||
*/
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[0]->sym->m_src);
|
||||
g_test_overflow = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_crazy_rw(void)
|
||||
{
|
||||
unsigned block_len = 512;
|
||||
int num_blocks = 4;
|
||||
int i;
|
||||
|
||||
/* Multi block size read, single element, strange IOV makeup */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 3;
|
||||
g_bdev_io->u.bdev.num_blocks = num_blocks;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = 512;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_crazy_rw;
|
||||
g_bdev_io->u.bdev.iovs[1].iov_len = 1024;
|
||||
g_bdev_io->u.bdev.iovs[1].iov_base = &test_crazy_rw + 512;
|
||||
g_bdev_io->u.bdev.iovs[2].iov_len = 512;
|
||||
g_bdev_io->u.bdev.iovs[2].iov_base = &test_crazy_rw + 512 + 1024;
|
||||
|
||||
g_crypto_bdev.crypto_bdev.blocklen = block_len;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = num_blocks;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == num_blocks);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
|
||||
|
||||
for (i = 0; i < num_blocks; i++) {
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_crazy_rw + (i * block_len));
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->data_len == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->next == NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.length == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->userdata == g_bdev_io);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src == g_test_crypto_ops[i]->sym->m_src);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_dst == NULL);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_src);
|
||||
}
|
||||
|
||||
/* Multi block size write, single element strange IOV makeup */
|
||||
num_blocks = 8;
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->u.bdev.iovcnt = 4;
|
||||
g_bdev_io->u.bdev.num_blocks = num_blocks;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_len = 2048;
|
||||
g_bdev_io->u.bdev.iovs[0].iov_base = &test_crazy_rw;
|
||||
g_bdev_io->u.bdev.iovs[1].iov_len = 512;
|
||||
g_bdev_io->u.bdev.iovs[1].iov_base = &test_crazy_rw + 2048;
|
||||
g_bdev_io->u.bdev.iovs[2].iov_len = 512;
|
||||
g_bdev_io->u.bdev.iovs[2].iov_base = &test_crazy_rw + 2048 + 512;
|
||||
g_bdev_io->u.bdev.iovs[3].iov_len = 1024;
|
||||
g_bdev_io->u.bdev.iovs[3].iov_base = &test_crazy_rw + 2048 + 512 + 512;
|
||||
|
||||
g_crypto_bdev.crypto_bdev.blocklen = block_len;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
g_enqueue_mock = g_dequeue_mock = ut_rte_crypto_op_bulk_alloc = num_blocks;
|
||||
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_io_ctx->cryop_cnt_remaining == num_blocks);
|
||||
CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT);
|
||||
|
||||
for (i = 0; i < num_blocks; i++) {
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_crazy_rw + (i * block_len));
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->data_len == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->next == NULL);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.length == block_len);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->cipher.data.offset == 0);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->userdata == g_bdev_io);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_src == g_test_crypto_ops[i]->sym->m_src);
|
||||
CU_ASSERT(g_test_crypto_ops[i]->sym->m_dst == g_test_crypto_ops[i]->sym->m_dst);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_src);
|
||||
spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_dst);
|
||||
}
|
||||
spdk_dma_free(g_io_ctx->cry_iov.iov_base);
|
||||
}
|
||||
|
||||
static void
|
||||
test_passthru(void)
|
||||
{
|
||||
/* Make sure these follow our completion callback, test success & fail. */
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_UNMAP;
|
||||
MOCK_SET(spdk_bdev_unmap_blocks, 0);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
MOCK_SET(spdk_bdev_unmap_blocks, -1);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
MOCK_CLEAR(spdk_bdev_unmap_blocks);
|
||||
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_FLUSH;
|
||||
MOCK_SET(spdk_bdev_flush_blocks, 0);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
MOCK_SET(spdk_bdev_flush_blocks, -1);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
MOCK_CLEAR(spdk_bdev_flush_blocks);
|
||||
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_RESET;
|
||||
MOCK_SET(spdk_bdev_reset, 0);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
MOCK_SET(spdk_bdev_reset, -1);
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
MOCK_CLEAR(spdk_bdev_reset);
|
||||
|
||||
/* We should never get a WZ command, we report that we don't support it. */
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE_ZEROES;
|
||||
vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
}
|
||||
|
||||
static void
|
||||
test_initdrivers(void)
|
||||
{
|
||||
int rc;
|
||||
static struct spdk_mempool *orig_mbuf_mp;
|
||||
static struct spdk_mempool *orig_session_mp;
|
||||
|
||||
/* No drivers available, not an error though */
|
||||
MOCK_SET(rte_eal_get_configuration, g_test_config);
|
||||
MOCK_SET(rte_cryptodev_count, 0);
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* Test failure of DPDK dev init. */
|
||||
MOCK_SET(rte_cryptodev_count, 2);
|
||||
MOCK_SET(rte_vdev_init, -1);
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
MOCK_SET(rte_vdev_init, 0);
|
||||
|
||||
/* Can't create session pool. */
|
||||
MOCK_SET(spdk_mempool_create, NULL);
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
orig_session_mp = g_session_mp;
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
g_session_mp = orig_session_mp;
|
||||
CU_ASSERT(rc == -ENOMEM);
|
||||
MOCK_CLEAR(spdk_mempool_create);
|
||||
|
||||
/* Can't create op pool. These tests will alloc and free our g_mbuf_mp
|
||||
* so save that off here and restore it after each test is over.
|
||||
*/
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
orig_session_mp = g_session_mp;
|
||||
MOCK_SET(rte_crypto_op_pool_create, NULL);
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
g_session_mp = orig_session_mp;
|
||||
CU_ASSERT(rc == -ENOMEM);
|
||||
MOCK_SET(rte_crypto_op_pool_create, (struct rte_mempool *)1);
|
||||
|
||||
/* Check resources are sufficient failure. */
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
orig_session_mp = g_session_mp;
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
g_session_mp = orig_session_mp;
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
|
||||
/* Test crypto dev configure failure. */
|
||||
MOCK_SET(rte_cryptodev_device_count_by_driver, 2);
|
||||
MOCK_SET(rte_cryptodev_info_get, 1);
|
||||
MOCK_SET(rte_cryptodev_configure, -1);
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
orig_session_mp = g_session_mp;
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
g_session_mp = orig_session_mp;
|
||||
MOCK_SET(rte_cryptodev_configure, 0);
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
|
||||
/* Test failure of qp setup. */
|
||||
MOCK_SET(rte_cryptodev_queue_pair_setup, -1);
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
orig_session_mp = g_session_mp;
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
g_session_mp = orig_session_mp;
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
MOCK_SET(rte_cryptodev_queue_pair_setup, 0);
|
||||
|
||||
/* Test failure of dev start. */
|
||||
MOCK_SET(rte_cryptodev_start, -1);
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
orig_session_mp = g_session_mp;
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
g_session_mp = orig_session_mp;
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
MOCK_SET(rte_cryptodev_start, 0);
|
||||
|
||||
/* Test happy path. */
|
||||
rc = vbdev_crypto_init_crypto_drivers();
|
||||
CU_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_crypto_op_complete(void)
|
||||
{
|
||||
/* Make sure completion code respects failure. */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_FAILED;
|
||||
g_completion_called = false;
|
||||
_crypto_operation_complete(g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
CU_ASSERT(g_completion_called == true);
|
||||
|
||||
/* Test read completion. */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
|
||||
g_completion_called = false;
|
||||
_crypto_operation_complete(g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_completion_called == true);
|
||||
|
||||
/* Test write completion success. */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
g_completion_called = false;
|
||||
MOCK_SET(spdk_bdev_writev_blocks, 0);
|
||||
/* Code under test will free this, if not ASAN will complain. */
|
||||
g_io_ctx->cry_iov.iov_base = spdk_dma_malloc(16, 0x10, NULL);
|
||||
_crypto_operation_complete(g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
|
||||
CU_ASSERT(g_completion_called == true);
|
||||
|
||||
/* Test write completion failed. */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||
g_completion_called = false;
|
||||
MOCK_SET(spdk_bdev_writev_blocks, -1);
|
||||
/* Code under test will free this, if not ASAN will complain. */
|
||||
g_io_ctx->cry_iov.iov_base = spdk_dma_malloc(16, 0x10, NULL);
|
||||
_crypto_operation_complete(g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
CU_ASSERT(g_completion_called == true);
|
||||
|
||||
/* Test bogus type for this completion. */
|
||||
g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
g_bdev_io->type = SPDK_BDEV_IO_TYPE_RESET;
|
||||
g_completion_called = false;
|
||||
_crypto_operation_complete(g_bdev_io);
|
||||
CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
|
||||
CU_ASSERT(g_completion_called == true);
|
||||
}
|
||||
|
||||
static void
|
||||
test_supported_io(void)
|
||||
{
|
||||
void *ctx = NULL;
|
||||
bool rc = true;
|
||||
|
||||
/* Make sure we always report false to WZ, we need the bdev layer to
|
||||
* send real 0's so we can encrypt/decrypt them.
|
||||
*/
|
||||
rc = vbdev_crypto_io_type_supported(ctx, SPDK_BDEV_IO_TYPE_WRITE_ZEROES);
|
||||
CU_ASSERT(rc == false);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
CU_pSuite suite = NULL;
|
||||
unsigned int num_failures;
|
||||
|
||||
if (CU_initialize_registry() != CUE_SUCCESS) {
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
suite = CU_add_suite("crypto", test_setup, test_cleanup);
|
||||
if (suite == NULL) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
if (CU_add_test(suite, "test_error_paths",
|
||||
test_error_paths) == NULL ||
|
||||
CU_add_test(suite, "test_simple_write",
|
||||
test_simple_write) == NULL ||
|
||||
CU_add_test(suite, "test_simple_read",
|
||||
test_simple_read) == NULL ||
|
||||
CU_add_test(suite, "test_large_rw",
|
||||
test_large_rw) == NULL ||
|
||||
CU_add_test(suite, "test_dev_full",
|
||||
test_dev_full) == NULL ||
|
||||
CU_add_test(suite, "test_crazy_rw",
|
||||
test_crazy_rw) == NULL ||
|
||||
CU_add_test(suite, "test_passthru",
|
||||
test_passthru) == NULL ||
|
||||
CU_add_test(suite, "test_initdrivers",
|
||||
test_initdrivers) == NULL ||
|
||||
CU_add_test(suite, "test_crypto_op_complete",
|
||||
test_crypto_op_complete) == NULL ||
|
||||
CU_add_test(suite, "test_supported_io",
|
||||
test_supported_io) == NULL
|
||||
) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
num_failures = CU_get_number_of_failures();
|
||||
CU_cleanup_registry();
|
||||
return num_failures;
|
||||
}
|
95
test/unit/lib/bdev/crypto.c/rte_crypto.h
Normal file
95
test/unit/lib/bdev/crypto.c/rte_crypto.h
Normal file
@ -0,0 +1,95 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* Copyright(c) 2016 6WIND S.A.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUcryptoION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _RTE_CRYPTO_H_
|
||||
#define _RTE_CRYPTO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In order to mock some DPDK functions, we place headers here with the name name as the DPDK headers
|
||||
* so these definitions wil be picked up. Only what's mocked is included.
|
||||
*/
|
||||
|
||||
#include "rte_mbuf.h"
|
||||
#include "rte_mempool.h"
|
||||
#include "rte_crypto_sym.h"
|
||||
|
||||
enum rte_crypto_op_type {
|
||||
RTE_CRYPTO_OP_TYPE_UNDEFINED,
|
||||
RTE_CRYPTO_OP_TYPE_SYMMETRIC,
|
||||
};
|
||||
|
||||
enum rte_crypto_op_status {
|
||||
RTE_CRYPTO_OP_STATUS_SUCCESS,
|
||||
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED,
|
||||
RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
|
||||
RTE_CRYPTO_OP_STATUS_INVALID_SESSION,
|
||||
RTE_CRYPTO_OP_STATUS_INVALID_ARGS,
|
||||
RTE_CRYPTO_OP_STATUS_ERROR,
|
||||
};
|
||||
|
||||
struct rte_crypto_op {
|
||||
uint8_t type;
|
||||
uint8_t status;
|
||||
uint8_t sess_type;
|
||||
uint8_t reserved[5];
|
||||
struct rte_mempool *mempool;
|
||||
rte_iova_t phys_addr;
|
||||
__extension__
|
||||
union {
|
||||
struct rte_crypto_sym_op sym[0];
|
||||
};
|
||||
};
|
||||
|
||||
extern struct rte_mempool *
|
||||
rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
|
||||
unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
|
||||
int socket_id);
|
||||
|
||||
static inline unsigned
|
||||
rte_crypto_op_bulk_alloc(struct rte_mempool *mempool,
|
||||
enum rte_crypto_op_type type,
|
||||
struct rte_crypto_op **ops, uint16_t nb_ops);
|
||||
|
||||
static inline int
|
||||
rte_crypto_op_attach_sym_session(struct rte_crypto_op *op,
|
||||
struct rte_cryptodev_sym_session *sess);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
147
test/unit/lib/bdev/crypto.c/rte_cryptodev.h
Normal file
147
test/unit/lib/bdev/crypto.c/rte_cryptodev.h
Normal file
@ -0,0 +1,147 @@
|
||||
/*-
|
||||
*
|
||||
* Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
|
||||
* Copyright 2014 6WIND S.A.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _RTE_CRYPTODEV_H_
|
||||
#define _RTE_CRYPTODEV_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In order to mock some DPDK functions, we place headers here with the name name as the DPDK headers
|
||||
* so these definitions wil be picked up. Only what's mocked is included.
|
||||
*/
|
||||
|
||||
uint8_t dummy[16];
|
||||
#define rte_crypto_op_ctod_offset(c, t, o) &dummy[0]
|
||||
|
||||
#define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
|
||||
|
||||
struct rte_cryptodev_info {
|
||||
const char *driver_name;
|
||||
uint8_t driver_id;
|
||||
struct rte_pci_device *pci_dev;
|
||||
uint64_t feature_flags;
|
||||
const struct rte_cryptodev_capabilities *capabilities;
|
||||
unsigned max_nb_queue_pairs;
|
||||
struct {
|
||||
unsigned max_nb_sessions;
|
||||
unsigned int max_nb_sessions_per_qp;
|
||||
} sym;
|
||||
};
|
||||
|
||||
enum rte_cryptodev_event_type {
|
||||
RTE_CRYPTODEV_EVENT_UNKNOWN,
|
||||
RTE_CRYPTODEV_EVENT_ERROR,
|
||||
RTE_CRYPTODEV_EVENT_MAX
|
||||
};
|
||||
|
||||
struct rte_cryptodev_qp_conf {
|
||||
uint32_t nb_descriptors;
|
||||
};
|
||||
|
||||
struct rte_cryptodev_stats {
|
||||
uint64_t enqueued_count;
|
||||
uint64_t dequeued_count;
|
||||
uint64_t enqueue_err_count;
|
||||
uint64_t dequeue_err_count;
|
||||
};
|
||||
|
||||
#define RTE_CRYPTODEV_NAME_MAX_LEN (64)
|
||||
|
||||
extern uint8_t
|
||||
rte_cryptodev_count(void);
|
||||
|
||||
extern uint8_t
|
||||
rte_cryptodev_device_count_by_driver(uint8_t driver_id);
|
||||
|
||||
extern int
|
||||
rte_cryptodev_socket_id(uint8_t dev_id);
|
||||
|
||||
struct rte_cryptodev_config {
|
||||
int socket_id;
|
||||
uint16_t nb_queue_pairs;
|
||||
};
|
||||
|
||||
extern int
|
||||
rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
|
||||
|
||||
extern int
|
||||
rte_cryptodev_start(uint8_t dev_id);
|
||||
|
||||
extern void
|
||||
rte_cryptodev_stop(uint8_t dev_id);
|
||||
|
||||
extern int
|
||||
rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
|
||||
const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
|
||||
struct rte_mempool *session_pool);
|
||||
|
||||
extern void
|
||||
rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
|
||||
|
||||
static inline uint16_t
|
||||
rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
|
||||
struct rte_crypto_op **ops, uint16_t nb_ops);
|
||||
|
||||
static inline uint16_t
|
||||
rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
|
||||
struct rte_crypto_op **ops, uint16_t nb_ops);
|
||||
|
||||
struct rte_cryptodev_sym_session {
|
||||
__extension__ void *sess_private_data[0];
|
||||
};
|
||||
|
||||
struct rte_cryptodev_sym_session *
|
||||
rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
|
||||
|
||||
int
|
||||
rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
|
||||
|
||||
int
|
||||
rte_cryptodev_sym_session_init(uint8_t dev_id,
|
||||
struct rte_cryptodev_sym_session *sess,
|
||||
struct rte_crypto_sym_xform *xforms,
|
||||
struct rte_mempool *mempool);
|
||||
|
||||
int
|
||||
rte_cryptodev_sym_session_clear(uint8_t dev_id,
|
||||
struct rte_cryptodev_sym_session *sess);
|
||||
|
||||
unsigned int
|
||||
rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
148
test/unit/lib/bdev/crypto.c/rte_mbuf.h
Normal file
148
test/unit/lib/bdev/crypto.c/rte_mbuf.h
Normal file
@ -0,0 +1,148 @@
|
||||
/*-
|
||||
*
|
||||
* Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
|
||||
* Copyright 2014 6WIND S.A.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _RTE_MBUF_H_
|
||||
#define _RTE_MBUF_H_
|
||||
|
||||
#include "rte_mempool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In order to mock some DPDK functions, we place headers here with the name name as the DPDK headers
|
||||
* so these definitions wil be picked up. Only what's mocked is included.
|
||||
*/
|
||||
|
||||
__extension__
|
||||
typedef void *MARKER[0];
|
||||
__extension__
|
||||
typedef uint8_t MARKER8[0];
|
||||
__extension__
|
||||
typedef uint64_t MARKER64[0];
|
||||
|
||||
struct rte_mbuf {
|
||||
MARKER cacheline0;
|
||||
void *buf_addr;
|
||||
RTE_STD_C11
|
||||
union {
|
||||
rte_iova_t buf_iova;
|
||||
rte_iova_t buf_physaddr;
|
||||
} __rte_aligned(sizeof(rte_iova_t));
|
||||
MARKER64 rearm_data;
|
||||
uint16_t data_off;
|
||||
RTE_STD_C11
|
||||
union {
|
||||
rte_atomic16_t refcnt_atomic;
|
||||
uint16_t refcnt;
|
||||
};
|
||||
uint16_t nb_segs;
|
||||
uint16_t port;
|
||||
uint64_t ol_flags;
|
||||
MARKER rx_descriptor_fields1;
|
||||
RTE_STD_C11
|
||||
union {
|
||||
uint32_t packet_type;
|
||||
struct {
|
||||
uint32_t l2_type: 4;
|
||||
uint32_t l3_type: 4;
|
||||
uint32_t l4_type: 4;
|
||||
uint32_t tun_type: 4;
|
||||
RTE_STD_C11
|
||||
union {
|
||||
uint8_t inner_esp_next_proto;
|
||||
__extension__
|
||||
struct {
|
||||
uint8_t inner_l2_type: 4;
|
||||
uint8_t inner_l3_type: 4;
|
||||
};
|
||||
};
|
||||
uint32_t inner_l4_type: 4;
|
||||
};
|
||||
};
|
||||
uint32_t pkt_len;
|
||||
uint16_t data_len;
|
||||
uint16_t vlan_tci;
|
||||
union {
|
||||
uint32_t rss;
|
||||
struct {
|
||||
RTE_STD_C11
|
||||
union {
|
||||
struct {
|
||||
uint16_t hash;
|
||||
uint16_t id;
|
||||
};
|
||||
uint32_t lo;
|
||||
};
|
||||
uint32_t hi;
|
||||
} fdir;
|
||||
struct {
|
||||
uint32_t lo;
|
||||
uint32_t hi;
|
||||
} sched;
|
||||
uint32_t usr;
|
||||
} hash;
|
||||
uint16_t vlan_tci_outer;
|
||||
uint16_t buf_len;
|
||||
uint64_t timestamp;
|
||||
MARKER cacheline1 __rte_cache_min_aligned;
|
||||
RTE_STD_C11
|
||||
union {
|
||||
void *userdata;
|
||||
uint64_t udata64;
|
||||
};
|
||||
struct rte_mempool *pool;
|
||||
struct rte_mbuf *next;
|
||||
RTE_STD_C11
|
||||
union {
|
||||
uint64_t tx_offload;
|
||||
__extension__
|
||||
struct {
|
||||
uint64_t l2_len: 7;
|
||||
uint64_t l3_len: 9;
|
||||
uint64_t l4_len: 8;
|
||||
uint64_t tso_segsz: 16;
|
||||
uint64_t outer_l3_len: 9;
|
||||
uint64_t outer_l2_len: 7;
|
||||
};
|
||||
};
|
||||
uint16_t priv_size;
|
||||
uint16_t timesync;
|
||||
uint32_t seqn;
|
||||
|
||||
} __rte_cache_aligned;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
145
test/unit/lib/bdev/crypto.c/rte_mempool.h
Normal file
145
test/unit/lib/bdev/crypto.c/rte_mempool.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*-
|
||||
*
|
||||
* Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
|
||||
* Copyright 2014 6WIND S.A.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _RTE_MEMPOOL_H_
|
||||
#define _RTE_MEMPOOL_H_
|
||||
|
||||
/**
|
||||
* @file
|
||||
* RTE Mempool.
|
||||
*
|
||||
* A memory pool is an allocator of fixed-size object. It is
|
||||
* identified by its name, and uses a ring to store free objects. It
|
||||
* provides some other optional services, like a per-core object
|
||||
* cache, and an alignment helper to ensure that objects are padded
|
||||
* to spread them equally on all RAM channels, ranks, and so on.
|
||||
*
|
||||
* Objects owned by a mempool should never be added in another
|
||||
* mempool. When an object is freed using rte_mempool_put() or
|
||||
* equivalent, the object data is not modified; the user can save some
|
||||
* meta-data in the object data and retrieve them when allocating a
|
||||
* new object.
|
||||
*
|
||||
* Note: the mempool implementation is not preemptible. An lcore must not be
|
||||
* interrupted by another task that uses the same mempool (because it uses a
|
||||
* ring which is not preemptible). Also, usual mempool functions like
|
||||
* rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL
|
||||
* thread due to the internal per-lcore cache. Due to the lack of caching,
|
||||
* rte_mempool_get() or rte_mempool_put() performance will suffer when called
|
||||
* by non-EAL threads. Instead, non-EAL threads should call
|
||||
* rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache
|
||||
* created with rte_mempool_cache_create().
|
||||
*/
|
||||
|
||||
#include <rte_config.h>
|
||||
#include <rte_spinlock.h>
|
||||
#include <rte_debug.h>
|
||||
#include <rte_ring.h>
|
||||
#include <rte_memcpy.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In order to mock some DPDK functions, we place headers here with the name name as the DPDK headers
|
||||
* so these definitions wil be picked up. Only what's mocked is included.
|
||||
*/
|
||||
|
||||
STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
|
||||
STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
|
||||
struct rte_mempool {
|
||||
char name[RTE_MEMZONE_NAMESIZE];
|
||||
RTE_STD_C11
|
||||
union {
|
||||
void *pool_data;
|
||||
uint64_t pool_id;
|
||||
};
|
||||
void *pool_config;
|
||||
const struct rte_memzone *mz;
|
||||
unsigned int flags;
|
||||
int socket_id;
|
||||
uint32_t size;
|
||||
uint32_t cache_size;
|
||||
uint32_t elt_size;
|
||||
uint32_t header_size;
|
||||
uint32_t trailer_size;
|
||||
unsigned private_data_size;
|
||||
int32_t ops_index;
|
||||
struct rte_mempool_cache *local_cache;
|
||||
uint32_t populated_size;
|
||||
struct rte_mempool_objhdr_list elt_list;
|
||||
uint32_t nb_mem_chunks;
|
||||
struct rte_mempool_memhdr_list mem_list;
|
||||
#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
|
||||
struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
|
||||
#endif
|
||||
} __rte_cache_aligned;
|
||||
#define RTE_MEMPOOL_OPS_NAMESIZE 32
|
||||
typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
|
||||
typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
|
||||
typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
|
||||
void *const *obj_table, unsigned int n);
|
||||
typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
|
||||
void **obj_table, unsigned int n);
|
||||
typedef unsigned(*rte_mempool_get_count)(const struct rte_mempool *mp);
|
||||
typedef int (*rte_mempool_get_capabilities_t)(const struct rte_mempool *mp,
|
||||
unsigned int *flags);
|
||||
typedef int (*rte_mempool_ops_register_memory_area_t)
|
||||
(const struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len);
|
||||
struct rte_mempool_ops {
|
||||
char name[RTE_MEMPOOL_OPS_NAMESIZE];
|
||||
rte_mempool_alloc_t alloc;
|
||||
rte_mempool_free_t free;
|
||||
rte_mempool_enqueue_t enqueue;
|
||||
rte_mempool_dequeue_t dequeue;
|
||||
rte_mempool_get_count get_count;
|
||||
rte_mempool_get_capabilities_t get_capabilities;
|
||||
rte_mempool_ops_register_memory_area_t register_memory_area;
|
||||
} __rte_cache_aligned;
|
||||
#define RTE_MEMPOOL_MAX_OPS_IDX 16
|
||||
struct rte_mempool_ops_table {
|
||||
rte_spinlock_t sl;
|
||||
uint32_t num_ops;
|
||||
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX];
|
||||
} __rte_cache_aligned;
|
||||
extern struct rte_mempool_ops_table rte_mempool_ops_table;
|
||||
void
|
||||
rte_mempool_free(struct rte_mempool *mp);
|
||||
static __rte_always_inline void
|
||||
rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table,
|
||||
unsigned int n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RTE_MEMPOOL_H_ */
|
@ -54,6 +54,10 @@ $valgrind $testdir/lib/bdev/scsi_nvme.c/scsi_nvme_ut
|
||||
$valgrind $testdir/lib/bdev/gpt/gpt.c/gpt_ut
|
||||
$valgrind $testdir/lib/bdev/vbdev_lvol.c/vbdev_lvol_ut
|
||||
|
||||
if grep -q '#define SPDK_CONFIG_CRYPTO 1' $rootdir/config.h; then
|
||||
$valgrind $testdir/lib/bdev/crypto.c/crypto_ut
|
||||
fi
|
||||
|
||||
if grep -q '#define SPDK_CONFIG_PMDK 1' $rootdir/config.h; then
|
||||
$valgrind $testdir/lib/bdev/pmem/bdev_pmem_ut
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user