From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E85753B0AF5 for ; Tue, 5 May 2026 16:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777997498; cv=none; b=Vdrsz68ymKqWYPHAUsVhbKpYYNxO4/vQhFQzK1tc2/GZeuVeBlI/TTVurSm5oVmrHb2L9Eee+Ekhwttz2irm1ViWcqC9YlpzmJryLjvMiAxz/EsGUdUR39iKxVUBUCgvMsptQvVLFXEi5TsIeXpP/k3XLhrOxPxYWrJzLE9QdvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777997498; c=relaxed/simple; bh=Qflkkm/CQAQrIoUGNyccI6IVq5NOizMVdJ4CG/Wx3YI=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: Mime-Version:Content-Type; b=SNto3yZzV7WexDCqsdHHWFbpJcHgMaum6wAp0c0M+OpYuNR5jKKnZtU37ghGRspqisSbzkQ8H+qGcO9G9OlsH8xLsc5r7edU4mQD+F6in0T64K2Bz8JZSeHEZAG6i7DGKAXyvBeRo9Cdc0VoHfuMe9fZpsdqkMsKf2pvjj7yX4c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nFqmNkwz; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nFqmNkwz" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-79827d28fc4so48424507b3.1 for ; Tue, 05 May 2026 09:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777997496; x=1778602296; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ezuVIzME6POM2AEJaoHAJrjUF5+Hch9VDQkjGxLVMvA=; b=nFqmNkwzyJGHGJMN0u13YKGAnWCkpc6of3aZSqvHJFiiOVJYEdlf4vdqAozIMt6koD 6g1tfLJGofgyFszjAuiaDyRZxF44PYuL2ds9uh0LZiDXS+iUiRox8+1JKynGKhZSPQX/ 0mPCjm2oOUbZAHQBCDnROzTEgSBcwa68mdeMUoGHiAONM0yjiNtWl8hh5N6efdhFO5o7 SMRAR/Ev78hVSuhf9KuBpZhOEPRmsF4ac0kH8c84A+xHYfkqDOtxnUFXAo6qJjeIdLZS OXfXrNOYXk1WWZXer3xUuCBgRPaaoF07yFfZMn0s5e7tW4TEMMuDWSOcg5FFdIGdfQa8 wmNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777997496; x=1778602296; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ezuVIzME6POM2AEJaoHAJrjUF5+Hch9VDQkjGxLVMvA=; b=dnq5rC7SvIm1jZRsztyBJBNV1yFJw6WvQFz+PSM35B00qEMSBj5pqf4kQMu76b16Ov Q2Dt083+HHlLUg2IgI6C1GvIUTIYl7+9rYhy/Hrn+Sx/96gQO84gp/Ygm1coG4BQwoXh 4es1HtNOF/wivgzmjG3MUHW9Cs9dgqyzbqX8a3SZaUqicX4P3a8LzCWXOwR9Rqwk2SwQ riu6wd/qvaM5/K7luFhl8/FoHTPR7q4BqAVqUPWwHXf51Qs1qI3OVVZAdj0laMP1UUkT +jO2OB6OuUBLeCiX9/p21mnts/UBz4LrdSJ76iRQOUNp2u976Fzqzl2CMtqWoS1rNZlc ZH5w== X-Forwarded-Encrypted: i=1; AFNElJ9wlF/0Azzn0y+uGnGLKwCi7ZLnXw1pxg/TdjPdGIA44uNqXImjC8YR9O93t1GNp2As8OkqoE+KxyKsjp4=@vger.kernel.org X-Gm-Message-State: AOJu0YwdtD1KRHTbG5w946liKdDUiapLo36R2ohZJHrqxTi0KrVVNHNo UIeBU9fGq1IYQVn7zz+pKSzRR6N/p7jFRhgLGXZSjX8PGY2NqE10Ea1D X-Gm-Gg: AeBDieuMx91pHPbTXexTVJYRsYX9FJaHY21D0WvNpAqQXIxc011Al3jlIso30MQJDdW WdPVCZpoawIo9hZ+Jh3wvdQHI2nGJVTXhRMNGwXe6caaCG0e8d1o5zFKKE/iRW/STfMpBIP4XkL 9eEwzpoKTLwwyI6s0RFEMElh0xIP53cVn5edSGzemGFw+QGbHTTYmkt14xs+fOf8lHGQE7eB8oS kWrmabEvJA78TkLsikE0kxdv1tEjUaotLstvDRM2UcWvNclgmRQ8hZG16fBXhRNXRZTi8vMQXUZ bPbxXj0LQutdJqTgROSXdc4Pqy8pG5Xd5Y4pQEt2FFpMpUTG1esV0G7vFYcdC4dhO0ihlepClIY xtbzjuMmTb8U5Bmf1v1xsIL9Yy1CTrBCpnK66D+ZPH+B8pw+7ExpktHjBbPJGV94nSOsf8oT2QM QKV4RLJ6VM7Wd0yRkJqUehxzgydUbz0JiYPzbluJBB269eAXkqj/BhYFio7NSHXldVKO8FVHc1X F+ULT6LKbrZuzg= X-Received: by 2002:a05:690c:110:b0:7bd:7b2e:f079 with SMTP id 00721157ae682-7bd7b2ef1e7mr132263037b3.44.1777997495762; Tue, 05 May 2026 09:11:35 -0700 (PDT) Received: from gmail.com (172.235.85.34.bc.googleusercontent.com. [34.85.235.172]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7bd66888cc7sm65629577b3.44.2026.05.05.09.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 09:11:35 -0700 (PDT) Date: Tue, 05 May 2026 12:11:34 -0400 From: Willem de Bruijn To: Maoyi Xie , "David S . Miller" Cc: Jakub Kicinski , Paolo Abeni , Eric Dumazet , David Ahern , Alexey Kuznetsov , Willem de Bruijn , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Message-ID: In-Reply-To: <20260505072015.1672730-2-maoyi.xie@ntu.edu.sg> References: <20260505072015.1672730-1-maoyi.xie@ntu.edu.sg> <20260505072015.1672730-2-maoyi.xie@ntu.edu.sg> Subject: Re: [PATCH net v7 1/2] ipv6: flowlabel: take ip6_fl_lock across mem_check and fl_intern 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-Transfer-Encoding: 7bit Maoyi Xie wrote: > mem_check() in net/ipv6/ip6_flowlabel.c reads fl_size without > holding ip6_fl_lock. fl_intern() takes the lock immediately > afterwards. The two checks therefore race against concurrent > fl_intern, ip6_fl_gc and ip6_fl_purge writers, which makes the > mem_check budget check approximate. > > Move spin_lock_bh(&ip6_fl_lock) and the matching unlock from > fl_intern() into its only caller ipv6_flowlabel_get(). The > mem_check() call now runs under the same critical section as the > fl_intern() insert, so the budget check is exact. > > With all writers and the read of fl_size under ip6_fl_lock, > convert fl_size from atomic_t to plain int. The four sites that > update or read fl_size are fl_intern (insert path), ip6_fl_gc > (garbage collector, the !sched check and the per-entry decrement), > ip6_fl_purge (per-netns purge), and mem_check (budget check), and > all four now run under ip6_fl_lock. > > This is a prerequisite for adding a per-netns budget alongside > fl_size. The follow-up patch adds netns_ipv6::flowlabel_count and > folds it into mem_check(). > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Suggested-by: Willem de Bruijn > Signed-off-by: Maoyi Xie Please update either your git config name or Signed-off-by to make sure that the two are the same. Not sure whether that requires a respin. With those asides Reviewed-by: Willem de Bruijn Thanks for fixing this along with your main fix. > --- > net/ipv6/ip6_flowlabel.c | 33 ++++++++++++++++++++------------- > 1 file changed, 20 insertions(+), 13 deletions(-) > > diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c > index c92f98c6f..43b5e9ce9 100644 > --- a/net/ipv6/ip6_flowlabel.c > +++ b/net/ipv6/ip6_flowlabel.c > @@ -40,7 +40,7 @@ > #define FL_HASH_MASK 255 > #define FL_HASH(l) (ntohl(l)&FL_HASH_MASK) > > -static atomic_t fl_size = ATOMIC_INIT(0); > +static int fl_size; > static struct ip6_flowlabel __rcu *fl_ht[FL_HASH_MASK+1]; > > static void ip6_fl_gc(struct timer_list *unused); > @@ -163,7 +163,7 @@ static void ip6_fl_gc(struct timer_list *unused) > if (time_after_eq(now, ttd)) { > *flp = fl->next; > fl_free(fl); > - atomic_dec(&fl_size); > + fl_size--; > continue; > } > if (!sched || time_before(ttd, sched)) > @@ -172,7 +172,7 @@ static void ip6_fl_gc(struct timer_list *unused) > flp = &fl->next; > } > } > - if (!sched && atomic_read(&fl_size)) > + if (!sched && fl_size) > sched = now + FL_MAX_LINGER; > if (sched) { > mod_timer(&ip6_fl_gc_timer, sched); > @@ -196,7 +196,7 @@ static void __net_exit ip6_fl_purge(struct net *net) > atomic_read(&fl->users) == 0) { > *flp = fl->next; > fl_free(fl); > - atomic_dec(&fl_size); > + fl_size--; > continue; > } > flp = &fl->next; > @@ -205,6 +205,7 @@ static void __net_exit ip6_fl_purge(struct net *net) > spin_unlock_bh(&ip6_fl_lock); > } > > +/* Caller must hold ip6_fl_lock. */ nit: lockdep_assert_held as used below is preferable over comments > @@ -464,10 +459,14 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq, > > static int mem_check(struct sock *sk) > { > - int room = FL_MAX_SIZE - atomic_read(&fl_size); > + int room; > struct ipv6_fl_socklist *sfl; > int count = 0; > > + lockdep_assert_held(&ip6_fl_lock); > + > + room = FL_MAX_SIZE - fl_size; > + > if (room > FL_MAX_SIZE - FL_MAX_PER_SOCK) > return 0; >