From nobody Sun Feb 8 13:09:15 2026 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) (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 C4638405FD; Mon, 25 Mar 2024 19:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711396417; cv=none; b=n0ORiSCUSkbVnwqn8X5kPWMjObVNSkD+RZlh/u3WkFo1M+SBWSQ3slXq3Mkt4sDoV4VhWvh1LdHSBKUBN4hIg0Yvv9+62SIrmOreAkApcJ2c/XIpKcpJPDonxZCz6lo1IBm6aS6FigYhnDPeLNpaRmP5C8xzgCJN76uW5nCJGzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711396417; c=relaxed/simple; bh=V5QfoxDhwAJ0q0BlEtFIGB+N4NV5UoeStGXWV9Li+qA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DXVmjlUw9Bm+lDhx/p7VgEAah3QxVDQjciKpePfAD3ruDMH1NLMN88KDIYz1ISRG1gtZ1AduC8PnveAxAv9BC/h7o45RYcovb+5bkDiydvRhixFRgHMz4PAZ0pmot4/qL2KtS+vasVYFwaiCNqrpKq7fansaZSw7P6fjpoHUv6w= 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=s+4UPc5f; arc=none smtp.client-ip=99.78.197.218 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="s+4UPc5f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1711396416; x=1742932416; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=780CzWQuS3gw5Y/2WbB9iB+XzN5JGzKplO7LP7fR96Q=; b=s+4UPc5fVVmsKB1bBMiBcY4jzSozHjbY5XAuoDidTmE2gu87v18BaHVM 0wl3gmYrrRo7RXpFjXxOmvUEGPRjYj/QWa9UyRlY5pddZGfL0VI4EEYUx /JUc+mJUTW7szVyTTGw8fuHUidSaOIvzc68ZDBZmgxOs0lAv1PqAq+qm3 Q=; X-IronPort-AV: E=Sophos;i="6.07,154,1708387200"; d="scan'208";a="283714625" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:53:31 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.43.254:16692] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.24.234:2525] with esmtp (Farcaster) id 633946d4-ff55-4761-967e-78cd922af786; Mon, 25 Mar 2024 19:53:30 +0000 (UTC) X-Farcaster-Flow-ID: 633946d4-ff55-4761-967e-78cd922af786 Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUA001.ant.amazon.com (10.252.50.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 25 Mar 2024 19:53:30 +0000 Received: from bcd074994f7f.amazon.com (10.106.83.11) 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; Mon, 25 Mar 2024 19:53:25 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v3 1/4] virt: vmgenid: rearrange code to make review easier Date: Mon, 25 Mar 2024 19:53:03 +0000 Message-ID: <20240325195306.13133-2-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240325195306.13133-1-sudanl@amazon.com> References: <20240325195306.13133-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: EX19D039UWB001.ant.amazon.com (10.13.138.119) 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 13:09:15 2026 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) (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 862554085A; Mon, 25 Mar 2024 19:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711396420; cv=none; b=YIdFlypr7iwVCKb99+Ixf1J+p2CdR9T3rG6l+ShMQxW8AB8KRSu4BMQNwucmgzbINcSTgDVotwXCrhZGlPxcCrQRv9i52WGCY6ONMl2CQ4PTpRZYUlcyrh7QuNEH8BNyXViSgi7bzE3M7ds7tSWvQXuPReXuS0R/AEe80SrpPeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711396420; 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=dOAdwv11I0a+AivsGHy9QFPCciZE0pk9tCEQaG3J3VTufyEUFmqiAZlMBlrBzZGZVdORuTXSXrcUe6+QmN+Giud83DjyPi82uJ/gPZEyQHh9oE6tM5r/ULQ0njiF6f36Tfl6lbaYBJISGLYyD0rqef1L1OUFFikeybkhw3S5T2g= 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=inRixaMv; arc=none smtp.client-ip=99.78.197.217 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="inRixaMv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1711396419; x=1742932419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eYEegrjH0qqz5TwkXTvElujjd0LDRDev29SImBbbI6Q=; b=inRixaMvdy1m2w2kdU7JFIjfhqloWfm8MrJp/wBqYqhoi7ijMRFhn37u OGAaXRlA+NzYj8qqO0/BC/jPjIg9ofwUCup21D/wDtF2VJVICrNfDiFOq WKQMofDwNQrSGbYPF0lSs8KPDpJhCN91vxy5oDsr3N4gQrXrhmyUM/ruv 0=; X-IronPort-AV: E=Sophos;i="6.07,154,1708387200"; d="scan'208";a="282762815" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:53:37 +0000 Received: from EX19MTAEUA002.ant.amazon.com [10.0.10.100:29969] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.36.231:2525] with esmtp (Farcaster) id d573997d-a1bd-45e8-9e81-72d826ed55fa; Mon, 25 Mar 2024 19:53:35 +0000 (UTC) X-Farcaster-Flow-ID: d573997d-a1bd-45e8-9e81-72d826ed55fa 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; Mon, 25 Mar 2024 19:53:35 +0000 Received: from bcd074994f7f.amazon.com (10.106.83.11) 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; Mon, 25 Mar 2024 19:53:30 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v3 2/4] virt: vmgenid: change implementation to use a platform driver Date: Mon, 25 Mar 2024 19:53:04 +0000 Message-ID: <20240325195306.13133-3-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240325195306.13133-1-sudanl@amazon.com> References: <20240325195306.13133-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: EX19D039UWB001.ant.amazon.com (10.13.138.119) 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 13:09:15 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 95AB3482EB; Mon, 25 Mar 2024 19:53:44 +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=1711396426; cv=none; b=QEnf742qFvnv+d0RqNeoZkLRC3xWoEW9E5UWZHTsldKnns1zzDbhIBLs6vyY77N3n330eBTyoGPdm+0so2dZK4HbVxGGpcO8vEDHRwFe3qoATVhUCbTlWzRlbwdyrQ3DVe3mES0FVMGZ1X4wQktbZIbc3uYtF0iiwr9d+qzQdvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711396426; c=relaxed/simple; bh=GFGzs9et60G/U08sqKPCyX+gjwPAtjZmArJvI7mOHFQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tP3GhLUKFvQjzTfpU/wQtSDRqnJhQtuxbWeYaJsVGFwbbcfljjyLMgCciI2yLSDsoPYtDIdEhGH7wDoOWZXTvrRBaYQXDoIp1uCzaU6+tg0jNfzHSIjjgocvivZ+IbjD6PbGzsyEVyk/WEgzwncu8wepiB4Z2kd+EcQUMVozKWI= 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=eNMDJr+2; 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="eNMDJr+2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1711396424; x=1742932424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8vSxYYjnh5jLuw/n28r6x07Vkzh/WohwY3OP2PwKVus=; b=eNMDJr+2oREN9fOJhA7BuG6+YaTzHIJVsieinw7gTW5vc707BMNQUiye lT+f8I4CZtuRRsL4CcfgD/2lXc+jnQ40RRTXchGsza1F4sLayR41gIX+q RydzrHghCOoMjVyPi2yUA/9gkWGkcfLQ3cKTIIOKtSboeJeAh9WPZXDKy g=; X-IronPort-AV: E=Sophos;i="6.07,154,1708387200"; d="scan'208";a="390412313" 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; 25 Mar 2024 19:53:43 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.17.79:40238] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.4.153:2525] with esmtp (Farcaster) id ff591b8d-2c64-4631-85f3-35c0594d0314; Mon, 25 Mar 2024 19:53:43 +0000 (UTC) X-Farcaster-Flow-ID: ff591b8d-2c64-4631-85f3-35c0594d0314 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; Mon, 25 Mar 2024 19:53:40 +0000 Received: from bcd074994f7f.amazon.com (10.106.83.11) 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; Mon, 25 Mar 2024 19:53:35 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v3 3/4] dt-bindings: rng: Add vmgenid support Date: Mon, 25 Mar 2024 19:53:05 +0000 Message-ID: <20240325195306.13133-4-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240325195306.13133-1-sudanl@amazon.com> References: <20240325195306.13133-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: EX19D039UWB001.ant.amazon.com (10.13.138.119) 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- machine-generation-identifier Signed-off-by: Sudan Landge --- .../devicetree/bindings/rng/vmgenid.yaml | 58 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 59 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..24643080d6b0 --- /dev/null +++ b/Documentation/devicetree/bindings/rng/vmgenid.yaml @@ -0,0 +1,58 @@ +# 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: virtual,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-map: true + + reg: + description: + The 1st cell specifies the base physical address of the 8-byte align= ed + buffer in guest memory space which is guaranteed not to be used by t= he + operating system. + The 2nd cell specifies the size of the buffer which holds the VMGenI= D. + maxItems: 1 + + interrupts: + description: + interrupt used to notify that a new VMGenID counter is available. + maxItems: 1 + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + rng@80000000 { + compatible =3D "virtual,vmgenctr"; + reg =3D <0x80000000 0x1000>; + interrupts =3D <0x00 0x23 0x01>; + }; + +... diff --git a/MAINTAINERS b/MAINTAINERS index de6a64b248ae..e295d2f50af4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18461,6 +18461,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 13:09:15 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 7573B4AEEF; Mon, 25 Mar 2024 19:53:54 +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=1711396436; cv=none; b=uTkBMmy3ObVMfhtLeC/4+3s1m0cVJYNeXHcdwDVnHC4cGlwb2iWz9Q6UbfKA98HuuqjTgtmdE32orneTdbkDZa2/4qwrPg+dlRSOo8cSfgQdbuYO2OoLNMNpG/c2j4R1JpKzki06Ktek0T16NGVKv5I1YFOfLSSYJieRgJuzpBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711396436; c=relaxed/simple; bh=++m9N0MCieE6cSYPHOMl1yqT3JI/VESso5nM1BQnBe8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S5K0OytHh4/nL7Sckk8CfMiS1HfKVI9+W9sHmQ7mJLBJ5LOj2EPDB4Lvf4KboTG3PoVN+DD1E7MEOu4MKOY2pu+odQFwaZAYI3fNk6evRyQCfoqsm/FmeRqNJ7ZmLrbond4SUl7Ixd/YYU6nri+d7yA5L/uZE1kcZugokIKf5MA= 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=IsrbFAkm; 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="IsrbFAkm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1711396435; x=1742932435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9tccM5MnneqoFu3JC/qRsGHXetyTwu2/OTI1HpvUe7k=; b=IsrbFAkmNZEyvt/oJJQV/qpt68SwRdptgJ9qf52BWnJu3hjAFmn+yYvM yMIlI/9d+VcLc0KA6eS5MX+H7p0RGi3xQ4Nl/UT2mi61VD05uOTTGLZ+D JAp+Oa09VlWEHe7fmsOFKp4dI6NQelBmiag9Cda9PWAHhr/R3so3KAK5H 0=; X-IronPort-AV: E=Sophos;i="6.07,154,1708387200"; d="scan'208";a="335105095" 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-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:53:48 +0000 Received: from EX19MTAEUB002.ant.amazon.com [10.0.10.100:36564] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.33.239:2525] with esmtp (Farcaster) id 76e9f19c-adbd-4c42-aecc-51f4614478ad; Mon, 25 Mar 2024 19:53:46 +0000 (UTC) X-Farcaster-Flow-ID: 76e9f19c-adbd-4c42-aecc-51f4614478ad Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUB002.ant.amazon.com (10.252.51.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 25 Mar 2024 19:53:45 +0000 Received: from bcd074994f7f.amazon.com (10.106.83.11) 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; Mon, 25 Mar 2024 19:53:40 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings Date: Mon, 25 Mar 2024 19:53:06 +0000 Message-ID: <20240325195306.13133-5-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240325195306.13133-1-sudanl@amazon.com> References: <20240325195306.13133-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: EX19D039UWB001.ant.amazon.com (10.13.138.119) 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 | 1 - drivers/virt/vmgenid.c | 85 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 40129b6f0eca..d8c848cf09a6 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -16,7 +16,6 @@ if VIRT_DRIVERS config VMGENID tristate "Virtual Machine Generation ID driver" default y - depends on ACPI 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..a648465bea43 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. */ @@ -21,6 +21,7 @@ enum { VMGENID_SIZE =3D 16 }; struct vmgenid_state { u8 *next_id; u8 this_id[VMGENID_SIZE]; + unsigned int irq; }; =20 static void vmgenid_notify(struct device *device) @@ -37,10 +38,24 @@ static void vmgenid_notify(struct device *device) kobject_uevent_env(&device->kobj, KOBJ_CHANGE, envp); } =20 +#if IS_ENABLED(CONFIG_ACPI) static void vmgenid_acpi_handler(acpi_handle handle, u32 event, void *dev) { + (void)handle; + (void)event; vmgenid_notify(dev); } +#endif + +#if IS_ENABLED(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 +70,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) { +#if IS_ENABLED(CONFIG_ACPI) struct acpi_device *device =3D ACPI_COMPANION(dev); struct acpi_buffer parsed =3D { ACPI_ALLOCATE_BUFFER }; union acpi_object *obj; @@ -96,6 +112,49 @@ 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 platform_device *pdev, struct vmgenid_sta= te *state) +{ +#if IS_ENABLED(CONFIG_OF) + void __iomem *remapped_ptr; + int ret =3D 0; + + remapped_ptr =3D devm_platform_get_and_ioremap_resource(pdev, 0, NULL); + if (IS_ERR(remapped_ptr)) { + ret =3D PTR_ERR(remapped_ptr); + goto out; + } + + ret =3D setup_vmgenid_state(state, remapped_ptr); + if (ret) + goto out; + + state->irq =3D platform_get_irq(pdev, 0); + if (state->irq < 0) { + ret =3D state->irq; + goto out; + } + pdev->dev.driver_data =3D state; + + ret =3D devm_request_irq(&pdev->dev, state->irq, + vmgenid_of_irq_handler, + IRQF_SHARED, "vmgenid", &pdev->dev); + if (ret) + pdev->dev.driver_data =3D NULL; + +out: + return ret; +#else + (void)dev; + (void)state; + return -EINVAL; +#endif } =20 static int vmgenid_add(struct platform_device *pdev) @@ -108,7 +167,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(pdev, state); + else + ret =3D vmgenid_add_acpi(dev, state); =20 if (ret) devm_kfree(dev, state); @@ -116,18 +178,31 @@ static int vmgenid_add(struct platform_device *pdev) return ret; } =20 -static const struct acpi_device_id vmgenid_ids[] =3D { +#if IS_ENABLED(CONFIG_OF) +static const struct of_device_id vmgenid_of_ids[] =3D { + { .compatible =3D "linux,vmgenctr", }, + {}, +}; +MODULE_DEVICE_TABLE(of, vmgenid_of_ids); +#endif + +#if IS_ENABLED(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), + .acpi_match_table =3D ACPI_PTR(vmgenid_acpi_ids), +#if IS_ENABLED(CONFIG_OF) + .of_match_table =3D vmgenid_of_ids, +#endif .owner =3D THIS_MODULE, }, }; --=20 2.40.1