Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp533927pxm; Fri, 25 Feb 2022 13:08:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJywC8V796fNX7tGI+tJ8mcXb/sERX4LXW0snaxr50e1/kpncD+U3qbrENgC1uqT4d3whUu9 X-Received: by 2002:a63:4b09:0:b0:372:c793:ab50 with SMTP id y9-20020a634b09000000b00372c793ab50mr7575042pga.495.1645823291475; Fri, 25 Feb 2022 13:08:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645823291; cv=none; d=google.com; s=arc-20160816; b=vMaJxbrvL8Szz+eJwbIjKwuEZGxK9cFNochExCO+C0xGBSvh47fbqnQM+nfyS/u5Di UtZ+SnBo4VA+6uYMiDJvP2dleA5eYDAbxkrrPSYmjN3R1XB1LiIqFUqcUytD2YoYDfgt 4r8V8B1ZFKOuJs86ItjL362g8zN61FaA6sFlQhIg3WOcd3MrTFRybt9kNgy1J7q15j7W yXQghmZvAhxd5Yt/8sv8yL2ts2Rqff4SLnENq4XXshxKkfQ+2WPlHrnAwFaFxi+d8PDs MTGgnClLXPx3EjHV3epl3Re4w8foi4zYK1kwI6p7Njx6IG3+2de10PwJv+ia3ZpfgaHG BzkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QaEuFFdyGR6A7Oz/STZpzo7FI2QY+5sp42nmtINjm4A=; b=JeX0aXV161bdvr9KcHy2V9pxYxbZcctEGb0de7MP0u0yYG1+KJg2XHQEyjLXIWBh6I wiTTJgfhEDE4STFEuuM6iLkYRfaPqyHL7rsk0x4lRkTmWW5GT+GOarZkdSKjfVGyPJvJ d5amR+xVVA1Q2VePcWUjO2ro5l4s1NnbPLdLX6X2ezZYDPMNg9pPYPKNd77wFU7FNYGd zME3K+cuRuUjv6BoyFaeAcnqkW9wDeLQPQuX1czx3bxg+PT9V+VWdGnRDukZvCtld/ru JC+CwfX4hJiqyRTFjvjCrVVtBzKV8HBLbQssbUwc7Ycrp7RDD61aEw3G1EmSd91TS5Hn Rczw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BF55rSVh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a056a00085600b004e13dee8101si3098057pfk.278.2022.02.25.13.07.43; Fri, 25 Feb 2022 13:08:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BF55rSVh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243531AbiBYRO1 (ORCPT + 99 others); Fri, 25 Feb 2022 12:14:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240804AbiBYRO0 (ORCPT ); Fri, 25 Feb 2022 12:14:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 790A51AA48A; Fri, 25 Feb 2022 09:13:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3DF93B832D2; Fri, 25 Feb 2022 17:13:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8885C340F5; Fri, 25 Feb 2022 17:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645809230; bh=PAzgk9fc8UNeS61XwY8qL+LCQ/UWWXGsmNJHOaD8Wqs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BF55rSVh3MUsVAQ0EqnmhHfNI2U7oWOru1e8h8lpAeL5NJ6tNtpiGD72MF+sCSmd2 1ey99dvbhkignhEj/6Uxio6AG+j9bncI+eNP/KUOex4n+TKOJklcXaSrbNMmRhEa2w tpqt9AcYflWIhXJK8KhyYt0n32cW9m0K5q/P66YWnAhLRId8RCk6chcW7I55+bRn7x KyY+UILiydfOsY0T64fU78XytNuDVGvF8OOZ6bHml6V6nTeieg8SWKjNLapaqU4rlT Lz4MzY1eVgp1XOL/GFihSu5UvLcfbkIlh6WI1Xw8vqbwqlVG0rQQYFM9/QOf0LjXli cqCk99aoJHC7w== Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-2d641c31776so40429027b3.12; Fri, 25 Feb 2022 09:13:50 -0800 (PST) X-Gm-Message-State: AOAM533YdlGrpykHomY/nZMwrKk7d4MkhSohVPRYnSfq4uHakjiepwwk BCfZdEhHu1Xp+YYo8BIAATObk8SkK0h4amIfgKk= X-Received: by 2002:a0d:d482:0:b0:2d8:1555:e21d with SMTP id w124-20020a0dd482000000b002d81555e21dmr6750504ywd.272.1645809229658; Fri, 25 Feb 2022 09:13:49 -0800 (PST) MIME-Version: 1.0 References: <20220225155552.30636-1-graf@amazon.com> In-Reply-To: <20220225155552.30636-1-graf@amazon.com> From: Ard Biesheuvel Date: Fri, 25 Feb 2022 18:13:38 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ACPI: bus: Match first 9 bytes of device IDs To: Alexander Graf Cc: ACPI Devel Maling List , Linux Kernel Mailing List , Len Brown , "Rafael J. Wysocki" , "Jason A . Donenfeld" , Greg KH , "Woodhouse, David" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 25 Feb 2022 at 16:56, Alexander Graf wrote: > > We create a list of ACPI "PNP" IDs which contains _HID, _CID and CLS > entries of the respective devices. However, we squeeze them into > struct acpi_device_id which only has 9 bytes space to store the identifier > based on the ACPI spec: > > """ > A _HID object evaluates to either a numeric 32-bit compressed EISA > type ID or a string. If a string, the format must be an alphanumeric > PNP or ACPI ID with no asterisk or other leading characters. > A valid PNP ID must be of the form "AAA####" where A is an uppercase > letter and # is a hex digit. > A valid ACPI ID must be of the form "NNNN####" where N is an uppercase > letter or a digit ('0'-'9') and # is a hex digit. This specification > reserves the string "ACPI" for use only with devices defined herein. > It further reserves all strings representing 4 HEX digits for > exclusive use with PCI-assigned Vendor IDs. > """ > > While most people adhere to the ACPI specs, Microsoft decided that its > VM Generation Counter device [1] should only be identifiable by _CID with > an value of "VM_Gen_Counter" - longer than 9 characters. > > To still allow device drivers to match identifiers that exceed the 9 byte > limit, without wasting memory for the unlikely case that you have long > identifiers, let's match only the first 9 characters of the identifier. > > This patch is a prerequisite to add support for VMGenID in Linux [2]. > > [1] https://download.microsoft.com/download/3/1/C/31CFC307-98CA-4CA5-914C-D9772691E214/VirtualMachineGenerationID.docx > [2] https://lore.kernel.org/lkml/20220225124848.909093-1-Jason@zx2c4.com/ > > Signed-off-by: Alexander Graf > > --- > > Alternatives to the approach above would be: > > 1) Always set id[8] = '\0' in acpi_add_id() > 2) Allocate the id in struct acpi_device_id dynamically > > I'm happy to explore option 1 instead if people believe it's cleaner. > Option 2 on the other hand seems overkill for the issue at hand. We don't > have a lot of devices that exceed the 8 character threshold, so chance of > collision is quite small. On the other hand, the extra overhead of > maintaining the string allocation dynamically will quickly become a > headache. > I don't like this hack. If we are going to accept the fact that CIDs could be arbitrary length strings, we should handle them properly. The device subsystem side of things already deals with this properly: the modalias of the QEMU vmgenid device comes up as 'acpi:QEMUVGID:VM_GEN_COUNTER', which means it already captures the entire string, and exposes it in the correct way (modulo the all caps) So what we need is a way for a module to describe its compatibility with such a _CID, which shouldn't be that complicated. I'll try to cook something up. > --- > drivers/acpi/bus.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c > index 07f604832fd6..aba93171739f 100644 > --- a/drivers/acpi/bus.c > +++ b/drivers/acpi/bus.c > @@ -829,7 +829,7 @@ static bool __acpi_match_device(struct acpi_device *device, > /* First, check the ACPI/PNP IDs provided by the caller. */ > if (acpi_ids) { > for (id = acpi_ids; id->id[0] || id->cls; id++) { > - if (id->id[0] && !strcmp((char *)id->id, hwid->id)) > + if (id->id[0] && !strncmp((char *)id->id, hwid->id, ACPI_ID_LEN)) > goto out_acpi_match; > if (id->cls && __acpi_match_device_cls(id, hwid)) > goto out_acpi_match; > -- > 2.16.4 > > > > > Amazon Development Center Germany GmbH > Krausenstr. 38 > 10117 Berlin > Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss > Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B > Sitz: Berlin > Ust-ID: DE 289 237 879 > > >