From patchwork Thu Jul 20 08:38:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 12323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2981564vqt; Thu, 20 Jul 2023 02:02:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgyVdza4TJoNMTDW7OOfmPU1PmfqSTtc3EIBfY889QnYvqbvUI0/xZjwc7+re8JwkS7DgH X-Received: by 2002:a17:906:3f48:b0:994:5577:aeed with SMTP id f8-20020a1709063f4800b009945577aeedmr1769814ejj.5.1689843733517; Thu, 20 Jul 2023 02:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689843733; cv=none; d=google.com; s=arc-20160816; b=ILK0LYsn/qV9wED4lBX+qcRBlJ4Tga29gy03r+ug6xLhvDDeNPWs8YhLBq7bZtmvLg BiQxJb3YDcKgCmV1OHXcGxMF+qDzEus1bUCN9mV7X+pW+z2NyRKHFPeq89y0+cJT6Twd wHi03L4BBsAsm6KCryxjxaRSPiUOwj4orFm7PZI4VgZXisNX9xW7xT3FZ+qQfayS6SnP JoB3zLro4c7KgxMHbNB/MFLuiTKI7Pe8jqgEWNnM4o3Pfqm9kpB4Vi56HwtprrZszPhu ddCFSG6MaaRtvJ4JUsGLF7I7Oo+VLK58WEyLEHyeu/hnltBeKDZHErVsvF3gFU7Xsogn kpRQ== 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=uD8lCSCMjSGZH3wOzVWgkovAsvnWHdzdpIGokpNxVkQ=; fh=OJ7/iRsvElcEdO8PFPHhUuQuWW/5XTtWV3MPeONcTQA=; b=ljEg+2czhmDFaBn0QdBVf4KsoU67tnh3hQClDXymcSKXLiEm8SxAMUsxjMIA+98UL2 8ancLxgQg77ETSGPUHeaPH7bfVAAD/e2JlVlIRrIXhHMDGSP+ClUV44n0Ni56X7gP3uH 6H4UFUDi9mIXmU2hOrTFDcAdpEwFg2TYDaDwwKP0BU5jKpEkeh6zdu98KetPchtJF/w+ +VkkGvYwwErKHq06W/OWGFVIe7JzNLLVewbn6ETb65SBPQWCPvS9FRIazrF66taZWUPs DK8Vzx2vRAx+tNQ+kF7hCzTGGAPjQiPf5C5Ql2EPOWWxgC97cxAaGmtgaM2ua1eXTb4/ K4OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZL8pSSWq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a170906270a00b009945658c5b9si398770ejc.811.2023.07.20.02.01.48; Thu, 20 Jul 2023 02:02:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZL8pSSWq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231516AbjGTI7b (ORCPT + 99 others); Thu, 20 Jul 2023 04:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjGTIjj (ORCPT ); Thu, 20 Jul 2023 04:39:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DE3C26A9 for ; Thu, 20 Jul 2023 01:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689842332; 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; bh=uD8lCSCMjSGZH3wOzVWgkovAsvnWHdzdpIGokpNxVkQ=; b=ZL8pSSWqUAWmwgl/TRVir4n0vx9ZNfenxfVmUvxwxKqcloa31x/JB/3a9FM5wculs2f3m4 D/QELC6eNgAFHUMACq+wWg2PtBzjQzP+JMC1RGgAFgB0MSLGN4ffhRtHIGCtG9d00AVLYR rZ7kvFXUu1FfNwzYvh/G7J/q/5B7zb8= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-227-MUO2sSHNPdOz-BhsdqPtqg-1; Thu, 20 Jul 2023 04:38:47 -0400 X-MC-Unique: MUO2sSHNPdOz-BhsdqPtqg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4532E1C04B62; Thu, 20 Jul 2023 08:38:46 +0000 (UTC) Received: from dell-per430-12.lab.eng.pek2.redhat.com (dell-per430-12.lab.eng.pek2.redhat.com [10.73.196.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAEEBF6CD8; Thu, 20 Jul 2023 08:38:41 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alvaro.karsz@solid-run.com, maxime.coquelin@redhat.com Subject: [PATCH net-next v4 0/2] virtio-net: don't busy poll for cvq command Date: Thu, 20 Jul 2023 04:38:37 -0400 Message-Id: <20230720083839.481487-1-jasowang@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771929582445170536 X-GMAIL-MSGID: 1771929582445170536 Hi all: The code used to busy poll for cvq command which turns out to have several side effects: 1) infinite poll for buggy devices 2) bad interaction with scheduler So this series tries to use cond_resched() in the waiting loop. Before doing this we need first make sure the cvq command is not executed in atomic environment, so we need first convert rx mode handling to a workqueue. Note that, this doesn't try to solve the case that a malicous device may block networking stack (RTNL) or break freezer which requries more thought to gracefully exit and resend the commands. Please review. Changes since V3: - Tweak the comments - Tweak the changelog to explain the rx mode lost after resuming. - No functional changes Changes since V2: - Don't use interrupt but cond_resched() Changes since V1: - use RTNL to synchronize rx mode worker - use completion for simplicity - don't try to harden CVQ command Changes since RFC: - switch to use BAD_RING in virtio_break_device() - check virtqueue_is_broken() after being woken up - use more_used() instead of virtqueue_get_buf() to allow caller to get buffers afterwards - break the virtio-net device when timeout - get buffer manually since the virtio core check more_used() instead Jason Wang (2): virtio-net: convert rx mode setting to use workqueue virtio-net: add cond_resched() to the command waiting loop drivers/net/virtio_net.c | 59 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-)