Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp61173lqb; Tue, 16 Apr 2024 08:50:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU35Uut0R5q04FsvsEI/ZGDPxz5+21lrON8EaWOWR48Dnnh3K7FdGkKckBVE8Wpy9KiWpwGFyF9JeMFv/FmlcqHB1x5N2mPlK7JFAsP7A== X-Google-Smtp-Source: AGHT+IFSEXovqkA+jqYfPu4tVojm5/SLAi+ICaRgSFidIO0He4Rr1+nauZO41gnNcq8S80Rur1DK X-Received: by 2002:a17:903:1110:b0:1e6:3494:620f with SMTP id n16-20020a170903111000b001e63494620fmr9060993plh.11.1713282611057; Tue, 16 Apr 2024 08:50:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713282611; cv=pass; d=google.com; s=arc-20160816; b=WMeN5VDXuGMYB4q6MoSYk/MxscgOjvid0sEaVXqGjMPwNe0py4EdvvFESWVijAYe4m voD+v1TDA/mT3mek7CXtTuZB3Rghq5x1rVoZJ2pbVwVG7DshOJ5ZvCQrG2JBPGaGrihg pBlqrPESTEsFGIc5xj5eGzGk8Z7DXTBsWcJaGYwUtYIhz9V8uQZdDEqRsMrAO4akz+P+ VJfs2TEuMvHQsDInr/UwtW3wHKwHLzBL+FKYXbSwKvgYr3/9c/tJ+Fg0/rotHXkiJsKa hezhhYkW75aQgJ70oNWl2c/NXrrHZFXMJvNNDHoIMLwVGzWw/rHY/sZT2Rd0+Rq8QUPt n6cA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=mntj+fXN5a54sfKhFM7PgZmUZBd4LjjmIWz6DPtP244=; fh=61kgz2czu/2SErqI5i9bWavYNVJgMnEpRccynhlGZa4=; b=ub0JSUvYqBT43C4L0w5XpNMlblE9uRuxvdMy4wJBCzwAtLoRJYSAZSlF4QPnd16g6i xhL8NNDMwLS8X3hom/11Nk9nyNyk8graM2eWr0KZgqf8bY2iCirDKmUVr9DYDqnh21x6 WJPq+U2hcvm394/Jb1SsXSZ39CoBndTDN6EuwXQuLuBNmNpO1hHzf5BSwY4VXq7P9phe 4GOZwpNxyijAVjDh1hJQOfFnDkl+k68n+vz8Td2WL0BvpO0oSqH8QgE3Pigj0ZoIEaos r+SJC+tOm3ZMpsdtBEDSA49Vk8f4qzHti7U7hZTTNVIZlr3/mVoH5xeKdIMU9atydYG1 IRMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.es header.s=amazon201209 header.b=cR76Hz4l; 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-kernel+bounces-147152-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.es Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t8-20020a170902e84800b001e45f010f5dsi9811030plg.585.2024.04.16.08.50.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 08:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147152-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.es header.s=amazon201209 header.b=cR76Hz4l; 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-kernel+bounces-147152-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147152-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3DA0A281A9C for ; Tue, 16 Apr 2024 15:50:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83D8C131728; Tue, 16 Apr 2024 15:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.es header.i=@amazon.es header.b="cR76Hz4l" 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 767BC53E15; Tue, 16 Apr 2024 15:49:59 +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=1713282601; cv=none; b=Ri3ZWOS8ZdaMQmpy+uP0XBRlmh0twGVIdB7WXMD7Yv4/TSaKd1wr3WBteznpk75MWfTA4PLgNdLax56iFOnc7r66OosDjZytvMSPrW7ZwjdXbBJI3nhUEg+sskxzUIfMPlNlQEj1NS1RI8/4JGTJ9lwxFuvKlHi2JoZDJ8YA9KU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713282601; c=relaxed/simple; bh=DeIGpI4J2s2bhWdutKdlfr6mBJvVRwiz0KjAewxS9Bs=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=ErIaq/sqTTYsvjYBYL1keLq3Vi2xw2nz8xDXVL1lYXmiMyVxzFB55EozjELXlNJHW4UeTNeX68VvmdZN7ycAOV9JWIgEURW8IFk0ZN3mVqE7o1+PW7JvlZy38deha3bWsRIJyL60kBSWljAeH4MktE0MipN+jP/oLcXglOnoWkE= 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=cR76Hz4l; 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=1713282600; x=1744818600; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=mntj+fXN5a54sfKhFM7PgZmUZBd4LjjmIWz6DPtP244=; b=cR76Hz4lHUXTv4GVGcQCfraJJIYZKfUz8cLSjpuCV1JMKOc2LV1b+8zY zDcENoS6Zg3quZr6BJOMTNK5lbh3h3B4lTG9rDHI9UDJUotiVMAynekWl PLZ1SiUDiec7JREeGm7qq06lzc3SYJLC3V6lQcDeZPCTfB9JhUWj2ZkaZ U=; X-IronPort-AV: E=Sophos;i="6.07,206,1708387200"; d="scan'208";a="652346720" 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; 16 Apr 2024 15:49:58 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.43.254:17357] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.2.180:2525] with esmtp (Farcaster) id c30e20ed-742d-4336-9503-02da0bb74705; Tue, 16 Apr 2024 15:49:56 +0000 (UTC) X-Farcaster-Flow-ID: c30e20ed-742d-4336-9503-02da0bb74705 Received: from EX19D037EUB003.ant.amazon.com (10.252.61.119) 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; Tue, 16 Apr 2024 15:49:56 +0000 Received: from [192.168.224.251] (10.1.212.48) 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; Tue, 16 Apr 2024 15:49:51 +0000 Message-ID: Date: Tue, 16 Apr 2024 17:49:47 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 5/5] virt: vmgenid: add support for devicetree bindings To: Alexander Graf , Sudan Landge , , , , , , , , , , CC: , References: <20240409181154.9962-1-sudanl@amazon.com> <20240409181154.9962-6-sudanl@amazon.com> <1e4fad99-76d4-4c45-a924-b78b597c7cd6@amazon.de> Content-Language: en-US From: Babis Chalios Autocrypt: addr=bchalios@amazon.es; keydata= xsFNBGIonY4BEACl1/Qf/fYoDawcFfvjckR5H2yDxlBvKoFT4m5KYiRUivcf5nwCijrM3Fij d38MBpMb9kvwN7lAXOXPCBZMhaNH3J3NuFpUCIZ+UZtf5JgDGiKd/Obli/c0m+7du8wEysCD Z1ldpDeW3c9aENw/uUChQkTEEh0Cmj83uVYEz+BMJKmeA/1Qz0kzGp/MkW8mZYVY5ts4PcBq UmH8Qm5x9NqspTMqIj/yUyxFgxRcKzBOPCF7KiabuCNGCWJAL3EN4SQIQ4MsLBJOSyk5RazC 5x4Vdt9+oCq+jD6H5S19FBSiXKDZCFitIQ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wFC4sndc86tl1yKpxpDdQ858uZYs33Ur+WmxJJQ5BD6sQ48OD 5hEseFrcbikSKk/eVD1FrT3lzbaVqqvQ71soCYYuo2VKxmShuQxUeeFp8hnDw3TR5SO1KJft CT6sQ4dS3vUDeKzVu8E2ofGyOQZ9j6KlFz9daBiRHowFON1vZKS/k8A7ZCZ5Co3Skx538GW8 jDNZJgnSbaam8FVDT1z2H6irmEHz1/vb3hZns0bAmqgwWONTW/gO5jcPbzbTqPfIlmCEtBDf qGaQH7uIyC5kPMTQCNvEMKKn/R2hV3al2/gLvRYFI1GGFE/QdLXiYXmtkDBaz/niHxUUGqO4 LbSF+KYpZYewC8Wx5gTr4Glj+9+RcDWzdkGBd+Kthh0VIOdalbjbnv2jmt5gvLoeLDNpIZRQ AQ+HulTHw5frK1j8+AHIKQYXIE8xXzVkssNuX0Hc7ecC5jm/XlGr5IuQkJpFyVtiXfjkd6tq 9CfKbXmQEUz/yWPkXerBltQSv7ePqJHPFMwJrFAqFftGK6t9nvzGjQB91RM= In-Reply-To: <1e4fad99-76d4-4c45-a924-b78b597c7cd6@amazon.de> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: EX19D043UWA001.ant.amazon.com (10.13.139.45) To EX19D037EUB003.ant.amazon.com (10.252.61.119) On 16/4/24 12:49, Alexander Graf wrote: > > On 09.04.24 20:11, Sudan Landge wrote: >> 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 >> >> Signed-off-by: Sudan Landge >> --- >>   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..e1ad74116c0c 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 __maybe_unused irqreturn_t > > > Why is this maybe_unused? It seems to be always referenced by > vmgenid_add_of(), no? You are right, Alex. I removed the attribute and build the kernel without `CONFIG_OF` without any warnings. I will remove it in the next version. > > >> +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; > > > Doesn't this error path need to do something about the ioremap'ed > resource? Or does devm do that automatically for you? devm should be doing this automatically according to this: https://docs.kernel.org/driver-api/driver-model/devres.html#devres Also, I took a quick look in other drivers and it looks like the virtio-mmio probe callback follows the same pattern: https://elixir.bootlin.com/linux/latest/source/drivers/virtio/virtio_mmio.c#L636 Cheers, Babis > > Alex > > >> + >> +    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, >>       }, >>   };