Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2526675imm; Thu, 18 Oct 2018 16:38:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV61uk7Bh3fGjIF6tcpX5WWugU3LeT8q9vi2LBAA3UYC3o0oRVMtIHbYCpw0lsEn25p8VIj+3 X-Received: by 2002:a17:902:b492:: with SMTP id y18-v6mr32103859plr.254.1539905884368; Thu, 18 Oct 2018 16:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539905884; cv=none; d=google.com; s=arc-20160816; b=PlNLYhiEvG9p5wZWp2dCBv1Uhy0qJ9qnYXPp1Gt6KXJJicYE9zloBVl/kclXihOSCq mX2CQoD6YbABgjzpCh+nFc6EKVnCjcS89SKFI0KrUi9ZyEKDj8LUZbi5Gozo5t1TdbQ+ UMnOQf8lKHr2YqmH49FVbUQ4++pnzmrflvuBf1Op2Y+YK+rfKPa1wvo+rvJN+UIaFQ45 wmiDyiAQSFs+jA9Vkwm3wgrsCeciRq3/jB+OH6/0yQ7r1E+ImXzVm7zWvCZnWkkKqLDy OblWftOHQ7+GHXcN8tyPIXWj7lGuIek8Aa/t38OyxWAZQO4+2kTDIVVHQ3ICTIA6GTQw +tyQ== 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=6351bzF+lI5O7U+wVHUEhoKIEgDmwbDIUIJo2+Hv3CA=; b=uQ3XeT/LewtPwLbT5xGyCi3hNejQPjRt843RtMTpdw0U3HhgtGQ6sDfOl8b16gDe/R 8hylD8TE7kDS1nJYwBjfxyZdZWVphJYWKxSvn098elGKSjsQ/dHafH6SBGkaWwJf3fJf 18QEP7+lsmBha/j0fiAlU6/tSf1i/g/NDTc/9ctA/sIRPrEiAR8l67jG+99VBuCGdgfB EAYyhKK+2GDzbMLURBzfpIPYiR13o46u04IK9NIUXF2Pg5sYPLMCZT/Tc+lMB+G/jdcj AZEqr+sodXitm66qbDwuClCt1MQx/MLoELjVw9dCNcTBxoWFqLldEtXX0bZVpcDWoH5f TYDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=gp2V2+sh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 74-v6si23719808pga.231.2018.10.18.16.37.48; Thu, 18 Oct 2018 16:38:04 -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=@joelfernandes.org header.s=google header.b=gp2V2+sh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbeJSHjz (ORCPT + 99 others); Fri, 19 Oct 2018 03:39:55 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40150 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726507AbeJSHjz (ORCPT ); Fri, 19 Oct 2018 03:39:55 -0400 Received: by mail-pf1-f196.google.com with SMTP id g21-v6so8598869pfi.7 for ; Thu, 18 Oct 2018 16:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6351bzF+lI5O7U+wVHUEhoKIEgDmwbDIUIJo2+Hv3CA=; b=gp2V2+sh3pf79Q5b82iwczYpxVQKD+ivSXxKfcreGwG5o3XUy/gDPr/KLsnIDmxApp Dd55qQWT2vW7SHiA2qaJEEVW9EryuCkrjUIgmkFJbgIRcpR7fU5UiXPJBh7RaQS72lV2 As4Jqh8mzwj4z0QiAJ8nEtQ0EXrRU0SA2jPfE= 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=6351bzF+lI5O7U+wVHUEhoKIEgDmwbDIUIJo2+Hv3CA=; b=VLn/+7p0sG3i58lY+uysFgz5FcnYv0Ij7wF8/7BbnlEV3SRdpcMRSJzagLbwFZMXFt nxgf8ia5JJMK/czuvdZKTsVXAYxUJdg1j1u1JusatCZRt9pbDBVjk9adfM9R1hkpYPK3 BI9P891q42m55GdAmrEPo7CeGOm+hG6xYGoRDQQni+UGvrPb49pluV+rM+/Y75jr3cLR G80H+pzS6zMBuyOEdZpd1p9+9IYlqSGaaZW04IUi+ENKVZ2Ez6fEM2hVmZx1/Tedg+Nw JPtDrutVo479KT+DzSBZA5BQm62pblADdiL0F42otXq5aOkT+EzAtVLUDfbqG0lAU6G2 MsFA== X-Gm-Message-State: ABuFfojTm/sRX5z6hbVdSwRE7uE8GS3xd4MfU4jhI5Ma/+PAalSPGWUc HxCC8juLCCcKQY6VmJ84Igw/cA== X-Received: by 2002:a63:3c46:: with SMTP id i6-v6mr30050434pgn.286.1539905795753; Thu, 18 Oct 2018 16:36:35 -0700 (PDT) Received: from localhost ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id e3-v6sm28220163pgc.71.2018.10.18.16.36.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Oct 2018 16:36:34 -0700 (PDT) Date: Thu, 18 Oct 2018 16:36:33 -0700 From: Joel Fernandes To: Alexei Starovoitov 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: <20181018233633.GA89903@joelaf.mtv.corp.google.com> References: <20180816040145.gqzqicab4s6kcbye@ast-mbp.dhcp.thefacebook.com> <20181012105427.243779-1-dancol@google.com> <20181013023138.m445q6itdmyxdtoc@ast-mbp.dhcp.thefacebook.com> <20181018154657.ehgj3ozy62zy47hi@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181018154657.ehgj3ozy62zy47hi@ast-mbp.dhcp.thefacebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 18, 2018 at 08:46:59AM -0700, Alexei Starovoitov wrote: > 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. > Sounds good, thanks. - Joel