Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5895232pxj; Wed, 23 Jun 2021 11:14:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaIcZgSCEu0mlvrIXJUKZSYkDv/Ohj+B9UuvEo119yjUpvJvKER6QZVNq1ApUwc9cURKpm X-Received: by 2002:a17:906:25db:: with SMTP id n27mr1366304ejb.170.1624472062107; Wed, 23 Jun 2021 11:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624472062; cv=none; d=google.com; s=arc-20160816; b=yEmVarCVvd7DpMKEewKIjdDGektL59goHYGo9SCONP17NS/mFW18ihWtsOT6fLEcg9 QJzZHJX2PN2XsfGu2tQuTL8fYhKEfJXQhcrw5EIyoRhGvNvik2kHbfQ1W93CMV2ayqG9 5Vlh4W8EHHbS8RTaXSCZ2oV2802WWw+seELBQavSpM0tNsXrzLYshqPvtvW18JYfirLt fF8N1Q2ifULqaSpp5xq27r5KLXCd/QEgsojCmMtcWgzFxGvRX8fPQyGgLdaMYsy+cK1P +wMzy9S+mgYRltIs1faeIir/WAc6Ml/Lj7Xa+MAGh/HZLBUOKCHv+6usxS6CjC//j0YF HDBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=k7O/1D2MABRKTWEnJ4gsRDyfVcuNtzDzmQ12E1aStS8=; b=Ksrg4t63+uMPkQyD2mtTNfGEHB/+jfq/OP5pko4skj6+bbHcwUgThUZg9HsQi5IEDi HWPW1hm47Ck9ReUQ8rwRoFmIyxUDZGFFVrQTAzFllDm7n92l6XuBoVfz0+mlgjnIsUXG HmzLbQKd7J13prBJ/korch2W8e23/0GGB7htoU2M89PJjIrMRaaAcgzPcoYQDcdQnV9k AP7pQkQ0Y197JBzQot8f6Sz/TlKhPFsFDy9Td9qF5wscn7KBiIEwfGbrMwbLcuMe9d7H jGsemE8HMcvX/gqC5Fibzz7Dx4PuAXaExmwatnZu8676nueGtWtLh73+bwk5fS0QEu38 HFdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=O2lFQDP8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 5si386459ejh.535.2021.06.23.11.13.58; Wed, 23 Jun 2021 11:14:22 -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=@google.com header.s=20161025 header.b=O2lFQDP8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbhFWSON (ORCPT + 99 others); Wed, 23 Jun 2021 14:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbhFWSOM (ORCPT ); Wed, 23 Jun 2021 14:14:12 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27B3EC061756 for ; Wed, 23 Jun 2021 11:11:55 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id s17so4375441oij.0 for ; Wed, 23 Jun 2021 11:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=k7O/1D2MABRKTWEnJ4gsRDyfVcuNtzDzmQ12E1aStS8=; b=O2lFQDP85iiyxpQsmL3RsHJsuO2o54nS0Y+LaeWF/gpizYfeoWcc7tmzg7oR9yqb2s SVqEf6eJqLmPHl9bLJRA3Qzl1gC6p776tGoPb1kz+pYOtpnSTIzEaorVf+t41j3tsxi2 dDu4WXRGgc3Vw+hkAR2DaJUvuB5kbGLP1VDpsynVMvwr/2jignw81smHX9qCBHrI+Pjw C38w/CwaYOGs1RBDjQ0PaqsH9Q4UocEBh4cscpNPXNM58p+1ttQ5g6Vn6VPuPUi7UJ+s O2g/sA1An/sWmWHcQilH4YRrqfwoSOPuNRYekg1JQMNDrdb7Oza3mVuoYOG82ZvLxE2G 4NuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=k7O/1D2MABRKTWEnJ4gsRDyfVcuNtzDzmQ12E1aStS8=; b=X49Sbc7bKeRhv/zXhr1ZUL5RIQvgTSq9jKmSZR/EswDy/t1oKmplBJxc3TKhPF7gLI Yf6zOiyZDUR9SJZX7IIahuuXegnorb7VVxhhlwAd9j+OyvgVQ3TlBPCOqa1omaH3utm0 cGa1xpV7MsmfsNvB8w6nY1uayjy7dIyz56Zw4fui6AiV6+oT4klaVV8H84lL0TOwVvEJ DXKCQ7GwN1luKLxY302OiqXH70bVCsOv6IlJ3fvZ3ypzkzarzGudQ140PI1T3ZAvEH6A tt8ndUkipwcZ02z9AoWIDh4yD4G2DlswCoY4LzpX99za3hUWJAeB4+Aq9vcf1pzN4ZIc AviQ== X-Gm-Message-State: AOAM530jPyQmQscanOKwMpTQN+8G1wT0b62gXhkeLmmr+iOxSpmPP76v kA4HBBHXIAD+52FSmXp592m2/h6GKDaQ6kfeePE9Bw== X-Received: by 2002:a54:4586:: with SMTP id z6mr4217883oib.6.1624471914212; Wed, 23 Jun 2021 11:11:54 -0700 (PDT) MIME-Version: 1.0 References: <20210622175739.3610207-1-seanjc@google.com> <20210622175739.3610207-8-seanjc@google.com> <6f25273e-ad80-4d99-91df-1dd0c847af39@redhat.com> In-Reply-To: <6f25273e-ad80-4d99-91df-1dd0c847af39@redhat.com> From: Jim Mattson Date: Wed, 23 Jun 2021 11:11:43 -0700 Message-ID: Subject: Re: [PATCH 07/54] KVM: x86: Alert userspace that KVM_SET_CPUID{,2} after KVM_RUN is broken To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML , Yu Zhang , Maxim Levitsky Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 23, 2021 at 10:11 AM Paolo Bonzini wrote: > > On 23/06/21 19:00, Jim Mattson wrote: > > On Wed, Jun 23, 2021 at 7:16 AM Paolo Bonzini wrote: > >> > >> On 22/06/21 19:56, Sean Christopherson wrote: > >>> + /* > >>> + * KVM does not correctly handle changing guest CPUID after KVM_RUN, as > >>> + * MAXPHYADDR, GBPAGES support, AMD reserved bit behavior, etc.. aren't > >>> + * tracked in kvm_mmu_page_role. As a result, KVM may miss guest page > >>> + * faults due to reusing SPs/SPTEs. Alert userspace, but otherwise > >>> + * sweep the problem under the rug. > >>> + * > >>> + * KVM's horrific CPUID ABI makes the problem all but impossible to > >>> + * solve, as correctly handling multiple vCPU models (with respect to > >>> + * paging and physical address properties) in a single VM would require > >>> + * tracking all relevant CPUID information in kvm_mmu_page_role. That > >>> + * is very undesirable as it would double the memory requirements for > >>> + * gfn_track (see struct kvm_mmu_page_role comments), and in practice > >>> + * no sane VMM mucks with the core vCPU model on the fly. > >>> + */ > >>> + if (vcpu->arch.last_vmentry_cpu != -1) > >>> + pr_warn_ratelimited("KVM: KVM_SET_CPUID{,2} after KVM_RUN may cause guest instability\n"); > >> > >> Let's make this even stronger and promise to break it in 5.16. > >> > >> Paolo > > > > Doesn't this fall squarely into kvm's philosophy of "we should let > > userspace shoot itself in the foot wherever possible"? I thought we > > only stepped in when host stability was an issue. > > > > I'm actually delighted if this is a sign that we're rethinking that > > philosophy. I'd just like to hear someone say it. > > Nah, that's not the philosophy. The philosophy is that covering all > possible ways for userspace to shoot itself in the foot is impossible. > > However, here we're talking about 2 lines of code (thanks also to your > patches that add last_vmentry_cpu for completely unrelated reasons) to > remove a whole set of bullet/foot encounters. What about the problems that arise when we have different CPUID tables for different vCPUs in the same VM? Can we just replace this hole-in-foot inducing ioctl with a KVM_VM_SET_CPUID ioctl on the VM level that has to be called before any vCPUs are created?