Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp478479yba; Mon, 1 Apr 2019 10:06:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCaTvOm2NiKSIj5Vicg49GhbbW+KrI18yKtV7yLEd9N+7j+HETQRZ3JeRZjy+w3JWat3Yq X-Received: by 2002:a17:902:8a4:: with SMTP id 33mr64053730pll.7.1554138390658; Mon, 01 Apr 2019 10:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554138390; cv=none; d=google.com; s=arc-20160816; b=e3n3oIOv4419/FJEd6aiiO0O0Cfd/Jt6Ysx+PPivNNNHFsZ5QNViIcMGmIHfzmbmsf ckCx9s9LyWqBUoST8H8Ag6WLzg66/qC3jfjMpidHcm48ZL/8thrxn8Ddj/+M3y5RVKuv xYZdb+LGwsoa9Z66vEBTQfWJgTMNditiFDc6UjIwpFKsk2zXgeDjIipkH192T7dRvXCL sl+2wvjGPFIKci10ouNvrCAkgeBKzTAth6oRXegJiwwuu0ljNtnBxZkc6LCELxtSMSUw JChc2lmZmIWjetYSzTGXM3xPrBssIVK96NPLQjXXlrIqwOcL4haNKPk7jeSdLKDK6tiy Dr4Q== 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=ltCn8y2cgZtCEpFfpInMNlQWuQjE/dBBIVx4S+JzVq8=; b=0BK8g63hPeqcD2EWWxGQRM9QpGSCecVAf4iPqrbCBPVBXtSZM79yLe57ttpB0p8v/x zbs2w6i6VCuGGBd2ejcHHQf2t94qHDjFKR1Kb9igxPvSb0Br7w+xZZsmBVV8hXf5YvN6 wC8KDzEhV641psIL5Wzw6aq18NE4WTUE/QYq8iHleWMnMX3FgCD7EvdiVzAl/a9lIQvf P0XeE/gEF6m6LZP8L6MhkV91AYZaAiYEDBOLbLaZ+Hbrf4+ZKsDpxrRa6oHkELkpVNmq fpVX3nGhH+IPX4IPEZIwYERfct64fJfdgPVpXgjbxiI+V/91iRqQqoZL2jLhZlOjt0aC 146g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="avu/D9QZ"; 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 b16si6151836pgb.501.2019.04.01.10.06.15; Mon, 01 Apr 2019 10:06:30 -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="avu/D9QZ"; 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 S1728912AbfDARFR (ORCPT + 99 others); Mon, 1 Apr 2019 13:05:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:50332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728731AbfDARFQ (ORCPT ); Mon, 1 Apr 2019 13:05:16 -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 8DC3A21925; Mon, 1 Apr 2019 17:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554138316; bh=x5BRezBiPtxQGQDUXshgssybnj4dcrJVEWmJ4nXCKMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avu/D9QZL4bhzk62DkTc2V861I68tP/YhZvxsBfhRBrB78W2Y5MA86fN+t0ho6DOA Eaz4G5q038awN26Tlb28Aoh1n+xIHamtR8+TlhEUWfBEJKWf3CENhenBp31XB9StsY WYnMCi6G82HFGcKcx31EwsrxxLD5QvbOb1yJnJjM= 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 5.0 030/146] thunderx: eliminate extra calls to put_page() for pages held for recycling Date: Mon, 1 Apr 2019 19:00:42 +0200 Message-Id: <20190401170051.085412279@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170048.449559024@linuxfoundation.org> References: <20190401170048.449559024@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 5.0-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++;