mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Johansen <john.johansen@canonical.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Anil Altinay <aaltinay@google.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	LKLM <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Tomasz Figa <tfiga@chromium.org>,
	linux-security-module@vger.kernel.org,
	John Johansen <john.johansen@canonical.com>
Subject: Re: [PATCH v5 4/4] apparmor: limit the number of buffers in percpu cache
Date: Tue, 17 Oct 2023 02:26:35 -0700	[thread overview]
Message-ID: <ff0e8a95-7395-41b3-b3b4-e0f678a2a581@canonical.com> (raw)
In-Reply-To: <ffd13862-bc57-45ae-9fd0-454ee2d30fc2@canonical.com>

Force buffers to be returned to the global pool, regardless of contention
when the percpu cache is full. This ensures that the percpu buffer list
never grows longer than needed.

Signed-off-by: John Johansen <john.johansen@canonical.com>
---
  security/apparmor/lsm.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 52423d88854a..e6765f64f6bf 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -56,6 +56,7 @@ struct aa_local_cache {
  	struct list_head head;
  };
  
+#define MAX_LOCAL_COUNT 2
  #define RESERVE_COUNT 2
  static int reserve_count = RESERVE_COUNT;
  static int buffer_count;
@@ -1878,9 +1879,15 @@ void aa_put_buffer(char *buf)
  
  	cache = get_cpu_ptr(&aa_local_buffers);
  	if (!cache->hold) {
+		bool must_lock = cache->count >= MAX_LOCAL_COUNT;
+
  		put_cpu_ptr(&aa_local_buffers);
  
-		if (spin_trylock(&aa_buffers_lock)) {
+		if (must_lock) {
+			spin_lock(&aa_buffers_lock);
+			goto locked;
+		} else if (spin_trylock(&aa_buffers_lock)) {
+		locked:
  			/* put back on global list */
  			list_add(&aa_buf->list, &aa_global_buffers);
  			buffer_count++;
-- 
2.34.1



  parent reply	other threads:[~2023-10-17  9:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 13:19 apparmor: global buffers spin lock may get contended Sergey Senozhatsky
2021-08-15  9:47 ` John Johansen
2022-10-28  9:34 ` John Johansen
2022-10-31  3:52   ` Sergey Senozhatsky
2022-10-31  3:55     ` John Johansen
2022-10-31  4:04       ` Sergey Senozhatsky
2023-02-17  0:03         ` John Johansen
2023-02-17  0:08       ` [PATCH v3] " John Johansen
2023-02-17 10:44         ` Sebastian Andrzej Siewior
2023-02-20  8:42           ` John Johansen
2023-02-21 21:27             ` Anil Altinay
2023-06-26 23:35               ` Anil Altinay
     [not found]               ` <CACCxZWO-+M-J_enENr7q1WDcu1U8vYFoytqJxAh=x-nuP268zA@mail.gmail.com>
2023-06-27  0:31                 ` John Johansen
2023-10-06  4:18                   ` Sergey Senozhatsky
2023-10-17  9:21                     ` [PATCH v5 0/4] apparmor: cache buffers on percpu list if there is lock, contention John Johansen
2023-10-17  9:23                       ` [PATCH v5 1/4] " John Johansen
2023-10-17  9:24                       ` [PATCH v5 2/4] apparmor: exponential backoff on cache buffer contention John Johansen
2023-10-17  9:25                       ` [PATCH v5 3/4] apparmor: experiment with faster backoff on global buffer John Johansen
2023-10-17  9:26                       ` John Johansen [this message]
2023-10-26  5:13                       ` [PATCH v5 0/4] apparmor: cache buffers on percpu list if there is lock, contention Sergey Senozhatsky
     [not found] ` <20221030013028.3557-1-hdanton@sina.com>
2022-10-30  6:32   ` apparmor: global buffers spin lock may get contended John Johansen

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=ff0e8a95-7395-41b3-b3b4-e0f678a2a581@canonical.com \
    --to=john.johansen@canonical.com \
    --cc=aaltinay@google.com \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=senozhatsky@chromium.org \
    --cc=tfiga@chromium.org \
    /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®