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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED9CCC25B06 for ; Thu, 4 Aug 2022 17:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237351AbiHDRIb (ORCPT ); Thu, 4 Aug 2022 13:08:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234734AbiHDRIa (ORCPT ); Thu, 4 Aug 2022 13:08:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 60AAA67C88 for ; Thu, 4 Aug 2022 10:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659632908; 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=acKEhL55txfWJodj/kwqYF65Txyu4XN1fZSdGnmYxoY=; b=Mc36B+pNzZ6arKqqE+jCqu63UL0164/eSUl2lCVOy65htTHTaesRsP9nC+VZLa9eR8O7ca QyjafETRQG62hJTmDyNYHvWgoRHvOrPu8FWNXpIHfMqv156b5qLRgR3oSGmKhUjoBbjB0N m7zuMAZYtRDPt1epkXdfuB76RYJM2YQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-203-l5WeRPqVPI2ztoh3IDP14Q-1; Thu, 04 Aug 2022 13:08:26 -0400 X-MC-Unique: l5WeRPqVPI2ztoh3IDP14Q-1 Received: by mail-wm1-f72.google.com with SMTP id j22-20020a05600c485600b003a50fa6981bso1014877wmo.9 for ; Thu, 04 Aug 2022 10:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=acKEhL55txfWJodj/kwqYF65Txyu4XN1fZSdGnmYxoY=; b=bmSsyAtaeQf7xQg9OXxpN7Z2pMdwmtZN2dzNOCGNmJbdrVsqLXdQMAzvkIsE1D0LG4 oeWKy/puS24Yakxxee7Ag3p2AENNpG4N22bBZRkzRHj+Vb/po6lhLceoFTwa07NiYQcm tTSRN96CW4WStiqPPajT435iwfCqjeCLWx7od0KNE+6okRxNPbcaKyYej57JczqSdIFM xEz6W3AeVAK92izHxui9UQ5P8qQVKGklgADRNOsMblrQNkBUvrKBWG4aho70c4rDxE21 mwhZG72vKd/IhUTsl5rfOT1Wt+SM24bIUXY9w5nFttMriry09yqNVFPj4lEQzMgK9NNZ ntWQ== X-Gm-Message-State: ACgBeo19qYo76b7NaJE2CMUoLvBzciV/WRv4RmAdxhQwY27ztf6jLYHh r/Q4LkPeyQ+gpegsGZ52PmKECLqW5GYpnkr8g/vRyjyDwga4z9zdepDjQwyO96sFahR84eLawUG vHZUV2aUJRVHo X-Received: by 2002:a5d:67c1:0:b0:220:7079:78ef with SMTP id n1-20020a5d67c1000000b00220707978efmr2069190wrw.264.1659632905452; Thu, 04 Aug 2022 10:08:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR69LuPWeRZ63EEvNbjUmD6npjXR31aH5eDe1l9v6pHIeuEf1FkGBjnYrOa4bgoa+Aro9OFfYg== X-Received: by 2002:a5d:67c1:0:b0:220:7079:78ef with SMTP id n1-20020a5d67c1000000b00220707978efmr2069167wrw.264.1659632905142; Thu, 04 Aug 2022 10:08:25 -0700 (PDT) Received: from work-vm (cpc109025-salf6-2-0-cust480.10-2.cable.virginm.net. [82.30.61.225]) by smtp.gmail.com with ESMTPSA id a18-20020a05600c349200b003a35ec4bf4fsm2119048wmq.20.2022.08.04.10.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 10:08:24 -0700 (PDT) Date: Thu, 4 Aug 2022 18:08:22 +0100 From: "Dr. David Alan Gilbert" To: Vitaly Kuznetsov Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Dave Young , Xiaoying Yan , David Woodhouse , stable@vger.kernel.org Subject: Re: [PATCH] KVM: x86: revalidate steal time cache if MSR value changes Message-ID: References: <20220804132832.420648-1-pbonzini@redhat.com> <87v8r8yuvo.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v8r8yuvo.fsf@redhat.com> User-Agent: Mutt/2.2.6 (2022-06-05) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org * Vitaly Kuznetsov (vkuznets@redhat.com) wrote: > Paolo Bonzini writes: > > > Commit 7e2175ebd695 ("KVM: x86: Fix recording of guest steal time > > / preempted status", 2021-11-11) open coded the previous call to > > kvm_map_gfn, but in doing so it dropped the comparison between the cached > > guest physical address and the one in the MSR. This cause an incorrect > > cache hit if the guest modifies the steal time address while the memslots > > remain the same. This can happen with kexec, in which case the steal > > time data is written at the address used by the old kernel instead of > > the old one. > > > > While at it, rename the variable from gfn to gpa since it is a plain > > physical address and not a right-shifted one. > > > > Reported-by: Dave Young > > Reported-by: Xiaoying Yan > > Analyzed-by: Dr. David Alan Gilbert > > Cc: David Woodhouse > > Cc: stable@vger.kernel.org > > Fixes: 7e2175ebd695 ("KVM: x86: Fix recording of guest steal time / preempted status") > > Signed-off-by: Paolo Bonzini > > --- > > arch/x86/kvm/x86.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index e5fa335a4ea7..36dcf18b04bf 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -3380,6 +3380,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu) > > struct gfn_to_hva_cache *ghc = &vcpu->arch.st.cache; > > struct kvm_steal_time __user *st; > > struct kvm_memslots *slots; > > + gpa_t gpa = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS; > > u64 steal; > > u32 version; > > > > @@ -3397,13 +3398,12 @@ static void record_steal_time(struct kvm_vcpu *vcpu) > > slots = kvm_memslots(vcpu->kvm); > > > > if (unlikely(slots->generation != ghc->generation || > > + gpa != ghc->gpa || > > kvm_is_error_hva(ghc->hva) || !ghc->memslot)) { > > - gfn_t gfn = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS; > > - > > /* We rely on the fact that it fits in a single page. */ > > BUILD_BUG_ON((sizeof(*st) - 1) & KVM_STEAL_VALID_BITS); > > > > - if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gfn, sizeof(*st)) || > > + if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gpa, sizeof(*st)) || > > (It would be nice to somehow get at least a warning when 'gfn_t' is used > instead of 'gpa_t' and vice versa) Can't sparse be taught to do that? Dave > > kvm_is_error_hva(ghc->hva) || !ghc->memslot) > > return; > > } > > Reviewed-by: Vitaly Kuznetsov > > -- > Vitaly > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK