Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5469084imm; Tue, 16 Oct 2018 10:41:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV60mF0r32CNMpFJZ4UF/8X2R6wSOSh50cwZwMRcwGZNXSZdYhHdBDYMzPfxALBCqxTaaN/cu X-Received: by 2002:a63:df03:: with SMTP id u3-v6mr2420263pgg.362.1539711715695; Tue, 16 Oct 2018 10:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539711715; cv=none; d=google.com; s=arc-20160816; b=BKtqpgxyfu+IoQd7Z+1cP45JC2CmYo3kPduZZ/jvfyiwyb+kQ/dLNj/SH0dEMrA2ol G3NSxGQY27vv4G762yTKJCBJBd/Sf0XEE2NKZ+Y5o7azf8d5BaZjhBVhg+SLg/aO++NY SUT3vB0ws3l2jZ6D6wemYXCqCc/wv0wokh/x3gsz06S7lhDCK3GIj9PkZ7SuRaFg7j98 BG3XYUstN0egYFhcNjRQ/E07aKLfXuoigiPc3+M+PXEnDtQnG6c68TOyTdV/PtIZa7CW 2oUDt8PWbzjHtA+8i29wnm1TPTlLpdwizyYpEHxjqvaTUI4U3dOJhyIg568njbyxdx8L j+xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=CW3fizjK+uSps4gcbmeTOTp5t8eAV7kn765UhydQxMQ=; b=sPmLIAkqBSFPjoaT5uW9gsrLLOa31MsY2Y0wGtSvZWeT5EKEVNEnKnWstgplLgOe/X 1nO0e0CYYURX8U/RaN1UNcZ7baA4JY3vrbRQ1uSvUup24Q5vWi3I9FshVdfZ23Y0GmUo yX3kAW2VVIbIxAvJoDpFP00NxUWYSDRpQvjFUUudPdXtgTRmN42zj2v/cMyigB+KB/hB 18FkqrgBuEPit1OQWPRLG7Vl4fhMmT8atM13nuIGUNrTciMpWPPnJNh3QoSD4yLAIkOg VFy6vUNn7Gz3o28fWnBg3CoMorSzIyXoaFNsFHUImkQhBcTmoCZIB60/w9bQ3J7NXYkH qxJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=pDyM+N3g; 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 y11-v6si14646611pgi.121.2018.10.16.10.41.40; Tue, 16 Oct 2018 10:41:55 -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=pDyM+N3g; 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 S1727488AbeJQBbc (ORCPT + 99 others); Tue, 16 Oct 2018 21:31:32 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45314 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727266AbeJQBbb (ORCPT ); Tue, 16 Oct 2018 21:31:31 -0400 Received: by mail-lj1-f193.google.com with SMTP id j4-v6so21708716ljc.12 for ; Tue, 16 Oct 2018 10:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CW3fizjK+uSps4gcbmeTOTp5t8eAV7kn765UhydQxMQ=; b=pDyM+N3gudvSeTUY6ILaaP2YWhklhl65BCNWJJRxyoTOK4n/YP/eWvK1SofFZDn84U ikQVO6oi+rmraSGWrAXOnf25yyY7cBgFC0A5OV2dx3pEQz3oKQC4fbNmSE50rG5VXCT0 WHYfpxJyyBpL+UL2gCOcgLCLf7Nh6r0lGKQFY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CW3fizjK+uSps4gcbmeTOTp5t8eAV7kn765UhydQxMQ=; b=oGqbbxNwsSKLJmXNB3+dfL87LDTVYKmLnBn/CfUFmSEK2kjIQQB4hkEz/PHvEyXBYG RWjcw5BRCkGV4G+oFfKy9kLHciXtWvc0AZx3XfY7DNl4Na2oj1aFWnw26mkv/4/e4FWF A/aPoKtretJZccr0rcOT9TdTWt/+OYJoCuk0C0z4imT1DyXY8bM7ynud/LoNND9Br1A8 V3Q52S75kTT7BW8VIBXed1GDvd56X2tX4MfrQ2aBNZc/ah76NPMhiLNoriqs2gEZEv/W YuWMV/7XCrib9TipkhnOhaqFNbw0KYIOz60uMeD2V1pbxEEUQKA2kL3L/xXyI5p4qYTZ rYvw== X-Gm-Message-State: ABuFfoh8AR4a2EzkWKb5rK9VgRGUnYBUN6d10WVbXwd5STNSMlFuvvsR Qj8fljTNaMGw9QmayX0eb3hQOvabv/Vj/KHGoxUK7Q== X-Received: by 2002:a2e:3211:: with SMTP id y17-v6mr15748787ljy.39.1539711598748; Tue, 16 Oct 2018 10:39:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:8e91:0:0:0:0:0 with HTTP; Tue, 16 Oct 2018 10:39:57 -0700 (PDT) In-Reply-To: <20181013023138.m445q6itdmyxdtoc@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> From: Joel Fernandes Date: Tue, 16 Oct 2018 10:39:57 -0700 Message-ID: Subject: Re: [PATCH v4] Wait for running BPF programs when updating map-in-map 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -Joel