Translated message

A translation of this page exists in English.

Red Hat Enterprise Linux の同時マルチスレッド

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 5 - 10

Issue

  • 同時マルチスレッド (SMT) とは何ですか?
  • 同時マルチスレッドはハイパースレッディングと同じですか?
  • SMT が使用されているかどうかを判断するにはどうすればよいですか?
  • RHEL の同時マルチスレッドを無効にするにはどうすればよいですか?
  • SMT に関連するセキュリティー上の懸念はありますか?

Resolution

概要

同時マルチスレッド (SMT) を使用すると、単一の物理 CPU コアで複数の実行スレッドを実行できます。このテクノロジーは、ハイパースレッディングなどさまざまな名前で知られていますが、同様の原理で動作します。

Intel は、SMT の実装であるハイパースレッディング (HT) について、およびアプリケーションの特性に応じて有効な場合とそうでない場合について、優れた概要を提供しています。

Intel® ハイパースレッディングテクノロジー
アプリケーションにおけるハイパースレッディングテクノロジーの有効性を判断する方法 | Intel® Software

警告:上記の VMWare へのリンクは、Red Hat が直接執筆していないソースへのリンクとなります。そのため、Red Hat サポートはその正確性と内容を検証できません。

SMT のセキュリティーに関する懸念

最近、マイクロプロセッサーのさまざまな不具合が発見されました。特定の問題では、問題をできる限り軽減するために SMT を無効にする必要があります。SMT 固有の懸念事項については、次の脆弱性を確認することを推奨します。

L1 Terminal Fault (L1TF) を使用したカーネルのサイドチャネル攻撃: CVE-2018-3620 & CVE-2018-3646
MDS - マイクロアーキテクチャーストアバッファーデータ - CVE-2018-12130、CVE-2018-12126、CVE-2018-12127、および CVE-2019-11091

システムのハイパースレッドトポロジーの検証

システムの各ハイパースレッドは、カーネルに対して論理 CPU コアとして表示されます。 lscpu ユーティリティーで示されるように、物理ソケットごとに複数のコアが存在する場合があります。

# lscpu | grep -e Socket -e Core -e Thread
Thread(s) per core:    2
Core(s) per socket:    6
Socket(s):             2

上記では、システムは 2 つのソケットがあり、それぞれに 6 つのコアがあり、各コアに 2 つのスレッドがあることを示しています。視覚的には、次のようなトポロジーが得られます。

+-------------------------------------------------------+-------------------------------------------------------+
|                        Socket 1                       |                        Socket 2                       |
| +-------------------------+-------------------------+ | +-------------------------+-------------------------+ |
| |          Core 1         |          Core 2         | | |          Core 1         |          Core 2         | |
| +------------+-------------------------+------------+ | +------------+-------------------------+------------+ |
| |            |            |            |            | | |            |            |            |            | |
| |  Thread 1  |  Thread 2  |  Thread 1  |  Thread 2  | | |  Thread 1  |  Thread 2  |  Thread 1  |  Thread 2  | |
| |            |            |            |            | | |            |            |            |            | |
| +------------+-------------------------+------------+ | +------------+-------------------------+------------+ |
| |          Core 3         |          Core 4         | | |          Core 3         |          Core 4         | |
| +------------+-------------------------+------------+ | +------------+-------------------------+------------+ |
| |            |            |            |            | | |            |            |            |            | |
| |  Thread 1  |  Thread 2  |  Thread 1  |  Thread 2  | | |  Thread 1  |  Thread 2  |  Thread 1  |  Thread 2  | |
| |            |            |            |            | | |            |            |            |            | |
| +------------+-------------------------+------------+ | +------------+-------------------------+------------+ |
| |          Core 5         |          Core 6         | | |          Core 5         |          Core 6         | |
| +------------+-------------------------+------------+ | +------------+-------------------------+------------+ |
| |            |            |            |            | | |            |            |            |            | |
| |  Thread 1  |  Thread 2  |  Thread 1  |  Thread 2  | | |  Thread 1  |  Thread 2  |  Thread 1  |  Thread 2  | |
| |            |            |            |            | | |            |            |            |            | |
| +---------------------------------------------------+ | +---------------------------------------------------+ |
+-------------------------------------------------------+-------------------------------------------------------+

