From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 DF56E3F39C9 for ; Wed, 20 May 2026 17:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779299541; cv=none; b=m1jQVmqs5lZireRO0Awb3V58NMTvDfnhl1Gdl8T277bXM8iTUfPVQ6UHA4sOzBBT32oPQyRRF1N9hN2tStH1FAfjteLwD6GOCqjcobZQgmYQeRxPyQ0vg9QAMbT5HQBeLsdiGl3Gpf04hUYQSGjwhgzi0fbrFOiFqsMD1FANSKI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779299541; c=relaxed/simple; bh=yUYQ7RmeBPSZ5QIVBpoHb3L2lfSe+sROOt2kPJCJqX4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sjpDVJw3f4wwbGRsq69G+aPDxkTk3ni0sdlU8yXAf0rgjG0VtTl0lpLd7nC5jirdRDIRHSw7RebBoF6JSUfdkxJJ/0sWwCcnbRZQqfpgJICkOaLw9HEaCespSLMvDzLlZ8dg0OGBf9qr3jZPNS3JF627Yk33Xu/JKfIBUosT5ZY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=N5cU4+sd; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="N5cU4+sd" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-c795f441ff7so4177710a12.2 for ; Wed, 20 May 2026 10:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779299539; x=1779904339; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=TKV+NtiCl8YF4YdmlzAi7pGrLz4Pr8ApNbd04TJvVDY=; b=N5cU4+sd2Ai+XSGtSNooQ0NxW5KcjbgC3GoE+yNmccpCAG1QvoZnY34CdPNbi1B7xh mTe0jkVY3946pjKSs3pv0c+hFi4ZBQ6WJbIQ2n4AJzhXXqHLia97ECZsHg9ciPvTZ2FC 7F4uR4ou8KuqZqn++oH6iHn/STsB0c1SOmr4zyBqwm897iZsr4621lQad4WHvgT/aky2 ha+aJcw85YCFsLSy2kI4Rk47KtTQ2mrAoXo7/917XP/F+XVayrP9RNMYgkXwlz/wIGIE 1QW/v0UjWP2kJQHOxHvveNmgcfPheUIPduMWFE4vbm/355XFROgMtxUasq5Oix1+LvmP rOEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779299539; x=1779904339; h=in-reply-to:content-transfer-encoding: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=TKV+NtiCl8YF4YdmlzAi7pGrLz4Pr8ApNbd04TJvVDY=; b=kVQ2ieZm/WV0EFtoIi0Ad/Bt2iGL2T5Xo0T7gCgkkEGml++QFgV6W4xbLPBEXdL11N CuCa9NttkxhE6Fzy6mKURFjymPVh2EUViuwK9HPcGhgUn/adecGED8A7vJSuwNPprVms 45127u4Mpnx+cU5RUmTXiIdydd/pBXrX/gzZ2dtN2uqYPLixw4mKIXpY6vD4W8Y134LE 1/b6llZ4qQKIg5NtY2J27UcHjkwqsfAlUjbANz+06kDt/F2tPPG+sZfiyb/CK7nVt4QI hc83/Eb/Hkn+/tgL13Mz7MXKZz1II9T8UJQvYaZYT/u9ntzNvqYwJ6bI3tHMzdRLpAr+ ZeZA== X-Forwarded-Encrypted: i=1; AFNElJ8jEx+bhd+WYn+jAo+9IRUbrq8+QinHnGWbff5IY1ikG6389W2s+2M2lAjGGa5GqHtZsLUfPWoCXgM5HEw=@vger.kernel.org X-Gm-Message-State: AOJu0YxtqN3wSTWT2Wy3k1v4k/hrUO2iCEcBoxbHukPcg068wEWan8Hj jogOgevaw5PVOcgV9S0Or6MUF95IHVyYxu+EQzi1VLp6FM2r5TBsN8vc19+AqYbwpjAwWq9rfcm tYgf1 X-Gm-Gg: Acq92OGMXU/t9nwJnBfR1eeUocSCbcXUaWkLWr5tytlzPXshAwXz4AuAufSAv9MPe4r Qz1ErBqjpqWCd/O4FMeAU6uCZnxQuIIw5bXcsuk27PMLZ6dTa+OVAI+uqnAnVd1dkYmlaqTaAVK tfIyk28nxjBduoAM4s5Gh8O8qLyn4PLLcXv1vv8V9XWPpaBSU3lnQMc6CKsn8s/hOGtWtnPWiB+ L6TxjX6A1V8tVK/ngoxWcdVeM+mzlTbfQrJYIRt0wOzH7gGy3KcjbhAQ1RfaxpLS42iP4heSQ5V r8RcbO8l+LYIqoTPR/s2KbgUheJvurDVagu6mmq3vmIFCQgOWJBcLh5Dp2dWRTUG9IwrGF/+l/3 v/hlWt0lHSsmNYS3whJcwqOL8mEBw6cA3P+g3lFatXn63MC65xpXoYjo7z+mGT3tE8+R4LFcV8a 654pcLEbx2UM6+NKmKX53DzamCAw== X-Received: by 2002:a05:6a20:2454:b0:3a3:addc:8f47 with SMTP id adf61e73a8af0-3b22ec64553mr28508767637.42.1779299521316; Wed, 20 May 2026 10:52:01 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:87f:b712:e05a:7e28]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c82bb07d2f2sm19827943a12.10.2026.05.20.10.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 10:52:00 -0700 (PDT) Date: Wed, 20 May 2026 11:51:58 -0600 From: Mathieu Poirier To: tanmay.shah@amd.com Cc: Arnaud POULIQUEN , andersson@kernel.org, linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org Subject: Re: [PATCH v2 2/3] rpmsg: virtio_rpmsg_bus: get buffer size from config space Message-ID: References: <20260429161052.528015-1-tanmay.shah@amd.com> <20260429161052.528015-3-tanmay.shah@amd.com> <0ea5801b-c435-4f67-b811-aed696bd64b7@foss.st.com> <313c02dd-0a19-48d4-bdaf-c53e2be1131b@amd.com> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <313c02dd-0a19-48d4-bdaf-c53e2be1131b@amd.com> On Wed, May 20, 2026 at 09:55:33AM -0500, Shah, Tanmay wrote: > > > On 5/20/2026 2:44 AM, Arnaud POULIQUEN wrote: > > > > > > On 5/19/26 19:36, Mathieu Poirier wrote: > >> On Wed, Apr 29, 2026 at 09:10:52AM -0700, Tanmay Shah wrote: > >>> 512 bytes isn't always suitable for all case, let firmware > >>> maker decide the best value from resource table. > >>> enable by VIRTIO_RPMSG_F_BUFSZ feature bit. > >>> > >>> Signed-off-by: Tanmay Shah > >>> --- > >>> > >>> Test done: > >>>    - Verify this patch works with the existing firmware > >>>    - Verify this patch works with the firmware that configures > >>>      differt tx & rx buf size > >>> > >>> Changes in v2: > >>>    - %s/sbuf_size/tx_buf_size/ > >>>    - %s/rbuf_size/rx_buf_size/ > >>>    - fix typo > >>>    - do not use ALIGN on buf size, rely on allocator > >>>    - make err msg more explicit, %s/vdev config:/bad vdev config/ > >>>    - fix license and add AMD copyrights in the header virtio_rpmsg.h > >>>    - Assign bit 1 to VIRTIO_RPMSG_F_BUFSZ feature > >>>    - use __virtio32 over __u32 > >>>    - add version field to virtio rpmsg config structure > >>>    - move linux/virtio_rpmsg.h to linux/rpmsg/virtio_rpmsg.h > >>> > >>>   drivers/rpmsg/virtio_rpmsg_bus.c   | 70 ++++++++++++++++++++++-------- > >>>   include/linux/rpmsg/virtio_rpmsg.h | 27 ++++++++++++ > >>>   2 files changed, 79 insertions(+), 18 deletions(-) > >>>   create mode 100644 include/linux/rpmsg/virtio_rpmsg.h > >>> > >>> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/ > >>> virtio_rpmsg_bus.c > >>> index e59d8cf9b975..8116d94413cc 100644 > >>> --- a/drivers/rpmsg/virtio_rpmsg_bus.c > >>> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c > >>> @@ -20,6 +20,7 @@ > >>>   #include > >>>   #include > >>>   #include > >>> +#include > >>>   #include > >>>   #include > >>>   #include > >>> @@ -39,7 +40,8 @@ > >>>    * @tx_bufs:    kernel address of tx buffers > >>>    * @num_rx_buf:    total number of buffers for rx > >>>    * @num_tx_buf:    total number of buffers for tx > >>> - * @buf_size:    size of one rx or tx buffer > >>> + * @rx_buf_size: size of one rx buffer > >>> + * @tx_buf_size: size of one tx buffer > >>>    * @last_sbuf:    index of last tx buffer used > >>>    * @bufs_dma:    dma base addr of the buffers > >>>    * @tx_lock:    protects svq and tx_bufs, to allow concurrent senders. > >>> @@ -59,7 +61,8 @@ struct virtproc_info { > >>>       void *rx_bufs, *tx_bufs; > >>>       unsigned int num_rx_buf; > >>>       unsigned int num_tx_buf; > >>> -    unsigned int buf_size; > >>> +    unsigned int rx_buf_size; > >>> +    unsigned int tx_buf_size; > >>>       int last_sbuf; > >>>       dma_addr_t bufs_dma; > >>>       struct mutex tx_lock; > >>> @@ -68,9 +71,6 @@ struct virtproc_info { > >>>       wait_queue_head_t sendq; > >>>   }; > >>>   -/* The feature bitmap for virtio rpmsg */ > >>> -#define VIRTIO_RPMSG_F_NS    0 /* RP supports name service > >>> notifications */ > >>> - > >>>   /** > >>>    * struct rpmsg_hdr - common header for all rpmsg messages > >>>    * @src: source address > >>> @@ -128,7 +128,7 @@ struct virtio_rpmsg_channel { > >>>    * processor. > >>>    */ > >>>   #define MAX_RPMSG_NUM_BUFS    (256) > >>> -#define MAX_RPMSG_BUF_SIZE    (512) > >>> +#define DEFAULT_RPMSG_BUF_SIZE    (512) > >>>     /* > >>>    * Local addresses are dynamically allocated on-demand. > >>> @@ -444,7 +444,7 @@ static void *get_a_tx_buf(struct virtproc_info *vrp) > >>>         /* either pick the next unused tx buffer */ > >>>       if (vrp->last_sbuf < vrp->num_tx_buf) > >>> -        ret = vrp->tx_bufs + vrp->buf_size * vrp->last_sbuf++; > >>> +        ret = vrp->tx_bufs + vrp->tx_buf_size * vrp->last_sbuf++; > >>>       /* or recycle a used one */ > >>>       else > >>>           ret = virtqueue_get_buf(vrp->svq, &len); > >>> @@ -514,7 +514,7 @@ static int rpmsg_send_offchannel_raw(struct > >>> rpmsg_device *rpdev, > >>>        * messaging), or to improve the buffer allocator, to support > >>>        * variable-length buffer sizes. > >>>        */ > >>> -    if (len > vrp->buf_size - sizeof(struct rpmsg_hdr)) { > >>> +    if (len > vrp->tx_buf_size - sizeof(struct rpmsg_hdr)) { > >>>           dev_err(dev, "message is too big (%d)\n", len); > >>>           return -EMSGSIZE; > >>>       } > >>> @@ -647,7 +647,7 @@ static ssize_t virtio_rpmsg_get_mtu(struct > >>> rpmsg_endpoint *ept) > >>>       struct rpmsg_device *rpdev = ept->rpdev; > >>>       struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); > >>>   -    return vch->vrp->buf_size - sizeof(struct rpmsg_hdr); > >>> +    return vch->vrp->tx_buf_size - sizeof(struct rpmsg_hdr); > >>>   } > >>>     static int rpmsg_recv_single(struct virtproc_info *vrp, struct > >>> device *dev, > >>> @@ -673,7 +673,7 @@ static int rpmsg_recv_single(struct virtproc_info > >>> *vrp, struct device *dev, > >>>        * We currently use fixed-sized buffers, so trivially sanitize > >>>        * the reported payload length. > >>>        */ > >>> -    if (len > vrp->buf_size || > >>> +    if (len > vrp->rx_buf_size || > >>>           msg_len > (len - sizeof(struct rpmsg_hdr))) { > >>>           dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, > >>> msg_len); > >>>           return -EINVAL; > >>> @@ -706,7 +706,7 @@ static int rpmsg_recv_single(struct virtproc_info > >>> *vrp, struct device *dev, > >>>           dev_warn_ratelimited(dev, "msg received with no recipient\n"); > >>>         /* publish the real size of the buffer */ > >>> -    rpmsg_sg_init(&sg, msg, vrp->buf_size); > >>> +    rpmsg_sg_init(&sg, msg, vrp->rx_buf_size); > >>>         /* add the buffer back to the remote processor's virtqueue */ > >>>       err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); > >>> @@ -824,6 +824,7 @@ static int rpmsg_probe(struct virtio_device *vdev) > >>>       int err = 0, i; > >>>       size_t total_buf_space; > >>>       bool notify; > >>> +    u16 version; > >>>         vrp = kzalloc_obj(*vrp); > >>>       if (!vrp) > >>> @@ -855,9 +856,41 @@ static int rpmsg_probe(struct virtio_device *vdev) > >>>       else > >>>           vrp->num_tx_buf = MAX_RPMSG_NUM_BUFS; > >>>   -    vrp->buf_size = MAX_RPMSG_BUF_SIZE; > >>> +    /* > >>> +     * If VIRTIO_RPMSG_F_BUFSZ feature is supported, then configure buf > >>> +     * size from virtio device config space from the resource table. > >>> +     * If the feature is not supported, then assign default buf size. > >>> +     */ > >>> +    if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_BUFSZ)) { > >>> +        /* note: virtio_rpmsg_config is defined from remote view */ > >>> +        version = 0; > >>> +        virtio_cread(vdev, struct virtio_rpmsg_config, > >>> +                 version, &version); > >>> +        virtio_cread(vdev, struct virtio_rpmsg_config, > >>> +                 txbuf_size, &vrp->rx_buf_size); > >>> +        virtio_cread(vdev, struct virtio_rpmsg_config, > >>> +                 rxbuf_size, &vrp->tx_buf_size); > >>> + > >> > >> A check is also needed to make sure the version received from the > >> resource table > >> is '0'. > > I think we should start with versaion = 1. So, can I check the version > number for 1 ? I've been thinking about that and I agree it should be something else than '0'. Since we have a u16, I suggest to make bit 15-8 a magic number (surprise us!) and bit 7-0 the actual version number. > > >> > >>> +        /* The buffers must hold at least the rpmsg header */ > >>> +        if (vrp->rx_buf_size < sizeof(struct rpmsg_hdr) || > >>> +            vrp->tx_buf_size < sizeof(struct rpmsg_hdr)) { > >>> +            dev_err(&vdev->dev, > >>> +                "bad vdev config: rx buf sz = %d, tx buf sz = %d\n", > >>> +                vrp->rx_buf_size, vrp->tx_buf_size); > >>> +            err = -EINVAL; > >>> +            goto vqs_del; > >>> +        } > >>> + > >>> +        dev_dbg(&vdev->dev, > >>> +            "vdev config: version=%d, rx buf sz = 0x%x, tx buf sz = > >>> 0x%x\n", > >>> +            version, vrp->rx_buf_size, vrp->tx_buf_size); > >>> +    } else { > >>> +        vrp->rx_buf_size = DEFAULT_RPMSG_BUF_SIZE; > >>> +        vrp->tx_buf_size = DEFAULT_RPMSG_BUF_SIZE; > >>> +    } > >>>   -    total_buf_space = (vrp->num_rx_buf + vrp->num_tx_buf) * vrp- > >>> >buf_size; > >>> +    total_buf_space = (vrp->num_rx_buf * vrp->rx_buf_size) + > >>> +              (vrp->num_tx_buf * vrp->tx_buf_size); > >>>         /* allocate coherent memory for the buffers */ > >>>       bufs_va = dma_alloc_coherent(vdev->dev.parent, > >>> @@ -875,14 +908,14 @@ static int rpmsg_probe(struct virtio_device *vdev) > >>>       vrp->rx_bufs = bufs_va; > >>>         /* and second part is dedicated for TX */ > >>> -    vrp->tx_bufs = bufs_va + vrp->num_rx_buf * vrp->buf_size; > >>> +    vrp->tx_bufs = bufs_va + (vrp->num_rx_buf * vrp->rx_buf_size); > >>>         /* set up the receive buffers */ > >>>       for (i = 0; i < vrp->num_rx_buf; i++) { > >>>           struct scatterlist sg; > >>> -        void *cpu_addr = vrp->rx_bufs + i * vrp->buf_size; > >>> +        void *cpu_addr = vrp->rx_bufs + i * vrp->rx_buf_size; > >>>   -        rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size); > >>> +        rpmsg_sg_init(&sg, cpu_addr, vrp->rx_buf_size); > >>>             err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, > >>>                         GFP_KERNEL); > >>> @@ -965,8 +998,8 @@ static int rpmsg_remove_device(struct device > >>> *dev, void *data) > >>>   static void rpmsg_remove(struct virtio_device *vdev) > >>>   { > >>>       struct virtproc_info *vrp = vdev->priv; > >>> -    unsigned int num_bufs = vrp->num_rx_buf + vrp->num_tx_buf; > >>> -    size_t total_buf_space = num_bufs * vrp->buf_size; > >>> +    size_t total_buf_space = (vrp->num_rx_buf * vrp->rx_buf_size) + > >>> +                 (vrp->num_tx_buf * vrp->tx_buf_size); > >>>       int ret; > >>>         virtio_reset_device(vdev); > >>> @@ -992,6 +1025,7 @@ static struct virtio_device_id id_table[] = { > >>>     static unsigned int features[] = { > >>>       VIRTIO_RPMSG_F_NS, > >>> +    VIRTIO_RPMSG_F_BUFSZ, > >>>   }; > >>>     static struct virtio_driver virtio_ipc_driver = { > >>> diff --git a/include/linux/rpmsg/virtio_rpmsg.h b/include/linux/ > >>> rpmsg/virtio_rpmsg.h > >>> new file mode 100644 > >>> index 000000000000..285918be68b9 > >>> --- /dev/null > >>> +++ b/include/linux/rpmsg/virtio_rpmsg.h > >>> @@ -0,0 +1,27 @@ > >>> +/* SPDX-License-Identifier: GPL-2.0 */ > >>> +/* > >>> + * Copyright (C) Pinecone Inc. 2019 > >>> + * Copyright (C) Xiang Xiao > >>> + * Copyright (C) Advanced Micro Devices, Inc. > >>> + */ > >>> + > >>> +#ifndef _LINUX_VIRTIO_RPMSG_H > >>> +#define _LINUX_VIRTIO_RPMSG_H > >>> + > >>> +#include > >>> +#include > >>> + > >>> +/* The feature bitmap for virtio rpmsg */ > >>> +#define VIRTIO_RPMSG_F_NS    0 /* RP supports name service > >>> notifications */ > >>> +#define VIRTIO_RPMSG_F_BUFSZ    1 /* RP get buffer size from config > >>> space */ > >>> + > >>> +struct virtio_rpmsg_config { > >>> +    __virtio16 version; > >>> +    /* The tx/rx individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */ > >>> +    __virtio32 txbuf_size; > >>> +    __virtio32 rxbuf_size; > >>> +    __virtio32 reserved[14]; /*: Reserve for the future use */ > >> > >> 66 byte for the configuratio space?  I'm puzzled about the > >> reserved[14], how did > >> you come up with that number? > > I kept the reserved bytes from the original series as it is. The > original series did not contain version field. With version I don't > think we need reserved field at all. At best, if we want to append > padding bytes, then I think __virtio16 reserved; makes sense. That will > make the structure aligned to 4 byte. > > > > > Is it useful to define the reserved field? > > I think reserved field is only useful to keep the structure size aligned > to 4 bytes. > > > The version should allow us to determine the content. > > Correct, but I think the structure can be aligned if used correct > reserved bytes. > > > An other solution is to introduce a'size' field to determine the size of > > the structure: > > I think, the resource table already contains config_len field which is > size of the structure: > > https://github.com/torvalds/linux/blob/27fa82620cbaa89a7fc11ac3057701d598813e87/include/linux/remoteproc.h#L275 > > > struct virtio_rpmsg_config { > >     __virtio16 version; > >     __virtio16 size; /* size of the configuration space */ > >     /* The tx/rx individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */ > >     __virtio32 txbuf_size; > >     __virtio32 rxbuf_size; > >     __u8 private[0]; /* customized config */ > > Do we need customized config? I think I should remove this comment from > the original patch as well. > > Thanks, > Tanmay > > > }; > > > >> > >> The rest looks good to me. > >> > > > > Looks good to me too. > > > > Thanks, > > Arnaud > > > >>> +    /* Put the customize config here */ > >>> +} __packed; > >>> + > >>> +#endif /* _LINUX_VIRTIO_RPMSG_H */ > >>> --  > >>> 2.34.1 > >>> > > >