Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp524777lqb; Wed, 17 Apr 2024 03:43:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV08wdMT35Omvtk2GyfoAZ2CIf5NRiNcIaGzLVtudFVOAs27/32gp8BNh9EVybipJy1SF4OyA6yVDoBByXt7EdU7j8NuompvudhwZQZPg== X-Google-Smtp-Source: AGHT+IGNNtMvy+1EGzjgOFjLI4PVZnPWtXn64JoBP/68KX78xIbmCvke+4Yrr7FECAbQJas+set1 X-Received: by 2002:a50:9544:0:b0:566:777:af4f with SMTP id v4-20020a509544000000b005660777af4fmr10389249eda.1.1713350623098; Wed, 17 Apr 2024 03:43:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713350623; cv=pass; d=google.com; s=arc-20160816; b=VcC/8IdijRCPGqy2Ov4Zbl3sN1nhmN3IIaUFF98815eZSTnhn37fqJ5LJP+9U9AK// oQWi63ZZrGwVDfLBYqDtdwKgkBj+LrY1dtaC2O/uCL0oMovDRaS8lnf5Stvoj0hLn3Lk KpRVrCEIv/jHLyxDyeeR9/sVLGjoJkNS+y75ggo81WCbQ8Bb1snBAIWMHOb5LmNM1OmT NeF09UG4ExD3OlHGrmn6Dh5/jfEAmtghnxK78TZnaxqZ19/D1Dr85oxf+E5IDuV5YurU ZBMbEP+8LVUSP2sH4ma1lC4EvN4jmo/iidUgyxMCMQs69mdRSvOk2t4h5G3QDQQYZ/E+ JnPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=pB206NtwaUbEhMjjil9wyDcA6enkKxcWAv9suS66OrY=; fh=LvRt7euW51oWzM/Pdr0UyIiqHfWW9rv6r59sFMuNoYU=; b=rbg+Gs+6RMMXSVRCVfuJkbC4yj605L7rQgyWDhajQ0D58v4LUxe5W4o9KPqt9zU9Ix /Fj5ji2ctOBEKZz1sKZMHlHtRBih2/9PJGpyjsVrEbMowH1h87Tzb6bmQMUASNNF3b9W ec0fZJ+OQIL+Uqvmwcn09ilY40L0a0MPYZWsQvaMMns2U6licwPWaLTFdqwbKqsHdVDH DzcTbyx+DhKq3W3OT1H6ta46lIAgEmZw0WYghLF9PGx4IjRgGBVl74Rq5+Q0yfoTJk0G o3oQLU4X9VOhiTe2uzPasfhgn3dYZyTzRbHl7lsMT5KFwXWeFnITubdXE7JK550/7WYt U/Lg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.es header.s=amazon201209 header.b=MgxsYVQJ; arc=pass (i=1 spf=pass spfdomain=amazon.es dkim=pass dkdomain=amazon.es dmarc=pass fromdomain=amazon.es); spf=pass (google.com: domain of linux-crypto+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.es Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y19-20020a056402271300b0056bed02304csi6685791edd.348.2024.04.17.03.43.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:43:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.es header.s=amazon201209 header.b=MgxsYVQJ; arc=pass (i=1 spf=pass spfdomain=amazon.es dkim=pass dkdomain=amazon.es dmarc=pass fromdomain=amazon.es); spf=pass (google.com: domain of linux-crypto+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.es Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A66B31F21F07 for ; Wed, 17 Apr 2024 10:43:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34DD713C67C; Wed, 17 Apr 2024 10:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.es header.i=@amazon.es header.b="MgxsYVQJ" X-Original-To: linux-crypto@vger.kernel.org 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 397FA128807; Wed, 17 Apr 2024 10:43:34 +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=1713350617; cv=none; b=Hw0YZTtlFhRQneh7F5hIVqeGbWes0/8NdcShNx65oUEM/51ytKuJ3iTtMhnMgXSBO95fv7PFm2zPEpzMCcdMi+Y1jpxntZRKeN8y5L8X/fh0YqxrD5vKdO1NB7Rf3V4qR/ro7mhxTapEp+6/G9JegchizeKzDMlvxYd+BuNbpcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713350617; c=relaxed/simple; bh=mJml5qWfZ8nlSFywTk/ONcwzQZz8heZFKS7gzIVI5lc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tCWZIc8Xm0TxEdsyMAIgAyxsVGezr3JhB2GAUO1kzWup4xt/VlNkhdMEo6vi6fCBQRYvL7gQX0d+NtE6IP8vvEAnJDLqtUUFnqDOLVggGc91ekJwyJH2Aq0wALouJJ/FqsF5OtP/DCTJNwWOgKi5dTgtjdRVj+YB0Ph0ziVWlgw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.es; spf=pass smtp.mailfrom=amazon.es; dkim=pass (1024-bit key) header.d=amazon.es header.i=@amazon.es header.b=MgxsYVQJ; arc=none smtp.client-ip=52.119.213.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.es Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.es DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.es; i=@amazon.es; q=dns/txt; s=amazon201209; t=1713350616; x=1744886616; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pB206NtwaUbEhMjjil9wyDcA6enkKxcWAv9suS66OrY=; b=MgxsYVQJQ/J/ePGhIM3bOs6VCPFgrYCtsk/vDjGmUbq19fWFtEfNrGaY z8nB34vLkj0L9f0vTyuj/NBu7R7b7OkpS+O4l8Bl0kHiy1JZZI98mlk3G iLTnCk3/gpttygJm6QIXhapUZXimp8sSfszMIGy44g0VP1JUwp1M09msE o=; X-IronPort-AV: E=Sophos;i="6.07,209,1708387200"; d="scan'208";a="652567382" 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-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 10:43:32 +0000 Received: from EX19MTAEUC001.ant.amazon.com [10.0.43.254:48862] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.40.183:2525] with esmtp (Farcaster) id 9ad80e1d-3dc3-45c1-bbdc-8f35e4f070b7; Wed, 17 Apr 2024 10:43:30 +0000 (UTC) X-Farcaster-Flow-ID: 9ad80e1d-3dc3-45c1-bbdc-8f35e4f070b7 Received: from EX19D037EUB003.ant.amazon.com (10.252.61.119) 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; Wed, 17 Apr 2024 10:43:30 +0000 Received: from f4d4887fdcfb.ant.amazon.com (10.106.83.20) by EX19D037EUB003.ant.amazon.com (10.252.61.119) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Wed, 17 Apr 2024 10:43:25 +0000 From: Babis Chalios To: , , , , , , , , , CC: , , , , , Alexander Graf Subject: [PATCH v6 5/5] virt: vmgenid: add support for devicetree bindings Date: Wed, 17 Apr 2024 12:40:46 +0200 Message-ID: <20240417104046.27253-6-bchalios@amazon.es> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240417104046.27253-1-bchalios@amazon.es> References: <20240417104046.27253-1-bchalios@amazon.es> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D041UWA003.ant.amazon.com (10.13.139.105) To EX19D037EUB003.ant.amazon.com (10.252.61.119) 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/microsoft,vmgenid.yaml Co-authored-by: Sudan Landge Signed-off-by: Babis Chalios Reviewed-by: Alexander Graf --- drivers/virt/vmgenid.c | 53 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index 3d93e3fb94c4..9a3c12e5dd6e 100644 --- a/drivers/virt/vmgenid.c +++ b/drivers/virt/vmgenid.c @@ -2,12 +2,13 @@ /* * Copyright (C) 2022 Jason A. Donenfeld . All Rights Reserved. * - * The "Virtual Machine Generation ID" is exposed via ACPI and changes when a + * The "Virtual Machine Generation ID" is exposed via ACPI or DT and changes when a * virtual machine forks or is cloned. This driver exists for shepherding that * information to random.c. */ #include +#include #include #include #include @@ -20,6 +21,7 @@ enum { VMGENID_SIZE = 16 }; struct vmgenid_state { u8 *next_id; u8 this_id[VMGENID_SIZE]; + int irq; }; static void vmgenid_notify(struct device *device) @@ -43,6 +45,14 @@ vmgenid_acpi_handler(acpi_handle __always_unused handle, vmgenid_notify(dev); } +static irqreturn_t +vmgenid_of_irq_handler(int __always_unused irq, void *dev) +{ + vmgenid_notify(dev); + + return IRQ_HANDLED; +} + static int __maybe_unused setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) { @@ -106,6 +116,35 @@ static int vmgenid_add_acpi(struct device __maybe_unused *dev, #endif } +static int vmgenid_add_of(struct platform_device *pdev, + struct vmgenid_state *state) +{ + u8 *virt_addr; + int ret = 0; + + virt_addr = (u8 *)devm_platform_get_and_ioremap_resource(pdev, 0, NULL); + if (IS_ERR(virt_addr)) + return PTR_ERR(virt_addr); + + ret = setup_vmgenid_state(state, virt_addr); + if (ret) + return ret; + + ret = platform_get_irq(pdev, 0); + if (ret < 0) + return ret; + + state->irq = ret; + pdev->dev.driver_data = state; + + ret = devm_request_irq(&pdev->dev, state->irq, vmgenid_of_irq_handler, + IRQF_SHARED, "vmgenid", &pdev->dev); + if (ret) + pdev->dev.driver_data = NULL; + + return ret; +} + static int vmgenid_add(struct platform_device *pdev) { struct vmgenid_state *state; @@ -116,7 +155,10 @@ static int vmgenid_add(struct platform_device *pdev) if (!state) return -ENOMEM; - ret = vmgenid_add_acpi(dev, state); + if (dev->of_node) + ret = vmgenid_add_of(pdev, state); + else + ret = vmgenid_add_acpi(dev, state); if (ret) devm_kfree(dev, state); @@ -124,6 +166,12 @@ static int vmgenid_add(struct platform_device *pdev) return ret; } +static const struct of_device_id vmgenid_of_ids[] = { + { .compatible = "microsoft,vmgenid", }, + { }, +}; +MODULE_DEVICE_TABLE(of, vmgenid_of_ids); + static const struct acpi_device_id vmgenid_acpi_ids[] = { { "VMGENCTR", 0 }, { "VM_GEN_COUNTER", 0 }, @@ -136,6 +184,7 @@ static struct platform_driver vmgenid_plaform_driver = { .driver = { .name = "vmgenid", .acpi_match_table = vmgenid_acpi_ids, + .of_match_table = vmgenid_of_ids, }, }; -- 2.40.1