どの CPU を無効にするかを判断するには、同じ CPU コアで実行されているスレッドを識別する必要があります。/sys/devices/system/cpu/cpuN/topology/thread_siblings_list という名前のファイルが存在します。ここで、N は論理 CPU 番号です。これらのファイルには、以下に示すように、ハイパースレッド CPU ペアが含まれます。

# grep -H . /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sort -n -t ':' -k 2 -u
/sys/devices/system/cpu/cpu0/topology/thread_siblings_list:0-1
/sys/devices/system/cpu/cpu2/topology/thread_siblings_list:2-3
/sys/devices/system/cpu/cpu4/topology/thread_siblings_list:4-5
/sys/devices/system/cpu/cpu6/topology/thread_siblings_list:6-7
/sys/devices/system/cpu/cpu8/topology/thread_siblings_list:8-9
/sys/devices/system/cpu/cpu10/topology/thread_siblings_list:10-11
/sys/devices/system/cpu/cpu12/topology/thread_siblings_list:12-13
/sys/devices/system/cpu/cpu14/topology/thread_siblings_list:14-15
/sys/devices/system/cpu/cpu16/topology/thread_siblings_list:16-17
/sys/devices/system/cpu/cpu18/topology/thread_siblings_list:18-19
/sys/devices/system/cpu/cpu20/topology/thread_siblings_list:20-21
/sys/devices/system/cpu/cpu22/topology/thread_siblings_list:22-23

注記:兄弟リスト内の区切り文字は、CPU モデルに応じて 0-1 または 0,2 形式になります。

上記の出力は、論理 CPU 0 と論理 CPU 1 が同じコア上のスレッドであることを示しています。

SMT を無効にする

SMT を無効にする方法はいくつかあります。効果的な方法は、使用しているカーネルのバージョンによって異なります。以下の方法でさらに新しいカーネルが必要な場合は、具体的な方法も合わせて提供されます。

注記:再起動を必要としない以下の SMT を無効にする方法では、無効にした後に SMT スレッドの再有効化は推奨しません。一度無効にした場合の最も効果的かつ安全に SMT を再有効化する方法は、システムを再起動することです。

ハードウェアレベルの無効化

この方法は再起動が必要であり、永続的です。システムファームウェアまたは BIOS 内で SMT を無効にすることが最も効果的で、一般的に推奨される方法です。適切な SMT の無効化のプロセスを確認するには、システムハードウェアベンダーのドキュメントを参照してください。オペレーティングシステムはファームウェアの CPU 設定を認識します。

カーネルブートパラメーターによる無効化

この方法は新しいカーネルを必要とし、永続的であり、再起動が必要です。この機能は、RHEL6 の 2.6.32-754 (RHEL6.10GA カーネル) および RHEL7 の以下のカーネルで、nosmt ブートパラメーターを介して利用できます。

  • RHEL7.2: カーネル 3.10.0-327.71.4 以降 (ストリームの AUS フェーズでリリース)
  • RHEL7.3: カーネル 3.10.0-514.55.4 以降 (ストリームの EUS フェーズでリリース)
  • RHEL7.4: カーネル 3.10.0-693.37.4 以降 (ストリームの EUS フェーズでリリース)
  • RHEL7.5: カーネル 3.10.0-862.11.6 以降
  • RHEL7.6: カーネル 3.10.0-957 (GA カーネル)
        nosmt           [KNL,S390] Disable symmetric multithreading (SMT).
                        Equivalent to smt=1.

                        [KNL,x86] Disable symmetric multithreading (SMT).
                        nosmt=force: Force disable SMT, cannot be undone
                                     via the sysfs control file.
  • アクティブカーネルのパラメーターは、次のように設定できます。
# grubby --args=nosmt --update-kernel=DEFAULT
  • 上記の変更により、カーネルブートパラメーターがデフォルトのカーネルブートエントリーに適用され、カーネルの更新によって引き継がれる可能性があります。Red Hat Enterprise Linux 7 およびそれ以前のリリースでは、新しいカーネルバージョンの引数が含まれます。Red Hat Enterprise Linux 8 では、上記のコマンドの意図に沿って、変更はデフォルトのブートカーネルエントリーにのみ適用され、引数は引き継がれません。リリースに関係なく、grub2-mkconfig コマンドを使用すると、パラメーターはオーバーライドされます。パラメーターが grub2-mkconfig に引き継がれるようにするには、/etc/sysconfig/grub 設定ファイル内の GRUB_CMDLINE_LINUX エントリーに nosmt パラメーターを適用する必要があります。

