From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 808153BE15F for ; Mon, 23 Mar 2026 16:48:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774284530; cv=none; b=azBWn/FI0UY2rdep6NU/F6aJfy99+93SA/LE+loz08nwuwB0/SuBfBddEnJ2fE/kPX+8D2ra7+0/D02nUjnOJG/zEgJaUiior5NRJsKc3pFGsPlLjz5zcAoM/q5v0LfEl6eV7ysrY25arL5R+ABIep+lhBiBgL2R2dIc+4XHEZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774284530; c=relaxed/simple; bh=NouiXx6B+Np00usGwcYy2fnIzJ9Ixe8p6ABtlOiMDMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lywkO93FifW4o+xHgyzYJ1iIO7sRcdg5nexR142mggdaZWBYOCfR9zoaHd/Hug68LPR/40VXrRRiMoZD4E+QmAy5m/GhWTcF5Tke9/PUq3OhSI5eaGK8mVrVNV8aHIGnW0siSoxhm2U9vB4KoMaAouOJJxxogqVxrrVJ7PyU37w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E00mLAce; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E00mLAce" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774284528; 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: in-reply-to:in-reply-to:references:references; bh=3nx2L4DBlvuxQx4skhkMM1msBMEVkuWM1JL61OcaVkc=; b=E00mLAceuMSKYJ0N728pIeMjiYQu3H/timanpsPu0x7+BPqm0/ojFJonEf2tR9OWDufAPr 5ZWJhNIuJ0mZeyibRMabPB/BPh7bLOlIkHBMCOaZ4x/mXuqhFETzXWl072MhOpdUc0nc9E AocI2omJxsEjQ0Zch6paNgMuVyM5Brs= Received: from mx-prod-mc-05.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-479-zqFRXhbbMRmlHTkYmxD_-A-1; Mon, 23 Mar 2026 12:48:45 -0400 X-MC-Unique: zqFRXhbbMRmlHTkYmxD_-A-1 X-Mimecast-MFC-AGG-ID: zqFRXhbbMRmlHTkYmxD_-A_1774284524 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A89A195609F; Mon, 23 Mar 2026 16:48:44 +0000 (UTC) Received: from x2.localnet (unknown [10.22.64.60]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 35D1319560B7; Mon, 23 Mar 2026 16:48:43 +0000 (UTC) From: Steve Grubb To: audit@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Robaina Cc: paul@paul-moore.com, eparis@redhat.com, Ricardo Robaina Subject: Re: [PATCH] audit: add backlog high water mark metric Date: Mon, 23 Mar 2026 12:48:40 -0400 Message-ID: <22574086.4csPzL39Zc@x2> Organization: Red Hat In-Reply-To: <20260323150700.614139-1-rrobaina@redhat.com> References: <20260323150700.614139-1-rrobaina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On Monday, March 23, 2026 11:07:00=E2=80=AFAM Eastern Daylight Time Ricardo= Robaina=20 wrote: > Currently, determining the optimal `audit_backlog_limit` relies on > instantaneous polling of the queue size. This misses transient > micro-bursts, making it difficult for system administrators to know > if their queue is adequately sized or if they are at risk of > dropping events. >=20 > This patch introduces `backlog_max_depth`, a high-water mark metric > that tracks the maximum number of buffers in the audit queue since > the system was booted or the metric was last reset. To minimize > performance overhead in the fast-path, the metric is updated using > a lockless cmpxchg loop in `__audit_log_end()`. >=20 > Userspace can read-and-clear this metric by sending an `AUDIT_SET` > message with the `AUDIT_STATUS_BACKLOG_MAX_DEPTH` mask. To support > periodic telemetry polling (e.g., statsd, Prometheus), the reset > operation atomically returns the snapshot of the high-water mark > right before zeroing it, ensuring no peaks are lost between polls. =46rom a user space point of view, this looks good. User space support was = co- developed alongside of this patch to ensure it works as advertised. Acked-by: Steve Grubb =2DSteve > Link: https://github.com/linux-audit/audit-kernel/issues/63 > Suggested-by: Steve Grubb > Signed-off-by: Ricardo Robaina > --- > include/linux/audit.h | 3 ++- > include/uapi/linux/audit.h | 2 ++ > kernel/audit.c | 32 ++++++++++++++++++++++++++++++++ > 3 files changed, 36 insertions(+), 1 deletion(-) >=20 > diff --git a/include/linux/audit.h b/include/linux/audit.h > index d79218bf075a..53132b303c20 100644 > --- a/include/linux/audit.h > +++ b/include/linux/audit.h > @@ -22,7 +22,8 @@ > AUDIT_STATUS_BACKLOG_LIMIT | \ > AUDIT_STATUS_BACKLOG_WAIT_TIME | \ > AUDIT_STATUS_LOST | \ > - AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL) > + AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL | \ > + AUDIT_STATUS_BACKLOG_MAX_DEPTH) >=20 > #define AUDIT_INO_UNSET ((unsigned long)-1) > #define AUDIT_DEV_UNSET ((dev_t)-1) > diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h > index e8f5ce677df7..862ca93c0c31 100644 > --- a/include/uapi/linux/audit.h > +++ b/include/uapi/linux/audit.h > @@ -355,6 +355,7 @@ enum { > #define AUDIT_STATUS_BACKLOG_WAIT_TIME 0x0020 > #define AUDIT_STATUS_LOST 0x0040 > #define AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL 0x0080 > +#define AUDIT_STATUS_BACKLOG_MAX_DEPTH 0x0100 >=20 > #define AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT 0x00000001 > #define AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME 0x00000002 > @@ -486,6 +487,7 @@ struct audit_status { > __u32 backlog_wait_time_actual;/* time spent waiting while > * message limit exceeded > */ > + __u32 backlog_max_depth; /* message queue max depth */ > }; >=20 > struct audit_features { > diff --git a/kernel/audit.c b/kernel/audit.c > index e1d489bc2dff..256053cb6132 100644 > --- a/kernel/audit.c > +++ b/kernel/audit.c > @@ -163,6 +163,9 @@ static struct sk_buff_head audit_retry_queue; > /* queue msgs waiting for new auditd connection */ > static struct sk_buff_head audit_hold_queue; >=20 > +/* audit queue high water mark since last startup or reset */ > +static atomic_t audit_backlog_max_depth __read_mostly =3D ATOMIC_INIT(0); > + > /* queue servicing thread */ > static struct task_struct *kauditd_task; > static DECLARE_WAIT_QUEUE_HEAD(kauditd_wait); > @@ -1286,6 +1289,7 @@ static int audit_receive_msg(struct sk_buff *skb, > struct nlmsghdr *nlh, s.backlog =3D skb_queue_len(&audit_queue); > s.feature_bitmap =3D AUDIT_FEATURE_BITMAP_ALL; > s.backlog_wait_time =3D audit_backlog_wait_time; > + s.backlog_max_depth =3D atomic_read(&audit_backlog_max_depth); > s.backlog_wait_time_actual =3D > atomic_read(&audit_backlog_wait_time_actual); audit_send_reply(skb, seq, > AUDIT_GET, 0, 0, &s, sizeof(s)); > break; > @@ -1399,6 +1403,12 @@ static int audit_receive_msg(struct sk_buff *skb, > struct nlmsghdr *nlh, audit_log_config_change("backlog_wait_time_actual", > 0, actual, 1); return actual; > } > + if (s.mask =3D=3D AUDIT_STATUS_BACKLOG_MAX_DEPTH) { > + u32 old_depth =3D atomic_xchg(&audit_backlog_max_depth, 0); > + > + audit_log_config_change("backlog_max_depth", 0, old_depth,=20 1); > + return old_depth; > + } > break; > } > case AUDIT_GET_FEATURE: > @@ -2761,6 +2771,25 @@ int audit_signal_info(int sig, struct task_struct > *t) return audit_signal_info_syscall(t); > } >=20 > +/* > + * audit_update_backlog_max_depth - update the audit queue high water ma= rk > + * > + * Safely updates the audit_backlog_max_depth metric using a lockless > + * cmpxchg loop. This ensures the high-water mark is accurately tracked > + * even when multiple CPUs are logging audit records concurrently. > + */ > +static inline void audit_update_backlog_max_depth(void) > +{ > + u32 q_len =3D skb_queue_len(&audit_queue); > + u32 q_max =3D atomic_read(&audit_backlog_max_depth); > + > + while (unlikely(q_len > q_max)) { > + if (likely(atomic_try_cmpxchg(&audit_backlog_max_depth, > + &q_max, q_len))) > + break; > + } > +} > + > /** > * __audit_log_end - enqueue one audit record > * @skb: the buffer to send > @@ -2777,6 +2806,9 @@ static void __audit_log_end(struct sk_buff *skb) >=20 > /* queue the netlink packet */ > skb_queue_tail(&audit_queue, skb); > + > + /* update backlog high water mark */ > + audit_update_backlog_max_depth(); > } else { > audit_log_lost("rate limit exceeded"); > kfree_skb(skb);