Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp286204lqg; Fri, 1 Mar 2024 05:26:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcX5INmzzo6XUQAPhP1sc/hLWhj79UtecLYNIW+ggVRg7/vUmCvD0Rp6e5JyzmytYNqd3JnYshaGiEqpFBlnzwLauH2ppb3KNurnMvzg== X-Google-Smtp-Source: AGHT+IGU+uykPsYX+wYP2y0HSXhA/KQWHmvx6WtoGv6pjbKona+H9rNyaIAXnGzY94JYKHdOOG6b X-Received: by 2002:a50:8dc5:0:b0:566:ef9:30ce with SMTP id s5-20020a508dc5000000b005660ef930cemr1371022edh.3.1709299565755; Fri, 01 Mar 2024 05:26:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709299565; cv=pass; d=google.com; s=arc-20160816; b=W/s6dtnIjLREvkhiJ694k9AzKoyHTX3X0d/iUMBxvJfyDvtXrOraCB9uP2qOGGhNt1 0dvAzeBBZf+ddgnMlgkAgeu3b53cwiWfIv7Vq3JC81GdzZpK4N0cEJnYosMl/6JPRnce aoq7nJUWtpYXsTqekp8C7Whm/AeF8tWCeCluLhX6Q183YDqOXF1OBFze2P6i7RE+9gb+ hmoP+uGJz56M3L5kgxEZRRQUBYWuGWmHfI+a0Nh5paShi2LCFqVoThaLyRpS/60oYBeG lh9xUCwPBm4OuuXrO/Ltdud39//OMR7vYXhSfHIYJxPQpaezN0WSSHM8cpU62Aj/T0T6 Qjjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=+1teAiWc1jVGCssi6rgN3jeMMtmC7N9NmiOj97TQSRI=; fh=thCNqNN3d4lqiiyNYs0cH6dTo3YJ2hmaoXWbhK5i1wA=; b=EVBMMfN8/Ag4jG/gMTOmq/zDzrQqi/kyE04KCg623WaZBq/8PbD3Kj/tkE0HrszAJ5 0/ezfs/Ah5FKrT7zF+dUhxxKjV2+wyMdjODxwquFgZN8nvP0p17DvXbC71rKQ6yte+Vw S5s3zo3EU7iqCvi7JhN2byO62MAHfFq0VZeyA0EWR69440aOGMadJCXMS2Bo+iEtcmeq +0Y8gJX2igZi0t7RYOp2lP3NP80J3AfT/qEgGDfwEuzjtpCwIxex8+trEebFXmJc1r68 DyXGcCaGmXwZXvtvsE6X6gAm/7WZ9RTSwuXkm5WGhD2k+w2L4IBdHvfDok+II44CBwfh KuPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=B+Q2+3Fy; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-88463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a2-20020a50c302000000b00566cd374c76si593083edb.383.2024.03.01.05.26.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 05:26:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=B+Q2+3Fy; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-88463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6C15C1F23CFE for ; Fri, 1 Mar 2024 13:26:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9F0D6D517; Fri, 1 Mar 2024 13:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B+Q2+3Fy" Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 445AD69E15 for ; Fri, 1 Mar 2024 13:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709299554; cv=none; b=QhH5mI7B3a5ZJhH1ExB5VgbfydCS42gmC32a9/E8oQNM52mLXGvZFakWp/BYhjh65fXQ3fdOzoKlZMQhyN7gWeovups3tD1p3dib16oswmzGB1IfsMNCjW7fyIFPLoMYtNjI+8575ctmE0kWd/QxOYHzLibUJRtvYTuEg6A1kqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709299554; c=relaxed/simple; bh=JHWldWA6nNHKcTRlr05zV/nwVzVNIlbYVSMFB9iJlos=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=uq59DvWIVT7b/fG/vE5IpTZoiM1qbjDo76u69zXNipWG2TA1nNK+4KJ58qQQ0gBA4Aiozbj/+Y8mOiodTmCXG1tTpuk6fe1fB4Ep3Wof2wqTLuzR9BrGbJdN0YScrCCyn0kKtgrExe6SgdNsNuessdk+w2yfjjXUDo5Hb/ehmvM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B+Q2+3Fy; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5654ef0c61fso10595a12.0 for ; Fri, 01 Mar 2024 05:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709299552; x=1709904352; darn=vger.kernel.org; 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=+1teAiWc1jVGCssi6rgN3jeMMtmC7N9NmiOj97TQSRI=; b=B+Q2+3FyhzzHOF8F2GLt2wkZhMidxgsedxhsBtInm8nvf198JXT1DWUuF0u/356Wxn bHie3f4Uu/XHdrg+Vfa953FWhqx8oTkSxkHOqiW2KnCzAx7R4cD2NPj2TsXquakIjDcE 76UQQglv9A6OGSz2uwzZkR8KRPH8tPj4ZZe2hogP5p7bxSCh5+f3aUvhHjuq5MZHp8P7 7M2KrYJhNfbtyRCQP89PQJ/FD9VfpkinyagzG8V2v+DAKiZ7P84LOwrPvC5bXiBAILiy Ra0kWb1lgODBF7kJQfvGMA3m9OzYX4TpQbrPd4MRKf2eJIzvsx2D4eOV8BvrxHB8P7Su 094A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709299552; x=1709904352; 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=+1teAiWc1jVGCssi6rgN3jeMMtmC7N9NmiOj97TQSRI=; b=GfQi5gzmYuTpUiEEB4j2+nY/eKOi0/q9wrTuo5tSJSxMDDK84iXVjUYVf4GU0NQ2uZ 8pFFBFa4Stkpjx1fsVOWRJLYdtVNTinzRl7CpOVSkLumGRXBSPQE7YfeG+dWo6FnQSMq LTSHTgjlUhREK8NHfGrZsMAZZ5zkfD9fe7i3kEWxOgfKrnoaaRVx/bKlZQ3MchcCsgxW eAhyAfAgtmKeTIrCQO+BMR+JJKn1W6AxyTTrFYAcNZhcjS5AEWItkucMRc7pKMCKdO8P 2WpkH0le/0zenY8SCTup50uGTpHroJMKzW5u1OIcYM9BeSZlGNLNPKqxa3LLP819TsBa tDnA== X-Forwarded-Encrypted: i=1; AJvYcCUAzYVln4lFjjM0cNj7QwXGBHZb1tgyAXzz91f6Ils5xu37XYACaQiKIfyFnAJXBjYCBkpJrG9etHo2It6R5ld4q2iTrtc9sOcqK2Bf X-Gm-Message-State: AOJu0YyvDj/tQyMzXi5bkwm0acvSNhEsToH+a60bj1jbQZw2Qishs+/P BOyb2bdo3xyM5Y2tunFSDNJEST9GyEHhB480R3wKZS81btgzIZFSU8hCEitL7la8f5n5k2l+Yt5 jenr50KPvbcmdzLgNG8bhMSkupuLKsNM7gkGf X-Received: by 2002:a05:6402:350e:b0:563:f48a:aa03 with SMTP id b14-20020a056402350e00b00563f48aaa03mr141224edd.2.1709299551406; Fri, 01 Mar 2024 05:25:51 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240229213018.work.556-kees@kernel.org> <20240229225910.79e224cf@kernel.org> <9050bdec-b34a-4133-8ba5-021dfd4b1c75@intel.com> In-Reply-To: <9050bdec-b34a-4133-8ba5-021dfd4b1c75@intel.com> From: Eric Dumazet Date: Fri, 1 Mar 2024 14:25:37 +0100 Message-ID: Subject: Re: [PATCH] netdev: Use flexible array for trailing private bytes To: Alexander Lobakin Cc: Jakub Kicinski , Kees Cook , "David S. Miller" , Paolo Abeni , Andy Shevchenko , "Gustavo A. R. Silva" , netdev@vger.kernel.org, linux-hardening@vger.kernel.org, Simon Horman , Jiri Pirko , Daniel Borkmann , Coco Li , Amritha Nambiar , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 1, 2024 at 1:59=E2=80=AFPM Alexander Lobakin wrote: > > From: Eric Dumazet > Date: Fri, 1 Mar 2024 09:03:55 +0100 > > > On Fri, Mar 1, 2024 at 7:59=E2=80=AFAM Jakub Kicinski = wrote: > >> > >> On Thu, 29 Feb 2024 13:30:22 -0800 Kees Cook wrote: > > Re WARN_ONCE() in netdev_priv(): netdev_priv() is VERY hot, I'm not sure > we want to add checks there. Maybe under CONFIG_DEBUG_NET? > > > > >>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > >>> index 118c40258d07..b476809d0bae 100644 > >>> --- a/include/linux/netdevice.h > >>> +++ b/include/linux/netdevice.h > >>> @@ -1815,6 +1815,8 @@ enum netdev_stat_type { > >>> NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */ > >>> }; > >>> > >>> +#define NETDEV_ALIGN 32 > >> > >> Unless someone knows what this is for it should go. > >> Align priv to cacheline size. > > > > +2 > > > > Maybe > > > #define NETDEV_ALIGN L1_CACHE_BYTES > > #define NETDEV_ALIGN max(SMP_CACHE_BYTES, 32) Why would we care if some arches have a very small SMP_CACHE_BYTES ? Bet it ! IMO nothing in networking mandates this minimal 32 byte alignment. > > ? > > (or even max(1 << INTERNODE_CACHE_SHIFT, 32)) I do not think so. INTERNODE_CACHE_SHIFT is a bit extreme on allyesconfig on x86 :/ (with CONFIG_X86_VSMP=3Dy) > > > > > or a general replacement of NETDEV_ALIGN.... > > > > > > + I'd align both struct net_device AND its private space to > %NETDEV_ALIGN and remove this weird PTR_ALIGN. {k,v}malloc ensures > natural alignment of allocations for at least a couple years already > (IOW if struct net_device is aligned to 64, {k,v}malloc will *always* > return a 64-byte aligned address). I think that with SLAB or SLOB in the past with some DEBUG options there was no such guarantee. But this is probably no longer the case, and heavy DEBUG options these days (KASAN, KFENCE...) do not expect fast networking anyway.