実行時に無効化する

この方法では新しいカーネルが必要になる可能性があります。再起動は必要なく、永続的ではありません。新しいカーネルには、実行時に SMT を制御するための次のインターフェイスが含まれています。

   /sys/devices/system/cpu/smt/control:

     This file allows to read out the SMT control state and provides the
     ability to disable or (re)enable SMT. The possible states are:

        ==============  ===================================================
        on              SMT is supported by the CPU and enabled. All
                        logical CPUs can be onlined and offlined without
                        restrictions.

        off             SMT is supported by the CPU and disabled. Only
                        the so called primary SMT threads can be onlined
                        and offlined without restrictions. An attempt to
                        online a non-primary sibling is rejected

        forceoff        Same as 'off' but the state cannot be controlled.
                        Attempts to write to the control file are rejected.

        notsupported    The processor does not support SMT. It's therefore
                        not affected by the SMT implications of L1TF.
                        Attempts to write to the control file are rejected.
        ==============  ===================================================

     The possible states which can be written into this file to control SMT
     state are:

     - on
     - off
     - forceoff

   /sys/devices/system/cpu/smt/active:

     This file reports whether SMT is enabled and active, i.e. if on any
     physical core two or more sibling threads are online.
  • 実行時に SMT を無効にするには、以下を使用できます。
    > ~~~
    > # echo off > /sys/devices/system/cpu/smt/control
    > ~~~

実行時に無効化する代替手段

この方法は再起動を必要とせず、永続的ではありません。

Red Hat では、実行時に SMT を有効化または無効化しないことを強く推奨します。無効化すると、パフォーマンスの低下やランタイムエラーなどの予期しない動作が発生する可能性があります。SMT を制御するには、カーネルブートコマンドラインフラグを使用する方法が推奨されます。

次のセクションでは、全体が見えるようにランタイム SMT コントロールを説明しますが、前述のとおり推奨されません。

  • カーネルの CPU ホットプラグ機能を使用すると、コアごとに HT を無効化できます。 CPU ホットプラグを手動で進める方法は、次の記事を参照してください。

    Is it possible to "hotplug" a CPU on a running Red Hat Enterprise Linux?

  • または、次の 1 行スクリプトを使用して、システム上の各 CPU コアの 1 つのハイパースレッドを無効化することもできます。

    for CPU in $( ls /sys/devices/system/cpu/cpu[0-9]* -d | sort); do 
    awk -F '[-,]' '{if(NF > 1) {HOTPLUG="/sys/devices/system/cpu/cpu"$NF"/online"; print "0" > HOTPLUG; close(HOTPLUG)}}' $CPU/topology/thread_siblings_list 2>/dev/null; done
    

前の例のシステムでは、結果は以下のとおりです。

# grep -H . /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sort -n -t ':' -k 2 -u
/sys/devices/system/cpu/cpu0/topology/thread_siblings_list:0
/sys/devices/system/cpu/cpu2/topology/thread_siblings_list:2
/sys/devices/system/cpu/cpu4/topology/thread_siblings_list:4
/sys/devices/system/cpu/cpu6/topology/thread_siblings_list:6
/sys/devices/system/cpu/cpu8/topology/thread_siblings_list:8
/sys/devices/system/cpu/cpu10/topology/thread_siblings_list:10
/sys/devices/system/cpu/cpu12/topology/thread_siblings_list:12
/sys/devices/system/cpu/cpu14/topology/thread_siblings_list:14
/sys/devices/system/cpu/cpu16/topology/thread_siblings_list:16
/sys/devices/system/cpu/cpu18/topology/thread_siblings_list:18
/sys/devices/system/cpu/cpu20/topology/thread_siblings_list:20
/sys/devices/system/cpu/cpu22/topology/thread_siblings_list:22

Root Cause

Diagnostic Steps

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments