From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 EFEBA43B3F9 for ; Tue, 14 Jul 2026 08:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784019418; cv=none; b=cv30rGxTsqoy8wrfrqNnIwjeC29tK7m/D5UKqNnT0+yyOlxt/1aAQKERvWNSQIVK/l7v191zAi6en+f2+OeiaYgo0i+6UX+J8g7GOt2/RiWujrlbPGPNblOBWihtwnExyPApZKkAdZdnyAeL5Dajbgx6lG8SeMGjtCGQe3pam/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784019418; c=relaxed/simple; bh=Bzdu5b5y55NorpL/qYxPJhHOrlRCKuhOC+OyuSYeTXQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OnjjH45aPxOH4DJGA7HYG+Bc15llpMonZznG1dulYB1YdeXRXIRS2HX+14gblnNd5FzS/Qw1bHiE0Qhroez9vHOI/ej7c//3r/D2N2QFZlYijzkpKZ8qJGmxiJaaWe1mCYpt0WjXkSfr98CLNGTbW48TiFAnYh/+u1ZNaIVPQ7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QDzU1rGw; arc=none smtp.client-ip=209.85.128.45 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QDzU1rGw" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-493be0fbcc5so45125e9.0 for ; Tue, 14 Jul 2026 01:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784019415; x=1784624215; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QyZuaZgVMmJscBeBh04gUUQoTYZ+pKlntaOnTL9z2uQ=; b=QDzU1rGwcGHjRgUu2G2eO+H6rzNfk5sXyLlHwqHJU/VmpwyqwKJCjgh8WLk8kZUjiI L1BCG1Ukiwivnn14BnQxZikH+XgbMv7snaLOp98/IZFTN7RKtx5E1DgpS+m29HUsrS2/ sYeFPZi8YX9ihfT8lbhbd9UcTOECiRkMABj6im3SEW41n6BpmMtyEdW2onmZB53zdzE0 inowy7TExWvz7ku/m5cftRka5zJAP5eQXOS8EnWWUEWAxzb5uSMyYhOX1iyRlAmHBN6Q AtW4SfqA9EkIDr+FLxijOq+gmz3vLvX/FffVksA3uahsoQQpi111QT4fD3xL7zrCAf4w ENHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784019415; x=1784624215; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QyZuaZgVMmJscBeBh04gUUQoTYZ+pKlntaOnTL9z2uQ=; b=YFf1wYknoTSoGet43+vLlXh/cc0rCHTpuhFQ+7URnR5a7EeCWqWfdVzoPRg1VdaIOD wH/dvUx9ULoFwAq+wFO6QHOfUgANyqbyoo34zWm2ndjWIxQuUvUwzNOw01Fwl8J6AMLN +9orcQic2LisdjyQtb5BmMRIu8TP+KkPulGM9/XAjv99REWvEsPu1XyMJby4UASCTyM9 tGqwt7u8gEogMu8h3l8/uqIKmAFkScL1FD32SWFO1xYx6zs+5CjJ9S4Wm17lASahuH6G eICMhpbAyzUfeWDMQOm3wkpRvxuaHRJ1HWq8XaWXzQFHlJmN4OqFNJW1E2iLoEkmqopX RXTQ== X-Forwarded-Encrypted: i=1; AHgh+RrZbyvfi81kXDNZM/wlO/qhMFNjFR9O4p2HFNAW88Z0j9Uj/ejzHdVXFjjBzny/axWHX7UHr3caLFKN44o=@vger.kernel.org X-Gm-Message-State: AOJu0YxmUl48MMjlOZk1/sWqxGAHO/LBMiS+2n4I0nXTTggZ+bs1Fmku QXK1rb6dOf1QP+MAWQ671/crQkMr9X8K3Ny02wLxWBcfWgURYuVA4MiTXik/QLh0Eg== X-Gm-Gg: AfdE7cmtA7NIFDZWtOcitvckXXDk6cn8RGCy9n1WF67cJdsIxYUehD1QUo7+Z7EK/3I +DeDerruUl9fLGbOzsOvLNfF/B9Sd9NH2l6pJA90b8/hODrkkyZDB8B3rvt1lB8HjUwKYNg1VD7 P1YBX6jYfhtq6EEqfNSw4S4Raamrdh4TLJH3RyBZ4VcUf0wmovMQDooHMJcTO/GfkdOfK2ankNP XBAd+RrDJd+Mt62getCGg2lg1I0TPPKCe8zEl/iaWqi/JcdgTvwz1ctnvzJwMX7ey12e/H/pYv5 mw5pMxKuCEQZUGAQeA0LLvEZBogwN5Tu4QPbgfappGBWVwHNtrpq1xglVJF2Zp4DrrnPMCeXgCu jNvPcFhJhnalGaY+XwNFVWsPWQn1ZkyhPbpLJ4xPIr4EBbbCELqxMG/32JqV3RPKTd12aaDrRI0 7vvplllLy5Q7tnrC68MgKj230mVdeaDUyPQw9Age6QB+YiDtgz X-Received: by 2002:a05:600c:8b6f:b0:492:668f:410c with SMTP id 5b1f17b1804b1-494688928b1mr1719985e9.10.1784019414601; Tue, 14 Jul 2026 01:56:54 -0700 (PDT) Received: from google.com (220.60.76.34.bc.googleusercontent.com. [34.76.60.220]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4950a2f9402sm64121965e9.13.2026.07.14.01.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 01:56:53 -0700 (PDT) Date: Tue, 14 Jul 2026 08:56:50 +0000 From: Mostafa Saleh To: Vincent Donnefort Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, joro@8bytes.org, jean-philippe@linaro.org, jgg@ziepe.ca, mark.rutland@arm.com, qperret@google.com, tabba@google.com, sebastianene@google.com, keirf@google.com Subject: Re: [PATCH v6 08/25] KVM: arm64: iommu: Shadow host stage-2 page table Message-ID: References: <20260501111928.259252-9-smostafa@google.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: On Tue, Jul 14, 2026 at 09:47:24AM +0100, Vincent Donnefort wrote: > On Tue, Jul 14, 2026 at 08:29:38AM +0000, Mostafa Saleh wrote: > > On Tue, Jul 14, 2026 at 09:16:29AM +0100, Vincent Donnefort wrote: > > > On Mon, Jul 13, 2026 at 06:19:24PM +0000, Mostafa Saleh wrote: > > > > > > > > That would walk the table twice, first time with a massive map, then > > > > to unmap the pages that was just mapped, issuing TLB invalidations > > > > for all of those, also as the IOMMU page table code never frees tables > > > > that means we would immediately exahust the IOMMU pool. > > > > > > Well the massive map is pretty quick we would mostly just allocate the PGD? And > > > then it would be just for the subsequent unmaps to split the blocks. So nothing > > > to be freed really and no risk to exhaust the pool. But if you put the calls to > > > the host_stage2_* functions that's pretty transparent. > > > > Not for the IOMMU, everything is mapped with a leaf mapping, because > > Ha Ok my bad, I didn't get that! > > > the pgtable code does not support splitting blocks, this is something > > I plan to add support for in a follow up series after this one is > > merged along side other optimizations. > > > > > > > > Just to make sure I am clear. Here's what it could look like: > > > > > > in iommu.c: > > > > > > int kvm_iommu_stage2_idmap_init(struct kvm_s2_mmu *host_mmu) > > > { > > > u64 addr = 0; > > > > > > for (i = 0; i < hyp_memblock_nr; i++) { > > > kvm_iommu_stage2_idmap(addr, reg->start, IOMMU_MMIO); > > > > > > addr = reg->start + reg->size; > > > kvm_iommu_stage2_idmap(reg->start, addr, IOMMU_READ | IOMMU_WRITE); > > > } > > > > > > kvm_iommu_stage2_idmap(addr, kvm_phys_size(host_mmu), IOMMU_MMIO); > > > } > > > > > > in mem_protect.c: > > > > > > int kvm_host_prepare_stage2(void *pgt_pool_base) > > > { > > > ... > > > > > > return kvm_iommu_stage2_idmap_init(mmu); > > > > > > /* > > > * From here, all the changes to the host stage-2 will be reported to > > > * the iommu driver > > > */ > > > } > > > > > > On the pro side: no custom walker and we really couple the iommu idmap to the > > > host stage-2 map. > > > > > > On the con side: As you've pointed out, we'd need indeed the iommu to be ready > > > early enough. > > > > > > If you want to stick to the snapshot function, could we have the walker to > > > first walk the hyp_memblock? the .arg could just pass if we are walking a MMIO > > > region? That would avoid that find_mem_range_from() and I believe would > > > massively simplify the snapshot walker. > > > > > > > I see, let me try that. > > > > > > Unrelated to this, but while looking into option#2 I see that > > __pkvm_guest_share_host() does not call either of the > > host_stage2_set_owner* so that requires another explicit > > pkvm_iommu_host_stage2_idmap() call. > > It does! it calls __host_set_page_state_range() which calls > host_stage2_idmap_locked(). But host_stage2_idmap_locked() does not call any set_owner variant, so __pkvm_guest_share_host() would require an explicit pkvm_iommu_host_stage2_idmap() call. Thanks, Mostafa > > FTR, I don't really like __host_set_page_state_range(). And we removed it > recently from our Android tree. Because there's just a special case in > __host_set_page_state_range() to cover guest_share_host. So we can easily > replace all the callers with __host_update_page_state() and and call the > idmap explicitely in __pkvm_guest_share_host(). > > > > > I still plan to use option#2 in v7. > > > > Thanks, > > Mostafa > >