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)