From patchwork Tue Feb 7 18:06:16 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: 93578 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2319092qgi; Tue, 7 Feb 2017 10:06:56 -0800 (PST) X-Received: by 10.237.53.164 with SMTP id c33mr16816692qte.121.1486490816283; Tue, 07 Feb 2017 10:06:56 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g5si3529036qtf.86.2017.02.07.10.06.55; Tue, 07 Feb 2017 10:06:56 -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 816BD62F80; Tue, 7 Feb 2017 18:06:55 +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 3685062F82; Tue, 7 Feb 2017 18:06:29 +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 8586A62F7A; Tue, 7 Feb 2017 18:06:26 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id 784C662EA2 for ; Tue, 7 Feb 2017 18:06:24 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id z134so67705691lff.3 for ; Tue, 07 Feb 2017 10:06:24 -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:in-reply-to :references; bh=rKxedAa6Gn8vGHPnFUA7R7dvLTyrdeIG1FYEeN6dYZ4=; b=J/PkyB6URDDOBR1QhR1PT6xts9YTZBZPYgsD15AjsJu9wytdRqV19cv6FfXNpjoBgL 32IGBAaUTcwifSjtFDHLIDnOmwT8+zO0K1t/HE7zoM3eCNG4fFbGcZiRZi4s9iN/PdXz ZTx+bHy3B7DZCPeiS6FRvtEOR1Wqd4FUpuEpzMAzt1CR8vs9nYbNpi5wiLAJ9d4NcfAa 1O2BX+JpIc1J7uaYGC4hnMSzTAS4O76o7OI6kNK9hlzdp99fDxMjA5JNkJ9sVCM/dwQ+ 2wmRWqIb0863uDhdm92oL98PSDvu3Cm8sxzadFwhkZORnjyB5+chnQ842AmY+zswLQcK jzNw== X-Gm-Message-State: AIkVDXLflrYZpm7bX7jbkhheSBGfU46m8Ve9GYOvIFdasUpXVQgOQHDMf7VUDOVsYyCuZcd7j7o= X-Received: by 10.25.56.70 with SMTP id d6mr6181219lfj.2.1486490783185; Tue, 07 Feb 2017 10:06:23 -0800 (PST) Received: from forlindon.lumag.auriga.ru ([93.185.26.131]) by smtp.gmail.com with ESMTPSA id s20sm1548331lfe.41.2017.02.07.10.06.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 10:06:22 -0800 (PST) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Tue, 7 Feb 2017 21:06:16 +0300 Message-Id: <20170207180617.5169-2-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170207180617.5169-1-dmitry.ereminsolenikov@linaro.org> References: <20170207180617.5169-1-dmitry.ereminsolenikov@linaro.org> Subject: [lng-odp] [PATCH v2 2/3] linux-generic: crypto: move OpenSSL locks out of global crypto data 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" In preparation to update crypto code for OpenSSL 1.1.0 move locks out of global data. Signed-off-by: Dmitry Eremin-Solenikov --- platform/linux-generic/odp_crypto.c | 67 ++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 20 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index b53b0fc1..d83b8e09 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -64,7 +64,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]; }; @@ -954,16 +953,53 @@ 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 openssl_init_locks(void) +{ + int nlocks; + size_t mem_size; + odp_shm_t shm; + int idx; + + nlocks = CRYPTO_num_locks(); + 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 openssl_term_locks(void) +{ + CRYPTO_set_locking_callback(NULL); + CRYPTO_set_id_callback(NULL); + + return odp_shm_free(odp_shm_lookup("crypto_openssl_locks")); } int @@ -972,12 +1008,10 @@ 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 +1029,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); - } + openssl_init_locks(); return 0; } @@ -1024,8 +1048,11 @@ int odp_crypto_term_global(void) rc = -1; } - CRYPTO_set_locking_callback(NULL); - CRYPTO_set_id_callback(NULL); + ret = openssl_term_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) {