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=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 B2F21C433ED for ; Thu, 15 Apr 2021 09:29:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C48961222 for ; Thu, 15 Apr 2021 09:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231251AbhDOJ3v (ORCPT ); Thu, 15 Apr 2021 05:29:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39319 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbhDOJ3t (ORCPT ); Thu, 15 Apr 2021 05:29:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618478964; 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: in-reply-to:in-reply-to:references:references; bh=2kU6pnkx8ahC9lrMW5Fx29wiRnsU7XdlivJV5ohDfks=; b=RNjaTJQVA3THVxAD3LARhO7Q+m3IE/Y6KbjW7Z8D9bMazX2FzTxIfRtBDdLIU08B3sYDhg 1AcTa8V4J6xIRZjyCnYRs71m4TYpa5EuoB9IG7HSDkliXm1/BK9wyOrxcjUcHEjXi3hXLx 8VIUbl+b886/yyI8FYdTjhmy3DHoNio= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-424-VPaCU54NM2SvgCCnJZ4_ig-1; Thu, 15 Apr 2021 05:29:23 -0400 X-MC-Unique: VPaCU54NM2SvgCCnJZ4_ig-1 Received: by mail-ed1-f70.google.com with SMTP id c5-20020aa7d6050000b02903825f4da4f3so4835108edr.16 for ; Thu, 15 Apr 2021 02:29:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=2kU6pnkx8ahC9lrMW5Fx29wiRnsU7XdlivJV5ohDfks=; b=ra4fG30B3p98XU+fSGBIb4xBwPv26vcqtputt2gXkgDzrAu6BlGCjEy5SKNT77HZS7 5sT7DHB6Od+FbijkAXvD3tQ8UEw+svSsOqrJ3i93d5Z76z4afvZViaCwSixs5S+4Ksnr Cozj571YZRk/8EAb5Cm2CBKePiXAu1JDlQirNsnLbZRi1vfBjNsvAqF49HZY6Ct5W+S5 rymIOkMl20QIFccU8jQYID26nxm+3MmOHkEsgBVPBmb6DRsGaTS6VeEDtkzdASio3X5S LSFTRPXAJ9QTb2RzacZ1YHwW0pSDRdeE3qldYYoihKdWAMy3gpw7Vdq4Fzi/svCZy42e kwBA== X-Gm-Message-State: AOAM532WcHiQ2JMy+mOlwDt3cZZYhF03fDx8rRu2QfbK1s5zlkH5WHad iktf14VvNVHdT+F/H7FRdrY+/34plt1SE75+mczNjbvjAvvSrMypMIuUVwX128k1DzvJPourYLL PTQprC2vOjr1q X-Received: by 2002:a05:6402:5153:: with SMTP id n19mr3043718edd.173.1618478961828; Thu, 15 Apr 2021 02:29:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN1YONbgCaDAZ7dB148jhXZY0vOhSLRfPeDL37+0RZfGd1KDG48fS8Qo4Vek+pOtpWNjw9uQ== X-Received: by 2002:a05:6402:5153:: with SMTP id n19mr3043699edd.173.1618478961521; Thu, 15 Apr 2021 02:29:21 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id k8sm1937480edr.75.2021.04.15.02.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 02:29:21 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 47FBC1806B3; Thu, 15 Apr 2021 11:29:20 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Hangbin Liu , Martin KaFai Lau Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jiri Benc , Jesper Dangaard Brouer , Eelco Chaudron , ast@kernel.org, Daniel Borkmann , Lorenzo Bianconi , David Ahern , Andrii Nakryiko , Alexei Starovoitov , John Fastabend , Maciej Fijalkowski , =?utf-8?B?QmrDtnJuIFQ=?= =?utf-8?B?w7ZwZWw=?= Subject: Re: [PATCHv7 bpf-next 2/4] xdp: extend xdp_redirect_map with broadcast support In-Reply-To: <20210415022127.GQ2900@Leo-laptop-t470s> References: <20210414122610.4037085-1-liuhangbin@gmail.com> <20210414122610.4037085-3-liuhangbin@gmail.com> <20210415002350.247ni4rqjwzguu4j@kafai-mbp.dhcp.thefacebook.com> <20210415022127.GQ2900@Leo-laptop-t470s> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 15 Apr 2021 11:29:20 +0200 Message-ID: <87lf9jkia7.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Hangbin Liu writes: > On Wed, Apr 14, 2021 at 05:23:50PM -0700, Martin KaFai Lau wrote: >> On Wed, Apr 14, 2021 at 08:26:08PM +0800, Hangbin Liu wrote: >> [ ... ] >> >> > +static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifindex, >> > + u64 flags, u64 flag_mask, >> > void *lookup_elem(struct bpf_map *map, u32 key)) >> > { >> > struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info); >> > >> > /* Lower bits of the flags are used as return code on lookup failure */ >> > - if (unlikely(flags > XDP_TX)) >> > + if (unlikely(flags & ~(BPF_F_ACTION_MASK | flag_mask))) >> > return XDP_ABORTED; >> > >> > ri->tgt_value = lookup_elem(map, ifindex); >> > - if (unlikely(!ri->tgt_value)) { >> > + if (unlikely(!ri->tgt_value) && !(flags & BPF_F_BROADCAST)) { >> > /* If the lookup fails we want to clear out the state in the >> > * redirect_info struct completely, so that if an eBPF program >> > * performs multiple lookups, the last one always takes >> > @@ -1482,13 +1484,21 @@ static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u32 ifind >> > */ >> > ri->map_id = INT_MAX; /* Valid map id idr range: [1,INT_MAX[ */ >> > ri->map_type = BPF_MAP_TYPE_UNSPEC; >> > - return flags; >> > + return flags & BPF_F_ACTION_MASK; >> > } >> > >> > ri->tgt_index = ifindex; >> > ri->map_id = map->id; >> > ri->map_type = map->map_type; >> > >> > + if (flags & BPF_F_BROADCAST) { >> > + WRITE_ONCE(ri->map, map); >> Why only WRITE_ONCE on ri->map? Is it needed? > > I think this is make sure the map pointer assigned to ri->map safely. > which starts from commit f6069b9aa993 ("bpf: fix redirect to map under tail > calls") The reason WRITE_ONCE() is only on the map field is because that's the one that could be changed by a remote CPU (in bpf_clear_redirect_map()) - everything else is only accessed on the local CPU. As for whether it's strictly needed from a memory model PoV, I'm not actually sure (and should we be using smp_{store_release,load_acquire}() instead?); I view it mostly as an annotation to make it clear that the map field is 'special' in this respect... -Toke