Translated message

A translation of this page exists in English.

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

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 5, 6, 7, 8, 9

Issue

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

Resolution

概要

Simultaneous Multithreading (SMT) は、1つの物理CPUコアで複数の実行スレッドを実行する技術です。この技術は、Hyper-Threading など、さまざまな名前で知られていますが、同様の原理で動作します。

インテルは、SMT の実装である Hyper-Threading (HT) の概要と、アプリケーションによってそれが役立つ場合とそうでない場合について、優れた概要を提供しています:

注意 上記のリンクは、Red Hat が直接作成したものではありません。そのため、Red Hat のサポートはその正確性と内容を確認することができません。

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

最近、マイクロプロセッサの様々な問題が発見されています。一部の問題では、その問題をより完全に軽減するために SMT を無効にする必要があります。以下の脆弱性については、SMT特有の懸念事項として確認されることをお勧めします。

L1TF - L1 Terminal Fault Attack - CVE-2018-3620 & CVE-2018-3646
MDS - Microarchitectural Store Buffer Data - CVE-2018-12130, CVE-2018-12126, CVE-2018-12127, and 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番号である。 このファイルには、以下に示すようなHyper-Thread 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を無効にする手順にはOS再起動を必要としない方法もあります。SMTを一度無効化したら、再びSMTを有効化する事は推奨しません。システムの再起動がSMTを再度有効にする際の、最も効率的で安全な方法です。

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

この方法は、再起動が必要で、持続性があります。SMTを無効にする最も効果的で一般的な方法は、システムのファームウェアまたはBIOSを使用する方法です。SMTを無効にするための正しい手順については、システムのハードウェアベンダのドキュメントを参照してください。オペレーティングシステムは、ファームウェアのCPUコンフィギュレーションを尊重します。

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

この方法は、新しいカーネルを必要とし、永続的で再起動が必要です。この機能は nosmt ブートパラメータを介して、RHEL6 では 2.6.32-754 (RHEL6.10GA カーネル) で、RHEL7 ではこれらのカーネルで利用可能になっています。

  • RHEL7.2: kernel 3.10.0-327.71.4 またはそれ以降 (ストリームの AUS フェーズでリリースされた)
  • RHEL7.3: kernel 3.10.0-514.55.4 またはそれ以降 (ストリームの EUS フェーズでリリースされた)
  • RHEL7.4: kernel 3.10.0-693.37.4 以降 (ストリームの EUS フェーズでリリースされた)
  • RHEL7.5: kernel 3.10.0-862.11.6 またはそれ以降。
  • RHEL7.6: kernel 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?

  • また、以下のワンライナー・スクリプトを使用して、システム上の各CPUコアのHyper-Threadを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

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