Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2214263rdh; Tue, 26 Sep 2023 16:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAkP3FOIOUa0blU7FzLqi67LFcJvbMYAsaqgGdrvR7llNkjslZW3ZlhPaG9TX3F2xSfQkq X-Received: by 2002:a05:6870:64aa:b0:1bf:50e0:95d9 with SMTP id cz42-20020a05687064aa00b001bf50e095d9mr646495oab.26.1695772333428; Tue, 26 Sep 2023 16:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695772333; cv=none; d=google.com; s=arc-20160816; b=F9UM/J793GpMaCr+MaDjYooMBf/hNnxYuEODifayc8oKLJEW8Q6NKMno2/zdI1OK2l Y5NeLmTbbHjGDY+QHsBQvTgiwxrrdJIoCY4MXqBIbHdDUeShmbXarmWf62NzUhb0vzRo 4Woua4K0DfRq7BUZvcfv39gYNkJTYN+kYZDcjzwkwtlNb3WN979dulDGLHd1vklInbtO h20iU5NBTRuPu0usG0ntLCrbjcGLwfVkCpu4KKRspTmBqzrcBQwAJ4NODzkr5h/5C4J2 E+itH1QO2uNk5ItvbZCJXFpl2I5UOBDNStZpVHlO+4M6yjUiYSkSTE3BXX1q722X0ZQ3 BuCw== 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:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=gsf5Dcm+oBvt0OepvgcW/nShbExlI1OvGeUPMDjYhrI=; fh=fctvfrKtqpr+29SlGEaJ8EZxYWDyueOLWkShIvh7+/w=; b=ghhSJUSFZNtvTpC6+DaL4sSl7oWVzbXXqWxoaoVNmd2/jCtnwwKUij1m1Pk9Jf0A2Z P6AmZWTpYL7XMPiJUTX+o5OZreHX2MijiWCrFf4ZoKjRz0Br0hodbfXgbFtH0FkgVAwK I06F4jYCYwOBstHmN6AnZUzQ11nmnnUhgLkrVmIHQwVbQ7j/68ksP/iUZwM6YLL135W8 yc85ebzDcHgYxG/v7xDwOWmZOj/HH+l8PRHlnuYE1UvWFGuvnKE5SVwicJoxDLSw1eWl QIAcdYQ89r6W/VRNd/Vcu8EOiPswnNhh4+l5HalbYkKPNjOHpUP6f82nBfN+pSJzIytV IiUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=II5niPaD; 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 be3-20020a656e43000000b00578a30162c8si10646646pgb.537.2023.09.26.16.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 16:52:13 -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=II5niPaD; 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 01A4B802D3F8; Tue, 26 Sep 2023 05:49:01 -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 S234688AbjIZMtC (ORCPT + 99 others); Tue, 26 Sep 2023 08:49:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234560AbjIZMtA (ORCPT ); Tue, 26 Sep 2023 08:49:00 -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 778A7FB; Tue, 26 Sep 2023 05:48:53 -0700 (PDT) Received: from [192.168.192.83] (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 744923F1DB; Tue, 26 Sep 2023 12:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1695732531; bh=gsf5Dcm+oBvt0OepvgcW/nShbExlI1OvGeUPMDjYhrI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=II5niPaDBIMHxuG6ai8j6A+VHw++umAb1/E4ACNhGAdkyVH69wgavwqr9ZPIjClHR GkhrpvCUh6Sin2lx08+/pC+RXzF0HBSDDicEpaWmCUDSZUjD8jfDv3zDsxjslbtY6h hr8z09Ow0rPItwwHeOTESsnnk8+4Fc8E4xfegqpIEV1mOldn5bgUhNKttg/k2/zTyv OPOfMkrjEAYnEIggXcNXOdje0KMrIGUgy++xBlAk99wZSB5lgKoUMMPJF+fWKMa6rw Y99dUivatZ1SI/YtvFM6C0czTelLMOLT2p3RBoY4ZKCvkjBsmjKQpanbiHUJnUv2i8 IV/tgYC3HBivg== Message-ID: Date: Tue, 26 Sep 2023 05:48:47 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [apparmor] use per-cpu refcounts for apparmor labels? Content-Language: en-US To: Mateusz Guzik Cc: Vinicius Costa Gomes , linux-security-module@vger.kernel.org, apparmor@lists.ubuntu.com, linux-kernel@vger.kernel.org References: <87a5t9bypm.fsf@intel.com> <20230926063857.h3afce5hagnlkoob@f> From: John Johansen Organization: Canonical In-Reply-To: <20230926063857.h3afce5hagnlkoob@f> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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, 26 Sep 2023 05:49:01 -0700 (PDT) On 9/25/23 23:38, Mateusz Guzik wrote: > On Mon, Sep 25, 2023 at 11:21:26PM -0700, John Johansen wrote: >> On 9/25/23 16:49, Vinicius Costa Gomes wrote: >>> Hi Mateusz, >>> >>> Mateusz Guzik writes: >>> >>>> I'm sanity-checking perf in various microbenchmarks and I found >>>> apparmor to be the main bottleneck in some of them. >>>> >>>> For example: will-it-scale open1_processes -t 16, top of the profile: >>>> 20.17% [kernel] [k] apparmor_file_alloc_security >>>> 20.08% [kernel] [k] apparmor_file_open >>>> 20.05% [kernel] [k] apparmor_file_free_security >>>> 18.39% [kernel] [k] apparmor_current_getsecid_subj >>>> [snip] >>>> >>>> This serializes on refing/unrefing apparmor objs, sounds like a great >>>> candidate for per-cpu refcounting instead (I'm assuming they are >>>> expected to be long-lived). >>>> >>>> I would hack it up myself, but I failed to find a clear spot to switch >>>> back from per-cpu to centalized operation and don't want to put >>>> serious effort into it. >>>> >>>> Can you sort this out? >>> >> >> I will add looking into it on the todo list. Its going to have to come >> after some other major cleanups land, and I am not sure we can make >> the semantic work well for some of these. For other we might get away >> with switching to a critical section like Vinicius's patch has done >> for apparmor_current_getsecid_subj. >> > > Is there an eta? > sorry no > I looked at dodging ref round trips myself, but then found that ref > manipulation in apparmor_file_alloc_security and the free counterpart > cannot be avoided. Thus per-cpu refs instead. > right for file_aloc/free, I don't see a way around keeping a ref count. > Perhaps making the label as stale would be a good enough switching > point? Is it *guaranteed* to get labelled as stale before it gets freed? > no. the stale flag only indicates the label has been replaced, and we make no guarentees as to when it will get set/be in use beyond so point after it happens. > btw, __aa_proxy_redirect open-codes setting the flag. > yes, I am aware. >>> I was looking at this same workload, and proposed a patch[1] some time >>> ago, see if it helps: >>> >>> https://lists.ubuntu.com/archives/apparmor/2023-August/012914.html >>> >>> But my idea was different, in many cases, we are looking at the label >>> associated with the current task, and there's no need to take the >>> refcount. >>> >> >> yes, and thanks for that. >>