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 B4663C7EE32 for ; Fri, 3 Mar 2023 20:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231773AbjCCU6p (ORCPT ); Fri, 3 Mar 2023 15:58:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231415AbjCCU6m (ORCPT ); Fri, 3 Mar 2023 15:58:42 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EEFA17145 for ; Fri, 3 Mar 2023 12:58:33 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id g3so15435465eda.1 for ; Fri, 03 Mar 2023 12:58:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1677877111; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1o4OY5lQPKh+GkI89Rz6TXZXk/LYf31mRBJK3Sl9ezg=; b=he65XQOu+UTB4in3Szyiw11xAa8mqRP2ytbOj4xIHb6LvrWUZKUzdsqGCCEJ1W4C3X TuMyEiexc/qgDlzevsKPjI04q8h/4QsxnWeO2rFK26G98RH928vITMEmJoE2GmYgnrT9 +mC3ntKhkSOfnIoYv0aY8TgoZDk1kMSa2WELY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677877111; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1o4OY5lQPKh+GkI89Rz6TXZXk/LYf31mRBJK3Sl9ezg=; b=iLmsKqDK/yxWZQDn8A8yZ7bfyUJPAtE1qZ8LTn2edxSmy73jaiUwj5CqefHVP5yDDi Y/3mASsBJQaxrVdd4MvpGlCGaqQv1IHO4Fz4O/NlxmDdEnOnZfLo0wObxNL6seKX5KmA MSdtzjPwGMLyRCzlmIz/gEqI7ypkXYlgEGFm2i1sfOEApJwfYunyvsDgKneBCl4oSykf v5UR3mbOwgsDXQeCeph6Vfbpr5Q/LYW4s2fwWUXN/BtfaR0E1OR77rj1aoZR9kQOPY/G XQIJLA24S/R8quxhpK4yGrkxFN0+mTrL2dx61QISciEsU86QqKPBSdQFsup9LW6Vqnp8 FCCQ== X-Gm-Message-State: AO0yUKWwZzG/slkmsniLeN2edVX/4gyY6pq3Zxh9q5dmxbjixVXrBP4e gXmHXL2p6wHZdnMXJJRmn34Rg65ugcfjumHLApu2mg== X-Google-Smtp-Source: AK7set+heXTvPJi8Jqm4Nl/lLabmZbxQHkGm4oXsMsfCuZY1OKEE0jTNZgNOyrPEFQEBN/Hj3av9iw== X-Received: by 2002:a17:906:a00a:b0:87b:d3f3:dcf3 with SMTP id p10-20020a170906a00a00b0087bd3f3dcf3mr2540396ejy.35.1677877111531; Fri, 03 Mar 2023 12:58:31 -0800 (PST) Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com. [209.85.208.43]) by smtp.gmail.com with ESMTPSA id n13-20020a170906164d00b008deba75e89csm1342236ejd.66.2023.03.03.12.58.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Mar 2023 12:58:30 -0800 (PST) Received: by mail-ed1-f43.google.com with SMTP id f13so15327817edz.6 for ; Fri, 03 Mar 2023 12:58:30 -0800 (PST) X-Received: by 2002:a17:906:3d51:b0:8f1:4c6a:e72 with SMTP id q17-20020a1709063d5100b008f14c6a0e72mr1497478ejf.0.1677877109830; Fri, 03 Mar 2023 12:58:29 -0800 (PST) MIME-Version: 1.0 References: <20230302083025.khqdizrnjkzs2lt6@wittgenstein> <6400fedb.170a0220.ece29.04b8@mx.google.com> In-Reply-To: From: Linus Torvalds Date: Fri, 3 Mar 2023 12:58:13 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 2/2] vfs: avoid duplicating creds in faccessat if possible To: Mateusz Guzik Cc: Alexander Potapenko , Al Viro , 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" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 3, 2023 at 12:39=E2=80=AFPM Mateusz Guzik w= rote: > > I think there is a systemic problem which comes with the kzalloc API Well, it's not necessarily the API that is bad, but the implementation. We could easily make kzalloc() with a constant size just expand to kmalloc+memset, and get the behavior you want. We already do magical things for "find the right slab bucket" part of kmalloc too for constant sizes. It's changed over the years, but that policy goes back a long long time. See https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/= ?id=3D95203fe78007f9ab3aebb96606473ae18c00a5a8 from the BK history tree. Exactly because some things are worth optimizing for when the size is known at compile time. Maybe just extending kzalloc() similarly? Trivial and entirely untested pat= ch: --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -717,6 +717,12 @@ static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags) */ static inline __alloc_size(1) void *kzalloc(size_t size, gfp_t flags) { + if (__builtin_constant_p(size)) { + void *ret =3D kmalloc(size, flags); + if (ret) + memset(ret, 0, size); + return ret; + } return kmalloc(size, flags | __GFP_ZERO); } This may well be part of what has changed over the years. People have done a *lot* of pseudo-automated "kmalloc+memset -> kzalloc" code simplification. And in the process we've lost a lot of good optimizations. I used to do profiling religiously, but these days I only do it for particular areas (usually just the walking part of pathname lookup) Linus