From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E95A8A04A3 for ; Fri, 5 Jun 2020 20:27:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DF21E1D560; Fri, 5 Jun 2020 20:27:18 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 5720A1D560 for ; Fri, 5 Jun 2020 20:27:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591381637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BOM0iJjRbsCT7n3lnfp/jhC7J8v/vhOQ97HsVEqs2z4=; b=BaGLISX1yO4sz11136MbTR6fMh91IgtbLCD/lZXsOs4eeB7Pd09HlFecHSOcfWb/Q1ILLP f4wNectMUL4eJWuvWDk4N+sQh3at9ShJi36hGaof1khoZB3X444R6cRZpcJNR3TY4PXKYv 1K9y+VRq2K+TgI1SaAWUHg74fSk+hZ8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-E_lXIZWwNaCI0JQ9oyzqZg-1; Fri, 05 Jun 2020 14:27:14 -0400 X-MC-Unique: E_lXIZWwNaCI0JQ9oyzqZg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7041107ACCD; Fri, 5 Jun 2020 18:27:13 +0000 (UTC) Received: from rh.redhat.com (unknown [10.33.36.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id F26F360E1C; Fri, 5 Jun 2020 18:27:12 +0000 (UTC) From: Kevin Traynor To: Yunjian Wang Cc: Gagandeep Singh , dpdk stable Date: Fri, 5 Jun 2020 19:24:48 +0100 Message-Id: <20200605182525.22483-51-ktraynor@redhat.com> In-Reply-To: <20200605182525.22483-1-ktraynor@redhat.com> References: <20200605182525.22483-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'crypto/caam_jr: fix check of file descriptors' has been queued to LTS release 18.11.9 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 18.11.9 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 06/10/20. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/af983173ae9e13417a221d147f3ee0b7970c2dfc Thanks. Kevin. --- >From af983173ae9e13417a221d147f3ee0b7970c2dfc Mon Sep 17 00:00:00 2001 From: Yunjian Wang Date: Thu, 14 May 2020 18:59:55 +0800 Subject: [PATCH] crypto/caam_jr: fix check of file descriptors [ upstream commit 61552661e25df5b78be3079bc02b56a375dc0fdc ] Zero is a valid fd. It will fail to check the fd if the fd is zero. The "job_ring->uio_fd" is an fd, so define it as "int". Fixes: e7a45f3cc245 ("crypto/caam_jr: add UIO specific operations") Fixes: a5e1018d5e67 ("crypto/caam_jr: add routines to configure HW") Signed-off-by: Yunjian Wang Acked-by: Gagandeep Singh --- drivers/crypto/caam_jr/caam_jr.c | 23 ++++++++++++--- drivers/crypto/caam_jr/caam_jr_hw_specific.h | 2 +- drivers/crypto/caam_jr/caam_jr_pvt.h | 9 +++--- drivers/crypto/caam_jr/caam_jr_uio.c | 30 +++++++++++++------- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/caam_jr/caam_jr.c b/drivers/crypto/caam_jr/caam_jr.c index a4e70babf4..7aca8d6fbd 100644 --- a/drivers/crypto/caam_jr/caam_jr.c +++ b/drivers/crypto/caam_jr/caam_jr.c @@ -2111,5 +2111,5 @@ close_job_ring(struct sec_job_ring_t *job_ring) { PMD_INIT_FUNC_TRACE(); - if (job_ring->irq_fd) { + if (job_ring->irq_fd != -1) { /* Producer index is frozen. If consumer index is not equal * with producer index, then we have descs to flush. @@ -2120,5 +2120,5 @@ close_job_ring(struct sec_job_ring_t *job_ring) /* free the uio job ring */ free_job_ring(job_ring->irq_fd); - job_ring->irq_fd = 0; + job_ring->irq_fd = -1; caam_jr_dma_free(job_ring->input_ring); caam_jr_dma_free(job_ring->output_ring); @@ -2224,5 +2224,5 @@ caam_jr_dev_uninit(struct rte_cryptodev *dev) */ static void * -init_job_ring(void *reg_base_addr, uint32_t irq_id) +init_job_ring(void *reg_base_addr, int irq_id) { struct sec_job_ring_t *job_ring = NULL; @@ -2234,5 +2234,5 @@ init_job_ring(void *reg_base_addr, uint32_t irq_id) for (i = 0; i < MAX_SEC_JOB_RINGS; i++) { - if (g_job_rings[i].irq_fd == 0) { + if (g_job_rings[i].irq_fd == -1) { job_ring = &g_job_rings[i]; g_job_rings_no++; @@ -2487,4 +2487,13 @@ cryptodev_caam_jr_remove(struct rte_vdev_device *vdev) } +static void +sec_job_rings_init(void) +{ + int i; + + for (i = 0; i < MAX_SEC_JOB_RINGS; i++) + g_job_rings[i].irq_fd = -1; +} + static struct rte_vdev_driver cryptodev_caam_jr_drv = { .probe = cryptodev_caam_jr_probe, @@ -2501,4 +2510,10 @@ RTE_PMD_REGISTER_CRYPTO_DRIVER(caam_jr_crypto_drv, cryptodev_caam_jr_drv.driver, cryptodev_driver_id); +RTE_INIT(caam_jr_init) +{ + sec_uio_job_rings_init(); + sec_job_rings_init(); +} + RTE_INIT(caam_jr_init_log) { diff --git a/drivers/crypto/caam_jr/caam_jr_hw_specific.h b/drivers/crypto/caam_jr/caam_jr_hw_specific.h index 5f58a585d7..bbe8bc3f90 100644 --- a/drivers/crypto/caam_jr/caam_jr_hw_specific.h +++ b/drivers/crypto/caam_jr/caam_jr_hw_specific.h @@ -361,5 +361,5 @@ struct sec_job_ring_t { */ - uint32_t irq_fd; /* The file descriptor used for polling from + int irq_fd; /* The file descriptor used for polling from * user space for interrupts notifications */ diff --git a/drivers/crypto/caam_jr/caam_jr_pvt.h b/drivers/crypto/caam_jr/caam_jr_pvt.h index 9f1adabc7d..7997a1d45c 100644 --- a/drivers/crypto/caam_jr/caam_jr_pvt.h +++ b/drivers/crypto/caam_jr/caam_jr_pvt.h @@ -216,5 +216,5 @@ calc_chksum(void *buffer, int len) struct uio_job_ring { uint32_t jr_id; - uint32_t uio_fd; + int uio_fd; void *register_base_addr; int map_size; @@ -224,6 +224,7 @@ struct uio_job_ring { int sec_cleanup(void); int sec_configure(void); +void sec_uio_job_rings_init(void); struct uio_job_ring *config_job_ring(void); -void free_job_ring(uint32_t uio_fd); +void free_job_ring(int uio_fd); /* For Dma memory allocation of specified length and alignment */ @@ -274,5 +275,5 @@ static inline rte_iova_t caam_jr_dma_vtop(void *ptr) * @retval -1 value for error */ -uint32_t caam_jr_enable_irqs(uint32_t uio_fd); +uint32_t caam_jr_enable_irqs(int uio_fd); /** @brief Request to SEC kernel driver to disable interrupts for descriptor @@ -287,5 +288,5 @@ uint32_t caam_jr_enable_irqs(uint32_t uio_fd); * */ -uint32_t caam_jr_disable_irqs(uint32_t uio_fd); +uint32_t caam_jr_disable_irqs(int uio_fd); #endif diff --git a/drivers/crypto/caam_jr/caam_jr_uio.c b/drivers/crypto/caam_jr/caam_jr_uio.c index afd75c9a62..8eaa8ae467 100644 --- a/drivers/crypto/caam_jr/caam_jr_uio.c +++ b/drivers/crypto/caam_jr/caam_jr_uio.c @@ -151,5 +151,5 @@ file_read_first_line(const char root[], const char subdir[], fd = open(absolute_file_name, O_RDONLY); - SEC_ASSERT(fd > 0, fd, "Error opening file %s", + SEC_ASSERT(fd >= 0, fd, "Error opening file %s", absolute_file_name); @@ -185,5 +185,5 @@ file_read_first_line(const char root[], const char subdir[], */ static int -sec_uio_send_command(uint32_t uio_fd, int32_t uio_command) +sec_uio_send_command(int uio_fd, int32_t uio_command) { int ret; @@ -208,5 +208,5 @@ sec_uio_send_command(uint32_t uio_fd, int32_t uio_command) */ uint32_t -caam_jr_enable_irqs(uint32_t uio_fd) +caam_jr_enable_irqs(int uio_fd) { int ret; @@ -239,5 +239,5 @@ caam_jr_enable_irqs(uint32_t uio_fd) */ uint32_t -caam_jr_disable_irqs(uint32_t uio_fd) +caam_jr_disable_irqs(int uio_fd) { int ret; @@ -328,10 +328,10 @@ uio_map_registers(int uio_device_fd, int uio_device_id, void -free_job_ring(uint32_t uio_fd) +free_job_ring(int uio_fd) { struct uio_job_ring *job_ring = NULL; int i; - if (!uio_fd) + if (uio_fd == -1) return; @@ -353,5 +353,5 @@ free_job_ring(uint32_t uio_fd) close(job_ring->uio_fd); g_uio_jr_num--; - job_ring->uio_fd = 0; + job_ring->uio_fd = -1; if (job_ring->register_base_addr == NULL) return; @@ -376,5 +376,5 @@ uio_job_ring *config_job_ring(void) for (i = 0; i < MAX_SEC_JOB_RINGS; i++) { - if (g_uio_job_ring[i].uio_fd == 0) { + if (g_uio_job_ring[i].uio_fd == -1) { job_ring = &g_uio_job_ring[i]; g_uio_jr_num++; @@ -395,5 +395,5 @@ uio_job_ring *config_job_ring(void) /* Open device file */ job_ring->uio_fd = open(uio_device_file_name, O_RDWR); - SEC_ASSERT(job_ring->uio_fd > 0, NULL, + SEC_ASSERT(job_ring->uio_fd >= 0, NULL, "Failed to open UIO device file for job ring %d", job_ring->jr_id); @@ -494,11 +494,21 @@ sec_cleanup(void) * sent using the fd */ - if (job_ring->uio_fd != 0) { + if (job_ring->uio_fd != -1) { CAAM_JR_INFO( "Closed device file for job ring %d , fd = %d", job_ring->jr_id, job_ring->uio_fd); close(job_ring->uio_fd); + job_ring->uio_fd = -1; } } return 0; } + +void +sec_uio_job_rings_init(void) +{ + int i; + + for (i = 0; i < MAX_SEC_JOB_RINGS; i++) + g_uio_job_ring[i].uio_fd = -1; +} -- 2.21.3 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2020-06-05 19:20:53.622376931 +0100 +++ 0051-crypto-caam_jr-fix-check-of-file-descriptors.patch 2020-06-05 19:20:50.858039723 +0100 @@ -1 +1 @@ -From 61552661e25df5b78be3079bc02b56a375dc0fdc Mon Sep 17 00:00:00 2001 +From af983173ae9e13417a221d147f3ee0b7970c2dfc Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 61552661e25df5b78be3079bc02b56a375dc0fdc ] + @@ -11 +12,0 @@ -Cc: stable@dpdk.org @@ -23 +24 @@ -index 45003ba25a..caf2386772 100644 +index a4e70babf4..7aca8d6fbd 100644 @@ -26,2 +27 @@ -@@ -2073,5 +2073,5 @@ static void - close_job_ring(struct sec_job_ring_t *job_ring) +@@ -2111,5 +2111,5 @@ close_job_ring(struct sec_job_ring_t *job_ring) @@ -28,0 +29 @@ + PMD_INIT_FUNC_TRACE(); @@ -33 +34 @@ -@@ -2082,5 +2082,5 @@ close_job_ring(struct sec_job_ring_t *job_ring) +@@ -2120,5 +2120,5 @@ close_job_ring(struct sec_job_ring_t *job_ring) @@ -40 +41 @@ -@@ -2186,5 +2186,5 @@ caam_jr_dev_uninit(struct rte_cryptodev *dev) +@@ -2224,5 +2224,5 @@ caam_jr_dev_uninit(struct rte_cryptodev *dev) @@ -47 +48 @@ -@@ -2196,5 +2196,5 @@ init_job_ring(void *reg_base_addr, uint32_t irq_id) +@@ -2234,5 +2234,5 @@ init_job_ring(void *reg_base_addr, uint32_t irq_id) @@ -54 +55 @@ -@@ -2449,4 +2449,13 @@ cryptodev_caam_jr_remove(struct rte_vdev_device *vdev) +@@ -2487,4 +2487,13 @@ cryptodev_caam_jr_remove(struct rte_vdev_device *vdev) @@ -68 +69 @@ -@@ -2463,4 +2472,10 @@ RTE_PMD_REGISTER_CRYPTO_DRIVER(caam_jr_crypto_drv, cryptodev_caam_jr_drv.driver, +@@ -2501,4 +2510,10 @@ RTE_PMD_REGISTER_CRYPTO_DRIVER(caam_jr_crypto_drv, cryptodev_caam_jr_drv.driver, @@ -91 +92 @@ -index 98cd4438aa..d6b3dafaa6 100644 +index 9f1adabc7d..7997a1d45c 100644 @@ -94 +95 @@ -@@ -217,5 +217,5 @@ calc_chksum(void *buffer, int len) +@@ -216,5 +216,5 @@ calc_chksum(void *buffer, int len) @@ -101 +102 @@ -@@ -225,6 +225,7 @@ struct uio_job_ring { +@@ -224,6 +224,7 @@ struct uio_job_ring { @@ -110 +111 @@ -@@ -280,5 +281,5 @@ static inline rte_iova_t caam_jr_dma_vtop(void *ptr) +@@ -274,5 +275,5 @@ static inline rte_iova_t caam_jr_dma_vtop(void *ptr) @@ -117 +118 @@ -@@ -293,5 +294,5 @@ uint32_t caam_jr_enable_irqs(uint32_t uio_fd); +@@ -287,5 +288,5 @@ uint32_t caam_jr_enable_irqs(uint32_t uio_fd); @@ -125 +126 @@ -index b1bb44ca42..30837c1164 100644 +index afd75c9a62..8eaa8ae467 100644 @@ -128 +129 @@ -@@ -146,5 +146,5 @@ file_read_first_line(const char root[], const char subdir[], +@@ -151,5 +151,5 @@ file_read_first_line(const char root[], const char subdir[], @@ -135 +136 @@ -@@ -180,5 +180,5 @@ file_read_first_line(const char root[], const char subdir[], +@@ -185,5 +185,5 @@ file_read_first_line(const char root[], const char subdir[], @@ -142 +143 @@ -@@ -203,5 +203,5 @@ sec_uio_send_command(uint32_t uio_fd, int32_t uio_command) +@@ -208,5 +208,5 @@ sec_uio_send_command(uint32_t uio_fd, int32_t uio_command) @@ -149 +150 @@ -@@ -234,5 +234,5 @@ caam_jr_enable_irqs(uint32_t uio_fd) +@@ -239,5 +239,5 @@ caam_jr_enable_irqs(uint32_t uio_fd) @@ -156 +157 @@ -@@ -323,10 +323,10 @@ uio_map_registers(int uio_device_fd, int uio_device_id, +@@ -328,10 +328,10 @@ uio_map_registers(int uio_device_fd, int uio_device_id, @@ -169 +170 @@ -@@ -348,5 +348,5 @@ free_job_ring(uint32_t uio_fd) +@@ -353,5 +353,5 @@ free_job_ring(uint32_t uio_fd) @@ -176 +177 @@ -@@ -371,5 +371,5 @@ uio_job_ring *config_job_ring(void) +@@ -376,5 +376,5 @@ uio_job_ring *config_job_ring(void) @@ -183 +184 @@ -@@ -390,5 +390,5 @@ uio_job_ring *config_job_ring(void) +@@ -395,5 +395,5 @@ uio_job_ring *config_job_ring(void) @@ -190 +191 @@ -@@ -489,11 +489,21 @@ sec_cleanup(void) +@@ -494,11 +494,21 @@ sec_cleanup(void)