From nobody Sun Feb 8 05:42:09 2026 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 8785379D8; Thu, 21 Mar 2024 02:51:25 +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=1710989488; cv=none; b=AENJh5aAlMk0nug5Lr0HJ9YLF8vHssDynoEn02dsYLPcZw9bL58ThguBptemv3QTKULx6Cftc/wnCPhWkux9cw/m8U9TNYgfGWjyWcfwL7BppK5nC2txR5EIL+12EWcLZgZkxHq/SID4/XqHYTcpcBPdk2s8Y1C8fuNl+emNxyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989488; c=relaxed/simple; bh=V5QfoxDhwAJ0q0BlEtFIGB+N4NV5UoeStGXWV9Li+qA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C/ABRZs8NdzXORvkf2MkKS6mp/OCFm3ma5ytto6NLEoYh41rJ7UEjDZsWPMYt5x5pYh7t2K6mh3DkaoqITS3x8Rl76QCcPyR1bmE1HrIKib0iWHHDWbGuogt1s11gRjLw9kQAGr6NL30thRiGhx8R8KD/0oM7Et12zHGRk3TNnI= 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=eRxvE4r8; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="eRxvE4r8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710989486; x=1742525486; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=780CzWQuS3gw5Y/2WbB9iB+XzN5JGzKplO7LP7fR96Q=; b=eRxvE4r8cucGZq5N1LT3pnOWbPai2R0UgXy5a/BnsZGNf51T0QwHFsae di8Kpvo84k2L6oqxiFcQkgZhoQOk+1dQQx6tYfeSn5WDR59rwYUfh/fF8 2KTnyabFke6KnetG25x9PeWO/S8C2RlyQLR/R7nT0CoMbOFdW07QX1A0x Q=; X-IronPort-AV: E=Sophos;i="6.07,141,1708387200"; d="scan'208";a="389303551" 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:22 +0000 Received: from EX19MTAEUA002.ant.amazon.com [10.0.17.79:55052] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.6.197:2525] with esmtp (Farcaster) id 5cc6084e-03c4-492e-875e-b4cc0c2a6394; Thu, 21 Mar 2024 02:51:22 +0000 (UTC) X-Farcaster-Flow-ID: 5cc6084e-03c4-492e-875e-b4cc0c2a6394 Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) 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:21 +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:17 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v2 1/4] virt: vmgenid: rearrange code to make review easier Date: Thu, 21 Mar 2024 02:51:02 +0000 Message-ID: <20240321025105.53210-2-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: quoted-printable X-ClientProxiedBy: EX19D043UWA002.ant.amazon.com (10.13.139.53) To EX19D036EUC002.ant.amazon.com (10.252.61.191) Content-Type: text/plain; charset="utf-8" Rearrage the functions of vmgenid to make the next commit, which re-implements vmgenid as a platform driver, easier to review. Signed-off-by: Sudan Landge --- drivers/virt/vmgenid.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index b67a28da4702..ea956df02874 100644 --- a/drivers/virt/vmgenid.c +++ b/drivers/virt/vmgenid.c @@ -21,6 +21,20 @@ struct vmgenid_state { u8 this_id[VMGENID_SIZE]; }; =20 +static void vmgenid_notify(struct acpi_device *device, u32 event) +{ + struct vmgenid_state *state =3D acpi_driver_data(device); + char *envp[] =3D { "NEW_VMGENID=3D1", NULL }; + u8 old_id[VMGENID_SIZE]; + + memcpy(old_id, state->this_id, sizeof(old_id)); + memcpy(state->this_id, state->next_id, sizeof(state->this_id)); + 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); +} + static int vmgenid_add(struct acpi_device *device) { struct acpi_buffer parsed =3D { ACPI_ALLOCATE_BUFFER }; @@ -65,20 +79,6 @@ static int vmgenid_add(struct acpi_device *device) return ret; } =20 -static void vmgenid_notify(struct acpi_device *device, u32 event) -{ - struct vmgenid_state *state =3D acpi_driver_data(device); - char *envp[] =3D { "NEW_VMGENID=3D1", NULL }; - u8 old_id[VMGENID_SIZE]; - - memcpy(old_id, state->this_id, sizeof(old_id)); - memcpy(state->this_id, state->next_id, sizeof(state->this_id)); - 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); -} - static const struct acpi_device_id vmgenid_ids[] =3D { { "VMGENCTR", 0 }, { "VM_GEN_COUNTER", 0 }, --=20 2.40.1 From nobody Sun Feb 8 05:42:09 2026 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="SyJXwdCw" 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: quoted-printable X-ClientProxiedBy: EX19D043UWA002.ant.amazon.com (10.13.139.53) To EX19D036EUC002.ant.amazon.com (10.252.61.191) Content-Type: text/plain; charset="utf-8" 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 =20 ACPI_MODULE_NAME("vmgenid"); =20 @@ -21,9 +23,9 @@ struct vmgenid_state { u8 this_id[VMGENID_SIZE]; }; =20 -static void vmgenid_notify(struct acpi_device *device, u32 event) +static void vmgenid_notify(struct device *device) { - struct vmgenid_state *state =3D acpi_driver_data(device); + struct vmgenid_state *state =3D device->driver_data; char *envp[] =3D { "NEW_VMGENID=3D1", NULL }; u8 old_id[VMGENID_SIZE]; =20 @@ -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); } =20 -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 =3D 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 *stat= e) +{ + struct acpi_device *device =3D ACPI_COMPANION(dev); struct acpi_buffer parsed =3D { ACPI_ALLOCATE_BUFFER }; - struct vmgenid_state *state; union acpi_object *obj; phys_addr_t phys_addr; acpi_status status; int ret =3D 0; =20 - state =3D devm_kmalloc(&device->dev, sizeof(*state), GFP_KERNEL); - if (!state) - return -ENOMEM; - status =3D 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) =20 phys_addr =3D (obj->package.elements[0].integer.value << 0) | (obj->package.elements[1].integer.value << 32); - state->next_id =3D devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, M= EMREMAP_WB); - if (IS_ERR(state->next_id)) { - ret =3D PTR_ERR(state->next_id); + + ret =3D setup_vmgenid_state(state, + (u8 *)devm_memremap(&device->dev, phys_addr, + VMGENID_SIZE, MEMREMAP_WB)); + if (ret) + goto out; + + dev->driver_data =3D state; + status =3D 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 =3D -ENODEV; + dev->driver_data =3D NULL; goto out; } +out: + ACPI_FREE(parsed.pointer); + return ret; +} =20 - 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 =3D &pdev->dev; + int ret =3D 0; =20 - device->driver_data =3D state; + state =3D devm_kmalloc(dev, sizeof(*state), GFP_KERNEL); + if (!state) + return -ENOMEM; + + ret =3D vmgenid_add_acpi(dev, state); + + if (ret) + devm_kfree(dev, state); =20 -out: - ACPI_FREE(parsed.pointer); return ret; } =20 @@ -84,20 +121,30 @@ static const struct acpi_device_id vmgenid_ids[] =3D { { "VM_GEN_COUNTER", 0 }, { } }; +MODULE_DEVICE_TABLE(acpi, vmgenid_ids); =20 -static struct acpi_driver vmgenid_driver =3D { - .name =3D "vmgenid", - .ids =3D vmgenid_ids, - .owner =3D THIS_MODULE, - .ops =3D { - .add =3D vmgenid_add, - .notify =3D vmgenid_notify - } +static struct platform_driver vmgenid_plaform_driver =3D { + .probe =3D vmgenid_add, + .driver =3D { + .name =3D "vmgenid", + .acpi_match_table =3D ACPI_PTR(vmgenid_ids), + .owner =3D THIS_MODULE, + }, }; =20 -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) =20 -MODULE_DEVICE_TABLE(acpi, vmgenid_ids); MODULE_DESCRIPTION("Virtual Machine Generation ID"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Jason A. Donenfeld "); --=20 2.40.1 From nobody Sun Feb 8 05:42:09 2026 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) (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 C46FDBE4A; Thu, 21 Mar 2024 02:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.49.90 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989495; cv=none; b=NG6HzJ5t0NTEjE7UARU19JL1wa1ZIKOR0kvys9pIWTyGm/0gBlG5+DwMLy5vPRbdtpjXdvivoc5TZAZOjFnHo1N6z2QF2b1N3qd21UbXmKAjxUqxNN8rWmtOTC3bCzS/g/PieTTBhixeeRm3kjQkUj9Us0vgaTcN1fDoCOJe6nQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989495; c=relaxed/simple; bh=i4WFnTjbboOv3N6BjZB4Dczpvy+GhVVvEUDiM6kzroU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fr6eYIDCJ0kYeQDkgFg9Ul+aBeiYuiM9lpjwFC6NbxJE5Lf1DOiZVkRSJvyfhCB/1b/OvG8SevBnXyqUmQNH/Xa7cABAl5rp/rbUEUYvEJ3hZy1bU3Qi5o65QxSqCYk20GEshN+SR7Ut/XsEdZ5c1Ti8vo8gJQGKwNY/lkaeiTk= 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=ajILYF2/; arc=none smtp.client-ip=52.95.49.90 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="ajILYF2/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710989494; x=1742525494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G5dhZaRQlfB7f7CNYBWHN5QscrDy9JTquI8zOhrJCpk=; b=ajILYF2/e62girKfI9IR7p8CYMBfC5O1vvbPosxeorD+l0dN+4N2HFGs EXqS5XEBlByxsTjwGCmGfBIs8XVADidEvmTdjM7yZIcLtrzs3Pa+qphk+ 1p6j81rmhagwftGgFoNGn743fgYLZlq8PEphnqAFrdIS+7MN4mkNZFuEG 4=; X-IronPort-AV: E=Sophos;i="6.07,141,1708387200"; d="scan'208";a="394817793" 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-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 02:51:33 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.17.79:25006] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.23.112:2525] with esmtp (Farcaster) id 02fcd6f8-c622-4150-946e-5f418e1db5de; Thu, 21 Mar 2024 02:51:32 +0000 (UTC) X-Farcaster-Flow-ID: 02fcd6f8-c622-4150-946e-5f418e1db5de Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) 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:31 +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:27 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v2 3/4] dt-bindings: rng: Add vmgenid support Date: Thu, 21 Mar 2024 02:51:04 +0000 Message-ID: <20240321025105.53210-4-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: quoted-printable X-ClientProxiedBy: EX19D043UWA002.ant.amazon.com (10.13.139.53) To EX19D036EUC002.ant.amazon.com (10.252.61.191) Content-Type: text/plain; charset="utf-8" Virtual Machine Generation ID driver was introduced in commit af6b54e2b5ba ("virt: vmgenid: notify RNG of VM fork and supply generation ID"), as an ACPI only device. VMGenID specification http://go.microsoft.com/fwlink/?LinkId=3D260709 defin= es a mechanism for the BIOS/hypervisors to communicate to the virtual machine that it is executed with a different configuration (e.g. snapshot execution or creation from a template). The guest operating system can use the notification for various purposes such as re-initializing its random number generator etc. As per the specs, hypervisor should provide a globally unique identified, or GUID via ACPI. This patch tries to mimic the mechanism to provide the same functionality which is for a hypervisor/BIOS to notify the virtual machine when it is executed with a different configuration. As part of this support the devicetree bindings requires the hypervisors or BIOS to provide a memory address which holds the GUID and an IRQ which is used to notify when there is a change in the GUID. The memory exposed in the DT should follow the rules defined in the vmgenid spec mentioned above. *Reason for this change*: Chosing ACPI or devicetree is an intrinsic part of an hypervisor design. Without going into details of why a hypervisor would chose DT over ACPI, we would like to highlight that the hypervisors that have chose devicetree and now want to make use of the vmgenid functionality cannot do so today because vmgenid is an ACPI only device. This forces these hypervisors to change their design which could have undesirable impacts on their use-cases, test-scenarios etc. The point of vmgenid is to provide a mechanism to discover a GUID when the execution state of a virtual machine changes and the simplest way to do it is pass a memory location and an interrupt via devicetree. It would complicate things unnecessarily if instead of using devicetree, we try to implement a new protocol or modify other protocols to somehow provide the same functionility. We believe that adding a devicetree binding for vmgenid is a simpler, better alternative to provide the same functionality and will allow such hypervisors as mentioned above to continue using devicetree. More references to vmgenid specs: - https://www.qemu.org/docs/master/specs/vmgenid.html - https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/virtual-machin= e-generation-identifier Signed-off-by: Sudan Landge --- .../devicetree/bindings/rng/vmgenid.yaml | 57 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/rng/vmgenid.yaml diff --git a/Documentation/devicetree/bindings/rng/vmgenid.yaml b/Documenta= tion/devicetree/bindings/rng/vmgenid.yaml new file mode 100644 index 000000000000..4b6ab62cc2ae --- /dev/null +++ b/Documentation/devicetree/bindings/rng/vmgenid.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/rng/vmgenid.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Virtual Machine Generation Counter ID device + +maintainers: + - Jason A. Donenfeld + +description: + Firmwares or hypervisors can use this devicetree to describe + interrupts and the shared resources to inject a Virtual Machine Generati= on + counter. + +properties: + compatible: + const: linux,vmgenctr + + "#interrupt-cells": + const: 3 + description: | + The 1st cell is the interrupt type. + The 2nd cell contains the interrupt number for the interrupt type. + The 3rd cell is for trigger type and level flags. + + interrupt-controller: true + + reg: + description: | + specifies the base physical address and + size of the regions in memory which holds the VMGenID counter. + maxItems: 1 + + interrupts: + description: | + interrupt used to notify that a new VMGenID counter is available. + The interrupt should be Edge triggered. + maxItems: 1 + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + rng@80000000 { + compatible =3D "linux,vmgenctr"; + reg =3D <0x80000000 0x1000>; + interrupts =3D <0x00 0x23 0x01>; + }; + +... diff --git a/MAINTAINERS b/MAINTAINERS index 43b39956694a..cf4b2e10fb49 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18431,6 +18431,7 @@ M: "Theodore Ts'o" M: Jason A. Donenfeld S: Maintained T: git https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git +F: Documentation/devicetree/bindings/rng/vmgenid.yaml F: drivers/char/random.c F: drivers/virt/vmgenid.c =20 --=20 2.40.1 From nobody Sun Feb 8 05:42:09 2026 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) (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 44D897462; Thu, 21 Mar 2024 02:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.190.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989507; cv=none; b=sWDFxshraz8PJC72DkI5/863GnDmMVPPxoJaqnkCUq8bXXnuHiQ/YraYmRRgsbSHWYQJhKG+vY6fz2WTLgC5lRbmP5BKRxKjzmutrMfYIN5uRtHUQZ+CF3cmeS2LzErW0u6en4Yd38/9CawJdxVzpVgcAJVTHyyi8aCgrytRhpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710989507; c=relaxed/simple; bh=Ne9uSAiMJaLyo2UxKCXKDjH6mIO6I4ya4u4Kl+S6IOg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F9huebblMhub1Hg2inry5hZ/ROJTGc/9CJiJvzSMlWpggP0JqSUJH6OrLxI0nY57ReE+Gw5HLzDiOxhHBDoQk5ukklgIqGeDwgX0HeKMlj87NPPSdl2zdAc7gT7piLiBm62RAh6gEuzfDtYmYSy54FvQri2Gfg8Se2g9JYxeInM= 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=kaowWn/i; arc=none smtp.client-ip=207.171.190.10 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="kaowWn/i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710989507; x=1742525507; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w7lsFF7Jt7Wx4QuN10hvG9q2YtU3jwzHcLdTM8DXudE=; b=kaowWn/iq2QpxcsuPiuvOBwjlB1KO28ODAnz+3jOlhgoGnZFd1esyOa3 6fzZDvVrCAKuyMB+KFwK0q4kltOBh23I+FCQQFVbwjFJVbpg3Z5cxe5vs JvcZVrrZwLQZeMpQ2fe+ZOwE/5dPvkBUCBkrVRhpF0i+yzQUc+oB76xMF w=; X-IronPort-AV: E=Sophos;i="6.07,141,1708387200"; d="scan'208";a="334143291" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 02:51:39 +0000 Received: from EX19MTAEUC001.ant.amazon.com [10.0.17.79:18408] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.26.123:2525] with esmtp (Farcaster) id 927bfbc6-a8a5-4bb7-a8da-9035a6125689; Thu, 21 Mar 2024 02:51:37 +0000 (UTC) X-Farcaster-Flow-ID: 927bfbc6-a8a5-4bb7-a8da-9035a6125689 Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUC001.ant.amazon.com (10.252.51.155) 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:37 +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:32 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v2 4/4] virt: vmgenid: add support for devicetree bindings Date: Thu, 21 Mar 2024 02:51:05 +0000 Message-ID: <20240321025105.53210-5-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: quoted-printable X-ClientProxiedBy: EX19D043UWA002.ant.amazon.com (10.13.139.53) To EX19D036EUC002.ant.amazon.com (10.252.61.191) Content-Type: text/plain; charset="utf-8" - Extend the vmgenid platform driver to support devicetree bindings. With this support, hypervisors can send vmgenid notifications to the virtual machine without the need to enable ACPI. The bindings are located at: Documentation/devicetree/bindings/rng/vmgenid.yaml - Use proper FLAGS to compile with and without ACPI and/or devicetree. Signed-off-by: Sudan Landge --- drivers/virt/Kconfig | 2 +- drivers/virt/vmgenid.c | 106 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 101 insertions(+), 7 deletions(-) diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 40129b6f0eca..4f33ee2f0372 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -16,7 +16,7 @@ if VIRT_DRIVERS config VMGENID tristate "Virtual Machine Generation ID driver" default y - depends on ACPI + depends on (ACPI || OF) help Say Y here to use the hypervisor-provided Virtual Machine Generation ID to reseed the RNG when the VM is cloned. This is highly recommended if diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index d5394c706bd9..ec378c37a2a2 100644 --- a/drivers/virt/vmgenid.c +++ b/drivers/virt/vmgenid.c @@ -2,7 +2,7 @@ /* * Copyright (C) 2022 Jason A. Donenfeld . All Rights Res= erved. * - * The "Virtual Machine Generation ID" is exposed via ACPI and changes whe= n a + * The "Virtual Machine Generation ID" is exposed via ACPI or DT and chang= es when a * virtual machine forks or is cloned. This driver exists for shepherding = that * information to random.c. */ @@ -13,14 +13,27 @@ #include #include #include - +#ifdef CONFIG_OF +#include +#include +#include +#include +#include +#include +#endif + +#ifdef CONFIG_ACPI ACPI_MODULE_NAME("vmgenid"); +#endif =20 enum { VMGENID_SIZE =3D 16 }; =20 struct vmgenid_state { u8 *next_id; u8 this_id[VMGENID_SIZE]; +#ifdef CONFIG_OF + unsigned int irq; +#endif }; =20 static void vmgenid_notify(struct device *device) @@ -37,10 +50,24 @@ static void vmgenid_notify(struct device *device) kobject_uevent_env(&device->kobj, KOBJ_CHANGE, envp); } =20 +#ifdef CONFIG_ACPI static void vmgenid_acpi_handler(acpi_handle handle, u32 event, void *dev) { + (void)handle; + (void)event; vmgenid_notify(dev); } +#endif + +#ifdef CONFIG_OF +static irqreturn_t vmgenid_of_irq_handler(int irq, void *dev) +{ + (void)irq; + vmgenid_notify(dev); + + return IRQ_HANDLED; +} +#endif =20 static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) { @@ -55,6 +82,7 @@ static int setup_vmgenid_state(struct vmgenid_state *stat= e, u8 *next_id) =20 static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *stat= e) { +#ifdef CONFIG_ACPI struct acpi_device *device =3D ACPI_COMPANION(dev); struct acpi_buffer parsed =3D { ACPI_ALLOCATE_BUFFER }; union acpi_object *obj; @@ -96,6 +124,54 @@ static int vmgenid_add_acpi(struct device *dev, struct = vmgenid_state *state) out: ACPI_FREE(parsed.pointer); return ret; +#else + (void)dev; + (void)state; + return -EINVAL; +#endif +} + +static int vmgenid_add_of(struct device *dev, struct vmgenid_state *state) +{ +#ifdef CONFIG_OF + struct resource res; + int ret =3D 0; + + if (of_address_to_resource(dev->of_node, 0, &res)) { + dev_err(dev, "Failed to get resources from device tree"); + ret =3D -EINVAL; + goto out; + } + + if (!__request_mem_region(res.start, resource_size(&res), + "vmgenid", IORESOURCE_EXCLUSIVE)) { + dev_err(dev, "Failed to request mem region"); + ret =3D -EINVAL; + goto out; + } + + ret =3D setup_vmgenid_state(state, (u8 *)of_iomap(dev->of_node, 0)); + if (ret) + goto out; + + state->irq =3D irq_of_parse_and_map(dev->of_node, 0); + dev->driver_data =3D state; + + if (request_irq(state->irq, vmgenid_of_irq_handler, + IRQF_SHARED, "vmgenid", dev) < 0) { + dev_err(dev, "request_irq failed"); + dev->driver_data =3D NULL; + ret =3D -EINVAL; + goto out; + } + +out: + return ret; +#else + (void)dev; + (void)state; + return -EINVAL; +#endif } =20 static int vmgenid_add(struct platform_device *pdev) @@ -108,7 +184,10 @@ static int vmgenid_add(struct platform_device *pdev) if (!state) return -ENOMEM; =20 - ret =3D vmgenid_add_acpi(dev, state); + if (dev->of_node) + ret =3D vmgenid_add_of(dev, state); + else + ret =3D vmgenid_add_acpi(dev, state); =20 if (ret) devm_kfree(dev, state); @@ -116,18 +195,33 @@ static int vmgenid_add(struct platform_device *pdev) return ret; } =20 -static const struct acpi_device_id vmgenid_ids[] =3D { +#ifdef CONFIG_OF +static const struct of_device_id vmgenid_of_ids[] =3D { + { .compatible =3D "linux,vmgenctr", }, + {}, +}; +MODULE_DEVICE_TABLE(of, vmgenid_of_ids); +#endif + +#ifdef CONFIG_ACPI +static const struct acpi_device_id vmgenid_acpi_ids[] =3D { { "VMGENCTR", 0 }, { "VM_GEN_COUNTER", 0 }, { } }; -MODULE_DEVICE_TABLE(acpi, vmgenid_ids); +MODULE_DEVICE_TABLE(acpi, vmgenid_acpi_ids); +#endif =20 static struct platform_driver vmgenid_plaform_driver =3D { .probe =3D vmgenid_add, .driver =3D { .name =3D "vmgenid", - .acpi_match_table =3D ACPI_PTR(vmgenid_ids), +#ifdef CONFIG_ACPI + .acpi_match_table =3D ACPI_PTR(vmgenid_acpi_ids), +#endif +#ifdef CONFIG_OF + .of_match_table =3D vmgenid_of_ids, +#endif .owner =3D THIS_MODULE, }, }; --=20 2.40.1