Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1229904ybt; Tue, 7 Jul 2020 10:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFY89m1fTtOEJgE9XMJzEN3b1kDuxw8r1LrUWPKl2MSH8jdYL9UOrbS1REu59JKwEIxxHZ X-Received: by 2002:a50:8a62:: with SMTP id i89mr48876757edi.324.1594143041306; Tue, 07 Jul 2020 10:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594143041; cv=none; d=google.com; s=arc-20160816; b=DfOeS0ILUHvvPymmwORcAWyxZeP7TZHNmZeOVLH5S1+rhe0/tBMp7W8y1cx02SLuhl Aqkz45RK/O8fKmFTGQSQQUcbDq1zIqylyK/Hd1gykoZ3k5Qxrtg+V6A1xjP3QHWjfW9x D1K2pYynbec8QVGQOz8gS19YxdYZU9u/GkhIXzK/PKdsvBKZR9/J7wd0COpWXvngCW9U LCBgEBeSmcBPUAqFjUw/U+Iy/qaqwyJ9jjM5hlMd1zbikNbdbvuWDjAW9xKnWQVCQxeC lDYkJaL9juQyyFdkwvGSJy0eOmunB+Nl6uKAcjJch+dgdmLYanU8GhKMVYbbMLNSvdHN SiRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=JFu+J3f3YvitPW2qOTGdlUSKLvLJmDbemGT0ZC+HJr4=; b=sJxGtzuekZam4dJj7MQjoTOPhML8tXlo9gdpV+Ng2EBFjgrMZt7L5/YYVY67Xnm8M1 18ZKom/buXy1ej6XWxp6iFYwdkDcb6KObTKg/0QwAzM8amrJ+Fq904x0vTubsA8dm+6u p2NQB8rFhQ/PNM4yViHDoajxvbPCUb1vfJYO2JKUu9zV309CDZ0J4iFifoMJskWWJJKL tQDyOq+mV7JBSVRbGRwPkRSGUOkIhsy2sM32aGRz8Lp3kFpAliGpQwgDvhVwFam9z9gm h2oIRa193w0sjkgguNmx5W/2ZSaG3xZ0XVw1NHK5wW+Ld1IzkTcn43l1kjom2rAzVpxH Ksnw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf2si15419048edb.288.2020.07.07.10.30.18; Tue, 07 Jul 2020 10:30:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728379AbgGGR11 (ORCPT + 99 others); Tue, 7 Jul 2020 13:27:27 -0400 Received: from mga03.intel.com ([134.134.136.65]:2939 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbgGGR11 (ORCPT ); Tue, 7 Jul 2020 13:27:27 -0400 IronPort-SDR: qhnS5c1ONGiJOGylm2vtij2cjGXL+p3F0SvjeTm6tiE4hrD40d1MP3yNGKz566m06IUcgT3t8x fqsn7VYeNZ2g== X-IronPort-AV: E=McAfee;i="6000,8403,9675"; a="147670617" X-IronPort-AV: E=Sophos;i="5.75,324,1589266800"; d="scan'208";a="147670617" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jul 2020 10:27:26 -0700 IronPort-SDR: OuSpcUAd08hrIa2H9NtKNPS4/LExb711TfIFjx7oAafmvSZKAjzi8BNErBNl2KdZM2gFQdFVkE 1cE4KKPqAWQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,324,1589266800"; d="scan'208";a="268257264" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by fmsmga008.fm.intel.com with ESMTP; 07 Jul 2020 10:27:25 -0700 Date: Tue, 7 Jul 2020 10:27:25 -0700 From: Sean Christopherson To: Maxim Levitsky Cc: Paolo Bonzini , kvm@vger.kernel.org, "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , linux-kernel@vger.kernel.org, Joerg Roedel , Thomas Gleixner , Wanpeng Li , "H. Peter Anvin" , Borislav Petkov , Vitaly Kuznetsov , Ingo Molnar , Jim Mattson Subject: Re: [PATCH] kvm: x86: rewrite kvm_spec_ctrl_valid_bits Message-ID: <20200707172725.GH20096@linux.intel.com> References: <20200702174455.282252-1-mlevitsk@redhat.com> <20200702181606.GF3575@linux.intel.com> <3793ae0da76fe00036ed0205b5ad8f1653f58ef2.camel@redhat.com> <20200707061105.GH5208@linux.intel.com> <7c1d9bbe-5f59-5b86-01e9-43c929b24218@redhat.com> <20200707081444.GA7417@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 07, 2020 at 02:35:59PM +0300, Maxim Levitsky wrote: > On Tue, 2020-07-07 at 01:14 -0700, Sean Christopherson wrote: > > Aren't you supposed to be on vacation? :-) > > > > On Tue, Jul 07, 2020 at 10:04:22AM +0200, Paolo Bonzini wrote: > > > On 07/07/20 08:11, Sean Christopherson wrote: > > > > One oddity with this whole thing is that by passing through the MSR, KVM is > > > > allowing the guest to write bits it doesn't know about, which is definitely > > > > not normal. It also means the guest could write bits that the host VMM > > > > can't. > > > > > > That's true. However, the main purpose of the kvm_spec_ctrl_valid_bits > > > check is to ensure that host-initiated writes are valid; this way, you > > > don't get a #GP on the next vmentry's WRMSR to MSR_IA32_SPEC_CTRL. > > > Checking the guest CPUID bit is not even necessary. > > > > Right, what I'm saying is that rather than try and decipher specs to > > determine what bits are supported, just throw the value at hardware and > > go from there. That's effectively what we end up doing for the guest writes > > anyways. > > > > Actually, the current behavior will break migration if there are ever legal > > bits that KVM doesn't recognize, e.g. guest writes a value that KVM doesn't > > allow and then migration fails when the destination tries to stuff the value > > into KVM. > > After thinking about this, I am thinking that we should apply similiar logic > as done with the 'cpu-pm' related features. > This way the user can choose between passing through the IA32_SPEC_CTRL, > (and in this case, we can since the user choose it, pass it right away, and thus > avoid using kvm_spec_ctrl_valid_bits completely), and between correctness, > in which case we can always emulate this msr, and therefore check all the bits, > both regard to guest and host supported values. > Does this makes sense, or do you think that this is overkill? It doesn't really work because the host doesn't have a priori knowledge of whether or not the guest will use IA32_SPEC_CTRL. For PM stuff, there's no meaningful overhead in exposing capabilities and the features more or less ubiquitous, i.e. odds are very good the guest will use the exposed features and there's no penalty if it doesn't.