Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2414099ybg; Fri, 5 Jun 2020 13:20:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYQBbdYVrcsq+0aIp+C0I7RGiRpBCo1J/ESzlaN6hwWSrjdkjBmyJqxrt2nU1FxtIRqALc X-Received: by 2002:a17:906:2dc7:: with SMTP id h7mr3271669eji.15.1591388456275; Fri, 05 Jun 2020 13:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591388456; cv=none; d=google.com; s=arc-20160816; b=webx1HYdzqXij+f5YuUmAw+kYH+qt1KhMUJ0cNWcVSqOqkHGX27p2IcCCKDD8tNzoV DLnKVNomjNu+eFdfPA5KCyG9AU7QQ0yrKNpJlKsKMJgeYF4RcqxAuxfyFs0K3LUMNEda LAQO0C/PC+7+rQQZIBMSRqtUj4mCX1eRm/fstZiWZChjyUCHIdsmbLfia4EheeVh04W5 ya8pLHRablkK/I/GCzHwOk83DbcpL1g84EELDc5TAZxHe4vmQrMmsjrwb9LEmXJA8FcE OIXZyMESYn2fJYDZArGAx1lKSQvICjbyBj3CcQ0WZn2j0jqb+cq8upQST5UGdJK6zpja Qwbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IyZXapUgSv5A3j8QPmWLFE2iYeTmmUoWDYx23agQz54=; b=QzDGeD5FCog6Ej3iYvFGbLG9jjMbvlz1xz+F8aVLOQqnz1WFDI2qw4s26+do+R5qDE MD7h2m8HVemtOHee/NKYuxP0uKzhwULe3/pWROys+Koqkuz1MyVCgVq3BlUJgU5d+5CT DTYx2oTVGiAZIRWBu86OmRP09p0+j4fj8pG9fVFMSFwmrW0Y85CxRsLUnEN9GpOynhUb D2foNtCkON8Dipimt8kJEmOobfmFOz2uspKfFuoWx2i5KXXzQEHDvvZ29Npuw2CYCpnC AZw5del1ELorSbWskpTdaoEkDc3q43KMvzqORpl/F6WydBebb8BVn2IlSszIzYqARajS PShA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=YYiqnQqM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si1192187edv.82.2020.06.05.13.20.33; Fri, 05 Jun 2020 13:20:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=YYiqnQqM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728228AbgFEUSm (ORCPT + 99 others); Fri, 5 Jun 2020 16:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727087AbgFEUSm (ORCPT ); Fri, 5 Jun 2020 16:18:42 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A97F1C08C5C2 for ; Fri, 5 Jun 2020 13:18:41 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id z9so13246708ljh.13 for ; Fri, 05 Jun 2020 13:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IyZXapUgSv5A3j8QPmWLFE2iYeTmmUoWDYx23agQz54=; b=YYiqnQqM7NGXKi3qv8b8zw6+JFTu2Oks5vDFwqewXnT0C6nTwpTLvRv+w2vnIa50ux JZ7XEsvqzKMuyX0XT2Geu6g1Zz10yr/6Oj4g/6IlEAL2qAV72//YEpWmVsYTPafRKhOj Z3RVMkeziQuTJT8/AGw71xR8ZWIsB0ShrmBC0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IyZXapUgSv5A3j8QPmWLFE2iYeTmmUoWDYx23agQz54=; b=m83CVICiLW1a3fk70gTs0V2s/D84fuJ6ySolcgPXCsakugB4w8ABNiSKn6s/tWNZa6 PeVW9/vNraGJ71UaSeXRXNJqRFFc60Nx04MAl9wXZWCd2rUVhi4me1uCC+gJ4LzKrHDz oojZwfYwh+BSr0B+f7fT1U3Qw0+IrVmBQpQHFXXJK7cpOSIaFRz2Wf39aNhxHJaJJpLa oXMzcWndSxDGDfvbnsGgkxKCVrnJ/pCeElWptHEP1wbj2qlEQYcBrTjzow06djh6bp9V ZqfOZ+G9nf/1IsmaOWsFVcT19E65nm1fZK858QsgBqIrk3YSYZaNK62oZ7aS4UBP2Rl3 YHIw== X-Gm-Message-State: AOAM531kooFeUCU5kJqdC63SifRTBmSt8LZt/gbgQSL9k7hJbtQCBvrN zZFLan5YP/1QbShK35JkmMFAcyGPED4= X-Received: by 2002:a05:651c:391:: with SMTP id e17mr5173018ljp.373.1591388319552; Fri, 05 Jun 2020 13:18:39 -0700 (PDT) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com. [209.85.208.173]) by smtp.gmail.com with ESMTPSA id w25sm1359068lfn.42.2020.06.05.13.18.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jun 2020 13:18:38 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id a9so9717717ljn.6 for ; Fri, 05 Jun 2020 13:18:38 -0700 (PDT) X-Received: by 2002:a2e:b5d9:: with SMTP id g25mr5890987ljn.285.1591388317824; Fri, 05 Jun 2020 13:18:37 -0700 (PDT) MIME-Version: 1.0 References: <20200605142300.14591-1-linux@rasmusvillemoes.dk> In-Reply-To: <20200605142300.14591-1-linux@rasmusvillemoes.dk> From: Linus Torvalds Date: Fri, 5 Jun 2020 13:18:21 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH resend] fs/namei.c: micro-optimize acl_permission_check To: Rasmus Villemoes Cc: Alexander Viro , linux-fsdevel , Linux Kernel Mailing List Content-Type: multipart/mixed; boundary="0000000000006294c705a75bf797" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000006294c705a75bf797 Content-Type: text/plain; charset="UTF-8" On Fri, Jun 5, 2020 at 7:23 AM Rasmus Villemoes wrote: > > + /* > + * If the "group" and "other" permissions are the same, > + * there's no point calling in_group_p() to decide which > + * set to use. > + */ > + if ((((mode >> 3) ^ mode) & 7) && in_group_p(inode->i_gid)) > mode >>= 3; Ugh. Not only is this ugly, but it's not even the best optimization. We don't care that group and other match exactly. We only care that they match in the low 3 bits of the "mask" bits. So if we want this optimization - and it sounds worth it - I think we should do it right. But I also think it should be written more legibly. And the "& 7" is the same "& (MAY_READ | MAY_WRITE | MAY_EXEC)" we do later. In other words, if we do this, I'd like it to be done even more aggressively, but I'd also like the end result to be a lot more readable and have more comments about why we do that odd thing. Something like this *UNTESTED* patch, perhaps? I might have gotten something wrong, so this would need double-checking, but if it's right, I find it a _lot_ more easy to understand than making one expression that is pretty complicated and opaque. Hmm? Linus --0000000000006294c705a75bf797 Content-Type: application/octet-stream; name=patch Content-Disposition: attachment; filename=patch Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kb2ni6c00 IGZzL25hbWVpLmMgfCAzNyArKysrKysrKysrKysrKysrKysrKysrKy0tLS0tLS0tLS0tLS0tCiAx IGZpbGUgY2hhbmdlZCwgMjMgaW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