Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3225512ybi; Mon, 17 Jun 2019 19:41:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxs95GbZD/ge1sY+LB7V0DCJ6Fj3EGvXZ4AsuA9Qo22ek2wKWk5TA7xq9aBizwvty+eznA X-Received: by 2002:a17:90a:cb97:: with SMTP id a23mr2448477pju.67.1560825666774; Mon, 17 Jun 2019 19:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560825666; cv=none; d=google.com; s=arc-20160816; b=gAB5+SgPZel4JWIKhCKJZg4osN2eWu8qjelQy6Z3fQkdcgKNenXm8V1KFvu0qyG/fN anDnydtFLuqh+Yqxjx2DZVEKAZto5yhrBqvjc79Wl1Drv57FDFGg/17TvO0VDalTSUpe DHWMP1Tr9GfuoDL/vt68HhvsM+KeH6x0Cv+NjBr5MWQaSX0xqqJh+Ua6txcpr5R16lLx TGCgodNAb6q0R4BEltlKTz8D0De6hw0joukklkp5m8TUKEHfDDDTkm59kMRof1UlwrD0 vKG2PfQweB9lNCXUX5PBLGcOwraLY59/HPB2108KKNCGrI6DhFuQy4Q7AS1+jp3matwi tG5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=G85u6myseYI31kMh+MkYebqQ8RXCnaBpNS2Y5jkag98=; b=BigrHZ181Xf5OsE1zOKXjA1EYPmFu0ihYeRCF/pJiCk6km/9dQ/4PhdxxPPqmsuMEv iC2CUt6vKTmQ2xoq2deDYRmf82d03TqjFaEJhVI6T7wHTlUyG5JQsh0jkmlkmItemiSI J/nfFPdXr9RyA07AlHEBSzZHLaxvFLEIgIxNViMdOQI8bhe/YEdHCmiVytVMscJhdYbI rysVEBvKo7ibOJaEIe+C1lHxrvPLOlBzs8pt9QjXlwtMatla9QWHQJl1+Pz+Vlu7ZVQ5 WYb2oUsulSno7R6K1HYSoMkKLl6bPCyrJynz3l+6CZsk3JUtigP4kf7b0EBkD7dGPzU+ y73w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si1001430pjc.42.2019.06.17.19.40.50; Mon, 17 Jun 2019 19:41:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfFRCkX (ORCPT + 99 others); Mon, 17 Jun 2019 22:40:23 -0400 Received: from mga14.intel.com ([192.55.52.115]:46433 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725829AbfFRCkX (ORCPT ); Mon, 17 Jun 2019 22:40:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jun 2019 19:40:22 -0700 X-ExtLoop1: 1 Received: from txu2-mobl.ccr.corp.intel.com (HELO [10.239.196.224]) ([10.239.196.224]) by orsmga003.jf.intel.com with ESMTP; 17 Jun 2019 19:40:19 -0700 Subject: Re: [PATCH RESEND v3 2/3] KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Xiaoyao Li Cc: pbonzini@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sean.j.christopherson@intel.com, fenghua.yu@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, jingqi.liu@intel.com References: <20190616095555.20978-1-tao3.xu@intel.com> <20190616095555.20978-3-tao3.xu@intel.com> <20190617155038.GA13955@flask> From: Tao Xu Message-ID: Date: Tue, 18 Jun 2019 10:40:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20190617155038.GA13955@flask> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/17/2019 11:50 PM, Radim Krčmář wrote: > 2019-06-17 14:31+0800, Xiaoyao Li: >> On 6/17/2019 11:32 AM, Xiaoyao Li wrote: >>> On 6/16/2019 5:55 PM, Tao Xu wrote: >>>> +    if (vmx->msr_ia32_umwait_control != host_umwait_control) >>>> +        add_atomic_switch_msr(vmx, MSR_IA32_UMWAIT_CONTROL, >>>> +                      vmx->msr_ia32_umwait_control, >>>> +                      host_umwait_control, false); >>> >>> The bit 1 is reserved, at least, we need to do below to ensure not >>> modifying the reserved bit: >>> >>>     guest_val = (vmx->msr_ia32_umwait_control & ~BIT_ULL(1)) | >>>             (host_val & BIT_ULL(1)) >>> >> >> I find a better solution to ensure reserved bit 1 not being modified in >> vmx_set_msr() as below: >> >> if((data ^ umwait_control_cached) & BIT_ULL(1)) >> return 1; > > We could just be checking > > if (data & BIT_ULL(1)) > > because the guest cannot change its visible reserved value and KVM > currently initializes the value to 0. > > The arch/x86/kernel/cpu/umwait.c series assumes that the reserved bit > is 0 (hopefully deliberately) and I would do the same in KVM as it > simplifies the logic. (We don't have to even think about migrations > between machines with a different reserved value and making it play > nicely with possible future implementations of that bit.) > > Thanks. > Thank you Radim and xiaoyao's review, I will improve it in the next version. Xiaoyao's suggestion remind me another thing. And I am wondering if we need to initialize the value of MSR_IA32_UMWAIT_CONTROL in KVM to 0x186a0(umwait_control = 100000, as host does). Although the guest with new kernel(has umwait host patch)can initialize the value to 0x186a0. But there is a case that a guest with a old kernel and the host with the new kernel and has the cpuid of WAITPKG. Because the msr value is 0, the guest umwait will have no max time by default.