From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 F08EF3E3D9E for ; Fri, 5 Jun 2026 01:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780623818; cv=none; b=ORZ9MeyBZJb3K4Q02M5R7DtqI3eg431yyRR5lB4BVk9f5tFDVkQITbw942dvF6fa0L0FrcuK3/1p+vSll3CnPBvBLIskTxQ9qRKsUGzlnnloEEl1b0AH7psdi6vaN5nZmiD3sosJUHfskDDstCk/WZv7tl/Ved80KZ6qaUdZTZo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780623818; c=relaxed/simple; bh=EDdO8sCFNSFFX5asKV9mS604oajtv91yhZtFBop5IP8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tI7W//OYknmz8ih/mhEUe1eGflxSX9lHGIj4a1sH25DnghSWHCdUFVpRPVPOCFiOX17RGlpQPUNt+udxRWlZ5Quvyrbw9GaKFOetgX8hm+YsTCsPp/t8yalpBBV+gnEVhTrfIJSEeZXr7Vsk1kyF9K4RIAz2R3PJLBnMcLaB4uY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Inr+20uM; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Inr+20uM" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c85d9f0ace9so1269047a12.1 for ; Thu, 04 Jun 2026 18:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780623808; x=1781228608; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iVAJucd+GVsBBf1FGgcJQ8cRedfncMhwEKsquMbLLdE=; b=Inr+20uMaAQbLN9lbx+DFFI+p8Zk3FYKooLRjyg6OE4Am/6RDsHF/o0BSUGsmG+Z/O dsZFJ59bm1jpBuFcTTtTdSQCGZDr0luWTBaG8GHyE2Q0P+RAgpKpjS+6adNsGkAYGdMq h0mcJABbaDZGfoAJ6iDVBtbMPxatAcEQyPgA+K0uu7YG34qma7DXBpU9dFa5HghG4O7F w83RbywJrTvPJFsQdAGt9GT4ztpxe/0FmJ9kWsGWCOEhGYaTwUfSFrkBAKubIr29VfbN yfBcIW30r6PlFIkFyOauX8jPy+6MD3N6xmR3BWkKXi8MyopaG9JcO3aXyPso9eEm1ppI gT2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780623808; x=1781228608; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iVAJucd+GVsBBf1FGgcJQ8cRedfncMhwEKsquMbLLdE=; b=P/d33ZxuwgGCAj3IpJPTEVtl42jDgwc6MZLVfVqN4TnXvkjjwswKpWJSqN6GJKJi2M rVwO+7hrgbV8xUefR+vxxBe0OmgxxQ5jWFlwpcdvjx+XxaOBZh/vxZ/Gog3ljiwAM6Wt 4L6+1I5kjyYmD19eQjpAzJauF/TBlCYiT6Qx6D6BhHDlAaxHIzJEltt0xEcfOcN9FDIQ cW8V6Bc1F4tN813QzigQJWxShf8Is2l+Illy9hOjWSF4QeptoXKrC5QNGFqxcv0yeWOf cPY2i2bRel8TPLb4CxZggyZ2JysLbVKlEz1WFhMA9yjmpN0MZQk4d+RE+ycprF7VhH/I jy9Q== X-Forwarded-Encrypted: i=1; AFNElJ97h46U7tX0rMtBAQ3Swpo3lnSp9h/cSiXKwmpmD1LFRT5LpOWqEpF0ZKSopUhdkb/Kz8p0dy+ReG6D1mw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxq0pM4S/QSpMWBWp+zC99R1LXmbj3Dl0sisiYdnlufTm/Zy1Em vsfa1+zupk6DJm99jTpwlO/J+yecglkiMp2jo2ygZzsFo6YvXS4Z3yBOq87XiPuqwDHOmxi5abN MtEtZetjOqkJgD5397dKfSam1Sg== X-Received: from pghl22.prod.google.com ([2002:a63:f316:0:b0:c82:7df9:8c21]) (user=yuyanghuang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:a8b:b0:3b4:8ec9:514e with SMTP id adf61e73a8af0-3b4ccd77529mr1868150637.4.1780623807839; Thu, 04 Jun 2026 18:43:27 -0700 (PDT) Date: Fri, 5 Jun 2026 10:43:17 +0900 In-Reply-To: <20260605014318.3890804-1-yuyanghuang@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260605014318.3890804-1-yuyanghuang@google.com> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Message-ID: <20260605014318.3890804-2-yuyanghuang@google.com> Subject: [PATCH net-next v2 1/2] ipv4: igmp: annotate data-races around in_dev->mc_count From: Yuyang Huang To: Yuyang Huang Cc: "David S. Miller" , David Ahern , Eric Dumazet , Ido Schimmel , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" /proc/net/igmp walks the multicast list for IPv4 interfaces locklessly under RCU and prints state->in_dev->mc_count. Concurrently, device init/destruction and multicast join/leave paths update the count under the RTNL lock. Fix this intentional lockless snapshot by annotating the read with READ_ONCE() and the updates with WRITE_ONCE(). Signed-off-by: Yuyang Huang Reviewed-by: Ido Schimmel --- net/ipv4/igmp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index f2aca659b29c..fd0faf042fa6 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -1566,7 +1566,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr, #endif im->next_rcu = in_dev->mc_list; - in_dev->mc_count++; + WRITE_ONCE(in_dev->mc_count, in_dev->mc_count + 1); rcu_assign_pointer(in_dev->mc_list, im); ip_mc_hash_add(in_dev, im); @@ -1790,7 +1790,8 @@ void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp) if (new_users == 0) { ip_mc_hash_remove(in_dev, i); *ip = i->next_rcu; - in_dev->mc_count--; + WRITE_ONCE(in_dev->mc_count, + in_dev->mc_count - 1); __igmp_group_dropped(i, gfp); inet_ifmcaddr_notify(in_dev->dev, i, RTM_DELMULTICAST); @@ -1922,7 +1923,7 @@ void ip_mc_destroy_dev(struct in_device *in_dev) while ((i = rtnl_dereference(in_dev->mc_list)) != NULL) { in_dev->mc_list = i->next_rcu; - in_dev->mc_count--; + WRITE_ONCE(in_dev->mc_count, in_dev->mc_count - 1); ip_mc_clear_src(i); ip_ma_put(i); } @@ -2974,7 +2975,9 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v) if (rcu_access_pointer(state->in_dev->mc_list) == im) { seq_printf(seq, "%d\t%-10s: %5d %7s\n", - state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); + state->dev->ifindex, state->dev->name, + READ_ONCE(state->in_dev->mc_count), + querier); } delta = im->timer.expires - jiffies; -- 2.54.0.1032.g2f8565e1d1-goog