Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4664468pxu; Tue, 13 Oct 2020 04:19:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCPH/fwBJj+vGd3mtUNBhgCHK2w3hSCc4wf41YQJSpmC1psXHbNNBWzJ8x2wvvNyCaUwK4 X-Received: by 2002:aa7:dd11:: with SMTP id i17mr19424273edv.188.1602587973346; Tue, 13 Oct 2020 04:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602587973; cv=none; d=google.com; s=arc-20160816; b=mfZzh5USZNaJOoXQTcbQcxzrolMpjQo3+2e/6UJkT6wi5EJRCkWHUZBfFvkPWtsEss aavCcOZGC/kSVEsCkv2j3qx4dOko+1eyKWdIZrjY+bKhsY0wweJm5DEFepJ7IgkwAK9x 51KtdPYbwU1qW5yq8jwKVPFWUpGqWn3YhbI5CW94ww3HeJrmBG/3dkLOLCIK98jnP9PO N53wdIs/ahLwP1KbJ/dmzRUjlNeHStreJ0ldTKJv3tdeZ2sieNUPeAOCQFNn+n4vwSWq JPS2XKgAKAof1Rb1djLfInBrc/xth6RLQ3pNYw6LegnyBtW3a989dtC6oV2orJ/ffJZp 4O6Q== 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 :ironport-sdr:ironport-sdr; bh=xPOe6JyPAlg5XzumH6mriDA8tAx6crCU43zLKtMm1o8=; b=lILPBH663cQYwTqa4ju1x7DUGaWvS5tQcUbi9pR78w0knwdgfKRhIlVWKgsCJuhrk8 QROlTVvj5tz6lrLt+F5qtmh2aE3h428+VMUv/u2dKHBaL02Sbbu1z23BRzTdHS3TXkJS Hg75h2X5XgtYFvOS6Z8owh1CDEFe2gXLsW+Xn3MAv649qq52YFtRZyTaZIeJfWI0MfBV dyR4PWoXJulYZzJVoaThyIpTRZkacnAd0xwNIaGt/pqjM00tPqoXPr0UpgMuKFPmc0Fn bReWYCRYMPEHIkEhdgQqdAiMePMQpX/XQZDheLFJXQlbtq71OtI6ZMj19XOZWMrl87Cb hd1Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si15057951edg.229.2020.10.13.04.19.11; Tue, 13 Oct 2020 04:19:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbgJMB3k (ORCPT + 99 others); Mon, 12 Oct 2020 21:29:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:56905 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728093AbgJMB3k (ORCPT ); Mon, 12 Oct 2020 21:29:40 -0400 IronPort-SDR: JtsYpXbwLMfQ+JvGj54YzXEz8bhqDeSoKlMKQEiIVzCP9L+PNQKSdxsBgdR0pHn6HK6yu9tG/X ELAfGeCF9btQ== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="165940576" X-IronPort-AV: E=Sophos;i="5.77,369,1596524400"; d="scan'208";a="165940576" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 18:29:38 -0700 IronPort-SDR: yZvtb1Pk85zflXWxZ0jIgBKFOv1+Bv1jAnj+/xc76PN7o4MmmO29r1FI7ilHQxgFVPZCIUxw2A zQYZmjRZkLWQ== X-IronPort-AV: E=Sophos;i="5.77,369,1596524400"; d="scan'208";a="313633677" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 18:29:38 -0700 Date: Mon, 12 Oct 2020 18:29:37 -0700 From: Sean Christopherson To: Cathy Avery Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, vkuznets@redhat.com, wei.huang2@amd.com, mlevitsk@redhat.com Subject: Re: [PATCH v2 1/2] KVM: SVM: Move asid to vcpu_svm Message-ID: <20201013012937.GA10366@linux.intel.com> References: <20201011184818.3609-1-cavery@redhat.com> <20201011184818.3609-2-cavery@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201011184818.3609-2-cavery@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 11, 2020 at 02:48:17PM -0400, Cathy Avery wrote: > Move asid to svm->asid to allow for vmcb assignment This is misleading. The asid isn't being moved, it's being copied/tracked. The "to allow" wording also confused me; I though this was just a prep patch and the actual assignment was in a follow-up patch. > during svm_vcpu_run without regard to which level > guest is running. > Signed-off-by: Cathy Avery > --- > arch/x86/kvm/svm/svm.c | 4 +++- > arch/x86/kvm/svm/svm.h | 1 + > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index d4e18bda19c7..619980a5d540 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -1101,6 +1101,7 @@ static void init_vmcb(struct vcpu_svm *svm) > save->cr4 = 0; > } > svm->asid_generation = 0; > + svm->asid = 0; > > svm->nested.vmcb = 0; > svm->vcpu.arch.hflags = 0; > @@ -1663,7 +1664,7 @@ static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd) > } > > svm->asid_generation = sd->asid_generation; > - svm->vmcb->control.asid = sd->next_asid++; > + svm->asid = sd->next_asid++; > vmcb_mark_dirty(svm->vmcb, VMCB_ASID); I know very little (ok, nothing) about SVM VMCB caching rules, but I strongly suspect this is broken. The existing code explicitly marks VMCB_ASID dirty, but there is no equivalent code for the case where there are multiple VMCBs, e.g. if new_asid() is called while vmcb01 is active, then vmcb02 will pick up the new ASID but will not mark it dirty. > } > @@ -3446,6 +3447,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) > > sync_lapic_to_cr8(vcpu); > > + svm->vmcb->control.asid = svm->asid; Related to the above, handling this in vcpu_run() feels wrong. There really shouldn't be a need to track the ASID. vmcb01 will always exist if vmcb02 exits, e.g. the ASID can be copied and marked dirty when loading vmcb02. For new_asid(), it can unconditionally update vmcb01 and conditionally update vmcb02. > svm->vmcb->save.cr2 = vcpu->arch.cr2; > > /* > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > index a798e1731709..862f0d2405e8 100644 > --- a/arch/x86/kvm/svm/svm.h > +++ b/arch/x86/kvm/svm/svm.h > @@ -104,6 +104,7 @@ struct vcpu_svm { > struct vmcb *vmcb; > unsigned long vmcb_pa; > struct svm_cpu_data *svm_data; > + u32 asid; > uint64_t asid_generation; > uint64_t sysenter_esp; > uint64_t sysenter_eip; > -- > 2.20.1 >