From nobody Thu Sep 19 17:10:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1723124593; cv=none; d=zohomail.com; s=zohoarc; b=Uxm4TgP6u6hnDm3UllL8EZxPAyzSnREKoygFAbyQGm1V5YWQ08I2HfW1fEQS0eA0Bx2cdtX+DqWKTj39rU3lpzNQrzk4lJDEbw8jEeYvN7LqawFUXFhvK+7DmFYUDRd+jZ2vnW+RK4q++7QgXVOka0wIL1a9LQdjMa4Tc98xg+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723124593; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3uKc4D/FCmujJpSYe6Bi/Q/cwgGcN1SIl98HqfdDNIU=; b=XFlyNyLsT+16GgDg4TvIWlYXGpxYTPSNoFuQTBtC20MPHEB9rBzkTu2PLKIXXKfPfLsJzAcG58spdyhOiuiCVkkmODYQJYutFnb/Iy+vqyYc1vau6gKrOQLCXmdhtwimRp8HOJFKnXW9Kkd/J+cJSGQp0CEOJ+uT9xj+CPdNcsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 172312459326037.929047388913546; Thu, 8 Aug 2024 06:43:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.774172.1184665 (Exim 4.92) (envelope-from ) id 1sc3Pv-0004Dw-Ll; Thu, 08 Aug 2024 13:42:59 +0000 Received: by outflank-mailman (output) from mailman id 774172.1184665; Thu, 08 Aug 2024 13:42:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sc3Pv-0004Do-J5; Thu, 08 Aug 2024 13:42:59 +0000 Received: by outflank-mailman (input) for mailman id 774172; Thu, 08 Aug 2024 13:42:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sc3Pu-0002jZ-K9 for xen-devel@lists.xenproject.org; Thu, 08 Aug 2024 13:42:58 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1f3ff6fa-558c-11ef-bc04-fd08da9f4363; Thu, 08 Aug 2024 15:42:58 +0200 (CEST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a7d89bb07e7so127096966b.3 for ; Thu, 08 Aug 2024 06:42:58 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9ecb551sm741537166b.223.2024.08.08.06.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 06:42:56 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1f3ff6fa-558c-11ef-bc04-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1723124577; x=1723729377; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3uKc4D/FCmujJpSYe6Bi/Q/cwgGcN1SIl98HqfdDNIU=; b=j3VjLwcFLMsopbU9tHf4Byue+gDPit1w+gvBhAAlNj0trC6LKwzUHae7Fz6Yx6ZT0q LnWA2b9L9jPYL5PYupLrHMmDciiiqsKeJ1mhyNRXc1Udw4d/J46QttkMI+XeNZxRY3oF stzFgApwCPlMhXG7LLLE8vRWYIphDvaVn5PeY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723124577; x=1723729377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3uKc4D/FCmujJpSYe6Bi/Q/cwgGcN1SIl98HqfdDNIU=; b=SqLUNZt0Ffx1OSb8EatbzuT5E1FOZ/GqQZanSMPVUiYbS3RSru7LDTDjXrxF6wFsUB Q1d3s3vwXXlWVg9a2LWx6YYAhi3b/5Uq4CsIV/R4JlhSp0GpvUm6ks2umqOczlQ0SCqU +7RkZA3R0Ig4YynH5kHY8Z6ND3NZ4kro4FOwjcPwNwPhJeqAmF9lKTxdB6qVoCyrgtwd Szl2wJOECpiVq6I1sDHchKkrci9aY+awt0bAvVvVOKO9V70hHRCOmsHeILH3EVJs2Qfd drXjGap++YipEm4nJHz2JXx+Jw3KRbhgpDizIimOW0ygCd6jhF+MH3NAF0ypp5hPYn94 tbAA== X-Gm-Message-State: AOJu0YwNVmpAd61PvAiKnDVqDZZkeMFNhtr04MDbwEuwOD2CAzA3YQl6 8sHkEbGR8GGZwbXumz2PQt3kk/5Rwbta3D3r9cjLrqUVsUpHBOdEeTz7OWdV158vViWy1SyR1I7 B X-Google-Smtp-Source: AGHT+IFfFhFaLf1ArmgnvJU2ePQ6v9ViJlwrPDJl5nizABtj7PAsREdAazV3vZO4vx70PKKP/ds9IQ== X-Received: by 2002:a17:907:d2da:b0:a72:8762:1f5d with SMTP id a640c23a62f3a-a8090e9e1ecmr147267966b.55.1723124577270; Thu, 08 Aug 2024 06:42:57 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Anthony PERARD Subject: [PATCH v5 01/10] tools/hvmloader: Fix non-deterministic cpuid() Date: Thu, 8 Aug 2024 14:42:41 +0100 Message-ID: <20240808134251.29995-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240808134251.29995-1-alejandro.vallejo@cloud.com> References: <20240808134251.29995-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1723124593937116600 Content-Type: text/plain; charset="utf-8" hvmloader's cpuid() implementation deviates from Xen's in that the value passed on ecx is unspecified. This means that when used on leaves that implement subleaves it's unspecified which one you get; though it's more than likely an invalid one. Import Xen's implementation so there are no surprises. Fixes: 318ac791f9f9 ("Add utilities needed for SMBIOS generation to hvmloader") Signed-off-by: Alejandro Vallejo Reviewed-by: Jan Beulich --- v5: * Added Fixes tag * Cosmetic changes to static inline, as proposed by Andrew --- tools/firmware/hvmloader/util.c | 9 --------- tools/firmware/hvmloader/util.h | 27 ++++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/uti= l.c index c34f077b38e3..d3b3f9038e64 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -267,15 +267,6 @@ memcmp(const void *s1, const void *s2, unsigned n) return 0; } =20 -void -cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t = *edx) -{ - asm volatile ( - "cpuid" - : "=3Da" (*eax), "=3Db" (*ebx), "=3Dc" (*ecx), "=3Dd" (*edx) - : "0" (idx) ); -} - static const char hex_digits[] =3D "0123456789abcdef"; =20 /* Write a two-character hex representation of 'byte' to digits[]. diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/uti= l.h index deb823a892ef..e53a36476b70 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -184,9 +184,30 @@ int uart_exists(uint16_t uart_base); int lpt_exists(uint16_t lpt_base); int hpet_exists(unsigned long hpet_base); =20 -/* Do cpuid instruction, with operation 'idx' */ -void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, - uint32_t *ecx, uint32_t *edx); +/* Some CPUID calls want 'count' to be placed in ecx */ +static inline void cpuid_count( + uint32_t leaf, + uint32_t subleaf, + uint32_t *eax, + uint32_t *ebx, + uint32_t *ecx, + uint32_t *edx) +{ + asm volatile ( "cpuid" + : "=3Da" (*eax), "=3Db" (*ebx), "=3Dc" (*ecx), "=3Dd" (*edx) + : "a" (leaf), "c" (subleaf) ); +} + +/* Generic CPUID function (subleaf 0) */ +static inline void cpuid( + uint32_t leaf, + uint32_t *eax, + uint32_t *ebx, + uint32_t *ecx, + uint32_t *edx) +{ + cpuid_count(leaf, 0, eax, ebx, ecx, edx); +} =20 /* Read the TSC register. */ static inline uint64_t rdtsc(void) --=20 2.45.2