From patchwork Tue Jun 23 17:32:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1315395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49rtdj2lgkz9sQx; Wed, 24 Jun 2020 03:32:41 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jnmmi-000305-Rp; Tue, 23 Jun 2020 17:32:36 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jnmmf-0002y1-DI for kernel-team@lists.ubuntu.com; Tue, 23 Jun 2020 17:32:33 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jnmmf-0004LK-20 for kernel-team@lists.ubuntu.com; Tue, 23 Jun 2020 17:32:33 +0000 Received: by mail-qk1-f198.google.com with SMTP id 16so15779332qka.15 for ; Tue, 23 Jun 2020 10:32:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yAij2jIWTavBrtL4yLkBVjkf13Aj6cEgSb/SQgkgMh8=; b=lZ0eH0VK2AFbfRk6Rkyn2ETW5oYXtkpF0YQtMfOtVri6pTQ941mtlmNE+ts32/nlm4 8OrtHSufYSbRgt0eYyVjX+BAc9QaOQPHaSulBOOOHjFnJlegnYBmcniXAi3fxbvdL7Hy LT4q5t2qyvmzQQABx4yiiy/1SYjtcpjbcC1sRDLjlpBitzwS0vJFWKgwlDii+5hM6m63 +uxLvFwVLhLj7gpxEZ8h8jzYJVAiJfwlCI3JirUcAubv93RXSREutdSzctEiYxJwtfUz Zn/0Ws0hadSzgt6aITf8zjSRv0FTpTRz3F1FFBzFjhyEJHqxw2pR8Z285YAZrBjqmQ6N mrTQ== X-Gm-Message-State: AOAM532A/AmkjREq5hETFCUWVkmbWiiftZEUMFr/Wykj1j3FGHp3Z1uj +7hmv+/ovnOF9+qBfaTfr+3dUETnxOph4xzOWLC/vH5MGiNnqFHFlIb/bBoCLj2VMPqA6RFaNjX MG2NrBMm9ydLsP88y0zSxqWh+6rR3neVqP2vRqA3A X-Received: by 2002:ad4:482c:: with SMTP id h12mr7580625qvy.146.1592933551649; Tue, 23 Jun 2020 10:32:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGlAVIAW34+P9gTFNWRLySacL2byLAvv4gDqefbS0NC4OFaRttgSSPyylVwQESKEe8BLfU5Q== X-Received: by 2002:ad4:482c:: with SMTP id h12mr7580599qvy.146.1592933551379; Tue, 23 Jun 2020 10:32:31 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1562:8007::aac:44d8]) by smtp.gmail.com with ESMTPSA id u6sm1267636qtc.34.2020.06.23.10.32.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 10:32:30 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [bionic:linux-azure][PATCH 3/3] hv_netvsc: Fix XDP refcnt for synthetic and VF NICs Date: Tue, 23 Jun 2020 14:32:15 -0300 Message-Id: <20200623173215.346858-4-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200623173215.346858-1-marcelo.cerri@canonical.com> References: <20200623173215.346858-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Haiyang Zhang BugLink: https://bugs.launchpad.net/bugs/1877654 The caller of XDP_SETUP_PROG has already incremented refcnt in __bpf_prog_get(), so drivers should only increment refcnt by num_queues - 1. To fix the issue, update netvsc_xdp_set() to add the correct number to refcnt. Hold a refcnt in netvsc_xdp_set()’s other caller, netvsc_attach(). And, do the same in netvsc_vf_setxdp(). Otherwise, every time when VF is removed and added from the host side, the refcnt will be decreased by one, which may cause page fault when unloading xdp program. Fixes: 351e1581395f ("hv_netvsc: Add XDP support") Signed-off-by: Haiyang Zhang Signed-off-by: David S. Miller (cherry picked from commit 184367dce4f744bde54377203305ccc8889aa79f) Signed-off-by: Marcelo Henrique Cerri --- drivers/net/hyperv/netvsc_bpf.c | 13 +++++++++++-- drivers/net/hyperv/netvsc_drv.c | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/hyperv/netvsc_bpf.c b/drivers/net/hyperv/netvsc_bpf.c index 20adfe544294..b86611041db6 100644 --- a/drivers/net/hyperv/netvsc_bpf.c +++ b/drivers/net/hyperv/netvsc_bpf.c @@ -120,7 +120,7 @@ int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog, } if (prog) - bpf_prog_add(prog, nvdev->num_chn); + bpf_prog_add(prog, nvdev->num_chn - 1); for (i = 0; i < nvdev->num_chn; i++) rcu_assign_pointer(nvdev->chan_table[i].bpf_prog, prog); @@ -136,6 +136,7 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog) { struct netdev_bpf xdp; bpf_op_t ndo_bpf; + int ret; ASSERT_RTNL(); @@ -148,10 +149,18 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog) memset(&xdp, 0, sizeof(xdp)); + if (prog) + bpf_prog_inc(prog); + xdp.command = XDP_SETUP_PROG; xdp.prog = prog; - return ndo_bpf(vf_netdev, &xdp); + ret = ndo_bpf(vf_netdev, &xdp); + + if (ret && prog) + bpf_prog_put(prog); + + return ret; } static u32 netvsc_xdp_query(struct netvsc_device *nvdev) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index a33b088fda24..9aebae66821d 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1055,9 +1055,12 @@ static int netvsc_attach(struct net_device *ndev, prog = dev_info->bprog; if (prog) { + bpf_prog_inc(prog); ret = netvsc_xdp_set(ndev, prog, NULL, nvdev); - if (ret) + if (ret) { + bpf_prog_put(prog); goto err1; + } } /* In any case device is now ready */