From patchwork Wed Mar 30 00:47:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mika_Penttil=C3=A4?= X-Patchwork-Id: 12795367 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 063C7C433EF for ; Wed, 30 Mar 2022 00:47:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5156A8D0002; Tue, 29 Mar 2022 20:47:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 475A88D0001; Tue, 29 Mar 2022 20:47:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C7638D0002; Tue, 29 Mar 2022 20:47:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 1632A8D0001 for ; Tue, 29 Mar 2022 20:47:47 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B2023A5674 for ; Wed, 30 Mar 2022 00:47:46 +0000 (UTC) X-FDA: 79299214932.16.297B528 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 25A7220004 for ; Wed, 30 Mar 2022 00:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648601265; 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; bh=nAylo5IpwXAoPRELTx8+AnmsJ+Mgi0O7r60sCfc5+XY=; b=IpzJ+frLRDCSKulGnqbnHvuIrlkG3UYiGww8IAMowbGfRWsI55oCvHt6Z1/pYZTYOsgqTj tCSERKX+WGpCsFkAKT0KrmKXSbZHmZPtCbriupiPxpuwpW9GfpGq64NjpH4VFGWrpA9d30 WnCrobcFHUWVlwA46lH5LkK8lns9D+s= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-BGs_ACHaMYOvHjl0psZtLw-1; Tue, 29 Mar 2022 20:47:44 -0400 X-MC-Unique: BGs_ACHaMYOvHjl0psZtLw-1 Received: by mail-lj1-f200.google.com with SMTP id b2-20020a2e8942000000b002497c9833c2so8112456ljk.8 for ; Tue, 29 Mar 2022 17:47:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nAylo5IpwXAoPRELTx8+AnmsJ+Mgi0O7r60sCfc5+XY=; b=jgbv5M+kRMDxjpFN6sshBGngD9yyMJZCpAD6f7fN1JzwZ7nu9qAYy+y5K2AO9qAOHd VgD2/WQ86vIZ9LAI7OQ16OMMjezIs5a7oR6VQHwDJiF1DA0ksL1Ruo8Pyt0E8ykLiyqI CXxHwImbuQz16MNBJajMpkFUGF+uYdQHeyZ8jMMQhOTFwW6sW/odHmY3c512rZGjhgLI Qx5qn5+VKZgyezw7tIo0Vj4bYiM0SRZTr4qzaAY1HkK7EY6c4FDP9LrTtUN90/wOzcMY xrCZnJk5avDoh6HCDATgrEI7fW5E31WgWjeH6TIVIa6fJ7sZcWPJt8I0GpDk+IYetWRP bbbg== X-Gm-Message-State: AOAM533fg5hU/pckKFuMPGZs/oeog3V54JBxThIgXe4TqL68amOQI7WJ q3FcWIQOa5ezckDpGbgnYecOvMqEAgb+1oRz2CD80Y27f1VUNNgLH5RlRm5jpxDYUlzntK38RFM P89BCIeGZpw== X-Received: by 2002:ac2:4847:0:b0:44a:24b6:7e99 with SMTP id 7-20020ac24847000000b0044a24b67e99mr4826281lfy.279.1648601262794; Tue, 29 Mar 2022 17:47:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO6TIz7tFG/OsyMvXsipWMnTwVVf/JV9vGBcN4ImwDDVo0wx4BipRownJSPkKzQEAqGyJDPw== X-Received: by 2002:ac2:4847:0:b0:44a:24b6:7e99 with SMTP id 7-20020ac24847000000b0044a24b67e99mr4826273lfy.279.1648601262571; Tue, 29 Mar 2022 17:47:42 -0700 (PDT) Received: from mjp-Z390-AORUS-MASTER.redhat.com (91-145-109-188.bb.dnainternet.fi. [91.145.109.188]) by smtp.gmail.com with ESMTPSA id g12-20020a05651222cc00b0044a1065ca5fsm2146292lfu.304.2022.03.29.17.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 17:47:42 -0700 (PDT) From: mpenttil@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: apopple@nvidia.com, jhubbard@nvidia.com, rcampbell@nvidia.com, jgg@ziepe.ca, vbabka@suse.cz, =?utf-8?q?Mika_Penttil=C3=A4?= Subject: [PATCH v6] mm/hmm/test: use char dev with struct device to get device node Date: Wed, 30 Mar 2022 03:47:25 +0300 Message-Id: <20220330004725.13428-1-mpenttil@redhat.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 25A7220004 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IpzJ+frL; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf03.hostedemail.com: domain of mpenttil@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=mpenttil@redhat.com X-Stat-Signature: bieeksbphjmjm6rf1ujwixsnpdegdi4m X-HE-Tag: 1648601265-906836 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: From: Mika Penttilä 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. 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ä Reviewed-by: John Hubbard Cc: Alistair Popple Cc: Ralph Campbell Cc: Jason Gunthorpe Cc: Vlastimil Babka Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- v6: - remove device names array - check return value of dev_set_name() 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 | 13 ++++++++++--- tools/testing/selftests/vm/test_hmm.sh | 6 ------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index cfe632047839..7d1f98bc9c9a 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -86,7 +86,7 @@ struct dmirror_chunk { */ struct dmirror_device { struct cdev cdevice; - struct hmm_devmem *devmem; + struct device device; unsigned int devmem_capacity; unsigned int devmem_count; @@ -1227,7 +1227,14 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) cdev_init(&mdevice->cdevice, &dmirror_fops); mdevice->cdevice.owner = THIS_MODULE; - ret = cdev_add(&mdevice->cdevice, dev, 1); + device_initialize(&mdevice->device); + mdevice->device.devt = dev; + + ret = dev_set_name(&mdevice->device, "hmm_dmirror%u", id); + if (ret) + return ret; + + ret = cdev_device_add(&mdevice->cdevice, &mdevice->device); if (ret) return ret; @@ -1254,7 +1261,7 @@ static void dmirror_device_remove(struct dmirror_device *mdevice) kfree(mdevice->devmem_chunks); } - cdev_del(&mdevice->cdevice); + cdev_device_del(&mdevice->cdevice, &mdevice->device); } static int __init hmm_dmirror_init(void) diff --git a/tools/testing/selftests/vm/test_hmm.sh b/tools/testing/selftests/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 [ $? == 0 ]; then - major=$(awk "\$2==\"HMM_DMIRROR\" {print \$1}" /proc/devices) - mknod /dev/hmm_dmirror0 c $major 0 - mknod /dev/hmm_dmirror1 c $major 1 - fi } unload_driver() { modprobe -r $DRIVER > /dev/null 2>&1 - rm -f /dev/hmm_dmirror? } run_smoke()