From patchwork Wed May 22 01:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 1937568 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Oy13Uv4F; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=w9sMHdj9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VkYsZ41Qvz1ydW for ; Wed, 22 May 2024 11:40:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :Mime-Version:Date:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=EtLhljMs6xcrteh768o0hEYS5BeSKQ+35e1g9ahagZk=; b=Oy13Uv4FqKx2z5 aWW0ceFT5ljKd2EPlZuXVDLeYEAVvzoyrLQ7ubpeMIwjO0vCxaUvQoo/aJ5H1q9PV6/3pGEqP5Dx2 ssnTtg9Yl6hL7RrTloEdg6PUEi8Qj2iCILyylZCSDTN/XI14hwBA5vu9SAGpSgQPY0E+P4eQXdWEX mm//9LNSesPgikkrwtdNaxjIQkWtDv+srokylKxde3oNXA5yah3VzgMs6wiNo9nsO7wxUHtIHrTf/ bhTs5k4rXX4/ccLOA6/oOB7apC/SbxDPAx2wiw/u6TgrglhquiDm9rVECBhTa2s/9in5nBFgzrUBC +CoyetCYXN1VEcq8tLmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axz-00000001efE-2htf; Wed, 22 May 2024 01:40:31 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axo-00000001eVp-01K2 for kvm-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:23 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-df1cfa720aaso11515190276.2 for ; Tue, 21 May 2024 18:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342016; x=1716946816; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=zcj+niLGOsOBGFG/wxz5ssr64Z9mR+IM9s4JveywwVo=; b=w9sMHdj9nLPN3ZUoNV+5YRisDZZEBfGZyi9QgsGY+9T7fdjPxAKd291YoR5JGiB5Zg 8tbWrdS/Bo3VMJ/xzZXsrD8Uw/Qjo57t2JUrzRuESn/cPFLOuOF423w17yodREOuokO5 lLCXrSS9yJZBWu2ImM50yNvxiObu8DrMU3LLMfmvYLWJmDZ3E0oAOhoyim0vQOFjnYeG A5lCOdML6/XCxsKJ9HNyyEOKxyX01xsBYkGJuEHfB/JpQMvC5UQeCmxqaeyJ6Oia0gsi WUDR2GOTUcYxJ3dd4vEOZB9OLGvvUNOoOMZ6AAUtLS/o/hn191C+bIZPbmi+zMjtW6y4 ukyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342016; x=1716946816; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zcj+niLGOsOBGFG/wxz5ssr64Z9mR+IM9s4JveywwVo=; b=SpZMdAMqFBZbN1Lo98vWQMtm3lLmCzErZe1R2K3vwpsT9ag5/0h0azKm63bVWNGUS+ WZjRo5BZhvoqfUesuWndIPL3/pX2LhuEQyBaLQWO0I6JkqIWbCdKye5SM6JQLKtiyB2P Eh9slLzh8exmpvu3kMN0g9BRLDnnm882zxwX9b7912FXkqscIQ/pNa1k2IUX7o0Rk6at fDW7tdrHVBCuB68SRkqXkWOU+RkxynhYNjKHRB2RhwZLl+PpR0i5IAs2tZECa3/Hx+7n N8kNql7yuA/1axl41Icpfo0sn82OFN7lQ7IcvGO4DLB+UsJiaISxkcdG+yvPmY4let9B kXlg== X-Forwarded-Encrypted: i=1; AJvYcCV2aBPjVABVf83ZRdw+BFlCuK5jyzAETjiffyX5l9G04O95VNoMmU4qsmg59rX6kVqTJu3+RX+ZYOgWZ9VsOeGct2XQx3QZEuWM0RoHfw== X-Gm-Message-State: AOJu0Yy51WYMRc7ZJAxIWHNOsMzdhc/qPgx3UZ4j7CtGBlHt1Fsn7QK9 3/v0hfyEK0AjPl7/HstzR24OqP0C4MVI9BVkCyp0QxNSbdBatd7HJvnQUu6pL8Lb9ImjkqPYwQU WYg== X-Google-Smtp-Source: AGHT+IF8tl2Sd1O1Adb/DEG65NrlAsoUAahexLMaCbbpQeSeG4ZOBg+4u/hLB5lJUUIzwhVDdo9qeU1encA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:20c1:b0:de5:3003:4b64 with SMTP id 3f1490d57ef6-df4e0a80c05mr82582276.1.1716342016391; Tue, 21 May 2024 18:40:16 -0700 (PDT) Date: Tue, 21 May 2024 18:40:07 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-1-seanjc@google.com> Subject: [PATCH v2 0/6] KVM: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184020_063218_2A56ED7C X-CRM114-Status: GOOD ( 11.59 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Drop kvm_arch_sched_in() and instead add and use kvm_vcpu.scheduled_out to communicate to kvm_arch_vcpu_load() that the vCPU is being scheduling back in. While fiddling with an idea for optimizing state management on AMD CPUs, I wanted to skip re-saving certain host state when a vCPU is scheduled back in, as the state (theoretically) shouldn't change f [...] Content analysis details: (-7.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b4a listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM welcome-list -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Drop kvm_arch_sched_in() and instead add and use kvm_vcpu.scheduled_out to communicate to kvm_arch_vcpu_load() that the vCPU is being scheduling back in. While fiddling with an idea for optimizing state management on AMD CPUs, I wanted to skip re-saving certain host state when a vCPU is scheduled back in, as the state (theoretically) shouldn't change for the task while it's scheduled out. Actually doing that was annoying and unnecessarily brittle due to having a separate API for the kvm_sched_in() case (the state save needed to be in kvm_arch_vcpu_load() for the common path). The other motivation for this is to avoid yet another arch hook, and more arbitrary ordering, if there's a future need to hook kvm_sched_out() (we've come close on the x86 side several times). E.g. kvm_arch_vcpu_put() can simply check kvm_vcpu.scheduled_out if it needs to something specific for the vCPU being scheduled out. v2: - Add scheduled_out flag instead of passing a bool to kvm_arch_vcpu_load(). [Oliver] - Tack on patches to clean up x86's setting of l1tf_flush_l1d in kvm_arch_sched_load() (the code looked slightly less weird when the flag was being set by kvm_arch_sched_in()). v1: https://lore.kernel.org/all/20240430193157.419425-1-seanjc@google.com Sean Christopherson (6): KVM: Add a flag to track if a loaded vCPU is scheduled out KVM: VMX: Move PLE grow/shrink helpers above vmx_vcpu_load() KVM: x86: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load() KVM: Delete the now unused kvm_arch_sched_in() KVM: x86: Unconditionally set l1tf_flush_l1d during vCPU load KVM: x86: Drop now-superflous setting of l1tf_flush_l1d in vcpu_run() arch/arm64/include/asm/kvm_host.h | 1 - arch/loongarch/include/asm/kvm_host.h | 1 - arch/mips/include/asm/kvm_host.h | 1 - arch/powerpc/include/asm/kvm_host.h | 1 - arch/riscv/include/asm/kvm_host.h | 1 - arch/s390/include/asm/kvm_host.h | 1 - arch/x86/include/asm/kvm-x86-ops.h | 1 - arch/x86/include/asm/kvm_host.h | 2 - arch/x86/kvm/pmu.c | 6 +- arch/x86/kvm/svm/svm.c | 11 +--- arch/x86/kvm/vmx/main.c | 2 - arch/x86/kvm/vmx/vmx.c | 80 +++++++++++++-------------- arch/x86/kvm/vmx/x86_ops.h | 1 - arch/x86/kvm/x86.c | 22 +++----- include/linux/kvm_host.h | 3 +- virt/kvm/kvm_main.c | 5 +- 16 files changed, 59 insertions(+), 80 deletions(-) base-commit: 4aad0b1893a141f114ba40ed509066f3c9bc24b0 Acked-by: Kai Huang