Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2082641imm; Thu, 18 Oct 2018 08:47:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ZCX6C6KYltwVelNVZnzBJ8AshvZTTqPRE8ORlW3YYZ1C8NI5f4ss9man/BDS6JKmAHTc7 X-Received: by 2002:a62:5103:: with SMTP id f3-v6mr30917566pfb.107.1539877661652; Thu, 18 Oct 2018 08:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539877661; cv=none; d=google.com; s=arc-20160816; b=DDgzR11iuuVRMSBlRZ/CH913MyWTt+yYaK+whyUj28pAStLsm+agW8Ai++aKXtL/Fl hTlZ7YQglzKFUjUw5S6NTF4a84o+3AVfwlYWoYvZhtlOAZiUQTvupP5vV9ekdoKFUvIM bOJT/ejvI379ADIpgfDxzgMjpvvX+j4KDwlY9XQ4NbV8Dkq8hPi20FHHuuGavPPB35zm aKoOsIW/h4yOCDkS7/YBPOILuRkBv6SVmurpJ9+/U5oJ4hBuTQDHpjrn4s1tlgLFbHND D3zokHF320Xjka3+YhO2VXI1eIuAlhLLGL4pvhHf7wnRq7bUXEhCOVe+wdhPu2VHKSKh wM+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PjOqgVaJv/ojAIKUyDQMVhFrWFdFG0K0V1bDLkbd25Y=; b=cNzRuEE2V9Dx3LaZYpBbqpyKTvA+Rth1+kUBKCMUddcDm6a1MN7UFhd8tKD5LxUhgQ 0CAzkKZLnt91YaEu/qrIPxw0ldk09ocl9+D4YSVgiL+yP7EvMtAmmsgHer4vyk6F5Nml E1hUY4CQTa+Jp47LzaGjQqqxN+l35OwoABd7R5WY0eOfMcD/yIPeQ1AG+Lh9Qkv0SXLt C6vIP3ftAwVbpKBVKGTvKAprgjDScjr1vBEF9vShniilGiBVET6KCgEcm0BaIrir2/jR 9GOBsIrOi/GsJ9g3MD7r8rWr0EnzEm5Uk9rUD8Aw/VVWe3S+r5hskv8m2MPvYrwrajbl UlkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nWpRxeP7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id i9-v6si21105821pgq.382.2018.10.18.08.47.25; Thu, 18 Oct 2018 08:47:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nWpRxeP7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728328AbeJRXsk (ORCPT + 99 others); Thu, 18 Oct 2018 19:48:40 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43867 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728015AbeJRXsk (ORCPT ); Thu, 18 Oct 2018 19:48:40 -0400 Received: by mail-pl1-f195.google.com with SMTP id 30-v6so14488316plb.10; Thu, 18 Oct 2018 08:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=PjOqgVaJv/ojAIKUyDQMVhFrWFdFG0K0V1bDLkbd25Y=; b=nWpRxeP74V25o2HXVbG1MxA/ZNQDldfzLIwIPnbKGjtmvacbUHZkRwRRxbdhXWlny0 1EUDGeD9hi1gtOhaFPW9rKrY3SINX9ax+ANQxhHYrl3gzubbNcOwOPgH4YsttJo3DWPf NjqycDVbs/HjHnqDeLtjXeV3OuLtYsEQtmCIl1rDP/ui8Ur2G1gPyKEafr7phb/CEVpG UzooJD3EX2Ixq2xkla3V1rBCoUTFwTHZvBQNBOxUdQjRdBJ+wt7CzExRVD7wXNbPVjEh YUCNj+CqG2/U+Nocnaa52yLD8E5pif1OcnIxn6eBrqnURV+F4hsR7MxOk8YPwJbEWC/s meCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=PjOqgVaJv/ojAIKUyDQMVhFrWFdFG0K0V1bDLkbd25Y=; b=sJK8OnkpBV/brkkTPW0dFKpQu5AY/2Xtp38GYWV7z6R6LM/2vE9kAd/dxKc2ehCCwI 8irwhD45yr3x+3OVghDKS5jOIBvDL8QswOcw3gJEaxRCGd+APpsSPKceMc/1caH9XRiO 5wdfTmhaxaEVQYBOPhzVUgpL9V5y0To1aP5qjxlcn9cpzIwJbkslMvJyYbbhhHPHVCpa 0R6TISnaAPd6uFA7RU1wbL4NW/E1S90kEFs1GMUAwOYl1vzPQppoj3HgOh/DkqeMawk6 edcpRXsw+z8AKea8n2DMe8rPKB3YtSZg33d86I4w90S1tml1DgOMeBaQPeyru9pWNVPv QGoQ== X-Gm-Message-State: ABuFfojUwev8hV6omI/lvfuYsKiVPekKh7StcdXGfKlB2oSVXGYo2ePB qEmdD8lF3wORMe1gPDt61Tg= X-Received: by 2002:a17:902:8502:: with SMTP id bj2-v6mr30188803plb.295.1539877623807; Thu, 18 Oct 2018 08:47:03 -0700 (PDT) Received: from ast-mbp.dhcp.thefacebook.com ([2620:10d:c090:180::1:733a]) by smtp.gmail.com with ESMTPSA id y24-v6sm39551131pfi.24.2018.10.18.08.47.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 08:47:02 -0700 (PDT) Date: Thu, 18 Oct 2018 08:46:59 -0700 From: Alexei Starovoitov To: Joel Fernandes Cc: Daniel Colascione , Joel Fernandes , LKML , Tim Murray , netdev , Lorenzo Colitti , Chenbo Feng , Mathieu Desnoyers , Alexei Starovoitov , Daniel Borkmann , stable@vger.kernel.org Subject: Re: [PATCH v4] Wait for running BPF programs when updating map-in-map Message-ID: <20181018154657.ehgj3ozy62zy47hi@ast-mbp.dhcp.thefacebook.com> References: <20180816040145.gqzqicab4s6kcbye@ast-mbp.dhcp.thefacebook.com> <20181012105427.243779-1-dancol@google.com> <20181013023138.m445q6itdmyxdtoc@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 16, 2018 at 10:39:57AM -0700, Joel Fernandes wrote: > On Fri, Oct 12, 2018 at 7:31 PM, Alexei Starovoitov > wrote: > > On Fri, Oct 12, 2018 at 03:54:27AM -0700, Daniel Colascione wrote: > >> The map-in-map frequently serves as a mechanism for atomic > >> snapshotting of state that a BPF program might record. The current > >> implementation is dangerous to use in this way, however, since > >> userspace has no way of knowing when all programs that might have > >> retrieved the "old" value of the map may have completed. > >> > >> This change ensures that map update operations on map-in-map map types > >> always wait for all references to the old map to drop before returning > >> to userspace. > >> > >> Signed-off-by: Daniel Colascione > >> --- > >> kernel/bpf/syscall.c | 14 ++++++++++++++ > >> 1 file changed, 14 insertions(+) > >> > >> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > >> index 8339d81cba1d..d7c16ae1e85a 100644 > >> --- a/kernel/bpf/syscall.c > >> +++ b/kernel/bpf/syscall.c > >> @@ -741,6 +741,18 @@ static int map_lookup_elem(union bpf_attr *attr) > >> return err; > >> } > >> > >> +static void maybe_wait_bpf_programs(struct bpf_map *map) > >> +{ > >> + /* Wait for any running BPF programs to complete so that > >> + * userspace, when we return to it, knows that all programs > >> + * that could be running use the new map value. > >> + */ > >> + if (map->map_type == BPF_MAP_TYPE_HASH_OF_MAPS || > >> + map->map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS) { > >> + synchronize_rcu(); > >> + } > > > > extra {} were not necessary. I removed them while applying to bpf-next. > > Please run checkpatch.pl next time. > > Thanks > > Thanks Alexei for taking it. Me and Lorenzo were discussing that not > having this causes incorrect behavior for apps using map-in-map for > this. So I CC'd stable as well. It is too late in the release cycle. We can submit it to stable releases after the merge window.