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 E0960C433F5 for ; Tue, 15 Mar 2022 03:22:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3E888D0002; Mon, 14 Mar 2022 23:22:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEDD68D0001; Mon, 14 Mar 2022 23:22:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8EF18D0002; Mon, 14 Mar 2022 23:22:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0177.hostedemail.com [216.40.44.177]) by kanga.kvack.org (Postfix) with ESMTP id 95D128D0001 for ; Mon, 14 Mar 2022 23:22:21 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2527FA15C2 for ; Tue, 15 Mar 2022 03:22:21 +0000 (UTC) X-FDA: 79245172482.26.0C8EE96 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 A0EDD18000E for ; Tue, 15 Mar 2022 03:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647314540; 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=6ypJCil04CfaW3VomauJXpYfaEKwnBls7PLMuFbkqEc=; b=czWNV5qV2NCjqeV4aXs9HFKdWGIWbOHVy2v9XRc8Z/6cIENFmtL0i1CxYPAyMrQX/1aT0P HClwcfOlUXV0ExLJT8/GuPrhg0nKyMZONBA5aoEQ8vswQbOzJq0xoxmGruUMnnZZmnDKSO 8QEWLe8Iyf8AFKYKfXkSyd530G8Zat4= 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-638-kt3VDtDqPfqQVWEi5wDkWQ-1; Mon, 14 Mar 2022 23:22:19 -0400 X-MC-Unique: kt3VDtDqPfqQVWEi5wDkWQ-1 Received: by mail-lj1-f200.google.com with SMTP id l11-20020a2e99cb000000b00247c058c077so7199408ljj.18 for ; Mon, 14 Mar 2022 20:22:18 -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=6ypJCil04CfaW3VomauJXpYfaEKwnBls7PLMuFbkqEc=; b=CmD1bhfuSgzgAG885FKBXOGka9PPfDcl0b9RtV3tNHHOSSEATK8fZj0QGpAWldqDZC 2Q/isXaHl99C3GHqTpFehiKXrLiFZUD/IFihYc5LZR8+SsS+Z2XIa7yMOIXwjEDPphFX ZyxQVL4xbRx8TcECxY4fumlfxVMFjuUw0v9JQ6+OgXGXomNokYInFi5Ui+TmkFME2mG3 4b8rZ6A5TW/aSQIcv/SJHAGB9WZHuhXlvzPustSzsKjXM72HPbru/7/z8ENohxmPppPN ZYALVx/PSaFBJWC3iztp+NVnPTFhMouVPGJywzieTJODdZ6m8mVajJegX2uc6Zb5UR5b lUaA== X-Gm-Message-State: AOAM530cWp2cSOO7dhWkPa3u+gV0sMfcX5gjHpKBDYWeim214NRhIVhD +7VS4t4jjBY9+7vO5U9W/Jkuh0NSyMW7wt9zKoodqvHQGAPBsEGork5jq2//cEzC51a4sQKNPF/ DHuoxsmFkgA== X-Received: by 2002:a05:6512:1115:b0:448:6c0b:d1f with SMTP id l21-20020a056512111500b004486c0b0d1fmr11687881lfg.94.1647314537503; Mon, 14 Mar 2022 20:22:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwY3CCDk9ukH2U+Kr/8vGYwVnK5BsS8X6MQn5V8KteHKP7+4yht4SnmJrDlzhjnpAN/lgS5cg== X-Received: by 2002:a05:6512:1115:b0:448:6c0b:d1f with SMTP id l21-20020a056512111500b004486c0b0d1fmr11687861lfg.94.1647314537143; Mon, 14 Mar 2022 20:22:17 -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 j15-20020a2e3c0f000000b00247e9bafa20sm4272092lja.99.2022.03.14.20.22.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Mar 2022 20:22:16 -0700 (PDT) Message-ID: Date: Tue, 15 Mar 2022 05:22:15 +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 v2] mm/hmm/test: simplify hmm test code: use miscdevice instead of char dev 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: <20220311033050.22724-1-mpenttil@redhat.com> <20220314182439.GB64706@ziepe.ca> From: =?UTF-8?Q?Mika_Penttil=c3=a4?= In-Reply-To: <20220314182439.GB64706@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 X-Stat-Signature: bf5dxk9tmwcoqz139m7ukjuxayx4pbsg Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=czWNV5qV; 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: rspam08 X-Rspamd-Queue-Id: A0EDD18000E X-HE-Tag: 1647314540-850442 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: 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=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. >> >> 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 appe= ar >> for us. This also enables udev-like processing if desired. >=20 > 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=20 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=20 lifetime issue or what? Many of the examples above embed miscdevice in a=20 dynamically allocated object also. The file object's private_data holds a pointer to the miscdevice, and=20 fops_get() pins the module. So freeing the objects miscdevice is=20 embedded in at module_exit time should be fine. But, as you said, in=20 this case the miscdevices are statically allocated, so that shouldn't be=20 an issue either. But maybe I'm missing something? >=20 >> Delete the /proc/devices parsing from the user-space test script, now >> that it is unnecessary. >=20 > 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. >=20 I think using cdev_add ends up in the same results in device_* api=20 sense. miscdevice acting like a mux at a higher abstraction level=20 simplifies the code. > Jason >=20 Thanks, Mika