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 2A92145A78; Tue, 1 Oct 2024 11:15:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 100F24027C; Tue, 1 Oct 2024 11:15:19 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 2AC144027A for ; Tue, 1 Oct 2024 11:15:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727774116; 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; bh=KyAaMgEfbaqmxgktZUI64KgFSEN3SQM19cW+wEliV+o=; b=Cn6nZBHxSlHdeQJ8fw2wOp4KV4cTgLPA5dYea4EYQTfyPql6dF2WTFWFyGLogL+SgEXxzP 4zsfa6t5eFplkwx0lPVwiyPQxowUQEHb4cUlNBwpXHRBUvj89UHjKRkT3noVuH6QeRqxg/ EP7Lr4JqgcGTHOAgCqIa/MDEvOz6pQQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-uht8dy50OmO9g-T_AUHhRg-1; Tue, 01 Oct 2024 05:15:13 -0400 X-MC-Unique: uht8dy50OmO9g-T_AUHhRg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AE5E61944D3F; Tue, 1 Oct 2024 09:15:12 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.68]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BAC93003E4D; Tue, 1 Oct 2024 09:15:10 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: bruce.richardson@intel.com, Jingjing Wu Subject: [PATCH] net/iavf: simplify mailbox message generation for mac Date: Tue, 1 Oct 2024 11:15:07 +0200 Message-ID: <20241001091507.98785-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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 Caught by code review. The mailbox message maximum size is larger than the biggest message to update mac addresses. Remove the double loop and add some build / assert checks. This cleanup also fixes a (never hit) issue where multiple mac addresses would be marked as VIRTCHNL_ETHER_ADDR_PRIMARY if multiple messages had been effectively sent. Signed-off-by: David Marchand --- drivers/net/iavf/iavf_vchnl.c | 86 ++++++++++++++--------------------- 1 file changed, 34 insertions(+), 52 deletions(-) diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index 065ab3594c..e5113605ac 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -1397,62 +1397,44 @@ void iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add) { struct virtchnl_ether_addr_list *list; + char buf[sizeof(*list) + sizeof(struct virtchnl_ether_addr) * IAVF_NUM_MACADDR_MAX]; struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter); - struct rte_ether_addr *addr; struct iavf_cmd_info args; - int len, err, i, j; - int next_begin = 0; - int begin = 0; - - do { - j = 0; - len = sizeof(struct virtchnl_ether_addr_list); - for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) { - addr = &adapter->dev_data->mac_addrs[i]; - if (rte_is_zero_ether_addr(addr)) - continue; - len += sizeof(struct virtchnl_ether_addr); - if (len >= IAVF_AQ_BUF_SZ) { - next_begin = i + 1; - break; - } - } + int len, i; - list = rte_zmalloc("iavf_del_mac_buffer", len, 0); - if (!list) { - PMD_DRV_LOG(ERR, "fail to allocate memory"); - return; - } + RTE_BUILD_BUG_ON(sizeof(buf) > IAVF_AQ_BUF_SZ); + list = (struct virtchnl_ether_addr_list *)buf; - for (i = begin; i < next_begin; i++) { - addr = &adapter->dev_data->mac_addrs[i]; - if (rte_is_zero_ether_addr(addr)) - continue; - rte_memcpy(list->list[j].addr, addr->addr_bytes, - sizeof(addr->addr_bytes)); - list->list[j].type = (j == 0 ? - VIRTCHNL_ETHER_ADDR_PRIMARY : - VIRTCHNL_ETHER_ADDR_EXTRA); - PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT, - RTE_ETHER_ADDR_BYTES(addr)); - j++; - } - list->vsi_id = vf->vsi_res->vsi_id; - list->num_elements = j; - args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : - VIRTCHNL_OP_DEL_ETH_ADDR; - args.in_args = (uint8_t *)list; - args.in_args_size = len; - args.out_buffer = vf->aq_resp; - args.out_size = IAVF_AQ_BUF_SZ; - err = iavf_execute_vf_cmd_safe(adapter, &args, 0); - if (err) - PMD_DRV_LOG(ERR, "fail to execute command %s", - add ? "OP_ADD_ETHER_ADDRESS" : - "OP_DEL_ETHER_ADDRESS"); - rte_free(list); - begin = next_begin; - } while (begin < IAVF_NUM_MACADDR_MAX); + len = sizeof(struct virtchnl_ether_addr_list); + for (i = 0; i < IAVF_NUM_MACADDR_MAX; i++) { + struct rte_ether_addr *addr; + + addr = &adapter->dev_data->mac_addrs[i]; + if (rte_is_zero_ether_addr(addr)) + continue; + len += sizeof(struct virtchnl_ether_addr); + assert(len <= IAVF_AQ_BUF_SZ); + + rte_memcpy(list->list[i].addr, addr->addr_bytes, + sizeof(addr->addr_bytes)); + list->list[i].type = (i == 0 ? + VIRTCHNL_ETHER_ADDR_PRIMARY : + VIRTCHNL_ETHER_ADDR_EXTRA); + PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT, + RTE_ETHER_ADDR_BYTES(addr)); + } + + list->vsi_id = vf->vsi_res->vsi_id; + list->num_elements = i; + args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR; + args.in_args = (uint8_t *)list; + args.in_args_size = len; + args.out_buffer = vf->aq_resp; + args.out_size = IAVF_AQ_BUF_SZ; + + if (iavf_execute_vf_cmd_safe(adapter, &args, 0)) + PMD_DRV_LOG(ERR, "fail to execute command %s", + add ? "OP_ADD_ETHER_ADDRESS" : "OP_DEL_ETHER_ADDRESS"); } int -- 2.46.2