Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5041902pxv; Wed, 28 Jul 2021 01:28:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMy3u9kvdFGj3Mc8Gif3wae4lkeXk4dFLmG1hxTyXsTpVhM4zDdWxE16/OVsugwcjkn3sJ X-Received: by 2002:a05:6402:3507:: with SMTP id b7mr8836674edd.293.1627460923610; Wed, 28 Jul 2021 01:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627460923; cv=none; d=google.com; s=arc-20160816; b=iRI2h86ePUipcIBfpD0M7/I5LqL20CUyPLYo4e8YdwSgx8Ysx2o4NYHdZXpCtuRXf3 6l4iXPn9A7VkQkEkwsZ52ag8hRb1b7VTOTIM44cIPFMMBMG/7tH6sm+0Q5uuWvov/Yfs WnJ/gv7SkBGszKIL+v4DG14LWqbIMDViVjMbRTC6WC6Lp53AUzcypTxqEbciU5K8XIqd 72s32gUSzq7LD+TBcyXC5pceVUSWhpvmNvE3iGA1oK5nipgUFtb2ZiAdN2tUTEJM4i4W Usse94IjUnF4IQ/pcLYajTsqUzkraf9h5SQ4IEPnfTwrGUz6/vcQZHvQSv/EDQqFSbAC dcpQ== 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=ZMGwKyu8jqV5qxQj5VyYFQaR0FbEKXSg7AZgwn+oyRU=; b=Uu9284uN0wSYD9XLubkUj8JerPsGU8xFzjQo+pg04GBkYtIlIEAape34Vqpu+R6vV9 l+eIXUYw+1W7MyKEzwLGb1PlldbOGMPXfDXRoqGyASjes2b5oyEttR+rqBlStAM3OHca 7985C7Tt4xW3DHjrEA0BNDUVd3TbvmHTPV5lC6wm3XlO4oPbapMpQ3NcSKMMX8YV7M9T 1cECJriVk9bQIAOci0QDC9kS35dcn0AZ+n7CICHVL8rQthT3CkEbLr5GQDlvadmgHY49 96EVEFvAeEwYBG5ihECVVwT53ovM4tApasA8SHKHs43OeKyTm1oPHq6Wn9QORlb9K9wM k+tQ== 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 lv9si1694261ejb.470.2021.07.28.01.28.20; Wed, 28 Jul 2021 01:28:43 -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 S234892AbhG1I1E (ORCPT + 99 others); Wed, 28 Jul 2021 04:27:04 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:45957 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234495AbhG1I1E (ORCPT ); Wed, 28 Jul 2021 04:27:04 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UhEA0ga_1627460820; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0UhEA0ga_1627460820) by smtp.aliyun-inc.com(127.0.0.1); Wed, 28 Jul 2021 16:27:01 +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: <0d03a42b-b46c-408f-17a4-b6c094c0c29e@linux.alibaba.com> Date: Wed, 28 Jul 2021 16:27:00 +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 在 2021/7/28 下午3:25, Arnd Bergmann 写道: > On Wed, Jul 28, 2021 at 4:59 AM Xianting Tian > 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