Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1284155ybp; Wed, 9 Oct 2019 11:36:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqytA3X/BSiex1g8UZq5ygzYA9Zd7EntQNUUJo7ywuBylWO6tDV9ZWXtwTStvTK6g74uYbg8 X-Received: by 2002:a17:906:48cf:: with SMTP id d15mr4283164ejt.59.1570646179211; Wed, 09 Oct 2019 11:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570646179; cv=none; d=google.com; s=arc-20160816; b=z8xUf0X7mO7zeoq3T+gyIGjNGEW/uHeyExg99aZtMC0g7sUAx+bSs97Xo2IbsExIbZ tPnBvq5rub/X5ed/vECvZwyhEPd+/pEyz6S4yUYeIG4KXIl/QnSRCb3h8t0iwa2qKKRc 4Z79aWF/tZZfiXALXvJeHBEy6V0u9BnmpcMmNowWNZKjHYYtJYAXdfUmfdxtMUuaCWdW VbYFN10kP3abgp26oH8AxMrjl+ZI9emMUH3tARasfTvIg6qURlEZURbhy7jl4h22J9FM igbrHG9mM2Rl3qo861qetXzFClb+1IjSWtPPiJNyFg5yYhDvgs35tHLeqFwk66Nj+6Gs EY6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=RwDkFnOafd0e5q4R3PlRBWVZf3IusPOaHvh7uIeYbOs=; b=gtul34fBOvg08yLNhJWnrFPCVJAaVgXDLYFLnWuPJ24VD6JhYSoJKEgLtv1Zq1l6zv BCfbXriwgKPG6ID8zmFGbbjvX/3CfMUmiz0xvw36RoWDL2FKOkt9gpRevDEWrMY7o29/ pQGNv5RL+ztunNbW2CFOmTIzS3bgruEkow2FesWL9Tm2K4v8t8tb2nU2nQNC+ofP+RTE NXBUsIUzKXBrPPbzZtyxXQtTx1GKTJ2A9LR4vH8yznw7LvnVReo5gP2hhD5pAR4Hnvo3 FmuvzsotWxlWGvxRoLuV/zAsjzZ/dsUEf9APqPWqqJ6BLXNBL4VyZR+fv4gJ07qL5kwd xp1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v53si1817736edc.378.2019.10.09.11.35.55; Wed, 09 Oct 2019 11:36:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731340AbfJISff (ORCPT + 99 others); Wed, 9 Oct 2019 14:35:35 -0400 Received: from www17.your-server.de ([213.133.104.17]:49446 "EHLO www17.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731144AbfJISfe (ORCPT ); Wed, 9 Oct 2019 14:35:34 -0400 Received: from sslproxy01.your-server.de ([88.198.220.130]) by www17.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1iIGo8-0003dQ-9e; Wed, 09 Oct 2019 20:35:32 +0200 Received: from [2a02:908:4c22:ec00:8ad5:993:4cda:a89f] (helo=localhost.localdomain) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1iIGo7-0008Ma-Ve; Wed, 09 Oct 2019 20:35:32 +0200 From: Thomas Meyer To: Rasmus Villemoes Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel/groups.c: use bsearch library function References: <20191007192632.29535-1-thomas@m3y3r.de> <60e43953-a7f9-c52e-150c-74059d1b377b@rasmusvillemoes.dk> Date: Wed, 09 Oct 2019 20:35:29 +0200 In-Reply-To: <60e43953-a7f9-c52e-150c-74059d1b377b@rasmusvillemoes.dk> (Rasmus Villemoes's message of "Wed, 9 Oct 2019 09:46:21 +0200") Message-ID: <875zkxydfy.fsf@m3y3r.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Authenticated-Sender: thomas@m3y3r.de X-Virus-Scanned: Clear (ClamAV 0.101.4/25597/Wed Oct 9 10:39:14 2019) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rasmus Villemoes writes: > On 07/10/2019 21.26, Thomas Meyer wrote: >> commit b7b2562f7252 ("kernel/groups.c: use sort library function") >> introduced the sort library function. >> also use the bsearch library function instead of open-coding the binary >> search. Hi, > Yes, but please note the difference between sorting the group_info and > searching it: The former is done quite rarely - the setgroups syscall is > used roughly once per login-session. > > But the searching of that structure is done more or less every time a > user accesses a file not owned by that user (e.g., any time a normal > user accesses anything in /usr) - at least if I'm reading > acl_permission_check() right. > > So using a callback-based interface, especially in a post-spectre world, > may have a somewhat large performance impact. okay, so the code is duplicated for performance reasons? nothing a compiler can inline, I guess. so what about a comment instead: diff --git a/kernel/groups.c b/kernel/groups.c index daae2f2dc6d4f..46b5d4cd53c2e 100644 --- a/kernel/groups.c +++ b/kernel/groups.c @@ -93,7 +93,7 @@ void groups_sort(struct group_info *group_info) } EXPORT_SYMBOL(groups_sort); -/* a simple bsearch */ +/* duplicate code from lib/bsearch.c for performance reasons */ int groups_search(const struct group_info *group_info, kgid_t grp) { unsigned int left, right; Mfg thomas