From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mx.groups.io with SMTP id smtpd.web12.34203.1618240092141753130 for ; Mon, 12 Apr 2021 08:08:12 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bPf5m3//; spf=pass (domain: gmail.com, ip: 209.85.215.171, mailfrom: naitaku@gmail.com) Received: by mail-pg1-f171.google.com with SMTP id w10so9614866pgh.5 for ; Mon, 12 Apr 2021 08:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nXVR1pKg0dSvbA8Ja/0vvnoUp45yre/9zke2y3miXVc=; b=bPf5m3//Hgmd3mTJv49uyjX09p2XTH2I1Lm6jwK8zvvOv7BzqKrnomhmszHV4fLC0U ItwAo48GNWk7yalWiGlik7sDWIplTg1K4IWeZFjzb9WZsgt/E55aOFf/ryplktH6odPD jVyn31b4U7bl8yg3cNgLF97+RgYa4B+HCJjZk/ypvIJFWiHlbu1llNuZmacpuJ+51dsu MKAhGXSYBSLlAMRnZBbV029vG8dvI7sfIeoRSJjW82kQQaU11g8pZcMj00JZcVdSoF6O fMEf6Z6Cldf0vptCjuWfx/grzFpYeDIzVkWANeHeeD8OxcHP9jkjIlkh592/HvxckAfg MT/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nXVR1pKg0dSvbA8Ja/0vvnoUp45yre/9zke2y3miXVc=; b=lY/eTbsah3WQNeoafOn08H5IK/n17yWYyLzt6FXgkOi5Ea9YdBv7hEuQpDWm75eI2y IeQFyu6Cs+aBtjfgTiJa21qIcIssdi4Kv3Y9O6eQg+nbBf/J5xQ6Z2pptum5WlM2ro9Y a4SkHnISMrI905duwEEUqJLlXKzGUkN3WpEhCX0mz0LEyuJKd3PVJlnbNLxz/jqEditG l2jAqSGPb0TUC9OI/7fS7TSpp4pJMw9gBHQcvARrRfpoFfV3reHRxqERVSeOAdhC4Hoq a/krIYqK6N6/Tu+zev3uYWc6w36APMWJNhyhmU4t/ZY/9NxbqRmx/GjnxJn+8kGpq0t/ NyKw== X-Gm-Message-State: AOAM530wlW/p1ee7CujMlJ0bUOGwhnPFGzY8LwUJ1mqC5HbjjirUR4vB WYZQSPOoWZuKdcOsNHdVN2Mx62kApK/HBHWz X-Google-Smtp-Source: ABdhPJxjGiR8QS3G5ddBA7oCJ2LA7zAKX59/PO0KESCJ9tn7+Tr/Q07yS4jLtGhr/WF+KUmKCH9/sw== X-Received: by 2002:a65:6483:: with SMTP id e3mr27726009pgv.208.1618240091315; Mon, 12 Apr 2021 08:08:11 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([240d:1e:84:2c00:f834:96b1:5066:781d]) by smtp.googlemail.com with ESMTPSA id i10sm267479pjm.1.2021.04.12.08.08.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Apr 2021 08:08:10 -0700 (PDT) From: "Takuto Naito" To: devel@edk2.groups.io Cc: Takuto Naito , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [PATCH v1 1/1] Fix AsmReadMsr64() and AsmWriteMsr64() with GCC toolchain Date: Tue, 13 Apr 2021 00:07:18 +0900 Message-Id: <20210412150718.71002-2-naitaku@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412150718.71002-1-naitaku@gmail.com> References: <20210412150718.71002-1-naitaku@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3325 1. AsmReadMsr64() in X64/GccInlinePriv.c AsmReadMsr64 can return uninitialized value if FilterBeforeMsrRead returns False. This causes build error with the CLANG toolchain. 2. AsmWriteMsr64() in X64/GccInlinePriv.c In the case that FilterBeforeMsrWrite changes Value and returns True, The original Value, not the changed Value, is written to the MSR. This behavior is different from the one of AsmWriteMsr64() in X64/WriteMsr64.c for the MSFT toolchain. Signed-off-by: Takuto Naito Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu --- MdePkg/Library/BaseLib/X64/GccInlinePriv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MdePkg/Library/BaseLib/X64/GccInlinePriv.c b/MdePkg/Library/BaseLib/X64/GccInlinePriv.c index e4920f2116..244bd62ee6 100644 --- a/MdePkg/Library/BaseLib/X64/GccInlinePriv.c +++ b/MdePkg/Library/BaseLib/X64/GccInlinePriv.c @@ -80,7 +80,7 @@ AsmReadMsr64 ( } FilterAfterMsrRead (Index, &Value); - return (((UINT64)HighData) << 32) | LowData; + return Value; } /** @@ -111,11 +111,10 @@ AsmWriteMsr64 ( UINT32 HighData; BOOLEAN Flag; - LowData = (UINT32)(Value); - HighData = (UINT32)(Value >> 32); - Flag = FilterBeforeMsrWrite (Index, &Value); if (Flag) { + LowData = (UINT32)(Value); + HighData = (UINT32)(Value >> 32); __asm__ __volatile__ ( "wrmsr" : -- 2.31.1