From nobody Sun Mar 06 16:40:03 2022 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 05FC119F5652; Sun, 6 Mar 2022 16:40:04 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KBS4M6kGlz4Wg3; Sun, 6 Mar 2022 16:40:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646584804; 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=Ym4qRHx8lHYkZSzDt1GtHIQhSnWW4dAk1n+1yJM0hu0=; b=f0mDO7EykKcofqPuW0xA0q0DFzOKV3N8obBfqwzU5vWbafyjgrvbbfv+5cdDn8O+k6qQp7 DcOVJwnu/UemtkI/1F0a7YbwMG+v28w7dPfW4uxQMwSEC49zRivI/OpM8Mc6S+CvHAYr/1 vOdkUlT3NfdRZcagwB7XgU0zxgBeXdsuzybNjWWhNgXIiJ0WCOAiIuNVcc8XFS+9Qwwr+K ZJSrklI0pp33iIkTmdxdVNp4XvmYBVJBkbFfV4uObRWPVwl+NlrNiCZsKk+GaHigrh1CA+ S1wL1PMtF7ZDNZ702v1bcfH2QjbRvgF64Ai5ZSOoPS4t6vjfl+D4Ob2PLc8qMQ== 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 C7AAA17D33; Sun, 6 Mar 2022 16:40:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 226Ge3b0081899; Sun, 6 Mar 2022 16:40:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 226Ge3a8081896; Sun, 6 Mar 2022 16:40:03 GMT (envelope-from git) Date: Sun, 6 Mar 2022 16:40:03 GMT Message-Id: <202203061640.226Ge3a8081896@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vincenzo Maffione Subject: git: 09a1893398fd - main - netmap: fix refcount bug in netmap allocator 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vmaffione X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 09a1893398fdcd1d000dae1cb3fd5239c0bfb360 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646584804; 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=Ym4qRHx8lHYkZSzDt1GtHIQhSnWW4dAk1n+1yJM0hu0=; b=TXXO3cLm/3UrKeIbZSEOlisB2fuBDAUN8iA9+DmFasovnRDg6EN4nJ8VXUW/Eq284h4H9N ybN1ZUzcScc6J10U/ovqx/yeMrDJH0M01ZhhroiUohcdQ5b2nHlJzcLVQV/VXQHdHKnHo1 yS2lLk100elr81b5HbfZhaP/1U750tHOSj9kZRVvWQY8J5JVcZQsFaxNCRLp1f4xAacNdW Op59XFafhel3Re9xUM/CHPOcitQqQXDOGbXqd+aCd263JppkoE/T1X6mCObd+Ifa7xAIje wwQ9GbMV5tAzf1QzFC0KPUpSTDUo5UIFFIWVjKbkMDn2Y26L9yB+GIW+RLMjtg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646584804; a=rsa-sha256; cv=none; b=y22GL+WAD/dYPEUnL1ah/oDZ9A3Vr/B3Y4xCVeQpJkgd/P3IFdf9E97w7Aif2JlJ80H2tz DQDrUrcdcPSKcay5A7Nn9287RP8Djqn+JlQtoq/PZ/fOLx4oUgES6OHsRZ4OE+lZlVgnQh dK/FsDRcmf4SE35zLrVCNd2+Ja5H58TwHa5Wwsty0O40Ronf2zIECCyCYVg31fCphVUOWt oT3GEplM0tqMerT/Hvxi8IlzQ34W6tIvMOPtp1dv2zDHDMEe7kRWhx3fyxKPrYTTenQa2C mo4ilZHYJzfSBcYavxQiKDzLW9zmB+Myx/FSpW3T9U+zK/+Lb9oIgi1dkbw1Sg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by vmaffione: URL: https://cgit.FreeBSD.org/src/commit/?id=09a1893398fdcd1d000dae1cb3fd5239c0bfb360 commit 09a1893398fdcd1d000dae1cb3fd5239c0bfb360 Author: Vincenzo Maffione AuthorDate: 2022-03-06 16:39:16 +0000 Commit: Vincenzo Maffione CommitDate: 2022-03-06 16:39:16 +0000 netmap: fix refcount bug in netmap allocator Symptom: when a single extmem memory region is provided to netmap multiple times, for multiple interfaces, the memory region is never released by netmap once all the existing file descriptors are closed. Fix the relevant condition in netmap_mem_drop(): release the memory when the last user of netmap_adapter is gone, rather then when the last user of netmap_mem_d is gone. MFC after: 2 weeks --- sys/dev/netmap/netmap.c | 10 ++++++---- sys/dev/netmap/netmap_mem2.c | 2 +- sys/net/netmap_user.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c index ed3154a524db..17b6eeaac085 100644 --- a/sys/dev/netmap/netmap.c +++ b/sys/dev/netmap/netmap.c @@ -994,10 +994,12 @@ netmap_mem_restore(struct netmap_adapter *na) static void netmap_mem_drop(struct netmap_adapter *na) { - /* if the native allocator had been overridden on regif, - * restore it now and drop the temporary one - */ - if (netmap_mem_deref(na->nm_mem, na)) { + netmap_mem_deref(na->nm_mem, na); + + if (na->active_fds <= 0) { + /* if the native allocator had been overridden on regif, + * restore it now and drop the temporary one + */ netmap_mem_restore(na); } } diff --git a/sys/dev/netmap/netmap_mem2.c b/sys/dev/netmap/netmap_mem2.c index 2b41af761c04..8575a940961e 100644 --- a/sys/dev/netmap/netmap_mem2.c +++ b/sys/dev/netmap/netmap_mem2.c @@ -323,7 +323,7 @@ netmap_mem_get_id(struct netmap_mem_d *nmd) #ifdef NM_DEBUG_MEM_PUTGET #define NM_DBG_REFC(nmd, func, line) \ - nm_prinf("%d mem[%d:%d] -> %d", line, (nmd)->nm_id, (nmd)->nm_grp, (nmd)->refcount); + nm_prinf("%s:%d mem[%d:%d] -> %d", func, line, (nmd)->nm_id, (nmd)->nm_grp, (nmd)->refcount); #else #define NM_DBG_REFC(nmd, func, line) #endif diff --git a/sys/net/netmap_user.h b/sys/net/netmap_user.h index e17d2dcbe357..e8983565ddf0 100644 --- a/sys/net/netmap_user.h +++ b/sys/net/netmap_user.h @@ -986,7 +986,7 @@ nm_close(struct nm_desc *d) close(d->fd); } - bzero(d, sizeof(*d)); + bzero((char *)d, sizeof(*d)); free(d); return 0; }