From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Sjur Brændeland" <sjurbren@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
Amit Shah <amit.shah@redhat.com>
Subject: Re: [RFC 1/2] virtio_console: Add support for DMA memory allocation
Date: Mon, 3 Sep 2012 23:27:37 +0300 [thread overview]
Message-ID: <20120903202737.GD6181@redhat.com> (raw)
In-Reply-To: <CAJK669bkHHMAPYMEr22-6uOwfgJv1uKTbzNBQVVCq=OooExC0g@mail.gmail.com>
On Mon, Sep 03, 2012 at 04:57:45PM +0200, Sjur Brændeland wrote:
> Hi Michael,
>
> > How does access to descriptors work in this setup?
>
> When the ring is setup by remoteproc the descriptors are
> also allocated using dma_alloc_coherent().
>
> >> -static void free_buf(struct port_buffer *buf)
> >> +/* Allcoate data buffer from DMA memory if requested */
> >
> > typo
>
> Thanks.
>
> >> +static inline void *
> >> +alloc_databuf(struct virtio_device *vdev, size_t size, dma_addr_t *dma_handle,
> >> + gfp_t flag)
> >> {
> >> - kfree(buf->buf);
> >> +#ifdef CONFIG_HAS_DMA
> >> + if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_DMA_MEM)) {
> >> + struct device *dev = &vdev->dev;
> >> + /*
> >> + * Allocate DMA memory from ancestors. Finding the ancestor
> >> + * is a bit quirky when DMA_MEMORY_INCLUDES_CHILDREN is not
> >> + * implemented.
> >> + */
> >> + dev = dev->parent ? dev->parent : dev;
> >> + dev = dev->parent ? dev->parent : dev;
> >> + return dma_alloc_coherent(dev, size, dma_handle, flag);
> >> + }
> >> +#endif
> >
> > Are these ifdefs really needed? If DMA_MEM is set,
> > can't we use dma_alloc_coherent
> > unconditionally?
>
> If an architecture do not support DMA you will get
> a link error: "unknown symbol" for dma_alloc_coherent.
>
> Regards,
> Sjur
Yes, it even seems intentional.
But I have a question: can the device work without DMA?
Does not VIRTIO_CONSOLE_F_DMA_MEM mean dma api is required?
If yes you should just fail load.
Also let's add a wrapper at top of file so ifdefs
do not litter the code like this. For example:
#ifdef CONFIG_HAS_DMA
#define VIRTIO_CONSOLE_HAS_DMA (1)
#else
#define VIRTIO_CONSOLE_HAS_DMA (0)
#endif
Now use if instead of ifdef.
--
MST
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Sjur Brændeland" <sjurbren@gmail.com>
Cc: Amit Shah <amit.shah@redhat.com>,
linux-kernel@vger.kernel.org,
Rusty Russell <rusty@rustcorp.com.au>,
Ohad Ben-Cohen <ohad@wizery.com>,
Linus Walleij <linus.walleij@linaro.org>,
virtualization@lists.linux-foundation.org
Subject: Re: [RFC 1/2] virtio_console: Add support for DMA memory allocation
Date: Mon, 3 Sep 2012 23:27:37 +0300 [thread overview]
Message-ID: <20120903202737.GD6181@redhat.com> (raw)
In-Reply-To: <CAJK669bkHHMAPYMEr22-6uOwfgJv1uKTbzNBQVVCq=OooExC0g@mail.gmail.com>
On Mon, Sep 03, 2012 at 04:57:45PM +0200, Sjur Brændeland wrote:
> Hi Michael,
>
> > How does access to descriptors work in this setup?
>
> When the ring is setup by remoteproc the descriptors are
> also allocated using dma_alloc_coherent().
>
> >> -static void free_buf(struct port_buffer *buf)
> >> +/* Allcoate data buffer from DMA memory if requested */
> >
> > typo
>
> Thanks.
>
> >> +static inline void *
> >> +alloc_databuf(struct virtio_device *vdev, size_t size, dma_addr_t *dma_handle,
> >> + gfp_t flag)
> >> {
> >> - kfree(buf->buf);
> >> +#ifdef CONFIG_HAS_DMA
> >> + if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_DMA_MEM)) {
> >> + struct device *dev = &vdev->dev;
> >> + /*
> >> + * Allocate DMA memory from ancestors. Finding the ancestor
> >> + * is a bit quirky when DMA_MEMORY_INCLUDES_CHILDREN is not
> >> + * implemented.
> >> + */
> >> + dev = dev->parent ? dev->parent : dev;
> >> + dev = dev->parent ? dev->parent : dev;
> >> + return dma_alloc_coherent(dev, size, dma_handle, flag);
> >> + }
> >> +#endif
> >
> > Are these ifdefs really needed? If DMA_MEM is set,
> > can't we use dma_alloc_coherent
> > unconditionally?
>
> If an architecture do not support DMA you will get
> a link error: "unknown symbol" for dma_alloc_coherent.
>
> Regards,
> Sjur
Yes, it even seems intentional.
But I have a question: can the device work without DMA?
Does not VIRTIO_CONSOLE_F_DMA_MEM mean dma api is required?
If yes you should just fail load.
Also let's add a wrapper at top of file so ifdefs
do not litter the code like this. For example:
#ifdef CONFIG_HAS_DMA
#define VIRTIO_CONSOLE_HAS_DMA (1)
#else
#define VIRTIO_CONSOLE_HAS_DMA (0)
#endif
Now use if instead of ifdef.
--
MST
next prev parent reply other threads:[~2012-09-03 20:27 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 13:51 [RFC 1/2] virtio_console: Add support for DMA memory allocation sjur.brandeland
2012-09-03 13:51 ` [RFC 2/2] virtio_console: Add feature to disable console port sjur.brandeland
2012-09-03 13:51 ` sjur.brandeland
2012-09-03 14:30 ` [RFC 1/2] virtio_console: Add support for DMA memory allocation Michael S. Tsirkin
2012-09-03 14:30 ` Michael S. Tsirkin
2012-09-03 14:57 ` Sjur Brændeland
2012-09-03 14:57 ` Sjur Brændeland
2012-09-03 20:27 ` Michael S. Tsirkin [this message]
2012-09-03 20:27 ` Michael S. Tsirkin
2012-09-04 6:07 ` Rusty Russell
2012-09-04 6:07 ` Rusty Russell
2012-09-05 13:00 ` Sjur Brændeland
2012-09-05 13:00 ` Sjur Brændeland
2012-09-05 14:35 ` Michael S. Tsirkin
2012-09-05 14:35 ` Michael S. Tsirkin
2012-09-05 18:15 ` Sjur Brændeland
2012-09-05 18:15 ` Sjur Brændeland
2012-09-05 19:16 ` Michael S. Tsirkin
2012-09-05 19:16 ` Michael S. Tsirkin
2012-09-07 9:24 ` Sjur Brændeland
2012-09-07 9:24 ` Sjur Brændeland
2012-09-04 11:28 ` Sjur Brændeland
2012-09-04 11:28 ` Sjur Brændeland
2012-09-04 13:50 ` Michael S. Tsirkin
2012-09-04 13:50 ` Michael S. Tsirkin
2012-09-04 16:58 ` Sjur Brændeland
2012-09-04 16:58 ` Sjur Brændeland
2012-09-04 18:55 ` Michael S. Tsirkin
2012-09-04 18:55 ` Michael S. Tsirkin
2012-09-06 2:04 ` Rusty Russell
2012-09-06 2:04 ` Rusty Russell
2012-09-06 5:27 ` Michael S. Tsirkin
2012-09-06 5:27 ` Michael S. Tsirkin
2012-09-10 22:11 ` Michael S. Tsirkin
2012-09-10 22:11 ` Michael S. Tsirkin
2012-09-12 6:24 ` Rusty Russell
2012-09-12 6:24 ` Rusty Russell
2012-09-07 8:35 ` Sjur Brændeland
2012-09-07 8:35 ` Sjur Brændeland
2012-09-16 9:44 ` [PATCH repost] virtio: don't crash when device is buggy Michael S. Tsirkin
2012-09-16 9:44 ` Michael S. Tsirkin
2012-09-17 4:27 ` Rusty Russell
2012-09-17 4:27 ` Rusty Russell
2012-09-18 22:24 ` Michael S. Tsirkin
2012-09-18 22:24 ` Michael S. Tsirkin
2012-09-19 4:10 ` Rusty Russell
2012-09-19 4:10 ` Rusty Russell
-- strict thread matches above, loose matches on Subject: below --
2012-09-03 13:51 [RFC 1/2] virtio_console: Add support for DMA memory allocation sjur.brandeland
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=20120903202737.GD6181@redhat.com \
--to=mst@redhat.com \
--cc=amit.shah@redhat.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sjurbren@gmail.com \
--cc=virtualization@lists.linux-foundation.org \
/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.