Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp357271lqh; Fri, 31 May 2024 03:38:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXeHfR+Ro1NcFOVEp4rKEUylt9hD2/y3ZSLGDA1HrbS0X/XySADQBq+8tM3nX2I/cChj+U+vZIGT1jCWIUTpZL8AVWINSs1wJK6lT2oEA== X-Google-Smtp-Source: AGHT+IExqph1SsHKPLLhyIjdBpaCSXjLidRFeszbV9o+RMc0wm9+bXiGWu6QU+6vi5BbC7bgKIZP X-Received: by 2002:a50:bac4:0:b0:57a:2abb:9e82 with SMTP id 4fb4d7f45d1cf-57a364e3e07mr780641a12.41.1717151922024; Fri, 31 May 2024 03:38:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717151922; cv=pass; d=google.com; s=arc-20160816; b=ACqC4/G9k1EZxXHv4P8y3hk2us707ehrNukFuEVrKP/KvMksfwms1ziFMH0Q6gDdaU hSYJBE+jWCSJEBquPNIiQM1Px2rHBBgPiQvVGEwKT/ZTdfYAm2Uqmpl4N4GLz4dCfYyC gWdXqH8u5BsWPBeIsobInLjdenFS8qOgpJUmfrQ9vJavgVLTyJ88xxbWLQ4DoFILPDoK 6fuPZGooEOgYGFQQoHnLTaj/9uOkP4yYgmD7FueVGixjm3xI6JYh50sTPMgDjBJ82E0M QsarpFkx3jnAQXmlM9dwA2sXh2TbbSlcfRnrEHG9G7cqBPyZXoQGghtTE0ljUgDjZr01 Lu3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=s4acigBe027wOQx0luMaaon6tV311jRRizAmbiQqL3w=; fh=R/vfQYnx3DbnrDo4bPcN87aESLGuSR+yCNioXQBk/iI=; b=Olf1m4IrHlewB/aOBItvopQB58wcdY3aSAaU7/SBnO5HKpjhNcTBXzh8R+09nApY1S 7lrwnksYFMj/zAYGJuCIGm3tGaYQd8GY/Pg8QYpZDEqXkZ67pVkE6PPaN9AjSk7fr0WV arhruVW8SDz+mmSbak0RJLGMiKvbC07DM+BjTS1GrqHELvhoJXOMeZKfuHPeaVgFss3x Rjbd2uywt8zOypxF3UDvo75yKGRn49of7ijEIuGKPvEPPJWAWFWURvbwVrz2KwmpbM2b gnR5hNydBbIfQocdFvzTsheMjHvGdluVq58IWgV/vspaaNAMYjo232UffMnbkAk23Oe7 QaYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F0heMktW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-196679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31c62f33si824440a12.294.2024.05.31.03.38.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 03:38:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F0heMktW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-196679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 694371F256B5 for ; Fri, 31 May 2024 10:38:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D546156223; Fri, 31 May 2024 10:38:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F0heMktW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YN+uNLES" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46900155C8E; Fri, 31 May 2024 10:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717151892; cv=none; b=TKYVd6bDWSG2ZyRwwS/8Uj0nYUjNwQSXO2xjOQDZeJDcuN2CZ/fxrl5qNKxesf5S5t2EExkPOlhWxJ6DAzCOwQHkUA7kJFtCGXFhNhQNUjQV6Io+SIYp+5IUdSVCjA+JTaUQItGY2sHLzrXhAuWjL/idntnuyt9mi9XwAZo7O58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717151892; c=relaxed/simple; bh=pHEsO2qn1rcaa/CVVCC1rJCGrocpF3xq2ymrPBC1hyM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tVa84WxKhoNcvFLGRU7mPDvTn3SYjw7Slnhf/Dyb+0WDQn2nuyX/CyEOOcdFGupdMLE4fV5FfWWjkhxhMRZAQGXCFB31ElW2VCIPcM9z/of7iyW2vZHOO5h7TNkhyZTs+7mbWNfMcVeSI9oStdRlHmsJcVw3tIdVSM2TnMdcvjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=F0heMktW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YN+uNLES; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 31 May 2024 12:38:07 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1717151889; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s4acigBe027wOQx0luMaaon6tV311jRRizAmbiQqL3w=; b=F0heMktWAuN3lpcjkR+BkoYknS08e++75PnvWStPB9mL2ifxNdHcKz5weNkFgwFB1j84Qw QMYeUMqjHfYnQDfLmxfG2IMol2YmnIYoV9aDk3SIvCyO9iJc/PrYDZExR53KWU5eBit800 A/8ur4BgPCXyYAcK0arCAFyxTYkLdMSj9Go2Y8rByOr4PvmyKltCd8K6hxKDc8uxbiMzhS O/0ecInyrCKM0d9uYSRkS3A/JOTNZ6Up+04k9Kl5vtbZutIm4rIE2mvgdJFOll5X/Ok3EF Wu1wiB8LMEdDeFz3DMTP32t5qruIRsjPHFSDeoImxEjZtLmkFDty3EdUcpWWnA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717151889; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s4acigBe027wOQx0luMaaon6tV311jRRizAmbiQqL3w=; b=YN+uNLESzX+WmX/Q2l0gLeQmgehpBRHwNK7BGf1Ci7es9A7xJHTFdbLQVw8obMJK45/1gV 40Y6OrLNtX5SqzCQ== From: Sebastian Andrzej Siewior To: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, "David S. Miller" , Boqun Feng , Daniel Borkmann , Eric Dumazet , Frederic Weisbecker , Ingo Molnar , Jakub Kicinski , Paolo Abeni , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , Alexei Starovoitov , Andrii Nakryiko , Eduard Zingerman , Hao Luo , Jesper Dangaard Brouer , Jiri Olsa , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Yonghong Song , bpf@vger.kernel.org Subject: Re: [PATCH v3 net-next 14/15] net: Reference bpf_redirect_info via task_struct on PREEMPT_RT. Message-ID: <20240531103807.QjzIOAOh@linutronix.de> References: <20240529162927.403425-1-bigeasy@linutronix.de> <20240529162927.403425-15-bigeasy@linutronix.de> <87y17sfey6.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <87y17sfey6.fsf@toke.dk> On 2024-05-30 00:09:21 [+0200], Toke H=C3=B8iland-J=C3=B8rgensen wrote: > [...] > > @@ -240,12 +240,14 @@ static int cpu_map_bpf_prog_run(struct bpf_cpu_ma= p_entry *rcpu, void **frames, > > int xdp_n, struct xdp_cpumap_stats *stats, > > struct list_head *list) > > { > > + struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx; > > int nframes; >=20 > I think we need to zero-initialise all the context objects we allocate > on the stack. >=20 > The reason being that an XDP program can return XDP_REDIRECT without > calling any of the redirect helpers first; which will lead to > xdp_do_redirect() being called without any of the fields in struct > bpf_redirect_info having being set. This can lead to a crash if the > values happen to be the wrong value; and if we're not initialising the > stack space used by this struct, we have no guarantees about what value > they will end up with. Okay, I can do that. > > void bpf_clear_redirect_map(struct bpf_map *map) > > { > > - struct bpf_redirect_info *ri; > > - int cpu; > > - > > - for_each_possible_cpu(cpu) { > > - ri =3D per_cpu_ptr(&bpf_redirect_info, cpu); > > - /* Avoid polluting remote cacheline due to writes if > > - * not needed. Once we pass this test, we need the > > - * cmpxchg() to make sure it hasn't been changed in > > - * the meantime by remote CPU. > > - */ > > - if (unlikely(READ_ONCE(ri->map) =3D=3D map)) > > - cmpxchg(&ri->map, map, NULL); > > - } > > + /* ri->map is assigned in __bpf_xdp_redirect_map() from within a eBPF > > + * program/ during NAPI callback. It is used during > > + * xdp_do_generic_redirect_map()/ __xdp_do_redirect_frame() from the > > + * redirect callback afterwards. ri->map is cleared after usage. > > + * The path has no explicit RCU read section but the local_bh_disable= () > > + * is also a RCU read section which makes the complete softirq callba= ck > > + * RCU protected. This in turn makes ri->map RCU protected and it is > > + * sufficient to wait a grace period to ensure that no "ri->map =3D= =3D map" > > + * exists. dev_map_free() removes the map from the list and then > > + * invokes synchronize_rcu() after calling this function. > > + */ > > } >=20 > With the zeroing of the stack variable mentioned above, I agree that > this is not needed anymore, but I think we should just get rid of the > function entirely and put a comment in devmap.c instead of the call to > the (now empty) function. I wasn't entirely sure if my reasoning is valid. In that case=E2=80=A6 > -Toke Sebastian