Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1312798rdb; Sat, 3 Feb 2024 01:01:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IERMH9a4y8fLvrzNnpvUrS4G72sfoou2JNFEZufa1kR6QxUsdmFKQ9CfpCu3bxFwLK+8wpm X-Received: by 2002:a17:906:5399:b0:a36:fc15:c6b2 with SMTP id g25-20020a170906539900b00a36fc15c6b2mr2338756ejo.35.1706950889957; Sat, 03 Feb 2024 01:01:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706950889; cv=pass; d=google.com; s=arc-20160816; b=BUFHfpUWX9k+TpEFNAQTgUm/xd5crQMbGqtqfTCOvehnhbgIUM87lftnbAiaUqUKyc /GecElmJxtv6/pqZb58rS74MFagWWxhOgMqp5eOi/yA6dwWdVKXxnNuFGeGZ0kEE87rv Spb8+OysJ0F5bRWRy9P66n2rodXGEe7pulDNSta8Nfj0Rg7OAAkCth7cj/5B7dOhLykK x4qo0+yLHFdQOEXq9TgXGlfSPQk0W5rtkmCBTM/39ak/Q1CV4TJd/P3A2M1umfiKi6Ma ery30zTGf8hi5tUklvaPN59RQOGt2maFjZMcrtXvdiqgmeXAbFzIqzx3PLu178Q4rEZt 3fUQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=AvEy5E8sH19O0VVYqDlfbmx41XWTYS0P1Uygge6JKg8=; fh=GRR0fjN2z7TCFV0tlOe8NjMTqIrqI9z/VU3KuWCn0vU=; b=LZNkoBeeFGkX6ltvy0W438NEegN3MxgxdPCBSHun3pnxQkrkNrntMvL2eXRHw25OQI YA4mXiQRThJGN81fUKshgZls7pVFhnUhnL75tDp7Dkvt+GWYi71zWY3Po8gxB3syfbdu BTAYU8Fg3TR3egCKoUQ+lZiw/yC6lRUtN62WetCE7eWxU+p8MLsXeEmK8LH0cHG/W21N 4RrxYODoTH3me1Epn3n/9wHN6mZtUzpuZm8bDarw3XabQYqtLttwXf2ThCQuPoC+3OLS lx3RoZMhZbIQ7tQC0H8wucclA6yQhwP7rXapv5SVPYUswB65jdYY2Zc9CWK/FpIFWq3U 3JqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZVUA9QAv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-50982-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50982-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVBRmczXUjW0Omr7bF4X510w/DtqajH28CQnFpqyWtvamL+waqKGZ+doe3ewzKiXo9y+1roMcnjdlyG6Yv0bQYGGsnv9YPowPgoeq3I5A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gt18-20020a170906f21200b00a35fd4bc26asi1673914ejb.619.2024.02.03.01.01.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 01:01:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50982-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZVUA9QAv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-50982-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50982-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8B24C1F237AF for ; Sat, 3 Feb 2024 09:01:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5FEE5DF03; Sat, 3 Feb 2024 09:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZVUA9QAv" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 530CA5C91F; Sat, 3 Feb 2024 09:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706950814; cv=none; b=k7YaobqxS5fj5lHwqksuHmf9KhLDCBkzU4Mrge1Mj1HXJ+855VbIyNhpSJ0LE4DWdoxXRk6PIHEt655xgPE8DWV1gMyZlJLhTmcX741XeQ9JO//WGJOu7K5unMiBMXpYeaORKxvfSdVf2NPc2D29GyqjTn6L0bY/83lrGy5MEBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706950814; c=relaxed/simple; bh=HuU52pRVoiXsEnoBJbVxkcXWDiT120gC151O8BbGlew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rUGfB04SflGKtCniRFMsQdHLCjrx1XSxsowzGdfP2tMnKw9RhHL/9oYWafhgihemXd75UmFFCzgeg9+AM7CpvpyXLun7eYblJH6Q0dMd0VMVBF6h7kGLeXhGxxStKSeCE+/lHWKFmfV7BNN2VJYUI6g78/JTkTf3l619wZFHbqM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZVUA9QAv; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706950814; x=1738486814; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HuU52pRVoiXsEnoBJbVxkcXWDiT120gC151O8BbGlew=; b=ZVUA9QAvzO2U1DvNdzfCOPCALYqV1C41Vxr8e6H2wYVlWw5ZMI3OJnre uyVDm1f7tgUh2s6g/MmLzDtTeygKF+1SU6AuMovo44bI2e2kB+oycRmHL Cf0GDbxUocfAcBZJ2c36qdRuXTeQGUU1eHlFs67A2aF1uXW9EHhWOOcxa yU5RW3zSbGDMxc2Z2wDJW9Rd+TVTxFeL1LI537bqH77rxLeUnKSqc9hgo 9uFR0sqLEtg3IdjWKXRHXu9SKHYmXS0RjxG7zkcwPJEGfhzpyFRbgL9wT xKIGWwuyDpK81FTEykMWhXhgITbXsgIUlu0rsI1d5p1tGDF/bsIXnyQTv A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="4131886" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="4131886" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:00:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="291240" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa009.fm.intel.com with ESMTP; 03 Feb 2024 01:00:02 -0800 From: Zhao Liu To: Paolo Bonzini , Sean Christopherson , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , kvm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ricardo Neri , Len Brown , Zhang Rui , Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Vineeth Pillai , Suleiman Souhlal , Masami Hiramatsu , David Dai , Saravana Kannan , Zhao Liu Subject: [RFC 04/26] KVM: Add kvm_arch_sched_out() hook Date: Sat, 3 Feb 2024 17:11:52 +0800 Message-Id: <20240203091214.411862-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203091214.411862-1-zhao1.liu@linux.intel.com> References: <20240203091214.411862-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zhao Liu x86 needs to reset classification history when vCPU is scheduled out. Add the kvm_arch_sched_out() hook to allow x86 implements its own history reset logic at sched_out. Tested-by: Yanting Jiang Signed-off-by: Zhao Liu --- arch/arm64/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_host.h | 2 ++ include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 1 + 8 files changed, 9 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 21c57b812569..a7898fceb761 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1127,6 +1127,7 @@ static inline bool kvm_system_needs_idmapped_vectors(void) static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +static inline void kvm_arch_sched_out(struct kvm_vcpu *vcpu) {} void kvm_arm_init_debug(void); void kvm_arm_vcpu_init_debug(struct kvm_vcpu *vcpu); diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h index 179f320cc231..2bcd462db11a 100644 --- a/arch/mips/include/asm/kvm_host.h +++ b/arch/mips/include/asm/kvm_host.h @@ -891,6 +891,7 @@ static inline void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +static inline void kvm_arch_sched_out(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 8abac532146e..96bcf62439b2 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -898,6 +898,7 @@ static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +static inline void kvm_arch_sched_out(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 484d04a92fa6..a395a366f034 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -273,6 +273,7 @@ struct kvm_vcpu_arch { static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +static inline void kvm_arch_sched_out(struct kvm_vcpu *vcpu) {} #define KVM_RISCV_GSTAGE_TLB_MIN_ORDER 12 diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index 52664105a473..6e03188d11b0 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -1045,6 +1045,7 @@ extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc); static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} +static inline void kvm_arch_sched_out(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index b5b2d0fde579..2be78549bec8 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2280,6 +2280,8 @@ static inline int kvm_cpu_get_apicid(int mps_cpu) int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages); +static inline void kvm_arch_sched_out(struct kvm_vcpu *vcpu) {} + #define KVM_CLOCK_VALID_FLAGS \ (KVM_CLOCK_TSC_STABLE | KVM_CLOCK_REALTIME | KVM_CLOCK_HOST_TSC) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 7e7fd25b09b3..3aabd3813de0 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1478,6 +1478,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu); +void kvm_arch_sched_out(struct kvm_vcpu *vcpu); void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu); void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 10bfc88a69f7..671f88dff006 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -6317,6 +6317,7 @@ static void kvm_sched_out(struct preempt_notifier *pn, WRITE_ONCE(vcpu->ready, true); } kvm_arch_vcpu_put(vcpu); + kvm_arch_sched_out(vcpu); __this_cpu_write(kvm_running_vcpu, NULL); } -- 2.34.1