From patchwork Sat Feb 23 06:34:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10827425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 318B417E9 for ; Sat, 23 Feb 2019 10:40:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DF6C2F33D for ; Sat, 23 Feb 2019 10:40:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 113572F365; Sat, 23 Feb 2019 10:40:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 00EF02F33D for ; Sat, 23 Feb 2019 10:40:14 +0000 (UTC) Received: (qmail 7312 invoked by uid 550); 23 Feb 2019 10:40:09 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 15581 invoked from network); 23 Feb 2019 06:35:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+VRwkLma4QHsLodLyqLqscrFLAElLwMuFYkHuZgYCiA=; b=LXf4B9jiVhDDmWHqmpX8sitFrnlfo5OGBPgxZMG1SG9dPgcG05UwP/0ab87QJca35A +5vX47xZXK/bvlYBPDse0FJpr4WEcj+RtEPX3feM0h5vddYnqNxNRh1Wj7XVR3VJINey NNLEqhrf5Bc1rXkGgXSBIsTOm2/s0liaYt+t8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+VRwkLma4QHsLodLyqLqscrFLAElLwMuFYkHuZgYCiA=; b=CCRKJc8Z2m1Ms6CLtJI2nOMzUcTg3pSI6zpz91tqg7t3ckWWcW3d1eOoKgGGGkgfIw 56dn3SIjwPOzeO8XBG3AqS0EBl86hHGqU2wkVC+0MRdzrPqm8tQap3K4a65fH5SwvchL AKYK2LjxZl8lC/OosZ6SVvgnge//ciHvrLqSj/VWz6xhCd9UMl5JO+NBWX3r1mqCGnJo JyqyWM7oZWsF+brVTFhgGvfjT59KXpXgwghblknMDarjUT12+/absVg+1Oeb27XgSLbv sgIce3lAZPxd33XJbciKboAdcfTAcCU0kncDsOStzw/vvxfpA7r9ydha4KpcyoRQdG3v W+fw== X-Gm-Message-State: AHQUAuYHRMXq14QyOLDrDRCgI1kTm2/Wpa16mBw1mcT1rOkHnS15KsIr aJCJLQDoFTiu+podIvLQdYYJ+Q== X-Google-Smtp-Source: AHgI3IahEVRnoZ+AHkPdERWnSNKPgReNQYpi0yxVo8XFjoaLgTIuIzDAlYYdutedD2WueyS54r/lCw== X-Received: by 2002:a0c:92ec:: with SMTP id c41mr6220040qvc.158.1550903693796; Fri, 22 Feb 2019 22:34:53 -0800 (PST) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Alexei Starovoitov , Christian Brauner , Daniel Borkmann , David Ahern , "David S. Miller" , Ingo Molnar , Jakub Kicinski , Jeff Kirsher , Jesper Dangaard Brouer , John Fastabend , Josh Triplett , keescook@chromium.org, kernel-hardening@lists.openwall.com, kernel-team@android.com, Kirill Tkhai , Lai Jiangshan , Martin KaFai Lau , Mathieu Desnoyers , netdev@vger.kernel.org, "Paul E. McKenney" , Peter Zijlstra , Quentin Perret , rcu@vger.kernel.org, Song Liu , Steven Rostedt , Vincent Guittot , xdp-newbies@vger.kernel.org, Yonghong Song Subject: [PATCH v2 2/6] ixgbe: Fix incorrect RCU API usage Date: Sat, 23 Feb 2019 01:34:30 -0500 Message-Id: <20190223063434.6793-3-joel@joelfernandes.org> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog In-Reply-To: <20190223063434.6793-1-joel@joelfernandes.org> References: <20190223063434.6793-1-joel@joelfernandes.org> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP Recently, I added an RCU annotation check in rcu_assign_pointer. This caused a sparse error to be reported by the ixgbe driver. Further looking, it seems the adapter->xdp_prog pointer is not annotated with __rcu. Annonating it fixed the error, but caused a bunch of other warnings. This patch tries to fix all warnings by using RCU API properly. This makes sense to do because not using RCU properly can result in various hard to find bugs. This is a best effort fix and is only build tested. The sparse errors and warnings go away with the change. I request maintainers / developers in this area to review / test it properly. The sparse error fixed is: ixgbe_main.c:10256:25: error: incompatible types in comparison expression Signed-off-by: Joel Fernandes (Google) Reviewed-by: Paul E. McKenney --- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 4 ++-- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h index 08d85e336bd4..3b14daf27516 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h @@ -311,7 +311,7 @@ struct ixgbe_ring { struct ixgbe_ring *next; /* pointer to next ring in q_vector */ struct ixgbe_q_vector *q_vector; /* backpointer to host q_vector */ struct net_device *netdev; /* netdev ring belongs to */ - struct bpf_prog *xdp_prog; + struct bpf_prog __rcu *xdp_prog; struct device *dev; /* device for DMA mapping */ void *desc; /* descriptor ring memory */ union { @@ -560,7 +560,7 @@ struct ixgbe_adapter { unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; /* OS defined structs */ struct net_device *netdev; - struct bpf_prog *xdp_prog; + struct bpf_prog __rcu *xdp_prog; struct pci_dev *pdev; struct mii_bus *mii_bus; diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index daff8183534b..408a312aa6ba 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -2199,7 +2199,7 @@ static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter, u32 act; rcu_read_lock(); - xdp_prog = READ_ONCE(rx_ring->xdp_prog); + xdp_prog = rcu_dereference(rx_ring->xdp_prog); if (!xdp_prog) goto xdp_out; @@ -6547,7 +6547,7 @@ int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, rx_ring->queue_index) < 0) goto err; - rx_ring->xdp_prog = adapter->xdp_prog; + rcu_assign_pointer(rx_ring->xdp_prog, adapter->xdp_prog); return 0; err: @@ -10246,7 +10246,8 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) if (nr_cpu_ids > MAX_XDP_QUEUES) return -ENOMEM; - old_prog = xchg(&adapter->xdp_prog, prog); + old_prog = rcu_access_pointer(adapter->xdp_prog); + rcu_assign_pointer(adapter->xdp_prog, prog); /* If transitioning XDP modes reconfigure rings */ if (!!prog != !!old_prog) { @@ -10271,13 +10272,17 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp) { struct ixgbe_adapter *adapter = netdev_priv(dev); + struct bpf_prog *prog; switch (xdp->command) { case XDP_SETUP_PROG: return ixgbe_xdp_setup(dev, xdp->prog); case XDP_QUERY_PROG: - xdp->prog_id = adapter->xdp_prog ? - adapter->xdp_prog->aux->id : 0; + rcu_read_lock(); + prog = rcu_dereference(adapter->xdp_prog); + xdp->prog_id = prog ? prog->aux->id : 0; + rcu_read_unlock(); + return 0; case XDP_QUERY_XSK_UMEM: return ixgbe_xsk_umem_query(adapter, &xdp->xsk.umem,