Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp118624pxj; Thu, 27 May 2021 23:12:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf9xwKDkehQ/iVh+EghGF3r50jKgPhzEWrqwJiLePhlQa+yWmLMLGT/e+voMnjjeYb+9XG X-Received: by 2002:a17:907:72d5:: with SMTP id du21mr5646518ejc.375.1622182328652; Thu, 27 May 2021 23:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622182328; cv=none; d=google.com; s=arc-20160816; b=A2D8KfbBnim5gow1h4aY1XHiyRS6HPaTwx70clYgUTj0x9btdpKD4ChNMhrzXs6TNu aa3RJNsEfLY6n1Yyns+W0UWiJktf59Pp/2sNrA6x2lBMlSQ4TcLzCDoaG4eRFlZiRtXS xXkzxY2fE1uubxJP9OxQo3NCE7kBTEszJ11zPVqyu8lGf8pXXare3H9E1e3mURrMeU0E F1817nMaG4JLOQjDJmL2IYK+mKhRsLD3LiiTNryuz1ydoWXt81KLsi/iuvJiCfXcGrEr /SbU0kWh8FJuavusxlj68VyHDu+8eAAByuDA+S1tZPcToz1HJ/We380GsqCYGKbFo9Sy uN/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pLn+gpBLNZeIF0DTenRXeN54nn8tAxDvBLhOSpC0WxA=; b=LnS5DMVw4anlUtE8ucsItFJzToNjl8RFkFXxJeSf337S3ZiJMRGopvta0Qp6CKeM4S IjnL9lh4/H38BYB/ZiImbegzJt5WNciTo7jvMP+Vqtk8VD/pz8vnEoHD28TMoc4m2lYx 2nB0m+noNa9zn6VkaxtwH8vrv9UnDijEWZrvgCz7UdwCzncU3jQKYO5+8nj8hgLgK1w/ V+1EzaEgms2mYUwRZYo2IqX9tFOde1yKnJyuViI+kAdu1XBBqPwz8oVDNHbnFrhM2AEg ab3ZpHjZwo8x8PxABYWDrrhxx0slow8itgEWaKB6hWSR9hp8w9fSW2iz3kObFu7vBc+f ZFcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c+HPOkTL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zo10si1010658ejb.241.2021.05.27.23.11.45; Thu, 27 May 2021 23:12:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c+HPOkTL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236325AbhE1DUp (ORCPT + 99 others); Thu, 27 May 2021 23:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236023AbhE1DUp (ORCPT ); Thu, 27 May 2021 23:20:45 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFDFC061574; Thu, 27 May 2021 20:19:11 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id c12so2197278pfl.3; Thu, 27 May 2021 20:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pLn+gpBLNZeIF0DTenRXeN54nn8tAxDvBLhOSpC0WxA=; b=c+HPOkTLlzbK6BU49rtrU41ZshgOYSDdabzouPmvfzwfQ0OOuTbTYWHT2tOg6KnU8H ORYbt+dJIIg+hvqAwM/wOsiO2suNUGJTF6X1YHUFjcDAOlQwZH/t4yJGJlpoHguQTLSK zQoLInsS6hTCGEMax1KTg7/WAtXhlnYFrl5u+C5m/+e1mE1P79C4zucfQouUKWEXHOUE vTAyeMTSHjWYQbXg+JipabTjYmltQIncojKIdP08K7qmzcaweQ8nUuZCPLwrkJ1ADTmW poDStNenHgVFOs+F+cdFQeZk9Bu8d+EZz/NH5DkCer/JiYjr6QOfriTzRtdoXZECp1Sx ggVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pLn+gpBLNZeIF0DTenRXeN54nn8tAxDvBLhOSpC0WxA=; b=PxYClqRblhte7bWlVVw05uIu7zJ7Bw27UbXtY6Tt8lC6zv5GkByJXPNR4WkkoYO5Qe f1jPQPDzCelsEL1yRQzEumW0y+tIX50mIOy9pN8rUI14s5MFtjPU68gY6yxzC6i9idpC W4MqeVOAL9mZCi4Us9t1wsVTreAdcA1BhDg+JlzTslGiFThdGpXgmtxc2oly3vUDfISp Dzvyd5ts1fSsxz01LQpHAbQXye2sBgOtUj8uJVtkrQ4kNAOGSTvZisVMhbg0nO3eP70i pu+oS7ljTXnj3Da+OClYWZX1UwTgUTHq9fT+FqXm3eNQTpJQkdBidy9bY9VV1Wkm3gQy wgAg== X-Gm-Message-State: AOAM532D2UZK6TqErnkY9ViFuGCneqwkZigTikair8gPGq1aA93m5jTw WkqMs9AQfbUeckc9O8fsBmTN9pbfbRY= X-Received: by 2002:a62:3344:0:b029:28c:6f0f:cb90 with SMTP id z65-20020a6233440000b029028c6f0fcb90mr1641818pfz.58.1622171950615; Thu, 27 May 2021 20:19:10 -0700 (PDT) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id u22sm3024766pfl.118.2021.05.27.20.19.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 May 2021 20:19:10 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Oliver Upton , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Peter Shier , kvm@vger.kernel.org Subject: [PATCH] KVM: X86: always reset st->preempted in record_steal_time() Date: Fri, 28 May 2021 01:33:58 +0800 Message-Id: <20210527173358.49427-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lai Jiangshan st->preempted needs to be reset in record_steal_time() to clear the KVM_VCPU_PREEMPTED bit. But the commit 66570e966dd9 ("kvm: x86: only provide PV features if enabled in guest's CPUID") made it cleared conditionally and KVM_VCPU_PREEMPTED might not be cleared when entering into the guest. Also make st->preempted be only read once, so that trace_kvm_pv_tlb_flush() and kvm_vcpu_flush_tlb_guest() is consistent with same value of st->preempted. Cc: Oliver Upton Fixes: 66570e966dd9 ("kvm: x86: only provide PV features if enabled in guest's CPUID") Signed-off-by: Lai Jiangshan --- arch/x86/kvm/x86.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bbc4e04e67ad..b8a7259ebd14 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3101,10 +3101,14 @@ static void record_steal_time(struct kvm_vcpu *vcpu) * expensive IPIs. */ if (guest_pv_has(vcpu, KVM_FEATURE_PV_TLB_FLUSH)) { + u8 st_preempted = xchg(&st->preempted, 0); + trace_kvm_pv_tlb_flush(vcpu->vcpu_id, - st->preempted & KVM_VCPU_FLUSH_TLB); - if (xchg(&st->preempted, 0) & KVM_VCPU_FLUSH_TLB) + st_preempted & KVM_VCPU_FLUSH_TLB); + if (st_preempted & KVM_VCPU_FLUSH_TLB) kvm_vcpu_flush_tlb_guest(vcpu); + } else { + st->preempted = 0; } vcpu->arch.st.preempted = 0; -- 2.19.1.6.gb485710b