Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7901235rwd; Tue, 20 Jun 2023 07:41:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sCj+ISI57YXqyZ3Eu3HdKWO0dGxh6dqPci0FhEMkDdw9ZPJbNBwyOGRqe0L0phrYAWyOj X-Received: by 2002:a9d:6284:0:b0:6b1:605d:36d6 with SMTP id x4-20020a9d6284000000b006b1605d36d6mr7802593otk.23.1687272072810; Tue, 20 Jun 2023 07:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687272072; cv=none; d=google.com; s=arc-20160816; b=iKHlRypC3vBb2i300qP70GKYSoTyTtEYxt0MOaTQw3N15SbBH53oAvuaml1NzlyVHe egWzZ0befkJFYB3R9DJIoRWi2CmklilmClyQY6ZHcJ3syo5f9TtFXuRibkBUUA0xFtX6 lBw90L6qt+Ix/a+m9xTAw762wnjsvgoyDYNmtXBQZF0rB0J6JadaVEIxN3ROij3y7W4F u6yvfm7LKdgm5zhyfN7KAHU/2TrswTceekQFgEnilWg5V15D9qbZ5/eDY/s91yA6NAGx VfPyv36F/1K9stTg6a/Swo87zG6S6p+Y36sarY/FT8iG844YhfA8otPWzNqp2/wxCetu LtIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xcoOW1ZR6wswnF4rij7hWtB4wmZnp/XX0PDU4BubJAY=; b=gqKjV6e21jalyOEkvl2ohDlooSXL0b2WGYMgwwMiKWr5REZhS8KgFXvCFApf7bxKDZ LbCIs1qhTEMpYoEGBOW6/fXuBFEkHamNHm/SoxycTf8Uj0a02AznWrLQJ9BMWOHTgCi3 wQTFahmmRu5K16pu3Sp/2b3WOVJcqAeerHkYn1Vzv5Z63qsSrXXuU3JzCNSxcYrZkFxo ESqly10FnmAXmBKtyDu4ZsQq1B4FnuZYyBnhOu54jA/yW5gdzVWp1mXSEzwLPP9V7Tay uAl7VTlxVPErJ5AIv4nS/smXCH7emeLS2CHm2OXqXkZHh59s3r+yAt40p+hD0O5D5gU7 T6Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=emhmzWlj; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i27-20020a633c5b000000b00553921dbc22si1975535pgn.643.2023.06.20.07.41.00; Tue, 20 Jun 2023 07:41:12 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=emhmzWlj; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233116AbjFTOLI (ORCPT + 99 others); Tue, 20 Jun 2023 10:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbjFTOKw (ORCPT ); Tue, 20 Jun 2023 10:10:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B63210CE for ; Tue, 20 Jun 2023 07:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687270208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xcoOW1ZR6wswnF4rij7hWtB4wmZnp/XX0PDU4BubJAY=; b=emhmzWljLnThEP4yHnnEEU/510tkDVayAcR80xSsPRU43ylG52/v9lDgrZeFWXGeK5Vsz/ JDYz2t215cvbaZ/eZfviqDhXPppAT5Ish4dKNfQ9hsWfvixV5NtQMrk5xJ35zdHRcVjW2V wu+GnMF3fjvKlBvrYM3a8K+XrnwydLI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-pSQ_-q6DO1WXmzsWOAOpSg-1; Tue, 20 Jun 2023 10:09:04 -0400 X-MC-Unique: pSQ_-q6DO1WXmzsWOAOpSg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1A5388D56E; Tue, 20 Jun 2023 14:06:31 +0000 (UTC) Received: from llong.com (unknown [10.22.34.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE24D425357; Tue, 20 Jun 2023 14:06:30 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Josh Poimboeuf , Pawan Gupta , Jacob Pan , Len Brown Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org, Robin Jarry , Joe Mario , Waiman Long Subject: [PATCH v2 0/5] x86/speculation: Disable IBRS when idle Date: Tue, 20 Jun 2023 10:06:20 -0400 Message-Id: <20230620140625.1001886-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 For Intel processors that need to turn on IBRS to protect against Spectre v2 and Retbleed, the IBRS bit in the SPEC_CTRL MSR affects the performance of the whole core even if only one thread is turning it on when running in the kernel. For user space heavy applications, the performance impact of occasionally turning IBRS on during syscalls shouldn't be significant. Unfortunately, that is not the case when the sibling thread is idling in the kernel. In that case, the performance impact can be significant. When DPDK is running on an isolated CPU thread processing network packets in user space while its sibling thread is idle. The performance of the busy DPDK thread with IBRS on and off in the sibling idle thread are: IBRS on IBRS off ------- -------- packets/second: 7.8M 10.4M avg tsc cycles/packet: 282.26 209.86 This is a 25% performance degradation. The test system is a Intel Xeon 4114 CPU @ 2.20GHz. Commit bf5835bcdb96 ("intel_idle: Disable IBRS during long idle") disables IBRS when the CPU enters long idle (C6 or below). However, there are existing users out there who have set "intel_idle.max_cstate=1" or even "intel_idle.max_cstate=0" to decrease latency. Those users won't be able to benefit from this commit. This patch series extends this commit by providing a new "intel_idle.no_ibrs" module option to force disable IBRS even when "intel_idle.max_cstate=1" at the expense of increased IRQ response latency. It also includes commit to allow the disabling of IBRS with "intel_idle.max_cstate=0" as well as when a CPU becomes offline. The first patch adds a new x86/spec_ctrl_msrs debugfs file which display the current cached values of the SPEC_CTRL MSRs of all the CPUs. This allows us to verify that IBRS bit is correctly turned off in idle CPUs for various cstate values. Waiman Long (5): x86/speculation: Provide a debugfs file to dump SPEC_CTRL MSRs x86/idle: Disable IBRS when cpu is offline intel_idle: Sync up the SPEC_CTRL MSR value to x86_spec_ctrl_current intel_idle: Add no_ibrs module parameter to force disable IBRS x86/idle: Disable IBRS entering mwait idle and enable it on wakeup arch/x86/include/asm/mwait.h | 17 ++++++++ arch/x86/kernel/cpu/bugs.c | 79 ++++++++++++++++++++++++++++++++++++ arch/x86/kernel/smpboot.c | 13 ++++++ drivers/idle/intel_idle.c | 22 ++++++++-- 4 files changed, 127 insertions(+), 4 deletions(-) -- 2.31.1