From: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
To: paul@paul-moore.com, eparis@redhat.com,
linux-kernel@vger.kernel.org, audit@vger.kernel.org
Cc: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
Subject: [PATCH 2/4] audit: account backlog waiting time in audit_receive()
Date: Mon, 8 May 2023 07:58:10 +0000 [thread overview]
Message-ID: <20230508075812.76077-3-eiichi.tsukata@nutanix.com> (raw)
In-Reply-To: <20230508075812.76077-1-eiichi.tsukata@nutanix.com>
Currently backlog waiting time in audit_receive() is not accounted as
audit_backlog_wait_time_actual. Accounts it as well.
Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
---
kernel/audit.c | 44 ++++++++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/kernel/audit.c b/kernel/audit.c
index c15694e1a76b..89e119ccda76 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -628,6 +628,29 @@ static void kauditd_retry_skb(struct sk_buff *skb, __always_unused int error)
kfree_skb(skb);
}
+/**
+ * wait_for_kauditd - Wait for kauditd to drain the queue
+ * @stime: time to sleep
+ *
+ * Description:
+ * Waits for kauditd to drain the queue then adds duration of sleep time to
+ * audit_backlog_wait_time_actual as cumulative sum.
+ * Returns remaining time to sleep.
+ */
+static long wait_for_kauditd(long stime)
+{
+ long rtime;
+ DECLARE_WAITQUEUE(wait, current);
+
+ add_wait_queue_exclusive(&audit_backlog_wait, &wait);
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ rtime = schedule_timeout(stime);
+ atomic_add(stime - rtime, &audit_backlog_wait_time_actual);
+ remove_wait_queue(&audit_backlog_wait, &wait);
+
+ return rtime;
+}
+
/**
* auditd_reset - Disconnect the auditd connection
* @ac: auditd connection state
@@ -1568,15 +1591,9 @@ static void audit_receive(struct sk_buff *skb)
/* can't block with the ctrl lock, so penalize the sender now */
if (audit_queue_full(&audit_queue)) {
- DECLARE_WAITQUEUE(wait, current);
-
/* wake kauditd to try and flush the queue */
wake_up_interruptible(&kauditd_wait);
-
- add_wait_queue_exclusive(&audit_backlog_wait, &wait);
- set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_timeout(audit_backlog_wait_time);
- remove_wait_queue(&audit_backlog_wait, &wait);
+ wait_for_kauditd(audit_backlog_wait_time);
}
}
@@ -1874,17 +1891,8 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
/* sleep if we are allowed and we haven't exhausted our
* backlog wait limit */
- if (gfpflags_allow_blocking(gfp_mask) && (stime > 0)) {
- long rtime = stime;
-
- DECLARE_WAITQUEUE(wait, current);
-
- add_wait_queue_exclusive(&audit_backlog_wait,
- &wait);
- set_current_state(TASK_UNINTERRUPTIBLE);
- stime = schedule_timeout(rtime);
- atomic_add(rtime - stime, &audit_backlog_wait_time_actual);
- remove_wait_queue(&audit_backlog_wait, &wait);
+ if (gfpflags_allow_blocking(gfp_mask) && stime > 0) {
+ stime = wait_for_kauditd(stime);
} else {
if (audit_rate_check() && printk_ratelimit())
pr_warn("audit_backlog=%d > audit_backlog_limit=%d\n",
--
2.40.0
next prev parent reply other threads:[~2023-05-08 7:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 7:58 [PATCH 0/4] audit: refactor and fix for potential deadlock Eiichi Tsukata
2023-05-08 7:58 ` [PATCH 1/4] audit: refactor queue full checks Eiichi Tsukata
2023-05-10 6:54 ` Rinat Gadelshin
2023-05-10 7:17 ` Eiichi Tsukata
2023-05-10 7:28 ` Rinat Gadelshin
2023-05-08 7:58 ` Eiichi Tsukata [this message]
2023-05-08 7:58 ` [PATCH 3/4] audit: convert DECLARE_WAITQUEUE to DEFINE_WAIT Eiichi Tsukata
2023-05-08 7:58 ` [PATCH 4/4] audit: check if queue is full after prepare_to_wait_exclusive() Eiichi Tsukata
2023-05-08 17:13 ` kernel test robot
2023-05-09 1:44 ` Eiichi Tsukata
2023-05-08 14:07 ` [PATCH 0/4] audit: refactor and fix for potential deadlock Paul Moore
2023-05-09 1:34 ` Eiichi Tsukata
2023-05-10 8:09 ` Eiichi Tsukata
2023-05-17 16:15 ` Paul Moore
2023-05-17 16:03 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230508075812.76077-3-eiichi.tsukata@nutanix.com \
--to=eiichi.tsukata@nutanix.com \
--cc=audit@vger.kernel.org \
--cc=eparis@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®