Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp83753pxb; Mon, 1 Feb 2021 23:11:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgxSzmNG20EzEQcOZD761fX4szSLcG+jBg7PCIWuSt2n/xMZ1TdVsdPW4/mUnZkVpHyrqB X-Received: by 2002:a05:6402:1642:: with SMTP id s2mr4002382edx.360.1612249893028; Mon, 01 Feb 2021 23:11:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612249893; cv=none; d=google.com; s=arc-20160816; b=z5JpF66Z+Y9NVMOB9l8fLlh1iZO5D2JjDKrQkGRRMdzbtmdkTkgOUK40Q54KDQvuVE Z53c0BDbkyt4OYF0V5qABBHxXbXqPIJIrW6ISRhT9eRvPTyMsBm5ShjsmBtcXUcDGt8p Ult4nkaWGmjz0M2ccNJ3hXtNNGIfEB/mL3yiPlby//bZsDLc7BFpSwug9CEMdO9ZU4XY LM5L+johXLMqo0Ois0ZG18trcg8GXV4Lkp1iczsefgWD5+F6/L4dEbKm68J67OyVQbsx gikWUbfb1RutUI5cpDpzrsRvQDhdnG3MTcC96kNnuy6Uc9qE8pAuINR8jkmfFjtk4UvV qnIQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=1tpaqvOitmoTdUOKCltTkXQMrQMduhfR/V/K0TJ91jk=; b=DKKOW/okPK4wlejEgQD4DsQ0AZJb+RzdCQm5zsA/a/Fyk9mY7gP45/1XEj1rIBMBSJ nSEXD4QSP6RIyHHZYE/e1i06Q/WcNKIit/bxvCRI650U/l7zRgtBnKDtUP7JPGR2A0sO KEWHQ+SCRMiB7VdujKjnQH6Kvi3qbSE/YsxJ9BMoEIcOAqY9NOv7XI91nxjl1bxLborq BQOEgAfh2dYn8S62w7zrbrak7Yltxc2Ad18nHeceYQGqeA6KBbc8bjvbXbY5JVGrvjA0 j8GeqFkzgho2IuiQRDSvV+Nhns0ozXTfZpPY+w0XvioNrWjHIUGltqWLkle2uHDcnuSP 7oFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pbaIptID; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 16si11904682edw.253.2021.02.01.23.11.07; Mon, 01 Feb 2021 23:11:33 -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=@suse.com header.s=susede1 header.b=pbaIptID; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231445AbhBBHKd (ORCPT + 99 others); Tue, 2 Feb 2021 02:10:33 -0500 Received: from mx2.suse.de ([195.135.220.15]:58388 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbhBBHK2 (ORCPT ); Tue, 2 Feb 2021 02:10:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612249781; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=1tpaqvOitmoTdUOKCltTkXQMrQMduhfR/V/K0TJ91jk=; b=pbaIptIDBcZvfobat6HNoXje6mR3kf8+MuWpibPjXaHBmoQvt3LBZ1S4k+WfN+6v3yXqqG CnLh7G8uXWy5d/2yQhTslehE4QmbeheYR1UmRM7pfxMgd1ZiuvafUH6s9i4k7bnpbVZHHm wGiaWxu3itzFTHNe0z01xg0UqKte3eQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 46D2EACB7; Tue, 2 Feb 2021 07:09:41 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Wei Liu , Paul Durrant , "David S. Miller" , Jakub Kicinski , Igor Druzhinin , stable@vger.kernel.org Subject: [PATCH] xen/netback: avoid race in xenvif_rx_ring_slots_available() Date: Tue, 2 Feb 2021 08:09:38 +0100 Message-Id: <20210202070938.7863-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Cc: stable@vger.kernel.org Signed-off-by: Juergen Gross --- 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 b8febe1d1bfd..accc991d153f 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.26.2