mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mika Penttilä" <mpenttil@redhat.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	apopple@nvidia.com, jhubbard@nvidia.com, rcampbell@nvidia.com,
	vbabka@suse.cz
Subject: Re: [PATCH v2] mm/hmm/test: simplify hmm test code: use miscdevice instead of char dev
Date: Tue, 15 Mar 2022 05:22:15 +0200	[thread overview]
Message-ID: <d9b9c82e-4012-cf0a-d966-d9669a684a27@redhat.com> (raw)
In-Reply-To: <20220314182439.GB64706@ziepe.ca>

Hi Jason and thanks for your comments..

On 14.3.2022 20.24, Jason Gunthorpe wrote:
> On Fri, Mar 11, 2022 at 05:30:50AM +0200, mpenttil@redhat.com wrote:
>> From: Mika Penttilä <mpenttil@redhat.com>
>>
>> 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.
>>
>> This duplicates a fair amount of boilerplate that misc device can do
>> instead.
>>
>> Change this to use misc device, which makes the device node names appear
>> for us. This also enables udev-like processing if desired.
> 
> This is borderline the wrong way to use misc devices, they should
> never be embedded into other structs like this. It works out here
> because they are eventually only placed in a static array, but still
> it is a generally bad pattern to see.

Could you elaborate on this one? We have many in-tree usages of the same 
pattern, like:

drivers/video/fbdev/pxa3xx-gcu.c
drivers/platform/goldfish/goldfish_pipe.c
drivers/virt/vboxguest/vboxguest_linux.c
drivers/virt/nitro_enclaves/ne_pci_dev.c
drivers/watchdog/cpwd.c
drivers/platform/x86/toshiba_acpi.c
drivers/platform/x86/wmi.c
drivers/platform/surface/surface_dtx.c
drivers/bus/fsl-mc/fsl-mc-uapi.c
drivers/misc/dw-xdata-pcie.c
drivers/input/serio/serio_raw.c
fs/dlm/user.c
lib/test_kmod.c

You mention "placed in a static array", are you seeing a potential 
lifetime issue or what? Many of the examples above embed miscdevice in a 
dynamically allocated object also.

The file object's private_data holds a pointer to the miscdevice, and 
fops_get() pins the module. So freeing the objects miscdevice is 
embedded in at module_exit time should be fine. But, as you said, in 
this case the miscdevices are statically allocated, so that shouldn't be 
an issue either. But maybe I'm missing something?

> 
>> Delete the /proc/devices parsing from the user-space test script, now
>> that it is unnecessary.
> 
> This is all because the cdev is being used wrong - it get all this
> stuff it should be done via cdev_device_add() and a dmirror_device
> needs a struct device to hold the sysfs.
> 

I think using cdev_add ends up in the same results in device_* api 
sense. miscdevice acting like a mux at a higher abstraction level 
simplifies the code.


> Jason
> 


Thanks,

Mika


  reply	other threads:[~2022-03-15  3:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11  3:30 mpenttil
2022-03-11  6:15 ` John Hubbard
2022-03-11  6:18   ` Mika Penttilä
2022-03-14 18:24 ` Jason Gunthorpe
2022-03-15  3:22   ` Mika Penttilä [this message]
2022-03-15 18:39     ` Jason Gunthorpe
2022-03-17  5:47       ` Mika Penttilä
2022-03-17  6:58         ` Mika Penttilä
2022-03-17 14:15           ` Jason Gunthorpe
2022-03-18  2:34             ` Mika Penttilä
2022-03-18  2:58               ` John Hubbard
2022-03-18 12:40                 ` Jason Gunthorpe

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=d9b9c82e-4012-cf0a-d966-d9669a684a27@redhat.com \
    --to=mpenttil@redhat.com \
    --cc=apopple@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rcampbell@nvidia.com \
    --cc=vbabka@suse.cz \
    /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

all inboxes | Powered by JetHome®