Received: by 10.223.148.5 with SMTP id 5csp6139514wrq; Wed, 17 Jan 2018 09:55:01 -0800 (PST) X-Google-Smtp-Source: ACJfBou6aCysqJek3ynV+b+Ml/Kbz1mn9aU9rhvpLQnklNSwPItdZJtpc6Bgvf5GU6ExW2DDeYZC X-Received: by 10.159.246.135 with SMTP id c7mr36459298pls.138.1516211701014; Wed, 17 Jan 2018 09:55:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516211700; cv=none; d=google.com; s=arc-20160816; b=pAQrXQaF/tsOTnFJ6fd2Me7i1zs4cSZqs3Eu4l2DzSNpiR90UzzOaJCfLsOgd5gJHW SKKyBT6toy5W5dwbJ/0Ut12B+EQXCMU/w/2ZRg1ygRGXkvttpK9JIF/qw5sn+7p0ftK5 yIexyTVk81+37RY7OD/XcHP4HCuFC/BfQ9lE4mGYDIy/7GcegYuBaV5qhNdVmiKq5rnq AaAQbBRWRprvrdFvXxUaPJDdDQGoYrXjfehBhROxG3jeH/9IDa0/y+/OVU5CDvPbte9J NRBaz2psX8p+jWdc7Ui4f3h4cZHJIapVs1M1k6qwchiwYFysEZP+DzOPeI/kCvQXAfg8 JYLA== 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:arc-authentication-results; bh=htcFJyAKOjGiBFPbj3UJfm//JV74PSPGd9X4sOk0+Zk=; b=DlPLsrzkGgrlIGr2VDMyuet7wReo98tTMpGfcWeKaO9BV4tLdFbUCNDW1R6M0KUmZG FrommDC4GOEGO6E/Fh3Bb6+jsJpkkp//fq3wwtit0zHorJYACz0yHr3gHUwWRaZkRYlg S6gMgJIi0oQmPCe8+gtCd6GqYTlW7F1033xRvelEPoLMxqnEglhTkYr5QjNqY/Wqgexb j4FWndGidlrfo63MXbPpxWQ9iFDCuNY3QSDM/UQUmcxlD4RNeQcrdVa8kcxVqbW0EtqY NBOfkIG9Ia9G/Kr6kI6fBIiLvbhgXcsIZvfTZh88yYyoPDwr4oQ2wXuiwfgI4Y+M7Gyq Fo8A== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si4370064pgr.290.2018.01.17.09.54.46; Wed, 17 Jan 2018 09:55:00 -0800 (PST) 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754594AbeAQRyB (ORCPT + 99 others); Wed, 17 Jan 2018 12:54:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59578 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754291AbeAQRx7 (ORCPT ); Wed, 17 Jan 2018 12:53:59 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 035D525B8E; Wed, 17 Jan 2018 17:53:49 +0000 (UTC) Received: from [10.36.117.142] (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D5D05D964; Wed, 17 Jan 2018 17:53:39 +0000 (UTC) Subject: Re: [tip:x86/pti] x86/cpu/AMD: Use LFENCE_RDTSC instead of MFENCE_RDTSC To: Tom Lendacky , "Dr. David Alan Gilbert" , Andrew Cooper Cc: Thomas Gleixner , bp@alien8.de, dwmw@amazon.co.uk, gregkh@linux-foundation.org, pjt@google.com, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, tim.c.chen@linux.intel.com, torvalds@linux-foundation.org, peterz@infradead.org, Dave Hansen , Eduardo Habkost , "Sironi, Filippo" References: <20180105160756.23786.4220.stgit@tlendack-t1.amdoffice.net> <1b179b8b-6cc8-d736-81dc-2445be4baf02@citrix.com> <4d9a1f0d-a401-3f0f-9ee2-dd42f4b4716a@amd.com> <929a34a1-e3bc-b1c8-4c71-196610c0d02a@citrix.com> <20180108164803.GF2462@work-vm> <0be27b7e-7285-b23b-7eda-55a70338d16c@redhat.com> From: Paolo Bonzini Message-ID: Date: Wed, 17 Jan 2018 18:53:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 17 Jan 2018 17:53:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/01/2018 18:21, Tom Lendacky wrote: > On 1/8/2018 11:01 AM, Paolo Bonzini wrote: >> On 08/01/2018 17:48, Dr. David Alan Gilbert wrote: >>>> If your hypervisor is lying to you about the primary family, then all >>>> bets are off.  I don't expect there will be any production systems doing >>>> this. >>> It's not that an unusual thing to do on qemu/kvm - to specify the lowest >>> common denominator of the set of CPUs in your data centre (for any one >>> vendor); it does tend to get some weird combinations. >> >> Agreed. But on a hypervisor we pretty much know that: >> >> - the MSR_AMD64_DE_CFG doesn't exist unless you have a fix >> >> - setting the MSR_AMD64_DE_CFG bit to 1 if you have a fix can be done >> independent of the family >> >> So all KVM needs is a X86_FEATURE_LFENCE_SERIALIZE, it doesn't matter if >> it's because of the family or because Linux has set MSR_F10H_DE_CFG. >> The guest will either try setting the MSR bit and #GP, or it will find >> it already set and do nothing. >> >> Of course no code for this has been written yet. >> > > Hi Paolo, > > What would be the best way to approach the MSR support? I was thinking of > just recognizing a write to that MSR but not actually doing anything and, > on read, just returning a value with the single bit set if LFENCE is > serializing and not worrying about the full contents of the MSR. Or I > could save the value so that it could also be host initiated and only > allow the LFENCE serialization bit to be set if the LFENCE_RDTSC feature > is enabled. Yes, the latter is the correct one. We'll need changes in QEMU to add a new feature bit in "-cpu" too. The "-cpu" feature bit, if set, causes QEMU to set the bit in the MSR at CPU creation time. MSR-based features are not yet a thing in QEMU, but we were planning to add them before this whole kerfuffle started. But indeed we need to return also whether the feature is supported on the host, which would be similar to the first part (read-only, just returning a value with the single bit set is LFENCE is serializing). We would add KVM_GET_MSRS and KVM_GET_MSR_INDEX_LIST ioctls on the VM file descriptor for that, and a new capability KVM_CAP_GET_HOST_MSR (or KVM_CAP_GET_MSR_VM, you choose :)). QEMU can use these two ioctls to query the available MSR-based CPU features. These can include microcode version, VMX features, LFENCE serialization, IA32_ARCH_FACILITIES, etc. Thanks, Paolo