From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 722CD41D5F; Fri, 24 Feb 2023 16:12:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E1A0142D1A; Fri, 24 Feb 2023 16:12:22 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 67B3D41153 for ; Fri, 24 Feb 2023 16:12:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677251538; 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=pIyWTv3RHZWLdtSDwGJsVinsd2PFzP34hSWO7rnujgs=; b=MxnQuUaZmazTOY3px7PnZY/zuLrIiyW/7QrIo46aN/DOcI8yn7bLDyHID+vwBdAAkjg/Rj UyIDK20fOc2aEkIG7amkXn0C9C/d24/RL2DiKaedJl4IWB2J/Fqi1z7Eg+Vb/8wbLviXiw WdE6WvgL4RpyQ3zXdz1dBFcWu+f52aI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-M7SDaBWsMa2d9sVFkRNK1A-1; Fri, 24 Feb 2023 10:12:17 -0500 X-MC-Unique: M7SDaBWsMa2d9sVFkRNK1A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D8903C02B78; Fri, 24 Feb 2023 15:12:17 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99A3B4015319; Fri, 24 Feb 2023 15:12:16 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Andrew Rybchenko Subject: [PATCH v2 09/20] net/sfc: rework locking in proxy code Date: Fri, 24 Feb 2023 16:11:32 +0100 Message-Id: <20230224151143.3274897-10-david.marchand@redhat.com> In-Reply-To: <20230224151143.3274897-1-david.marchand@redhat.com> References: <20230224081642.2566619-1-david.marchand@redhat.com> <20230224151143.3274897-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Remove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id() now only resolves the sa object and sfc_adapter_(|un)lock() are added were necessary. This will simplify lock checks later. Signed-off-by: David Marchand --- drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/drivers/net/sfc/sfc_repr_proxy.c b/drivers/net/sfc/sfc_repr_proxy.c index 4b958ced61..4ba7683370 100644 --- a/drivers/net/sfc/sfc_repr_proxy.c +++ b/drivers/net/sfc/sfc_repr_proxy.c @@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id) dev = &rte_eth_devices[pf_port_id]; sa = sfc_adapter_by_eth_dev(dev); - sfc_adapter_lock(sa); - return sa; } -static void -sfc_put_adapter(struct sfc_adapter *sa) -{ - sfc_adapter_unlock(sa); -} - static struct sfc_repr_proxy_port * sfc_repr_proxy_find_port(struct sfc_repr_proxy *rp, uint16_t repr_id) { @@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, int rc; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, } sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; @@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, fail_alloc_port: fail_port_exists: sfc_log_init(sa, "failed: %s", rte_strerror(rc)); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return rc; } @@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id) int rc; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id) sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; fail_port_remove: fail_no_port: sfc_log_init(sa, "failed: %s", rte_strerror(rc)); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return rc; } @@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, struct sfc_adapter *sa; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, port = sfc_repr_proxy_find_port(rp, repr_id); if (port == NULL) { sfc_err(sa, "%s() failed: no such port", __func__); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return ENOENT; } rxq = &port->rxq[queue_id]; if (rp->dp_rxq[queue_id].mp != NULL && rp->dp_rxq[queue_id].mp != mp) { sfc_err(sa, "multiple mempools per queue are not supported"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return ENOTSUP; } @@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].ref_count++; sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; } @@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, struct sfc_adapter *sa; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, port = sfc_repr_proxy_find_port(rp, repr_id); if (port == NULL) { sfc_err(sa, "%s() failed: no such port", __func__); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return; } @@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].mp = NULL; sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); } int @@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, struct sfc_adapter *sa; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, port = sfc_repr_proxy_find_port(rp, repr_id); if (port == NULL) { sfc_err(sa, "%s() failed: no such port", __func__); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return ENOENT; } @@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, *egress_mport = port->egress_mport; sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; } @@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, struct sfc_adapter *sa; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, port = sfc_repr_proxy_find_port(rp, repr_id); if (port == NULL) { sfc_err(sa, "%s() failed: no such port", __func__); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return; } @@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, txq->ring = NULL; sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); } int @@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) int rc; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) } sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; @@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) fail_not_found: sfc_err(sa, "failed to start repr %u proxy port: %s", repr_id, rte_strerror(rc)); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return rc; } @@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) int rc; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); sfc_log_init(sa, "entry"); @@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port = sfc_repr_proxy_find_port(rp, repr_id); if (port == NULL) { sfc_err(sa, "%s() failed: no such port", __func__); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return ENOENT; } if (!port->enabled) { sfc_log_init(sa, "repr %u proxy port is not started - skip", repr_id); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; } @@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) sfc_err(sa, "failed to stop representor proxy TxQ %u: %s", repr_id, rte_strerror(rc)); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return rc; } } @@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port->enabled = false; sfc_log_init(sa, "done"); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return 0; } @@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id, int rc; sa = sfc_get_adapter_by_pf_port_id(pf_port_id); + sfc_adapter_lock(sa); rp = sfc_repr_proxy_by_adapter(sa); port = sfc_repr_proxy_find_port(rp, repr_id); if (port == NULL) { sfc_err(sa, "%s() failed: no such port (repr_id=%u)", __func__, repr_id); - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return ENOENT; } @@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id, __func__, repr_id, rte_strerror(rc)); } - sfc_put_adapter(sa); + sfc_adapter_unlock(sa); return rc; } -- 2.39.2