From patchwork Mon Feb 6 21:45:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Eremin-Solenikov X-Patchwork-Id: 93493 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1903980qgi; Mon, 6 Feb 2017 13:45:42 -0800 (PST) X-Received: by 10.200.37.183 with SMTP id e52mr12135117qte.166.1486417542588; Mon, 06 Feb 2017 13:45:42 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f90si1439018qkf.272.2017.02.06.13.45.42; Mon, 06 Feb 2017 13:45:42 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3AE9660933; Mon, 6 Feb 2017 21:45:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 1CF3860734; Mon, 6 Feb 2017 21:45:37 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id EE1EB60747; Mon, 6 Feb 2017 21:45:34 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by lists.linaro.org (Postfix) with ESMTPS id 17C46606F3 for ; Mon, 6 Feb 2017 21:45:31 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id z134so52314020lff.3 for ; Mon, 06 Feb 2017 13:45:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=u/H/z+gXk+Ii8WS4I7po6Md+CDLiIOtjM6M8LVffqsQ=; b=rmvlq+5QOt5PANzf6o/TcWES48cDHxpezAqZ9V0EMJytbJ1kslgMPnjey3DNGakbK+ OEfYY6q1qI+xBMhmiFhRsP5cRhHyLDpGOH4+Koseg/5bRGms0ZSqre3jYaVL/cooveUD LTdUQHgCK2ZHygkW6PKO8iGquYC0c8j+oAfPo711qRaEN5gBx/Xzg8rZ4wRhXMTR/1IW BfnhRlfGzdaO0NjeCti1J2NWMQLZkE6yk00gu8JH8Fpfes0AjXcOFR+2aZxQTikxds6I RIlmCXvmFcwx9e+/AvDaWDA49+DT11eCHIddA8xALw0RrjY28fHfX5JecENl8j1YEvCW x55w== X-Gm-Message-State: AMke39nJk13U9FSbnOuknFU+XFWC7TFeHtkfYbZkEU6uLmHKe1KRxKiDa27E1ofAN+K2pDuuVjo= X-Received: by 10.25.72.20 with SMTP id v20mr3913266lfa.46.1486417529565; Mon, 06 Feb 2017 13:45:29 -0800 (PST) Received: from forlindon.lumag.auriga.ru ([94.25.228.29]) by smtp.gmail.com with ESMTPSA id j87sm646689lfi.25.2017.02.06.13.45.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Feb 2017 13:45:28 -0800 (PST) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Tue, 7 Feb 2017 00:45:26 +0300 Message-Id: <20170206214526.6926-1-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 Subject: [lng-odp] [PATCH] linux-generic: crypto: support OpenSSL 1.1.0 X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" OpenSSL 1.1.0 uses new threading API. It is no longer necessary to set locking callbacks to use OpenSSL in a multi-threaded environment. The old threading API should no longer be used. Separate old locking code into separate functions that are guarded by OPENSSL_VERSION_NUMBER check. Signed-off-by: Dmitry Eremin-Solenikov --- .../linux-generic/include/odp_crypto_internal.h | 1 + platform/linux-generic/odp_crypto.c | 78 ++++++++++++++++------ 2 files changed, 59 insertions(+), 20 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index c7b893aa..f85b76ea 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -13,6 +13,7 @@ extern "C" { #include #include +#include #define MAX_IV_LEN 64 #define OP_RESULT_MAGIC 0x91919191 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index b53b0fc1..2145c36e 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -26,6 +26,7 @@ #include #include #include +#include #define MAX_SESSIONS 32 @@ -64,7 +65,6 @@ typedef struct odp_crypto_global_s odp_crypto_global_t; struct odp_crypto_global_s { odp_spinlock_t lock; - odp_ticketlock_t **openssl_lock; odp_crypto_generic_session_t *free; odp_crypto_generic_session_t sessions[0]; }; @@ -949,35 +949,80 @@ odp_crypto_operation(odp_crypto_op_param_t *param, return 0; } +#if OPENSSL_VERSION_NUMBER < 0x10100000L static unsigned long openssl_thread_id(void) { return (unsigned long)odp_thread_id(); } +odp_ticketlock_t *openssl_locks; + static void openssl_lock(int mode, int n, const char *file ODP_UNUSED, int line ODP_UNUSED) { if (mode & CRYPTO_LOCK) - odp_ticketlock_lock((odp_ticketlock_t *) - &global->openssl_lock[n]); + odp_ticketlock_lock(&openssl_locks[n]); else - odp_ticketlock_unlock((odp_ticketlock_t *) - &global->openssl_lock[n]); + odp_ticketlock_unlock(&openssl_locks[n]); +} + +static void odp_crypto_init_openssl_locks(void) +{ + int nlocks = CRYPTO_num_locks(); + size_t mem_size; + odp_shm_t shm; + int idx; + + if (nlocks <= 0) + return; + + mem_size = nlocks * sizeof(odp_ticketlock_t); + + /* Allocate our globally shared memory */ + shm = odp_shm_reserve("crypto_openssl_locks", mem_size, + ODP_CACHE_LINE_SIZE, 0); + + openssl_locks = odp_shm_addr(shm); + + /* Clear it out */ + memset(openssl_locks, 0, mem_size); + + for (idx = 0; idx < nlocks; idx++) + odp_ticketlock_init(&openssl_locks[idx]); + + CRYPTO_set_id_callback(openssl_thread_id); + CRYPTO_set_locking_callback(openssl_lock); } +static int odp_crypto_term_openssl_locks(void) +{ + CRYPTO_set_locking_callback(NULL); + CRYPTO_set_id_callback(NULL); + + return odp_shm_free(odp_shm_lookup("crypto_openssl_locks")); +} +#else +static void odp_crypto_init_openssl_locks(void) +{ +} + +static int odp_crypto_term_openssl_locks(void) +{ + return 0; +} +#endif + int odp_crypto_init_global(void) { size_t mem_size; odp_shm_t shm; int idx; - int nlocks = CRYPTO_num_locks(); /* Calculate the memory size we need */ mem_size = sizeof(*global); mem_size += (MAX_SESSIONS * sizeof(odp_crypto_generic_session_t)); - mem_size += nlocks * sizeof(odp_ticketlock_t); /* Allocate our globally shared memory */ shm = odp_shm_reserve("crypto_pool", mem_size, @@ -995,17 +1040,7 @@ odp_crypto_init_global(void) } odp_spinlock_init(&global->lock); - if (nlocks > 0) { - global->openssl_lock = - (odp_ticketlock_t **)&global->sessions[MAX_SESSIONS]; - - for (idx = 0; idx < nlocks; idx++) - odp_ticketlock_init((odp_ticketlock_t *) - &global->openssl_lock[idx]); - - CRYPTO_set_id_callback(openssl_thread_id); - CRYPTO_set_locking_callback(openssl_lock); - } + odp_crypto_init_openssl_locks(); return 0; } @@ -1024,8 +1059,11 @@ int odp_crypto_term_global(void) rc = -1; } - CRYPTO_set_locking_callback(NULL); - CRYPTO_set_id_callback(NULL); + ret = odp_crypto_term_openssl_locks(); + if (ret < 0) { + ODP_ERR("shm free failed for crypto_openssl_locks\n"); + rc = -1; + } ret = odp_shm_free(odp_shm_lookup("crypto_pool")); if (ret < 0) {