From patchwork Tue Jun 20 14:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3739642vqr; Tue, 20 Jun 2023 08:15:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/AlwkBXUpO6mIP0W3okG7xRF+bdiwpbVrElxDaktX6prcfyjJros2swihXKctza+tljCC X-Received: by 2002:a17:90a:2f47:b0:253:8260:f9aa with SMTP id s65-20020a17090a2f4700b002538260f9aamr7235690pjd.6.1687274136769; Tue, 20 Jun 2023 08:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687274136; cv=none; d=google.com; s=arc-20160816; b=PO+vW1kq84ONKOPdcY9mgGkggWZAMNaUuKscLet0rYlO1sKoYqC8p21nSMAYQlezC2 asm9JtiNM3xXqwhOi/zott5/ON8Dgn9G2NS3tH9Cph9A9txlltbZDlZqT/rVnDWBs5n7 fv0C8iY8rYCrnesTervXv3x/WETJr8S4bPHgaAmcty+PC64cO80seSnjFzQD7zSKzL22 Zaa0Qz0VhilOLilOK2Zen/WiuXo3NKnC5wlMzt59zw0tLCxpFS6GBu7nXJe3CwS9GnCL 6UfPducw+jisLaS3eSMrV8s+m6DHC7qSxeU4vREz9+QQrHl8Xdo+K7YGIuEqC2WE7ls8 Ld1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ZMa3PG08pyVeP024oldwHuMmurBg9Nk8kmlC4xLzG/M=; b=e3xdS4Vj2r93RtGubW/RyPvxiWu+kBqyUp9DRra3givZbKaXX844EZaJH3jPYmV7YZ Pzii/AzOhBvShY8hxG4HqCfvxCnn1sjW0w8H39BZU4zFtSwVx0FrQoM7pIk5uUqiNLG/ 6ly8dbJycf+Ukx+4AATjk2r+N7PGi3qJuEhY38ybVWTrYLm+Q8YRPMtRQYb2pf376Ew+ mB3nM5//irx5Fx5XilP4tVTxaeZ6e93iATymUYhNdflLbeCXymkvb476cD1S41OWiiw8 8x4ReKs8SSjO8u8g2aDLWaSVlsVL1jiHBCAXTLt1Nz1VRQvLAsNqIQBI7wZGV++UE53S bMpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JQXTek8z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 26-20020a17090a031a00b0025ef64e6357si5512062pje.127.2023.06.20.08.15.22; Tue, 20 Jun 2023 08:15:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JQXTek8z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233141AbjFTOol (ORCPT + 99 others); Tue, 20 Jun 2023 10:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbjFTOoj (ORCPT ); Tue, 20 Jun 2023 10:44:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5BAE1A4 for ; Tue, 20 Jun 2023 07:44:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 68459612A3 for ; Tue, 20 Jun 2023 14:44:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 790D9C433C0; Tue, 20 Jun 2023 14:44:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687272277; bh=i6meXYqzLbS/T0+2ewiMbX093Oqmfn9KIdm7F7gK6M4=; h=From:To:Cc:Subject:Date:From; b=JQXTek8zGep3caKrdUoaW7M5Enue8KiHrWKsE1hsNc7D4oF1wUTkmaV/VF1XjB+Ej d87yR7YNNRsSxgbZMVxDlL0KFvNGts5jS8SB19helGvZx6cr0EXyax7orzNPu8rjOc mnpZ8X+mNS48DNt8kV0hd+dGzxFB6AwdDOQyfifw= From: Greg Kroah-Hartman To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Ivan Orlov , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Greg Kroah-Hartman Subject: [PATCH 1/3] x86/cpuid: make cpuid_class a static const structure Date: Tue, 20 Jun 2023 16:44:32 +0200 Message-ID: <20230620144431.583290-4-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3139; i=gregkh@linuxfoundation.org; h=from:subject; bh=aBTFKVZ8OOd4/o/cKdaCS1NflsAv/K3saJjhqsnO3t0=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTd/tHzZh33qhUYeZvlee2Zd+Dc846ic7lEHlmlXlX8 cc2o+kyHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCR6p0MCzY2m9V67toaf3b1 XyXBXzJhwkJPqhjm6e6z+vDg/p3p35dEvvr3eZHjfz5dPQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769235165123449513?= X-GMAIL-MSGID: =?utf-8?q?1769235165123449513?= From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the cpuid_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: "H. Peter Anvin" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpuid.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c index bdc0d5539b57..dae436253de4 100644 --- a/arch/x86/kernel/cpuid.c +++ b/arch/x86/kernel/cpuid.c @@ -40,7 +40,6 @@ #include #include -static struct class *cpuid_class; static enum cpuhp_state cpuhp_cpuid_state; struct cpuid_regs_done { @@ -124,26 +123,31 @@ static const struct file_operations cpuid_fops = { .open = cpuid_open, }; +static char *cpuid_devnode(const struct device *dev, umode_t *mode) +{ + return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt)); +} + +static const struct class cpuid_class = { + .name = "cpuid", + .devnode = cpuid_devnode, +}; + static int cpuid_device_create(unsigned int cpu) { struct device *dev; - dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL, + dev = device_create(&cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL, "cpu%d", cpu); return PTR_ERR_OR_ZERO(dev); } static int cpuid_device_destroy(unsigned int cpu) { - device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu)); + device_destroy(&cpuid_class, MKDEV(CPUID_MAJOR, cpu)); return 0; } -static char *cpuid_devnode(const struct device *dev, umode_t *mode) -{ - return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt)); -} - static int __init cpuid_init(void) { int err; @@ -154,12 +158,9 @@ static int __init cpuid_init(void) CPUID_MAJOR); return -EBUSY; } - cpuid_class = class_create("cpuid"); - if (IS_ERR(cpuid_class)) { - err = PTR_ERR(cpuid_class); + err = class_register(&cpuid_class); + if (err) goto out_chrdev; - } - cpuid_class->devnode = cpuid_devnode; err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/cpuid:online", cpuid_device_create, cpuid_device_destroy); @@ -170,7 +171,7 @@ static int __init cpuid_init(void) return 0; out_class: - class_destroy(cpuid_class); + class_unregister(&cpuid_class); out_chrdev: __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); return err; @@ -180,7 +181,7 @@ module_init(cpuid_init); static void __exit cpuid_exit(void) { cpuhp_remove_state(cpuhp_cpuid_state); - class_destroy(cpuid_class); + class_unregister(&cpuid_class); __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); } module_exit(cpuid_exit); From patchwork Tue Jun 20 14:44:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3742741vqr; Tue, 20 Jun 2023 08:20:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Xp1/UkBihyF39SfebJcBs5HF2cPR/0Esz0/00ZQFU+t6KDO/Igg2KlRbCn6Mz63ebTHeu X-Received: by 2002:a05:6a20:4fa3:b0:11d:2b0c:7f49 with SMTP id gh35-20020a056a204fa300b0011d2b0c7f49mr9020243pzb.36.1687274399709; Tue, 20 Jun 2023 08:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687274399; cv=none; d=google.com; s=arc-20160816; b=AubSDHPgITVbix34e1t1qxLDgTSBfWifKB2RS1PTJAVYxTBkdGCCjwhptRzaGWBNWd LZhJGrbTV/+tQJrxtEDRLK8IJ8OBJ44J6wR8XNVFzLGAUtaMTm+JG/WXdsRROS2hg85v x+3+t3mgaUuRQyuH2w4kFNtFYidMvqVETtCQoHgrOipPuTe5+tITmmblCR1434vt8qLl 5TYeVmftUA6fVlk24IepyaZDADVWxrIeZoTmYaAJX28UUriNUEsQLfzOXqP2A7Kn0Bv3 9LHWihAQQ/fO/HhN/V7Obr6Pd1XtaFKYIp85kQtIK4jhNCHnCzBoQF3qVbDIkNdvXIvc qMiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S2KhalGs46EH+Qp0iSKRFoFtD6MviRvU7QleG9a24cA=; b=anynTLXxyNatI/ElqSGXB6Bf5ydVo/EdY74RtCjAKOJDS4Y37y7Z1lUdD8Y9kawQGE Np5DzrT69lqxXL2JaND3GLPvtSEjlRCGq2LT2GwNgexvkUXosbA6cuti/ENO6qrFqipA fQGA2NfBaRghIWqXfXuYdaCeUHBnAQIQuiC7W9QIP/XNwuferltuBiK6h7jESCZQZPSQ zxWnjnCT5ud5kZvsvoCtkgilD5ASnQV6LJ7Qr1tk5sNFueC4pkibMM6scq90rKzSes87 9cdJVvuHgK/W/yeMv3svr2ntx613t69FY2WgHGnjG36iI3EuXwnGQej1u7DNEfrnHf1m B+EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sqKJzl5O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c21-20020a624e15000000b006432e1ea8e4si1957106pfb.14.2023.06.20.08.19.45; Tue, 20 Jun 2023 08:19:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sqKJzl5O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233158AbjFTOoj (ORCPT + 99 others); Tue, 20 Jun 2023 10:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232204AbjFTOoh (ORCPT ); Tue, 20 Jun 2023 10:44:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B671A4 for ; Tue, 20 Jun 2023 07:44:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5C63612A3 for ; Tue, 20 Jun 2023 14:44:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93A9CC433C8; Tue, 20 Jun 2023 14:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687272275; bh=ZS4Ma8KGECNAShkM8JDnUCoN4X024GBO7+VXioAiQOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sqKJzl5Oy8nDvHjVWIMXDTtE+FvqXAThnODgirzp2HvH6ohctvQE1zC9eMjoCQXle 9zA7Rp7CajM/wpjpU7pA6ECuNniyvDNwKXYioBDm+OYpnmwpoqCD5hpFOUq0+Xi8de o2gIiZJjS3E8wxpIeBR8OT3lR8CCb6qsFs6zKVBM= From: Greg Kroah-Hartman To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Ivan Orlov , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Greg Kroah-Hartman Subject: [PATCH 2/3] x86/MSR: make msr_class a static const structure Date: Tue, 20 Jun 2023 16:44:33 +0200 Message-ID: <20230620144431.583290-5-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620144431.583290-4-gregkh@linuxfoundation.org> References: <20230620144431.583290-4-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3079; i=gregkh@linuxfoundation.org; h=from:subject; bh=QDmKO6VsyrTokC1ZOS4qNRgZzQOeNd6yP/KZZtalGwM=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTd/u3q2mW+Py3/J5//cR115zNiysLZqmnH962ztma/ c46dpNjHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRWfcY5hd9/D9FPn8x17qM iMAzYW5v1HY2ODPMlZX5vPWcyl430ap1XRxF4rn2JS1HAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769235440665003690?= X-GMAIL-MSGID: =?utf-8?q?1769235440665003690?= From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the msr_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: "H. Peter Anvin" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/msr.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c index 7bb17d37db01..e17c16c54a37 100644 --- a/arch/x86/kernel/msr.c +++ b/arch/x86/kernel/msr.c @@ -39,7 +39,6 @@ #include #include -static struct class *msr_class; static enum cpuhp_state cpuhp_msr_state; enum allow_write_msrs { @@ -235,26 +234,31 @@ static const struct file_operations msr_fops = { .compat_ioctl = msr_ioctl, }; +static char *msr_devnode(const struct device *dev, umode_t *mode) +{ + return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt)); +} + +static const struct class msr_class = { + .name = "msr", + .devnode = msr_devnode, +}; + static int msr_device_create(unsigned int cpu) { struct device *dev; - dev = device_create(msr_class, NULL, MKDEV(MSR_MAJOR, cpu), NULL, + dev = device_create(&msr_class, NULL, MKDEV(MSR_MAJOR, cpu), NULL, "msr%d", cpu); return PTR_ERR_OR_ZERO(dev); } static int msr_device_destroy(unsigned int cpu) { - device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu)); + device_destroy(&msr_class, MKDEV(MSR_MAJOR, cpu)); return 0; } -static char *msr_devnode(const struct device *dev, umode_t *mode) -{ - return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt)); -} - static int __init msr_init(void) { int err; @@ -263,12 +267,9 @@ static int __init msr_init(void) pr_err("unable to get major %d for msr\n", MSR_MAJOR); return -EBUSY; } - msr_class = class_create("msr"); - if (IS_ERR(msr_class)) { - err = PTR_ERR(msr_class); + err = class_register(&msr_class); + if (err) goto out_chrdev; - } - msr_class->devnode = msr_devnode; err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online", msr_device_create, msr_device_destroy); @@ -278,7 +279,7 @@ static int __init msr_init(void) return 0; out_class: - class_destroy(msr_class); + class_unregister(&msr_class); out_chrdev: __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); return err; @@ -288,7 +289,7 @@ module_init(msr_init); static void __exit msr_exit(void) { cpuhp_remove_state(cpuhp_msr_state); - class_destroy(msr_class); + class_unregister(&msr_class); __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); } module_exit(msr_exit) From patchwork Tue Jun 20 14:44:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3724556vqr; Tue, 20 Jun 2023 07:56:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51z568HLjw6XjMTjDxxBLeyBqysyF6tByJeNAENPDbDpMhJFbPx2h9vDw0KlyZDyRrUBzq X-Received: by 2002:a17:90a:f2d2:b0:25e:86ab:f4d7 with SMTP id gt18-20020a17090af2d200b0025e86abf4d7mr11743595pjb.22.1687273014319; Tue, 20 Jun 2023 07:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687273014; cv=none; d=google.com; s=arc-20160816; b=qKAvEklGuprGa90mSmolueI01H3Z1RhMGY/Tzhu5EEphH+WBdLcNes692HG30pskXu lMn6bcRPyW1Cu8v4iODlpdboCnPX4ROIRE4TJqLI9wClhCfAnY5MYIBmKWrR0oj1SHkB nt9dV4DvYDRkeMyBz3zIBGulnAP9w20OQrEvbYKxzuqliG1NAhOzeEw8wyTvrDQwyVqw 8xgZpqR08Yrf0rxLLQ6hhyOvPxoWAiYirlQ4Fs2OD8bZnzm+LSqKxuQMH/G+Kq79qxx3 Q7i7KeNwjfweVS6benHIgB+Me4YlFgNp+GLhRHlEPqsDxnD68kP94bjrZot50L6tLT3v TiGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WY2chNgunmkezs4ZsDoVnj+Gqfz2zU61Qap54PQ9+dc=; b=YGusk3xJQw+RG1mKjx9hfB8j/5jNBCtIP06xVltyqOBdvjIkkJ5RaA5Zl07zfi/lMV cukqOMVubPFCzXIQPnpeng5TL5DJhANWrleZOlIqwoyxzCPgLNRlQ/2ZFLbli1ZMP3gd 5Rbc4aUh2jlQeM+IAQn+3d7jsaJUwbCAAXkOg7n5GzV543giI+FAOett1OKc7ShOfV5W gmTGUi8Mk66D4uvZ6jZvMfZP/fnJiS183rotrlRsU0iZAGmq5MBAIjqUQn6zMCDHJ/yd uyAwMD6up6Z5JLxTNqNuNCZsnS+6z5RN5J6a9wCpXWI0q1JXFHLHJndM0dWugRrySMcu Fh2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MLwwgaMm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n31-20020a17090a5aa200b0025691c00096si1993908pji.140.2023.06.20.07.56.39; Tue, 20 Jun 2023 07:56:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MLwwgaMm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233331AbjFTOpQ (ORCPT + 99 others); Tue, 20 Jun 2023 10:45:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233390AbjFTOos (ORCPT ); Tue, 20 Jun 2023 10:44:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782BC172C for ; Tue, 20 Jun 2023 07:44:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C9FC1612DC for ; Tue, 20 Jun 2023 14:44:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2323C433C8; Tue, 20 Jun 2023 14:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687272283; bh=0M+nLDZFlAC5uRcRvEMx4cqFIB9rQ/EvGoomT6DUzoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MLwwgaMml5dK+FvsH6PsvtOiiQAoV4boR4i1tQlPEadC77P2+sXwbSxIp4PEiZIgP HSXE7vnBYJ9iviRTAL++jSv27eMNV+0lGziwRlGKEP86qj4a/Esh6lIClJelE/uZuv +tR910dysRtoUG5PHzjiugQN8txycfwTQpj9dffs= From: Greg Kroah-Hartman To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Ivan Orlov , Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Greg Kroah-Hartman Subject: [PATCH 3/3] x86/resctrl: make pseudo_lock_class a static const structure Date: Tue, 20 Jun 2023 16:44:34 +0200 Message-ID: <20230620144431.583290-6-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620144431.583290-4-gregkh@linuxfoundation.org> References: <20230620144431.583290-4-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3944; i=gregkh@linuxfoundation.org; h=from:subject; bh=ZrmDno1rLPLMmfgPHDkLl0x2OYPv6j0/RiEkxcIsOsI=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTd/uvrP4R+Pdra3ZSeXnI1OfTEsTVnjFV5hkEM8dub 84rtyzpiGVhEGRikBVTZPmyjefo/opDil6Gtqdh5rAygQxh4OIUgImcjWSYw7351gv3jes5d+1P 6PystCDmbO6OhQwLls9a8+Z240fe5VUcpnyzrBllF2yMBwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769233988361579859?= X-GMAIL-MSGID: =?utf-8?q?1769233988361579859?= From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the pseudo_lock_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: Fenghua Yu Cc: Reinette Chatre Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman Acked-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 41 ++++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index 458cb7419502..8f559eeae08e 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -45,7 +45,21 @@ static u64 prefetch_disable_bits; */ static unsigned int pseudo_lock_major; static unsigned long pseudo_lock_minor_avail = GENMASK(MINORBITS, 0); -static struct class *pseudo_lock_class; + +static char *pseudo_lock_devnode(const struct device *dev, umode_t *mode) +{ + const struct rdtgroup *rdtgrp; + + rdtgrp = dev_get_drvdata(dev); + if (mode) + *mode = 0600; + return kasprintf(GFP_KERNEL, "pseudo_lock/%s", rdtgrp->kn->name); +} + +static const struct class pseudo_lock_class = { + .name = "pseudo_lock", + .devnode = pseudo_lock_devnode, +}; /** * get_prefetch_disable_bits - prefetch disable bits of supported platforms @@ -1353,7 +1367,7 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp) &pseudo_measure_fops); } - dev = device_create(pseudo_lock_class, NULL, + dev = device_create(&pseudo_lock_class, NULL, MKDEV(pseudo_lock_major, new_minor), rdtgrp, "%s", rdtgrp->kn->name); @@ -1383,7 +1397,7 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp) goto out; out_device: - device_destroy(pseudo_lock_class, MKDEV(pseudo_lock_major, new_minor)); + device_destroy(&pseudo_lock_class, MKDEV(pseudo_lock_major, new_minor)); out_debugfs: debugfs_remove_recursive(plr->debugfs_dir); pseudo_lock_minor_release(new_minor); @@ -1424,7 +1438,7 @@ void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp) pseudo_lock_cstates_relax(plr); debugfs_remove_recursive(rdtgrp->plr->debugfs_dir); - device_destroy(pseudo_lock_class, MKDEV(pseudo_lock_major, plr->minor)); + device_destroy(&pseudo_lock_class, MKDEV(pseudo_lock_major, plr->minor)); pseudo_lock_minor_release(plr->minor); free: @@ -1560,16 +1574,6 @@ static const struct file_operations pseudo_lock_dev_fops = { .mmap = pseudo_lock_dev_mmap, }; -static char *pseudo_lock_devnode(const struct device *dev, umode_t *mode) -{ - const struct rdtgroup *rdtgrp; - - rdtgrp = dev_get_drvdata(dev); - if (mode) - *mode = 0600; - return kasprintf(GFP_KERNEL, "pseudo_lock/%s", rdtgrp->kn->name); -} - int rdt_pseudo_lock_init(void) { int ret; @@ -1580,21 +1584,18 @@ int rdt_pseudo_lock_init(void) pseudo_lock_major = ret; - pseudo_lock_class = class_create("pseudo_lock"); - if (IS_ERR(pseudo_lock_class)) { - ret = PTR_ERR(pseudo_lock_class); + ret = class_register(&pseudo_lock_class); + if (ret) { unregister_chrdev(pseudo_lock_major, "pseudo_lock"); return ret; } - pseudo_lock_class->devnode = pseudo_lock_devnode; return 0; } void rdt_pseudo_lock_release(void) { - class_destroy(pseudo_lock_class); - pseudo_lock_class = NULL; + class_unregister(&pseudo_lock_class); unregister_chrdev(pseudo_lock_major, "pseudo_lock"); pseudo_lock_major = 0; }