Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp845341rdb; Sat, 7 Oct 2023 01:22:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG78z8fHzhtjXnwwrMenvn5BV/Y+UB8QDrT6kR0T9vkDotahZVqKmbZhCZnppuI6HhKkQ4d X-Received: by 2002:a05:6358:91c:b0:134:c8cb:6a00 with SMTP id r28-20020a056358091c00b00134c8cb6a00mr12155503rwi.12.1696666959895; Sat, 07 Oct 2023 01:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696666959; cv=none; d=google.com; s=arc-20160816; b=TIomVAf86EhZcS/eCVjSvJJnuhJ0LEq8We7NKJGbt7ycv4gImteeG4gF1vkGdJcmOg MipOetCV3gkm4OYiGNGaTlF3MX93auIawb3oKhe4T49Eo6CEP4USHt9GGcIMC8s5Ypro cI35s83dgXcgnnN7QZgM+YN3y1dgA3MFpa56eST6p2lUJUbPV72HXTeVOwbM6hOCQ7Ux rAS0v2I2iMfICFuJAzcdOh72nH0rS04uG8kSrGkJDHvvoLcNAX4lfYXeq3S4MWnZ3Jzp 1GXwrxw86FAMDIXzi/FYEV5XoJ16U3srKZbOgHJFBZoHRT51YF5yKyAJZ2Jm2ye7LfpY daTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=LAz8xXmhRswI9Wfo/147YMtE0iio01uYuGksIL2zD0E=; fh=kTuyLCaTv5MsZWiT7zXg5O4oyh3ZUpNPmbuuLBiZJ3A=; b=myHJtrvvaZvmk4khb9rbOKETOQoZQ2l5CDx0rj9ov9ct+17JOFQqUJJ2ec7rXEG670 j83h1/1s2lV3VUK3LBIVb3yiju5ZQnRFscKkn1o131pQo7cou5dfHtnlQgculR2if20E vFF1pSga4isjbz98zUHykJpQIe1v08f4dO2nnEyLON4tvC6bb7rxCQcP/Li8tYEKASCO I+QPJW5nj8OzW72TzjnpIiCurZaypD0xDikI1sagipLRP0t8bCgoBPfZvLqIokiNeOwm vC7G4POf2usU97Un+ByerLtcwoXcY16Gxle07r3c/F7q2GOE4BnpIW31kSv/WLMD21kZ taFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZuqRX91n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id lk12-20020a17090b33cc00b00262e5a82047si2785391pjb.44.2023.10.07.01.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 01:22:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZuqRX91n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1550780268A4; Sat, 7 Oct 2023 01:22:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234154AbjJGIWX (ORCPT + 99 others); Sat, 7 Oct 2023 04:22:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234148AbjJGIWU (ORCPT ); Sat, 7 Oct 2023 04:22:20 -0400 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25FC8BF for ; Sat, 7 Oct 2023 01:21:57 -0700 (PDT) Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-57b6a7e0deeso1715267eaf.2 for ; Sat, 07 Oct 2023 01:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1696666916; x=1697271716; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LAz8xXmhRswI9Wfo/147YMtE0iio01uYuGksIL2zD0E=; b=ZuqRX91nRAQQljq+JabndT4iMYfy2DwAm39ZFH/d71nSoA4p1SGzHOjorTZrN3AEJD VCfJpHFVnVaQ3T5Se1uJG9vXVsFKjk6uec5vR8mhvzuxTD5fWRp+Nm2UER0j3Nupj7V5 ni/JgPbBLWKvPIGjg0eVnl3iU084cf8pHbbGkw/JMA//3lTxzCJ3ogOzLdf1Tk/YutPr +44eAxLtRA9/vwPseir/6pKB4poiwEydrK/JvZ8c0ldAZG9WhPOULzmHc8DF9zn2wZGE Gns92ozM5PdqTz0KDJWfznNg1O2Sfc2LbPBPcFEACZWown09WneMEyPDqgpFseyQkDi4 C/RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696666916; x=1697271716; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LAz8xXmhRswI9Wfo/147YMtE0iio01uYuGksIL2zD0E=; b=r6/RjsSdmy4TAWpZo96ddkKauULLhrXL8bwgq8tHAE5JaVQcFd9w1/KOfEmlxZGoNl cGuvPzT19fUQ6lYwn3mwpMqAoyNiUNl95uuHyQGbPk/M2G2ESyz68iZt8Jf5I7Oy+uVp LZoPeRCs4zOtIsPHN9n0SE+xF52e2WHFHuKyGdhgRif7j8Hhi6jw+OGP6K7wcZ4BKV8C XtkwMQMMuEl1yZHvKIIkveRffiqgCVvdp6TAIOTikRApH60N8G9wu1Rc4/pBzSZsnbXw IxPhD+YPB95xe73GYPUOH4cm22scxDbFsg7PWD3SfD8cKc8R9utVxjn0C+sPPWsMQMe8 85yQ== X-Gm-Message-State: AOJu0YwBwdtUJ2gm7sUG1nju6nPfxUV2qgSwvCmJ9zwYLUw+matg97m7 BeyByID1DQgKh39xtxhPfevqXVKD/hiPx3bdsd7j X-Received: by 2002:a05:6358:52c2:b0:143:1063:d1ed with SMTP id z2-20020a05635852c200b001431063d1edmr11416237rwz.26.1696666916406; Sat, 07 Oct 2023 01:21:56 -0700 (PDT) MIME-Version: 1.0 References: <2023100643-tricolor-citizen-6c2d@gregkh> In-Reply-To: <2023100643-tricolor-citizen-6c2d@gregkh> From: Yongji Xie Date: Sat, 7 Oct 2023 16:21:45 +0800 Message-ID: Subject: Re: [PATCH] vduse: make vduse_class constant To: Greg Kroah-Hartman Cc: virtualization , linux-kernel , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 07 Oct 2023 01:22:37 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 6, 2023 at 10:31=E2=80=AFPM Greg Kroah-Hartman wrote: > > Now that the driver core allows for struct class to be in read-only > memory, we should make all 'class' structures declared at build time > placing them into read-only memory, instead of having to be dynamically > allocated at runtime. > > Cc: "Michael S. Tsirkin" > Cc: Jason Wang > Cc: Xuan Zhuo > Cc: Xie Yongji > Signed-off-by: Greg Kroah-Hartman > --- Reviewed-by: Xie Yongji Thanks, Yongji > drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 19 deletions(-) > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/= vduse_dev.c > index df7869537ef1..0ddd4b8abecb 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -134,7 +134,6 @@ static DEFINE_MUTEX(vduse_lock); > static DEFINE_IDR(vduse_idr); > > static dev_t vduse_major; > -static struct class *vduse_class; > static struct cdev vduse_ctrl_cdev; > static struct cdev vduse_cdev; > static struct workqueue_struct *vduse_irq_wq; > @@ -1528,6 +1527,16 @@ static const struct kobj_type vq_type =3D { > .default_groups =3D vq_groups, > }; > > +static char *vduse_devnode(const struct device *dev, umode_t *mode) > +{ > + return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev)); > +} > + > +static const struct class vduse_class =3D { > + .name =3D "vduse", > + .devnode =3D vduse_devnode, > +}; > + > static void vduse_dev_deinit_vqs(struct vduse_dev *dev) > { > int i; > @@ -1638,7 +1647,7 @@ static int vduse_destroy_dev(char *name) > mutex_unlock(&dev->lock); > > vduse_dev_reset(dev); > - device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)= ); > + device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor= )); > idr_remove(&vduse_idr, dev->minor); > kvfree(dev->config); > vduse_dev_deinit_vqs(dev); > @@ -1805,7 +1814,7 @@ static int vduse_create_dev(struct vduse_dev_config= *config, > > dev->minor =3D ret; > dev->msg_timeout =3D VDUSE_MSG_DEFAULT_TIMEOUT; > - dev->dev =3D device_create_with_groups(vduse_class, NULL, > + dev->dev =3D device_create_with_groups(&vduse_class, NULL, > MKDEV(MAJOR(vduse_major), dev->minor), > dev, vduse_dev_groups, "%s", config->name= ); > if (IS_ERR(dev->dev)) { > @@ -1821,7 +1830,7 @@ static int vduse_create_dev(struct vduse_dev_config= *config, > > return 0; > err_vqs: > - device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)= ); > + device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor= )); > err_dev: > idr_remove(&vduse_idr, dev->minor); > err_idr: > @@ -1934,11 +1943,6 @@ static const struct file_operations vduse_ctrl_fop= s =3D { > .llseek =3D noop_llseek, > }; > > -static char *vduse_devnode(const struct device *dev, umode_t *mode) > -{ > - return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev)); > -} > - > struct vduse_mgmt_dev { > struct vdpa_mgmt_dev mgmt_dev; > struct device dev; > @@ -2082,11 +2086,9 @@ static int vduse_init(void) > int ret; > struct device *dev; > > - vduse_class =3D class_create("vduse"); > - if (IS_ERR(vduse_class)) > - return PTR_ERR(vduse_class); > - > - vduse_class->devnode =3D vduse_devnode; > + ret =3D class_register(&vduse_class); > + if (ret) > + return ret; > > ret =3D alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vdus= e"); > if (ret) > @@ -2099,7 +2101,7 @@ static int vduse_init(void) > if (ret) > goto err_ctrl_cdev; > > - dev =3D device_create(vduse_class, NULL, vduse_major, NULL, "cont= rol"); > + dev =3D device_create(&vduse_class, NULL, vduse_major, NULL, "con= trol"); > if (IS_ERR(dev)) { > ret =3D PTR_ERR(dev); > goto err_device; > @@ -2141,13 +2143,13 @@ static int vduse_init(void) > err_wq: > cdev_del(&vduse_cdev); > err_cdev: > - device_destroy(vduse_class, vduse_major); > + device_destroy(&vduse_class, vduse_major); > err_device: > cdev_del(&vduse_ctrl_cdev); > err_ctrl_cdev: > unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX); > err_chardev_region: > - class_destroy(vduse_class); > + class_unregister(&vduse_class); > return ret; > } > module_init(vduse_init); > @@ -2159,10 +2161,10 @@ static void vduse_exit(void) > destroy_workqueue(vduse_irq_bound_wq); > destroy_workqueue(vduse_irq_wq); > cdev_del(&vduse_cdev); > - device_destroy(vduse_class, vduse_major); > + device_destroy(&vduse_class, vduse_major); > cdev_del(&vduse_ctrl_cdev); > unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX); > - class_destroy(vduse_class); > + class_unregister(&vduse_class); > } > module_exit(vduse_exit); > > -- > 2.42.0 >