Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp448362ybx; Wed, 30 Oct 2019 18:06:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiZccsivuqv+zUNTIsEpTSxOevwxD+JKWHT+bfapzYxwcBMoBwFdDO2caLQy15sPbna11l X-Received: by 2002:aa7:d3cd:: with SMTP id o13mr2967867edr.267.1572483960995; Wed, 30 Oct 2019 18:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572483960; cv=none; d=google.com; s=arc-20160816; b=ULfJi4G4mm3x7+/qmxGIk5sj16QPYKuwkD8OYxIpdlmnAZ5Wym0Zp1wCDsn9Id4J8X AfpYu3gxNG2C5UOx3XzbeC9+WYxIVbKWDzleTt89EFm4j17f6pJhZbuALWspfL6lLSJW wZYcTEMBHoKuZ56HigCwgTKhhNl7FlqQv8V62ZHddRpWr8oscZl+OZlFyEvAbTiVZfFz mSjEktWYp3GpW/2LR1wdBCLuCS2YySbC9YSjAIW6OIpwc7OrYSyH8iGZgASBMfWFxoC1 kYWW5utxKS4E+HwTC3CudZVE9GebQRryV2xlCNqqv4ANTqp4Uk8Rn5BSBRhFFmUUMr6t PoTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=aQDvoiizFwVElu/+JB2LeJEv2uD96Wkmo0qAhVBooQc=; b=x6QTr4WRkmvYVDHxHi8gyudZkPKbI2S96Gd+JasFmKsO21at14KkkqKP8Bbly9ndCB 3RWL9DS+Fs3zsjHwYz0gBMmWNp8MP/CNUki9HBzQTsx4LSj8UkFyfu/cEodmkQibrp/K 5iwSAsO/N2CUx8fYDsPlXVI87SqE/LcrGCfdiuUIT+zWOw1VHGQifNl+GLkD4Pnfl5IO dCu8LVFvr+VqHrE5YGFZQvf5nPZwotCXZaYI/wL7TF5oQxDcqMQAdemt0doPAGYyjO4u 0DyMdC8FKoyPxB0uvxyyeKbmyO992yS8+vH2EsZQuTy4yn1fFW/LBlAzJTF2TpF5fRNg r0sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=MWJCdQBY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e24si2770086ede.392.2019.10.30.18.05.37; Wed, 30 Oct 2019 18:06:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=MWJCdQBY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbfJaAOg (ORCPT + 99 others); Wed, 30 Oct 2019 20:14:36 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:17399 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726683AbfJaAOf (ORCPT ); Wed, 30 Oct 2019 20:14:35 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 30 Oct 2019 17:14:39 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 30 Oct 2019 17:14:33 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 30 Oct 2019 17:14:33 -0700 Received: from rcampbell-dev.nvidia.com (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 31 Oct 2019 00:14:31 +0000 Subject: Re: [PATCH v3 3/3] mm/hmm/test: add self tests for HMM To: Jason Gunthorpe CC: Jerome Glisse , John Hubbard , Christoph Hellwig , "linux-rdma@vger.kernel.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" References: <20191023195515.13168-1-rcampbell@nvidia.com> <20191023195515.13168-4-rcampbell@nvidia.com> <20191029175837.GS22766@mellanox.com> <3ffecdc6-625f-ebea-8fb4-984fe6ca90f3@nvidia.com> <20191029231255.GX22766@mellanox.com> From: Ralph Campbell X-Nvconfidentiality: public Message-ID: Date: Wed, 30 Oct 2019 17:14:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20191029231255.GX22766@mellanox.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1572480879; bh=aQDvoiizFwVElu/+JB2LeJEv2uD96Wkmo0qAhVBooQc=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=MWJCdQBYV5wFB7p92/YoCvnFMvaW5Z0IBrW0xE5hxmWN/aZqJV2A1iGIWrIIsAsV8 5VbUwe/ni8bh+UdPANC3o40XMQmti2jPniyG+kfKXopV2o92ZsH5WErJY0bTCkzbaq Uv2d9ejyWGNHiGyn+USoMYCdZGkZjaf1R1TKpH3UAg2J2+/Vihh1G5u/xoT1MrefGQ afjBFP8F4s4qdv4EK4vntC3rY/27ToshvjCbJrew79wgoor/yef38armEhFyhEvIAO ruemKtXzYLn3lyFMiFLsaf9rlg03HrmcImjcDUjHfi1/TdGEdrlMlA1xfixlHdVgdW DsWeazFXfVoKA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/29/19 4:12 PM, Jason Gunthorpe wrote: > On Tue, Oct 29, 2019 at 02:16:05PM -0700, Ralph Campbell wrote: > >>> Frankly, I'm not super excited about the idea of a 'test driver', it >>> seems more logical for testing to have some way for a test harness to >>> call hmm_range_fault() under various conditions and check the results? >> >> test_vmalloc.sh at least uses a test module(s). > > Well, that is good, is it also under drivers/char? It kind feels like > it should not be there... I think most of the test modules live in lib/ but I wasn't sure that was the right place for the HMM test driver. If you think that is better, I can easily move it. >>> It seems especially over-complicated to use a full page table layout >>> for this, wouldn't something simple like an xarray be good enough for >>> test purposes? >> >> Possibly. A page table is really just a lookup table from virtual address >> to pfn/page. Part of the rationale was to mimic what a real device >> might do. > > Well, but the details of the page table layout don't see really > important to this testing, IMHO. One problem with XArray is that on 32-bit machines the value would need to be u64 to hold a pfn which won't fit in a ULONG_MAX. I guess we could make the driver 64-bit only. >>>> + for (addr = start; addr < end; ) { >>>> + long count; >>>> + >>>> + next = min(addr + (ARRAY_SIZE(pfns) << PAGE_SHIFT), end); >>>> + range.start = addr; >>>> + range.end = next; >>>> + >>>> + down_read(&mm->mmap_sem); > > Also, did we get a mmget() before doing this down_read? > >>>> + >>>> + ret = hmm_range_register(&range, &dmirror->mirror); >>>> + if (ret) { >>>> + up_read(&mm->mmap_sem); >>>> + break; >>>> + } >>>> + >>>> + if (!hmm_range_wait_until_valid(&range, >>>> + DMIRROR_RANGE_FAULT_TIMEOUT)) { >>>> + hmm_range_unregister(&range); >>>> + up_read(&mm->mmap_sem); >>>> + continue; >>>> + } >>>> + >>>> + count = hmm_range_fault(&range, 0); >>>> + if (count < 0) { >>>> + ret = count; >>>> + hmm_range_unregister(&range); >>>> + up_read(&mm->mmap_sem); >>>> + break; >>>> + } >>>> + >>>> + if (!hmm_range_valid(&range)) { >>> >>> There is no 'driver lock' being held here, how does this work? >>> Shouldn't it hold dmirror->mutex for this sequence? >> >> I have a modified version of this driver that's based on your series >> removing hmm_mirror_register() which uses a mutex. >> Otherwise, it looks similar to the changes in nouveau. > > Well, that locking pattern is required even for original hmm calls.. Will be fixed in v4. > >>>> +static int dmirror_read(struct dmirror *dmirror, >>>> + struct hmm_dmirror_cmd *cmd) >>>> +{ >>> >>> Why not just use pread()/pwrite() for this instead of an ioctl? >> >> pread()/pwrite() could certainly be implemented. >> I think the idea was that the read/write is actually the "device" >> doing read/write and making that clearly different from a program >> reading/writing the device. Also, the ioctl() allows information >> about what faults or events happened during the operation. I only >> have number of pages and number of page faults returned at the moment, >> but one of Jerome's version of this driver had other counters being >> returned. > > Makes sense I guess > >>>> +static struct platform_driver dmirror_device_driver = { >>>> + .probe = dmirror_probe, >>>> + .remove = dmirror_remove, >>>> + .driver = { >>>> + .name = "HMM_DMIRROR", >>>> + }, >>>> +}; >>> >>> This presence of a platform_driver and device is very confusing. I'm >>> sure Greg KH would object to this as a misuse of platform drivers. >>> >>> A platform device isn't needed to create a char dev, so what is this for? >> >> The devm_request_free_mem_region() and devm_memremap_pages() calls for >> creating the ZONE_DEVICE private pages tie into the devm* clean up framework. >> I thought a platform_driver was the simplest way to also be able to call >> devm_add_action_or_reset() to clean up on module unload and be compatible >> with the private page clean up. > > IIRC Christoph recently fixed things so there was a non devm version > of these functions. Certainly we should not be making fake > platform_devices just to call devm. > > There is also a struct device inside the cdev, maybe that could be > arrange to be devm compatible if it was *really* needed. Will be fixed in v4. >>>> diff --git a/include/Kbuild b/include/Kbuild >>>> index ffba79483cc5..6ffb44a45957 100644 >>>> +++ b/include/Kbuild >>>> @@ -1063,6 +1063,7 @@ header-test- += uapi/linux/coda_psdev.h >>>> header-test- += uapi/linux/errqueue.h >>>> header-test- += uapi/linux/eventpoll.h >>>> header-test- += uapi/linux/hdlc/ioctl.h >>>> +header-test- += uapi/linux/hmm_dmirror.h >>> >>> Why? This list should only be updated if the header is broken in some >>> way. >> >> Should this be in include/linux/ instead? >> I wasn't sure where the "right" place was to put the header. > > No, it is right, it just shouldn't be in this makefile. > > Jason Will be fixed in v4. Thanks for the review, the code is much simpler now.