Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4878877pxv; Tue, 27 Jul 2021 20:01:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoHEJUWFFWQoR41sgT6JfbOqoPPTld/yrs0NLT+WczFhafqZql3JeqCiw1SnsDuXJt1u3Q X-Received: by 2002:a17:906:7951:: with SMTP id l17mr25106146ejo.529.1627441264981; Tue, 27 Jul 2021 20:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627441264; cv=none; d=google.com; s=arc-20160816; b=Z3cIchpYFpglLupKfLaPDsgX/NUTvE8TXHhaedUxwx0dER4aj4BVAWrttaOidvV9oB 48D9aOoJ3Jb5RxFlzD+54ytk0LA0WSw8ME6aSH7srPWyiv7xKuDwCKDL+pJLzwoRXFQn JxUuB3SLppcBCI7H0hA4bBcZggRlCnCF9Djt91k6/6L/MB1DGVRlCxkYZwlE2zXM87o5 T6lLbz2+MQzftBXhSg0ibSnxZGsNJXAvyvuSohdIVIk80J09mO4Qr388mMKyldGVf4rI bTtp+x9vH4KFIQFg204s1hupOR0i2xHslL+a483n2AaZhziZpIsBFvbN9ngWVKZh8+3x 6gVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=9v3yzx9azCk8RFm/rCR0ADK3vJ6DH7b+c3dJjBzp65Q=; b=MPNI2UMMWxK3XOpPnq4Byscxu0lWo4xwbSYp1tIGZno8LRw113qHSMEuA5RFO3sGkH cqQwNsej7nZauZGammpSS7JSu3969NO4JDVb4jhdGXfgeWZXSNdueJ18c/942nXTFWmN LDBvfg/zFpNFMqu6TGaGnCtw/+nUu41sjatKiJgUAGEd6jE5JlD3F7QgX1hEN5h49joj ny+fObf+TxXDYrq/jiHTlodGan+UmO0Q4yCvonu/h2GV8t2UxCoWYBnvlGHQmfYPEXiw zjYM5Ht6TxVDfhtr/+o/quc4hH6qVAByxKQRPZaPtNa7m9uTnMq096Y03xUjT4r1UUms DC1w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq16si4546744edb.303.2021.07.27.20.00.40; Tue, 27 Jul 2021 20:01:04 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233537AbhG1C6d (ORCPT + 99 others); Tue, 27 Jul 2021 22:58:33 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:40943 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbhG1C6b (ORCPT ); Tue, 27 Jul 2021 22:58:31 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R491e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UhCdVMj_1627441106; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0UhCdVMj_1627441106) by smtp.aliyun-inc.com(127.0.0.1); Wed, 28 Jul 2021 10:58:28 +0800 Subject: Re: [PATCH] virtio-console: avoid DMA from vmalloc area To: Arnd Bergmann Cc: Amit Shah , gregkh , Omar Sandoval , "open list:DRM DRIVER FOR QEMU'S CIRRUS DEVICE" , Linux Kernel Mailing List References: <20210727131217.15092-1-xianting.tian@linux.alibaba.com> From: Xianting Tian Message-ID: Date: Wed, 28 Jul 2021 10:58:26 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. 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);     } 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);         …     } 在 2021/7/27 下午9:18, Arnd Bergmann 写道: > On Tue, Jul 27, 2021 at 3:13 PM Xianting Tian > wrote: >> @@ -1127,13 +1128,18 @@ static int put_chars(u32 vtermno, const char *buf, int count) >> if (!port) >> return -EPIPE; >> >> - data = kmemdup(buf, count, GFP_ATOMIC); >> - if (!data) >> - return -ENOMEM; >> + if (is_vmalloc_addr(buf)) { >> + data = kmemdup(buf, count, GFP_ATOMIC); > What about buffers in .data? If those are in a loadable module, I guess you have > the same problem as with vmalloc() and vmap(). > > is_vmalloc_or_module_addr() would take care of both, not sure if there are > other examples that don't work. In theory it could be ioremap(), kmap_atomic() > or fixmap as well, but those seem less likely to matter here. > > Arnd