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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23916C433F5 for ; Thu, 10 Mar 2022 05:33:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5769E8D0002; Thu, 10 Mar 2022 00:33:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 555A78D0001; Thu, 10 Mar 2022 00:33:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 414E68D0002; Thu, 10 Mar 2022 00:33:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id 3266D8D0001 for ; Thu, 10 Mar 2022 00:33:59 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C8F5D9F5CF for ; Thu, 10 Mar 2022 05:33:58 +0000 (UTC) X-FDA: 79227360156.30.E4C20D8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 2031318000C for ; Thu, 10 Mar 2022 05:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646890437; 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=C+CV2ZTheCDjwIQatvOSM+2IpK+hatXZ+6LPwmkSoIU=; b=fnwlFk8DxAAMmhRWOvmGmtnhxZBsBwF9f8YKfCJ0Q2zdRjuNxLy1SJlbiDwgm8R2q9ZLAE RXXgmdsOkezqZSMiUJiSy12VFlky5ix7h/hwa99MRsNBouZUSIpSkDI3iLE2FA+gxxHg69 6QOCN4nS8MJtu6eSGRTUpuOdP5Xv+rY= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-586-sGUYCQqXN-eBtmmTD7LbEQ-1; Thu, 10 Mar 2022 00:33:53 -0500 X-MC-Unique: sGUYCQqXN-eBtmmTD7LbEQ-1 Received: by mail-lj1-f199.google.com with SMTP id 6-20020a2eb946000000b002463d2915d2so1837062ljs.9 for ; Wed, 09 Mar 2022 21:33:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=C+CV2ZTheCDjwIQatvOSM+2IpK+hatXZ+6LPwmkSoIU=; b=YlEtyXtuF1NqoHaG4iiCDngQ6Kkx7MbOoUAL6VzQsDCoYGeDepB810Co3Xl7gh03YJ L0n62WphiQRaCN3fmxe6csFsO3CAMUk6u0DrCexXchGY/2QlTViL3KwaG4iuLoDBPvSU rYW6xETg614bTLiWW6n67GnslaRj2VDLTQl3xyaJt8K3l+X6dVdWbp8W9c6wAtruoD1R rIdUcw73m6KqojkcmfX80Nttjtwsog285iDFlvwGA/W0/ggdejh8hK58POiIVJCe2EqS WG3x+0wIAlrI0fSCEEGWk3TqZRc9eUD9PxgoPpVXNRcyBYRpL6w+hTqgd483F4SMxE4/ cD+w== X-Gm-Message-State: AOAM531ZBN/fcKvFyvjmRUrny1DaPhUUBkHAacUaWy1sd3/WArq0+LiT pL+T7QBTo3e4gx7z0bzPtNH+sfswXZv4DUOBYGvO8XSBlEJQpw33RdJ8hOc/HF5CGywOHFC++4x 3LCZsp07dtQ== X-Received: by 2002:a05:651c:105:b0:247:e127:5e0b with SMTP id a5-20020a05651c010500b00247e1275e0bmr1913687ljb.147.1646890432336; Wed, 09 Mar 2022 21:33:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3JB6LT24RsvA9CYAMMS6VXGgsDqV6dK6GcgPOO9FwRlM1R3+OJmNsicqEiGdPL5QEbmlgGg== X-Received: by 2002:a05:651c:105:b0:247:e127:5e0b with SMTP id a5-20020a05651c010500b00247e1275e0bmr1913669ljb.147.1646890431963; Wed, 09 Mar 2022 21:33:51 -0800 (PST) Received: from [192.168.1.121] (91-145-109-188.bb.dnainternet.fi. [91.145.109.188]) by smtp.gmail.com with ESMTPSA id o20-20020ac24e94000000b004481ceec304sm773072lfr.220.2022.03.09.21.33.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Mar 2022 21:33:51 -0800 (PST) Message-ID: Date: Thu, 10 Mar 2022 07:33:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] HMM selftests changes To: John Hubbard , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Alistair Popple , Ralph Campbell , Jason Gunthorpe References: <20220308015705.8424-1-mpenttil@redhat.com> <7fc9cae2-04b3-153c-f826-e565a1beeb2d@suse.cz> <4c6bc437-32ba-7bfd-05e6-b555a1a13776@nvidia.com> From: =?UTF-8?Q?Mika_Penttil=c3=a4?= In-Reply-To: <4c6bc437-32ba-7bfd-05e6-b555a1a13776@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2031318000C X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fnwlFk8D; spf=none (imf16.hostedemail.com: domain of mpenttil@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: kwth7jzcyjqsss73a9x5188ffqpkb1gx X-HE-Tag: 1646890437-170941 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 10.3.2022 5.44, John Hubbard wrote: > On 3/8/22 5:10 AM, Vlastimil Babka wrote: >> +CC relevant folks >> >> On 3/8/22 02:57, mpenttil@redhat.com wrote: >>> From: Mika Penttil=C3=A4 >=20 > Hi Mika, >=20 > This looks like a very nice cleanup and simplification, delighted to se= e > it! Thanks! >=20 > In fact, I like it so much that I've got a bunch of fussy nitpicks I'm > hoping you'll consider applying, below. :) >=20 > Also, I'm assuming you've tested it a little bit? (My test rig is boxed > up for another day or two, don't ask...haha.) >=20 Yes it passed the tests with the changes. >>> >>> HMM selftests use a in-kernel pseudo device to emulate device private= memory. >>> >>> For now, the pseudo device registers a major device range for two pse= udo device instances. >>> User space has a script that goes figures out from /proc/devices the = assigned major >>> and mknods the device nodes. >>> >>> Change this use to a more standard device framework, like misc device= , >>> which makes the device node names to appear right under any decent us= er space. >>> This also makes it possible for udev- like processing if wanted, >>> and the /proc/devices parsing is not needed any more. >=20 > How about this for the subject line and body? I've made the subject lin= e > match what other commits look like in this area, and I've clarified the > wording in the body: >=20 >=20 > mm/hmm/test: simplify hmm test code: use miscdevice instead of char dev >=20 > HMM selftests use an in-kernel pseudo device to emulate device private > memory. The pseudo device registers a major device range for two pseudo > device instances. User space has a script that reads /proc/devices in > order to find the assigned major number, and sends that to mknod(1), > once for each node. >=20 > This duplicates a fair amount of boilerplate that misc device can do > instead. >=20 > Change this to use misc device, which makes the device node names appea= r > for us. This also enables udev-like processing if desired. >=20 > Delete the /proc/devices parsing from the user-space test script, now > that it is unnecessary. >=20 >>> >>> Signed-off-by: Mika Penttil=C3=A4 >>> --- >>> lib/test_hmm.c | 46 +++++++++++++++--------= --- >>> tools/testing/selftests/vm/test_hmm.sh | 6 ---- >>> 2 files changed, 26 insertions(+), 26 deletions(-) >>> >>> diff --git a/lib/test_hmm.c b/lib/test_hmm.c >>> index 767538089a62..76f6129e1f1f 100644 >>> --- a/lib/test_hmm.c >>> +++ b/lib/test_hmm.c >>> @@ -10,7 +10,6 @@ >>> #include >>> #include >>> #include >>> -#include >>> #include >>> #include >>> #include >>> @@ -25,18 +24,25 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> =20 >>> #include "test_hmm_uapi.h" >>> =20 >>> -#define DMIRROR_NDEVICES 2 >>> #define DMIRROR_RANGE_FAULT_TIMEOUT 1000 >>> #define DEVMEM_CHUNK_SIZE (256 * 1024 * 1024U) >>> #define DEVMEM_CHUNKS_RESERVE 16 >>> =20 >>> + >=20 > Extra newline, please delete. >=20 yep >>> +static const char *dmirror_device_names[] =3D { >>> + "hmm_dmirror0", >>> + "hmm_dmirror1" >>> +}; >>> + >>> +#define DMIRROR_NDEVICES ARRAY_SIZE(dmirror_device_names) >>> + >>> static const struct dev_pagemap_ops dmirror_devmem_ops; >>> static const struct mmu_interval_notifier_ops dmirror_min_ops; >>> -static dev_t dmirror_dev; >>> =20 >>> struct dmirror_device; >>> =20 >>> @@ -82,7 +88,7 @@ struct dmirror_chunk { >>> * Per device data. >>> */ >>> struct dmirror_device { >>> - struct cdev cdevice; >>> + struct miscdevice miscdevice; >>> struct hmm_devmem *devmem; >>> =20 >>> unsigned int devmem_capacity; >>> @@ -118,16 +124,20 @@ static void dmirror_bounce_fini(struct dmirror_= bounce *bounce) >>> =20 >>> static int dmirror_fops_open(struct inode *inode, struct file *filp= ) >>> { >>> - struct cdev *cdev =3D inode->i_cdev; >>> + >>> + struct dmirror_device *dd =3D container_of(filp->private_data, >>> + struct dmirror_device,= miscdevice >>> + ); >=20 > Let's delete that whole chunk, because the variable is unnecessary, and > is adding to the line count and mental load for no reason. Agreed. >=20 > Look how much cleaner this it gets after applying this incremental diff > on top of your patch: >=20 > diff --git a/lib/test_hmm.c b/lib/test_hmm.c > index 76f6129e1f1f..3ec8ca8059cd 100644 > --- a/lib/test_hmm.c > +++ b/lib/test_hmm.c > @@ -125,19 +125,16 @@ static void dmirror_bounce_fini(struct dmirror_bo= unce *bounce) > static int dmirror_fops_open(struct inode *inode, struct file *filp) > { > =20 > - struct dmirror_device *dd =3D container_of(filp->private_data, > - struct dmirror_device, m= iscdevice > - ); > struct dmirror *dmirror; > int ret; > =20 > - > /* Mirror this process address space */ > dmirror =3D kzalloc(sizeof(*dmirror), GFP_KERNEL); > if (dmirror =3D=3D NULL) > return -ENOMEM; > =20 > - dmirror->mdevice =3D dd; > + dmirror->mdevice =3D container_of(filp->private_data,struct dmirror_d= evice, > + miscdevice); > mutex_init(&dmirror->mutex); > xa_init(&dmirror->pt); >=20 >=20 >>> struct dmirror *dmirror; >>> int ret; >>> =20 >>> + >>> /* Mirror this process address space */ >>> dmirror =3D kzalloc(sizeof(*dmirror), GFP_KERNEL); >>> if (dmirror =3D=3D NULL) >>> return -ENOMEM; >>> =20 >>> - dmirror->mdevice =3D container_of(cdev, struct dmirror_device, cdev= ice); >>> + dmirror->mdevice =3D dd; >>> mutex_init(&dmirror->mutex); >>> xa_init(&dmirror->pt); >>> =20 >>> @@ -1216,16 +1226,18 @@ static const struct dev_pagemap_ops dmirror_d= evmem_ops =3D { >>> =20 >>> static int dmirror_device_init(struct dmirror_device *mdevice, int = id) >>> { >>> - dev_t dev; >>> + >>> int ret; >>> =20 >>> - dev =3D MKDEV(MAJOR(dmirror_dev), id); >>> mutex_init(&mdevice->devmem_lock); >>> spin_lock_init(&mdevice->lock); >>> =20 >>> - cdev_init(&mdevice->cdevice, &dmirror_fops); >>> - mdevice->cdevice.owner =3D THIS_MODULE; >>> - ret =3D cdev_add(&mdevice->cdevice, dev, 1); >>> + mdevice->miscdevice.minor =3D MISC_DYNAMIC_MINOR; >>> + mdevice->miscdevice.name =3D dmirror_device_names[id]; >>> + mdevice->miscdevice.fops =3D &dmirror_fops; >>> + >>> + ret =3D misc_register(&mdevice->miscdevice); >>> + >>> if (ret) >>> return ret; >>> =20 >>> @@ -1252,7 +1264,7 @@ static void dmirror_device_remove(struct dmirro= r_device *mdevice) >>> kfree(mdevice->devmem_chunks); >>> } >>> =20 >>> - cdev_del(&mdevice->cdevice); >>> + misc_deregister(&mdevice->miscdevice); >>> } >>> =20 >>> static int __init hmm_dmirror_init(void) >>> @@ -1260,11 +1272,6 @@ static int __init hmm_dmirror_init(void) >>> int ret; >>> int id; >>> =20 >>> - ret =3D alloc_chrdev_region(&dmirror_dev, 0, DMIRROR_NDEVICES, >>> - "HMM_DMIRROR"); >>> - if (ret) >>> - goto err_unreg; >>> - >>> for (id =3D 0; id < DMIRROR_NDEVICES; id++) { >>> ret =3D dmirror_device_init(dmirror_devices + id, id); >>> if (ret) >>> @@ -1277,8 +1284,7 @@ static int __init hmm_dmirror_init(void) >>> err_chrdev: >>> while (--id >=3D 0) >>> dmirror_device_remove(dmirror_devices + id); >>> - unregister_chrdev_region(dmirror_dev, DMIRROR_NDEVICES); >>> -err_unreg: >>> + >>> return ret; >>> } >>> =20 >>> @@ -1288,7 +1294,7 @@ static void __exit hmm_dmirror_exit(void) >>> =20 >>> for (id =3D 0; id < DMIRROR_NDEVICES; id++) >>> dmirror_device_remove(dmirror_devices + id); >>> - unregister_chrdev_region(dmirror_dev, DMIRROR_NDEVICES); >>> + >=20 > Another extra newline, please delete it. yes >=20 >>> } >>> =20 >>> module_init(hmm_dmirror_init); >>> diff --git a/tools/testing/selftests/vm/test_hmm.sh b/tools/testing/s= elftests/vm/test_hmm.sh >>> index 0647b525a625..69f5889f8575 100755 >>> --- a/tools/testing/selftests/vm/test_hmm.sh >>> +++ b/tools/testing/selftests/vm/test_hmm.sh >>> @@ -41,17 +41,11 @@ check_test_requirements() >>> load_driver() >>> { >>> modprobe $DRIVER > /dev/null 2>&1 >>> - if [ $? =3D=3D 0 ]; then >>> - major=3D$(awk "\$2=3D=3D\"HMM_DMIRROR\" {print \$1}" /proc/devices= ) >>> - mknod /dev/hmm_dmirror0 c $major 0 >>> - mknod /dev/hmm_dmirror1 c $major 1 >>> - fi >>> } >>> =20 >>> unload_driver() >>> { >>> modprobe -r $DRIVER > /dev/null 2>&1 >>> - rm -f /dev/hmm_dmirror? >=20 > Nice! >=20 >>> } >>> =20 >>> run_smoke() >> >=20 > thanks, Ok will make the changes and repost, thanks! --Mika