From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22E562D6E73 for ; Thu, 4 Dec 2025 15:08:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764860916; cv=none; b=lY/bGy3ZeXBxxluyrGyN6Mp8mCdpJVQ0vdjoXU78w+LxClNsO/tj/b1oani/v28C1Rw4DTMYcgVb27dWSlHvUg5Ea+KFP/Xg+CgVdVjfqusu9YPHlBPVYtvmiK73a21lRNOOTvLWZ0kbKSULrfXDYX5GG2hG0KIqvgUO9HyHBvI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764860916; c=relaxed/simple; bh=mow+fg3+RlIbDNumBSEnGyZekiI5a4ukShUjLnnu0Js=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=IrnMfK9yvrZUovi3Oj9l7uADJPrG1hN4LwxIi1sSirNSKK0dd+E3ZxwzjNp4aqpKdeHD7sbv8J88Ge9NiufyH0MXxIPuZhoGdm6Cu8euDgpzCEeVxsvr7Xuwqjvd8pw3JoqOs/kUx/DpvuoRVZ3ZaT6KoZ4EaQ72gqb0pdRs29c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EpJY+GbT; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EpJY+GbT" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7aab061e7cbso1178373b3a.1 for ; Thu, 04 Dec 2025 07:08:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764860913; x=1765465713; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=t1iqQ0ov45xjnCibqFJmGxUgMKunIGbHn1CsgPvUOa0=; b=EpJY+GbT2GuIEWdtU0ZHL742loWruVKtuTyFoCR8XRNym3OZBw4Yk5zRe6sd7P8XME 1NLacDQsksq4E1UckNBW7dbFes5qLwbXNZsmrhPIDkAs3uUhapi9Syd30ucWM5N80u0S yab9GrQboMOSjBO4dSaLOpKaS9St1IZcKFadd9azjKPFWQE98mFYJ5u2aIm715Hm+yHJ NuAICmdYffQudeH8KmIOFwXXGS8/UbcrNlncWZe1nLHdJ84Fy+7a7TP7zjjoM2k3z971 j/lq5R9MBymtH2gcTwy6ZOdY4dyVMBGGMCEwA15RBG65EZ0veXzKfx5lqTg+clEpFicT xQJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764860913; x=1765465713; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t1iqQ0ov45xjnCibqFJmGxUgMKunIGbHn1CsgPvUOa0=; b=FH52/z1Jkf02l8MtwPH9PdSLoj07DxOtIF8lIzpdtSwNZmbA2P7H9EfAG71ilQRN5i xcy/JXrsY/y62iABCDFxhnNsjaCsbDAvb8qMLKlFI/ArEAJBUC7d1RZ3Peb3WZdAbPh/ Mt3SesfxQ1PR0apO9zIOebMhI8VsHpG+USqG8suiEhm+Eyzv+L0+4cltkZs3d8uzLK4S deUj/QVl6+8KAcl2SGjz5UBotF07n3LGhzr4spWP4CNQilz/lmfTDgJQbmiOATICiBs2 O9jHnn0HKEfu8+0UDgcIHWsQCfsOT1crK/ZmFpGy4D6K/y0D8T+wOV1F2A4F4XvJGY24 fyXw== X-Forwarded-Encrypted: i=1; AJvYcCVSKDvCFQG6x6avlgDO376pI1m1tPtjuTRGCL1obbve42lXZp99jquddh1JY4AIgIciEpXQ/JX8nxt+lAU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+4HQVjX6T4sd9jcl78mwXTSUjtAagauAuCFxn+buG7PtY9uql GqBaQI9uMtylwjpr2bX0f9UpM7S05UA4yDRaOsrw9G+8wT0ci7o9SuoZ X-Gm-Gg: ASbGncteuq8Im/EuCEJPWnatqT0yYN0cfd7LXIkmcnzky/ucsyrAEMfjUlqZiWbbqw9 MaA+Oax4Z1fK67dUNiRw84M0ev0KB+2Q55Hnfk7lByIBLmREzbYdcZ9oYAbLXZQ3bclX/QIiEnK ObQfdswSvnWmUCBiVKt5jaXDImeuNNyzphDUXeJTisf1D1ZY+FvWeo6CZhOFXTNU5SU8YM5zUjB P/tGcCGXXMVuaSthhh5oHLeSX2TNRDCb2X6t169xHbbGmlcJyD1usKDxFqjkE2SpVxlAbjlsa4i yBJFN8Lb0q5tHWrcNGS1zBI+ryZy+XBVPbk9aRn6O7geSHWG+PqAZotJ/61jQ8rIH59rffSUi3O uT3lQ3NOBQFGqpdXogFY2Ep89jtgH9/YQzpe3iVYB0fOeHivlOwEQ/7iOzPsNNBkIL1tlEC3STN mxaZjqpBx2vXcg7260K03ludiPMksH9cf5+P8Lg35dTetouGut7OBs8XS2xyeGxg== X-Google-Smtp-Source: AGHT+IGT33HgCqLOZfJ01RgUk00qwFrULoYZQaMW53xI5BI0UsjXz8kyxp1vtyO+ouK42MOcyxdiSA== X-Received: by 2002:a05:6a20:3ca6:b0:34e:1009:4222 with SMTP id adf61e73a8af0-363f5e95146mr8047704637.51.1764860912867; Thu, 04 Dec 2025 07:08:32 -0800 (PST) Received: from ?IPV6:2001:ee0:4f4c:210:c2bc:6984:75c5:9339? ([2001:ee0:4f4c:210:c2bc:6984:75c5:9339]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf686b3b5a9sm2145622a12.9.2025.12.04.07.08.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Dec 2025 07:08:32 -0800 (PST) Message-ID: Date: Thu, 4 Dec 2025 22:08:25 +0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC] virtio_net: gate delayed refill scheduling To: Jason Wang Cc: "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Paolo Abeni , Xuan Zhuo , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , virtualization@lists.linux.dev, netdev@vger.kernel.org, bpf@vger.kernel.org References: <40af2b73239850e7bf1a81abb71ee99f1b563b9c.1764226734.git.mst@redhat.com> Content-Language: en-US From: Bui Quang Minh In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/3/25 13:37, Jason Wang wrote: > On Tue, Dec 2, 2025 at 11:29 PM Bui Quang Minh wrote: >> On 12/2/25 13:03, Jason Wang wrote: >>> On Mon, Dec 1, 2025 at 11:04 PM Bui Quang Minh wrote: >>>> On 11/28/25 09:20, Jason Wang wrote: >>>>> On Fri, Nov 28, 2025 at 1:47 AM Bui Quang Minh wrote: >>>>>> I think the the requeue in refill_work is not the problem here. In >>>>>> virtnet_rx_pause[_all](), we use cancel_work_sync() which is safe to >>>>>> use "even if the work re-queues itself". AFAICS, cancel_work_sync() >>>>>> will disable work -> flush work -> enable again. So if the work requeue >>>>>> itself in flush work, the requeue will fail because the work is already >>>>>> disabled. >>>>> Right. >>>>> >>>>>> I think what triggers the deadlock here is a bug in >>>>>> virtnet_rx_resume_all(). virtnet_rx_resume_all() calls to >>>>>> __virtnet_rx_resume() which calls napi_enable() and may schedule >>>>>> refill. It schedules the refill work right after napi_enable the first >>>>>> receive queue. The correct way must be napi_enable all receive queues >>>>>> before scheduling refill work. >>>>> So what you meant is that the napi_disable() is called for a queue >>>>> whose NAPI has been disabled? >>>>> >>>>> cpu0] enable_delayed_refill() >>>>> cpu0] napi_enable(queue0) >>>>> cpu0] schedule_delayed_work(&vi->refill) >>>>> cpu1] napi_disable(queue0) >>>>> cpu1] napi_enable(queue0) >>>>> cpu1] napi_disable(queue1) >>>>> >>>>> In this case cpu1 waits forever while holding the netdev lock. This >>>>> looks like a bug since the netdev_lock 413f0271f3966 ("net: protect >>>>> NAPI enablement with netdev_lock()")? >>>> Yes, I've tried to fix it in 4bc12818b363 ("virtio-net: disable delayed >>>> refill when pausing rx"), but it has flaws. >>> I wonder if a simplified version is just restoring the behaviour >>> before 413f0271f3966 by using napi_enable_locked() but maybe I miss >>> something. >> As far as I understand, before 413f0271f3966 ("net: protect NAPI >> enablement with netdev_lock()"), the napi is protected by the > I guess you meant napi enable/disable actually. > >> rtnl_lock(). But in the refill_work, we don't acquire the rtnl_lock(), > Any reason we need to hold rtnl_lock() there? Correct me if I'm wrong here. Before 413f0271f3966 ("net: protect NAPI enablement with netdev_lock()"), napi_disable and napi_enable are not safe to be called concurrently. The example race is napi_disable -> napi_save_config -> write to n->config->defer_hard_irqs napi_enable -> napi_restore_config -> read n->config->defer_hard_irqs In refill_work, we don't hold any locks so the race scenario can happen. Maybe I misunderstand what you mean by restoring the behavior before 413f0271f3966. Do you mean that we use this pattern     In virtnet_xdp_se;     netdev_lock(dev);     virtnet_rx_pause_all()         -> napi_disable_locked     virtnet_rx_resume_all()         -> napi_disable_locked     netdev_unlock(dev); And in other places where we pause the rx too. It will hold the netdev_lock during the time napi is disabled so that even when refill_work happens concurrently, napi_disable cannot acquire the netdev_lock and gets stuck inside. > >> so it seems like we will have race condition before 413f0271f3966 ("net: >> protect NAPI enablement with netdev_lock()"). >> >> Thanks, >> Quang Minh. >> > Thanks > Thanks, Quang Minh.