From patchwork Fri May 3 19:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653344 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 A618D2943F for ; Fri, 3 May 2024 19:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764065; cv=none; b=iW9XubvwNZ0MXIUx5XQYE+DcAnzF+vdbauM5kjZNPUbL65WQaEi7+ayMN3hhKt5UQjiv+5UtRr5/P9Fequ2D3CWpNh4B1+DDvlEW6YH4R3x4XhUVew2siYYqCua5iZ76HdstyAb3OFYu+v7AhZYmF7KQvdAT03L1wSAGmsBh3zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764065; c=relaxed/simple; bh=5+4RayyWeZBCxk2V3aJaBj9NTDUm0ShmZ5tB8hHBRVU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=c5/l5LvV8ok311VIDxJy+irT4CXbqjfMayD+oUDQ3sn26fvEjrQ9HgOLy/5nvX0Vy100wBx2sbxNibImWUYn3KtvtRQVyopoayHJ31rAi6FmpI6YiBpH2UyEYwkCzwtBUZkyO4K2M8SGlwA8Xbrwcqa0Yg5WCa8bo7J+QPBEUzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zEqs0hG7; arc=none smtp.client-ip=209.85.128.202 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zEqs0hG7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61bb09d8fecso140412507b3.0 for ; Fri, 03 May 2024 12:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764062; x=1715368862; 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=NliRQ/CYwpmitjtxwGzcwSoNhoffMvcr6dqlNHuVYeo=; b=zEqs0hG79AjF7N7E69uQR/m4vtEebJGMcV7DIRMXrtsBOMWJfEubctVBF7JQqaMU4F KjqyD+OaOUWHq1Lf/c9FC+fEzhymUddF5zsuSBM+8u03rj8JloyXfLPT2Flx8pKHHnal 5JK5ztn6pOXUTQABonVRyYt9vjh+u6MMVbdzsQx0235Uwtwxk3aa8YQm2YrOSYJw2CAd i+RTmJmbxLzc0NihUanNXvCpkpJXnBmpa2RIc3Ko304A9lFkJkwfkDxitjy2EA9MUi9Y RKsPtjiDBESOHCtlwDhDIrP8UbwEF5dZSPSFmEZqpgf7BlgmGZ4O2yqYBnz8JjNGC2sp a48Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764062; x=1715368862; 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=NliRQ/CYwpmitjtxwGzcwSoNhoffMvcr6dqlNHuVYeo=; b=W3gvQKhQAXz67auusueLk/W5tywK7dXTHRVxf8YE7CMS8ljwQvznJt0bT7rFLxNWMn 2Zc/0Be3DHr+twXfAjqI6OGCQqJj4a0bmMMDdykZ9Koe6FiYUg/EQN7l2RCKkZyY4iK3 dCUEzIWoAc9oNS4R28yi+1lWG/yH/VyGisw2U8ynXnQz9zGIo/HSph6a9O+dXNR2m6jZ 8sabt1AYoe27c/IOHjni5Bjtu5raOFbg34QX3CCx7VmQIX1ta9FdIR/3H39a6IdqEnFo Ih4KxZKco5eWTK5NNdJww/mGQGwExl2/Io8FDZNKvSuTIl/vSZIUcbq4d0ckDdiB9sHp F57A== X-Gm-Message-State: AOJu0YzhyYlttwTBdEPQBjoIhzsQklkltryH7195K6Nx+f1LoJKsMVx1 YhlomhWav9GjwL8r+NSJ9BZTwrjDdfmgj3OxotpEaHwxIF3uSECPxt2LDGNz9HuYzIFbSNdeyz2 7avw34Yx9Yg== X-Google-Smtp-Source: AGHT+IEuWkrTJzX79TaU9k/sdZ3In+L191ZcA+dEpvVrN4JhO75OCArhOj/zdjUfmLSpcBry5NUkAJNceBIACA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:100d:b0:de5:319b:a211 with SMTP id w13-20020a056902100d00b00de5319ba211mr456961ybt.3.1714764062727; Fri, 03 May 2024 12:21:02 -0700 (PDT) Date: Fri, 3 May 2024 19:20:52 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-2-edumazet@google.com> Subject: [PATCH net-next 1/8] rtnetlink: do not depend on RTNL for IFLA_QDISC output From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org dev->qdisc can be read using RCU protection. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/rtnetlink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 283e42f48af68504af193ed5763d4e0fcd667d99..f4a87f89d5cde0cdd35c156d78ebe31511d4a31c 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1832,7 +1832,6 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, if (tgt_netnsid >= 0 && nla_put_s32(skb, IFLA_TARGET_NETNSID, tgt_netnsid)) goto nla_put_failure; - qdisc = rtnl_dereference(dev->qdisc); if (nla_put_string(skb, IFLA_IFNAME, dev->name) || nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) || nla_put_u8(skb, IFLA_OPERSTATE, @@ -1857,8 +1856,6 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, #endif put_master_ifindex(skb, dev) || nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) || - (qdisc && - nla_put_string(skb, IFLA_QDISC, qdisc->ops->id)) || nla_put_ifalias(skb, dev) || nla_put_u32(skb, IFLA_CARRIER_CHANGES, atomic_read(&dev->carrier_up_count) + @@ -1924,6 +1921,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, goto nla_put_failure; rcu_read_lock(); + qdisc = rcu_dereference(dev->qdisc); + if (qdisc && nla_put_string(skb, IFLA_QDISC, qdisc->ops->id)) + goto nla_put_failure_rcu; if (rtnl_fill_link_af(skb, dev, ext_filter_mask)) goto nla_put_failure_rcu; if (rtnl_fill_link_ifmap(skb, dev)) From patchwork Fri May 3 19:20:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653345 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 3CC61158869 for ; Fri, 3 May 2024 19:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764066; cv=none; b=bBpCE/Evrmv1KinNDImCIYA55W3dKx1v5B429u+Zrabo7/btGr6YroKG9RUfG8ozA8vpvFmiXaTt3ZWYsi35BNITYHZkcjR9SFz5cXYgmaA7UO/H9tKNxSrQtpgk8JZXHjjcXIAHLCa69kAfAAuWdSYfNpVMzyZndcL7uXoV2no= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764066; c=relaxed/simple; bh=cjtmtU/qY66mskFg5LMQm5YqDpAxiSceCr1Av3WJ0LA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AQ9B/WlTzuqsRTk5dE1qYnv93j17s65+xQO5CXA6y1wcqocjuZ7qwBHx8gyySI0eHjXZiblwa1Mv0cOwUmY9WW/QXVm65Qv0rfk0mYZ5m1ZJCq6tFk+ftKbZ3u5cfFmal290Fl9+9dzAtQMkciddnXE6joYQpGyHrGucQ8oQxk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KXmVvi0W; arc=none smtp.client-ip=209.85.128.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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KXmVvi0W" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61bb09d8fecso140413477b3.0 for ; Fri, 03 May 2024 12:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764064; x=1715368864; 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=dz6D2GuVBAhhi2ShyqTlonmshv6ltlgTKSRmhVnZVcI=; b=KXmVvi0WUdbijAlqXMHSVGBEnwXnBWzi6Nqh0ltJg5T4Yn+fc15jc8DZ4SX+F5bVXT MCNUMQ4sFoohZDpHglDEqSDEzdDUajBBfigR83rB2+SXjU3D0MpTXgSRQcqeCLOoK2hS PvYH0YS08jzpVIeg/Nv8C9nZLHPuEFTMwEF7Iph+NDWMsY/VgTVpZWoethIKcdsUlJPX mY/EpsjRxk5DgAyd6Mmiqmk2xnTKBZVYRUH2jqrZPLYrJx0r4WHPstYWUPlfwmTM5C0S 20ZvQ6VwfilDgZIm9lirTegLYPlArUd/zZzEOe4eJZF9xci3j3cnvfXKCC9vS+Pcw4F2 qSXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764064; x=1715368864; 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=dz6D2GuVBAhhi2ShyqTlonmshv6ltlgTKSRmhVnZVcI=; b=UxLcJPqd6WqJjKEVJL/x59xY2bAqtw5ggMq20uOrhVgUL7gL9YDLSe2nNsMqu/TVu9 5DK/jErAa5B5E3dw/2V+nH5ZD6hOSxiNlfFrGipehQySJMlc3Mh6Xd6NuPF0+C2VUaXQ +rdc49hz7XxhupeG+1ik5+pVx5A8RhbfnsoEBQT/d7AqVZIYjB/1YWtXqZktaL80N8kW Snl9iCIdga6+8FZGd/ZOjuDrlWu3kbp0vcEttUEveWj2AFKx5BawAH7h+5xq3SfEZ4vb /QZdRRfSZQWhfX6ZDAF7CbCxaUS89AzkUVCI1829IxRV/eDAneecqob/93egzXX3wZZT jkqw== X-Gm-Message-State: AOJu0YxMMUlXgJAqfrpoEOsIdIG/ZlTZv9ak7NGuTbEMEK1SIcLkObiw nPXzMSAlAvRCkJBCT1f473jIBos/dODEmR2pJPOlip1g1CXTaMeel5EkOc5oGK00cR157m9DzHP UyMGztCVrKg== X-Google-Smtp-Source: AGHT+IG6l3qlrG5m/LlVp3NMTWf8BX0Qs4BWlh+srDdvbN4hraZZJ57Who3dt3ia0gDr90pSTYUUmCInk1I5pw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:18ca:b0:dc6:b813:5813 with SMTP id ck10-20020a05690218ca00b00dc6b8135813mr468363ybb.9.1714764064231; Fri, 03 May 2024 12:21:04 -0700 (PDT) Date: Fri, 3 May 2024 19:20:53 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-3-edumazet@google.com> Subject: [PATCH net-next 2/8] rtnetlink: do not depend on RTNL for IFLA_IFNAME output From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org We can use netdev_copy_name() to no longer rely on RTNL to fetch dev->name. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/rtnetlink.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index f4a87f89d5cde0cdd35c156d78ebe31511d4a31c..a92e3b533d8d2ed1a52a40e02eb994c3070ede38 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1812,6 +1812,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, u32 event, int *new_nsid, int new_ifindex, int tgt_netnsid, gfp_t gfp) { + char devname[IFNAMSIZ]; struct ifinfomsg *ifm; struct nlmsghdr *nlh; struct Qdisc *qdisc; @@ -1832,8 +1833,11 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, if (tgt_netnsid >= 0 && nla_put_s32(skb, IFLA_TARGET_NETNSID, tgt_netnsid)) goto nla_put_failure; - if (nla_put_string(skb, IFLA_IFNAME, dev->name) || - nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) || + netdev_copy_name(dev, devname); + if (nla_put_string(skb, IFLA_IFNAME, devname)) + goto nla_put_failure; + + if (nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) || nla_put_u8(skb, IFLA_OPERSTATE, netif_running(dev) ? dev->operstate : IF_OPER_DOWN) || nla_put_u8(skb, IFLA_LINKMODE, dev->link_mode) || From patchwork Fri May 3 19:20:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653346 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 ABBDC158A10 for ; Fri, 3 May 2024 19:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764068; cv=none; b=Cbk9F2PEx1X3ia1bfezOxbtDgyeNEsIZ4OEfbjiFMroBNRmGWQq+APO0iSv+q3k2UmIwWOUQNUA03eSMCkmQCtrbV/lFBlP2UOjtJBe/si6MqN43XuQFW1ZoeEEmf3NLDzaj1SnwSGJtfj7DZlhjXcBOTGblMDihFR2GZqRsv0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764068; c=relaxed/simple; bh=NAIlCGY6YaLW17JzJEy1hmCIs/+aQu+Gt8kyA29RDkA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g98dgpJvWB3DsBPWsz9PLWT16XUiF5cuVpFZMPHRkKYYnV9TZVy121Nie6lmrFC01PAH1dMkcOWgnJfKPognNPAvkMIqMBS4JguL/dTamWT3AAliMmulZ2F+gyEhWAYfKO1aH3i1BRiduIXT4Dyb6l2t4LicIJTZ5RgLWA/zky8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=O3r+ItbR; arc=none smtp.client-ip=209.85.128.202 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O3r+ItbR" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61e0c1f7169so28509127b3.0 for ; Fri, 03 May 2024 12:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764065; x=1715368865; 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=21xYpUHnHCZNtdsOBFrFzM+JEG0/NS8mk3/29aTeq6k=; b=O3r+ItbRN0ykAos9yLsewbi64mFlz2DzzqioL8mL2VL6TK8lw99d0dnG0wsdWf3u6g XvSs+dTB+Zvhz3MRYxc5Bs8fS6YV0zKNTTJoA84eDAy2QkfsnLsRwXZsDaOn3TBpcX54 FdFnvDAJ2PAMI7EMID4cAYAmubgLM9iW30t91ZvvHQI3OJMUolbel+o0eKAbKtWqBsm8 UbngfrgfwnqQRa3vonyuc8IDu8QrXu15e5ZZXK/hcBgbn+D4fU8xtTT8lEVMNEsUarru 4BWJZv0dr/kgx+BeBNXrHd1GBaeg6MedQ1vhL+ck5lSEh/3/F51PQ5793ktAkB/e3Koi cmmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764065; x=1715368865; 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=21xYpUHnHCZNtdsOBFrFzM+JEG0/NS8mk3/29aTeq6k=; b=nOp1Ou4mub92Yc3nEPBDd9yZo8gWOKB1isE5dh1lRkCsrPCaK3X9qhWEiJE3CwxAA1 TOYCw7FCFJVjM0eaqfDwFE37GoWe8cE3T3x14nHB+B0BlgmlP5NMNXifyo0RZMU3WevA hvnQ0rRJg2gG+5h+X9TMy9fZ2A2ZCoY1gZVz1KCOcVMtOJNxQkgtc23Gq/DL1rjBmm1a vntqmeNt/idnwc34Yz0jUTxJHWhtIw0L4Qx1rql3G9agkwUsiBFFpxffKpE91ryRFa5g QqHmNX3ZkAvQWmW7dQcZrUNVcxZzUtKySujN3bVgBAHg5QElRDWrZwoNTbBCS2sFgFpB a3Dw== X-Gm-Message-State: AOJu0YzdptRCRHK4FX214s6QKkLkra1XEo+SRW8oL9sk9Z86dWeb9PnE xTd0jtkcbiYuZrYNnbfB6TCAflqreFQTrV/UdpUPmc0I5w5Fjw8M15d3T+7QYHmySg6BT8/vVJd UJ85W2HTVUw== X-Google-Smtp-Source: AGHT+IEENznFlC3n49lGHdlZ/ddyEZ5HEQUh3DsC4igGU+M2Mgv5cg8g2jRInQwctoHUiWd+NT5UfnnEenRTEQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:9110:0:b0:618:2ad1:a46f with SMTP id i16-20020a819110000000b006182ad1a46fmr1718363ywg.2.1714764065748; Fri, 03 May 2024 12:21:05 -0700 (PDT) Date: Fri, 3 May 2024 19:20:54 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-4-edumazet@google.com> Subject: [PATCH net-next 3/8] rtnetlink: do not depend on RTNL for IFLA_TXQLEN output From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org rtnl_fill_ifinfo() can read dev->tx_queue_len locklessly, granted we add corresponding READ_ONCE()/WRITE_ONCE() annotations. Add missing READ_ONCE(dev->tx_queue_len) in teql_enqueue() Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/dev.c | 4 ++-- net/core/rtnetlink.c | 2 +- net/sched/sch_api.c | 2 +- net/sched/sch_teql.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index e02d2363347e2e403ccb2a59d44d35cee9a1b367..9c8c2ab2d76c3587d9114bc86a395341e1fd4d2b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8959,7 +8959,7 @@ int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len) return -ERANGE; if (new_len != orig_len) { - dev->tx_queue_len = new_len; + WRITE_ONCE(dev->tx_queue_len, new_len); res = call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev); res = notifier_to_errno(res); if (res) @@ -8973,7 +8973,7 @@ int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len) err_rollback: netdev_err(dev, "refused to change device tx_queue_len\n"); - dev->tx_queue_len = orig_len; + WRITE_ONCE(dev->tx_queue_len, orig_len); return res; } diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index a92e3b533d8d2ed1a52a40e02eb994c3070ede38..77d14528bdefc8b655f5da37ed88d0b937f35a61 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1837,7 +1837,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, if (nla_put_string(skb, IFLA_IFNAME, devname)) goto nla_put_failure; - if (nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) || + if (nla_put_u32(skb, IFLA_TXQLEN, READ_ONCE(dev->tx_queue_len)) || nla_put_u8(skb, IFLA_OPERSTATE, netif_running(dev) ? dev->operstate : IF_OPER_DOWN) || nla_put_u8(skb, IFLA_LINKMODE, dev->link_mode) || diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 6292d6d73b720fef6766d08ed01d8b93a99f97b6..74afc210527d237cca3b48166be5918f802eb326 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1334,7 +1334,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev, * before again attaching a qdisc. */ if ((dev->priv_flags & IFF_NO_QUEUE) && (dev->tx_queue_len == 0)) { - dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN; + WRITE_ONCE(dev->tx_queue_len, DEFAULT_TX_QUEUE_LEN); netdev_info(dev, "Caught tx_queue_len zero misconfig\n"); } diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c index 59304611dc0050e525de5f45b2a3b8628b684ff3..29850d0f073308290ac1a479bc98315034990663 100644 --- a/net/sched/sch_teql.c +++ b/net/sched/sch_teql.c @@ -78,7 +78,7 @@ teql_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free) struct net_device *dev = qdisc_dev(sch); struct teql_sched_data *q = qdisc_priv(sch); - if (q->q.qlen < dev->tx_queue_len) { + if (q->q.qlen < READ_ONCE(dev->tx_queue_len)) { __skb_queue_tail(&q->q, skb); return NET_XMIT_SUCCESS; } From patchwork Fri May 3 19:20:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653347 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 2FE20158863 for ; Fri, 3 May 2024 19:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764069; cv=none; b=U7btY7GQKj2XBa5zWIWVCmmwWOTGePd243P2LYIr4L7gYofVO4lrzh28CZqF0k6BG+kSgewmhpTurOKqgff+lBGEemQgo3ybNvcttqjvXYQir5wiNN/x/8eFr4qoYicoRX9EFxd7Y5kdQUg4EgOZxGLYPaWSqW3zc2prPQlJcrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764069; c=relaxed/simple; bh=CSV+1s7gEyCgzGjbySij0XcBjebpUYezWFKRWKUJ1Io=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mIEXXFhf8zgVTYF6JV1spawOw7NqQpwmIHkUi/hl5zXl3qX11KWfVIY6PEkmROhls5zKWCgBpLZnpKMBHaSCNid383BtmdvS5xWj40vOVOe3msSNtBEAc6iVAN7zYS3T/0bH36R5PpyiW1ZefyegYK8k1H5N4bNIN3eMybQTVpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Pa382NlX; arc=none smtp.client-ip=209.85.128.202 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Pa382NlX" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61bb09d8fecso140414677b3.0 for ; Fri, 03 May 2024 12:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764067; x=1715368867; 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=mxgCTefd4q94lTE6o3lgiJsd3Dd3lGIeXXmmQWG1Kds=; b=Pa382NlX54jQLo+nSn0FfBVepQc43shPirDeXw7g6ZrMu85MjEpw2o3GUCqg4w/FZq TG16lgmYQHwU3RQXN8qskRKPdzmMpDOOcHcnodITX77ngYC/m6x06sYfd6LdqCpHf0s1 umUmzb90dkTwxKuFr0yrPdAvYrqvPnnge2rCbG6Sa+qrFMAovc47vMOuE9KN62cwQZ4L FA+ODLgiWQgTnXJZCLwM+zfdidUwYQfis/I+N2OZ8/ILRTQi/13RcIh4dpbaIrWKqaLh HxntwRlpZYDbpCbdDZtc37IuqDr2iywFjFLBSE09p69grJUnBwx7uceT68lQzI33fFBz N3CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764067; x=1715368867; 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=mxgCTefd4q94lTE6o3lgiJsd3Dd3lGIeXXmmQWG1Kds=; b=ha+jrueexFgtc6Jn4mM3IlDzXpzouJ6kCs6mif15dfoRMdSYXH0uPjTKSm2tmebL4H y8fVNod1b/nzr6etSX4OZ+TCi5BGpOF8OxJ74EEVlbS4gwKnFqlzK1k+33KDu3ZnuMRW nIibdgNwzf/Ziv6cMzyLaMpci5UdzLC2MX19q4ptJxMKKuZdPqet/nLIzBzKFJJUVAfc yRQ7Nr52f1ND5gSfXA9YA3OSJoKvGk/Kr+NvHCoqtHOQWMWWBAsiBUbhAxIqP+nrI+pZ NYUs82t3n85tHmY0eCzzApLZiBYhbtMGDKZpHGosgiW9zbdVa1fUwdB4EBkZsqnK5NkB vUUw== X-Gm-Message-State: AOJu0YyoSoxSQW1Stus017onyeNufMau4/NLDtQ4c2Cj32m6Fv3kWi8T d4KOfrN7LYzkmI8BG3OeiL0Rb4+0/Acv60YyswEMVcnw2Ds4b4G2UB7QYXr7J/SembNHGZ82nOT bduGBAwXyiQ== X-Google-Smtp-Source: AGHT+IH8U9Z2bgS7j1fbzjxM106lT6qfu8GqWkcPon83ppMtCbgv2pGG4gBX1qpbnkMXs16C+UKbWZBy4JjhqA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:18ca:b0:dc6:b813:5813 with SMTP id ck10-20020a05690218ca00b00dc6b8135813mr468377ybb.9.1714764067203; Fri, 03 May 2024 12:21:07 -0700 (PDT) Date: Fri, 3 May 2024 19:20:55 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-5-edumazet@google.com> Subject: [PATCH net-next 4/8] net: write once on dev->allmulti and dev->promiscuity From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org In the following patch we want to read dev->allmulti and dev->promiscuity locklessly from rtnl_fill_ifinfo() In this patch I change __dev_set_promiscuity() and __dev_set_allmulti() to write these fields (and dev->flags) only if they succeed, with WRITE_ONCE() annotations. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/dev.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 9c8c2ab2d76c3587d9114bc86a395341e1fd4d2b..35ce603ffc57fa209dc9a57e60981a2bca5e6a29 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8544,27 +8544,29 @@ static void dev_change_rx_flags(struct net_device *dev, int flags) static int __dev_set_promiscuity(struct net_device *dev, int inc, bool notify) { unsigned int old_flags = dev->flags; + unsigned int promiscuity, flags; kuid_t uid; kgid_t gid; ASSERT_RTNL(); - dev->flags |= IFF_PROMISC; - dev->promiscuity += inc; - if (dev->promiscuity == 0) { + promiscuity = dev->promiscuity + inc; + if (promiscuity == 0) { /* * Avoid overflow. * If inc causes overflow, untouch promisc and return error. */ - if (inc < 0) - dev->flags &= ~IFF_PROMISC; - else { - dev->promiscuity -= inc; + if (unlikely(inc > 0)) { netdev_warn(dev, "promiscuity touches roof, set promiscuity failed. promiscuity feature of device might be broken.\n"); return -EOVERFLOW; } + flags = old_flags & ~IFF_PROMISC; + } else { + flags = old_flags | IFF_PROMISC; } - if (dev->flags != old_flags) { + WRITE_ONCE(dev->promiscuity, promiscuity); + if (flags != old_flags) { + WRITE_ONCE(dev->flags, flags); netdev_info(dev, "%s promiscuous mode\n", dev->flags & IFF_PROMISC ? "entered" : "left"); if (audit_enabled) { @@ -8615,25 +8617,27 @@ EXPORT_SYMBOL(dev_set_promiscuity); static int __dev_set_allmulti(struct net_device *dev, int inc, bool notify) { unsigned int old_flags = dev->flags, old_gflags = dev->gflags; + unsigned int allmulti, flags; ASSERT_RTNL(); - dev->flags |= IFF_ALLMULTI; - dev->allmulti += inc; - if (dev->allmulti == 0) { + allmulti = dev->allmulti + inc; + if (allmulti == 0) { /* * Avoid overflow. * If inc causes overflow, untouch allmulti and return error. */ - if (inc < 0) - dev->flags &= ~IFF_ALLMULTI; - else { - dev->allmulti -= inc; + if (unlikely(inc > 0)) { netdev_warn(dev, "allmulti touches roof, set allmulti failed. allmulti feature of device might be broken.\n"); return -EOVERFLOW; } + flags = old_flags & ~IFF_ALLMULTI; + } else { + flags = old_flags | IFF_ALLMULTI; } - if (dev->flags ^ old_flags) { + WRITE_ONCE(dev->allmulti, allmulti); + if (flags != old_flags) { + WRITE_ONCE(dev->flags, flags); netdev_info(dev, "%s allmulticast mode\n", dev->flags & IFF_ALLMULTI ? "entered" : "left"); dev_change_rx_flags(dev, IFF_ALLMULTI); From patchwork Fri May 3 19:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653348 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 70C7E158D62 for ; Fri, 3 May 2024 19:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764070; cv=none; b=RnqZD3k/yrEalRA06YAmjq61AbfQt6+P9wx/+4nt5iqf5ou2jAdhugiedS9B9qy6oiCrBp9VgBeW8cijAqwklwvR/TGZPGVZM9FffaCZ23pXT4rgHCAITF6vK9r3Wh3wHrEHVmW17kYbXGimWIQjaddZFOBjV/GBRws3RzfCXOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764070; c=relaxed/simple; bh=9inSIsYz7jeVuYDNCAdsbQnG65h01+pBIiNJcjCp5kA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IccNau/uHzODRnXbekMfsba4xz+c1fsc24vEhOj0dY4nGVmQjR36nYVAIgT1EdjcxHjvllMFWhPSpJxOx5+KSexb1rIfwyKbJYy1UTGPOHe/3VIukFEXSGp4W/EUOrNgtZzaEhArBYi9BYlu6w0t1NZtlROsiQ8ilBbBibPtrRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=j25g307l; arc=none smtp.client-ip=209.85.219.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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j25g307l" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b269686aso72300276.1 for ; Fri, 03 May 2024 12:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764068; x=1715368868; 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=cSZyZFAMTOLjqnKwjp5Wj0SARacf3WdqfjzifFZ+QaQ=; b=j25g307lHQRppeLvBXnmVJNt/NvODGi1EPDQ+JLsHpK0c+vdO1fkJ9OYC7o4xF4EUM g5bRXdRrVXkEccO9iA+ZrDo5/HymbebzOHmi+QU2x8QPh9BTh+E02a+OjIXDZqi5/w7b F6+dfzua8x0Ggr7PKYRYpevZuI9QjRSmHN2Z6evm/ycZDcRVWOr0N0VoYpY0Wh0jxRKm 4eS6OUlCGzqH0TlR0jeqq3/N0R80icdMQTBRjN7q4Ymav+NgczJNlJFOM5Zom81QGkp7 2g47bi5rdRD5dsC9uJp4a3WUJZ6UAKn47OzExoUtX7FstrRULS2q137D+vdb6trK2g6n vYOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764068; x=1715368868; 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=cSZyZFAMTOLjqnKwjp5Wj0SARacf3WdqfjzifFZ+QaQ=; b=FU/fq+LhS7Jhb4td7AS2/YT7klwTiEagqKyCbn1nVeflMnxj3S4jSlBR6ZlfYjFbTm OSzz6lYaNbvoWnUZObK556exZ7Atem3FXrT+AWkEyCwDb7Iag3CVjWvlohLV8oELxION nVp0N7M2cjllRPmbFvIT9ql4rALL5V7lYINyP8KSnZApHCBFtyJelqrgVZoabydUISAR xCFNwyqZxQpIhxl3hR9Bz5z6/nmynmtC9RI4O1N73qrSzZ7TOLlGs7iMX+v9lxDsskg4 /WsrZnBSjnd2KdTAYhNE5Eyvxrf2vkvKGUHYH0fezZ5ADk2CzVDbxgMeYHeKC5NALmgo C21A== X-Gm-Message-State: AOJu0YymkMMKUu6ZUVPonXVHnlw3auFNDF8uCFlLTIZs1NHUTCGWFynn StUUib96/55cjNMylYNaQ6O72PQ+rsib7uJ39r+9hhGIX32QbRb8dz5AG0qQ5vM61qzNL5mO2jA 8TtWgUNw3UQ== X-Google-Smtp-Source: AGHT+IEtrHV8BnWhYkyXUVcGa8trQqFBZLBs9GJMmSz6K4mV/Cs4bDFfXuBcBzHN0U1XLTI91x5hPZF46pOXhg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1082:b0:dce:5218:c89b with SMTP id v2-20020a056902108200b00dce5218c89bmr477031ybu.5.1714764068410; Fri, 03 May 2024 12:21:08 -0700 (PDT) Date: Fri, 3 May 2024 19:20:56 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-6-edumazet@google.com> Subject: [PATCH net-next 5/8] rtnetlink: do not depend on RTNL for many attributes From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Following device fields can be read locklessly in rtnl_fill_ifinfo() : type, ifindex, operstate, link_mode, mtu, min_mtu, max_mtu, group, promiscuity, allmulti, num_tx_queues, gso_max_segs, gso_max_size, gro_max_size, gso_ipv4_max_size, gro_ipv4_max_size, tso_max_size, tso_max_segs, num_rx_queues. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/rtnetlink.c | 51 +++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 77d14528bdefc8b655f5da37ed88d0b937f35a61..242c24e857ec4c799f0239be3371fd589a8ed191 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1603,7 +1603,8 @@ static int put_master_ifindex(struct sk_buff *skb, struct net_device *dev) upper_dev = netdev_master_upper_dev_get_rcu(dev); if (upper_dev) - ret = nla_put_u32(skb, IFLA_MASTER, upper_dev->ifindex); + ret = nla_put_u32(skb, IFLA_MASTER, + READ_ONCE(upper_dev->ifindex)); rcu_read_unlock(); return ret; @@ -1825,8 +1826,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, ifm = nlmsg_data(nlh); ifm->ifi_family = AF_UNSPEC; ifm->__ifi_pad = 0; - ifm->ifi_type = dev->type; - ifm->ifi_index = dev->ifindex; + ifm->ifi_type = READ_ONCE(dev->type); + ifm->ifi_index = READ_ONCE(dev->ifindex); ifm->ifi_flags = dev_get_flags(dev); ifm->ifi_change = change; @@ -1839,24 +1840,34 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, if (nla_put_u32(skb, IFLA_TXQLEN, READ_ONCE(dev->tx_queue_len)) || nla_put_u8(skb, IFLA_OPERSTATE, - netif_running(dev) ? dev->operstate : IF_OPER_DOWN) || - nla_put_u8(skb, IFLA_LINKMODE, dev->link_mode) || - nla_put_u32(skb, IFLA_MTU, dev->mtu) || - nla_put_u32(skb, IFLA_MIN_MTU, dev->min_mtu) || - nla_put_u32(skb, IFLA_MAX_MTU, dev->max_mtu) || - nla_put_u32(skb, IFLA_GROUP, dev->group) || - nla_put_u32(skb, IFLA_PROMISCUITY, dev->promiscuity) || - nla_put_u32(skb, IFLA_ALLMULTI, dev->allmulti) || - nla_put_u32(skb, IFLA_NUM_TX_QUEUES, dev->num_tx_queues) || - nla_put_u32(skb, IFLA_GSO_MAX_SEGS, dev->gso_max_segs) || - nla_put_u32(skb, IFLA_GSO_MAX_SIZE, dev->gso_max_size) || - nla_put_u32(skb, IFLA_GRO_MAX_SIZE, dev->gro_max_size) || - nla_put_u32(skb, IFLA_GSO_IPV4_MAX_SIZE, dev->gso_ipv4_max_size) || - nla_put_u32(skb, IFLA_GRO_IPV4_MAX_SIZE, dev->gro_ipv4_max_size) || - nla_put_u32(skb, IFLA_TSO_MAX_SIZE, dev->tso_max_size) || - nla_put_u32(skb, IFLA_TSO_MAX_SEGS, dev->tso_max_segs) || + netif_running(dev) ? READ_ONCE(dev->operstate) : + IF_OPER_DOWN) || + nla_put_u8(skb, IFLA_LINKMODE, READ_ONCE(dev->link_mode)) || + nla_put_u32(skb, IFLA_MTU, READ_ONCE(dev->mtu)) || + nla_put_u32(skb, IFLA_MIN_MTU, READ_ONCE(dev->min_mtu)) || + nla_put_u32(skb, IFLA_MAX_MTU, READ_ONCE(dev->max_mtu)) || + nla_put_u32(skb, IFLA_GROUP, READ_ONCE(dev->group)) || + nla_put_u32(skb, IFLA_PROMISCUITY, READ_ONCE(dev->promiscuity)) || + nla_put_u32(skb, IFLA_ALLMULTI, READ_ONCE(dev->allmulti)) || + nla_put_u32(skb, IFLA_NUM_TX_QUEUES, + READ_ONCE(dev->num_tx_queues)) || + nla_put_u32(skb, IFLA_GSO_MAX_SEGS, + READ_ONCE(dev->gso_max_segs)) || + nla_put_u32(skb, IFLA_GSO_MAX_SIZE, + READ_ONCE(dev->gso_max_size)) || + nla_put_u32(skb, IFLA_GRO_MAX_SIZE, + READ_ONCE(dev->gro_max_size)) || + nla_put_u32(skb, IFLA_GSO_IPV4_MAX_SIZE, + READ_ONCE(dev->gso_ipv4_max_size)) || + nla_put_u32(skb, IFLA_GRO_IPV4_MAX_SIZE, + READ_ONCE(dev->gro_ipv4_max_size)) || + nla_put_u32(skb, IFLA_TSO_MAX_SIZE, + READ_ONCE(dev->tso_max_size)) || + nla_put_u32(skb, IFLA_TSO_MAX_SEGS, + READ_ONCE(dev->tso_max_segs)) || #ifdef CONFIG_RPS - nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) || + nla_put_u32(skb, IFLA_NUM_RX_QUEUES, + READ_ONCE(dev->num_rx_queues)) || #endif put_master_ifindex(skb, dev) || nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) || From patchwork Fri May 3 19:20:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653349 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 D28C5158D6D for ; Fri, 3 May 2024 19:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764072; cv=none; b=Gn8Fg9uA3OMXopO2KnM1rVxw1M4hYuo1f84Lz2moJnO1Cj1wNGFcZz3VZaFTQL90Y01+dkyCyKl+SOlnKhqjMIdbRzHc3EuaZKfSem09BuokQb0M1nur9GFZDs0RT8cVtNXYrm9EF6Bo0vW6f3N2TT6g1GfYcxppeskbEdjqomg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764072; c=relaxed/simple; bh=fRjbT5NStrHvBG+rAmq+eyfDV2ZRKLzuSbh/toAiteI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AMAGi14gCv2cSF8OrOwd809jMU66z/xE/+bAEGj31Du1xNqFSq37ghKF3eVaGSjtl+NAKqCz0WjMlvvVa/bKaSGpPYdDv607bIVnSsixqQ0Vta1K7xelUwt+KUrHidOQiuxdQSv7Z9KQ7KlSCrPWnajOI6lmutP/3NgOHYWqvZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mtrE++n9; arc=none smtp.client-ip=209.85.219.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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mtrE++n9" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ddaf165a8d9so63425276.1 for ; Fri, 03 May 2024 12:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764070; x=1715368870; 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=Vn8/pGsIeiqYpc1qyip3qFRTTko/1kojG9TEz9vmOMQ=; b=mtrE++n9w2N8bhJpekQtOyxG1ISbKGxvTX/1ekriZ/VcoViHSuQbfWtRoOR1hYblEf 04il5/G8zKoPjLsbitK04LqFstVoeQQGqZZlFfEjGq22i3R6MJikBcwnt0UyO8EDPzfe IEGsc+3KgJoPeQqkLyDQQGYGgGsKAJSA8Q9YxfXf4lWBRlR0A/HuIW0psoj1YpYGa4B0 KGJ0CFdFi/lkhZu5mYqBZ7hXsemhHPMMae/ZlP7Ly+sGE5jAGLiKzzknQMEmLCaspNj2 bTCsYSnDz/xfncH+jpf2SzylwBRppMxDMW8pS64DHEj3aRspZPT7r0VU/qrbIKQhxfYg xz5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764070; x=1715368870; 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=Vn8/pGsIeiqYpc1qyip3qFRTTko/1kojG9TEz9vmOMQ=; b=i6pm+uVcsAUJWy4HwXsm9Xp2rJtuIgkiG3M7B86bMM6CpCFx3CJJ/OxKiwEKEwzneh MxIbtkjazHPIgiXfVUTwS3cWcuNHF0f1TYP1N/06mGEBqQhIp+Er7Ngst7kGFL0/8Pnp aADuQ40oCMvkrGVMLmZeJJje1UyIutBuXFCkH9bypRig+xSNt37Qbed5I/FmxhntVQU9 AlNZeWZ+URi6XRws79Kpx2rhPpzjcgbJAVeXmOqz1N3eYgh5RJYbyaHdmZSduZlxYR1b DwRkE+18Hj6VIbvtYk/rETl8XQ02TNc0iJRTcrFo3ppSh2mqJ30uMgra/DJNI535nwm8 I4Cg== X-Gm-Message-State: AOJu0Yzx4wKuiDZ87QWeZCwSSpz9dlGuOYAst7HDFcKEjaX0LD/e3yrN 1JpPTUmQeT16veS134ZyncuE99NHq14XjAAj68vgmWSK+wnQ0QUfhSpuzW0hHTMC1qUpqWih2g8 eXLkOcwJf0w== X-Google-Smtp-Source: AGHT+IHe7Mst5oE1XPHbOf89cc2ctM5rwmWKGEj+FFaUz9VwoRGY879/goYw4Ti0XkiEtLulGn7N047bxO7TQQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:b311:0:b0:dc6:44d4:bee0 with SMTP id l17-20020a25b311000000b00dc644d4bee0mr475887ybj.7.1714764069937; Fri, 03 May 2024 12:21:09 -0700 (PDT) Date: Fri, 3 May 2024 19:20:57 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-7-edumazet@google.com> Subject: [PATCH net-next 6/8] rtnetlink: do not depend on RTNL in rtnl_fill_proto_down() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Change dev_change_proto_down() and dev_change_proto_down_reason() to write once on dev->proto_down and dev->proto_down_reason. Then rtnl_fill_proto_down() can use READ_ONCE() annotations and run locklessly. rtnl_proto_down_size() should assume worst case, because readng dev->proto_down_reason multiple times would be racy without RTNL in the future. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/dev.c | 11 +++++++---- net/core/rtnetlink.c | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 35ce603ffc57fa209dc9a57e60981a2bca5e6a29..06304f07146c7f672573a977b069e7f2c031122e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9223,7 +9223,7 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) netif_carrier_off(dev); else netif_carrier_on(dev); - dev->proto_down = proto_down; + WRITE_ONCE(dev->proto_down, proto_down); return 0; } @@ -9237,18 +9237,21 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) void dev_change_proto_down_reason(struct net_device *dev, unsigned long mask, u32 value) { + u32 proto_down_reason; int b; if (!mask) { - dev->proto_down_reason = value; + proto_down_reason = value; } else { + proto_down_reason = dev->proto_down_reason; for_each_set_bit(b, &mask, 32) { if (value & (1 << b)) - dev->proto_down_reason |= BIT(b); + proto_down_reason |= BIT(b); else - dev->proto_down_reason &= ~BIT(b); + proto_down_reason &= ~BIT(b); } } + WRITE_ONCE(dev->proto_down_reason, proto_down_reason); } struct bpf_xdp_link { diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 242c24e857ec4c799f0239be3371fd589a8ed191..6af7f00503b43d4989d0aaafc8b968216a6e77f5 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1036,8 +1036,8 @@ static size_t rtnl_proto_down_size(const struct net_device *dev) { size_t size = nla_total_size(1); - if (dev->proto_down_reason) - size += nla_total_size(0) + nla_total_size(4); + /* Assume dev->proto_down_reason is not zero. */ + size += nla_total_size(0) + nla_total_size(4); return size; } @@ -1737,10 +1737,10 @@ static int rtnl_fill_proto_down(struct sk_buff *skb, struct nlattr *pr; u32 preason; - if (nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down)) + if (nla_put_u8(skb, IFLA_PROTO_DOWN, READ_ONCE(dev->proto_down))) goto nla_put_failure; - preason = dev->proto_down_reason; + preason = READ_ONCE(dev->proto_down_reason); if (!preason) return 0; From patchwork Fri May 3 19:20:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653350 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 4FF7F158D78 for ; Fri, 3 May 2024 19:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764073; cv=none; b=jDR9Pihxa/+WBYQGn3qmbk7xqpZbS4VEGfhxVkJxE7SsGa6ZJU6uFGNZx7FH4Q/YzppTHITa1GJQLV8xFMN9d2MrNqyxJK8XXH6MoPYmM8b62O/GU4wqaQpgFALHXHylFrrdrM+Ym3BY8SGCi+DhwSGidK4j6KBS4k10EAhqQCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764073; c=relaxed/simple; bh=VNH8X+mNursyIytidxBfk4zTvCG/6MbN9TDD/UEIU3g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oES7vfYFcjECDMVOyvbC7Od5v64rq4IkTzKw2fBa5cf/r81PWy+z4Tid789M2m5SAn/ZHFgcOTddRsnsphtU40mbv38XNFynHPS2TBFmBi2RO4mC4TypDQwXOKXayh5G8UNYJUjoLXSSii4uzBih3rCJn5odyg6KHBnD54L/BAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1nz/n6w/; arc=none smtp.client-ip=209.85.219.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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1nz/n6w/" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6ceade361so111017276.0 for ; Fri, 03 May 2024 12:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764071; x=1715368871; 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=NlLV9C8iwKrRlhE5CROAsvA0PyY8Z7OdesQFV96MNlM=; b=1nz/n6w/0DB1F4UoZpH0YVSwuqvqIn1qV/XyQOptRCwuG4N5Xm3A6T15e3+4y8A/RJ CSpXiNz4MLqkKeUQgyxE5vhQJubgZm6RQShv0kB0bOJuY2sD3JTmg87QT/3PZAQWaFAB WW6ps84XjSgDG++h4Ov58fVXtdOdn8q5Xn+C5qGpTltdcBbV1Bssvm1KtaysizEwv7c3 DxsN+IWaFo1QGDsNUEdF3n9un6cKE3iyJXdRroY903+1RUVifNvot8mR8qlvoy/Zyxcq o4pgchekf8DE2uGk4PEIvDE2hyvej0TFlaH1PMHpoe13PLRwPUGtNPoa0Sph5IyJg+Bw mZFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764071; x=1715368871; 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=NlLV9C8iwKrRlhE5CROAsvA0PyY8Z7OdesQFV96MNlM=; b=wAKbosHP/53PZ0TzA9D55O8wdOEViPxyxJ/8w53yZIKnZe3B8IzWzZpUlqkbRYkqVo TF1LZnVQgOmdQVLOgmr2fIGTTHQiaeb0aODLtaDrf2EX5sbb1d+Atr5I531HL6rWn2kN 2YogXw7aKoTaMXxkdXYaAYECpKETihtqvWDdCcOmYZZSyNAS7MT5GqDXmGhmDHt3S9Dj C4CnB4k2CRFYC0ipK0oW7AuU+sCL3KZDZznvcIsqb71ztYkkw8wDTltlvwUi5ypdSGgT AUMBBlRYlBpS5EGg22nUxpe6RPyYumgXJ100vPFQ7/U1ZwPHVP7zM+5EwczRrr9dhexa jWUw== X-Gm-Message-State: AOJu0Yzof9OsLZ9Brpiy9NRMyo8ScL6wlTq9Lg4C4J9MSiYO9GSeXA2x RqG+cZBhQ5A9MeMrharGzjxkej8McfBL4DnTuHBEdz7OTiYdD+OclZ87gEH4a9stTTksAyJyYa+ KwJgzu6Gp0Q== X-Google-Smtp-Source: AGHT+IGLPPg7j+diEojT83ezz8AofHKrsdleln61wy1V3x3Ny1PrxcrCmIIps+hkNf1tVUcEn1FJVBkryn4cRg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:701:b0:dc2:398d:a671 with SMTP id k1-20020a056902070100b00dc2398da671mr1068931ybt.10.1714764071377; Fri, 03 May 2024 12:21:11 -0700 (PDT) Date: Fri, 3 May 2024 19:20:58 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-8-edumazet@google.com> Subject: [PATCH net-next 7/8] rtnetlink: do not depend on RTNL in rtnl_xdp_prog_skb() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org dev->xdp_prog is protected by RCU, we can lift RTNL requirement from rtnl_xdp_prog_skb(). Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- net/core/rtnetlink.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 6af7f00503b43d4989d0aaafc8b968216a6e77f5..66e5be7b92686deb03f58ee43c9707470b8c70d6 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1477,13 +1477,15 @@ static int rtnl_fill_link_ifmap(struct sk_buff *skb, static u32 rtnl_xdp_prog_skb(struct net_device *dev) { const struct bpf_prog *generic_xdp_prog; + u32 res = 0; - ASSERT_RTNL(); + rcu_read_lock(); + generic_xdp_prog = rcu_dereference(dev->xdp_prog); + if (generic_xdp_prog) + res = generic_xdp_prog->aux->id; + rcu_read_unlock(); - generic_xdp_prog = rtnl_dereference(dev->xdp_prog); - if (!generic_xdp_prog) - return 0; - return generic_xdp_prog->aux->id; + return res; } static u32 rtnl_xdp_prog_drv(struct net_device *dev) From patchwork Fri May 3 19:20:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13653351 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 2AECC158873 for ; Fri, 3 May 2024 19:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764075; cv=none; b=rA/Y13S/QRQ8OWnJz8TDzAvGWk2Q43vEs2aSWUlwI1H6XOM/qHJK6wJr0GLdC8hSA4ozf7mrXkV6YOCnrWKFA9Jea1b64B+o4E+scfGYpXKB41NUarl8ATMj4yRMexPUI7lYJ/mcn/tMgVgpvi0uMz/hw0TaotGHCTmBqdvQPPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714764075; c=relaxed/simple; bh=nvsdQhsEhXKktIOdX+nnjFnxX4jjlW1EwDm1UUoWm1Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=frtXXriQzGdGC4cQ4HUrL1WTq2qMBLN8+tL2Rj5YBv6NKvrrg2NmsONRKLXfAiPrcsF1EY+oBovYZWCJ4GbdjDQBbZ8FTdFEwEIsIp3P0mLDvDIAb5/oAHYxp/50ddMcFCa9uzw9TTF7tcZGAyl1qRMWU06pY4I6oo2NQAbbO/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2P4f/pc1; arc=none smtp.client-ip=209.85.128.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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2P4f/pc1" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be25000a4so102032037b3.2 for ; Fri, 03 May 2024 12:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714764073; x=1715368873; 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=7Zk6JQ9TWgPWKV9n/jYU74muGrDtW2QHmeth5FkVCmA=; b=2P4f/pc19fdA6dVvsGBUNJ/9C9mjL37MC9taM68NYqIewciEMD0eofoK3te0faQOfp GIwiFWTwJVD1R6591qAOnAVb/+Tf0Z/XWGA+tWcI5UyZo5q6m9jxTZSfiIXbp1slIEne ynQSIh/SsCDKc6y7SWFwIaA5eXt6xJwvUYwoxmtVDSv/C2/PdkDQvdVUJ/y6hvfetzH6 EVQ6t1c3pvEnhntn5xuYEr76Gex7DUTzYJoXHazS/UBEhYGnQB2eAnlHAS9ZH9f5PjXq bt7f8+6sxXgqAIUjTxweMi/BnDVyKBTym5xbwL65Nh4HxvepNNt/RfrX9j68wCHx+cC6 lGAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714764073; x=1715368873; 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=7Zk6JQ9TWgPWKV9n/jYU74muGrDtW2QHmeth5FkVCmA=; b=VM82DPhi9DPkqDxhyEL8jHwMOl3yw3BcLy5cW3SquVVdbkkqlAkeXrvGkGlnIB2MYs CUQ4eqQvAld3Fi22jRzq8lh8yh3fVsTFGWBo47SLSFs66w4jChzfGbTnrKcNRvMITbwI CG0Jo4zjyvblqHl6ybQiF505Y0hdwun8YhLQql+pNFVTvgzZiKGUuvIUdZaOqSQjCzj6 R1V6RbyKFOlQFz0FS4XqienV/l+OlDx9TovU/QGCZqcBwprLeztA7Q7kHqkwyRl9xhPk OG6SBP4jERlgvR4yY84emZFVwcHuNx2dDH3JV+PuetQlkY/j+GeghZyID/cJNbkwkUaG JjKQ== X-Gm-Message-State: AOJu0YwR18f6WOE43qFtAnaS9UYicTTwfj0QQDJdEoc03jpCrzs/DO1M a9VqxhLsUwRM4dAcyQAZpM+QLBIOnHS8i/w8NH9PnhT5+cq4+w5eUYCFHN1Ig7SyRK9jld7eRo7 Pu1J6P0AmsQ== X-Google-Smtp-Source: AGHT+IFhuwZ28m4xko2Oo/h6oBS9i5iWnhd96fDnYlY+aCqzo7P27HA8dablygGnjb/1me4PmxrC2rOsO9E/yg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:10c1:b0:de5:3003:4b7d with SMTP id w1-20020a05690210c100b00de530034b7dmr1079076ybu.0.1714764073087; Fri, 03 May 2024 12:21:13 -0700 (PDT) Date: Fri, 3 May 2024 19:20:59 +0000 In-Reply-To: <20240503192059.3884225-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240503192059.3884225-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503192059.3884225-9-edumazet@google.com> Subject: [PATCH net-next 8/8] rtnetlink: allow rtnl_fill_link_netnsid() to run under RCU protection From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org We want to be able to run rtnl_fill_ifinfo() under RCU protection instead of RTNL in the future. All rtnl_link_ops->get_link_net() methods already using dev_net() are ready. I added READ_ONCE() annotations on others. Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman --- drivers/net/ppp/ppp_generic.c | 2 +- drivers/net/vxlan/vxlan_core.c | 2 +- net/core/rtnetlink.c | 5 ++--- net/ipv4/ip_tunnel.c | 2 +- net/ipv6/ip6_tunnel.c | 2 +- net/xfrm/xfrm_interface_core.c | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index fe380fe196e7b4a1ab4a6f15569d258132c00bac..0a65b6d690feb9fb5d4f1a2046d6195ac0bd39f9 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1357,7 +1357,7 @@ static struct net *ppp_nl_get_link_net(const struct net_device *dev) { struct ppp *ppp = netdev_priv(dev); - return ppp->ppp_net; + return READ_ONCE(ppp->ppp_net); } static struct rtnl_link_ops ppp_link_ops __read_mostly = { diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 8884913e04738b32848b951c671ae3ede9a828e7..7e3a7d1f2018120fbe729eb5c53a6783f492ead6 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -4569,7 +4569,7 @@ static struct net *vxlan_get_link_net(const struct net_device *dev) { struct vxlan_dev *vxlan = netdev_priv(dev); - return vxlan->net; + return READ_ONCE(vxlan->net); } static struct rtnl_link_ops vxlan_link_ops __read_mostly = { diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 66e5be7b92686deb03f58ee43c9707470b8c70d6..91ba27e9169664126f15d19be0299151ce722cd4 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1923,9 +1923,6 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, goto nla_put_failure; } - if (rtnl_fill_link_netnsid(skb, dev, src_net, gfp)) - goto nla_put_failure; - if (new_nsid && nla_put_s32(skb, IFLA_NEW_NETNSID, *new_nsid) < 0) goto nla_put_failure; @@ -1938,6 +1935,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, goto nla_put_failure; rcu_read_lock(); + if (rtnl_fill_link_netnsid(skb, dev, src_net, GFP_ATOMIC)) + goto nla_put_failure_rcu; qdisc = rcu_dereference(dev->qdisc); if (qdisc && nla_put_string(skb, IFLA_QDISC, qdisc->ops->id)) goto nla_put_failure_rcu; diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index ba46cf7612f4fc2cba33c098933b6578dd885587..f1c5f6c3f2f82e19b8e9b696c6900948a946bacc 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -1120,7 +1120,7 @@ struct net *ip_tunnel_get_link_net(const struct net_device *dev) { struct ip_tunnel *tunnel = netdev_priv(dev); - return tunnel->net; + return READ_ONCE(tunnel->net); } EXPORT_SYMBOL(ip_tunnel_get_link_net); diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 57bb3b3ea0c5a463f0c90659fcffe9358a4084b2..5aec79c2af1a58ed1c57cca6d06951403e087d62 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -2146,7 +2146,7 @@ struct net *ip6_tnl_get_link_net(const struct net_device *dev) { struct ip6_tnl *tunnel = netdev_priv(dev); - return tunnel->net; + return READ_ONCE(tunnel->net); } EXPORT_SYMBOL(ip6_tnl_get_link_net); diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c index 4df5c06e3ece834039e1713377538bd7f4d12a3e..e50e4bf993fa473769a0062ffcc661daefaf1b6b 100644 --- a/net/xfrm/xfrm_interface_core.c +++ b/net/xfrm/xfrm_interface_core.c @@ -926,7 +926,7 @@ static struct net *xfrmi_get_link_net(const struct net_device *dev) { struct xfrm_if *xi = netdev_priv(dev); - return xi->net; + return READ_ONCE(xi->net); } static const struct nla_policy xfrmi_policy[IFLA_XFRM_MAX + 1] = {