From nobody Tue Oct 15 17:43:17 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XShK22L7Lz5Yll8; Tue, 15 Oct 2024 17:43:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XShK16L2mz4ZMN; Tue, 15 Oct 2024 17:43:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729014197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ylkX1bVMWnL2DPOUpeN/KEY8n/p/UJmtURcOtNWq7ck=; b=G7yS35fN/FTXYW32z7Stiy5zAQ+cijgOfierybvXQmSAZRnBw43DSv7QqSUlz5Dsaw/5xx TUNZAZ78fEOX+6zq4r+E2p356drX8KBFtSJD+F5zg8ZkeOPjLl5GXBYaBcif6EiUq8sf8f HGkuIkTGFItQZxwIWwKaEBYQmkuqc9k9+m5qirpjdlz71CfnuPms8h8lfUXR7n4gADlLtq M5hlMjLr1lMGCw/cvubJ0BbgnaQFOiuB0QbUdUt9QFd+cmD0MTJHGTBQyugkhV6DkdhN+w 0qvdVEH24ap/K3Suv+dHVjH9u8qGe7imiT81KVEHSkAVSoz3RyYUZe4irUR1Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729014197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ylkX1bVMWnL2DPOUpeN/KEY8n/p/UJmtURcOtNWq7ck=; b=PLL5LKp6OBO9HMSHb6zDLe4MyaevWZMME72Rx5seNHGBZvrjV9wDH3bZXsp+8VrUrDxbvY jC3H0mfAbfNxzopbXeoerZmg0Gi1dKvQY+jCNktNUeJDv50uGD78IP6pjoehzJ8BtmQIUi 0x5e5jyBsEUJqrNnf9qhWNz8/C0ZTNuUbJEneJy0WrwZGddXJ9KO4ybsugtmSrJQwo+xM6 GidGIF/KD0ydW267oR5z5BL+QPvAltgiohtEgV6Vju6rDI/AbkJMWHsMdgTUqPouGJnb5a v8n9Lz25YL1ZwckV5dseyyabz2/9UjIvgfY8tGdYcO0JOhhsmNWHA2uvcp4Rfw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729014197; a=rsa-sha256; cv=none; b=Ee7wNf3H8LztKt7zcXWKzmP7pbJI5JjJXMuTXNpaVZw43pYjwHTzEk1muKDkltkrr86kKI cpz3J3IlxB9bdM+lmTbKxduQ8C19WYRs4yPvrxoWfge2oqVjn3Dp8eV2WiNo9dX9dhnKcG diuU28I2o8X1cJkC6PeC20NDfDHDeQM3KNVnWNIgiagHu9ZlVpQKRttAu6aw+Kj2/Ia5NM QrsmKvKdc8fWRXDlvVX1WkvSj0oIzECUhfzNt9P9RuZSUGFA5S6xRr1be80haF6FlQO5rJ iapCl5cOIVl/q3TN9iJzjDxD9fKa12ddLDsBiOccAxVr+rqSlsj9JbM2RLBTQg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XShK15xcdzXdF; Tue, 15 Oct 2024 17:43:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49FHhH79062602; Tue, 15 Oct 2024 17:43:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49FHhHdF062599; Tue, 15 Oct 2024 17:43:17 GMT (envelope-from git) Date: Tue, 15 Oct 2024 17:43:17 GMT Message-Id: <202410151743.49FHhHdF062599@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Osama Abboud Subject: git: f9c9c01de87e - main - ena: Reinit netmap adapter struct upon sysctl changes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: osamaabb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f9c9c01de87e0440380b939c684d9939d48ce175 Auto-Submitted: auto-generated The branch main has been updated by osamaabb: URL: https://cgit.FreeBSD.org/src/commit/?id=f9c9c01de87e0440380b939c684d9939d48ce175 commit f9c9c01de87e0440380b939c684d9939d48ce175 Author: Osama Abboud AuthorDate: 2024-08-07 06:24:21 +0000 Commit: Osama Abboud CommitDate: 2024-10-15 17:38:32 +0000 ena: Reinit netmap adapter struct upon sysctl changes When attaching ENA driver, ena_netmap_attach() is invoked which, in turn calls netmap_attach which, initializes a struct netmap_adapter, allocating the struct's netmap_ring and the struct selinfo. When we change the interface number of queues we need to reinit the netmap adapter struct as well, so we need to detach it in order to free the memory allocated by netmap_attach and allocate new memory based on the new parameters like number of rings, ring size etc... Without detaching and attaching the netmap interface, if we're to change the number of queues from 8 to 2 for example and try to enable netmap, the kernel will panic since the original netmap struct within the kernel's possession still thinks that the driver has 8 queues which will eventually cause a non-allocated virtual address access fault. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc. --- sys/dev/ena/ena.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c index bbc857004671..bfde950cb2b1 100644 --- a/sys/dev/ena/ena.c +++ b/sys/dev/ena/ena.c @@ -171,7 +171,9 @@ static int ena_copy_customer_metrics(struct ena_adapter *); static void ena_timer_service(void *); static enum ena_regs_reset_reason_types check_cdesc_in_tx_cq(struct ena_adapter *, struct ena_ring *); - +#ifdef DEV_NETMAP +static int ena_reinit_netmap(struct ena_adapter *adapter); +#endif static char ena_version[] = ENA_DEVICE_NAME ENA_DRV_MODULE_NAME " v" ENA_DRV_MODULE_VERSION; @@ -1162,6 +1164,21 @@ ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t num) return (i); } +#ifdef DEV_NETMAP +static int +ena_reinit_netmap(struct ena_adapter *adapter) +{ + int rc; + + netmap_detach(adapter->ifp); + rc = ena_netmap_attach(adapter); + if (rc != 0) + ena_log(adapter->pdev, ERR, "netmap attach failed: %d\n", rc); + + return rc; +} + +#endif /* DEV_NETMAP */ int ena_update_buf_ring_size(struct ena_adapter *adapter, uint32_t new_buf_ring_size) @@ -1179,6 +1196,12 @@ ena_update_buf_ring_size(struct ena_adapter *adapter, /* Reconfigure buf ring for all Tx rings. */ ena_free_all_io_rings_resources(adapter); ena_init_io_rings_advanced(adapter); +#ifdef DEV_NETMAP + rc = ena_reinit_netmap(adapter); + if (rc != 0) + return rc; + +#endif /* DEV_NETMAP */ if (dev_was_up) { /* * If ena_up() fails, it's not because of recent buf_ring size @@ -1196,7 +1219,12 @@ ena_update_buf_ring_size(struct ena_adapter *adapter, adapter->buf_ring_size = old_buf_ring_size; ena_free_all_io_rings_resources(adapter); ena_init_io_rings_advanced(adapter); +#ifdef DEV_NETMAP + rc = ena_reinit_netmap(adapter); + if (rc != 0) + return rc; +#endif /* DEV_NETMAP */ ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter); ena_trigger_reset(adapter, ENA_REGS_RESET_OS_TRIGGER); @@ -1224,6 +1252,12 @@ ena_update_queue_size(struct ena_adapter *adapter, uint32_t new_tx_size, /* Configure queues with new size. */ ena_init_io_rings_basic(adapter); +#ifdef DEV_NETMAP + rc = ena_reinit_netmap(adapter); + if (rc != 0) + return rc; + +#endif /* DEV_NETMAP */ if (dev_was_up) { rc = ena_up(adapter); if (unlikely(rc != 0)) { @@ -1235,7 +1269,12 @@ ena_update_queue_size(struct ena_adapter *adapter, uint32_t new_tx_size, adapter->requested_tx_ring_size = old_tx_size; adapter->requested_rx_ring_size = old_rx_size; ena_init_io_rings_basic(adapter); +#ifdef DEV_NETMAP + rc = ena_reinit_netmap(adapter); + if (rc != 0) + return rc; +#endif /* DEV_NETMAP */ /* And try again. */ rc = ena_up(adapter); if (unlikely(rc != 0)) { @@ -1359,7 +1398,12 @@ ena_update_io_queue_nb(struct ena_adapter *adapter, uint32_t new_num) ena_down(adapter); ena_update_io_rings(adapter, new_num); +#ifdef DEV_NETMAP + rc = ena_reinit_netmap(adapter); + if (rc != 0) + return rc; +#endif /* DEV_NETMAP */ if (dev_was_up) { rc = ena_up(adapter); if (unlikely(rc != 0)) { @@ -1369,7 +1413,12 @@ ena_update_io_queue_nb(struct ena_adapter *adapter, uint32_t new_num) new_num, old_num); ena_update_io_rings(adapter, old_num); +#ifdef DEV_NETMAP + rc = ena_reinit_netmap(adapter); + if (rc != 0) + return rc; +#endif /* DEV_NETMAP */ rc = ena_up(adapter); if (unlikely(rc != 0)) { ena_log(adapter->pdev, ERR,