Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp200689lqp; Wed, 20 Mar 2024 19:52:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUytpoLu/yc1f3oEbWTLX08W/2V+68fvGP2gebS23Gl3xzcFXbJjdN9rnm+aeQEah2jNSLaTn/AnQplXQ0bW1Qgx/ZV9siHdWURwKz2Mg== X-Google-Smtp-Source: AGHT+IFGfdyBQsd/GnZ3+/mj91ujL/2ESBO+t0FTSKXj2mi5UZ9Kkc59z2gQjdGJYo2b07/ccMI1 X-Received: by 2002:adf:e801:0:b0:33e:ca3a:1bba with SMTP id o1-20020adfe801000000b0033eca3a1bbamr643155wrm.20.1710989536567; Wed, 20 Mar 2024 19:52:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710989536; cv=pass; d=google.com; s=arc-20160816; b=k6FU/UkDq5RXJnvWHZUF4jIf3pz1R073CJDS1uUWT+QcptXZss+tw5AitlDgWxLOWV tgACdnQ5H2P6FRx+me6moJCbmS2qhfeD+uC5jQm9wqhFgZhcY0iAJqzFys83hrofmMIp dmMYn+wLnHs+q8m1w9FyiCGuLjZRZm5qIW519VmRkILZqCvPDCs+anlp5s+PmSjBodms AA0DVQoaNNnHVuKt9HimXOSiUPeQo3pd/DGdFi7fzm4scFWhM7+YvrpD5gIapEtz0iur 3h9yv0x1oVF6+Hq+eAB5EJgu3mUa3KPUSYH/ibxmAGDjjeo/hFh4TiDqKWzmHw7aMvgB iVIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=eYEegrjH0qqz5TwkXTvElujjd0LDRDev29SImBbbI6Q=; fh=eulCrYuY4zK7Gxr6B+4yAHyThWGi9/x0Te9WMho9aNk=; b=dKgeZh0lrPMiwVTgwzbMUDWW0o1L8yeQlko/sPRLqha0ka61CqfWdlb/A2lZ5PED7K ylg1zDiz+fj/X+AYjOv4I1auZze6sIlfiUabYtr1/ghu6hLh1sSy/U2Vo2pBIXfBxxPV mlT/CHqsyuAIg0Kd/PdQWUAA1tcczwA/fBGcAbY/XsgUZ9Q6xRbckEwxgD4umn1Mi5FJ WMzEC0tp+D641iyirO0aWCWpwYRgCXo93RpLjnBS1tzRjw1sLQuz1jJJkOs5fsQ9TgdG 8pTd5UeMPlPWs+Z2nzVFjnyvrSA/PX3Uwdl2WMU7dwJR1ppuc2p8fJILy/Hk0foCknKo 842Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=SyJXwdCw; arc=pass (i=1 spf=pass spfdomain=amazon.co.uk dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-109603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fi9-20020a170906da0900b00a467df32d76si6116848ejb.446.2024.03.20.19.52.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 19:52:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=SyJXwdCw; arc=pass (i=1 spf=pass spfdomain=amazon.co.uk dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-109603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D50CB1F2239F for ; Thu, 21 Mar 2024 02:52:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85900B651; Thu, 21 Mar 2024 02:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="SyJXwdCw" Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3A0179E0; Thu, 21 Mar 2024 02:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=72.21.196.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989490; cv=none; b=kmKi96vjm8sJPuheIj5gxilpsuZxVLLTGG2YX187bwh9wweYlkTPlYLrJGAiK24eNP/uzQ7Ouw4RRv9E7W2lomZDfAlD4r3DTDF/a1H90l6As5KrRUjYGzb1ZrRGrjwocp5jnIxsZATw/S/8OTmwC5tpRctT5ia+5y2Slx2m6Pc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989490; c=relaxed/simple; bh=ZaV+ev/jI/fqWFZttEUarlNcX/sXAziMRGH2RquOLcA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HDmJtOS85PQwC1IyHl8wSfcIqc3/MwGYBuDlNDr07zQAI0+nmvMc5fQj7/GOF3NaW1hrDFLFC6i26nQlOGKjkfgxtNgWZ0g+LWSP4l5KGD6i1jesNUpPMR8yae2pc0St8tzswAxmsSEVmmEnhI+RX28GWVYgXAacgJ+8lnwzYXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=SyJXwdCw; arc=none smtp.client-ip=72.21.196.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710989488; x=1742525488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eYEegrjH0qqz5TwkXTvElujjd0LDRDev29SImBbbI6Q=; b=SyJXwdCwLO4IwiTLCjZ2gCw7vHZqLkILudK+qpZpjkfKlYy3ZTmZyqBy 8J3U5ayWzX2jouFxs9UFxWAl82kpQhGGKY9QN2rt/PE/nvEIPO7E1d9yD 0KYanP810SM5jFSBtImy7LZ3LhMzECzWZCygaHOUUZDgB82WSuqyPi/xL 4=; X-IronPort-AV: E=Sophos;i="6.07,141,1708387200"; d="scan'208";a="389303561" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 02:51:27 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.43.254:45281] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.23.112:2525] with esmtp (Farcaster) id 27a5a9e3-969a-4190-92f4-a01d47d4f75c; Thu, 21 Mar 2024 02:51:27 +0000 (UTC) X-Farcaster-Flow-ID: 27a5a9e3-969a-4190-92f4-a01d47d4f75c Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 21 Mar 2024 02:51:26 +0000 Received: from bcd074994f7f.amazon.com (10.106.82.23) by EX19D036EUC002.ant.amazon.com (10.252.61.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 21 Mar 2024 02:51:22 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v2 2/4] virt: vmgenid: change implementation to use a platform driver Date: Thu, 21 Mar 2024 02:51:03 +0000 Message-ID: <20240321025105.53210-3-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240321025105.53210-1-sudanl@amazon.com> References: <20240321025105.53210-1-sudanl@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D043UWA002.ant.amazon.com (10.13.139.53) To EX19D036EUC002.ant.amazon.com (10.252.61.191) Re-implement vmgenid as a platform driver in preparation for adding devicetree bindings support in next commits. Signed-off-by: Sudan Landge --- drivers/virt/vmgenid.c | 101 ++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 27 deletions(-) diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index ea956df02874..d5394c706bd9 100644 --- a/drivers/virt/vmgenid.c +++ b/drivers/virt/vmgenid.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include ACPI_MODULE_NAME("vmgenid"); @@ -21,9 +23,9 @@ struct vmgenid_state { u8 this_id[VMGENID_SIZE]; }; -static void vmgenid_notify(struct acpi_device *device, u32 event) +static void vmgenid_notify(struct device *device) { - struct vmgenid_state *state = acpi_driver_data(device); + struct vmgenid_state *state = device->driver_data; char *envp[] = { "NEW_VMGENID=1", NULL }; u8 old_id[VMGENID_SIZE]; @@ -32,22 +34,34 @@ static void vmgenid_notify(struct acpi_device *device, u32 event) if (!memcmp(old_id, state->this_id, sizeof(old_id))) return; add_vmfork_randomness(state->this_id, sizeof(state->this_id)); - kobject_uevent_env(&device->dev.kobj, KOBJ_CHANGE, envp); + kobject_uevent_env(&device->kobj, KOBJ_CHANGE, envp); } -static int vmgenid_add(struct acpi_device *device) +static void vmgenid_acpi_handler(acpi_handle handle, u32 event, void *dev) { + vmgenid_notify(dev); +} + +static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) +{ + if (IS_ERR(next_id)) + return PTR_ERR(next_id); + + state->next_id = next_id; + memcpy(state->this_id, state->next_id, sizeof(state->this_id)); + add_device_randomness(state->this_id, sizeof(state->this_id)); + return 0; +} + +static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state) +{ + struct acpi_device *device = ACPI_COMPANION(dev); struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER }; - struct vmgenid_state *state; union acpi_object *obj; phys_addr_t phys_addr; acpi_status status; int ret = 0; - state = devm_kmalloc(&device->dev, sizeof(*state), GFP_KERNEL); - if (!state) - return -ENOMEM; - status = acpi_evaluate_object(device->handle, "ADDR", NULL, &parsed); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Evaluating ADDR")); @@ -63,19 +77,42 @@ static int vmgenid_add(struct acpi_device *device) phys_addr = (obj->package.elements[0].integer.value << 0) | (obj->package.elements[1].integer.value << 32); - state->next_id = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, MEMREMAP_WB); - if (IS_ERR(state->next_id)) { - ret = PTR_ERR(state->next_id); + + ret = setup_vmgenid_state(state, + (u8 *)devm_memremap(&device->dev, phys_addr, + VMGENID_SIZE, MEMREMAP_WB)); + if (ret) + goto out; + + dev->driver_data = state; + status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + vmgenid_acpi_handler, dev); + if (ACPI_FAILURE(status)) { + dev_err(dev, "Failed to install acpi notify handler"); + ret = -ENODEV; + dev->driver_data = NULL; goto out; } +out: + ACPI_FREE(parsed.pointer); + return ret; +} - memcpy(state->this_id, state->next_id, sizeof(state->this_id)); - add_device_randomness(state->this_id, sizeof(state->this_id)); +static int vmgenid_add(struct platform_device *pdev) +{ + struct vmgenid_state *state; + struct device *dev = &pdev->dev; + int ret = 0; - device->driver_data = state; + state = devm_kmalloc(dev, sizeof(*state), GFP_KERNEL); + if (!state) + return -ENOMEM; + + ret = vmgenid_add_acpi(dev, state); + + if (ret) + devm_kfree(dev, state); -out: - ACPI_FREE(parsed.pointer); return ret; } @@ -84,20 +121,30 @@ static const struct acpi_device_id vmgenid_ids[] = { { "VM_GEN_COUNTER", 0 }, { } }; +MODULE_DEVICE_TABLE(acpi, vmgenid_ids); -static struct acpi_driver vmgenid_driver = { - .name = "vmgenid", - .ids = vmgenid_ids, - .owner = THIS_MODULE, - .ops = { - .add = vmgenid_add, - .notify = vmgenid_notify - } +static struct platform_driver vmgenid_plaform_driver = { + .probe = vmgenid_add, + .driver = { + .name = "vmgenid", + .acpi_match_table = ACPI_PTR(vmgenid_ids), + .owner = THIS_MODULE, + }, }; -module_acpi_driver(vmgenid_driver); +static int vmgenid_platform_device_init(void) +{ + return platform_driver_register(&vmgenid_plaform_driver); +} + +static void vmgenid_platform_device_exit(void) +{ + platform_driver_unregister(&vmgenid_plaform_driver); +} + +module_init(vmgenid_platform_device_init) +module_exit(vmgenid_platform_device_exit) -MODULE_DEVICE_TABLE(acpi, vmgenid_ids); MODULE_DESCRIPTION("Virtual Machine Generation ID"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Jason A. Donenfeld "); -- 2.40.1