From nobody Sat Feb 7 17:48:50 2026 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) (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 A482453385; Tue, 19 Mar 2024 14:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.184.29 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858802; cv=none; b=fJJJtdfTtySxfZ7QH59y+cgBBcDXCdJG9ZglxoA1hyAurpzXeQODslbIzUNIUca9FgfyM7+KXMRnnMULW3gRfgg32QpnInZ9TQ7zajuMSfhh4tpZFOWkhoJR8AA/PVwoPCC6FUN6W8AOsBoy3a9BK0mRJ2Aty+7cNmFWiCYpIAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858802; c=relaxed/simple; bh=V5QfoxDhwAJ0q0BlEtFIGB+N4NV5UoeStGXWV9Li+qA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lMvEuHWUlpJgYjU8CphrevEIq+22X4iU+QEVxgIGAG0cO+wC1XKmrnOJrlOPo28K8+ZIOXf7jZiYL0r2DxO4rOzwFESL9loHPPowGV/zYx1nHun7Op3nGlBm+BvU54hhiGhBkAapjDfFMiJZy2gmy6q2C0g33gQIzbFKAkCrWwQ= 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=NhsvhxX1; arc=none smtp.client-ip=207.171.184.29 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="NhsvhxX1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710858800; x=1742394800; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=780CzWQuS3gw5Y/2WbB9iB+XzN5JGzKplO7LP7fR96Q=; b=NhsvhxX1ghq2Y+CdQFx9rtGOCmftUd7VDYjAn1sxsycg0lkgST5F1aEz 5G3YgnbuxRlHjOX2YGTTOgx3I52iyfLvjgnW0Vhd7KZAzu8GizfohNLxx 1nFFBafAiCvBaeNIiFZaUKD/srTOD/qH22N7Pe+LVHw3cTp0vwsMgPWvS E=; X-IronPort-AV: E=Sophos;i="6.07,137,1708387200"; d="scan'208";a="405001162" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2024 14:33:15 +0000 Received: from EX19MTAEUB002.ant.amazon.com [10.0.17.79:12055] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.5.106:2525] with esmtp (Farcaster) id daf94e99-709a-44a0-8ce6-892fd80da2ee; Tue, 19 Mar 2024 14:33:13 +0000 (UTC) X-Farcaster-Flow-ID: daf94e99-709a-44a0-8ce6-892fd80da2ee 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; Tue, 19 Mar 2024 14:33:13 +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; Tue, 19 Mar 2024 14:33:08 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v1 1/4] virt: vmgenid: rearrange code to make review easier Date: Tue, 19 Mar 2024 14:32:50 +0000 Message-ID: <20240319143253.22317-2-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240319143253.22317-1-sudanl@amazon.com> References: <20240319143253.22317-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: EX19D046UWA004.ant.amazon.com (10.13.139.76) 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 Sat Feb 7 17:48:50 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 1876C46BF; Tue, 19 Mar 2024 14:33:21 +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=1710858804; cv=none; b=M95tsLSzQJhmDxQsaPpFVgRZxyEj/2tQkIOB80RrRPYw+hQeH3DOilL7WUFdVc+85GvoFIpUNusePuAqE8u85E3Ko326IPn9lxvu01tZzAa2oTMyQTVBfJ6Vwlun89+pjWze8W+CQXjtgy7xj7La0hLODz1JtXQ9+4WVQqnGNiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858804; c=relaxed/simple; bh=m2GJUmJaHzkYsItjh54bfA5LBnAhX4P2f5TonsIozxM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MsRKREy1zZY7PxeyR0Ucce0AZuWBOdqcmNXUj57k2BtLAyAK3jpW5jQAdU8pL2SHzhY2Dkw9OCSJDSlA1j/kDYOQA2O/Z6In52GdkBOQVlNKrj/s+UBxLZ9z7Zba66J9OK6MsOayt6ZsQAyI8vPpb8+dQ4qVqd4TVQ9d4aRtZYo= 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=oTl0tlJT; 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="oTl0tlJT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710858802; x=1742394802; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fu+KVRO7pbwl42g5Q5J3eMOQhD0GGMxcCy1IWDkBFVY=; b=oTl0tlJTb3J/n6v4XImU4/8GSWF1J3lHm2Bssny5KBshT9Df/DBfoZNl 8lZqEMLwUykpLWBUAe6g6zcujOKbJv1okBWY15XGWNb00D1CiYgcNBcTx iwfmwNi5w22TGz5SPoVnSGcjT6gmyaXp2EHhDEZOylWDW+NywrGaUHB7s Q=; X-IronPort-AV: E=Sophos;i="6.07,137,1708387200"; d="scan'208";a="394339018" 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; 19 Mar 2024 14:33:19 +0000 Received: from EX19MTAEUC001.ant.amazon.com [10.0.43.254:14711] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.34.80:2525] with esmtp (Farcaster) id 27cdb139-13d1-4e5a-81b2-cb2ce885ec0c; Tue, 19 Mar 2024 14:33:19 +0000 (UTC) X-Farcaster-Flow-ID: 27cdb139-13d1-4e5a-81b2-cb2ce885ec0c Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUC001.ant.amazon.com (10.252.51.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Tue, 19 Mar 2024 14:33:18 +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; Tue, 19 Mar 2024 14:33:13 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v1 2/4] virt: vmgenid: change implementation to use a platform driver Date: Tue, 19 Mar 2024 14:32:51 +0000 Message-ID: <20240319143253.22317-3-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240319143253.22317-1-sudanl@amazon.com> References: <20240319143253.22317-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: EX19D046UWA004.ant.amazon.com (10.13.139.76) 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 | 99 +++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 26 deletions(-) diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index ea956df02874..e82b344a9d61 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, + 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 @@ -85,17 +122,27 @@ static const struct acpi_device_id vmgenid_ids[] =3D { { } }; =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"); --=20 2.40.1 From nobody Sat Feb 7 17:48:50 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 D72541F608; Tue, 19 Mar 2024 14:33:24 +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=1710858806; cv=none; b=uMzfOJCo+4s+3VW5A9ea4RLooOq4Wk/ijQc9imJhEyZk0jKQhJcUV8CCxZE51UhUxjC55ovB3KaJQ7qoVF4SpFSdEyEUkHxPAN6xVRNNyE5XLwZVzhN7FAmozULYBDoCK+V/IcXAZIe8ikaVTy5+0w8uvrc9X3a447UkilahKL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858806; c=relaxed/simple; bh=Nl4bkJNbQyhAtavoaz14N2Rq3aUzmmBrorGsRwloGmo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rDeqfL2NiU8qTVA20twBqimgJKnx9THosJDEiV4ItOfTYiWHtNjckdHbfQa1xSsLPPfQ+jFA9iXyXitjHmYWXVzt5fNq4TPycGd7fk0qCGSt6delHIxMgecW0yFVeQY9fjUMzX1dJw+Q/UxNbyDlVNOTXP+MXP4IvxTEnqVMx0M= 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=S7/1h4rU; 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="S7/1h4rU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710858805; x=1742394805; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rwn0ekYo1tnoNE3SYSolZc3xYMZlKQKYCAUM+58pS+E=; b=S7/1h4rUFKwy0DuhyEh4EOCN1q+2TWArHtKtBj8gUkCyKNhmJfbv0g4e i+dR8uz+3hokxhjsK0YYgI5QvJKq65guB79EtAMDe+VnIC2Fbx5SQ8csj XAcckVNmU2Dya3HUo8ljcE2RJscMR/QQF4gEw6miHDxAYc/j31lmqQYGW 8=; X-IronPort-AV: E=Sophos;i="6.07,137,1708387200"; d="scan'208";a="394339031" 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; 19 Mar 2024 14:33:24 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.17.79:35707] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.20.163:2525] with esmtp (Farcaster) id 1209ae3c-a02c-438f-8b73-91d9dc067d39; Tue, 19 Mar 2024 14:33:23 +0000 (UTC) X-Farcaster-Flow-ID: 1209ae3c-a02c-438f-8b73-91d9dc067d39 Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUA001.ant.amazon.com (10.252.50.223) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Tue, 19 Mar 2024 14:33:23 +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; Tue, 19 Mar 2024 14:33:18 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v1 3/4] dt-bindings: Add bindings for vmgenid Date: Tue, 19 Mar 2024 14:32:52 +0000 Message-ID: <20240319143253.22317-4-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240319143253.22317-1-sudanl@amazon.com> References: <20240319143253.22317-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: EX19D046UWA004.ant.amazon.com (10.13.139.76) 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. Add a devicetree binding support for vmgenid so that hypervisors can support vmgenid without the need to support ACPI. Signed-off-by: Sudan Landge --- .../devicetree/bindings/vmgenid/vmgenid.yaml | 57 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/vmgenid/vmgenid.yaml diff --git a/Documentation/devicetree/bindings/vmgenid/vmgenid.yaml b/Docum= entation/devicetree/bindings/vmgenid/vmgenid.yaml new file mode 100644 index 000000000000..17773aa96f8b --- /dev/null +++ b/Documentation/devicetree/bindings/vmgenid/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/vmgenid/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: + - | + vmgenid@80000000 { + compatible =3D "linux,vmgenctr"; + reg =3D <0x80000000 0x1000>; + interrupts =3D <0x00 0x23 0x01>; + }; + +... diff --git a/MAINTAINERS b/MAINTAINERS index d818866d6d73..e602a51b9bd7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18359,6 +18359,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/vmgenid/vmgenid.yaml F: drivers/char/random.c F: drivers/virt/vmgenid.c =20 --=20 2.40.1 From nobody Sat Feb 7 17:48:50 2026 Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) (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 5CCCF26AE4; Tue, 19 Mar 2024 14:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858814; cv=none; b=GZmnIjQn9dSs6I/JaoXcvbOOb9c06kvHL2/kKKJU/0AW3txUeU2WKGjTPURz9JEkzn0jeid0GE6cRZYh7mZCpfQ4RymXuLNzvhib407recQJUEb8+hLsViA5bPATvjiL9SRVSINDeMLPMam9PxJszJTPpBG2bP8Alg68Nw2eB7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858814; c=relaxed/simple; bh=N7UI4zhlk6TZ7w4PYAIRYUE3isb2Sqb8ySQ7KSf3r74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KOnC9lPykxfFPwU68v9BmcL8xJWosvDH815miY6KHOTt1/rgVP7mINHsguCZfmZm1RqmI+XeHoL4G3oPu8Hm5EkfwgTH50snR4Oo6y51Sdg5hshhwoevBOYDRwWGwCJJHntrx7mBGATrrJZTmPPxT8ygQxZRfXp1ujBw2kJXCso= 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=ch96fTbI; arc=none smtp.client-ip=52.119.213.152 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="ch96fTbI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1710858812; x=1742394812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3PKGxBWhjhu5SQFumdItpK7yL651FBVQmfMVf/J3HOQ=; b=ch96fTbIo+IsF9cO//VJB/KqZRUZQTmDQUjspu4EHZKLfUtI3gpa/hW2 DtgmqHOX7y4qiMzqcaxlyJJuKoPXGzNHZn6NsgmVEt4SpzXKCf3BS+g8q e2ucNlhL5a2HCJJaoJCPbT7OzgKgkhaCBwNmhag/WaWJ/VY2xhSGbkYKc U=; X-IronPort-AV: E=Sophos;i="6.07,137,1708387200"; d="scan'208";a="645831400" 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-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2024 14:33:30 +0000 Received: from EX19MTAEUA002.ant.amazon.com [10.0.17.79:61740] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.27.165:2525] with esmtp (Farcaster) id bcba8cb4-9acf-49d4-8b36-e70ba6ccbf47; Tue, 19 Mar 2024 14:33:29 +0000 (UTC) X-Farcaster-Flow-ID: bcba8cb4-9acf-49d4-8b36-e70ba6ccbf47 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; Tue, 19 Mar 2024 14:33:28 +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; Tue, 19 Mar 2024 14:33:23 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v1 4/4] virt: vmgenid: add support for devicetree bindings Date: Tue, 19 Mar 2024 14:32:53 +0000 Message-ID: <20240319143253.22317-5-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240319143253.22317-1-sudanl@amazon.com> References: <20240319143253.22317-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: EX19D046UWA004.ant.amazon.com (10.13.139.76) 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/vmgenid/vmgenid.yaml Signed-off-by: Sudan Landge --- drivers/virt/Kconfig | 2 +- drivers/virt/vmgenid.c | 90 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 6 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 e82b344a9d61..96a3ff8ec05a 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. */ @@ -12,6 +12,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include =20 ACPI_MODULE_NAME("vmgenid"); @@ -21,6 +27,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) @@ -42,6 +49,13 @@ static void vmgenid_acpi_handler(acpi_handle handle, u32= event, void *dev) vmgenid_notify(dev); } =20 +static irqreturn_t vmgenid_of_irq_handler(int irq, void *dev) +{ + vmgenid_notify(dev); + + return IRQ_HANDLED; +} + static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) { if (IS_ERR(next_id)) @@ -98,6 +112,43 @@ static int vmgenid_add_acpi(struct device *dev, struct = vmgenid_state *state) return ret; } =20 +static int vmgenid_add_of(struct device *dev, struct vmgenid_state *state) +{ + 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, 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; +} + static int vmgenid_add(struct platform_device *pdev) { struct vmgenid_state *state; @@ -108,7 +159,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,7 +170,30 @@ static int vmgenid_add(struct platform_device *pdev) return ret; } =20 -static const struct acpi_device_id vmgenid_ids[] =3D { +static int vmgenid_remove(struct platform_device *pdev) +{ + struct vmgenid_state *state =3D NULL; + + if (!pdev) + return -EINVAL; + + state =3D pdev->dev.driver_data; + + if (state && pdev->dev.of_node) + free_irq(state->irq, &pdev->dev); + + if (state) + devm_kfree(&pdev->dev, state); + + return 0; +} + +static const struct of_device_id vmgenid_of_ids[] =3D { + { .compatible =3D "linux,vmgenctr", }, + {}, +}; + +static const struct acpi_device_id vmgenid_acpi_ids[] =3D { { "VMGENCTR", 0 }, { "VM_GEN_COUNTER", 0 }, { } @@ -124,9 +201,11 @@ static const struct acpi_device_id vmgenid_ids[] =3D { =20 static struct platform_driver vmgenid_plaform_driver =3D { .probe =3D vmgenid_add, + .remove =3D vmgenid_remove, .driver =3D { .name =3D "vmgenid", - .acpi_match_table =3D ACPI_PTR(vmgenid_ids), + .acpi_match_table =3D ACPI_PTR(vmgenid_acpi_ids), + .of_match_table =3D vmgenid_of_ids, .owner =3D THIS_MODULE, }, }; @@ -144,7 +223,8 @@ static void vmgenid_platform_device_exit(void) module_init(vmgenid_platform_device_init) module_exit(vmgenid_platform_device_exit) =20 -MODULE_DEVICE_TABLE(acpi, vmgenid_ids); +MODULE_DEVICE_TABLE(acpi, vmgenid_acpi_ids); +MODULE_DEVICE_TABLE(of, vmgenid_of_ids); MODULE_DESCRIPTION("Virtual Machine Generation ID"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Jason A. Donenfeld "); --=20 2.40.1