From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C448329388 for ; Tue, 25 Nov 2025 16:54:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764089696; cv=none; b=n0tE04n+oFWRdfGSgJ8eYQBK9IvChi517vsHtYbTv/ivpss+U8WbfPwpjPrdXn9UohGtQ/zwrycpwJlZXd7zY6EO64ao/3PWplpZkRIo+T++tuit80j7vgsahckpFSQApxONxmOfh9bJx24Sik1pZ21+l6AmuMskkJXwCe6rVbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764089696; c=relaxed/simple; bh=M1xVC7gLm/5kXEcyVn8F+hiOuj4fAZSxatNimx4cXKI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=icsVn5s9Z4Hd7OtQwByu3jqX15gtpitfZ9+WWmHgS/NTJq14GN7DEJN8hMAJ9+eRGlus385xn1Mh2FEd8UqRWw50N+MwN/t4k12pRbR6gU/YLBHmfXNhYxvBdSKJpZAINh5KN5QPXyEYQHxouBwyDOeFDNGfg2fnV1OgkrFfFaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CU7DHyCr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Oz7s6MO8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CU7DHyCr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Oz7s6MO8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764089694; 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=VSyjzVF3bRMyEucyth0abh8Rzk8q/nESWV3mm3a9fMs=; b=CU7DHyCr8itCFZEVFss9vgC76yCxqgV/R5BwxjyZSjR/FFujcaPptDyUcUYATGM9nG8Dob x4atpcbbXpYtz5AhdjX5D8jMYH/Eq+kh+//aK0UFEK8fV2iZsEi/m9jH4hLmo02k075wf4 UOffzQ5DGI+u8301xkE8+VK+PH4Oa2E= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-676-Swh4WXedMG6rzowsQ9cFcw-1; Tue, 25 Nov 2025 11:54:49 -0500 X-MC-Unique: Swh4WXedMG6rzowsQ9cFcw-1 X-Mimecast-MFC-AGG-ID: Swh4WXedMG6rzowsQ9cFcw_1764089684 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4779da35d27so68456185e9.3 for ; Tue, 25 Nov 2025 08:54:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764089683; x=1764694483; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VSyjzVF3bRMyEucyth0abh8Rzk8q/nESWV3mm3a9fMs=; b=Oz7s6MO8s4itO6fJyW7LuGeA+YQYLb63NmnVODYfKsSpxbJPrwWcAIyiyC6Nrc0jDq hyD24dLZInuSLysOTuSSnRbVOcWH3Ej8UinzdHLOAUzr2XRl0JMoKJEDvJClltBWDJ/5 dlUEErJThDdC/uNkNn55Tl+URgCHiz/o2x2au9HFFzq+T1Dy6nWluZ22CIqBi/+JkZWg KDz0CfJOAmFDNKxePNyfITPTLtf2rfbRNUZW2ISigiWKpTOXWzg+x4P7a3vLRlQdXkA6 cc6QLRrdKFhJTXn8iETjRQibxktidIGg4Zg2JEOCuXVAis6kPxrRRU61a4AKEAkX+5as kKDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764089683; x=1764694483; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VSyjzVF3bRMyEucyth0abh8Rzk8q/nESWV3mm3a9fMs=; b=EOBHtzFaUlLoDpaoqLj65co8qX/70Cb1+tTokN1YqJyt0rK9Lh/Re9Kfr0035oiEQb Y7S7hxoOOoYE+dOG0f2tz9GOSo9hQ3vFvadE9M8vDYbDQuaHPDB2ZGZC/s2U6ZzwABQt rM7WMl5rivosRpBL7qHlS0x/WjW45js8GdTdGp+mGaMzZZcBA9jvVtIN8ULrVCqxVKdO PSH9+c2CMM1SVPKsWuB0qL4bEqrXbtF35Cr3yYk29NLA7arJyRqFsHuP5jNVmfcd4orY zelALCOaOVe1cdJR+rJiza+ETswaCFrd0QS2AMCNEtbENeP7cxoqwbSHjvuL0OAp2OTA noOw== X-Forwarded-Encrypted: i=1; AJvYcCVY5P7cMbUJu5fgqwZSNDP38fjT6l2IYCQyF2UK+8qmAFIbZjh5NlTMEqjShhdGd2gcLwl6SgW/wbQkoUs=@vger.kernel.org X-Gm-Message-State: AOJu0YyjRC0BNiaOR4VnBxgjRLgw1OJqZK+3bOpQV00gmspKQnbnsAMN OYRWkAv385lGLhO69q+nwGRpGXpoEEuuYo3Dph71uVn8Y8fpb+Z/oeDx4U1pQDKuGGAzSl4F9R1 1VAco59umhbgkQBOvHa7kFq0Kn4ZTJOlg9ljRqJ7IlLw+4EcqwyCW3WDRSESljEfUdA== X-Gm-Gg: ASbGncsZuBJ7gVX2kCgo1qpe+QgfS0yHzQTisT2Rq27awn1ODM9qdTAKGrEqcH6HdWP +4FxooLD8OLq6wLDF+I0mtz2MMW9Un6TWI+JRy9mLvNIoHnlK1bhmB8mZFvaj+zg9XcRYeq/iK0 qqw0pzcjWbbtDByRtonm2uJgJ2E393EfVsJvzMW67WQFrYtqpax0CJtNMShyJoc+UNyoDwL83EV 1Pe+CSuXLIanS8HMGLX7XGBsU4dqUBobaMDWc5g9bFC0R3qIFN7cZ0KJy5wCZsu2aUQYIr2wnhc t0StMWnIbUf54TjVDFIWZWHmM/TZ/N/FKkzkRQkANz93A7N3Kkz99cPVQcg2WVAqY11zajTGYRp 8hyv365HX48DBtwo= X-Received: by 2002:a05:600c:c8c:b0:471:1435:b0ea with SMTP id 5b1f17b1804b1-47904b242eemr43823175e9.24.1764089683423; Tue, 25 Nov 2025 08:54:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFI01s5vSZlwPc1XuZyxkfAjV2ILVY5rmqifLiNvt5a+hPHMgV9ZhgyCmVtX0zbnJSE6jyd/w== X-Received: by 2002:a05:600c:c8c:b0:471:1435:b0ea with SMTP id 5b1f17b1804b1-47904b242eemr43822735e9.24.1764089682896; Tue, 25 Nov 2025 08:54:42 -0800 (PST) Received: from redhat.com (IGLD-80-230-39-63.inter.net.il. [80.230.39.63]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477bf1e86b3sm317496245e9.6.2025.11.25.08.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 08:54:42 -0800 (PST) Date: Tue, 25 Nov 2025 11:54:39 -0500 From: "Michael S. Tsirkin" To: Simon Schippers Cc: willemdebruijn.kernel@gmail.com, jasowang@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, eperezma@redhat.com, jon@nutanix.com, tim.gebauer@tu-dortmund.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev Subject: Re: [PATCH net-next v6 3/8] tun/tap: add synchronized ring produce/consume with queue management Message-ID: <20251125100655-mutt-send-email-mst@kernel.org> References: <20251120152914.1127975-1-simon.schippers@tu-dortmund.de> <20251120152914.1127975-4-simon.schippers@tu-dortmund.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251120152914.1127975-4-simon.schippers@tu-dortmund.de> On Thu, Nov 20, 2025 at 04:29:08PM +0100, Simon Schippers wrote: > Implement new ring buffer produce and consume functions for tun and tap > drivers that provide lockless producer-consumer synchronization and > netdev queue management to prevent ptr_ring tail drop and permanent > starvation. > > - tun_ring_produce(): Produces packets to the ptr_ring with proper memory > barriers and proactively stops the netdev queue when the ring is about > to become full. > > - __tun_ring_consume() / __tap_ring_consume(): Internal consume functions > that check if the netdev queue was stopped due to a full ring, and wake > it when space becomes available. Uses memory barriers to ensure proper > ordering between producer and consumer. > > - tun_ring_consume() / tap_ring_consume(): Wrapper functions that acquire > the consumer lock before calling the internal consume functions. > > Key features: > - Proactive queue stopping using __ptr_ring_full_next() to stop the queue > before it becomes completely full. > - Not stopping the queue when the ptr_ring is full already, because if > the consumer empties all entries in the meantime, stopping the queue > would cause permanent starvation. what is permanent starvation? this comment seems to answer this question: /* Do not stop the netdev queue if the ptr_ring is full already. * The consumer could empty out the ptr_ring in the meantime * without noticing the stopped netdev queue, resulting in a * stopped netdev queue and an empty ptr_ring. In this case the * netdev queue would stay stopped forever. */ why having a single entry in the ring we never use helpful to address this? In fact, all your patch does to solve it, is check netif_tx_queue_stopped on every consumed packet. I already proposed: static inline int __ptr_ring_peek_producer(struct ptr_ring *r) { if (unlikely(!r->size) || r->queue[r->producer]) return -ENOSPC; return 0; } And with that, why isn't avoiding the race as simple as just rechecking after stopping the queue? __ptr_ring_produce(); if (__ptr_ring_peek_producer()) netif_tx_stop_queue if (!__ptr_ring_peek_producer()) netif_tx_wake_queue(txq); -- MST