From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46626C47E49 for ; Thu, 31 Oct 2019 19:18:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D60B20873 for ; Thu, 31 Oct 2019 19:18:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OkhWPsbn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729380AbfJaTSc (ORCPT ); Thu, 31 Oct 2019 15:18:32 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:23053 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729296AbfJaTSc (ORCPT ); Thu, 31 Oct 2019 15:18:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572549511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z1RO4I/4jdEzscBd4h7vo0/gknedRYXjuJXt2oE2lmM=; b=OkhWPsbnmmcrjLIZkRm7PNsYHAhfeHT+GM4SfYItNuZJCG88BDZnGmiU5RO/k8uNRsF/pg po8Zq0KoVjWFMYnPpA68XadsRZEiGk4FpWPA1d4Lr77X0Dq5+PS3jt6f5oLwzZTPezYS0Z 7tnfyfoDkGJNP0sDVAWuLeLtSHAL65Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-MjNOMBPYN3CLeiHudvBuiA-1; Thu, 31 Oct 2019 15:18:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 512602AD; Thu, 31 Oct 2019 19:18:25 +0000 (UTC) Received: from krava (ovpn-204-176.brq.redhat.com [10.40.204.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A491A7C5; Thu, 31 Oct 2019 19:18:17 +0000 (UTC) Date: Thu, 31 Oct 2019 20:18:15 +0100 From: Jiri Olsa To: Alexei Starovoitov Cc: Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Magnus Karlsson , Magnus Karlsson , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Alexei Starovoitov , Daniel Borkmann , Network Development , Jonathan Lemon , bpf , degeneloy@gmail.com, John Fastabend Subject: Re: [PATCH bpf-next v3] libbpf: fix compatibility for kernels without need_wakeup Message-ID: <20191031191815.GD2794@krava> References: <87lft1ngtn.fsf@toke.dk> <87imo5ng7w.fsf@toke.dk> <87d0ednf0t.fsf@toke.dk> <20191031174208.GC2794@krava> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: MjNOMBPYN3CLeiHudvBuiA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Thu, Oct 31, 2019 at 11:19:21AM -0700, Alexei Starovoitov wrote: > On Thu, Oct 31, 2019 at 10:42 AM Jiri Olsa wrote: > > > > On Thu, Oct 31, 2019 at 08:17:43AM -0700, Alexei Starovoitov wrote: > > > On Thu, Oct 31, 2019 at 7:52 AM Toke H=C3=B8iland-J=C3=B8rgensen wrote: > > > > > > > > Alexei Starovoitov writes: > > > > > > > > > On Thu, Oct 31, 2019 at 7:26 AM Toke H=C3=B8iland-J=C3=B8rgensen = wrote: > > > > >> > > > > >> Alexei Starovoitov writes: > > > > >> > > > > >> > On Thu, Oct 31, 2019 at 7:13 AM Toke H=C3=B8iland-J=C3=B8rgens= en wrote: > > > > >> >> > > > > >> >> Alexei Starovoitov writes: > > > > >> >> > > > > >> >> > On Thu, Oct 31, 2019 at 1:03 AM Bj=C3=B6rn T=C3=B6pel wrote: > > > > >> >> >> > > > > >> >> >> On Thu, 31 Oct 2019 at 08:17, Magnus Karlsson wrote: > > > > >> >> >> > > > > > >> >> >> > On Wed, Oct 30, 2019 at 2:36 PM Toke H=C3=B8iland-J=C3= =B8rgensen wrote: > > > > >> >> >> > > > > > > >> >> >> > > Magnus Karlsson writes: > > > > >> >> >> > > > > > > >> >> >> > > > When the need_wakeup flag was added to AF_XDP, the f= ormat of the > > > > >> >> >> > > > XDP_MMAP_OFFSETS getsockopt was extended. Code was a= dded to the > > > > >> >> >> > > > kernel to take care of compatibility issues arrising= from running > > > > >> >> >> > > > applications using any of the two formats. However, = libbpf was > > > > >> >> >> > > > not extended to take care of the case when the appli= cation/libbpf > > > > >> >> >> > > > uses the new format but the kernel only supports the= old > > > > >> >> >> > > > format. This patch adds support in libbpf for parsin= g the old > > > > >> >> >> > > > format, before the need_wakeup flag was added, and e= mulating a > > > > >> >> >> > > > set of static need_wakeup flags that will always wor= k for the > > > > >> >> >> > > > application. > > > > >> >> >> > > > > > > >> >> >> > > Hi Magnus > > > > >> >> >> > > > > > > >> >> >> > > While you're looking at backwards compatibility issues= with xsk: libbpf > > > > >> >> >> > > currently fails to compile on a system that has old ke= rnel headers > > > > >> >> >> > > installed (this is with kernel-headers 5.3): > > > > >> >> >> > > > > > > >> >> >> > > $ echo "#include " | gcc -x c - > > > > >> >> >> > > In file included from :1: > > > > >> >> >> > > /usr/include/bpf/xsk.h: In function =E2=80=98xsk_ring_= prod__needs_wakeup=E2=80=99: > > > > >> >> >> > > /usr/include/bpf/xsk.h:82:21: error: =E2=80=98XDP_RING= _NEED_WAKEUP=E2=80=99 undeclared (first use in this function) > > > > >> >> >> > > 82 | return *r->flags & XDP_RING_NEED_WAKEUP; > > > > >> >> >> > > | ^~~~~~~~~~~~~~~~~~~~ > > > > >> >> >> > > /usr/include/bpf/xsk.h:82:21: note: each undeclared id= entifier is reported only once for each function it appears in > > > > >> >> >> > > /usr/include/bpf/xsk.h: In function =E2=80=98xsk_umem_= _extract_addr=E2=80=99: > > > > >> >> >> > > /usr/include/bpf/xsk.h:173:16: error: =E2=80=98XSK_UNA= LIGNED_BUF_ADDR_MASK=E2=80=99 undeclared (first use in this function) > > > > >> >> >> > > 173 | return addr & XSK_UNALIGNED_BUF_ADDR_MASK; > > > > >> >> >> > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > >> >> >> > > /usr/include/bpf/xsk.h: In function =E2=80=98xsk_umem_= _extract_offset=E2=80=99: > > > > >> >> >> > > /usr/include/bpf/xsk.h:178:17: error: =E2=80=98XSK_UNA= LIGNED_BUF_OFFSET_SHIFT=E2=80=99 undeclared (first use in this function) > > > > >> >> >> > > 178 | return addr >> XSK_UNALIGNED_BUF_OFFSET_SHIFT= ; > > > > >> >> >> > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > >> >> >> > > > > > > >> >> >> > > > > > > >> >> >> > > > > > > >> >> >> > > How would you prefer to handle this? A patch like the = one below will fix > > > > >> >> >> > > the compile errors, but I'm not sure it makes sense se= mantically? > > > > >> >> >> > > > > > >> >> >> > Thanks Toke for finding this. Of course it should be pos= sible to > > > > >> >> >> > compile this on an older kernel, but without getting any= of the newer > > > > >> >> >> > functionality that is not present in that older kernel. > > > > >> >> >> > > > > >> >> >> Is the plan to support source compatibility for the header= s only, or > > > > >> >> >> the whole the libbpf itself? Is the usecase here, that you= 've built > > > > >> >> >> libbpf.so with system headers X, and then would like to us= e the > > > > >> >> >> library on a system with older system headers X~10? XDP so= ckets? BTF? > > > > >> >> > > > > > >> >> > libbpf has to be backward and forward compatible. > > > > >> >> > Once compiled it has to run on older and newer kernels. > > > > >> >> > Conditional compilation is not an option obviously. > > > > >> >> > > > > >> >> So what do we do, then? Redefine the constants in libbpf/xsh.= h if > > > > >> >> they're not in the kernel header file? > > > > >> > > > > > >> > why? How and whom it will help? > > > > >> > To libbpf.rpm creating person or to end user? > > > > >> > > > > >> Anyone who tries to compile a new libbpf against an older kernel= . You're > > > > >> saying yourself that "libbpf has to be backward and forward comp= atible". > > > > >> Surely that extends to compile time as well as runtime? > > > > > > > > > > how old that older kernel? > > > > > Does it have up-to-date bpf.h in /usr/include ? > > > > > Also consider that running kernel is often not the same > > > > > thing as installed in /usr/include > > > > > vmlinux and /usr/include are different packages. > > > > > > > > In this case, it's a constant introduced in the kernel in the curre= nt > > > > (5.4) cycle; so currently, you can't compile libbpf with > > > > kernel-headers-5.3. And we're discussing how to handle this in a > > > > backwards compatible way in libbpf... > > > > > > you simply don't. > > > It's not a problem to begin with. > > > > hum, that's possible case for distro users.. older kernel, newer libbpf >=20 > yes. older vmlinux and newer installed libbpf.so > or any version of libbpf.a that is statically linked into apps > is something that libbpf code has to support. > The server can be rebooted into older than libbpf kernel and > into newer than libbpf kernel. libbpf has to recognize all these > combinations and work appropriately. > That's what backward and forward compatibility is. > That's what makes libbpf so difficult to test, develop and code review. > What that particular server has in /usr/include is irrelevant. sure, anyway we can't compile following: =09tredaell@aldebaran ~ $ echo "#include " | gcc -x c -=20 =09In file included from :1: =09/usr/include/bpf/xsk.h: In function =E2=80=98xsk_ring_prod__needs_wakeup= =E2=80=99: =09/usr/include/bpf/xsk.h:82:21: error: =E2=80=98XDP_RING_NEED_WAKEUP=E2=80= =99 undeclared (first use in this function) =09 82 | return *r->flags & XDP_RING_NEED_WAKEUP; =09... =09XDP_RING_NEED_WAKEUP is defined in kernel v5.4-rc1 (77cd0d7b3f257fd0e309= 6b4fdcff1a7d38e99e10). =09XSK_UNALIGNED_BUF_ADDR_MASK and XSK_UNALIGNED_BUF_OFFSET_SHIFT are defin= ed in kernel v5.4-rc1 (c05cd3645814724bdeb32a2b4d953b12bdea5f8c). with: kernel-headers-5.3.6-300.fc31.x86_64 libbpf-0.0.5-1.fc31.x86_64 if you're saying this is not supported, I guess we could be postponing libbpf rpm releases until we have the related fedora kernel released or how about inluding uapi headers in libbpf-devel.. but that might actualy cause more confusion jirka