Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1250891pxa; Sun, 2 Aug 2020 00:47:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlzPt6UF8YMm30+nwNtiN87Ye01vhzkBtE1WvOzi0xkBid1ZHYWPTcUa25jH35oPIvrR0G X-Received: by 2002:a17:906:840c:: with SMTP id n12mr11068774ejx.246.1596354470943; Sun, 02 Aug 2020 00:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596354470; cv=none; d=google.com; s=arc-20160816; b=PpgHjvVzgCy/gFXXiSM+bBopp/aZXcQvGw9YpcTmvQZw+SfPQE8Sl5oTENBAdHp/N6 BpiqpAha3EMxJPH/2fivjZ1ivTEWoptin1of+JX/aqyLLvXI1KSwJdzBt1wyk6mQbOTG hPJUWhrNIxAl3cN+/iTg10voGTTkP1wcwTqUln7Dx9wDJWviup1Kbf6e1sudxv3ExOJO H+vphMglefc5xakgdFQ8aV3Zwhk0D5RfWE4AvcbZWz7hUK3W1ttG5EESeOINi1P3956Z 2j1Gw39EIPxtWhrZQx7TCJJasfwrHr9+LunxmYKcFaGrV5rLOWtUQP+uL80A9M0bRtP2 ty3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=IAgVj0gXYVlaTXq8SEgomUr4lSOaHoJ0eJTu6co3MWs=; b=wr7gDCHS5W8mJRqbYxGookO6NMbIf0rhZJuf1iJj/aPf4EnyVHYyuC8mXFCXXYUPPT mF8c+ALkniInlAOjPEx7+imum0Pc0/Wy+RabaXi0tCaulOM2BzSEUaAhAcBxguznbdT+ z8PCRpbLP7BMhzMAibx8UFh/OcKlMbnUiAvHpm53Oly9jEIm8jHJJI0DC0FTjH9wGdkE 9XydcKYAXnqqKQbeyzv618me6Ei7DW1TeaFsIW0Hnh1oh7PgxfFoiLXYzF7XRfgiz6L+ w+Fe/OeQcnNlhmgsON7Xrpo+1XI35TMMF7CR+ScWnoHwBShW5N3RTSPl8amCx5jfInwB UFXw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l12si9067461edk.328.2020.08.02.00.47.28; Sun, 02 Aug 2020 00:47:50 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbgHBHoT (ORCPT + 99 others); Sun, 2 Aug 2020 03:44:19 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:47074 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgHBHoT (ORCPT ); Sun, 2 Aug 2020 03:44:19 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=wenan.mao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0U4SKUq2_1596354250; Received: from VM20200710-3.tbsite.net(mailfrom:wenan.mao@linux.alibaba.com fp:SMTPD_---0U4SKUq2_1596354250) by smtp.aliyun-inc.com(127.0.0.1); Sun, 02 Aug 2020 15:44:16 +0800 From: Mao Wenan To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Mao Wenan Subject: [PATCH -next v3] virtio_ring: Avoid loop when vq is broken in virtqueue_poll Date: Sun, 2 Aug 2020 15:44:09 +0800 Message-Id: <1596354249-96204-1-git-send-email-wenan.mao@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20200802022549-mutt-send-email-mst@kernel.org> References: <20200802022549-mutt-send-email-mst@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 1.8.3.1