Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp520173yba; Mon, 1 Apr 2019 10:58:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzeXvsb0nPIYjU8Ydr/lpmRqfquyBsfe5XLF4mIp33cZjxeRk9+3WbS/oINpVFaWazuUp9 X-Received: by 2002:a62:5797:: with SMTP id i23mr63516384pfj.12.1554141480200; Mon, 01 Apr 2019 10:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554141480; cv=none; d=google.com; s=arc-20160816; b=y3n8G0nXZBxC+YGnFd8S3D+fsbx5KEI8SL9JwG2lVlSjQ3LWQUNRoC0Ogu2BJds6FE BZIr5WYhGIqC02VjdZmb742fAHjujS6PpnQDt2VqrRIx6+VmKWj4K/+ZQKseFGjTv6J8 v4w4KwnkO7MqzYppcRe3zcRjpYxqey8WUK/HMvPBOlejx78IDyKmT9nhjIeSEzpK5ny5 MzqFpf9vI1FccEYOUsi9Vg8qMH8jbU4i6Aci4bXfvIozPvbHThSdCvCVAeWbq6APo+sH Nj/dN8Wm0CXgK4Utex9GoWLFrUNVztUXy1DkfA1BT23dNzz7x7SvZLhKOVn+wZZP1Ied 81vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wkkc4zh//sTODfRh8i+4OvPiILHqbHsCvB8sht4trBY=; b=fsfjEzh228GlPTqnTtaUZO+pmmPfAkqTN+YEhVh5Yoj+02GNch1tJzUOghj2lngWZW 0NLhP/CHWyXahSIYWqIMcr/zZ33O+we9vXxXjDQ84mlMzrimo3w/IwaTZu+uesBuTqrl NJHp0FOxkVXKfB8rqwTm4sSCcq/hFyxm2j0vp5zLg15d0zX8LGesa4IxknmH0D6qlXUZ Pr2hEK69FwPQ68fGVTz/iM6Y2e1oO6LNsgG2Ucuo/a4zxuluDZzvvrhE/0f7SkWzoV2U +n8vT8lYBNbeGfuVTUS+hEt/U8bSKG3W3hiZdB+fjexQBLZ2ycGsNu3vGAH7NSKLF+l9 VUoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0cRVueU7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si8892831pgp.463.2019.04.01.10.57.44; Mon, 01 Apr 2019 10:58:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0cRVueU7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731677AbfDARUj (ORCPT + 99 others); Mon, 1 Apr 2019 13:20:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:48846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731667AbfDARUf (ORCPT ); Mon, 1 Apr 2019 13:20:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 13769206C0; Mon, 1 Apr 2019 17:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139234; bh=oegOK+2NbcsPCK/XnFVpp7o/4T1vFqZUoSvTIoqu6gs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0cRVueU7+xAl1LBouVq1V0uD/0JMmEpcsseuy5zIpusALGjPnB3c1474luQTAIvts gmBa5dYTD1qZH5GUUsvCfBBOZ76vQwo+espYaSf/eXqEawSA8brS6gHQMs8EFeOXXo 3hFITgtVwPMPInc3ea4rI0IJyirIIVRqzer3VfVc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dean Nelson , "David S. Miller" Subject: [PATCH 4.14 017/107] thunderx: eliminate extra calls to put_page() for pages held for recycling Date: Mon, 1 Apr 2019 19:01:32 +0200 Message-Id: <20190401170047.064445862@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170045.246405031@linuxfoundation.org> References: <20190401170045.246405031@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dean Nelson [ Upstream commit cd35ef91490ad8049dd180bb060aff7ee192eda9 ] For the non-XDP case, commit 773225388dae15e72790 ("net: thunderx: Optimize page recycling for XDP") added code to nicvf_free_rbdr() that, when releasing the additional receive buffer page reference held for recycling, repeatedly calls put_page() until the page's _refcount goes to zero. Which results in the page being freed. This is not okay if the page's _refcount was greater than 1 (in the non-XDP case), because nicvf_free_rbdr() should not be subtracting more than what nicvf_alloc_page() had previously added to the page's _refcount, which was only 1 (in the non-XDP case). This can arise if a received packet is still being processed and the receive buffer (i.e., skb->head) has not yet been freed via skb_free_head() when nicvf_free_rbdr() is spinning through the aforementioned put_page() loop. If this should occur, when the received packet finishes processing and skb_free_head() is called, various problems can ensue. Exactly what, depends on whether the page has already been reallocated or not, anything from "BUG: Bad page state ... ", to "Unable to handle kernel NULL pointer dereference ..." or "Unable to handle kernel paging request...". So this patch changes nicvf_free_rbdr() to only call put_page() once for pages held for recycling (in the non-XDP case). Fixes: 773225388dae ("net: thunderx: Optimize page recycling for XDP") Signed-off-by: Dean Nelson Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/cavium/thunder/nicvf_queues.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c @@ -364,11 +364,10 @@ static void nicvf_free_rbdr(struct nicvf while (head < rbdr->pgcnt) { pgcache = &rbdr->pgcache[head]; if (pgcache->page && page_ref_count(pgcache->page) != 0) { - if (!rbdr->is_xdp) { - put_page(pgcache->page); - continue; + if (rbdr->is_xdp) { + page_ref_sub(pgcache->page, + pgcache->ref_count - 1); } - page_ref_sub(pgcache->page, pgcache->ref_count - 1); put_page(pgcache->page); } head++;