From patchwork Wed Jan 8 21:34:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 1219986 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="p5OnCGtw"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47tMwR2Q05z9sR1 for ; Thu, 9 Jan 2020 08:35:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727327AbgAHVfB (ORCPT ); Wed, 8 Jan 2020 16:35:01 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:37434 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgAHVfB (ORCPT ); Wed, 8 Jan 2020 16:35:01 -0500 Received: by mail-io1-f65.google.com with SMTP id k24so4866193ioc.4; Wed, 08 Jan 2020 13:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=/GvOoCT0xFD8/6aGwV3eh9rvuRXrlgmC3zJNi4p6MqU=; b=p5OnCGtwo2osB6lOQuBTrsN1GV5U7I6I6KeNJZNYTotwr0hNkGsPV5kuvJm5bAT05b ACULR9KBOf1Z9tkjUV4szZZ0KQFjn7E3U07RRUlj5pSL4ppAnbCPAnTudcUbIqLx7mQf 2CfOMlsYpHXp+NojJgkCDmEmZuzIQ2Ic0bQ3BN99e2XXxMc+KWE+oZsK8YrRqOubEjFu Tw1tLkbf80h2Qg5GMG2sP3WCT1z4S43UYdvc8OTboCTbZZjKiU5gU53d8p6ysHx6e7yy moz/UFXv+HuZVAEH+m8ilXizda0czh5fr6N9Huv09kP3ADrQyvtKpS9aCwFs+dCrf7nF BlLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=/GvOoCT0xFD8/6aGwV3eh9rvuRXrlgmC3zJNi4p6MqU=; b=qj/GxiuATuCFuAGaXnbT5BBMuJ4vKlEiT+Kqpd9uRquJeWz+QXKebbTlvy8Kffbaa0 sWT3erUyRxLRZzrrYhF3ucaxJtRBW/8rbh6Hk4s7/lmIZzWg6KHqRFo8/xeEiwTRfp7Z X4FgbOtKuiNJuSZj0SLR/VMGJP6kWfZQfwe/E/IamelMXxS1YtNGCQKKfCsAkpxjB3oS Pfg/yEL2IKwsGphmN0JWjMCRcW7LKMm81NIz2pdPkHhCB+wV9AkveocEZqgFG3x1tKI+ d2lkSaBdshY2HPmBsRJuqKI8usC3a8TOKOnCblDlkJa1a8y6gsd6mIPqCJp+O7IVxl7g tORw== X-Gm-Message-State: APjAAAVsBCnyUX+wX2OWRfC1cA7u14uAWt4nUQS0NnlcBhIH2JLzVnz5 EEKTa2JLuhoE3CjzykU7B9g= X-Google-Smtp-Source: APXvYqwZPEpoahMPAkA06VCszBoDXb8lkbW+oFb1qpd/Oit4UVw+OonStnY3OwfkIQ+h/bKI0umsOA== X-Received: by 2002:a6b:3a8a:: with SMTP id h132mr4827450ioa.207.1578519300546; Wed, 08 Jan 2020 13:35:00 -0800 (PST) Received: from [127.0.1.1] ([184.63.162.180]) by smtp.gmail.com with ESMTPSA id e7sm917601iot.71.2020.01.08.13.34.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jan 2020 13:35:00 -0800 (PST) Subject: [bpf PATCH 1/2] bpf: xdp, update devmap comments to reflect napi/rcu usage From: John Fastabend To: bjorn.topel@gmail.com, bpf@vger.kernel.org, toke@redhat.com Cc: netdev@vger.kernel.org, john.fastabend@gmail.com, ast@kernel.org, daniel@iogearbox.net Date: Wed, 08 Jan 2020 13:34:46 -0800 Message-ID: <157851928650.21459.1089027650128166319.stgit@john-Precision-5820-Tower> In-Reply-To: <157851907534.21459.1166135254069483675.stgit@john-Precision-5820-Tower> References: <157851907534.21459.1166135254069483675.stgit@john-Precision-5820-Tower> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that we rely on synchronize_rcu and call_rcu waiting to exit perempt-disable regions (NAPI) lets update the comments to reflect this. Fixes: 0536b85239b84 ("xdp: Simplify devmap cleanup") Signed-off-by: John Fastabend Acked-by: Song Liu --- kernel/bpf/devmap.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index da9c832..f0bf525 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -193,10 +193,12 @@ static void dev_map_free(struct bpf_map *map) /* At this point bpf_prog->aux->refcnt == 0 and this map->refcnt == 0, * so the programs (can be more than one that used this map) were - * disconnected from events. Wait for outstanding critical sections in - * these programs to complete. The rcu critical section only guarantees - * no further reads against netdev_map. It does __not__ ensure pending - * flush operations (if any) are complete. + * disconnected from events. The following synchronize_rcu() guarantees + * both rcu read critical sections complete and waits for + * preempt-disable regions (NAPI being the relavent context here) so we + * are certain there will be no further reads against the netdev_map and + * all flush operations are complete. Flush operations can only be done + * from NAPI context for this reason. */ spin_lock(&dev_map_lock); @@ -498,12 +500,11 @@ static int dev_map_delete_elem(struct bpf_map *map, void *key) return -EINVAL; /* Use call_rcu() here to ensure any rcu critical sections have - * completed, but this does not guarantee a flush has happened - * yet. Because driver side rcu_read_lock/unlock only protects the - * running XDP program. However, for pending flush operations the - * dev and ctx are stored in another per cpu map. And additionally, - * the driver tear down ensures all soft irqs are complete before - * removing the net device in the case of dev_put equals zero. + * completed as well as any flush operations because call_rcu + * will wait for preempt-disable region to complete, NAPI in this + * context. And additionally, the driver tear down ensures all + * soft irqs are complete before removing the net device in the + * case of dev_put equals zero. */ old_dev = xchg(&dtab->netdev_map[k], NULL); if (old_dev) From patchwork Wed Jan 8 21:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 1219988 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bes7gIYs"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47tMwm39CDz9sPK for ; Thu, 9 Jan 2020 08:35:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726497AbgAHVfU (ORCPT ); Wed, 8 Jan 2020 16:35:20 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:45465 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgAHVfT (ORCPT ); Wed, 8 Jan 2020 16:35:19 -0500 Received: by mail-il1-f195.google.com with SMTP id p8so3893806iln.12; Wed, 08 Jan 2020 13:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=pGjnNwKmSOomeeUgLDOsf11LLdbS6lxP9M2BwdBU5ao=; b=bes7gIYsXruKZ2rdAWH0qwjhRAyDrcGA6mL1lHQ8MfALaHY4neWpXMi6nrbsBzgyiH O6imQ/iaIUgXpBB1/bfoDWqahFmXwxa8LQWTwexVG4AmM3+PDpkRdoen3pWZQBzkYNXo AeXelXr6amubUMTvG8GtIj41rh2tYh/cuyWhxiCvK8WmG9rvfrL/dsbflibc1tgGEpzc wMMDJNXXuAnt4gDE+AHgABPS2ZVoKhQoB9I5Z4w9cJLBVhKCRTF/5zir2kslOi4SOPvy Q+1HOA0Nbmjdhue9yeEXbDyZnBUutfZyza3fx0ZG5bnFUsII+3YfqohpAX7wS+b6fZR7 gsGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=pGjnNwKmSOomeeUgLDOsf11LLdbS6lxP9M2BwdBU5ao=; b=hS9N1lxD7oiwg/QX+Yp01E8gXiCc0K0Jz6fiG9HThc7AAJ8EVQM5quzZDVPGdUIwxn +zNvy3qcQxEO2/8tn6AWhSrLmgGGmlNqgB4EWs22hq0qh8TEjcE6+3FjEUQpF+5Y+ivb 6Uzw+VtCksAZ++QCfJl/cyRr5BKHiRhwACfCiWsuyXtqT/PasSOBIoGp878NpZ94TExb WKONMqU422VKDDgbB3ZnWfa+Qlr4xhtSiVdiGpX2JnLzZ8Ma4KVRDPaupsB/H+p0mjIL NM6VuEjsPhQbExHIpYfk4obD+SM8+VBegT0JFK2w1DJKN8lkoKterQKSFhOIfiZC5bRC dcPQ== X-Gm-Message-State: APjAAAUfASq+l9qRLNl7MZ8c60vYI7Xw0EOvrgSyenzrdZki2+uRYIK5 +Ru2I7ULb65G7PlKmuwFJmw= X-Google-Smtp-Source: APXvYqy5RdtK3f/7PixAgAsO2qdBz451nUje8NDx9ycz7aWmMXM+cKbotfQUAJg/r7DWNOABOjq1xg== X-Received: by 2002:a92:cb11:: with SMTP id s17mr6059966ilo.114.1578519319116; Wed, 08 Jan 2020 13:35:19 -0800 (PST) Received: from [127.0.1.1] ([184.63.162.180]) by smtp.gmail.com with ESMTPSA id l83sm1330187ild.34.2020.01.08.13.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jan 2020 13:35:18 -0800 (PST) Subject: [bpf PATCH 2/2] bpf: xdp, remove no longer required rcu_read_{un}lock() From: John Fastabend To: bjorn.topel@gmail.com, bpf@vger.kernel.org, toke@redhat.com Cc: netdev@vger.kernel.org, john.fastabend@gmail.com, ast@kernel.org, daniel@iogearbox.net Date: Wed, 08 Jan 2020 13:35:06 -0800 Message-ID: <157851930654.21459.7236323146782270917.stgit@john-Precision-5820-Tower> In-Reply-To: <157851907534.21459.1166135254069483675.stgit@john-Precision-5820-Tower> References: <157851907534.21459.1166135254069483675.stgit@john-Precision-5820-Tower> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Now that we depend on rcu_call() and synchronize_rcu() to also wait for preempt_disabled region to complete the rcu read critical section in __dev_map_flush() is no longer relevant. These originally ensured the map reference was safe while a map was also being free'd. But flush by new rules can only be called from preempt-disabled NAPI context. The synchronize_rcu from the map free path and the rcu_call from the delete path will ensure the reference here is safe. So lets remove the rcu_read_lock and rcu_read_unlock pair to avoid any confusion around how this is being protected. If the rcu_read_lock was required it would mean errors in the above logic and the original patch would also be wrong. Fixes: 0536b85239b84 ("xdp: Simplify devmap cleanup") Signed-off-by: John Fastabend Acked-by: Song Liu --- kernel/bpf/devmap.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index f0bf525..0129d4a 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -378,10 +378,8 @@ void __dev_map_flush(void) struct list_head *flush_list = this_cpu_ptr(&dev_map_flush_list); struct xdp_bulk_queue *bq, *tmp; - rcu_read_lock(); list_for_each_entry_safe(bq, tmp, flush_list, flush_node) bq_xmit_all(bq, XDP_XMIT_FLUSH); - rcu_read_unlock(); } /* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or