From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TEshHCqz; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 41E035A0621 for ; Tue, 18 Feb 2025 11:22:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739874133; 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=yvhzlRjbXUr0ojjQjEwdcWpTcHGG+Nr0AhXOUoXJPAU=; b=TEshHCqzaCBKkStAaKL8D+ceekM5mu1svfmicNdHikX4vu2ZmZYCpveSc745DehFWzP1aS ZlzTdVkX2UxlpGVGtB9JEdA9oIunDuJDEKbRf/K8KkoxAvfq2LNOnGJZinMpFZiIcVEfKN c+XohvrSvZxydZbqeJtleEmHamuYWrw= 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-663-UhVXJW5xPNinlNEJUWD6Uw-1; Tue, 18 Feb 2025 05:22:10 -0500 X-MC-Unique: UhVXJW5xPNinlNEJUWD6Uw-1 X-Mimecast-MFC-AGG-ID: UhVXJW5xPNinlNEJUWD6Uw_1739874130 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4394c0a58e7so38625785e9.0 for ; Tue, 18 Feb 2025 02:22:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739874129; x=1740478929; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yvhzlRjbXUr0ojjQjEwdcWpTcHGG+Nr0AhXOUoXJPAU=; b=VReivQw2/8I5c1+KDpf4Rsp5d5v4gmJz0FAhT718f2m11vL2u06jD/E+IXlgF1gggn JUmghnZUOkZ/Ek8LcUCaBktwg5a2vC2bFowZGiGdh5LfdOo8GvgdBZB9D6yxRexbvIi1 toMtgtuMDFYZTgo7V2pDdzMLsfMwN0955ksyMY/K2tnEqA4o4X1jUmoyXU2AZPwCasyX OS+cc2vazR7SnUBL4mWGu2d484EPtyJHXsrueWwXkgRf3Qsfgbmhy41u/VtTdIQbZ9x6 PQTiX6QKwavPzdvKTDQfrxg2OHIsvo1gbf86hbB49VxpvmxJHCGmpawsc/PVoViDPIAl 0OrA== X-Forwarded-Encrypted: i=1; AJvYcCVchq7++x5w8HAZVuGD0kFJDl5ogZmlKZGkGQBfKFJqO61Seqz9cHUC2aoPJvdN9US880hz+t5f8Os=@passt.top X-Gm-Message-State: AOJu0YxP3qkJEnf1GVXvjuCIzPv/AnH3zySwK3OMkgDP1MrpG1yBj06M TOXF024kjc8BAGi550qvvCFS0EcOe3iOYTGMOuNX7N7Np2KP0ybfcj/SDv+GFXIeics2WdqZFPG fi1JFdKekRH0KQqLnxKjKhpDxHeEyN5l6/rAy+9GmdZtURkZ6cQ== X-Gm-Gg: ASbGncsMzf/KoJZXkGfEQ4xXAsJB4RyZUxsI3/yweSiXGLdO9Nn6xHRug7e0gHFGuf9 S68oN848jfuVlnKEy4Md1YNLGJj1S755tVtuudvdGSFsjwVPQKrGwaPnZxFbhAaxsgnfK2PZNtw gnltQu0ANFIN048zRwmHyhZdw+iYV7JZI2qQj5c5cz8I7WVnT7snSZZEKxKx0Nghh6x/xwG2tKG v9/m78IN/OKGXQ2d6RoyLU6+HjWvcH+rthUIz9gcexIaoyZ3/FBMXpoREgMeoZCF6ixfwDjBpWD 3g0mLeQZ18CIXSN4 X-Received: by 2002:a05:600c:4511:b0:439:88bb:d012 with SMTP id 5b1f17b1804b1-43988bbd4c9mr48025115e9.8.1739874129614; Tue, 18 Feb 2025 02:22:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrIuR3wcYckHFbnjPQbBkmTetroVkTKVnAgg8AvwsbBvYzknaKjr4Du/tT5UciYjQU9NTw4g== X-Received: by 2002:a05:600c:4511:b0:439:88bb:d012 with SMTP id 5b1f17b1804b1-43988bbd4c9mr48024875e9.8.1739874129231; Tue, 18 Feb 2025 02:22:09 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d5d8bsm14602378f8f.70.2025.02.18.02.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 02:22:08 -0800 (PST) Date: Tue, 18 Feb 2025 11:22:06 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH] tcp_vu: head_cnt need not be global Message-ID: <20250218112206.7af5d711@elisabeth> In-Reply-To: <53e1b351-da19-4491-b438-1e77e0dc836c@redhat.com> References: <20250218025013.1035148-1-david@gibson.dropbear.id.au> <53e1b351-da19-4491-b438-1e77e0dc836c@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VTDBbqi-GBYfJEAgEDQvEy1nvFxSm08YA9B75eudwcY_1739874130 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: LHYSD5AV7GWU57U4R4OONWNO4VF25X6H X-Message-ID-Hash: LHYSD5AV7GWU57U4R4OONWNO4VF25X6H X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson , passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 18 Feb 2025 09:01:30 +0100 Laurent Vivier wrote: > On 18/02/2025 03:50, David Gibson wrote: > > head_cnt is a global variable which tracks how many entries in head[] are > > currently used. The fact that it's global obscures the fact that the > > lifetime over which it has a meaningful value is quite short: a single > > call to of tcp_vu_data_from_sock(). > > > > Make it a local to tcp_vu_data_from_sock() to make that lifetime clearer. > > We keep the head[] array global for now - although technically it has the > > same valid lifetime - because it's large enough we might not want to put > > it on the stack. > > We can make the array local but on the heap using a static declaration in the function. Well, it would still be in the data segment, not actually on the heap [1], but it would be somewhat hidden in the function. I'd rather suggest that we keep this stuff visible at the "top level". [1] I had a doubt for a moment so I tried it: $ git diff diff --git a/tcp_vu.c b/tcp_vu.c index 0622f17..c40b102 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -187,6 +187,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, { struct vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; + static char am_i_heap_or_am_i_data[64 << 20]; struct msghdr mh_sock = { 0 }; uint16_t mss = MSS_GET(conn); int s = conn->sock; @@ -195,6 +196,8 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, int elem_cnt; int i; + memset(am_i_heap_or_am_i_data, 0, sizeof(am_i_heap_or_am_i_data)); + *iov_cnt = 0; hdrlen = tcp_vu_hdrlen(v6); $ nm -td -S passt | grep am_i_heap_or_am_i_data 0000000202163552 0000000067108864 b am_i_heap_or_am_i_data.2 -- Stefano