Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5030900pxb; Mon, 15 Feb 2021 07:47:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtxhO0ywWK4h/P+Ar6u7H4MfVciMLTwgzh3ZwoJhdQWRR7pIGyelOrd2gxMY3fAJT79oeg X-Received: by 2002:a50:8466:: with SMTP id 93mr16276912edp.55.1613404049310; Mon, 15 Feb 2021 07:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613404049; cv=none; d=google.com; s=arc-20160816; b=VNte9phlOhUVxEeqrU3jBtyYOeZIgbLQbc6impW+v8SEVl63fenlbXxCca41raSIHG 2+z4nruo9IPj0mWKjdif+iT+CWWTuYjdNP8nUM81l8Sn5GKdxrfcLCkOGkPnnsiRojV0 fbDi2TxtRcrXhIH80neAcy3EXJDCM7bJqNewod3lXpg7HdOmfQuwIn3S5ZcG1nXnZHQU ZwLpQCD0qwbeXkNAgXG1qeptEH/Mj4cMhcrcCxD9xukzFpQgWLfW3ik2AOPODFJ4Lgv5 BIE87G1Z/hkZSPqT6flVZWdNWdqeGas1ETUdYRQ2XSY/H9zRHCmZyQax3Y5Ahueryy9K KWrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3g4ZCgMoCjiNMsFfcUhptm0KHn08gSoEFRAj+6omJz8=; b=028h1awPvLmIg9LWxWa2ihLsT73ob1jNd0UbBdDS2QsDXUygfV3DwXFnkVQgeVAbGd 8VD4+tdj1AQ6ZSEYskC507Dai4qb4WEIXhoYh26eWwM/1RKJGn+eYujWg1Qo1yKqraat pkh4cUPEGZEEFkxqJtCDfwqC4K7/p/qtZkVWFWmdqZA8aLWN7Tq9sm2NBzlpd5/32jez hHpsBH4atuLsTcqv6Np9OBWzwzVncYpqPDBaAj4VJ2c+VjwAhUCLEYb0Bdw9rm2zl7ds p3BgY4DCLjhr8zsiMaHjf8gf3J1GgJ5HDlz16USH4eyAb7cxUKgyrBk9ojGDYNfCg6yT jhZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h02aODN+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si14347285edb.260.2021.02.15.07.47.06; Mon, 15 Feb 2021 07:47:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h02aODN+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbhBOPqP (ORCPT + 99 others); Mon, 15 Feb 2021 10:46:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:45590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbhBOPbL (ORCPT ); Mon, 15 Feb 2021 10:31:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 74E32600EF; Mon, 15 Feb 2021 15:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402954; bh=h7ECxo7KSLQ+Cs+Nn7UsuDUa/mR25ezkyhmT5TaHxAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h02aODN+h1ZytJK5tx0/bx1VDZOU94pt9dFLb5N+xu0XcGVN+vzKly66mfbxFI2DN eN17lkAbWF+bdw+uUhe3O+oqmT5V56tdor7LGFCQBZFvoYr70uTIASnfRRRzH8dhIj lxMgI4Zlpb7PyrCvBbTnD9aPbtekn1cVjTsi0OIo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Igor Druzhinin , Juergen Gross , Wei Liu , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.4 32/60] xen/netback: avoid race in xenvif_rx_ring_slots_available() Date: Mon, 15 Feb 2021 16:27:20 +0100 Message-Id: <20210215152716.382419020@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross [ Upstream commit ec7d8e7dd3a59528e305a18e93f1cb98f7faf83b ] Since commit 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") xenvif_rx_ring_slots_available() is no longer called only from the rx queue kernel thread, so it needs to access the rx queue with the associated queue held. Reported-by: Igor Druzhinin Fixes: 23025393dbeb3b8b3 ("xen/netback: use lateeoi irq binding") Signed-off-by: Juergen Gross Acked-by: Wei Liu Link: https://lore.kernel.org/r/20210202070938.7863-1-jgross@suse.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/xen-netback/rx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/xen-netback/rx.c b/drivers/net/xen-netback/rx.c index 9b62f65b630e4..48e2006f96ce6 100644 --- a/drivers/net/xen-netback/rx.c +++ b/drivers/net/xen-netback/rx.c @@ -38,10 +38,15 @@ static bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue) RING_IDX prod, cons; struct sk_buff *skb; int needed; + unsigned long flags; + + spin_lock_irqsave(&queue->rx_queue.lock, flags); skb = skb_peek(&queue->rx_queue); - if (!skb) + if (!skb) { + spin_unlock_irqrestore(&queue->rx_queue.lock, flags); return false; + } needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE); if (skb_is_gso(skb)) @@ -49,6 +54,8 @@ static bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue) if (skb->sw_hash) needed++; + spin_unlock_irqrestore(&queue->rx_queue.lock, flags); + do { prod = queue->rx.sring->req_prod; cons = queue->rx.req_cons; -- 2.27.0