From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 7327443803E for ; Tue, 14 Jul 2026 08:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784018853; cv=none; b=Df2nvReoTRd+YvAyE4ejmfpWlbgrz2NlntCdTe4raVcKIZ2gHueb/U1OGyrIDnE4okMkQ5MHs9oQmROIeTg23K3jxwDdRTpbA8FjCv+bHEmD9pHcJwU3uMNZCP/Yzo/AN8gj+HmZBOXxb/534BKvMI/IWa0vsFFn4uAbYmKd+Dg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784018853; c=relaxed/simple; bh=BQvQA28/hQsJiQl1Rts5gtoQqHvUkzf0m5MoHJQ0PZE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p4O0VBbWVuZ8JECK2Z3+7UX0ga++gbC+f/PfHNy1MYaUVcvsyZrnSdO7TcP8FRRYrPy1EMU515/XvSG3mrxkOMZH4+Rv01ZxG2ki+Z7XYBxgLf0Glf+pr5M4guOh07+mhjunKunnD+n6Y8go+lQfvBgE7CY+3QafXCFZ+ZMAaDI= 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=c0eO580Q; arc=none smtp.client-ip=209.85.128.53 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="c0eO580Q" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-493e497643fso3706315e9.0 for ; Tue, 14 Jul 2026 01:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784018850; x=1784623650; 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=m879ws2jFhHLOh/9WRuezyCL3r8TAQ3JpjmFZyFa7tw=; b=c0eO580QVqiwLIc2hH1MSvkOK88mjkqLUhHD05hgmJhrWwsJFTltUbZxVTP56FHAox gC4yDO4XISGsEcFv3U+vwnpVBSySZTvfMigjyMRCUrnx5Ymx2ANhLk12sIRpq8lZsZKd yasPhVq36l634x6fyW/KvK7i7AV/7uqEwr7sMIJlN1b89zkegDevQvijt5ndxd6xrbCy KGKSzmKD/OKPiL3ZCMzbAme9FWAzxOMve/UKNRdYiC44k3KyCgwh+GBDVMm2m5iRU9YC nb/oMQwuVZBB7PhAtta9GBuf1+c+dFbniY5t/oZ89jDrYgYd4XGTGcpzg9Q8T7wcjrX4 KKKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784018850; x=1784623650; 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=m879ws2jFhHLOh/9WRuezyCL3r8TAQ3JpjmFZyFa7tw=; b=Ne2CUOq8P77jHUb/ovuBLZ/kl0OBUZbfL1KocRlUgfIok/HwxNcHJHm3Y9Xj0ofbDL DIM0CAkOyuLMSEsu1jJT6ty9hLPlmWdsQ4BVmQCKF2LWEnbNP1oiYerHyv5k+PIicAqW 1ix/n2UMUnqSwJiqdsJwACmIJKQdznyHgDVrfSV+WlD0oPKtLyRu36//FjDuR9sLD7Aq IsLM72NaOvEqn/g1mQfsp5FehKIOfsydCh/x4Mjh1eXXuBiv5OMBIY8P3Dab36ymU66P EfV6m9e7p6S1bO+jOgIK/WmZM06uRFcdsoI0odrm1Cj3AiiRRKfqqw4GZ5G0+G6EBwa3 r8Ww== X-Forwarded-Encrypted: i=1; AHgh+Rqf34PoefjY41lDX/EaI9/fq7GK/SddNsO8fEuZH4rqZO/5mqXMhERU60eGVfZbqfVo6Qj1UQm2aSJLujk=@vger.kernel.org X-Gm-Message-State: AOJu0YyydOMej9e68/20BP1B4yEMJWMsETvqzRIhIuv5sae5rIxizcRC PpIfFEpHEApMGurCGgUuNeGklri4qRajsAWd5I7ckkvWbGjA5xCqAxnnGn+E6PWznQ== X-Gm-Gg: AfdE7clOXluKTxSnhYah42ZoVBalKhOGta3UOkXDcQbl43tpVDCt1jtgScRULv6rwbX ZAWrG7e6XNQny+NsdMI33NJ69xw+R0sApJ+YcuZN/ssHzAn/I8qPUeIC2ry6amxonzEtAB8rMN6 achUsOFKiHE63dxHlEGTvA54dL6Qr5uwxGPPJJMMrUcM4kKxeLiTYbx9Y1m4LVJVnZazu1nQXES VL2wr+GcZ4LTQ4my3nVeadP1G7zOQVQ9HNYsIgSLGiAFvZcKw1p808/QGH4QhSnPaOP4W3zFbWF bPxr7cRYF2l6XGuOtIPlAk8RzDU3IE1phppNbAVvfkkxYMP8wUGkBFIrtKLs+GWFw1g98QXmzRM 607cxL/Sj7eGVvTIbWZ1PsmXVHhZliGQ3DWcUJVPAPsccwg+K4OAwJ/HFdy+L2NRqTOF4MmnKgi 9XXrUV0zez7e7VgF/5l2cIJdkj4INiJp9/IRW1j5JgkT5TfqmyXp8= X-Received: by 2002:a05:600c:4f8a:b0:493:f7c8:eae2 with SMTP id 5b1f17b1804b1-493f87e6e9cmr127818785e9.15.1784018849325; Tue, 14 Jul 2026 01:47:29 -0700 (PDT) Received: from google.com (137.69.77.34.bc.googleusercontent.com. [34.77.69.137]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-495086ca93esm59158715e9.0.2026.07.14.01.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 01:47:28 -0700 (PDT) Date: Tue, 14 Jul 2026 09:47:24 +0100 From: Vincent Donnefort To: Mostafa Saleh 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-1-smostafa@google.com> <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 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(). 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 >