From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754098AbdJaXs6 (ORCPT ); Tue, 31 Oct 2017 19:48:58 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:49556 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752859AbdJaXs4 (ORCPT ); Tue, 31 Oct 2017 19:48:56 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Christian Brauner Cc: linux-kernel@vger.kernel.org, serge@hallyn.com, tycho@tycho.ws, Linux Containers References: <20171024220441.10235-1-christian.brauner@ubuntu.com> <20171024220441.10235-2-christian.brauner@ubuntu.com> <871sliubhj.fsf_-_@xmission.com> Date: Tue, 31 Oct 2017 18:48:46 -0500 In-Reply-To: <871sliubhj.fsf_-_@xmission.com> (Eric W. Biederman's message of "Tue, 31 Oct 2017 18:46:32 -0500") Message-ID: <87efpiswtd.fsf_-_@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1e9gH4-0000g7-9N;;;mid=<87efpiswtd.fsf_-_@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=174.19.78.123;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+n+J0DPXEO4M6WrJlaLcBHojRN4ioLGus= X-SA-Exim-Connect-IP: 174.19.78.123 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.5 XMGappySubj_01 Very gappy subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4950] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Christian Brauner X-Spam-Relay-Country: X-Spam-Timing: total 5549 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.6 (0.1%), b_tie_ro: 2.5 (0.0%), parse: 1.51 (0.0%), extract_message_metadata: 18 (0.3%), get_uri_detail_list: 2.1 (0.0%), tests_pri_-1000: 9 (0.2%), tests_pri_-950: 1.87 (0.0%), tests_pri_-900: 1.44 (0.0%), tests_pri_-400: 22 (0.4%), check_bayes: 21 (0.4%), b_tokenize: 8 (0.2%), b_tok_get_all: 5 (0.1%), b_comp_prob: 2.4 (0.0%), b_tok_touch_all: 2.5 (0.0%), b_finish: 0.71 (0.0%), tests_pri_0: 278 (5.0%), check_dkim_signature: 0.93 (0.0%), check_dkim_adsp: 4.5 (0.1%), tests_pri_500: 5209 (93.9%), poll_dns_idle: 5202 (93.7%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 4/5] userns: Make map_id_down a wrapper for map_id_range_down X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no good reason for this code duplication, the number of cache line accesses not the number of instructions are the bottleneck in this code. Therefore simplify maintenance by removing unnecessary code. Signed-off-by: "Eric W. Biederman" --- kernel/user_namespace.c | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 4f7e357ac1e2..1d0298870ee3 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -313,45 +313,9 @@ static u32 map_id_range_down(struct uid_gid_map *map, u32 id, u32 count) return id; } -/** - * map_id_down_base - Find idmap via binary search in static extent array. - * Can only be called if number of mappings is equal or less than - * UID_GID_MAP_MAX_BASE_EXTENTS. - */ -static struct uid_gid_extent * -map_id_down_base(unsigned extents, struct uid_gid_map *map, u32 id) -{ - unsigned idx; - u32 first, last; - - /* Find the matching extent */ - for (idx = 0; idx < extents; idx++) { - first = map->extent[idx].first; - last = first + map->extent[idx].count - 1; - if (id >= first && id <= last) - return &map->extent[idx]; - } - return NULL; -} - static u32 map_id_down(struct uid_gid_map *map, u32 id) { - struct uid_gid_extent *extent; - unsigned extents = map->nr_extents; - smp_rmb(); - - if (extents <= UID_GID_MAP_MAX_BASE_EXTENTS) - extent = map_id_down_base(extents, map, id); - else - extent = map_id_range_down_max(extents, map, id, 1); - - /* Map the id or note failure */ - if (extent) - id = (id - extent->first) + extent->lower_first; - else - id = (u32) -1; - - return id; + return map_id_range_down(map, id, 1); } /** -- 2.14.1