Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp264730rdb; Mon, 22 Jan 2024 03:36:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4Z3CRgSoo+/P7mzxv9N90PiK2YhQyQfedFffkGIXSnVVg4A+rPolfPvt+fX30Gb/7HFL1 X-Received: by 2002:a25:83c7:0:b0:dc2:5457:ae67 with SMTP id v7-20020a2583c7000000b00dc25457ae67mr1282690ybm.90.1705923412186; Mon, 22 Jan 2024 03:36:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705923412; cv=pass; d=google.com; s=arc-20160816; b=tY/JFh1mbDyp1597Fp6+XgtVDBwsVeL64YZdhii691mORmEbm3y8tItBW6ipk3tHvI hddMyjemXclWLDoyYoHyn8shDk11XRJckYZa5dJjUFZVB/uwrx5ZbTmWcweVCPzFbUQM Eqh9aUFb2ue2/Tov8EihRwNZrh0n00gRdXHeaCtJOkJ8LofoHOeIIaLnliC+Zicp+lcy M2RMuQkNZeVcQMUEa+kjfvxFDqSByQfcXIgWspzZb5IcaE78jyaUINGnpiF3oNWYzzpl crrgyR9YYVeOGk0flUwgxfvHfDw2ltaJfxcRdSAHbqG+xRStpHCygrT9+mduB/l7u368 FIPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=xszYClSK+CsCGTSpIxFxpuSnSH1wZstVsErrb4ghUjg=; fh=afyeRAPHqTVKqAsks6QfDWeyhnwa5Bky8/4KfP1InWw=; b=DYC2PQFNY9+RVExIFvThhcFNA7Wy9JRTSYvUsh/2ZqKJq1L07/7rLjD2AKr9ftqZiN ZKs9lHCAvzOaLNvV2rnc81KYjJ27fNDZ9FYL+Fq1P7ghy6HZB+FLMziyfztLbA1caZdw wgi1Zat2bHB/KEhZdWN76COHdAsqaMb//mq7Q66Xom5Ljf3D54elslNVsDXN+N07VMTC r9OixJtLhTYeJAxvaT9b9gXLP+X1iA13bsEXckFjbqC5HQKxuHAEMbv2faQx01ULYkp1 1cknWo43bxBuPDWVZfFSvP/LocEN5XHyIUD+Suy7FV7Y7vViELCH9eaLMavHSum+KGCy vSbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OJGaeuHt; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-32915-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32915-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g30-20020a0caade000000b006846c97c980si5384425qvb.579.2024.01.22.03.36.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:36:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32915-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OJGaeuHt; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-32915-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32915-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4D6FB1C26604 for ; Mon, 22 Jan 2024 11:35:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C8193D98C; Mon, 22 Jan 2024 11:24:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OJGaeuHt" 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 55F5E3DB95 for ; Mon, 22 Jan 2024 11:24:41 +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=1705922684; cv=none; b=R9By+Rl9HQb0xqjM1AJA2d2L2ozadLk4Z0uRuipdQPmZor27yBzoVtlwLicSFf8hjGTFMJi6328Uf0jHOS6We6FyDg62ALvW4yiTBoaSKg5+bz0TEgCYdK+36/Y5stgafnS0GdvgHUa5nOMbzmkQR09WGf7xrIhLBws04uKvbEc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705922684; c=relaxed/simple; bh=yHR2yz+3CdE61E4n0W3BNb+3FTIUhRAD2+FYuwrHJ84=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=k31nlW0TewTDUj71gM/Go4g7Z2HtnjkUlxTjQdznZb6AOh7+p0XmH1u3RnXXeAJbh2bUQzTsVfACpyr+IDLq6krs1MwvatdKf/+SG+WkOehXzZWwKUV7amTG4HlDI7a8OWnZHr6ZrZ/Q5oGJyYcknbY0bV28aIQSZT1wj1n9eHo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=OJGaeuHt; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705922680; 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: in-reply-to:in-reply-to:references:references; bh=xszYClSK+CsCGTSpIxFxpuSnSH1wZstVsErrb4ghUjg=; b=OJGaeuHtetWactDIJ3+UdAltHN+AaA5Pm9UU7bx0KbQBOpCt95IFWuV+7ZQAHrHC7pRE+Y 2zP0NjCx93aX5OEDpMkbvXJXwXXXQn68xlOyhYDXDnzo4SCODqSuMe+dz+k/JtD/F0jMAz HvpNnHhHXcyVKzoV0ejh1RFbBb6Ow1s= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-rNIKWsBSP7SYeHtNX2y6dg-1; Mon, 22 Jan 2024 06:24:38 -0500 X-MC-Unique: rNIKWsBSP7SYeHtNX2y6dg-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-50e7ddf4dacso2185480e87.1 for ; Mon, 22 Jan 2024 03:24:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705922676; x=1706527476; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xszYClSK+CsCGTSpIxFxpuSnSH1wZstVsErrb4ghUjg=; b=Qh6ax40Z9IJ05BFuFSK0vF8rl15HTsv3M/m7L2cyMpNhJl/ADBp7ErHRoiJxyKhTQH ShrXv+3N7uBrCE1D7zGBaAyMdYx21X5nrL4yDV7vCtrKRzuuSuTPxZEtSNo0GF1q0Iam aHXoP/33WNjRDT/KJIsdNLijp4ja8bSOcOoUbeT6wZAGXPqa7s39+22DGhWxKqgELfL7 tw6vZkz6bOcYnybdYIN8CnOg3h0T6M8sQvcyvRj/aM20VKLuNJv6/S3WhhRaWXWH4KfY XUuzmlOGUsQgzka3CQ9fz+/s4d5XBwDsnCsLCYkq9IKn+HgYzkYWjDK8GsJY8JzzfTi1 3zVA== X-Gm-Message-State: AOJu0Ywp6msw1pJjN3R0L0DspIrA/fqsA0LZoSjZ+87Vt++IIdn/v4Yf P/QSa44rJzFQsn799TZQPVWsVdlPcpW9Uw1VrfMWZJOBYjgntS1HDf4dvZnujLRcyHW7q74a5L6 4UUdQdHbHZsSFL5GhJCzFFy8tnGzz2H09rsRR/WA51gNowOJV0eQPybNvwArObrmbaMigHw== X-Received: by 2002:a05:6512:110d:b0:50e:7cbf:7777 with SMTP id l13-20020a056512110d00b0050e7cbf7777mr1973085lfg.79.1705922676236; Mon, 22 Jan 2024 03:24:36 -0800 (PST) X-Received: by 2002:a05:6512:110d:b0:50e:7cbf:7777 with SMTP id l13-20020a056512110d00b0050e7cbf7777mr1973078lfg.79.1705922675868; Mon, 22 Jan 2024 03:24:35 -0800 (PST) Received: from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec? (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id fi6-20020a056402550600b0055c38f3ca66sm1057376edb.29.2024.01.22.03.24.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jan 2024 03:24:35 -0800 (PST) Message-ID: <7121300c-1fa3-461f-a531-d148b16d5079@redhat.com> Date: Mon, 22 Jan 2024 12:24:34 +0100 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 v3] Drop Tx network packet when Tx TmFIFO is full Content-Language: en-US, nl To: Liming Sun , Vadim Pasternak , David Thompson , Mark Gross , Dan Carpenter Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240111173106.96958-1-limings@nvidia.com> From: Hans de Goede In-Reply-To: <20240111173106.96958-1-limings@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, On 1/11/24 18:31, Liming Sun wrote: > Starting from Linux 5.16 kernel, Tx timeout mechanism was added > in the virtio_net driver which prints the "Tx timeout" warning > message when a packet stays in Tx queue for too long. Below is an > example of the reported message: > > "[494105.316739] virtio_net virtio1 tmfifo_net0: TX timeout on > queue: 0, sq: output.0, vq: 0×1, name: output.0, usecs since > last trans: 3079892256". > > This issue could happen when external host driver which drains the > FIFO is restared, stopped or upgraded. To avoid such confusing > "Tx timeout" messages, this commit adds logic to drop the outstanding > Tx packet if it's not able to transmit in two seconds due to Tx FIFO > full, which can be considered as congestion or out-of-resource drop. > > This commit also handles the special case that the packet is half- > transmitted into the Tx FIFO. In such case, the packet is discarded > with remaining length stored in vring->rem_padding. So paddings with > zeros can be sent out when Tx space is available to maintain the > integrity of the packet format. The padded packet will be dropped on > the receiving side. > > Signed-off-by: Liming Sun Thank you for your patch/series, I've applied this patch (series) to my review-hans branch: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans Note it will show up in the pdx86 review-hans branch once I've pushed my local branch there, which might take a while. I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle. Regards, Hans > --- > v2->v3: > Updates for Ilpo's comments: > - Revises commit message to avoid confusion. > v2: Fixed formatting warning > v1: Initial version > --- > drivers/platform/mellanox/mlxbf-tmfifo.c | 67 ++++++++++++++++++++++++ > 1 file changed, 67 insertions(+) > > diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c > index 5c683b4eaf10..f39b7b9d2bfe 100644 > --- a/drivers/platform/mellanox/mlxbf-tmfifo.c > +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c > @@ -47,6 +47,9 @@ > /* Message with data needs at least two words (for header & data). */ > #define MLXBF_TMFIFO_DATA_MIN_WORDS 2 > > +/* Tx timeout in milliseconds. */ > +#define TMFIFO_TX_TIMEOUT 2000 > + > /* ACPI UID for BlueField-3. */ > #define TMFIFO_BF3_UID 1 > > @@ -62,12 +65,14 @@ struct mlxbf_tmfifo; > * @drop_desc: dummy desc for packet dropping > * @cur_len: processed length of the current descriptor > * @rem_len: remaining length of the pending packet > + * @rem_padding: remaining bytes to send as paddings > * @pkt_len: total length of the pending packet > * @next_avail: next avail descriptor id > * @num: vring size (number of descriptors) > * @align: vring alignment size > * @index: vring index > * @vdev_id: vring virtio id (VIRTIO_ID_xxx) > + * @tx_timeout: expire time of last tx packet > * @fifo: pointer to the tmfifo structure > */ > struct mlxbf_tmfifo_vring { > @@ -79,12 +84,14 @@ struct mlxbf_tmfifo_vring { > struct vring_desc drop_desc; > int cur_len; > int rem_len; > + int rem_padding; > u32 pkt_len; > u16 next_avail; > int num; > int align; > int index; > int vdev_id; > + unsigned long tx_timeout; > struct mlxbf_tmfifo *fifo; > }; > > @@ -819,6 +826,50 @@ static bool mlxbf_tmfifo_rxtx_one_desc(struct mlxbf_tmfifo_vring *vring, > return true; > } > > +static void mlxbf_tmfifo_check_tx_timeout(struct mlxbf_tmfifo_vring *vring) > +{ > + unsigned long flags; > + > + /* Only handle Tx timeout for network vdev. */ > + if (vring->vdev_id != VIRTIO_ID_NET) > + return; > + > + /* Initialize the timeout or return if not expired. */ > + if (!vring->tx_timeout) { > + /* Initialize the timeout. */ > + vring->tx_timeout = jiffies + > + msecs_to_jiffies(TMFIFO_TX_TIMEOUT); > + return; > + } else if (time_before(jiffies, vring->tx_timeout)) { > + /* Return if not timeout yet. */ > + return; > + } > + > + /* > + * Drop the packet after timeout. The outstanding packet is > + * released and the remaining bytes will be sent with padding byte 0x00 > + * as a recovery. On the peer(host) side, the padding bytes 0x00 will be > + * either dropped directly, or appended into existing outstanding packet > + * thus dropped as corrupted network packet. > + */ > + vring->rem_padding = round_up(vring->rem_len, sizeof(u64)); > + mlxbf_tmfifo_release_pkt(vring); > + vring->cur_len = 0; > + vring->rem_len = 0; > + vring->fifo->vring[0] = NULL; > + > + /* > + * Make sure the load/store are in order before > + * returning back to virtio. > + */ > + virtio_mb(false); > + > + /* Notify upper layer. */ > + spin_lock_irqsave(&vring->fifo->spin_lock[0], flags); > + vring_interrupt(0, vring->vq); > + spin_unlock_irqrestore(&vring->fifo->spin_lock[0], flags); > +} > + > /* Rx & Tx processing of a queue. */ > static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx) > { > @@ -841,6 +892,7 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx) > return; > > do { > +retry: > /* Get available FIFO space. */ > if (avail == 0) { > if (is_rx) > @@ -851,6 +903,17 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx) > break; > } > > + /* Insert paddings for discarded Tx packet. */ > + if (!is_rx) { > + vring->tx_timeout = 0; > + while (vring->rem_padding >= sizeof(u64)) { > + writeq(0, vring->fifo->tx.data); > + vring->rem_padding -= sizeof(u64); > + if (--avail == 0) > + goto retry; > + } > + } > + > /* Console output always comes from the Tx buffer. */ > if (!is_rx && devid == VIRTIO_ID_CONSOLE) { > mlxbf_tmfifo_console_tx(fifo, avail); > @@ -860,6 +923,10 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx) > /* Handle one descriptor. */ > more = mlxbf_tmfifo_rxtx_one_desc(vring, is_rx, &avail); > } while (more); > + > + /* Check Tx timeout. */ > + if (avail <= 0 && !is_rx) > + mlxbf_tmfifo_check_tx_timeout(vring); > } > > /* Handle Rx or Tx queues. */