From nobody Thu Oct 31 16:01:38 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 4XfTJL3cBFz5bwrc; Thu, 31 Oct 2024 16:01:38 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XfTJL206xz4TH0; Thu, 31 Oct 2024 16:01:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730390498; 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=WuTTRKay8oOBV6vzI0neHfBT9A5Qo67HTLJTuUqZJ/4=; b=iZXTcN1YEPGvTJMwMGf9/zWRxnYVc4Hzl7DYZxLidDuO7cfD6L/S1v1c2GCYkllTKk3Cke Xla+W0XAcRW1ZF1zlBvaBAoPzjEDUTx1PKkArl8HsVitCPXBhKsMvDgOfdZ6LRp41BoOQY TSZfmF1d//i6IY0NA/K7mwinaT4nYNVwOeR6+QS6WP63Lx5iYcWte5iwyu8jZQ7oJyx/5o Sv+nWjfrk2o46AYiEuIyfe/c5F5ccSHzSIpsUxguCGJm/vlugOrb1+JcU9Cj3U3w2VguEV IOSk250gABXI1XHR1WLZANZbsSdV+kW77xC3SZ02mmajyHqX7jerEzt38eD+7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730390498; 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=WuTTRKay8oOBV6vzI0neHfBT9A5Qo67HTLJTuUqZJ/4=; b=TpodT22DooPS2OolqREODYU/aXcBb79k9scsR9zlxoWH1pp9y2fyDBoFC51DenX22l71Mv 1qJmgYIz+B45LAz0JXmkwj58CXVBvymlAEfM2gqMCUgsjTUp8DRuNqLNdx7Lxu+A5cEPAg hf9lr05hb9lzTpGTPRK88k4VtzFChLNGp/ivagzJq1dcDmk/gGIUMJAE6wMrRz+qi7b+1U W4upwQ4jLz+uBRFB2fk+91qfd5L0yQhfX0c9vKWkbI3FYsxDx4JD4BGkyqm58+VGgEgJIR 8RCHE72sTrJ4V8ZqmHwU7oORhBB+I0i/1NUsLuSP3mEfR/GTtChqIclEs4nsiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730390498; a=rsa-sha256; cv=none; b=eUtE8KiWOefjOfIViC9GnE0SzkAvv5HDgnozom6LuMULdeL39iFNudzbAdxD2UjBimd0sg e6OG2iJ9aDLua071XLLCsl/x7AUg6J5GKEl08lXeqPXwjNHIF3GThpyoPnGJSkxBSAiB48 Bo0gJqdE38elK6266BlJqonXpckgtjSmZexIgXbiwxt3rXGfoCXYQx/rLfpTb11AFSHwfj 7uJZ5IKiCARSh8Qc1y/Z4qGvDUlpB43jGtrj7B9n2DyU2DeytHm6fIYx2jAbkTd3a3tk4K swB+b8Dngz5rKCA11K30f9WQHMySxF3jrIWsrXrSFiAFzEWe769n1rAHSfbvxA== 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 4XfTJL1bGMzjsk; Thu, 31 Oct 2024 16:01:38 +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 49VG1ctn073255; Thu, 31 Oct 2024 16:01:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49VG1cwu073252; Thu, 31 Oct 2024 16:01:38 GMT (envelope-from git) Date: Thu, 31 Oct 2024 16:01:38 GMT Message-Id: <202410311601.49VG1cwu073252@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Osama Abboud Subject: git: 9aa14351c104 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 9aa14351c104d0d1603dd2484095116b86d9702c Auto-Submitted: auto-generated The branch stable/14 has been updated by osamaabb: URL: https://cgit.FreeBSD.org/src/commit/?id=9aa14351c104d0d1603dd2484095116b86d9702c commit 9aa14351c104d0d1603dd2484095116b86d9702c Author: Osama Abboud AuthorDate: 2024-08-07 06:24:21 +0000 Commit: Osama Abboud CommitDate: 2024-10-31 14:54:11 +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) Sponsored by: Amazon, Inc. (cherry picked from commit f9c9c01de87e0440380b939c684d9939d48ce175) --- 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,