Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp256163iog; Wed, 29 Jun 2022 23:35:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u3lAeLrW24SuFf8X0by8y2Hs+ph2qzUqv798piiEOKgaZzuFILcWK5vlrIAr8QQ247fVHU X-Received: by 2002:a05:6402:405:b0:433:426d:7d59 with SMTP id q5-20020a056402040500b00433426d7d59mr9645467edv.122.1656570932795; Wed, 29 Jun 2022 23:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656570932; cv=none; d=google.com; s=arc-20160816; b=qAJ5c96E4vvgLs3FazYIejROPKWFEAH6r7iXFfyaVxN81Ymec+37MimtVSPvfUbw/Q 0mD/BdJpiN6EI2HGc7dtO5w32uNtDsr/J0EulzlXjWcEa2mYMoyNNBOJcmzhBNBuu7j0 oGUeIjEjgRnLcixstStFmYxU+uutsu0//JTcUD2bDLy4WH/n7I8IIMVa5XprvEkMcX6c IZu/Ws6wC5PSEsRKK8YVajJ+fqST5fW6hVcDNj10ZC+spDOo4LUHtaSllzqTtgzcVquB fIcIA2Uo85vAXZD2jLWurYDFzzWdpxIs7f3c1NvO7kTbWvRzD4Xxa3ZPQdpsNeczOuUW pR0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LIyFvGXQvIKAI2Jhy0fL/iiZlXHvPxpCNakI+DBgKxw=; b=duOzHbiUzHnNeWr4/zHL7RVp3OsPRrr30AmZHA0a/pv07+fvJysD46HrR/r85nRWkh 8oFceclOd9t3gsehQq+q80G2IQlTHuj+vGB/xBxkIBpXBDIU5apeIxXe+tqqZe8viZkI HzKNqo0dshL7qe32gOVJ4jeNTVjkQao1J4YrqNz9jCgzHF8wo3IPdg/vfPUAS6VXLDx4 /h8N/EtBcxSjlK7xLZlnRdMcc0qM5xdzlQYheHgrNT+2vwIKGMXt0/Vct9i+kdxJmEeV rXYP5M2gVedYH5tR7bcmgTdohEGmD68nJ+hLBt3xjEzLdlEqiy7FTxngJNksxBYqJUEN pNDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Oj5hDNo4; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb13-20020a0564020d0d00b0043587e6b472si2772835edb.132.2022.06.29.23.35.07; Wed, 29 Jun 2022 23:35:32 -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=Oj5hDNo4; 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 S231690AbiF3GPw (ORCPT + 99 others); Thu, 30 Jun 2022 02:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiF3GPv (ORCPT ); Thu, 30 Jun 2022 02:15:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8395D17A96 for ; Wed, 29 Jun 2022 23:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656569749; 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: in-reply-to:in-reply-to:references:references; bh=LIyFvGXQvIKAI2Jhy0fL/iiZlXHvPxpCNakI+DBgKxw=; b=Oj5hDNo457W+uKz6jL4UmZ4Tfm2xgjOWQhPjbwYKStXi+Bd8ABZLFiHBxS5muFhfDYE0TM 1T2FFAA25TLAz6zQbug5N4ZuRFH48/7owz4IX5nvAAPUPn1cNkzQ15jBjTZQV0Ej79qTAl UrwGkh3GdWJZyZmV9l0qcwMB87wXv4Q= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-498-JPJNM5mFM_GCxKw2801UxA-1; Thu, 30 Jun 2022 02:15:46 -0400 X-MC-Unique: JPJNM5mFM_GCxKw2801UxA-1 Received: by mail-lj1-f198.google.com with SMTP id u23-20020a2ea177000000b0025baf70f8a9so2394783ljl.3 for ; Wed, 29 Jun 2022 23:15:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LIyFvGXQvIKAI2Jhy0fL/iiZlXHvPxpCNakI+DBgKxw=; b=xlBdqhdbQQ3qoAFAljWNtkCzKNNyxV+Zuz0SpHnwJtXryrhIpFqswf17PgwDjOBVpj b14LxQ3sqgczQlPkzSc3kE9xW2K6ojN1iM/wdyaS7rfdWtA5TdstoaDfZmd26Xe5l+4s Rkh2SMJkdbdifzSBDMuh25N7GhK0s0eCRkPQPRtxiTxKdRoXx6tr5UUKH1NRJHTNBH42 43zJUXHmERS6PsBXSS3RIr1lFHIcs0Z17db1pFndpxOL7B/VWNtxxtxzlvpyHMPdeUVY XOgJ5txApJny8EQmgX5Rfy4YbQ+aM3msi8lOXhJLFl0iv7mGiUD61BS+P6YGRsI3vZXU zWIQ== X-Gm-Message-State: AJIora+wROJekfHagCrO0sRCuwG1okMfGSYbQGEw7/Px9AE2ZbbOdhLa IN94WwA9/QwZXnroGNWeDyGWc6g4+FN7buy1lvkJ1qm4Z5HBnPKuJwpf+RRlJcjWciJW/Iulnug o4HlfumDnBzM+y6LJ979HinxszBDEQHGl9ZtiZNyT X-Received: by 2002:a05:6512:3f0f:b0:47f:6f89:326 with SMTP id y15-20020a0565123f0f00b0047f6f890326mr4399320lfa.124.1656569745187; Wed, 29 Jun 2022 23:15:45 -0700 (PDT) X-Received: by 2002:a05:6512:3f0f:b0:47f:6f89:326 with SMTP id y15-20020a0565123f0f00b0047f6f890326mr4399309lfa.124.1656569745030; Wed, 29 Jun 2022 23:15:45 -0700 (PDT) MIME-Version: 1.0 References: <20220630020805.74658-1-jasowang@redhat.com> <20220629195123.610eed9f@kernel.org> In-Reply-To: From: Jason Wang Date: Thu, 30 Jun 2022 14:15:34 +0800 Message-ID: Subject: Re: [PATCH V2] virtio-net: fix the race between refill work and close To: Jakub Kicinski Cc: mst , davem , virtualization , netdev , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 On Thu, Jun 30, 2022 at 2:07 PM Jason Wang wrote: > > On Thu, Jun 30, 2022 at 10:51 AM Jakub Kicinski wrote: > > > > On Thu, 30 Jun 2022 10:08:04 +0800 Jason Wang wrote: > > > +static void enable_refill_work(struct virtnet_info *vi) > > > +{ > > > + spin_lock(&vi->refill_lock); > > > + vi->refill_work_enabled = true; > > > + spin_unlock(&vi->refill_lock); > > > +} > > > + > > > +static void disable_refill_work(struct virtnet_info *vi) > > > +{ > > > + spin_lock(&vi->refill_lock); > > > + vi->refill_work_enabled = false; > > > + spin_unlock(&vi->refill_lock); > > > +} > > > + > > > static void virtqueue_napi_schedule(struct napi_struct *napi, > > > struct virtqueue *vq) > > > { > > > @@ -1527,8 +1547,12 @@ static int virtnet_receive(struct receive_queue *rq, int budget, > > > } > > > > > > if (rq->vq->num_free > min((unsigned int)budget, virtqueue_get_vring_size(rq->vq)) / 2) { > > > - if (!try_fill_recv(vi, rq, GFP_ATOMIC)) > > > - schedule_delayed_work(&vi->refill, 0); > > > + if (!try_fill_recv(vi, rq, GFP_ATOMIC)) { > > > + spin_lock(&vi->refill_lock); > > > + if (vi->refill_work_enabled) > > > + schedule_delayed_work(&vi->refill, 0); > > > + spin_unlock(&vi->refill_lock); > > > > Are you sure you can use the basic spin_lock() flavor in all cases? > > Isn't the disable/enable called from a different context than this > > thing here? > > This function will only be called in bh so it's safe. Ok, so it looks like we should use the bh variant in close. Otherwise we may have a deadlock. Will fix it. Thanks > > > > > The entire delayed work construct seems a little risky because the work > > may go to sleep after disabling napi, causing large latency spikes. > > Yes, but it only happens on OOM. > > > I guess you must have a good reason no to simply reschedule the NAPI > > and keep retrying with GFP_ATOMIC... > > Less pressure on the memory allocator on OOM probably, but it looks > like an independent issue that might be optimized in the future. > > > > > Please add the target tree name to the subject. > > Ok > > Thanks > > >