Bug 177366

Summary: [ieee80211] negative malloc(9) statistics for 80211node
Product: Base System Reporter: pluknet <pluknet>
Component: kernAssignee: Andriy Voskoboinyk <avos>
Status: Closed FIXED    
Severity: Affects Only Me CC: avos
Priority: Normal Flags: avos: mfc-stable10+
avos: mfc-stable11+
avos: mfc-stable12+
Version: 9.1-STABLE   
Hardware: Any   
OS: Any   

Description pluknet 2013-03-25 09:30:00 UTC
After upgrading from 8-stable to 9-stable I noticed the
error in malloc(9) type 80211node counter. From vmstat -m:
         Type InUse MemUse HighUse Requests  Size(s)
    80211node 18446744073709551605 18014398509481852K       -        0

18446744073709551605/18014398509481852
1024.00000

18446744073709551605/2^64
.99999

2^64-18446744073709551605
11

Looks like it updates stats on free and forget to update on malloc,
so it goes negative and wraps on uint64_t.

(kgdb) p ((struct malloc_type_internal *)M_80211_NODE->ks_handle)->mti_stats[0]
$20 = {mts_memalloced = 0, mts_memfreed = 61440, mts_numallocs = 0, mts_numfrees = 5, mts_size = 0, _mts_reserved1 = 0, _mts_reserved2 = 0, 
  _mts_reserved3 = 0}
(kgdb) p ((struct malloc_type_internal *)M_80211_NODE->ks_handle)->mti_stats[1]
$21 = {mts_memalloced = 0, mts_memfreed = 73728, mts_numallocs = 0, mts_numfrees = 6, mts_size = 0, _mts_reserved1 = 0, _mts_reserved2 = 0, 
  _mts_reserved3 = 0}
(kgdb) p mp_ncpus
$1 = 2

mts_numfrees[i] - mts_numallocs[i] => 11
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2013-03-25 22:51:29 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-net

Over to maintainer(s).
Comment 2 pluknet 2013-11-24 18:45:23 UTC
Still true on HEAD (11-CURRENT).

    80211node 18446744073709551603 18014398509481785K       -      294  1024

18446744073709551603-2^64
-13

The point of counter leaking is still to be investigated.

-- 
wbr,
pluknet
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:05 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 4 commit-hook freebsd_committer 2019-02-02 16:01:32 UTC
A commit references this bug:

Author: avos
Date: Sat Feb  2 16:01:17 UTC 2019
New revision: 343679
URL: https://svnweb.freebsd.org/changeset/base/343679

Log:
  run(4): fix allocated memory type and -Wincompatible-pointer-types
  compiler warning.

  PR:		177366
  MFC after:	3 days

Changes:
  head/sys/dev/usb/wlan/if_run.c
Comment 5 commit-hook freebsd_committer 2019-02-02 16:08:40 UTC
A commit references this bug:

Author: avos
Date: Sat Feb  2 16:07:56 UTC 2019
New revision: 343681
URL: https://svnweb.freebsd.org/changeset/base/343681

Log:
  run(4): fix allocated memory type for ieee80211_node(4).

  PR:		177366
  MFC after:	3 days

Changes:
  head/sys/dev/usb/wlan/if_run.c
Comment 6 Andriy Voskoboinyk freebsd_committer 2019-02-02 16:11:18 UTC
It is not misused nowhere, except in run(4); I think, this PR may be closed after MFC.
Comment 7 commit-hook freebsd_committer 2019-02-06 02:19:33 UTC
A commit references this bug:

Author: avos
Date: Wed Feb  6 02:18:12 UTC 2019
New revision: 343821
URL: https://svnweb.freebsd.org/changeset/base/343821

Log:
  MFC r343681:
  run(4): fix allocated memory type for ieee80211_node(4)

  PR:		177366

Changes:
_U  stable/10/
  stable/10/sys/dev/usb/wlan/if_run.c
_U  stable/11/
  stable/11/sys/dev/usb/wlan/if_run.c
_U  stable/12/
  stable/12/sys/dev/usb/wlan/if_run.c
Comment 8 Andriy Voskoboinyk freebsd_committer 2019-02-06 02:24:20 UTC
If counter is still incorrect - feel free to reopen this PR (driver / wlanmode / svn revision will help to diagnose the problem in this case).