mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xianting Tian <xianting.tian@linux.alibaba.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Amit Shah <amit@kernel.org>, gregkh <gregkh@linuxfoundation.org>,
	Omar Sandoval <osandov@fb.com>,
	"open list:DRM DRIVER FOR QEMU'S CIRRUS DEVICE" 
	<virtualization@lists.linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] virtio-console: avoid DMA from vmalloc area
Date: Wed, 28 Jul 2021 16:27:00 +0800	[thread overview]
Message-ID: <0d03a42b-b46c-408f-17a4-b6c094c0c29e@linux.alibaba.com> (raw)
In-Reply-To: <CAK8P3a1O02Ho2dM3F+bUXf9Ze8uRKYzY5fFmRGpszUXg_nrH4w@mail.gmail.com>


在 2021/7/28 下午3:25, Arnd Bergmann 写道:
> On Wed, Jul 28, 2021 at 4:59 AM Xianting Tian
> <xianting.tian@linux.alibaba.com> wrote:
>> Arnd, thanks for your quick reply,
>>
>> As we know put_chars() of virtio-console is registered to hvc framework.
>> I go throughed the code, actually there are totally three places that
>> put_chars() is called in hvc driver,  but only 1 has issue which is
>> fixed by commit c4baad5029.
> Ah, good. Knowing what the callers are definitely helps. ;-)
>
>> So I think the scenario that the buf is from "ioremap(), kmap_atomic() ,
>> fixmap, loadable module" doesn't exist for virtio-console.
>> If there is something wrong about above description, please correct me,
>> thanks.
> The description is good then.
>
>> Three places that put_chars() is called in hvc driver:
>> 1, it is on stack buf,  it is not ok for dma
>>       hvc_console_print():
>>           char c[N_OUTBUF] __ALIGNED__;
>>           cons_ops[index]->put_chars(vtermnos[index], c, i);
>>
>> 2, just one byte, no issue for dma
>>       static void hvc_poll_put_char(struct tty_driver *driver, int line,
>> char ch)
>>       {
>>           struct tty_struct *tty = driver->ttys[0];
>>           struct hvc_struct *hp = tty->driver_data;
>>           int n;
>>
>>           do {
>>               n = hp->ops->put_chars(hp->vtermno, &ch, 1);
>>           } while (n <= 0);
>>       }
> This is actually the same as the first, taking the address of a
> function argument forces it onto the stack.
>
>> 3,  hp->outbuf is allocated in hvc_alloc() via kzalloc(), no issue for dma
>>       static int hvc_push(struct hvc_struct *hp)
>>       {
>>           int n;
>>
>>           n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
>>           …
>>       }
> ok.
>
> I have a new question then: are there any other hvc backends that do
> DMA, or is the virtio-console driver the only one? If there are any others,
> I think this should better be fixed in the hvc framework, by changing it
> to never pass stack data into the put_chars() function in the first place.
>
> It may be possible to just use the 'hp->n_outbuf' buffer in all three cases.

thanks,

I checked several hvc backends, like drivers/tty/hvc/hvc_riscv_sbi.c, 
drivers/tty/hvc/hvc_iucv.c, drivers/tty/hvc/hvc_rtas.c, they don't use dma.

I not finished all hvc backends check yet. But I think even if all hvc 
backends don't use dma currently, it is still possible that the hvc 
backend using dma will be added in the furture.

So I agree with you it should better be fixed in the hvc framework, 
solve the issue in the first place.

Looking forward to your reply.

>
>         Arnd

  reply	other threads:[~2021-07-28  8:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 13:12 Xianting Tian
2021-07-27 13:18 ` Arnd Bergmann
2021-07-28  2:58   ` Xianting Tian
2021-07-28  7:25     ` Arnd Bergmann
2021-07-28  8:27       ` Xianting Tian [this message]
2021-07-28  9:01         ` Arnd Bergmann
2021-07-28  9:10           ` Xianting Tian

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=0d03a42b-b46c-408f-17a4-b6c094c0c29e@linux.alibaba.com \
    --to=xianting.tian@linux.alibaba.com \
    --cc=amit@kernel.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=osandov@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®