Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp443048pxb; Thu, 5 Nov 2020 04:24:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQdfjY8luKt1FmflF+OlXUHhb7n7zWIhX9mlAPHHktxt2UvQclFL0oDvekm2Nc8Lalggkg X-Received: by 2002:a17:906:1352:: with SMTP id x18mr2006175ejb.476.1604579058271; Thu, 05 Nov 2020 04:24:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604579058; cv=none; d=google.com; s=arc-20160816; b=IzUDRj9uCIITCFSrGF6Ul0r7Z/nXHZhZLzWzAzFRqprEd17nqrmGvx4yN+/ZYgTyvu OTzYwYwj5u1nVjSLgB1XWIaa/5I8R6BLQZZC7d83+93p74gRAVbRrvsPmz1TAWjGgggm Thq0iNBNF4N4jYAKbl0Zg41LHFEQkccV+eAE4yDG2t8faqoA+1h7psBce5Lp/DNe4r1Z zLW/C3nfjWegeN/M90zuN2Q4oHmkKtH2nhMimLuh+u5MZCB1miFJ3ZszTEvg7z50nbal 1naH6TRa7dQRTnAYjSp80VwgpcNXFOueKBNpeUILbvVO4WkydbQv98IShBN8FOsmn+jV hMWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=0nJYS+gLcbGAg8faV3yhKQST5RGSsRVlarw3xnFKf0w=; b=xIHwmj7eIKiZkxDm1Ui7JV8FujF6eY0Xub4NGSrJRWrobgqiDCjsBh6Ki71FZ7rBO9 INZIdQy4qvBeVnPvrAF/JINsnnfZb3h+9CrDqtxd3+FijnkAdZkdGk8LeiCawiXz22xE PDOljAzssjFLV8cNF3KO3YF5Oa9nPmb12TrgeZNAVhnZTsJwstm6uRwNhnFUApVizliu XctTwTm4NXgR49acpdSa8/sKUwPC6ldkVsDizWUwQxiIcb+6BdbtyITVJ1+p4JRH65eW lLaeG0o0HqxpA/DTFk98L+fvN7ZNYlaxu0E75pTCGcWcEhY9vPPiA7i12fi3FZGzN3kj jkpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=lxTpiM3R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si940447ejs.498.2020.11.05.04.23.55; Thu, 05 Nov 2020 04:24:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=lxTpiM3R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730270AbgKEMWb (ORCPT + 99 others); Thu, 5 Nov 2020 07:22:31 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:28664 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgKEMWb (ORCPT ); Thu, 5 Nov 2020 07:22:31 -0500 Date: Thu, 05 Nov 2020 12:22:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1604578948; bh=0nJYS+gLcbGAg8faV3yhKQST5RGSsRVlarw3xnFKf0w=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=lxTpiM3R1RrlQ+Nje7lDzS1LL7Oj2UD1NwDWMZFVVvvWjnK6TmFvAqor8pqv9pLON On99SDlA0PZSGavBfuxhCbZRf0nhMX6jQvHOELgGjdUz/wfuMbM0Ahkv9O3Bev8TEa uDrc9piQvaGlnMsFQmL8VMiAvGicMReSIOA8YEImk+08/56HTrsx0tmGnPKQbeKTSM qy1G+dufn8a4SNY49uzzNPwMIbFps0TEsAgEAHuLUVKnrwpbVmzo1BwOiaGjgKodJj pwQXRyx4CZNq4NgPP16Fuxa7AQwFiwe9yzwFClIPWuiti49S/juZAtoVPxlZYDijJG KTnxpeVVQA7Ug== To: Jason Wang From: Alexander Lobakin Cc: Alexander Lobakin , Amit Shah , Arnd Bergmann , Greg Kroah-Hartman , Arnaud Pouliquen , Suman Anna , Mathieu Poirier , Bjorn Andersson , Ohad Ben-Cohen , "Michael S. Tsirkin" , virtualization@lists.linux-foundation.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Reply-To: Alexander Lobakin Subject: Re: [PATCH virtio] virtio: virtio_console: fix DMA memory allocation for rproc serial Message-ID: In-Reply-To: <004da56d-aad2-3b69-3428-02a14263289b@redhat.com> References: <004da56d-aad2-3b69-3428-02a14263289b@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Wang Date: Thu, 5 Nov 2020 11:10:24 +0800 Hi Jason, > On 2020/11/4 =E4=B8=8B=E5=8D=8811:31, Alexander Lobakin wrote: >> Since commit 086d08725d34 ("remoteproc: create vdev subdevice with >> specific dma memory pool"), every remoteproc has a DMA subdevice >> ("remoteprocX#vdevYbuffer") for each virtio device, which inherits >> DMA capabilities from the corresponding platform device. This allowed >> to associate different DMA pools with each vdev, and required from >> virtio drivers to perform DMA operations with the parent device >> (vdev->dev.parent) instead of grandparent (vdev->dev.parent->parent). >> >> virtio_rpmsg_bus was already changed in the same merge cycle with >> commit d999b622fcfb ("rpmsg: virtio: allocate buffer from parent"), >> but virtio_console did not. In fact, operations using the grandparent >> worked fine while the grandparent was the platform device, but since >> commit c774ad010873 ("remoteproc: Fix and restore the parenting >> hierarchy for vdev") this was changed, and now the grandparent device >> is the remoteproc device without any DMA capabilities. >> So, starting v5.8-rc1 the following warning is observed: >> >> [ 2.483925] ------------[ cut here ]------------ >> [ 2.489148] WARNING: CPU: 3 PID: 101 at kernel/dma/mapping.c:427 0x80= e7eee8 >> [ 2.489152] Modules linked in: virtio_console(+) >> [ 2.503737] virtio_rpmsg_bus rpmsg_core >> [ 2.508903] >> [ 2.528898] >> [ 2.913043] >> [ 2.914907] ---[ end trace 93ac8746beab612c ]--- >> [ 2.920102] virtio-ports vport1p0: Error allocating inbufs >> >> kernel/dma/mapping.c:427 is: >> >> WARN_ON_ONCE(!dev->coherent_dma_mask); >> >> obviously because the grandparent now is remoteproc dev without any >> DMA caps: >> >> [ 3.104943] Parent: remoteproc0#vdev1buffer, grandparent: remoteproc0 >> >> Fix this the same way as it was for virtio_rpmsg_bus, using just the >> parent device (vdev->dev.parent, "remoteprocX#vdevYbuffer") for DMA >> operations. >> This also allows now to reserve DMA pools/buffers for rproc serial >> via Device Tree. >> >> Fixes: c774ad010873 ("remoteproc: Fix and restore the parenting hierarch= y for vdev") >> Cc: stable@vger.kernel.org # 5.1+ >> Signed-off-by: Alexander Lobakin >> --- >> drivers/char/virtio_console.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console= .c >> index a2da8f768b94..1836cc56e357 100644 >> --- a/drivers/char/virtio_console.c >> +++ b/drivers/char/virtio_console.c >> @@ -435,12 +435,12 @@ static struct port_buffer *alloc_buf(struct virtio= _device *vdev, size_t buf_size >> =09=09/* >> =09=09 * Allocate DMA memory from ancestor. When a virtio >> =09=09 * device is created by remoteproc, the DMA memory is >> -=09=09 * associated with the grandparent device: >> -=09=09 * vdev =3D> rproc =3D> platform-dev. >> +=09=09 * associated with the parent device: >> +=09=09 * virtioY =3D> remoteprocX#vdevYbuffer. >> =09=09 */ >> -=09=09if (!vdev->dev.parent || !vdev->dev.parent->parent) >> +=09=09buf->dev =3D vdev->dev.parent; >> +=09=09if (!buf->dev) >> =09=09=09goto free_buf; >> -=09=09buf->dev =3D vdev->dev.parent->parent; > > > I wonder it could be the right time to introduce dma_dev for virtio > instead of depending on something magic via parent. This patch are meant to hit RC window and stable trees as a fix of the bug that is present since v5.8-rc1. So any new features are out of scope of this particular fix. The idea of DMAing through "dev->parent" is that "virtioX" itself is a logical dev, not the real one, but its parent *is*. This logic is used across the whole tree -- every subsystem creates its own logical device, but drivers should always use the backing PCI/platform/etc. devices for DMA operations, which represent the real hardware. > (Btw I don't even notice that there's transport specific code in virtio > console, it's better to avoid it) > > Thanks Thanks, Al >> >> =09=09/* Increase device refcnt to avoid freeing it */ >> =09=09get_device(buf->dev);