Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp91758lqb; Thu, 23 May 2024 11:40:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpMN8BrFFrtLAecBZdtLocfohJSJfGWt0g8NRHekabVexbxBnsEgoPSa/EP1cJmr8d3uiwCmxfbVx4Jgu6e1I+elXC6c5PA+FXgvazCA== X-Google-Smtp-Source: AGHT+IHIG6CgRAv7AZU/PhGhl4eAroMm4P8qSvqrbQPD+1YVe6qoPQeShtWQbMDfbhtLgtRa5DKO X-Received: by 2002:a05:6a21:1394:b0:1af:acf5:f9e5 with SMTP id adf61e73a8af0-1b212d04d43mr293312637.23.1716489611369; Thu, 23 May 2024 11:40:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716489611; cv=pass; d=google.com; s=arc-20160816; b=pvj9TkGFB43Wh4gkPiR47SdP2Hi52UjCJWayVK5m512hscsMoyhprv03O1xEuwAEvk OgwBNTR0db3UJBOD/oibkRfmo1W7Kbr3zrIFK6hwZhh3PaX3ne+pqXc1adck4/VSUcCn rxT/lwFZ6HnKZyI6FDcyh4iReL9BPVmh7GSncOF/+UN241xEmeIdoyTAqsQUac5n3xD/ guBA2wOjzD4BgK+y03MXjZzmPVyjbbF9ZLeWaFgU34f/e2fbzg3LuQn7dVxbgaLi6dZ2 BOcbTX4WiIzWu1bxutBkY9WYHrWc8ctawIWa/+cEmWsiMorohvSef3AZiK17Ais+YJBf d7HA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=sPNsSdDaQu0NIT3u7mvtcXRasJFxRX07JUknJPwEvjQ=; fh=fr2vqNdG52cZg7wjE7oLHnVKTOt3G6ZsgrRqz7FnR5g=; b=qfgIUC7D4AfclEl6+dDcbsIL3h4n5k2it4W502ehqVxrLZu+Qc5ZH4bWwLOtltyKlF uuNHZ2LahliM+l0gpJPViVdWbCF4kQqNT0ePXOtTTPWD7tIPlrj6nSsjYjUqneKUeD4p OJEOK5IcWRqnK1N+D39Y0AqOymKngZBFmq9yP7bT2m8Y/Q+Ec0LL4aurwTYwHPukS6dn oVI8eWsgTYB70tq6vgPU5KuSKrIG6lykd7ytC9MkufYIbtm/w1D1vd0GJmbxLo+Q4Bf5 PvI32LhxU5DX+dmNUeaaaROX9xzFFrxLNsHPvgv3dOVzH/bXuGHyQvXeGiOnsbe2iKog dwBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=a4tS3Ipj; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-187889-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-67200e49ad9si5599810a12.385.2024.05.23.11.40.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 11:40:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187889-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=a4tS3Ipj; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-187889-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0DD89283407 for ; Thu, 23 May 2024 18:40:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6FB9C80603; Thu, 23 May 2024 18:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="a4tS3Ipj" Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 129357E586 for ; Thu, 23 May 2024 18:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716489604; cv=none; b=fuHpC7PsRDYsSdEIND9KNc+UVw2zBRlRruV4v1fg46wV2oG0ShJ0DwIBBPX01mZABT0Fc9gMSWfmltzYpQw4sq7mANMljmYQcuzSzxwKoIgzQC3OBd6ro+GGTa0xha76YCAZE4zL/O9z/SUijrc6zW5t4+N4vrhc24jqTKRjWBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716489604; c=relaxed/simple; bh=yRsCEoicgaKzohe9lKyCvRJ8ywpHXjW4YO2bnP2lO30=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tDd4OsC+Rk++38CLAMrAotDIZ5EyBhNgs4vOxxIUPGgYJ6+X5k2V5WX92rNmqneIo9e5rrwZad+TbvVcECZ7jCcga4JzshUlcf/2XJe42y/u6E/wNdS5N/cFeRr0Bs8lALXPJAvF1wrYEJrSAN0IAvCaMFCUAJ/mHJvPU6ozWPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=a4tS3Ipj; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-57851608e72so107488a12.1 for ; Thu, 23 May 2024 11:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1716489600; x=1717094400; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=sPNsSdDaQu0NIT3u7mvtcXRasJFxRX07JUknJPwEvjQ=; b=a4tS3IpjbyL6c2JGaNh2OvEtlug7cUCRkt9+3j0UJjwrPQImmOIdK7U4DNNVlpb7f7 Pr2hObXjEjYOLD6Dv8mlR9ZJwDVrX1Upm/jWSSnOqqcU/sORPy9lj32xYCXn6spuVDaq J5he9Yzb2SfwvRKo6V8wh2/D70uVuDepjmo/jdwUeCapBoXPEmPliFgzyE0CHzSxF9PT WqX+5sawNJDwPeEZEY0q5Oyor9V+fOzgbMyUDpF9XBoagCkT1weOCs/yn9lIkGgNLxDE pgbY1pT+KCxExIUdIrEgM8MbzKwMn/b53Y8oT5U+OHJXKt+XIFZyYnBOJDvVZqNg/O4n N24Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716489600; x=1717094400; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sPNsSdDaQu0NIT3u7mvtcXRasJFxRX07JUknJPwEvjQ=; b=JWCRCDQsAvZhrzXKREYgVtzIHbibiN2dVd32lG2ewyWWhgOVI/D613ksYVoLpTlHMB CU6r+8yOOTsWVviDRneKXbZTs7QwwytqZxgRE75LcMFD9sl387jYIVFU0S75G2HFWlsB atLG+W9YhAD3Q0NUfc2vtMoXRsuy6p++vdiPCEz0IKGoILUtyw2z8aj2C97U9C/U2MYe n8hdT4V9kBctbyqPQea/RIZpriG8jpBp/0eKzxcq7KIQQGV3EvVNHElCIsFzYtbAIA0o RBzibpdBgFRGyznNf3tcj3jPLjTSDBKCYXjKD5T0DSmnL7EIKDfgVyBuXdFTgqLg1GSN Pnlg== X-Forwarded-Encrypted: i=1; AJvYcCX5vr7M2X8JUUodvHJMVclGk6/Uc/IN9HPNK1tI1VJa9qeyxayEJXK45JDX0KFodnS3za+kZ8gdErLZ4GBaBejZPs1fB1vHmrTYINQC X-Gm-Message-State: AOJu0YxkEsbB1AUCXaQB5mZZkXjnHKupRxDCAe4GaLVvSHRUAbl+81ni KUf8iP5dODlvRF3rkrruKYxVdQWy8Q+3qU6/lPtjixlFDd/OAx/D+1WLBGDfAco= X-Received: by 2002:a17:906:e52:b0:a59:cb29:3fb8 with SMTP id a640c23a62f3a-a62641a392fmr12916666b.1.1716489600370; Thu, 23 May 2024 11:40:00 -0700 (PDT) Received: from ?IPV6:2003:e5:8729:4000:29eb:6d9d:3214:39d2? (p200300e58729400029eb6d9d321439d2.dip0.t-ipconnect.de. [2003:e5:8729:4000:29eb:6d9d:3214:39d2]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a179c7d9dsm1973152566b.132.2024.05.23.11.39.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 11:40:00 -0700 (PDT) Message-ID: Date: Thu, 23 May 2024 20:39:59 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/paravirt: Disable virt spinlock when CONFIG_PARAVIRT_SPINLOCKS disabled To: Dave Hansen , Chen Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Ajay Kaher , Alexey Makhalov , Arnd Bergmann , "H. Peter Anvin" , x86@kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Qiuxu Zhuo , Prem Nath Dey , Xiaoping Zhou References: <20240516130244.893573-1-yu.c.chen@intel.com> <7b8d1dd6-3913-45fe-941e-aac2c15916dc@intel.com> Content-Language: en-US From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= In-Reply-To: <7b8d1dd6-3913-45fe-941e-aac2c15916dc@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 23.05.24 18:30, Dave Hansen wrote: > On 5/16/24 06:02, Chen Yu wrote: >> 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 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 CONFIG_PARAVIRT_SPINLOCKS >> is not set, or it is on bare-metal. > > This is missing some background: > > 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). > > ... then describe the regression and the fix > >> diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c >> index 5358d43886ad..ee51c0949ed8 100644 >> --- a/arch/x86/kernel/paravirt.c >> +++ b/arch/x86/kernel/paravirt.c >> @@ -55,7 +55,7 @@ DEFINE_STATIC_KEY_TRUE(virt_spin_lock_key); >> >> void __init native_pv_lock_init(void) >> { >> - if (IS_ENABLED(CONFIG_PARAVIRT_SPINLOCKS) && >> + if (!IS_ENABLED(CONFIG_PARAVIRT_SPINLOCKS) || >> !boot_cpu_has(X86_FEATURE_HYPERVISOR)) >> static_branch_disable(&virt_spin_lock_key); >> } > This gets used at a single site: > > if (pv_enabled()) > goto pv_queue; > > if (virt_spin_lock(lock)) > return; > > which is logically: > > if (IS_ENABLED(CONFIG_PARAVIRT_SPINLOCKS)) > goto ...; // don't look at virt_spin_lock_key > > if (virt_spin_lock_key) > return; // On virt, but non-paravirt. Did Test-and-Set > // spinlock. > > So I _think_ Arnd was trying to optimize native_pv_lock_init() away when > it's going to get skipped over anyway by the 'goto'. > > But this took me at least 30 minutes of scratching my head and trying to > untangle the whole thing. It's all far too subtle for my taste, and all > of that to save a few bytes of init text in a configuration that's > probably not even used very often (PARAVIRT=y, but PARAVIRT_SPINLOCKS=n). > > Let's just keep it simple. How about the attached patch? Simple indeed. The attachment is empty. :-p Juergen