From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A088215075 for ; Thu, 23 Jul 2026 00:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784766483; cv=none; b=di8EEldv7Nr864khI1yvnbDG40hglrF9EZ36X7RVUMA71LNP0viwcN83ig2bVTItQcKEfoEc0SBAJKzrvUX+ibat3ac1Ajs6DLzcwz/38FC4pODdIvOKHIKdNu3tp+M70x/Rl5+fSBFpJYaQCU7473fuTwFQoWiPhKNWxiFI1/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784766483; c=relaxed/simple; bh=/UZySirpid/MfDWu44GC6SToSJ2/wtOHnG0Mh+touCI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LxK572wEvEMQ4rt0sVFqSUP16//r8E7Nom9xrTAYEYAyVxtbu4Q17jejUzX7bQUjq/egaYwiVdO74Cq/mnX4DAEzbbnvpoWQTJ+6YoCvjTSpzqZHldjLkNJbnNsowuu4Vmc05eYG5uhvy9gG6k2jyF3D1gYscAF+Aps+CtVx+H4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OBc/AfBI; arc=none smtp.client-ip=209.85.210.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OBc/AfBI" Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8485d853b08so170232b3a.1 for ; Wed, 22 Jul 2026 17:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784766482; x=1785371282; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QkJ7G3XJxikXzwURxYlXUdmxo4NZ//WfuDj4slMPc3E=; b=OBc/AfBIIUM1e8RISOuxldZ92ty+PBxhJIrLWYzzicF/xcnt9/yOwJVF5KRYWHkLso UWXWfxC19GiIHoI+MD991lv7TMBlrhGvNiyDCOUnd7UtK1aTckC2/A8ZmBll5c3e7vSM trz6qr19F3NMAfebPRXRg2jI8EESZp5V0tm1yqMaGZzzvvIT9PJXD4k/VhOJhrkreHdX 67hND8E9/SIH2a5AzMyi/rKMTUzjD5sdVCuEtwEHoxC04O1kOfUOR/GjrBDrFlI+6ztO QLX3IxRpyn2eFdDwk2ax+18vbFNoUSOD9OqLVjB+p1XUonYRNgkVX7khbJjcst4r1iDh z4SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784766482; x=1785371282; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QkJ7G3XJxikXzwURxYlXUdmxo4NZ//WfuDj4slMPc3E=; b=jruK6qAEHBoy/RgV4LCbzYz3MMOAwBgnpWN23wqb92JhAsIbZDqDQWLtZRCeGaS9Zn OPRxzVrORGzGoNXPQqT1IXJM7S+dRmtNhk/lR8PJFeaxjuDpJEoKPCXWbYwb1AB0oNWE MYC3yr9vzaKZHj5HHsghdq2wl9kF/mAc27tfQxs5OA9PQIp7JljwUWyq4qteZyXj0GdC 0u4KDLnXD0C/hBqKYOPAOYq8FKGUcQtnnVEP/bcjo45jQY9P5gS0AmwhBKe8mU5GDPX4 mqThUHO0SAdDjJ0zmXqMecdn5EgtsjVBMYgX3Kyb5d3s3cJ39RxnOwApM/clisDztpbt r06A== X-Forwarded-Encrypted: i=1; AHgh+Rp36Ug82iNFxcLBoGMHoD9fJoQob5kpIfbx9/r7A7b3mdNEPM/k68CzwhCNP1UgqMpHx0nhHm/ialzRhaI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1AZOaMyimV2Nyz7iFe2+2wQYf2PjxUgRB6CldT/MmVx1qyne/ z3IwLhIpzXUfCNtstKmq8uyNIDDGtuPfXk4oI8gK6DVJI4kSW3omPA3FqeW6jRZGkTQ/Xkrr8cb t/s9i9Q== X-Received: from pfbll22.prod.google.com ([2002:a05:6a00:7296:b0:84b:6d07:4d38]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2347:b0:847:9745:2f83 with SMTP id d2e1a72fcca58-84e2bc2ead6mr1152550b3a.18.1784766481557; Wed, 22 Jul 2026 17:28:01 -0700 (PDT) Date: Wed, 22 Jul 2026 17:28:00 -0700 In-Reply-To: <20260616004155.1435766-5-yosry@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260616004155.1435766-1-yosry@kernel.org> <20260616004155.1435766-5-yosry@kernel.org> Message-ID: Subject: Re: [RFC PATCH v2 04/25] KVM: x86/mmu: Support specifying a minimum TLB tag From: Sean Christopherson To: Yosry Ahmed Cc: Paolo Bonzini , Jim Mattson , Maxim Levitsky , Vitaly Kuznetsov , Tom Lendacky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Tue, Jun 16, 2026, Yosry Ahmed wrote: > In preparation for using the TLB tags allocator for SVM, which has a > range of ASIDs allocated for SEV/SNP, pass in a minimum TLB tag when > initializing the TLB tags allocator. The bitmap is conceptually shifted > such that bit=0 corresponds to tag=min. > > Specifying the minimum value during initialization also makes the API > clearer, as the passed number of tags becomes the actual number of > *usable* tags, and tag=0 is explicitly excluded by the caller. > > No functional change intended for VMX as VPID=0 is not used anyway. > > Signed-off-by: Yosry Ahmed > --- > arch/x86/kvm/mmu.h | 2 +- > arch/x86/kvm/mmu/mmu.c | 38 +++++++++++++++++++++++--------------- > arch/x86/kvm/vmx/vmx.h | 3 ++- > 3 files changed, 26 insertions(+), 17 deletions(-) > > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > index 9a2916012cbff..cfffee92b8b71 100644 > --- a/arch/x86/kvm/mmu.h > +++ b/arch/x86/kvm/mmu.h > @@ -337,7 +337,7 @@ static inline bool kvm_is_gfn_alias(struct kvm *kvm, gfn_t gfn) > > typedef unsigned int kvm_tlb_tag_t; > > -int kvm_init_tlb_tags(unsigned int nr); > +int kvm_init_tlb_tags(kvm_tlb_tag_t min, unsigned int nr); > void kvm_destroy_tlb_tags(void); > kvm_tlb_tag_t kvm_alloc_tlb_tag(void); > void kvm_free_tlb_tag(kvm_tlb_tag_t tag); > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index e021ed562502f..bf2e0c2205631 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -8197,24 +8197,26 @@ static struct { > spinlock_t lock; > unsigned long *bitmap; > unsigned int nr; > + kvm_tlb_tag_t min; > } tlb_tags; > > -int kvm_init_tlb_tags(unsigned int nr) > +int kvm_init_tlb_tags(kvm_tlb_tag_t min, unsigned int nr) Hmm, I think this code should handle "nr - min" instead of requiring the caller to do so. Because people that know how SEV+ works, but aren't familiar with this code (like I am right now), will probably find it confusing that nothing in here appears to account for the "reserved" ASIDs. Maybe this? With documentation that reserved ASIDs start at 0, inclusive, and are contiguous. int kvm_init_tlb_tags(unsigned int nr, unsigned nr_reserved) { } And then tlb_tags.min becomes something like tlb_tags.offset (that's a terrible name, but you probably get the gist).