From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 F366C1E8826 for ; Mon, 29 Dec 2025 15:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767021885; cv=none; b=g2Sc6j+0tzfAbCdDRyCtWEM3rSASA/TbmlHZ9CWjJ3AP/ko2JAQvgsxiFWFXcmd1FVaiJuUDZz+vi6D7IkW5t7RHKoTLszw6ozBbBLJO8P6V5gTctEFj2T91HQTZQwXGzbKkoaIcaYKhm+6H1rqWj+GnLrZKt3Ysz0kga3wYTjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767021885; c=relaxed/simple; bh=NN8T3287x7Ols1SXOdTD/e2049uwV6Gj932H5nZUdZM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q9v2CfHa7roMwfV7rlra1oTc1/tb9BH82XUJFbAoQiEBk4+bCycV3sbEaf8IxiXkU8IBi+q+GZtQN0xgS30W71TH1cCA7gHzjFZQ7gB5aM4FLz0U1TIxivKg5OR7EREE1vbhbEEJerUtnZ2kEx/l3du1ro0zzUntG+LmnYCNKqU= 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=iTXCUM0S; arc=none smtp.client-ip=209.85.210.202 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="iTXCUM0S" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7c1df71b076so17963579b3a.0 for ; Mon, 29 Dec 2025 07:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767021883; x=1767626683; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IPdy/u4ar4zg+FvL/tA84pDfFm5/wiGlEDxZ5SeN1nQ=; b=iTXCUM0SC9c3cD7+83LI9YBZBsLYPDvE5eIx8ftopShbVj5FYZiT1B2Rrepow65+J5 e/dkJ9BHmFPuEkwiL2rNTy918CUYqHB+izIOw9wJNCUSLNoACtwXOUalKPPXu8rd0Gvk wmEuqxL2VY9CRnRucGZTVrc7SrMuiPk8NV/r4iWSiqqmTFcZNnyC//+GKOnJIgbVPZbj cXdfkcQYZ8yzhbinC+yzoP2NHrSZCW42fSSV96qttu+YpOxB8dmAnPUYN1FZ5LhI1YoK sGGIBXiz8X34ZHt947cfJy9WAh6Nxqazdm5hgU3xNfpIZiPudZykheBsbp2/G29Tc7lg fJfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767021883; x=1767626683; h=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; bh=IPdy/u4ar4zg+FvL/tA84pDfFm5/wiGlEDxZ5SeN1nQ=; b=p3SRIdXGYldNLJrkom0tT9ds975raN5NU/fkHwvYWfH9tBlBa2wHnGMhxsYp9kXPXG hXSj0TRSblrL0DFpmKxcZ5lRzoklmH8l6K6G9XGbzIb8byFnKdP1Km3805yX0v0RIghh VDpgtH4x/JB1CoPoEyA1g3OgvcywW41R5nrMoFlnNvVnHsywyZRo0YZ/Bjfq+i/nmYmu WQuN6Nar7FnCho7oNO/nDhxUnu6taveo167/4T++6dIceA3D53mFPd1BoLP6FS9ml34p CxZyk4ErCTHytrSelgj2Og5ZDaCImZaVaHTNJsJ3Fa4K0kxKmgGb/pYn90ZxdCXnXfc1 9S7w== X-Forwarded-Encrypted: i=1; AJvYcCU8tgFs3WeLEAkug9wnGq+YaiU+QHZvEo29ABROTbUcDFQ/Oc9l9V8u+7kiZy+S9O+ujvqfAWUZ/atVlSs=@vger.kernel.org X-Gm-Message-State: AOJu0YxHbpPAExsAoN38xfXzjlpRsj5oHVoqoIBxtsq3vK2EWn4D8zQw +eQonBSndj2bVDNiWkycti0ygZmncKAKWN3xhLi1iAanMBozL7u2mBy4D0hADlGx/KVdZuY4p9L a2n4gLA== X-Google-Smtp-Source: AGHT+IFgS7WihSzpyIuhrJFpLQJCGyE0BCoxx8nYlJDyjilVPlDY1U8ZPShs2HwghBqKbLanUNIlqfzMI1o= X-Received: from pfbff2.prod.google.com ([2002:a05:6a00:2f42:b0:793:b157:af42]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:44c6:b0:7e8:4433:8fb9 with SMTP id d2e1a72fcca58-7ff66d5f992mr22928778b3a.65.1767021883283; Mon, 29 Dec 2025 07:24:43 -0800 (PST) Date: Mon, 29 Dec 2025 07:24:41 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251127013440.3324671-1-yosry.ahmed@linux.dev> <20251127013440.3324671-7-yosry.ahmed@linux.dev> Message-ID: Subject: Re: [PATCH v3 06/16] KVM: selftests: Introduce struct kvm_mmu From: Sean Christopherson To: Yosry Ahmed Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Tue, Dec 23, 2025, Yosry Ahmed wrote: > On Tue, Dec 23, 2025 at 02:29:23PM -0800, Sean Christopherson wrote: > > On Thu, Nov 27, 2025, Yosry Ahmed wrote: > > > diff --git a/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h b/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h > > > index 972bb1c4ab4c..d8808fa33faa 100644 > > > --- a/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h > > > +++ b/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h > > > @@ -10,6 +10,8 @@ > > > > > > extern bool is_forced_emulation_enabled; > > > > > > +struct kvm_mmu; > > > + > > > struct kvm_vm_arch { > > > vm_vaddr_t gdt; > > > vm_vaddr_t tss; > > > @@ -19,6 +21,8 @@ struct kvm_vm_arch { > > > uint64_t s_bit; > > > int sev_fd; > > > bool is_pt_protected; > > > + > > > + struct kvm_mmu *mmu; > > > > No, put kvm_mmu in common code and create kvm_vm.mmu. This makes the "mmu" object > > a weird copy of state that's already in kvm_vm (pgd, pgd_created, and pgtable_levels), > > and more importantly makes it _way_ to easy to botch the x86 MMU code (speaking > > from first hand experience), e.g. due to grabbing vm->pgtable_levels instead of > > the mmu's version. I don't see an easy way to _completely_ guard against goofs > > like that, but it's easy-ish to audit code the code for instance of "vm->mmu.", > > and adding a common kvm_mmu avoids the weird duplicate code. > > Do you mean move pgd, pgd_created, and pgtable_levels into kvm_mmu? Yep, exactly. > If yes, that makes sense to me and is obviously an improvement over what it's > in this patch. > > I didn't immediately make the connection, but in hindsight it's obvious > that having some of the state in kvm_vm_arch and some in kvm_vm is > fragile.