From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE2A6C48BE5 for ; Wed, 23 Jun 2021 18:11:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5CCD610F7 for ; Wed, 23 Jun 2021 18:11:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbhFWSOO (ORCPT ); Wed, 23 Jun 2021 14:14:14 -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-Google-Smtp-Source: ABdhPJxJCcpmCbfs9B6a7LnsucauuSHO0LXTdfFLhRhcJMlFStXC3aLC9TE5ynTw5kMX8wUvBz41Eqq5xHS39sXfi6U= 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?