Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39F55C6FD18 for ; Sat, 4 Mar 2023 20:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjCDUmZ (ORCPT ); Sat, 4 Mar 2023 15:42:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbjCDUmX (ORCPT ); Sat, 4 Mar 2023 15:42:23 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C19813D66; Sat, 4 Mar 2023 12:42:22 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id t22so4347613oiw.12; Sat, 04 Mar 2023 12:42:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677962542; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6A+lkGAA36imPClPUvyK1Oj/1mGA4QYHzNMLvCHSzGg=; b=hnkof/Ljt4H+uAYJCcodGlLzNPBBCka6TafMshG1e2mWJrikbr5sthB3jUMToe+1ry 3zd4hKmTLO/zDXi8HGLosfYt+lXLItHICdWm3ZUBAjOhYjopkn7slegDQnokWt9rNksp CPbQG2hTbj46JXSg3uOyl7na33lY+LrGE8+ZTWLvYbuaG3DzPL3L5CtNvraPDIyVV1ff OCz6M1msYu7HQnUrX+ppDHsHA4WmHFZ2aoeZYcdgWWn/olDTxdUjh9u29f3fE2/nDg7x V/L4wrr2zxuFslu+0ES9qs+SMG9jw6P3Jtd/BEihqOpQ+Ay9SW5lzDFSR8cA4m5cGm0V M1YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677962542; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6A+lkGAA36imPClPUvyK1Oj/1mGA4QYHzNMLvCHSzGg=; b=Si8QV0+YVGX3sFOmq9r7L1khItJ6H8LaEpCbWRPthSSEcfb5LFFQKsQBAQ8kUhiMIw aHpT2cKUCBuiE0+5yZaeKnTwQaDGBrD1+tPEQ1uUx6jr0vDsmHExD2vFff7Mqd0iqO4p eH6XUQUSI4H7IJhqMdCs29Chkm3d5nQvUX/pqgi5ES4U7oiKksMOsq1RPX6BBYCcZDaS xBOi+jWmH6C5k72LjqJlE7qDf+18qX3AQ2Fl9WJhckDuaxSPoi2Au9Wd0nFa5/vaa5ta p2CEyMENHO30WHzXYZbSIM1tS5QVXJ7awGSeQ6Ym+cOpvkMSgzoUEk/5C1CfM3QPDMVt gXwA== X-Gm-Message-State: AO0yUKX9fwZGER9Y2fo2VunGnSk2yjDcCNj7hOjtDh7d8UapkT0MO83m PCbxZv2MxmgQ7A3XTeA0biq5B5jAYLzh01DGy4U= X-Google-Smtp-Source: AK7set8Rs1QYDXu0qkMG7u5vSziTiaqw1wUpODsY7Tgu865vxSmEFsTOnPlibOeGKtkzYpujai68yHCJ+LlYmZIXeH8= X-Received: by 2002:a05:6808:2098:b0:383:f981:b1e5 with SMTP id s24-20020a056808209800b00383f981b1e5mr4740995oiw.5.1677962541759; Sat, 04 Mar 2023 12:42:21 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:6802:31f:b0:4c2:d201:fe1f with HTTP; Sat, 4 Mar 2023 12:42:21 -0800 (PST) In-Reply-To: References: <6400fedb.170a0220.ece29.04b8@mx.google.com> From: Mateusz Guzik Date: Sat, 4 Mar 2023 21:42:21 +0100 Message-ID: Subject: Re: [PATCH v3 2/2] vfs: avoid duplicating creds in faccessat if possible To: Al Viro Cc: Linus Torvalds , Alexander Potapenko , Kees Cook , Eric Biggers , Christian Brauner , serge@hallyn.com, paul@paul-moore.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/4/23, Al Viro wrote: > On Fri, Mar 03, 2023 at 09:39:11PM +0100, Mateusz Guzik wrote: > >> the allocation routine does not have any information about the size >> available at compilation time, so has to resort to a memset call at >> runtime. Instead, should this be: >> >> f = kmem_cache_alloc(...); >> memset(f, 0, sizeof(*f)); >> >> ... the compiler could in principle inititalize stuff as indicated by >> code and emit zerofill for the rest. Interestingly, last I checked >> neither clang nor gcc knew how to do it, they instead resort to a full >> sized memset anyway, which is quite a bummer. > > For struct file I wouldn't expect a win from that, TBH. > That was mostly for illustrative purposes, but you are right -- turns out the slab is 256 bytes in size per obj and only a small fraction of it is inititalized in the allocation routine. Good candidate to always punt to memset in the allocator as it happens now. Bummer though, it is also one of the 2 most memset'ed during kernel build. The other one allocated at the same rate is lsm_file_cache and that's only 32 bytes in size, so it will get a win. -- Mateusz Guzik