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 81EC3C433EF for ; Sat, 26 Mar 2022 03:20:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F4F36B0071; Fri, 25 Mar 2022 23:20:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A31D6B0073; Fri, 25 Mar 2022 23:20:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61DA76B0074; Fri, 25 Mar 2022 23:20:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 5009D6B0071 for ; Fri, 25 Mar 2022 23:20:02 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E82409CD7D for ; Sat, 26 Mar 2022 03:20:01 +0000 (UTC) X-FDA: 79285083402.31.ED8B809 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 23DB3180030 for ; Sat, 26 Mar 2022 03:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648264800; 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=YdzHyBRiDoFBIFf36Fo0Qt/OhY+QHu6QN9v137onA3I=; b=Hkzh7O9V1JU4ef4yeYfOH1GN2ZAoPU1q0ren7s7JzSRNyWe1MXBIzJhekJFlWdfuQMlQ6I GydeX7OjLrEPXDH6KpIvj1SPs3k6L6M0h87TD+xq5WfTbU3kKXXIIRZMyFDE/3ZTmzmWat 1aNfoaKrtDzr7alCsHKQG5CsCXhVsUY= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-306-vILUdJQIPsWjTp0KZkGpAA-1; Fri, 25 Mar 2022 23:19:59 -0400 X-MC-Unique: vILUdJQIPsWjTp0KZkGpAA-1 Received: by mail-lj1-f198.google.com with SMTP id x3-20020a05651c104300b00247ebe980b7so3555297ljm.11 for ; Fri, 25 Mar 2022 20:19:58 -0700 (PDT) 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=YdzHyBRiDoFBIFf36Fo0Qt/OhY+QHu6QN9v137onA3I=; b=giZJNTqDgfa37SkdgvHeN8qlXlwAohlGfJSGbAkAkgbC2D5Vv5QzUsoCVturZjn7/f FEkQd/DDT5sNAXN6lAO+OQ81Yb5UBMPd8/fMtrwHqRu9OuogXnn3L9AgPPGVa9tfhDR9 RFvB4BvL18gT/zYqDRTZ0sH1X1+cv0ZnNMDvhcY4+2gviPveXzIUILVHChZTShy83wPF hx6JU0e/f9mfWoqN8h7dWnslFva3tVt3RlzZA3jKMevN+bDNqvvsyn1+lHLL0LKWC7VE YwG/rfcalQceQCNLpGuEwe4bDhczWp0TSiBm2paf6rrM8Ouvk1VWauVrQDGIkXCqYX57 vEeg== X-Gm-Message-State: AOAM531Q7euK1a+tRB42lCtnmjnDSO/evwHc1VQYJx2jUwoYz8fIZ7sF WFnc6fFjod78dn73pRkIeZrTs1CZBvoK8Bc4G3EJ3VdqYcy2nlEui2JzkvNchyk32PnDaAVQcpE TH6HFEGM2Eg== X-Received: by 2002:a19:5f12:0:b0:44a:3274:9b96 with SMTP id t18-20020a195f12000000b0044a32749b96mr10370096lfb.251.1648264797618; Fri, 25 Mar 2022 20:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM3qYsyxD83Noo9clgxEEeANZ0nfQgAU/eUnMtrWmJHrKNISm2dBMmAdspzViGDbAiPam47Q== X-Received: by 2002:a19:5f12:0:b0:44a:3274:9b96 with SMTP id t18-20020a195f12000000b0044a32749b96mr10370079lfb.251.1648264797376; Fri, 25 Mar 2022 20:19:57 -0700 (PDT) Received: from [192.168.1.121] (91-145-109-188.bb.dnainternet.fi. [91.145.109.188]) by smtp.gmail.com with ESMTPSA id y24-20020a199158000000b0044a76a4808esm342529lfj.22.2022.03.25.20.19.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Mar 2022 20:19:57 -0700 (PDT) Message-ID: <18ee348d-f617-9e55-ed11-21321e284c0b@redhat.com> Date: Sat, 26 Mar 2022 05:19:55 +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 v5] mm/hmm/test: use char dev with struct device to get device node To: Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, apopple@nvidia.com, jhubbard@nvidia.com, rcampbell@nvidia.com, vbabka@suse.cz References: <20220322043543.18424-1-mpenttil@redhat.com> <20220325181739.GL64706@ziepe.ca> From: =?UTF-8?Q?Mika_Penttil=c3=a4?= In-Reply-To: <20220325181739.GL64706@ziepe.ca> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hkzh7O9V; 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-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 23DB3180030 X-Stat-Signature: u6tkk4a8gyhb899qgjuixqba9fecg51c X-HE-Tag: 1648264800-764662 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 25.3.2022 20.17, Jason Gunthorpe wrote: > On Tue, Mar 22, 2022 at 06:35:43AM +0200, mpenttil@redhat.com wrote: >> From: Mika Penttil=C3=A4 >> >> HMM selftests use an in-kernel pseudo device to emulate device private >> memory. The pseudo device registers a major device range for two pseud= o >> 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. >> >> Change this to properly use cdev and struct device APIs. >> >> Delete the /proc/devices parsing from the user-space test script, now >> that it is unnecessary. >> >> Also, deleted an unused field in struct dmirror_device: devmem. >> >> Signed-off-by: Mika Penttil=C3=A4 >> Reviewed-by: John Hubbard >> Cc: Alistair Popple >> Cc: Ralph Campbell >> Cc: Jason Gunthorpe >> Cc: Vlastimil Babka >> v5: >> - fix whitespace >> . delete unused structure field >> v4: >> - fix commit log >> v3: >> - use cdev_device_add() instead of miscdevice >> v2: >> - Cleanups per review comments from John Hubbard >> - Added Tested-by and Ccs >> >> lib/test_hmm.c | 18 ++++++++++++++---- >> tools/testing/selftests/vm/test_hmm.sh | 6 ------ >> 2 files changed, 14 insertions(+), 10 deletions(-) >> >> diff --git a/lib/test_hmm.c b/lib/test_hmm.c >> index 767538089a62..3c7f2a92b09e 100644 >> +++ b/lib/test_hmm.c >> @@ -29,11 +29,17 @@ >> =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 >> +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; >> @@ -83,7 +89,7 @@ struct dmirror_chunk { >> */ >> struct dmirror_device { >> struct cdev cdevice; >> - struct hmm_devmem *devmem; >> + struct device device; >> =20 >> unsigned int devmem_capacity; >> unsigned int devmem_count; >> @@ -1225,7 +1231,11 @@ static int dmirror_device_init(struct dmirror_d= evice *mdevice, int id) >> =20 >> cdev_init(&mdevice->cdevice, &dmirror_fops); >> mdevice->cdevice.owner =3D THIS_MODULE; >> - ret =3D cdev_add(&mdevice->cdevice, dev, 1); >> + device_initialize(&mdevice->device); >> + dev_set_name(&mdevice->device, "%s", dmirror_device_names[id]); >=20 > Just > dev_set_name(&mdevice->device, "hmm_dmirror%u", id); >=20 > No need for an array Yeah, no absolute need, thought names in an array is less hardcoded wrt=20 device node count and naming standard. >=20 > Also check for error True. Interesting fact is that even the device core itself doesn't check=20 for errors calling dev_set_name(), but sure it can fail in memory=20 allocations. >=20 > Jason >=20 Mika