From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B9DD1F12ED for ; Mon, 3 Mar 2025 22:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741039614; cv=none; b=HYSDIt+UNp+qmQI7R1EOFrKdSsLSr8Iye6xq6TSgVPyduj1+bXBMYvwbjosvZPnuzYwYvZWmO2F2lGWBD9Rgoe0FXtCr36K1G4wwd+pBdzPKBZ5dx7QXicULjNRRLpA6LItvqiDH0t9vMuBYjNgIKSZwmqp3XR6aWMQqNdSKir0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741039614; c=relaxed/simple; bh=QeY9z0+heLtap8BgmoW1vF5Flfd7VVfdLHG+7vA0RM0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fWSNqCDEg2fyHWjA0eSyVvBeqS+l3umFdGaiwh0rfhNqsKDVgGbPGBOhxNoDot9tzJI1aITGmXCMZ/2uhm7DSa00uG/F0L6X06vKeEKYyote1CVD3IXZtgMJNbQG8EtrRwclaxTub4N37GtsV1JMmX8Nwz0jLBS3pPjWeXOlTZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oR+U18gD; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oR+U18gD" Date: Mon, 3 Mar 2025 22:06:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741039610; 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=DQl5R4ebaZvP3xaAFBotmrLK16G34ov3SP3Vi7Kwp+U=; b=oR+U18gDDnv2P4Bbry71Vgi6YOA1sxdYR5UFhmEIZzwxhZs1setu4H8KOPQ71LncvVhc40 mK0UgrNQzfcxueHIYkUqJzg0U6O0GyOXicTvqsQhlaoXrJpny35um+crfEm52u/YM2gB5G o8Amlm5l97w91jeGdaGd7COFeQ7dAvQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Maxim Levitsky Cc: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 08/13] KVM: nSVM: Flush both L1 and L2 ASIDs on KVM_REQ_TLB_FLUSH Message-ID: References: <20250205182402.2147495-1-yosry.ahmed@linux.dev> <20250205182402.2147495-9-yosry.ahmed@linux.dev> <0ca86313d7fc0360009888243b1493c2bd44fb7b.camel@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0ca86313d7fc0360009888243b1493c2bd44fb7b.camel@redhat.com> X-Migadu-Flow: FLOW_OUT On Fri, Feb 28, 2025 at 08:58:04PM -0500, Maxim Levitsky wrote: > On Wed, 2025-02-05 at 18:23 +0000, Yosry Ahmed wrote: > > KVM_REQ_TLB_FLUSH is used to flush all TLB entries for all contexts > > (e.g. in kvm_flush_remote_tlbs()). Flush both L1 and L2 ASIDs in > > svm_flush_tlb_all() to handle it appropriately. > > > > This is currently not required as nested transitions do unconditional > > TLB flushes, but this is a step toward eliminating that. > > > > Signed-off-by: Yosry Ahmed > > --- > > arch/x86/kvm/svm/nested.c | 1 - > > arch/x86/kvm/svm/svm.c | 4 +++- > > 2 files changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > > index 0e9b0592c1f83..0735177b95a1d 100644 > > --- a/arch/x86/kvm/svm/nested.c > > +++ b/arch/x86/kvm/svm/nested.c > > @@ -491,7 +491,6 @@ static void nested_svm_entry_tlb_flush(struct kvm_vcpu *vcpu) > > * TODO: optimize unconditional TLB flush/MMU sync. A partial list of > > * things to fix before this can be conditional: > > * > > - * - Flush TLBs for both L1 and L2 remote TLB flush > > * - Honor L1's request to flush an ASID on nested VMRUN > > * - Sync nested NPT MMU on VMRUN that flushes L2's ASID[*] > > * - Don't crush a pending TLB flush in vmcb02 on nested VMRUN > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > index 9e29f87d3bd93..8342c7eadbba8 100644 > > --- a/arch/x86/kvm/svm/svm.c > > +++ b/arch/x86/kvm/svm/svm.c > > @@ -4044,7 +4044,9 @@ static void svm_flush_tlb_all(struct kvm_vcpu *vcpu) > > if (WARN_ON_ONCE(svm_hv_is_enlightened_tlb_enabled(vcpu))) > > hv_flush_remote_tlbs(vcpu->kvm); > > > > - svm_flush_tlb_asid(vcpu, svm->current_vmcb); > > + svm_flush_tlb_asid(vcpu, &svm->vmcb01); > > + if (svm->nested.initialized) > > + svm_flush_tlb_asid(vcpu, &svm->nested.vmcb02); > > } > > This makes sense. > > Note that this doesn't really flush the ASID used, but rather ensures > that we will flush it on next entry via that vmcb. (because of new asid, > that will be picked, or because we set tlb_ctl in that vmcb) Right, what I mean by 'flush' here is to setup the flush. For SVM all flushes are done on VM-enter anyway. > > Reviewed-by: Maxim Levitsky Thanks!