From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E027C433DB for ; Thu, 31 Dec 2020 07:12:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 924D822287 for ; Thu, 31 Dec 2020 07:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 924D822287 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D8E8B8D00B1; Thu, 31 Dec 2020 02:12:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3F6D8D00AE; Thu, 31 Dec 2020 02:12:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2DD68D00B1; Thu, 31 Dec 2020 02:12:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id A89A08D00AE for ; Thu, 31 Dec 2020 02:12:06 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 301808248047 for ; Thu, 31 Dec 2020 07:12:06 +0000 (UTC) X-FDA: 77652708252.26.lip07_380bed3274ab Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 07A4B1804B66A for ; Thu, 31 Dec 2020 07:12:06 +0000 (UTC) X-HE-Tag: lip07_380bed3274ab X-Filterd-Recvd-Size: 8391 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 31 Dec 2020 07:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609398724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KAcrvLM32Ywi1/Zvr81ALgzIuiKyK3fudx4Woo1wUAI=; b=am28qsOl9ZOPN/S6JxTBZukNTy7LpDrelYi87qdrosx9PzpfOubOhmxeN0JR2QHbU/2cNS YaUqkYJUFVRkqPifaVzRTrN5FdptEHsfm0PUKzlSydK5qHa305QwvsXwsugvMU6FHL5Tx1 Aoh0eu0L0aY8/W94b7xq41j6NsXWuhc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-527-T8AMp5lvMtiib-hqImZizQ-1; Thu, 31 Dec 2020 02:12:03 -0500 X-MC-Unique: T8AMp5lvMtiib-hqImZizQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A339A801AC2; Thu, 31 Dec 2020 07:12:00 +0000 (UTC) Received: from [10.72.12.236] (ovpn-12-236.pek2.redhat.com [10.72.12.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B32C10021B3; Thu, 31 Dec 2020 07:11:48 +0000 (UTC) Subject: Re: [RFC v2 09/13] vduse: Add support for processing vhost iotlb message To: Yongji Xie Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , sgarzare@redhat.com, Parav Pandit , akpm@linux-foundation.org, Randy Dunlap , Matthew Wilcox , viro@zeniv.linux.org.uk, axboe@kernel.dk, bcrl@kvack.org, corbet@lwn.net, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <20201222145221.711-1-xieyongji@bytedance.com> <2b24398c-e6d9-14ec-2c0d-c303d528e377@redhat.com> <1356137727.40748805.1609233068675.JavaMail.zimbra@redhat.com> <3fc6a132-9fc2-c4e2-7fb1-b5a8bfb771fa@redhat.com> <0885385c-ae46-158d-eabf-433ef8ecf27f@redhat.com> From: Jason Wang Message-ID: <79741d5d-0c35-ad1c-951a-41d8ab3b36a0@redhat.com> Date: Thu, 31 Dec 2020 15:11:46 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2020/12/31 =E4=B8=8B=E5=8D=882:52, Yongji Xie wrote: > On Thu, Dec 31, 2020 at 1:50 PM Jason Wang wrote: >> >> On 2020/12/31 =E4=B8=8B=E5=8D=881:15, Yongji Xie wrote: >>> On Thu, Dec 31, 2020 at 10:49 AM Jason Wang wro= te: >>>> On 2020/12/30 =E4=B8=8B=E5=8D=886:12, Yongji Xie wrote: >>>>> On Wed, Dec 30, 2020 at 4:41 PM Jason Wang wr= ote: >>>>>> On 2020/12/30 =E4=B8=8B=E5=8D=883:09, Yongji Xie wrote: >>>>>>> On Wed, Dec 30, 2020 at 2:11 PM Jason Wang = wrote: >>>>>>>> On 2020/12/29 =E4=B8=8B=E5=8D=886:26, Yongji Xie wrote: >>>>>>>>> On Tue, Dec 29, 2020 at 5:11 PM Jason Wang wrote: >>>>>>>>>> ----- Original Message ----- >>>>>>>>>>> On Mon, Dec 28, 2020 at 4:43 PM Jason Wang wrote: >>>>>>>>>>>> On 2020/12/28 =E4=B8=8B=E5=8D=884:14, Yongji Xie wrote: >>>>>>>>>>>>>> I see. So all the above two questions are because VHOST_IO= TLB_INVALIDATE >>>>>>>>>>>>>> is expected to be synchronous. This need to be solved by t= weaking the >>>>>>>>>>>>>> current VDUSE API or we can re-visit to go with descriptor= s relaying >>>>>>>>>>>>>> first. >>>>>>>>>>>>>> >>>>>>>>>>>>> Actually all vdpa related operations are synchronous in cur= rent >>>>>>>>>>>>> implementation. The ops.set_map/dma_map/dma_unmap should no= t return >>>>>>>>>>>>> until the VDUSE_UPDATE_IOTLB/VDUSE_INVALIDATE_IOTLB message= is replied >>>>>>>>>>>>> by userspace. Could it solve this problem? >>>>>>>>>>>> I was thinking whether or not we need to generate IOT= LB_INVALIDATE >>>>>>>>>>>> message to VDUSE during dma_unmap (vduse_dev_unmap_page). >>>>>>>>>>>> >>>>>>>>>>>> If we don't, we're probably fine. >>>>>>>>>>>> >>>>>>>>>>> It seems not feasible. This message will be also used in the >>>>>>>>>>> virtio-vdpa case to notify userspace to unmap some pages duri= ng >>>>>>>>>>> consistent dma unmapping. Maybe we can document it to make su= re the >>>>>>>>>>> users can handle the message correctly. >>>>>>>>>> Just to make sure I understand your point. >>>>>>>>>> >>>>>>>>>> Do you mean you plan to notify the unmap of 1) streaming DMA o= r 2) >>>>>>>>>> coherent DMA? >>>>>>>>>> >>>>>>>>>> For 1) you probably need a workqueue to do that since dma unma= p can >>>>>>>>>> be done in irq or bh context. And if usrspace does't do the un= map, it >>>>>>>>>> can still access the bounce buffer (if you don't zap pte)? >>>>>>>>>> >>>>>>>>> I plan to do it in the coherent DMA case. >>>>>>>> Any reason for treating coherent DMA differently? >>>>>>>> >>>>>>> Now the memory of the bounce buffer is allocated page by page in = the >>>>>>> page fault handler. So it can't be used in coherent DMA mapping c= ase >>>>>>> which needs some memory with contiguous virtual addresses. I can = use >>>>>>> vmalloc() to do allocation for the bounce buffer instead. But it = might >>>>>>> cause some memory waste. Any suggestion? >>>>>> I may miss something. But I don't see a relationship between the >>>>>> IOTLB_UNMAP and vmalloc(). >>>>>> >>>>> In the vmalloc() case, the coherent DMA page will be taken from the >>>>> memory allocated by vmalloc(). So IOTLB_UNMAP is not needed anymore >>>>> during coherent DMA unmapping because those vmalloc'ed memory which >>>>> has been mapped into userspace address space during initialization = can >>>>> be reused. And userspace should not unmap the region until we destr= oy >>>>> the device. >>>> Just to make sure I understand. My understanding is that IOTLB_UNMAP= is >>>> only needed when there's a change the mapping from IOVA to page. >>>> >>> Yes, that's true. >>> >>>> So if we stick to the mapping, e.g during dma_unmap, we just put IOV= A to >>>> free list to be used by the next IOVA allocating. IOTLB_UNMAP could = be >>>> avoided. >>>> >>>> So we are not limited by how the pages are actually allocated? >>>> >>> In coherent DMA cases, we need to return some memory with contiguous >>> kernel virtual addresses. That is the reason why we need vmalloc() >>> here. If we allocate the memory page by page, the corresponding kerne= l >>> virtual addresses in a contiguous IOVA range might not be contiguous. >> >> Yes, but we can do that as what has been done in the series >> (alloc_pages_exact()). Or do you mean it would be a little bit hard to >> recycle IOVA/pages here? >> > Yes, it might be hard to reuse the memory. For example, we firstly > allocate 1 IOVA/page during dma_map, then the IOVA is freed during > dma_unmap. Actually we can't reuse this single page if we need a > two-pages area in the next IOVA allocating. So the best way is using > IOTLB_UNMAP to free this single page during dma_unmap too. > > Thanks, > Yongji I get you now. Then I agree that let's go with IOTLB_UNMAP. Thanks >