Skip to content

Commit 9dd87c2

Browse files
ydrallapandersson
authored andcommitted
rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid kernel address
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> Acked-by: Patrice Chotard <patrice.chotard@st.com> Tested-by: Suman Anna <s-anna@ti.com> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
1 parent f93848f commit 9dd87c2

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

‎drivers/rpmsg/virtio_rpmsg_bus.c‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = {
194194
.trysend_offchannel = virtio_rpmsg_trysend_offchannel,
195195
};
196196

197+
/**
198+
* rpmsg_sg_init - initialize scatterlist according to cpu address location
199+
* @sg: scatterlist to fill
200+
* @cpu_addr: virtual address of the buffer
201+
* @len: buffer length
202+
*
203+
* An internal function filling scatterlist according to virtual address
204+
* location (in vmalloc or in kernel).
205+
*/
206+
static void
207+
rpmsg_sg_init(struct scatterlist *sg, void *cpu_addr, unsigned int len)
208+
{
209+
if (is_vmalloc_addr(cpu_addr)) {
210+
sg_init_table(sg, 1);
211+
sg_set_page(sg, vmalloc_to_page(cpu_addr), len,
212+
offset_in_page(cpu_addr));
213+
} else {
214+
WARN_ON(!virt_addr_valid(cpu_addr));
215+
sg_init_one(sg, cpu_addr, len);
216+
}
217+
}
218+
197219
/**
198220
* __ept_release() - deallocate an rpmsg endpoint
199221
* @kref: the ept's reference count
@@ -612,7 +634,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
612634
msg, sizeof(*msg) + msg->len, true);
613635
#endif
614636

615-
sg_init_one(&sg, msg, sizeof(*msg) + len);
637+
rpmsg_sg_init(&sg, msg, sizeof(*msg) + len);
616638

617639
mutex_lock(&vrp->tx_lock);
618640

@@ -736,7 +758,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
736758
dev_warn(dev, "msg received with no recipient\n");
737759

738760
/* publish the real size of the buffer */
739-
sg_init_one(&sg, msg, vrp->buf_size);
761+
rpmsg_sg_init(&sg, msg, vrp->buf_size);
740762

741763
/* add the buffer back to the remote processor's virtqueue */
742764
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
@@ -920,7 +942,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
920942
struct scatterlist sg;
921943
void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
922944

923-
sg_init_one(&sg, cpu_addr, vrp->buf_size);
945+
rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size);
924946

925947
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr,
926948
GFP_KERNEL);

0 commit comments

Comments
 (0)