linux-remoteproc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>,
	linux-remoteproc@vger.kernel.org,
	Ohad Ben-Cohen <ohad@wizery.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Liam Girdwood <liam.r.girdwood@linux.intel.com>
Subject: Re: [PATCH v2] rpmsg: virtio: add endianness conversions
Date: Wed, 1 Jul 2020 06:00:30 -0400	[thread overview]
Message-ID: <20200701055912-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20200630175057.GA3831001@xps15>

On Tue, Jun 30, 2020 at 11:50:57AM -0600, Mathieu Poirier wrote:
> On Tue, Jun 16, 2020 at 09:30:11AM +0200, Guennadi Liakhovetski wrote:
> > According to the VirtIO 1.0 spec data, sent over virtual queues must
> > be in little-endian format. Update the RPMsg VirtIO implementation
> > to enforce that but let legacy configurations continue use native
> > endianness.
> > 
> > Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
> > ---
> > 
> > v2: Following suggestions from Michael and Mathieu switch to using virtio16/32 
> > types and conversion functions.
> > 
> >  drivers/rpmsg/virtio_rpmsg_bus.c | 63 ++++++++++++++++++++++------------------
> >  1 file changed, 35 insertions(+), 28 deletions(-)
> > 
> > diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> > index 07d4f33..41025df 100644
> > --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> > +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> > @@ -11,6 +11,8 @@
> >  
> >  #define pr_fmt(fmt) "%s: " fmt, __func__
> >  
> > +#include <asm/byteorder.h>
> > +
> 
> Not sure about this header - what does it provide?
> 
> >  #include <linux/dma-mapping.h>
> >  #include <linux/idr.h>
> >  #include <linux/jiffies.h>
> > @@ -22,6 +24,7 @@
> >  #include <linux/scatterlist.h>
> >  #include <linux/slab.h>
> >  #include <linux/sched.h>
> > +#include <linux/types.h>
> 
> This too... It should be fine with linux/virtio_config.h below since it 
> already includes linux/virtio_byteorder.h

It's probably best to include linux/virtio_byteorder.h explicitly.

