Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1470308rdb; Sat, 3 Feb 2024 07:30:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHI7v2LO7QEm1/M2kGP0/oC1o3gF0obQTYp6W43BjwobvLpL14d0/AQUBB1LMCZ0VqHE66q X-Received: by 2002:a05:6a00:4e4e:b0:6e0:334a:76a7 with SMTP id gu14-20020a056a004e4e00b006e0334a76a7mr418638pfb.19.1706974236316; Sat, 03 Feb 2024 07:30:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706974236; cv=pass; d=google.com; s=arc-20160816; b=ChVHFEmQS3tRJAvHhTVZUWcUs2hlho1wtFLKZ72nuo751UB3DGh/CGvWbgiQBVNnEQ 9sQFEHtlKdtluNAv5hxjijXZ+EhBL/JUTZed17W05s591tln39pS00aOFPfb190lW3JO 1y42qLlLHCJzaCUYmjNna+rhYr4HS4VR8u/k7hdd/jiJUdJAQ1+Ve0yxEvejMTeDLJBR YWIqlMQvLXy4lETfeAqFiJv2mrea/aKwf/byGHQH2Fgb5mZlixItxIlbB8cfEfXR83M2 b8Y/GPyorLRGBQpF1QVVKdneEAQN3cYvd4FoLMDmXMQ638c6qe7QWfHqMRVDMfk3JBmP i5jA== 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=Li/0q0VI979equ/qgcDDfuE0vcbFUnJUpiVQgFgU2uY=; fh=8vPfwz60UKK3f+QhKt3oZNj6JuGaOni+ExfnE7f4e0s=; b=OnepkCpzuCB8vrxpIco+PqctRbK+ZKgeE11KTycXKJGeJHt02ovGMpfGvnnzbK64ZX p1kjgQPUBMkTnbJ6K7zE4yb2pjlMowvrLrHAXYTnObxprRnCxmHVPn0btbgC4/bh29Oh rCEpl6Uz562IHMxSjr6xl4gPQQ5KfYAkvi73eA+gvEuvA2II9ubow/vlWrU6T2/HaH/r p25cMw2Y8GtJ4hfc+BvWOjzyWjHKa0adWVynbkAXsAPOTIJ/VYa7OqnNn2GFeN9rnqm2 IlnawG8hfEi8YGugEb24UuV4cNukQTt6eOPF19Kln4ZwGXHTZISBOsatGko2OpWgud7W 74nw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kJh6d7hv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-50983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50983-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; AJvYcCXMxVVvuprSFKxYwqMfZy6Wp/38crEjv372UxZey0TFlkZNDdJBNqJfUfzJ7Jj44W+4tNH3IOdO+j8is5hKVxN4dFnv+B1LpZJ4eewbvQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ln7-20020a056a003cc700b006dd89875061si3370775pfb.388.2024.02.03.07.30.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 07:30:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kJh6d7hv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-50983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50983-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 02914B26402 for ; Sat, 3 Feb 2024 09:01:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 632695D739; Sat, 3 Feb 2024 09:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kJh6d7hv" 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 E2D7E5C61F; Sat, 3 Feb 2024 09:00:27 +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=1706950829; cv=none; b=WV9LJdm+Byfpc7XIRQJjZle0XtYGTyrLvEvzAm37+dnSG4gU3NCuIxvcLTiwkktY9Vm/5bWe0Uc+gexQg7XEKgeiW3oGQk6PWWRpXJtPMNhyO8UfdRvIgrskdD/uEW+A1EGkSbd0LijAX29Xa9YRbJYPDlgz/EhLRyAtLxKZ7TU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706950829; c=relaxed/simple; bh=SCjjaAWB7G5busdQtgw95kBzyDRKHqtVEz1Bv3Q2lXo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qC0ybgDqc6+0ucFY0DJtTvRlLGxheCAbWlh10XWYUaYpJXIO1MoDeonMAADHCJexyjqLrAAhbypU/tDW/Q5q2yrLKJka7Prz6T+L3xvTOiqmWqGSZ04lT6ErQcAVH+qc9h5jBV0ZAq88h5wmUTqiNBp6snyn12ZWoxg0rhSxN1w= 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=kJh6d7hv; 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=1706950828; x=1738486828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SCjjaAWB7G5busdQtgw95kBzyDRKHqtVEz1Bv3Q2lXo=; b=kJh6d7hv6OGZ80CVV+AFZZcrJ/XlBPL7M38Z1rj8bYO4bj5FRjjCQFRE OPxmDuCxCDUt7/BWpaJt0NocHZ27wKTdXGfNZ/LPcBizK87UXkBKs52gy MSG03aLL0plHfAvJF4KnEsEigtDB3WWmzKo0LDVsXpAL5qax2LdtV14JZ vMSM/+zUsi3/sWoMaYeWuuiC2aHgLt2V+eoQxO8kDR8BBXT1hc9AiekQq 9E+PVq6Kp9XHNEAGjxI62QHedLrqv7fZffQXNCWyRN4kRAsm5mSSCbozD bOSyTuyHf/0q5ItWyivr7hEPHfp6jy61sz+5bAWjhEUronu/v55NqnzDt Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="4131903" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="4131903" 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:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="291244" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa009.fm.intel.com with ESMTP; 03 Feb 2024 01:00:09 -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 05/26] KVM: x86: Reset hardware history at vCPU's sched_in/out Date: Sat, 3 Feb 2024 17:11:53 +0800 Message-Id: <20240203091214.411862-6-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 Reset the classification history of the vCPU thread when it's scheduled in and scheduled out. Hardware will start the classification of the vCPU thread from scratch. This helps protect Host/VM history information from leaking Host history to VMs or leaking VM history to sibling VMs. Tested-by: Yanting Jiang Signed-off-by: Zhao Liu --- arch/x86/include/asm/kvm_host.h | 2 -- arch/x86/kvm/x86.c | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 2be78549bec8..b5b2d0fde579 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2280,8 +2280,6 @@ 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/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 363b1c080205..cd9a7251c768 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -79,6 +79,7 @@ #include #include #include +#include #include #include #include @@ -12491,9 +12492,16 @@ void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) pmu->need_cleanup = true; kvm_make_request(KVM_REQ_PMU, vcpu); } + + reset_hardware_history(); static_call(kvm_x86_sched_in)(vcpu, cpu); } +void kvm_arch_sched_out(struct kvm_vcpu *vcpu) +{ + reset_hardware_history(); +} + void kvm_arch_free_vm(struct kvm *kvm) { #if IS_ENABLED(CONFIG_HYPERV) -- 2.34.1