Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755177AbdHYIfr (ORCPT ); Fri, 25 Aug 2017 04:35:47 -0400 Received: from mail-db5eur01on0042.outbound.protection.outlook.com ([104.47.2.42]:44352 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755067AbdHYIcr (ORCPT ); Fri, 25 Aug 2017 04:32:47 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Florent.Revest@arm.com; From: Florent Revest To: linux-arm-kernel@lists.infradead.org Cc: matt@codeblueprint.co.uk, ard.biesheuvel@linaro.org, pbonzini@redhat.com, rkrcmar@redhat.com, christoffer.dall@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, marc.zyngier@arm.com, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, leif.lindholm@arm.com, revestflo@gmail.com, Florent Revest Subject: [RFC 07/11] KVM: Allow initialization before the module target Date: Fri, 25 Aug 2017 09:31:37 +0100 Message-Id: <1503649901-5834-8-git-send-email-florent.revest@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1503649901-5834-1-git-send-email-florent.revest@arm.com> References: <1503649901-5834-1-git-send-email-florent.revest@arm.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: HE1PR09CA0051.eurprd09.prod.outlook.com (2603:10a6:7:3c::19) To HE1PR08MB0812.eurprd08.prod.outlook.com (2a01:111:e400:59b1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea6a959b-ed80-4e7b-3414-08d4eb93d0cb X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:HE1PR08MB0812; X-Microsoft-Exchange-Diagnostics: 1;HE1PR08MB0812;3:h66OWuFF4zb+zGgE4BkAEWf2/XZZPtMC33NaE2JURfeCvW/9m8vgI84bMwy2hJ99IvMNYcYIK5SvBDVMxGjTocofeZX7EyXdTIHKCJ1reP1Nr64G3jkcjEeHHTdDaTYRoe8hzLme6jaGuDt2wRtEG0pit4j8v3LxZhAkuf3uO/LjqEsZFKXZLpb3qlWzp+MN12VGby+fG4AgYRYxqqX1ULFi89Z++WpzBL7lhV3lHQy2/eggDZjcyLzTom+fnVLa;25:PfAV4v9mu6MnDiU++C11Z2nNwKhUKtCrqiG5TgV1rRo4AaZHBl4n9rUf3kOkUmyNA59hU/zNHKV0pbY84YKhopS9019E0+tJIKlcmgSXrzqPOBDldGjwJVro2n2Uag+PI6K+crXjWqhH4GA3vw19oSHk5wdWYSBeshgx+E2/J/Hkdq3NtU49ydItTk7ivSWwzI6iotq3coDr/y6muHfTJfNqigF0PMXlz9weecFXegMXa+AsXwVAdBnOUgH42rQTQ5HEYKhrSWlAJlLLir+SfsWCuPT23uQfs2Gwo62nAS0meXkOF6YHjblNy+PJi1PNrLoCAYb/0IDUzWdRuds/gQ==;31:UjLSlswRGWfqWRIfnaZQm5u0LliXz4AmJt0U0egRi7lC6mLwbhhSM4Tj4GSJTgFSMAUs504h1LTYs0058IATlXcLffZwG9n36UO1Ks/i91aLLPJnV8qsYa9xSzh9EXmG/F8yxS6HeBywD+QixbR10kE/Hzspcp56/OVPym7bYgLYS1cvdQP/+YVKUSrK3vGDNU/9XbtbP/9jyWm/AVhE3nbNMDA1SfnTl5YXR3UA85s= X-MS-TrafficTypeDiagnostic: HE1PR08MB0812: X-Microsoft-Exchange-Diagnostics: 1;HE1PR08MB0812;20:DHzc8Mm3jdNMUY3ZPGO10WoddMlX0/nn53FfGRDb+v14HIQMPGxjJWReVzQiTkTEcxmL5azK+bIF26y7w/3WQlX1FD64EIAIkCeoZp5b1kY8cm9dwtRVIc9D4Hx0xznTG29Sg1dfoOCMszaC+/OLXSxE6w1qPVFp18vVgXIh0fkP+9Gz7OFKeuVBn392CDlOkHHPoDOGJG1/O7eyRGEsKfUYgzGsLLb9T4MYvHW5L5kVYcLYFSTLgWD7EQxfmlrh2778qg4VdRvyGgnutuXdvYx+/dARSMYBJm3emB2zXfVTMHOixfCLVl5T2sWIWRx7/aty+IURzXlbslkiNqf0vvmXtIIi4xJSlWOOzGqOSUHdOY5HosgeZtUs/BtAV5V7nRqOxHCgGt6MG9xZ+DG3Vb4St/A7bAOXAR5Vt0TFu7jF3bWwSxQguTdh7tPttvRBoF5R6BJtvNJZx6qK5PUHTJdakBnNvqdRps1uzWP16g89Z+cZzZAVpNU5+8Ux4qae;4:sTlYyp0dcRyzn1pbW+6id2ozYYugOjVXPeXjTnEeCwPbktf9fK50lviKTyPyivFKtoGv03ELbE+JNvvjwKNWlRmRkWg7vF2ubeIqNlJeiSKY483te4gCjMQKr1C7XYzq0akuajec++CvwKHzXLGXnqDAYrde0aHZO3X7zz7682UG/ZE1yyiB59TWuKJ2Nypvr6ka9Fm/vTGI8NX3YgCwFOe1hF+gM7csGcihouZ8fRxnAg3AMK1s8BLDCVcW9RsaUbtQqUOycgmsf7rrqr2AkJFoYF3qozAZz26XF0ICO04= X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:HE1PR08MB0812;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:HE1PR08MB0812; X-Forefront-PRVS: 041032FF37 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6009001)(39860400002)(199003)(40434004)(189002)(478600001)(68736007)(76176999)(25786009)(5660300001)(97736004)(36756003)(6486002)(50226002)(47776003)(50986999)(50466002)(4326008)(48376002)(7350300001)(110136004)(66066001)(7416002)(8676002)(189998001)(305945005)(5890100001)(6916009)(2351001)(105586002)(42186005)(6116002)(2361001)(8746002)(3846002)(575784001)(86362001)(2906002)(72206003)(81156014)(81166006)(2950100002)(106356001)(6666003)(7736002)(33646002)(101416001)(5003940100001)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR08MB0812;H:e106757-lin.cambridge.arm.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR08MB0812;23:yMx73gC/vZugRtHk+zZKgquV09gqWBCTLF7P9xfAd?= =?us-ascii?Q?60H39jgHsHg1aXkep6ULMEt1F3WPINYOMD6kKJJq1DXjptB8404b1MnF+rOU?= =?us-ascii?Q?jyOMmAF/QgxXOv6a3zaXvoWVEZryJC2SRFxbQ+UNW9c4QjtTkcaLnSWI2rq7?= =?us-ascii?Q?1wEzK21WOFxrHGWee259c+yt7eVI/fFLr04gt1Z0hJfjEbVpnFYzoGht/cMf?= =?us-ascii?Q?r7HiDgj2f8q4jBKs3wynIXye+D8B5MooOdgKU6ry9w3AE63c2e7i3VouvJEQ?= =?us-ascii?Q?P0P2Ci8VVVNPPMZe9/WU/2q/HwoxsKlnpRGp3C57ZG9f1QMeiaLeXvd6AYY9?= =?us-ascii?Q?ni77PN5ox6xbqtubuAia1Jilnz/8cczqorXSo9IX6wHHh48IoFkOgDXtpd6D?= =?us-ascii?Q?60SNzpuL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E1PR08MB0812;6:8KzjcEw6sS+7BV3xth5jll7d/tHlJrKBRC+6JhKWiqT/G7MhvODxVExu2Rc4WsKylDypj0nQU+RhtBAoKA98RPdJOFFU4HF41brnyuEW9G+9Bl6jm0xkVy2z3oN/zHMqHtKfNmBgBLJm4T4C6duQIFcK5g6yjcJsKCjQiOGqEttzLb/WGCh9N+8cPLoCfBnPGLl3kfJSA1TTWPPz0SqHHNARsKE5+k7giBzNWfuHlNmeXdkeL9xy/b4Mz9aEIVMKG3i6Bi+Z4PCipkk5EvhmYuaQEiG8a0YItJ12q0q3oCia5vklTmHxhihNydGfd91/xbiYATxVkQaMDSQ7uudHnQ==;5:ENFfjBM3FzZqStiyJTCbBhV7p0XrsuhU5kbBOqCu0sPOUCPAHekFXEV+0kAnjvEx/MrwwYkVhTj3rEERU0lMDLo/pvi83OgryBiuxlG3z69kGP0hrnjpR/WhTvWLOk9q6ehuQDzMC2986Alg5QjiZA==;24:xc6PF95tW1YEMjg9SCclWHNTRRwETb8ej+TLH4NS6cSsn6s6XFoXlBSYNoNL6+hpbujcrZVYHd9Q2hz7BIBgneuKOUoa4Q31ZHtXYw35mEs=;7:QcLr/zfT48EgO4qy4nvwNAqjoYr8uaXaS6zTegP+/aRA/q8KeIz6WltAGPiP2KCFIbTvK1V3Kuqur/fGhLu9Voh0oPkHx5bxipXxC7xl7VwhBYDJciGi/hu+1kzzmciRYBP8Hjtk2f2FTfMT8mMIq1/pxK3IK0WfvZwN7ccI+LEQyimYecflbdfD9GFAy+8i8tAJiKji2LdVTE1lxSDI5hjsvRWB1xLG1hy/KCAq1fw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2017 08:32:25.0998 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB0812 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v7P8ZsR6010000 Content-Length: 3157 Lines: 84 The kvm_init function has been designed to be executed during the module_init target. It requires a struct module pointer to be used as the owner of the /dev/* files and also tries to register /dev/kvm with a function (misc_register) that can only be used late in the boot process. This patch modifies kvm_init to execute this late initialization code conditionally, only in the context of a module_init. It also offers a kvm_set_module function to be used for /dev/kvm registration and device files owning once the module target is reached. As is, this patch does not change anything. However it could be used by certain architectures to initialize the core of kvm earlier in the boot (e.g: in a subsys_initcall) and then initialize the userspace facing files in a module_init target. This can be useful to create internal VMs before being able to offer the userspace APIs. Signed-off-by: Florent Revest --- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index dd10d3b..15a0a8d 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -563,6 +563,7 @@ static inline void kvm_irqfd_exit(void) #endif int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, struct module *module); +int kvm_set_module(struct module *module); void kvm_exit(void); struct kvm *kvm_create_internal_vm(unsigned long type); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c1c8bb6..3c9cb00 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4086,14 +4086,10 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, if (r) goto out_free; - kvm_chardev_ops.owner = module; - kvm_vm_fops.owner = module; - kvm_vcpu_fops.owner = module; - - r = misc_register(&kvm_dev); - if (r) { - pr_err("kvm: misc device register failed\n"); - goto out_unreg; + if (module) { + r = kvm_set_module(module); + if (r) + goto out_unreg; } register_syscore_ops(&kvm_syscore_ops); @@ -4136,6 +4132,22 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, } EXPORT_SYMBOL_GPL(kvm_init); +int kvm_set_module(struct module *module) +{ + int r; + + kvm_chardev_ops.owner = module; + kvm_vm_fops.owner = module; + kvm_vcpu_fops.owner = module; + + r = misc_register(&kvm_dev); + if (r) + pr_err("kvm: misc device register failed\n"); + + return r; +} +EXPORT_SYMBOL_GPL(kvm_set_module); + void kvm_exit(void) { debugfs_remove_recursive(kvm_debugfs_dir); -- 1.9.1 IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.