> Moreover, please send another revision that applies on rproc-next.  The third
> hunk in this patch doesn't apply.
> 
> With the above:
> 
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> >  #include <linux/virtio.h>
> >  #include <linux/virtio_ids.h>
> >  #include <linux/virtio_config.h>
> > @@ -84,11 +87,11 @@ struct virtproc_info {
> >   * Every message sent(/received) on the rpmsg bus begins with this header.
> >   */
> >  struct rpmsg_hdr {
> > -	u32 src;
> > -	u32 dst;
> > -	u32 reserved;
> > -	u16 len;
> > -	u16 flags;
> > +	__virtio32 src;
> > +	__virtio32 dst;
> > +	__virtio32 reserved;
> > +	__virtio16 len;
> > +	__virtio16 flags;
> >  	u8 data[];
> >  } __packed;
> >  
> > @@ -106,8 +109,8 @@ struct rpmsg_hdr {
> >   */
> >  struct rpmsg_ns_msg {
> >  	char name[RPMSG_NAME_SIZE];
> > -	u32 addr;
> > -	u32 flags;
> > +	__virtio32 addr;
> > +	__virtio32 flags;
> >  } __packed;
> >  
> >  /**
> > @@ -335,8 +338,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)
> >  		struct rpmsg_ns_msg nsm;
> >  
> >  		strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE);
> > -		nsm.addr = rpdev->ept->addr;
> > -		nsm.flags = RPMSG_NS_CREATE;
> > +		nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr);
> > +		nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_CREATE);
> >  
> >  		err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
> >  		if (err)
> > @@ -359,8 +362,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)
> >  		struct rpmsg_ns_msg nsm;
> >  
> >  		strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE);
> > -		nsm.addr = rpdev->ept->addr;
> > -		nsm.flags = RPMSG_NS_DESTROY;
> > +		nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr);
> > +		nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_DESTROY);
> >  
> >  		err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
> >  		if (err)
> > @@ -612,15 +615,15 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
> >  		}
> >  	}
> >  
> > -	msg->len = len;
> > +	msg->len = cpu_to_virtio16(vrp->vdev, len);
> >  	msg->flags = 0;
> > -	msg->src = src;
> > -	msg->dst = dst;
> > +	msg->src = cpu_to_virtio32(vrp->vdev, src);
> > +	msg->dst = cpu_to_virtio32(vrp->vdev, dst);
> >  	msg->reserved = 0;
> >  	memcpy(msg->data, data, len);
> >  
> >  	dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
> > -		msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
> > +		src, dst, len, msg->flags, msg->reserved);
> >  #if defined(CONFIG_DYNAMIC_DEBUG)
> >  	dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
> >  			 msg, sizeof(*msg) + msg->len, true);
> > @@ -704,13 +707,17 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
> >  {
> >  	struct rpmsg_endpoint *ept;
> >  	struct scatterlist sg;
> > +	unsigned int msg_len = virtio16_to_cpu(vrp->vdev, msg->len);
> >  	int err;
> >  
> >  	dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
> > -		msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
> > +		virtio32_to_cpu(vrp->vdev, msg->src),
> > +		virtio32_to_cpu(vrp->vdev, msg->dst), msg_len,
> > +		virtio16_to_cpu(vrp->vdev, msg->flags),
> > +		virtio32_to_cpu(vrp->vdev, msg->reserved));
> >  #if defined(CONFIG_DYNAMIC_DEBUG)
> >  	dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
> > -			 msg, sizeof(*msg) + msg->len, true);
> > +			 msg, sizeof(*msg) + msg_len, true);
> >  #endif
> >  
> >  	/*
> > @@ -718,15 +725,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
> >  	 * the reported payload length.
> >  	 */
> >  	if (len > vrp->buf_size ||
> > -	    msg->len > (len - sizeof(struct rpmsg_hdr))) {
> > -		dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
> > +	    msg_len > (len - sizeof(struct rpmsg_hdr))) {
> > +		dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg_len);
> >  		return -EINVAL;
> >  	}
> >  
> >  	/* use the dst addr to fetch the callback of the appropriate user */
> >  	mutex_lock(&vrp->endpoints_lock);
> >  
> > -	ept = idr_find(&vrp->endpoints, msg->dst);
> > +	ept = idr_find(&vrp->endpoints, virtio32_to_cpu(vrp->vdev, msg->dst));
> >  
> >  	/* let's make sure no one deallocates ept while we use it */
> >  	if (ept)
> > @@ -739,8 +746,8 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
> >  		mutex_lock(&ept->cb_lock);
> >  
> >  		if (ept->cb)
> > -			ept->cb(ept->rpdev, msg->data, msg->len, ept->priv,
> > -				msg->src);
> > +			ept->cb(ept->rpdev, msg->data, msg_len, ept->priv,
> > +				virtio32_to_cpu(vrp->vdev, msg->src));
> >  
> >  		mutex_unlock(&ept->cb_lock);
> >  
> > @@ -846,15 +853,15 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
> >  	/* don't trust the remote processor for null terminating the name */
> >  	msg->name[RPMSG_NAME_SIZE - 1] = '\0';
> >  
> > -	dev_info(dev, "%sing channel %s addr 0x%x\n",
> > -		 msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
> > -		 msg->name, msg->addr);
> > -
> >  	strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
> >  	chinfo.src = RPMSG_ADDR_ANY;
> > -	chinfo.dst = msg->addr;
> > +	chinfo.dst = virtio32_to_cpu(vrp->vdev, msg->addr);
> > +
> > +	dev_info(dev, "%sing channel %s addr 0x%x\n",


Let's not try tricks. Just %s and destroying/creating below.
Wastes 3 bytes of kernel space but is clearer.

> > +		 virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY ?
> > +		 "destroy" : "creat", msg->name, chinfo.dst);
> >  
> > -	if (msg->flags & RPMSG_NS_DESTROY) {
> > +	if (virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY) {
> >  		ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo);
> >  		if (ret)
> >  			dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret);
> > -- 
> > 1.9.3
> > 


  reply	other threads:[~2020-07-01 10:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08 12:39 [PATCH] rpmsg: virtio: add endianness conversions Guennadi Liakhovetski
2020-06-08 13:13 ` Michael S. Tsirkin
2020-06-15 20:47 ` Mathieu Poirier
2020-06-16  6:14   ` Guennadi Liakhovetski
2020-06-16  7:30     ` [PATCH v2] " Guennadi Liakhovetski
2020-06-30 17:50       ` Mathieu Poirier
2020-07-01 10:00         ` Michael S. Tsirkin [this message]
2020-07-06 12:47           ` Guennadi Liakhovetski
2020-07-06 12:56             ` Guennadi Liakhovetski
2020-07-06 13:38               ` [PATCH v3] " Guennadi Liakhovetski
2020-07-07 15:11                 ` Arnaud POULIQUEN
2020-07-07 15:34                   ` [PATCH v4] " Guennadi Liakhovetski
2020-07-07 15:38                     ` Mathieu Poirier
2020-07-10  6:20                       ` Guennadi Liakhovetski
2020-07-21  8:56                       ` [PATCH RESEND " Guennadi Liakhovetski
2020-07-21 10:04                         ` Michael S. Tsirkin
2020-07-22  3:39                         ` Bjorn Andersson
2020-07-22  4:00                         ` patchwork-bot+linux-remoteproc
2020-07-27 16:07                         ` Michael S. Tsirkin
2020-07-27 16:09                           ` Mathieu Poirier
2020-07-28  9:51                             ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200701055912-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=guennadi.liakhovetski@linux.intel.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=ohad@wizery.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).