Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2536172pxa; Mon, 3 Aug 2020 19:43:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDXElktgWfTZrVCROViDcI/z1KEI6vTFWvB0Njjt4LTeL3bNbLJTKnE77753UUC+Iq3npn X-Received: by 2002:a17:906:4bc5:: with SMTP id x5mr20428018ejv.177.1596509033930; Mon, 03 Aug 2020 19:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596509033; cv=none; d=google.com; s=arc-20160816; b=hrZ+sJv9UT9pMRfzqHz5DItsDGl3O0fA5X1S2xxBBiMVWxscUgZXHCn9ohcVqBw8Dx Jn62QQtyHe/P5f0eUSO9fRek8LryTqBQxq1huiHldNDxsg0e5/osK4Va9GC7KGb1nQXk gRg2tenZxxi/VDTOKLs9SPx23B9TvD19ronOYa/wpYRIvaY5l8Uud5GZ6NKBvTcPgnpX +H9UmvtaS4W70bKEH3CTrzClX+oWsvBJyWeit1/h2Zk3W/qOPeyiHjeRXjYxtcLz9iA5 XIIhKTgsglrIZ3kFJ2btXNRvFeS1AqCNvQL6t8Um3DOAGDLpc25hI86jaibYVt+uRZtP t8tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=hp9A97oTrVOTq0PRhFxZTZEQWhgsYnn8g0JTZalBa94=; b=qkOSrXniaXO0tpQlb3QApBx1lTXLDWPXbfi8aCnzIyzWthDhrtacFQA79//qyp11JR i5x3DaOs2sVDO4WhdteT5CXS5HyzgP8mtvHN76iqf01RsBaAndYLpq4nJRTQlEdrrE3V cC/Ozvs+kJIkPvGyDU6iX28fX8FbVYJhIiUgrJmffm7q1YNFi00YrwiCrP9Lld+LUw8W G5wYXJZ06w7FOIEULZZ4bUUDFl+zELlUZ8EiwDBXw/fiv/tIO5JRfSENseOfd4SLYOfj Btcvo4Ps/TusNimZrGymGFQfFjeykcEoGTj3BdlROXpyyZYflLrcPdazfe7EAVStzuSZ vKTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="D/jKRpVM"; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z3si11394408ejx.477.2020.08.03.19.43.31; Mon, 03 Aug 2020 19:43:53 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b="D/jKRpVM"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729861AbgHDCnX (ORCPT + 99 others); Mon, 3 Aug 2020 22:43:23 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:34474 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729850AbgHDCnW (ORCPT ); Mon, 3 Aug 2020 22:43:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596509001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hp9A97oTrVOTq0PRhFxZTZEQWhgsYnn8g0JTZalBa94=; b=D/jKRpVMIVOP+sN9yDOlJRvVzb4ZVElYDTY1H31xhFFPFjf4KyrD37wLrSDarYg0qdWUYa JL6RS7rBRbI14nxN1W5MV1Ku9/Iv3lhSBVpZVZvbh1654u+h80LkVYctmKyIhoh4GPqOIi n1m3pv3z5ky2NjKYGGJ5feA8XRz3/rA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-FKQ4etofOjOF5d755bXmuw-1; Mon, 03 Aug 2020 22:43:17 -0400 X-MC-Unique: FKQ4etofOjOF5d755bXmuw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 437248017FB; Tue, 4 Aug 2020 02:43:16 +0000 (UTC) Received: from [10.72.13.197] (ovpn-13-197.pek2.redhat.com [10.72.13.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id A176E7852C; Tue, 4 Aug 2020 02:42:57 +0000 (UTC) Subject: Re: [PATCH -next v3] virtio_ring: Avoid loop when vq is broken in virtqueue_poll To: Mao Wenan , mst@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <20200802022549-mutt-send-email-mst@kernel.org> <1596354249-96204-1-git-send-email-wenan.mao@linux.alibaba.com> From: Jason Wang Message-ID: <12bf457d-1283-62c6-6901-29e7a14831ca@redhat.com> Date: Tue, 4 Aug 2020 10:42:56 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <1596354249-96204-1-git-send-email-wenan.mao@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/2 下午3:44, Mao Wenan wrote: > The loop may exist if vq->broken is true, > virtqueue_get_buf_ctx_packed or virtqueue_get_buf_ctx_split > will return NULL, so virtnet_poll will reschedule napi to > receive packet, it will lead cpu usage(si) to 100%. > > call trace as below: > virtnet_poll > virtnet_receive > virtqueue_get_buf_ctx > virtqueue_get_buf_ctx_packed > virtqueue_get_buf_ctx_split > virtqueue_napi_complete > virtqueue_poll //return true > virtqueue_napi_schedule //it will reschedule napi > > to fix this, return false if vq is broken in virtqueue_poll. > > Signed-off-by: Mao Wenan > Acked-by: Michael S. Tsirkin > --- > v2->v3: change subject, original is : "virtio_net: Avoid loop in virtnet_poll" > v1->v2: fix it in virtqueue_poll suggested by Michael S. Tsirkin > drivers/virtio/virtio_ring.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 58b96ba..4f7c73e 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -1960,6 +1960,9 @@ bool virtqueue_poll(struct virtqueue *_vq, unsigned last_used_idx) > { > struct vring_virtqueue *vq = to_vvq(_vq); > > + if (unlikely(vq->broken)) > + return false; > + > virtio_mb(vq->weak_barriers); > return vq->packed_ring ? virtqueue_poll_packed(_vq, last_used_idx) : > virtqueue_poll_split(_vq, last_used_idx); Acked-by: Jason Wang