From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from delivery.antispam.mailspamprotection.com (delivery.antispam.mailspamprotection.com [185.56.87.1]) (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 0A612267B90 for ; Fri, 10 Oct 2025 21:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=185.56.87.1 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760131258; cv=pass; b=RjnJkymKwAPOuuRQt/RwIJ+o4mX7oo23QiO6hTw+MfvXCYBOCBPtkQbDckrAdUS/CGDE8vIMEnwM8ioFl7r+NjzVDnSLSeb9Y903llX8NNPBJl+vrZWpAMCHlnlgTWhsN2qwxEdONow98E9D2OMxemMZzA1a7W1EbIcSIwD+cyM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760131258; c=relaxed/simple; bh=fPlDHZlSJRA5PDvHco57sjg3ozHSO1I20UpOSkNVqQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=geApORapRB7H2fe5iG026GJTnqq94hww6SbIvmmmG6MX8IA2sgkRyh7lcAG/vmtSbV9EdQY+/bGjbRWzztXXgXOgour3fkdJeqvsjsYVtwfkygoLfq7YZc53vzQdkvUvwCDJHqz74HF1c1byQ2IZxlmYN9vV9MXiYFT0sg/rSmk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=valla.it; spf=pass smtp.mailfrom=valla.it; dkim=pass (1024-bit key) header.d=antispam.mailspamprotection.com header.i=@antispam.mailspamprotection.com header.b=tMXSKbUg; dkim=pass (1024-bit key) header.d=valla.it header.i=@valla.it header.b=a4soGJk2; arc=pass smtp.client-ip=185.56.87.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=valla.it Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=valla.it Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antispam.mailspamprotection.com header.i=@antispam.mailspamprotection.com header.b="tMXSKbUg"; dkim=pass (1024-bit key) header.d=valla.it header.i=@valla.it header.b="a4soGJk2" ARC-Seal: i=1; cv=none; a=rsa-sha256; d=outgoing.instance-europe-west4-x65p.prod.antispam.mailspamprotection.com; s=arckey; t=1760131256; b=eHAX1tCe0JOj+Qqsk3aT9RUqQz+TRJasaES1aM0apH77CnDvQp8p9ol2QzOz2XSl31wIuUBrqZ XUBrThmGI/eDOCipnTIxF15fVru5eaXkVaBd4zNZWivSwUs8o9MaLglQNGrdu0EMQtdquWk0/V mfJf+ITIiGwfTzOcVNY1FFzqzhTE2NKVFqzFY++LJm1V5Fs54sX1IWfd51NJELa9weqI2DbgtG zlTWWDolqarhw0Bv4wO0GJWWKHN80+IcnpLuNW51QlyL3ATcGSoRhAwZtaho8mNpPAzdEk0Tl3 4sVgkmjWEAXvqmLw+CLv7/Xnk4I0VqdZKjRWYVbeR+4L9Q==; ARC-Authentication-Results: i=1; outgoing.instance-europe-west4-x65p.prod.antispam.mailspamprotection.com; smtp.remote-ip=35.214.173.214; iprev=pass (214.173.214.35.bc.googleusercontent.com) smtp.remote-ip=35.214.173.214; auth=pass (LOGIN) smtp.auth=esm19.siteground.biz; dkim=pass header.d=valla.it header.s=default header.a=rsa-sha256; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=outgoing.instance-europe-west4-x65p.prod.antispam.mailspamprotection.com; s=arckey; t=1760131256; bh=fPlDHZlSJRA5PDvHco57sjg3ozHSO1I20UpOSkNVqQI=; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:DKIM-Signature:DKIM-Signature; b=llKin1NBYm0pT1ECTlcE3tkuheE9eOqremetiFDjEIzjJeXWE84Rkv+BImQ2dluTKMkylF5xGk UV3hgJiy546yFjt1MyKJCt8/McD74y9cLjtarPq3Dn0Ey8pxDlJUnUU9RoS9jhHuXFOsk8JCss qXwC0TvWebajt2OKJPNolrPUVvqMu5/H9H7m63wKpY4jrlVxuwIHMMnY6fQ4izwkf8R2pNcfZw bK/AZSyo37Ll06YpEUzVIekDFetVrzkR/emyg+tY31uaf3EunLGvDgY9pvdDahKaGeYb5v4DhO LQ62+rf27fIp5MZ38Ql5KThid8ydgSZbEnEAnfPKNjF6nw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=antispam.mailspamprotection.com; s=default; h=CFBL-Feedback-ID:CFBL-Address :Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Reply-To:List-Unsubscribe; bh=Pa3D+kH4AJps3m5pvh+XsXvkn2PadB4zax/ER5QUhaU=; b=tMXSKbUglyzqsc292vWySzV3wK PHHtopZOb+/bWc4OGtcbNNNmEjFfnpdQKOOM12ODwo+nd6A+OJkMgQ/54Xm2ywv+YGhuAZIcm3E1Z nwtmgnqKQ4q9RE8bUlYDhShLA/1vW5uAcCXOY6n0VIs665jgHaf5BQOHgjFE1McxkJuo=; Received: from 214.173.214.35.bc.googleusercontent.com ([35.214.173.214] helo=esm19.siteground.biz) by instance-europe-west4-x65p.prod.antispam.mailspamprotection.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.1) (envelope-from ) id 1v7KXd-00000008iCo-2pk5 for virtualization@lists.linux.dev; Fri, 10 Oct 2025 21:20:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=valla.it; s=default; h=Date:Subject:Cc:To:From:list-help:list-unsubscribe: list-subscribe:list-post:list-owner:list-archive; bh=Pa3D+kH4AJps3m5pvh+XsXvkn2PadB4zax/ER5QUhaU=; b=a4soGJk2euqlfaLc6adf+mUjUX 2jNarlk/C/D5cX3Ig9UyytaSOhwu83PqdoS/XtcmZ4plVMKykP/nlbqJCnRsR0sqxCf0H3736eJxa PCNBpc7B4jQABd+kVG7cZmQl5wmPuW962CXROBvVoBdNwYRQJ3tdOjQPdRRbNGWAR1PI=; Received: from [87.16.13.60] (port=59834 helo=fedora.fritz.box) by esm19.siteground.biz with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.1) (envelope-from ) id 1v7KXH-00000000PLJ-0N73; Fri, 10 Oct 2025 21:20:23 +0000 From: Francesco Valla To: Matias Ezequiel Vara Larsen Cc: Marc Kleine-Budde , Paolo Abeni , Harald Mommer , Mikhail Golubev-Ciuchea , Wolfgang Grandegger , Eric Dumazet , Jakub Kicinski , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Damir Shaikhutdinov , linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, virtualization@lists.linux.dev, development@redaril.me Subject: Re: [PATCH v5] can: virtio: Initial virtio CAN driver. Date: Fri, 10 Oct 2025 23:20:22 +0200 Message-ID: <2318164.vFx2qVVIhK@fedora.fritz.box> In-Reply-To: References: <20240108131039.2234044-1-Mikhail.Golubev-Ciuchea@opensynergy.com> <2243144.yiUUSuA9gR@fedora.fritz.box> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - esm19.siteground.biz X-AntiAbuse: Original Domain - lists.linux.dev X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - valla.it X-Source: X-Source-Args: X-Source-Dir: X-SGantispam-id: c9a8f76ed2c6e40a816d5222f03a6910 AntiSpam-DLS: false AntiSpam-DLSP: AntiSpam-DLSRS: AntiSpam-TS: 1.0 CFBL-Address: feedback@antispam.mailspamprotection.com; report=arf CFBL-Feedback-ID: 1v7KXd-00000008iCo-2pk5-feedback@antispam.mailspamprotection.com Authentication-Results: outgoing.instance-europe-west4-x65p.prod.antispam.mailspamprotection.com; iprev=pass (214.173.214.35.bc.googleusercontent.com) smtp.remote-ip=35.214.173.214; auth=pass (LOGIN) smtp.auth=esm19.siteground.biz; dkim=pass header.d=valla.it header.s=default header.a=rsa-sha256; arc=none On Friday, 10 October 2025 at 17:46:25 Matias Ezequiel Vara Larsen wrote: > On Thu, Sep 11, 2025 at 10:59:40PM +0200, Francesco Valla wrote: > > Hello Mikhail, Harald, > > > > hoping there will be a v6 of this patch soon, a few comments: > > > > I am working on the v6 by addressing the comments in this thread. > > > On Monday, 8 January 2024 at 14:10:35 Mikhail Golubev-Ciuchea wrote: > > > > [...] > > > > > + > > > +/* virtio_can private data structure */ > > > +struct virtio_can_priv { > > > + struct can_priv can; /* must be the first member */ > > > + /* NAPI for RX messages */ > > > + struct napi_struct napi; > > > + /* NAPI for TX messages */ > > > + struct napi_struct napi_tx; > > > + /* The network device we're associated with */ > > > + struct net_device *dev; > > > + /* The virtio device we're associated with */ > > > + struct virtio_device *vdev; > > > + /* The virtqueues */ > > > + struct virtqueue *vqs[VIRTIO_CAN_QUEUE_COUNT]; > > > + /* I/O callback function pointers for the virtqueues */ > > > + vq_callback_t *io_callbacks[VIRTIO_CAN_QUEUE_COUNT]; > > > + /* Lock for TX operations */ > > > + spinlock_t tx_lock; > > > + /* Control queue lock. Defensive programming, may be not needed */ > > > + struct mutex ctrl_lock; > > > + /* Wait for control queue processing without polling */ > > > + struct completion ctrl_done; > > > + /* List of virtio CAN TX message */ > > > + struct list_head tx_list; > > > + /* Array of receive queue messages */ > > > + struct virtio_can_rx rpkt[128]; > > > > This array should probably be allocated dynamically at probe - maybe > > using a module parameter instead of a hardcoded value as length? > > > > If I allocate this array in probe(), I would not know sdu[] in advance > if I defined it as a flexible array. That made me wonder: can sdu[] be > defined as flexible array for rx? > > Thanks. > One thing that can be done is to define struct virtio_can_rx as: struct virtio_can_rx { #define VIRTIO_CAN_RX 0x0101 __le16 msg_type; __le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */ __u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */ __u8 padding; __le16 reserved_xl_priority; /* May be needed for CAN XL priority */ __le32 flags; __le32 can_id; __u8 sdu[] __counted_by(length); }; and then allocate the rpkt[] array using the maximum length for SDU: priv->rpkt = kcalloc(num_rx_buffers, sizeof(struct virtio_can_rx) + VIRTIO_CAN_MAX_DLEN, GFP_KERNEL); In this way, the size of each member of rpkt[] is known and is thus suitable for virtio_can_populate_vqs(). Regards, Francesco