Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3032804rdg; Tue, 17 Oct 2023 02:27:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbwu9fdnCKArjFhGE3xXhSNhZHfLbEvOEmk1x8n0SLOIoKBUF+SIjZccUb1KVG5yP+pKxm X-Received: by 2002:a17:90a:8a10:b0:27d:5946:5e2c with SMTP id w16-20020a17090a8a1000b0027d59465e2cmr1485284pjn.12.1697534823043; Tue, 17 Oct 2023 02:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697534823; cv=none; d=google.com; s=arc-20160816; b=U3oUHf63ao9Ujz/uGeOsiweEprlyU4zK7TgeIAD5CRggnLGhBe9rgp1UvREKhDTpKP cOpVWkyDBU6WFGdVnnTThV7ZUm5gS8XJT10i1xOEncDbp8YqfTP2hgDtXF3vsPbzf2NT ka6o+n7JB0ZD2iZzWYFJxxl/ApFzrfB7QtbMH/pDODriiPZjcvlXJC1D+z18DYiR7hKf CCmYzING/jEKe6wVafYiC83ozK/2j6fAljLhZQX4Kvf28FRGkQNDGpM2r/poNtcEFwe8 5/9Jh+2+8QQs3liIv5Yf9CsqAcJ5FSUoq1NUb9XfDqngbHMUxCzs1BgaR0ulBxuUyYjY U4vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=2ax4mAP+yVFBMlaJnxjACD7VuhYksjw5EpROGDN71OI=; fh=QAs9Z7ASEGiquGZOl6tUH28CaCcVKv5s8HKdiAFHzEQ=; b=OmlkGiLJA6rHIpUsMX1IUNkRODo5ZhQ9GD4Kohx2LXXcanPg54OwE9ZdateNxRtvD/ Y/QuXmEf4B8jWmtBB1ZGjgOi2cMCfwjdmT16BuNgXApfMvef7eYckKfIr9yo0FgOXAt5 tnurqpUh4J2oXJEgS3Rl7nv158c2pwpticC7bIgPtslEKoTCDgMVu7WevYSD5kAjImYZ jWuBu99BJnyxM1Lch9e9Q31kp3umZ4DMQ5gBfTi9/TbHWqlFzCYxNHGTPdzfhjwYLJt4 6/0nZVBT6ak1Y9wTTpu/TZa2pTbLsEkDs9QqvtMWQMazDcc5ZlrxrJLcAvonKpJdkqgJ b3pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=OZUkC9wC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id lk17-20020a17090b33d100b002774c98054csi1460198pjb.116.2023.10.17.02.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:27:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=OZUkC9wC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id CEC25803DB90; Tue, 17 Oct 2023 02:27:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234824AbjJQJ0m (ORCPT + 99 others); Tue, 17 Oct 2023 05:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234674AbjJQJ0k (ORCPT ); Tue, 17 Oct 2023 05:26:40 -0400 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1D18E; Tue, 17 Oct 2023 02:26:39 -0700 (PDT) Received: from [192.168.192.84] (unknown [50.39.103.33]) (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 smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 845403F6DB; Tue, 17 Oct 2023 09:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1697534797; bh=2ax4mAP+yVFBMlaJnxjACD7VuhYksjw5EpROGDN71OI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OZUkC9wC21O22v0mzYdRTM4vYccx+pGkrrXyvcSm4Zp5S80Y8MmNb+s/uyV/fvD6C ZBy7eMgHYL+1f5VhMbO2865/+yYG1Pb9Sgcn9bfOp+M4w/hutn2aWsJT6ryPe7NIVx QOQbde1wsUSHHao2Z/N1wWkwO7DxjZbM+RZKSGVEXVEs/T7TejZljwDUoGx2z0S2FZ RAAYgqKuXqrQYNhWW5kISQ4h2bkeYu0PvMbxSAHDad7zgyjg5PlF8jUU+ZUoNNHNQH wLdlRy+jRWd5qibuN4n4e2wVgkOL3fPSVSGEqqsn1MOUMHuOgD5LgD3EAYc7dPOCxL 48glrDVH1PYrQ== Message-ID: Date: Tue, 17 Oct 2023 02:26:35 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/4] apparmor: limit the number of buffers in percpu cache Content-Language: en-US To: Sergey Senozhatsky Cc: Anil Altinay , Sebastian Andrzej Siewior , LKLM , Peter Zijlstra , Tomasz Figa , linux-security-module@vger.kernel.org, John Johansen References: <4595e7b4-ea31-5b01-f636-259e84737dfc@canonical.com> <31d6e8d6-0747-a282-746b-5c144a9970bb@canonical.com> <20231006041837.GA17924@google.com> From: John Johansen Autocrypt: addr=john.johansen@canonical.com; keydata= xsFNBE5mrPoBEADAk19PsgVgBKkImmR2isPQ6o7KJhTTKjJdwVbkWSnNn+o6Up5knKP1f49E BQlceWg1yp/NwbR8ad+eSEO/uma/K+PqWvBptKC9SWD97FG4uB4/caomLEU97sLQMtnvGWdx rxVRGM4anzWYMgzz5TZmIiVTZ43Ou5VpaS1Vz1ZSxP3h/xKNZr/TcW5WQai8u3PWVnbkjhSZ PHv1BghN69qxEPomrJBm1gmtx3ZiVmFXluwTmTgJOkpFol7nbJ0ilnYHrA7SX3CtR1upeUpM a/WIanVO96WdTjHHIa43fbhmQube4txS3FcQLOJVqQsx6lE9B7qAppm9hQ10qPWwdfPy/+0W 6AWtNu5ASiGVCInWzl2HBqYd/Zll93zUq+NIoCn8sDAM9iH+wtaGDcJywIGIn+edKNtK72AM gChTg/j1ZoWH6ZeWPjuUfubVzZto1FMoGJ/SF4MmdQG1iQNtf4sFZbEgXuy9cGi2bomF0zvy BJSANpxlKNBDYKzN6Kz09HUAkjlFMNgomL/cjqgABtAx59L+dVIZfaF281pIcUZzwvh5+JoG eOW5uBSMbE7L38nszooykIJ5XrAchkJxNfz7k+FnQeKEkNzEd2LWc3QF4BQZYRT6PHHga3Rg ykW5+1wTMqJILdmtaPbXrF3FvnV0LRPcv4xKx7B3fGm7ygdoowARAQABzStKb2huIEpvaGFu c2VuIDxqb2huLmpvaGFuc2VuQGNhbm9uaWNhbC5jb20+wsF3BBMBCgAhBQJOjRdaAhsDBQsJ CAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJEAUvNnAY1cPYi0wP/2PJtzzt0zi4AeTrI0w3Rj8E Waa1NZWw4GGo6ehviLfwGsM7YLWF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/H7uPyIfeORAmHFPpkGFkZHHSCQfdP4XSc0Obk1olSxqzCAm uoVmRQZ3YyubWqcrBeIC3xIhwQ12rfdHQoopELzReDCPwmffS9ctIb407UYfRQxwDEzDL+m+ TotTkkaNlHvcnlQtWEfgwtsOCAPeY9qIbz5+i1OslQ+qqGD2HJQQ+lgbuyq3vhefv34IRlyM sfPKXq8AUTZbSTGUu1C1RlQc7fpp8W/yoak7dmo++MFS5q1cXq29RALB/cfpcwARAQABwsFf BBgBCgAJBQJOZqz6AhsMAAoJEAUvNnAY1cPYP9cP/R10z/hqLVv5OXWPOcpqNfeQb4x4Rh4j h/jS9yjes4uudEYU5xvLJ9UXr0wp6mJ7g7CgjWNxNTQAN5ydtacM0emvRJzPEEyujduesuGy a+O6dNgi+ywFm0HhpUmO4sgs9SWeEWprt9tWrRlCNuJX+u3aMEQ12b2lslnoaOelghwBs8IJ r998vj9JBFJgdeiEaKJLjLmMFOYrmW197As7DTZ+R7Ef4gkWusYFcNKDqfZKDGef740Xfh9d yb2mJrDeYqwgKb7SF02Hhp8ZnohZXw8ba16ihUOnh1iKH77Ff9dLzMEJzU73DifOU/aArOWp JZuGJamJ9EkEVrha0B4lN1dh3fuP8EjhFZaGfLDtoA80aPffK0Yc1R/pGjb+O2Pi0XXL9AVe qMkb/AaOl21F9u1SOosciy98800mr/3nynvid0AKJ2VZIfOP46nboqlsWebA07SmyJSyeG8c XA87+8BuXdGxHn7RGj6G+zZwSZC6/2v9sOUJ+nOna3dwr6uHFSqKw7HwNl/PUGeRqgJEVu++ +T7sv9+iY+e0Y+SolyJgTxMYeRnDWE6S77g6gzYYHmcQOWP7ZMX+MtD4SKlf0+Q8li/F9GUL p0rw8op9f0p1+YAhyAd+dXWNKf7zIfZ2ME+0qKpbQnr1oizLHuJX/Telo8KMmHter28DPJ03 lT9Q Organization: Canonical In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 17 Oct 2023 02:27:01 -0700 (PDT) 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 --- 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