From patchwork Wed Jan 10 13:16:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10155145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9CAD760231 for ; Wed, 10 Jan 2018 13:17:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D63A27F94 for ; Wed, 10 Jan 2018 13:17:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81F9E28497; Wed, 10 Jan 2018 13:17:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05D3C27F94 for ; Wed, 10 Jan 2018 13:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754734AbeAJNRl (ORCPT ); Wed, 10 Jan 2018 08:17:41 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:45988 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754705AbeAJNRV (ORCPT ); Wed, 10 Jan 2018 08:17:21 -0500 Received: by mail-pg0-f67.google.com with SMTP id c194so9805502pga.12 for ; Wed, 10 Jan 2018 05:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=1C8m8tAsJTps51iaVDGtT8Do75NU1baOd0UoCB7k/g4=; b=s0xS+uCMUDgsAiPcjK/LAinOubAiG16aKOYIdiSme2pCIKZA/M9GCVa2ES8mFkpI/W LsJgy7C+/yZrryd4nF94Qkgw30IeqXGqM+etM8i9CxwjpV+25+pmhvIe0Eif/mFoe7bV ZPdILGrUmRmBeNh/6NtUb5yF4ZHt4nVtJWhUK5mIzlHGibT+8GJWoVlBhi/obLt4zQXq lgenn9q3L0BbyRJkTTQrZg3asLiOQsFWwMsvuMU+X4Uo9uWBiW1Fyf/uAWzZlHk52sGn A/W6xNhxqf1hBFhgKf2Pu5JfN5JltaoGfKaZ8KWCEws5XD9vR0YYb35+5/YmPUKcoxiP ZhDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1C8m8tAsJTps51iaVDGtT8Do75NU1baOd0UoCB7k/g4=; b=Oh6q8dLivMTcBUijfYznPwiKRHq5i2YBUkG8oLZ3tv56RwesFjPOMxI5O8Oa8Ld/T7 EL8+To6vyhhHVpcDzdLxAGgzLcuZOKtGtPnkjPMD/Ec9nhdMKlMXcL1rA5S3Ncxr7inH FHxKzVhVoHXgM9UPUEYIA3UB3J5D6WY68r9p/h3e9ehac8Kd4c/9Ilfh7s28ezvXJ+51 t7xwThbNKl3v+oWHojOfTt7bYz/9+BrmlJSkSf1bdIqmODpK5qeUNLKaJGhCQD62qDjF UY7OkdNjz9p9u3pD9NQYDOJ+8kDqwvDRTWIObXnT0zsMiZE0VIe/HeEmSEb+tPjoA0w3 xb8g== X-Gm-Message-State: AKGB3mL/rHtAe9IhI3QsJ+43Fyx/g+xTLIVyw5knJ/0nx/ytvCOSpkTq Ug055otwgRzSJlAaHh/4h3WG0/lz X-Google-Smtp-Source: ACJfBot5cbBf79Dw0qfSGAljYyJ8HCKTOTv3d6D5xMlGXzUH+ND4UzZZwyDzibPHuLr2RMpk5V8jhw== X-Received: by 10.98.182.4 with SMTP id j4mr16911541pff.220.1515590234251; Wed, 10 Jan 2018 05:17:14 -0800 (PST) Received: from anup-ubuntu64.dlink.router ([122.171.99.18]) by smtp.googlemail.com with ESMTPSA id m13sm26251177pgs.77.2018.01.10.05.17.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jan 2018 05:17:13 -0800 (PST) From: Anup Patel To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Anup Patel , stable@vger.kernel.org Subject: [PATCH RESEND] rpmsg: virtio_rpmsg_bus: fix rpmsg_probe() for virtio-mmio transport Date: Wed, 10 Jan 2018 18:46:57 +0530 Message-Id: <1515590217-24256-1-git-send-email-anup@brainfault.org> X-Mailer: git-send-email 2.7.4 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When virtio-rpmsg device is provided via virtio-mmio transport, the dma_alloc_coherent() (called by rpmsg_probe()) fails on ARM/ARM64 systems because "vdev->dev.parent->parent" device is used as parameter to dma_alloc_coherent(). The "vdev->dev.parent->parent" device represents underlying remoteproc platform device when virtio-rpmsg device is provided via virtio-remoteproc transport. When virtio-rpmsg device is provided via virtio-mmio transport, the "vdev->dev.parent->parent" device represents the parent device of virtio-mmio platform device and dma_alloc_coherent() fails for this device because generally there is no corresponding platform device and dma_ops are not setup for "vdev->dev.parent->parent". This patch fixes dma_alloc_coherent() usage in rpmsg_probe() by trying dma_alloc_coherent() with "vdev->dev.parent" device when it fails with "vdev->dev.parent->parent" device. Fixes: b5ab5e24e960 ("remoteproc: maintain a generic child device for each rproc") Signed-off-by: Anup Patel Cc: stable@vger.kernel.org --- drivers/rpmsg/virtio_rpmsg_bus.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 82b8300..7f8710a 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -64,6 +64,7 @@ struct virtproc_info { struct virtio_device *vdev; struct virtqueue *rvq, *svq; + struct device *bufs_dev; void *rbufs, *sbufs; unsigned int num_bufs; unsigned int buf_size; @@ -924,9 +925,16 @@ static int rpmsg_probe(struct virtio_device *vdev) total_buf_space, &vrp->bufs_dma, GFP_KERNEL); if (!bufs_va) { - err = -ENOMEM; - goto vqs_del; - } + bufs_va = dma_alloc_coherent(vdev->dev.parent, + total_buf_space, &vrp->bufs_dma, + GFP_KERNEL); + if (!bufs_va) { + err = -ENOMEM; + goto vqs_del; + } else + vrp->bufs_dev = vdev->dev.parent; + } else + vrp->bufs_dev = vdev->dev.parent->parent; dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n", bufs_va, &vrp->bufs_dma); @@ -988,7 +996,7 @@ static int rpmsg_probe(struct virtio_device *vdev) return 0; free_coherent: - dma_free_coherent(vdev->dev.parent->parent, total_buf_space, + dma_free_coherent(vrp->bufs_dev, total_buf_space, bufs_va, vrp->bufs_dma); vqs_del: vdev->config->del_vqs(vrp->vdev); @@ -1023,7 +1031,7 @@ static void rpmsg_remove(struct virtio_device *vdev) vdev->config->del_vqs(vrp->vdev); - dma_free_coherent(vdev->dev.parent->parent, total_buf_space, + dma_free_coherent(vrp->bufs_dev, total_buf_space, vrp->rbufs, vrp->bufs_dma); kfree(vrp);