From patchwork Thu Nov 9 02:02:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 10049993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89659602D7 for ; Thu, 9 Nov 2017 02:03:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A5672A863 for ; Thu, 9 Nov 2017 02:03:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EFF52A865; Thu, 9 Nov 2017 02:03:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 283652A866 for ; Thu, 9 Nov 2017 02:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbdKICCW (ORCPT ); Wed, 8 Nov 2017 21:02:22 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:54546 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751352AbdKICCU (ORCPT ); Wed, 8 Nov 2017 21:02:20 -0500 Received: by mail-pf0-f193.google.com with SMTP id n89so3138942pfk.11; Wed, 08 Nov 2017 18:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=so10zxbWGu5PJYmEGRl0bEkYF+as7pSGKGskvTd0KsM=; b=Y6A7X9E/2yXGxh7liHZAQVX7M8W7umaeJySvC7nGagTvrMRfp+NBiL1rNgDa228cuA p2LAEIH4UPVRWgYMSCih2VGtRQ1PiQhD0yceH84h0MN22cU5DouiSERu+BNRWdJCObOR 1NM14wM5AIvzpX3+MYHnFJkEj+GBZK6Msw7C67+63MHnVoJ75wPrx02feCTVVX71NaFn 7r8xAkG4mGm9vSccqVQbb2yigLTgid1xNxGJ5XtKauUZhBTnT4YeEEzjdFV31K3yyRWR HZRcX+YG9XfW7qhk2+CT9TFiVvDn5A1MHlERvbKoK3ty/Xu5Q8cHQsBddPfv77dP0sUU gJVg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=so10zxbWGu5PJYmEGRl0bEkYF+as7pSGKGskvTd0KsM=; b=baA3aiic4ehjQQHPa2k98ep86+T9mnzAFLfTly4r/nAYNfuSX05KryI35p7W3Qp5mL Yfl3JpifR8QDcaGVGrB3ik7o+cfx9R1Zo+BKcAOKRVA0TVw+Yxho+H+J1BofJHzPI73P upbUB5WZRxzQT5gpACDIiBnQ3UvN10xQglTORyIVAAHZVUv6whGrPYFzQFc6VjzUyt2e ndSN58j07KYqqdtAIFR8O1nDbXP1IJigBXRNGisbQs/SC9G5IgC5LQqgYPuHa1AwNSvS vNOcAQpcNg2H0x/smEqyUYoTKbmYPwZz3Ndgr/cHOGgdMa/e3gZ6RTxAkqtrHPixMe/v sjyg== X-Gm-Message-State: AJaThX6HIqMSu8MA070Jc1FVPVNfMEQXFvWjW785ICUb9qhdpHV6V+lz mtyfoUDGptaXlMCSIqB5sBkZBA== X-Google-Smtp-Source: ABhQp+TmYurYuQcfMtwq0uCgz+FuoeLfJeDYlWhh2hvGBIYtEg3uNcyAc4kYpP71lzvwV7ulUfgmzQ== X-Received: by 10.99.180.3 with SMTP id s3mr2256035pgf.174.1510192939473; Wed, 08 Nov 2017 18:02:19 -0800 (PST) Received: from localhost ([203.205.141.123]) by smtp.gmail.com with ESMTPSA id r64sm10187999pfg.25.2017.11.08.18.02.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 18:02:18 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li Subject: [PATCH RESEND 1/3] KVM: Add vCPU running/preempted state Date: Wed, 8 Nov 2017 18:02:12 -0800 Message-Id: <1510192934-5369-2-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510192934-5369-1-git-send-email-wanpeng.li@hotmail.com> References: <1510192934-5369-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li This patch reuses the preempted field in kvm_steal_time, and will export the vcpu running/pre-empted information to the guest from host. This will enable guest to intelligently send ipi to running vcpus and set flag for pre-empted vcpus. This will prevent waiting for vcpus that are not running. Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- arch/x86/include/uapi/asm/kvm_para.h | 3 +++ arch/x86/kernel/kvm.c | 2 +- arch/x86/kvm/x86.c | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index a965e5b0..ff23ce9 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -50,6 +50,9 @@ struct kvm_steal_time { __u32 pad[11]; }; +#define KVM_VCPU_NOT_PREEMPTED (0 << 0) +#define KVM_VCPU_PREEMPTED (1 << 0) + #define KVM_CLOCK_PAIRING_WALLCLOCK 0 struct kvm_clock_pairing { __s64 sec; diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 8bb9594..1b1b641 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -608,7 +608,7 @@ __visible bool __kvm_vcpu_is_preempted(long cpu) { struct kvm_steal_time *src = &per_cpu(steal_time, cpu); - return !!src->preempted; + return !!(src->preempted & KVM_VCPU_PREEMPTED); } PV_CALLEE_SAVE_REGS_THUNK(__kvm_vcpu_is_preempted); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d2507c6..1ea28a2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2116,7 +2116,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu) &vcpu->arch.st.steal, sizeof(struct kvm_steal_time)))) return; - vcpu->arch.st.steal.preempted = 0; + vcpu->arch.st.steal.preempted = KVM_VCPU_NOT_PREEMPTED; if (vcpu->arch.st.steal.version & 1) vcpu->arch.st.steal.version += 1; /* first time write, random junk */ @@ -2887,7 +2887,7 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu) if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) return; - vcpu->arch.st.steal.preempted = 1; + vcpu->arch.st.steal.preempted = KVM_VCPU_PREEMPTED; kvm_write_guest_offset_cached(vcpu->kvm, &vcpu->arch.st.stime, &vcpu->arch.st.steal.preempted,