From patchwork Fri Aug 26 05:06:31 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: 12955537 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 2AEF3ECAAA3 for ; Fri, 26 Aug 2022 05:06:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DD7A940007; Fri, 26 Aug 2022 01:06:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88C2D6B0075; Fri, 26 Aug 2022 01:06:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 753F5940007; Fri, 26 Aug 2022 01:06:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 632EB6B0074 for ; Fri, 26 Aug 2022 01:06:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 30D90403DC for ; Fri, 26 Aug 2022 05:06:47 +0000 (UTC) X-FDA: 79840558854.10.244EAFE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id A493740009 for ; Fri, 26 Aug 2022 05:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661490404; 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=j5L7U70XfB7JJbqKJpFjRNU09Ztqe5oeNdPnEjrEBQE=; b=S6EHjY5iMGHCv49khcDzlqM/9tS49seQz52VgSnmKjKxHQsyIGHYPca+hdclTVjDHZPWkX ct1666ZdX5jdyeWSJHEV3toYx+BtEQve3TBktiBaWFHonZ7C7bEOZTHVry357rEXtuBwvG Uxj6jtFHv7LsMGMc4En1Gy7FMdnZuoA= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-60-IFrzTj3TN02x8uOTnuFhqw-1; Fri, 26 Aug 2022 01:06:43 -0400 X-MC-Unique: IFrzTj3TN02x8uOTnuFhqw-1 Received: by mail-lf1-f71.google.com with SMTP id m6-20020a05651202e600b00492d736eeefso101755lfq.22 for ; Thu, 25 Aug 2022 22:06:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=j5L7U70XfB7JJbqKJpFjRNU09Ztqe5oeNdPnEjrEBQE=; b=p5srF/0t4N09iwiztmwP1Aq9M5F+Ek0bAD/975P8xhzZA7zSjrHtspA2ry48MiZ+/+ iK53XNFAC2iGPCPx+oHZZupQn0Ncq/FWccMRqmFP9LE5tsm/FEJpwO+yJb4BX83+SL43 hi/qG/YwpU3FR8QeMS7xhVMW0jaXyu1fK6SpStnB543blf/kCY9vNHZDL4XS0nzWiZ9R luEf4akPVils8H8qNWYpGk08ouImMwMHgVQBplBScxp+S0IRSDSWNiyYfiPHo9K750uU jjfcJ5ufgr5lFXfg5/BmMjW3SSWL4R1Q6Mb+OAS9xVwB2tf1VYvdy+hE8k/2pytwGSf3 x8ZQ== X-Gm-Message-State: ACgBeo3apV0mwaWm85D10YCNGaHZBWs6y+kszzcmr/JPkfafGydNHTK0 +WL4LW1VgGQLspZCcjKMESFtPbD7QVNSqTZu6/FDF3yOYxZTn2KiDP0QJLJVc25k7H9twPxaab7 kOiN+sZrhyg== X-Received: by 2002:a05:651c:550:b0:261:c6c8:72ef with SMTP id q16-20020a05651c055000b00261c6c872efmr1959834ljp.313.1661490401973; Thu, 25 Aug 2022 22:06:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7KhnNWZPdexwn2fqKJLP2Kf5/TOYnhw+PhVAFrvK1VpkotIkBy7Oo3f3JabcMtk7Fj4fUTag== X-Received: by 2002:a05:651c:550:b0:261:c6c8:72ef with SMTP id q16-20020a05651c055000b00261c6c872efmr1959820ljp.313.1661490401685; Thu, 25 Aug 2022 22:06:41 -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 o20-20020ac24e94000000b0048b193f677dsm219269lfr.178.2022.08.25.22.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 22:06:41 -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 v8] mm/hmm/test: use char dev with struct device to get device node Date: Fri, 26 Aug 2022 08:06:31 +0300 Message-Id: <20220826050631.25771-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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661490406; h=from:from:sender: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: references:dkim-signature; bh=j5L7U70XfB7JJbqKJpFjRNU09Ztqe5oeNdPnEjrEBQE=; b=AzkdkI5V/CbgJsjc6hxtXAaRHUL22eSWXE5uuyjoR8j0CKsFnF1Emy3jrnvBa//5ZTqgg3 EMOP+8ds8ftD8ABIKTmUYJ6gIYN7RM6nRWWZe2aUlStNcVQ7JbjYvxhrJjMS1LzEcLIsV3 Lqh7n4kiNqIuGKvmMBYgrpytr/+X1cc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S6EHjY5i; spf=pass (imf11.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661490406; a=rsa-sha256; cv=none; b=My2+W/wxUJb8Vln9EiWhd2fHZUJkIbCjnrTVK7ZdmQylyExbgkp9v0JD1dmKupFT2yoW+O /kRJwUzXY+M5oF16nXwMFz5SZMiQdvl9fVwX0qK1GPB/GD4e6kJRXxSQjdiTrba79RpuZ7 dvBAH9tDXP6Vti+gC9OC8RBwyukeZ5M= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S6EHjY5i; spf=pass (imf11.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Stat-Signature: 8cbxw8p4jyytoy644ku3szqbhe4paqkj X-Rspamd-Queue-Id: A493740009 X-Rspamd-Server: rspam03 X-HE-Tag: 1661490405-214862 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 memory. The pseudo device registers a major device range for two or four 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 Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Cc: Alistair Popple Cc: Ralph Campbell Cc: Vlastimil Babka --- v8: - refresh for device coherent v7: - collected more Review-by's 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 | 10 ---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index e3965cafd27c..6a33f6b1b465 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -107,8 +107,8 @@ struct dmirror_chunk { */ struct dmirror_device { struct cdev cdevice; - struct hmm_devmem *devmem; unsigned int zone_device_type; + struct device device; unsigned int devmem_capacity; unsigned int devmem_count; @@ -1390,7 +1390,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; @@ -1416,7 +1423,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 539c9371e592..46e19b5d648d 100755 --- a/tools/testing/selftests/vm/test_hmm.sh +++ b/tools/testing/selftests/vm/test_hmm.sh @@ -52,21 +52,11 @@ load_driver() usage fi fi - 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 - if [ $# -eq 2 ]; then - mknod /dev/hmm_dmirror2 c $major 2 - mknod /dev/hmm_dmirror3 c $major 3 - fi - fi } unload_driver() { modprobe -r $DRIVER > /dev/null 2>&1 - rm -f /dev/hmm_dmirror? } run_smoke()