Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1358396lqb; Sat, 25 May 2024 19:02:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2umGPj6NJ+7oB2qXm56LljIXY+0aT2jzQsipRMmhv+NA+VDc5jIaag1RIa9PTJ0wf9pTL9zKXORzbJF6YJNYJa5ka57SB8Hcv0mUo8A== X-Google-Smtp-Source: AGHT+IGsBTJqiFyg1FxjEDjWKcLVcuna4cqaSh8FAqFvFu1fx7MvjEROEcsSIjv9AFq1UNDMW/YY X-Received: by 2002:a05:620a:11ba:b0:792:9741:ca86 with SMTP id af79cd13be357-794ab057bbbmr704113585a.11.1716688937360; Sat, 25 May 2024 19:02:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716688937; cv=pass; d=google.com; s=arc-20160816; b=LvWsvK4kkWtgGrRif42IGYnvrR4UeR2eqyaDrA9BX2p4yCZhh/JZFHIG7VpXejdQr5 nQub4DD8ruuyoTEAPeTaztaJfPZfV2fXWDolbyEzBlC7CNxgsooxtvbPlLNi52Ew5heC Twpg1ACO52FIYx69DoCSlQLIbBHeHxgbLxJ6OcuCr2077dQ+yumFy/0ufk1QwcJJariS nec/egMji/pPKTdEdDKUobRV9Nesvg+esCCdG6p4dkCsmbFIQryxLqF+UKa+k+nb7kFZ VnWuTru+sGGmIwta5D5igRYpnb3UXovsB2amOKmG/X6wYPofOyyTR3ZWjfn4cNukBB9H kTWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=1ZW8zEOs8cef2h+hpYZBEZ24pTbSTyN7pHFs8zML0yE=; fh=yac52SU+ecp1V3eN8wKmedkhzLyVSNaQoV6n5dYwEaM=; b=N4pmh0/aejwxri4UIfC/+8Ovkiasd8+ImDMEHd8fJTVIGUmSjfayvHeJEPxAzA/oix 6TLeyhNIc+9jQjeTQzl/eIemxIo8wwNLgWSqohGyJ5H9WncXc0NovwKMRSfjG8XEoIMm /pWOXTO+b6K++Suv+yhCBpfK74o4tWZUjTNlyr153J1/s3Q6W3tbVRoW7qivg18Q6JF1 HNp+LTe0Jbt/iKFA5xJ1dMoUHDiB4YDsv2QwRdL+NCOjsFdMhVkK18hnnHmZf0tiHtjR izkInnv/womEMCJhujc5IzCflPQJNp1PAJk0MBGVrg0Fkh1m6vyHhzhRecw/4446xQ/Y m3BQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="n2IPv/pc"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-189585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd610dbsi491362585a.738.2024.05.25.19.02.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 19:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="n2IPv/pc"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-189585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 19A1B1C208F5 for ; Sun, 26 May 2024 02:02:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3BC515CB; Sun, 26 May 2024 02:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="n2IPv/pc" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81BC44A0F for ; Sun, 26 May 2024 02:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716688930; cv=none; b=ktBhB8DKHayl7VzpxGT/RWAKwJEHhKoD90t9jNMWiH6yZJtzuX+KDFWboThx+JRhZD5uGrSRtWV47y1qH5xobuoyQ7OYHyEWKFryzOrg80Pr/qy7aCUwNyulEq4GESeUIgcRuV4Jkz5GiXb/qIHYYFfJEvvq3GqnAgJSg83XDbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716688930; c=relaxed/simple; bh=wySTrCiWbxv3d5CkP0WjwDn7rMNpNEwftP0j7quJ8LM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DlvGKdfHNeuAP0eM+p3Fzzg8HVx8/KiUCLr4ojW20c7ndFaANm2O8C1Rnb0yyiTrOATpfpXmplIeXajL91tkwxtsaluJrfOTQGOPVraDXLWobF2mhSX8gY6AgnjB2nuB34EhpbysdzdZdhZAIgg+MqfYPtVPGSIcAsjIRi9f5Ig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=n2IPv/pc; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716688928; x=1748224928; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wySTrCiWbxv3d5CkP0WjwDn7rMNpNEwftP0j7quJ8LM=; b=n2IPv/pcJzeFPUbZCgsSqVVdRRkNDvJsp9xilbc9mjIr1ULQNVGguITT KvotSGozl+JS0uGWZaKVZ5NcgZt21ti4b/VgvXd/aDfq8v8l0SdvQYpdR vgpzLMa1EXevvhqp21++lZKLvyeYKiHPZLuAIOnt73z8D8gpIzNfF9ZUe uU6iv09rdpiKppnz/4WoSDuse11ic85u8If2rZcfgVwF83zLtXt5CQFL/ JvTMGWHiixzqd24E0qFWcW7WzbNIeomTvQNcqXp0uYcuHWYY4KhCGuFOA Q7Pwiuld+T9RFvxeUezWrYSbMRkPPX6KqTuo3OTkjkFoIbOA7hG3Y/wTA A==; X-CSE-ConnectionGUID: iKKG1ii/QUuuZi2UzgI0lg== X-CSE-MsgGUID: aDqswrwAT8KdgAfQ1hrycQ== X-IronPort-AV: E=McAfee;i="6600,9927,11083"; a="23633421" X-IronPort-AV: E=Sophos;i="6.08,189,1712646000"; d="scan'208";a="23633421" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2024 19:02:08 -0700 X-CSE-ConnectionGUID: /iF1cy3dSnCmVTft7XP+Vw== X-CSE-MsgGUID: PPmQzdpWQ2WRWRTggtGsow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,189,1712646000"; d="scan'208";a="39375802" Received: from chenyu-dev.sh.intel.com ([10.239.62.164]) by orviesa004.jf.intel.com with ESMTP; 25 May 2024 19:02:04 -0700 From: Chen Yu To: Dave Hansen , Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Ajay Kaher Cc: x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Chen Yu , Qiuxu Zhuo , Prem Nath Dey , Xiaoping Zhou Subject: [PATCH v2] x86/paravirt: Disable virt spinlock on bare metal Date: Sun, 26 May 2024 09:58:47 +0800 Message-Id: <20240526015847.14142-1-yu.c.chen@intel.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The kernel can change spinlock behavior when running as a guest. But this guest-friendly behavior causes performance problems on bare metal. So there's a 'virt_spin_lock_key' static key to switch between the two modes. The static key is always enabled by default (run in guest mode) and should be disabled for bare metal (and in some guests that want native behavior). Performance drop is reported when running encode/decode workload and BenchSEE cache sub-workload. Bisect points to commit ce0a1b608bfc ("x86/paravirt: Silence unused native_pv_lock_init() function warning"). When CONFIG_PARAVIRT_SPINLOCKS is disabled the virt_spin_lock_key is incorrectly set to true on bare metal. The qspinlock degenerates to test-and-set spinlock, which decrease the performance on bare metal. Fix this by disabling virt_spin_lock_key if it is on bare metal, regardless of CONFIG_PARAVIRT_SPINLOCKS. Fixes: ce0a1b608bfc ("x86/paravirt: Silence unused native_pv_lock_init() function warning") Suggested-by: Dave Hansen Suggested-by: Qiuxu Zhuo Reported-by: Prem Nath Dey Reported-by: Xiaoping Zhou Reviewed-by: Juergen Gross Signed-off-by: Chen Yu --- v1->v2: Refine the commit log per Dave's suggestion. Simplify the fix by directly disabling the virt_spin_lock_key on bare metal. Collect Reviewed-by from Juergen. --- arch/x86/kernel/paravirt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 5358d43886ad..c193c9e60a1b 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -55,8 +55,7 @@ DEFINE_STATIC_KEY_TRUE(virt_spin_lock_key); void __init native_pv_lock_init(void) { - if (IS_ENABLED(CONFIG_PARAVIRT_SPINLOCKS) && - !boot_cpu_has(X86_FEATURE_HYPERVISOR)) + if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) static_branch_disable(&virt_spin_lock_key); } -- 2.25.1