Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp831886pxx; Tue, 27 Oct 2020 01:11:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxY7+xMo4Za3Mz0+SS0/pO3QuUvXdNmKi9nuEWN046klteEYc8Q1Rtr+EqcyexxzpoRzUK X-Received: by 2002:aa7:c955:: with SMTP id h21mr980764edt.315.1603786282177; Tue, 27 Oct 2020 01:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603786282; cv=none; d=google.com; s=arc-20160816; b=ijSThm+SCNeop7gRyUHzkifmov4MnMpKQ2le0r7zwTLHYKz6z8ou6nubdLTlDbQdMx n/OSTiazu0/HZtwxLwJahBBwbr1uBVsvNgU0yHF/miKM3rfMv2YXwqN+JPW9ae8fGgvt lXjDLhr7AYi9k3q8fLGOlzHvyMGop8iijZnROlca3DQuxFnNxuDyavprw3Ksq64IxD5X 471iRHLteE6O3iN1RhS20ptklzNc+Qf3rmJR7r9jzpDuJOuzQYEiV/jzEzXEkeO8Qjg+ QV0pw4YBfAWdKBfFD0Ooh17NB8wzMEVBtAeeSHiD/LkD8WqR3SPV1Ar/hFll8fpsvBHM JjwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tYGKgBOvXd0V/keZVVJoez9jaPUFednPhovrcJOgA2g=; b=iSUc4n5dXRH7gy4+jKGlfY1JNnbdJiuvgeIE73u1EiuBbPhSNGuHpDD2FT2WbWJv13 LARpkf7P4D2KU89Fq+C23M7Hb5iqSKAVANeTOS1DK+07VHkOIIFqteZwl0XGHRbsdGuC ryS/0LXwiCYh6lQCG1uK6eBw1qJugUddmJ0uzDSPxU83R725rIe2m1D2a+PqXFHwRRGX E4jWD/fbeN5nY/CjbrkuI9xglbYoUwkBtXT68ahj2JDcodtkQGYaCspm4jHCkQtAmIfk iYJgj82Rxy5B+J7P1DeKlJHjcpfPDbjsTpjzw/f5qOnmlBgeIrM58PgXmip48MU9r7Ot D1PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kAauVYU8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb22si466970ejb.414.2020.10.27.01.11.00; Tue, 27 Oct 2020 01:11:22 -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=@gmail.com header.s=20161025 header.b=kAauVYU8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394531AbgJZWdA (ORCPT + 99 others); Mon, 26 Oct 2020 18:33:00 -0400 Received: from mail-yb1-f194.google.com ([209.85.219.194]:35555 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394179AbgJZWdA (ORCPT ); Mon, 26 Oct 2020 18:33:00 -0400 Received: by mail-yb1-f194.google.com with SMTP id m188so4036091ybf.2; Mon, 26 Oct 2020 15:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tYGKgBOvXd0V/keZVVJoez9jaPUFednPhovrcJOgA2g=; b=kAauVYU8XtFtg2dOaqnJQwkbqB52ez/V5BY4VECXf1bDCA3xkrgRxmc8mhHkcL7Sh2 AnPLxWk9P9V1Lreux98xz77OgW9JboFSUIItFrvNvleQT0UzZqghu4150Ors4lsor85u gRoREfMaYdYZhjfAARgesMNdkJCswegVeHEWUIfeRxBQ5gQle3JJN5ORqwnMaSZuqUbe FALLq7z6Uf9W7P2t1zkJcuOiBjPeJbdCNQM82B7viQLfowGVyApJqeWkEBNtry0VWiCp LtwOeOXqtIen5DMkS5jbnd6DPA+/SQfqUxiLg9kUyrnEEscb7eIv0G0MOnvPkiMCdVT0 RzUQ== 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=tYGKgBOvXd0V/keZVVJoez9jaPUFednPhovrcJOgA2g=; b=O4YIv+7NEXQm19X/WYq0dMHS7qDu9RmEugG4/o2EAmxRWHNnlTQ9sLsiufFnBOfzwK BoHa00e13JFh5fYF9mzvdYmjJPDk9si3OGZWzC92utChH3WNTv7UzoMjPKCuOmgot+yQ bAZv1svxNNr8F8PxlLGuMuVOIkDwSHV1Hzn8PYBwKa9Vvb2SiwuvD4xx1dh+Uduks5wv qSlhJTtGGvscj8v/09hjMnYzoJXFiAsj8XXAm+VFt+RmnrxP7B5fHNfa3z2d+n31yy5Q xICSfmSVZ5hGuUKQ310a5ZhoTIZq83jEXTHOg3vzgyVTv/IEtYYNrG5QcBknQEy5Uqxa 7MPw== X-Gm-Message-State: AOAM532OJ+4sTGKHUXHMltBAOQkpO2Zn6B1IyXA0H9g5wbKrpRL+cgKU uIkM8iPxcebuLnNQdHGOPP1nZcMgZrhCiJY/WcA= X-Received: by 2002:a25:bdc7:: with SMTP id g7mr27858824ybk.260.1603751578973; Mon, 26 Oct 2020 15:32:58 -0700 (PDT) MIME-Version: 1.0 References: <20201026210355.3885283-1-arnd@kernel.org> In-Reply-To: <20201026210355.3885283-1-arnd@kernel.org> From: Andrii Nakryiko Date: Mon, 26 Oct 2020 15:32:48 -0700 Message-ID: Subject: Re: [PATCH] bpf: fix incorrect initialization of bpf_ctx_convert_map To: Arnd Bergmann Cc: Alexei Starovoitov , Daniel Borkmann , Jakub Sitnicki , Arnd Bergmann , Martin KaFai Lau , Marek Majkowski , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Jiri Olsa , Alan Maguire , Hao Luo , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 26, 2020 at 2:04 PM Arnd Bergmann wrote: > > From: Arnd Bergmann > > gcc -Wextra points out that a field may get overridden in some > configurations such as x86 allmodconfig, when the next index after the one > that has been assigned last already had a value, in this case for index > BPF_PROG_TYPE_SK_LOOKUP, which comes after BPF_PROG_TYPE_LSM in the list: > > kernel/bpf/btf.c:4225:2: warning: initialized field overwritten [-Woverride-init] > 4225 | 0, /* avoid empty array */ > | ^ > kernel/bpf/btf.c:4225:2: note: (near initialization for 'bpf_ctx_convert_map[30]') > > Move the zero-initializer first instead. This avoids the warning since > nothing else uses index 0, and the last element does not have to be zero. Wouldn't it be cleaner and more explicit to add __MAX_BPF_PROG_TYPE to enum bpf_prog_type in include/uapi/linux/bpf.h, similarly to how we do it with enum bpf_attach_type? Then just specify the size of the array here explicitly? Unless we are trying to save a few bytes for more minimal configurations where some BPF program types are not used (but still defined in an enum)? > > Fixes: e9ddbb7707ff ("bpf: Introduce SK_LOOKUP program type with a dedicated attach point") > Fixes: 4c80c7bc583a ("bpf: Fix build in minimal configurations, again") > Signed-off-by: Arnd Bergmann > --- > kernel/bpf/btf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index ed7d02e8bc93..2a4a4aeeaac1 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -4218,11 +4218,11 @@ enum { > __ctx_convert_unused, /* to avoid empty enum in extreme .config */ > }; > static u8 bpf_ctx_convert_map[] = { > + [0] = 0, /* avoid empty array */ > #define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \ > [_id] = __ctx_convert##_id, > #include > #undef BPF_PROG_TYPE > - 0, /* avoid empty array */ > }; > #undef BPF_MAP_TYPE > #undef BPF_LINK_TYPE > -- > 2.27.0 >