All of lore.kernel.org
 help / color / mirror / Atom feed
From: Loic Pallardy <loic.pallardy@st.com>
To: bjorn.andersson@linaro.org, ohad@wizery.com,
	lee.jones@linaro.org, patrice.chotard@st.com
Cc: loic.pallardy@st.com, linux-remoteproc@vger.kernel.org,
	kernel@stlinux.com, Ludovic Barre <ludovic.barre@st.com>
Subject: [PATCH v1 2/6] rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid kernel address
Date: Wed, 7 Dec 2016 21:35:37 +0100	[thread overview]
Message-ID: <1481142941-15616-3-git-send-email-loic.pallardy@st.com> (raw)
In-Reply-To: <1481142941-15616-1-git-send-email-loic.pallardy@st.com>

To specify memory for remoteproc, we declare (dma_declare_coherent_memory())
an area which is ioremap'ed to the vmalloc area.  However, this address is
not a kernel address so virt_addr_valid(buf) fails.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
---
 drivers/rpmsg/virtio_rpmsg_bus.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 1f6dfc6..0810d1f 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -195,6 +195,29 @@ static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
 };
 
 /**
+ * rpmsg_sg_init - initialize scatterlist according to cpu address location
+ * @sg: scatterlist to fill
+ * @cpu_addr: virtual address of the buffer
+ * @len: buffer length
+ *
+ * An internal function filling scatterlist according to virtual address
+ * location (in vmalloc or in kernel).
+ */
+static void
+rpmsg_sg_init(struct scatterlist *sg, void *cpu_addr, unsigned int len)
+{
+	if (is_vmalloc_addr(cpu_addr)) {
+		sg_init_table(sg, 1);
+		sg_set_page(sg, vmalloc_to_page(cpu_addr), len,
+			    offset_in_page(cpu_addr));
+	} else {
+		WARN_ON(!virt_addr_valid(cpu_addr));
+		sg_init_one(sg, cpu_addr, len);
+	}
+}
+
+
+/**
  * __ept_release() - deallocate an rpmsg endpoint
  * @kref: the ept's reference count
  *
@@ -606,7 +629,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
 			 msg, sizeof(*msg) + msg->len, true);
 #endif
 
-	sg_init_one(&sg, msg, sizeof(*msg) + len);
+	rpmsg_sg_init(&sg, msg, sizeof(*msg) + len);
 
 	mutex_lock(&vrp->tx_lock);
 
@@ -731,7 +754,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
 		dev_warn(dev, "msg received with no recipient\n");
 
 	/* publish the real size of the buffer */
-	sg_init_one(&sg, msg, vrp->buf_size);
+	rpmsg_sg_init(&sg, msg, vrp->buf_size);
 
 	/* add the buffer back to the remote processor's virtqueue */
 	err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
@@ -913,7 +936,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
 		struct scatterlist sg;
 		void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
 
-		sg_init_one(&sg, cpu_addr, vrp->buf_size);
+		rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size);
 
 		err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr,
 					  GFP_KERNEL);
-- 
1.9.1

  parent reply	other threads:[~2016-12-07 20:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 20:35 [PATCH v1 0/6] rtio_rpmsg: make rpmsg channel configurable Loic Pallardy
2016-12-07 20:35 ` [PATCH v1 1/6] rpmsg: virtio_rpmsg: set rpmsg_buf_size customizable Loic Pallardy
2017-01-14  1:39   ` Suman Anna
2017-01-14 19:23     ` Loic PALLARDY
2016-12-07 20:35 ` Loic Pallardy [this message]
2017-01-14  1:44   ` [PATCH v1 2/6] rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid kernel address Suman Anna
2016-12-07 20:35 ` [PATCH v1 3/6] include: virtio_rpmsg: add virtio rpmsg configuration structure Loic Pallardy
2016-12-08 21:59   ` Wendy Liang
2016-12-14 11:24     ` Loic PALLARDY
2016-12-07 20:35 ` [PATCH v1 4/6] rpmsg: virtio_rpmsg: get buffer configuration from virtio Loic Pallardy
2017-01-14  2:26   ` Suman Anna
2017-01-14 19:30     ` Loic PALLARDY
2016-12-07 20:35 ` [PATCH v1 5/6] rpmsg: virtio_rpmsg: don't allocate buffer if provided by low level driver Loic Pallardy
2017-01-14  2:37   ` Suman Anna
2017-01-14 19:26     ` Loic PALLARDY
2016-12-07 20:35 ` [PATCH v1 6/6] rpmsg: virtio_rpmsg: set buffer configuration to virtio Loic Pallardy
2017-01-14  2:41   ` Suman Anna
2017-01-14 19:36     ` Loic PALLARDY
2017-01-16 15:59       ` Suman Anna
2017-01-13 13:25 ` [PATCH v1 0/6] rtio_rpmsg: make rpmsg channel configurable loic pallardy
2017-01-14  1:36   ` Suman Anna
2017-01-14 19:20     ` Loic PALLARDY
2017-01-16 16:02       ` Suman Anna
2017-02-08 16:35         ` Loic PALLARDY

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=1481142941-15616-3-git-send-email-loic.pallardy@st.com \
    --to=loic.pallardy@st.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=kernel@stlinux.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=ludovic.barre@st.com \
    --cc=ohad@wizery.com \
    --cc=patrice.chotard@st.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.