linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ralph Campbell <rcampbell@nvidia.com>
To: Jason Gunthorpe <jgg@mellanox.com>
Cc: Jerome Glisse <jglisse@redhat.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Christoph Hellwig <hch@lst.de>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 3/3] mm/hmm/test: add self tests for HMM
Date: Wed, 30 Oct 2019 17:14:30 -0700	[thread overview]
Message-ID: <f42d06e2-ca08-acdd-948d-2803079a13c2@nvidia.com> (raw)
In-Reply-To: <20191029231255.GX22766@mellanox.com>


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.

  reply	other threads:[~2019-10-31  0:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-23 19:55 [PATCH v3 0/3] HMM tests and minor fixes Ralph Campbell
2019-10-23 19:55 ` [PATCH v3 1/3] mm/hmm: make full use of walk_page_range() Ralph Campbell
2019-10-29 17:40   ` Jason Gunthorpe
2019-10-23 19:55 ` [PATCH v3 2/3] mm/hmm: allow snapshot of the special zero page Ralph Campbell
2019-10-23 20:27   ` Jerome Glisse
2019-10-24  9:27   ` David Hildenbrand
2019-10-29 17:27   ` Jason Gunthorpe
2019-10-23 19:55 ` [PATCH v3 3/3] mm/hmm/test: add self tests for HMM Ralph Campbell
2019-10-23 20:28   ` Jerome Glisse
2019-10-23 21:55     ` Ralph Campbell
2019-10-29 17:58   ` Jason Gunthorpe
2019-10-29 21:16     ` Ralph Campbell
2019-10-29 23:12       ` Jason Gunthorpe
2019-10-31  0:14         ` Ralph Campbell [this message]
2019-10-31 12:42           ` Jason Gunthorpe
2019-10-31 17:28             ` Ralph Campbell
2019-10-31 17:34               ` Jason Gunthorpe
2019-10-31 17:48                 ` Ralph Campbell
2019-10-30 18:34     ` Qian Cai

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=f42d06e2-ca08-acdd-948d-2803079a13c2@nvidia.com \
    --to=rcampbell@nvidia.com \
    --cc=hch@lst.de \
    --cc=jgg@mellanox.com \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).