Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp760363rwb; Thu, 4 Aug 2022 10:22:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5oR0DbP/yR3IHcT/JegOXLgk7dIWv3wcge2Rapqz6lZn8UwN/O0Ma1JRMnesU24UGSTjjZ X-Received: by 2002:a05:6402:149:b0:431:7dde:9b59 with SMTP id s9-20020a056402014900b004317dde9b59mr3070619edu.339.1659633768490; Thu, 04 Aug 2022 10:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659633768; cv=none; d=google.com; s=arc-20160816; b=VLTY8l2r9KNasD1tHstJWR0Za8q/3e3tIl+vDEWBWNPll9WUnzMOJYAiR2KKV83RnE 8GTrw+8/SFra1RLWD3FYhGIcEykTk7WUwjD1G4Aodm8od7+qj/TPgpm7h5Lj89pGQkAz mvo5TLprFCZvb1wUcZDX+Hc4j2++4mENYK14C4rT04EWI8bNlwym+k2X6YNqh06k5XsS 7IOCQWSoVbMXu/pF2CwqOCvcwMAvN+MfOe1JXCqNALcN+igXpH2rvebji9XGe79SbLOx UQH5XVixxdXP2sikIL/h0tERQkchOqYBmBOeOC+KYf165ORETN8lp66/eAdwrZLGQFdw 0Rog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=acKEhL55txfWJodj/kwqYF65Txyu4XN1fZSdGnmYxoY=; b=dlxs+892/IV7+BL7jN6gzwfYSQIF9B8ncPJQ/LJo5ZdOgWNPik3oCawoMKQyxFQvTu Ap/SviNOP0GBKd+IOwLJkix4S1/kT3TF+swek4hNb1hqAZ/m49OYlRtoQefE5u1mA1w4 joWljSUr62nx7l29rKBaCr56taDGjF75HU6Jf/s8/FoAq6Swir+Sm5R4pmQe+56YlU/1 zoZUgDGeLTA6g8IfZc9KMw6cMS0ziliJLEX+8xvJSyLRf3SFVOsGUf5q7gf8kl9JsqLY 0xAo+khzeAr/merFnjOC5uzg3z4PaVRLZpCsZniKvMbLrOVMHLxzOTkUUiKLouY34UyF EvPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Mc36B+pN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a0564020e0400b0043c891e0f0fsi1711197edh.356.2022.08.04.10.22.22; Thu, 04 Aug 2022 10:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Mc36B+pN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237280AbiHDRIb (ORCPT + 99 others); Thu, 4 Aug 2022 13:08:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234802AbiHDRIa (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 57CFD67148 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-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-657-dH7UyZfcM_-uF0uLrIvGpw-1; Thu, 04 Aug 2022 13:08:27 -0400 X-MC-Unique: dH7UyZfcM_-uF0uLrIvGpw-1 Received: by mail-wm1-f69.google.com with SMTP id v130-20020a1cac88000000b003a4f057ed9fso109096wme.7 for ; Thu, 04 Aug 2022 10:08:27 -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=k5c+l0CvKqWSuF982GxOsTfeqP7jg0a/BIP1UcixdNp9LeZ4XOIKwanjRaNzJq/Fof Yh3OJDyK7v5/Z06UuEClm8E+s7dJy7qdRtmxhehwy9GVd/4HakGbBA2CdfJeWV75dfqF BM2zTBHcomzWRwd6hshPVHdDuwLcVtSObLh3cHcmEr41ZHUXVWj7HQQKrdjRDd2VuFA+ 4RY3CYM1sB0vJs10ImZXNyr6BtdD3cxue7ykTTjldAffFBlsL95lRVt55H3K+mx9xW7m z2c7NY5TOcwIS2nM2kT5vU8oyVIfZaVVWP3qYY9m1btixYoatl6UFFDJg3/abBvcA8KZ 3Tvg== X-Gm-Message-State: ACgBeo1uYrc7U5vBflBsG+p74QRZI+IdzvHBh1WB3SaJ310Vh39/6IOp EBeu4GEcs/oNT5NRS4hbq66RUkodTjyFFWUGL7Sj4krMyFnFUkR5bJm9ZL07CqDK9n66ONxUZoM aEX01/iziVQmCwQrIyD78hisL X-Received: by 2002:a5d:67c1:0:b0:220:7079:78ef with SMTP id n1-20020a5d67c1000000b00220707978efmr2069181wrw.264.1659632905392; Thu, 04 Aug 2022 10:08:25 -0700 (PDT) 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) X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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