Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3480533pxj; Tue, 11 May 2021 05:35:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqkgCjDzL/lNkZAZzI9E6iwDJJOzD8W3xLuv8XmDMUvDyMccjVGCfR8U7v5mWUUmVUpXt5 X-Received: by 2002:a92:c746:: with SMTP id y6mr26719136ilp.30.1620736542295; Tue, 11 May 2021 05:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620736542; cv=none; d=google.com; s=arc-20160816; b=VKCiRuUILmMH5d54Uiw6on9mIXsKS/wgr8h5BV0DZp0Epd+MRt0jmXssAqdpTMFLRe vCf1Olf6HhUcCo3wMzJ/zvg6QVM1jsL+AVJcK8pJPawzQqLpJK9aEb15QJ3EGqUMDaa6 wFCjWziQIstOvbNmiB7boHSj9ML/0eLlSmTvUloh4nsTLUnC71WdSVs7r7xDYCpIxRO8 MNtwtDYiayCJERe3sCCGmKy6eNl1d30174lWTv374vFekZv1RApZHBlGh4QVC7aQtk79 ZRCVEDXFmHOWzECOYD8LpLs0MKvefrmvYoXMnq/H/D0CVvIDtjCfBnuTMgfX4niu0c+d MmAg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=KAZa5nsMm2MKbyX2g6hfUlqMSl1TOoy9/BgiaTHbg7U=; b=jff3GG6NDyDqrDGmHbtFCcABOJcSoH1QMSzFbW5lGYyIBf+ud+CQ9jjry2XV2YQVi6 VPgKkhayIBpRopAvnVNeNHXFOo/r9ior2Po49c+IidlfYpCCyjcFdTivlv6E6hO2wpfL MzqCUgNxQuwiaU2qMS5lo/FNpEwJukaVsoRrPaG76jzs2ZiY54AYOnK80Va3KSm+FKyT djceJe7qhTiJToq5yIy+u2i5WArcPckjYb7RZxr55oX4UphjciwSHvIIrqnaVhjt8snn bfWE8cFZEnPqtx9B3MgSCKPXrdrhfj+iEqGpCStDmWHTSlPeiS0TVwmaOB9rVirrDJfa AvLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E6F9sozc; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y1si19351565ilq.100.2021.05.11.05.35.30; Tue, 11 May 2021 05:35:42 -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=@redhat.com header.s=mimecast20190719 header.b=E6F9sozc; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231340AbhEKMfO (ORCPT + 99 others); Tue, 11 May 2021 08:35:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31430 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbhEKMfO (ORCPT ); Tue, 11 May 2021 08:35:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620736447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KAZa5nsMm2MKbyX2g6hfUlqMSl1TOoy9/BgiaTHbg7U=; b=E6F9sozczLdiPQkLkAlVIOb74nRXEQyKqp3O7QIcoLP+ccs4w1CN66hcTXaJn8F/tbWu02 GawZAq11rRakS1RZeNpPBX+vGy9nmeMRnZR0PqD9oUApUIN71fJ4PJ5lcSbK3HEfzA4Vr9 H0uYh0gtVZirvFzodR2PId+4JtqPDrg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-r22KY4uyNwW44ttCNyCbiQ-1; Tue, 11 May 2021 08:34:06 -0400 X-MC-Unique: r22KY4uyNwW44ttCNyCbiQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2F4BCC626; Tue, 11 May 2021 12:34:04 +0000 (UTC) Received: from starship (unknown [10.40.194.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7F5319C44; Tue, 11 May 2021 12:34:01 +0000 (UTC) Message-ID: <93105f38e3668d2da633599b14922a02dabe1b33.camel@redhat.com> Subject: Re: [PATCH 03/15] KVM: SVM: Inject #UD on RDTSCP when it should be disabled in the guest From: Maxim Levitsky To: Sean Christopherson Cc: Jim Mattson , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML , Xiaoyao Li , Reiji Watanabe Date: Tue, 11 May 2021 15:34:00 +0300 In-Reply-To: References: <20210504171734.1434054-1-seanjc@google.com> <20210504171734.1434054-4-seanjc@google.com> <1b50b090-2d6d-e13d-9532-e7195ebffe14@redhat.com> <4a4b9fea4937da7b0b42e6f3179566d73bf022e2.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2021-05-10 at 16:56 +0000, Sean Christopherson wrote: > On Mon, May 10, 2021, Maxim Levitsky wrote: > > On Tue, 2021-05-04 at 14:58 -0700, Jim Mattson wrote: > > > On Tue, May 4, 2021 at 2:57 PM Paolo Bonzini wrote: > > > > On 04/05/21 23:53, Sean Christopherson wrote: > > > > > > Does the right thing happen here if the vCPU is in guest mode when > > > > > > userspace decides to toggle the CPUID.80000001H:EDX.RDTSCP bit on or > > > > > > off? > > > > > I hate our terminology. By "guest mode", do you mean running the vCPU, or do > > > > > you specifically mean running in L2? > > > > > > > > > > > > > Guest mode should mean L2. > > > > > > > > (I wonder if we should have a capability that says "KVM_SET_CPUID2 can > > > > only be called prior to KVM_RUN"). > > > > > > It would certainly make it easier to reason about potential security issues. > > > > > I vote too for this. > > Alternatively, what about adding KVM_VCPU_RESET to let userspace explicitly > pull RESET#, and defining that ioctl() to freeze the vCPU model? I.e. after > userspace resets the vCPU, KVM_SET_CPUID (and any other relevant ioctls() is > disallowed. I vote even stronger for this! I recently created what Paulo called an 'evil' test to stress KVM related bugs in nested migration by simulating a nested migration with a vCPU reset, followed by reload of all of its state including nested state. It is ugly since as you say I have to manually load the reset state, and thus using 'KVM_VCPU_RESET' ioctl instead would make this test much more cleaner and even more 'evil'. Best regards, Maxim Levitsky > > Lack of proper RESET emulation is annoying, e.g. userspace has to manually stuff > EDX after vCPU creation to get the right value at RESET. A dedicated ioctl() > would kill two birds with one stone, without having to add yet another "2" > ioctl(). >