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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 8EA17C433F5 for ; Tue, 21 Sep 2021 13:55:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 726C361159 for ; Tue, 21 Sep 2021 13:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233380AbhIUN5I (ORCPT ); Tue, 21 Sep 2021 09:57:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30289 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbhIUN5H (ORCPT ); Tue, 21 Sep 2021 09:57:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232538; 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: in-reply-to:in-reply-to:references:references; bh=hQA2iZmoG8rc7T5ZAkl2Bo9gs+c2W6PH/5qvslbTWg8=; b=iSIGKav7BjnLB7pzW3QDf5x2uU7j/NqCMIdyZFSZxQfptwKFB1/b6BzQ4QdSndIWRJFHSd EcaZiNNp5S8IlXoJgLAIEIoJg2nTiYIDWsIMnnkkFpQhJlbQISlCVASGtSNhm6fxC50TOS I7vUb22yPQ1f8gIpigZtVfitgIqQPMU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-dcYJM1_XM6-WQDm3EVCYXw-1; Tue, 21 Sep 2021 09:55:37 -0400 X-MC-Unique: dcYJM1_XM6-WQDm3EVCYXw-1 Received: by mail-wr1-f72.google.com with SMTP id k2-20020adfc702000000b0016006b2da9bso3830972wrg.1 for ; Tue, 21 Sep 2021 06:55:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=hQA2iZmoG8rc7T5ZAkl2Bo9gs+c2W6PH/5qvslbTWg8=; b=hSu6KnqbeU8T+aq5LaJ30jkAd8pXpzorweUviEGiErOnLGfsrTlj8nQrYDpyCnLvMf 00+1MWr12dt9wso69n5fP4LudY9nsc4ZyE7pQiu8CVSLFD1Ly9v9r9D4Nxppy/KPDK7/ avytUXB8d4EFzC+wIl9quRe2OaFMJUvPCVghVEnrrXU8vvAyjn21FvXJ7+UbOg5scYKQ C78zHQ+qTXAcCTIP1y23RVjctO2zC1AiYPAE366mpnZQy9P4zJ+Hn1Kn+5URi7PDVoYJ cKUF1lYxIeuDbWpELgJuY3mWW1FF59nwZA1T3TItbxqEZTdLjgzAztFk95ay0OO83xwc /aqw== X-Gm-Message-State: AOAM533CZwXAN9QDWBKseUaQhIVu3XMb5lzE3zEofgV+voQCgexKCPZp MMkk2b2kbLSrgbTb9vZ3zytntr1zZlN3/ONkiP0fX5wUJ/japcVMFFR1iO5wFuEWu+wK9fmPsZF LGSND1pj1UaCj42NWLO4jsfwl X-Received: by 2002:adf:ef02:: with SMTP id e2mr34633564wro.401.1632232535250; Tue, 21 Sep 2021 06:55:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyMKNkhwCL+W2v5q/hOPNTyhTF55HWavsNXVXZsMneIaIOxpjh23ykSVXLyy3cooWwlJx6Yw== X-Received: by 2002:adf:ef02:: with SMTP id e2mr34633547wro.401.1632232535047; Tue, 21 Sep 2021 06:55:35 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id f19sm3021316wmf.11.2021.09.21.06.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 06:55:34 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson Cc: Paolo Bonzini , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Reiji Watanabe Subject: Re: [PATCH v2 02/10] KVM: x86: Clear KVM's cached guest CR3 at RESET/INIT In-Reply-To: <878rzq9gte.fsf@vitty.brq.redhat.com> References: <20210921000303.400537-1-seanjc@google.com> <20210921000303.400537-3-seanjc@google.com> <878rzq9gte.fsf@vitty.brq.redhat.com> Date: Tue, 21 Sep 2021 15:55:33 +0200 Message-ID: <875yuu9goa.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vitaly Kuznetsov writes: > Sean Christopherson writes: > >> Explicitly zero the guest's CR3 and mark it available+dirty at RESET/INIT. >> Per Intel's SDM and AMD's APM, CR3 is zeroed at both RESET and INIT. For >> RESET, this is a nop as vcpu is zero-allocated. For INIT, the bug has >> likely escaped notice because no firmware/kernel puts its page tables root >> at PA=0, let alone relies on INIT to get the desired CR3 for such page >> tables. >> >> Cc: stable@vger.kernel.org >> Signed-off-by: Sean Christopherson >> --- >> arch/x86/kvm/x86.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index e77a5bf2d940..2cb38c67ed43 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -10899,6 +10899,9 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) >> kvm_set_rflags(vcpu, X86_EFLAGS_FIXED); >> kvm_rip_write(vcpu, 0xfff0); >> >> + vcpu->arch.cr3 = 0; >> + kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3); > > kvm_register_mark_dirty() is redundant here as PATCH1 does > > vcpu->arch.regs_avail = ~0; > vcpu->arch.regs_dirty = ~0; > > just a few lines above. The dependency is, however, implicit and this > patch is marked for stable@ (well, PATCH1 has 8 Fixes: tags so I'd > expect it to get picked by everyone too, especially by robots) and > flipping two bits is cheap. Scratch that, kvm_vcpu_reset() and kvm_arch_vcpu_create() got mixed up in my head :-( > > Reviewed-by: Vitaly Kuznetsov > >> + >> /* >> * CR0.CD/NW are set on RESET, preserved on INIT. Note, some versions >> * of Intel's SDM list CD/NW as being set on INIT, but they contradict -- Vitaly