From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 77C9A327C18 for ; Mon, 13 Jul 2026 16:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783958622; cv=none; b=pKuSTVOR/lHm07HsskA1SL3HxziXDXZj8eKL0gzORAUPYDb9wXNJgAVMhZD3nJrJPQGMabl0/0RZu66+drUV/sizTpc+bnIfjhHx7fj29PVIb2bv/gy7hysBVKRzw4fMsOOAheMPuiQykBYnjEDfrS/1sNYn4TcN/iURUuZAZ24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783958622; c=relaxed/simple; bh=Pylmx3Gl6thtuFKM5DfdQyuRxFbrHIWdSRzSM7xJa5I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KOHaHEOaTHIyS+BZrcUBkoBHLITpepB0XFCTDWFC+FUM+BrL7SFWDx21PsEnjhSUCYRuPsYKn4hyTcZbMApPoIa1r4LmQ54a74dasH+OCnNeGc6l3A6RDxH1hgWMKsYp9FCY9JsIWkwaCeYqpM+rQamGi2vDiwm499aHgunjckg= 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=cvOq2Wbg; arc=none smtp.client-ip=209.85.221.42 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="cvOq2Wbg" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-47122683cf3so1822528f8f.0 for ; Mon, 13 Jul 2026 09:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783958619; x=1784563419; 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=56E+7FMMOWqDmBxT+WtZLGSI2R/SROVQv8aPW35xP7c=; b=cvOq2WbgKKD7L09P0Tvc0E84u5dVuxO9gVovY9eHUZuGgIxQV35d83JVS76QJEHRj8 rIbLoH/+WMpORwwSXKKpzdHcPFrJV9GqC92ConeNlpwU9jAeCIoexuVjTEnoYtiPAxhV 9GxKYcC0PQ1pULvhiApdeF7ZXiCpmqyhaBYwKpF+OPQdB1oOPfRoSfFE9oJLKeqLoSTE hMD3V4g4qEb2Rh4XhOPDKqu2ktdhdC0xMD4M8zUAhSKvc7eXev03O0BSOTihSNhbvwBv E1ym+sCXrLAPoEcmfyTQseTVEio7Qo2HRhpJEjcAeij4IY40BzrvDIVGFA5FsUPgyBYS mS0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783958619; x=1784563419; 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=56E+7FMMOWqDmBxT+WtZLGSI2R/SROVQv8aPW35xP7c=; b=CEW+pl5P4btNs8BX76O/SlqHi/TtxYovxs9LKQ4GvcqrUXsG6Amyb10MPjTpunHTqx 9cgP89IzNKjmhcluXwZfaZF1HTay2XMiJr9e57j1aK7OWTwSRtI37RxeSsGI0wnGZPMi +Ykl85OMzzfBGnlz+R/otkaL6kJ4TvWpka+vnABgxyOQR+KfwXyeHoHe2vhouVDsZv5G uqw/KHDeQpNzgXw7WIwE6AlXlALI1WSlOW71e0sqchrbhAH/zJuWK+8gI6ikMASDGA04 vYJKY6nO1T0z+3GdzCZrRya2gniEq1PW6g67PB5q3C9DS4WOYq00/0/7VVKTTMeYCBcK CeBw== X-Forwarded-Encrypted: i=1; AHgh+RoAUMo8TZ9JcXTOeqUvFNFT3kc337+KBxWl3nJPJ0tFT93vI73UrcJpKD73UAzgzzo4+zdvbloEGXxZkgM=@vger.kernel.org X-Gm-Message-State: AOJu0YzU5WNTVUulH0+1DjQ5sjCTNzNvFzWKrEh9oBiep+9+gz2zZQEU yOhh7shlkO87ARQWfTiRzw6v9FUoGtXlCYIbGU7F5/JDLhilFw+YgQHKvOOH/YZaTQ== X-Gm-Gg: AfdE7clr3fGDHQ4J+LIXHhxxk4nu2RuvV/H9+I6Zm4nS2VsVzmOmjey9a4HyZ0qxET0 O3kwUjDzvuTf+QVGmEWhOX7mztntYIp6CWevChlIIWzRPR8Ms6m/fTzBTulSlQW3L/MUOkfsibs ruFXJb6juaTCN5SQv1CPEIgf5tfnkCu3SKuYQvgEo0wisTJURIJtCUR681RQ6SNR2tQZL3EdiN4 XlHuNMCqDJM2aYZFPiqIJ1OqaDo6eO+WVOV3WiSUxU4vppq52AgXVQOLntyKQ2O9L02CFo7uJc3 YBjJwOCnnrId/9CDpIlEo5u2b4bpP8XqGXsDhS+ekuOoM9rVI4CEWrs9gKKwJU1cTW2FWVWrHv7 2QvTCGQFVIXNKSlAqGMmBcJPEuNNuv4S5lZUl7IYXx1IjSVtW8hXvZzVAMT24E3uY83vWENeIEd rq4S8fNPDU+Olt9JHEY3ywGTFq5ecHlJpkQMbeSSq3nOWC/RDdNog= X-Received: by 2002:a05:600c:1d89:b0:493:f29d:d591 with SMTP id 5b1f17b1804b1-493f8837f95mr107335125e9.39.1783958618287; Mon, 13 Jul 2026 09:03:38 -0700 (PDT) Received: from google.com (137.69.77.34.bc.googleusercontent.com. [34.77.69.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f464b7f84sm323988f8f.27.2026.07.13.09.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 09:03:37 -0700 (PDT) Date: Mon, 13 Jul 2026 17:03:33 +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 Mon, Jul 13, 2026 at 03:51:07PM +0000, Mostafa Saleh wrote: > On Mon, Jul 13, 2026 at 04:14:55PM +0100, Vincent Donnefort wrote: > > On Mon, Jul 13, 2026 at 02:00:31PM +0000, Mostafa Saleh wrote: > > > On Mon, Jul 13, 2026 at 02:24:19PM +0100, Vincent Donnefort wrote: > > > > On Fri, May 01, 2026 at 11:19:10AM +0000, Mostafa Saleh wrote: > > > > > Create a page-table for the IOMMU that shadows the host CPU stage-2 > > > > > to establish DMA isolation. > > > > > > > > > > An initial snapshot is created after the driver init, then > > > > > on every permission change a callback would be called for > > > > > the IOMMU driver to update the page table. > > > > > > > > > > > [...] > > > > > > > > + */ > > > > > + if (pte && !kvm_pte_valid(pte)) > > > > > + return 0; > > > > > + > > > > > + if (kvm_pte_valid(pte)) { > > > > > + prot = pkvm_to_iommu_prot(kvm_pgtable_stage2_pte_prot(pte)); > > > > > + /* If the range is mapped in a single PTE, it must be the same type.*/ > > > > > + if (!addr_is_memory(start)) > > > > > + prot |= IOMMU_MMIO; > > > > > + > > > > > + return kvm_iommu_ops->host_stage2_idmap(start, end, prot); > > > > > > > > Do we really need to do that when is_memory()? > > > > > > > > fix_host_ownership_walker() by calling host_stage2_idmap_locked() and > > > > host_stage2_set_owner_locked() should already handle the memory region. That > > > > would also get rid of kvm_idmap_initialized. > > > > > > > > So this one here could only take care of the MMIO? > > > > > > > > Overall we would have a common point of synchro which is > > > > fix_host_ownership_walker() after which the host ownership is ready for both > > > > CPU stage-2 and the IOMMU? > > > > > > > > > > I am not sure I understand, this is another empty page table, so we > > > have to walk all of the host CPU stage-2 page table to shadow it in the > > > IOMMU. if you are refering to the case where it handle zero ptes for > > > memory, I can drop that but it will not change much in this logic. > > > > In fixup_host_ownership() we already walk the hyp pgtable to know what needs to be > > map/unmapped from the host stage-2. Can't we rely on that for the IOMMU > > page-table as well? > > > > As of, fix_host_ownership() could handle the host stage-2 __and__ the iommu? > > fix_host_ownership() only walks the hypervisor page table, and fixes the > hypervisor pages in the host. Yeah, Looking closer I don't think my proposal simplify things so much in the end. > That means that the IOMMU page table has > to be fully populated first, then we unmap the donated pages. > That seems more complicated and it feels that decoupling the IOMMU > logic outside of this would be better. Why more complicated? That's actually another solution I was thinking about, to just map everything as soon as possible and let host_stage2_idmap_locked() and host_stage2_set_owner_locked() unmap what is needed here. (and also in __pkvm_host_donate_hyp_mmio()) We wouldn't need any specific setup walker for the iommu at all. > > Also, I rely on the IOMMU init to be done at the end of setup, so we > do not have to clean the IOMMU init if any other part of KVM fails. We could just leak those pages if it fails? > > > > > > > > > > > + } > > > > > + > > > > > + /* In case of invalid PTE, we need to figure out which part of it is MMIO */ > > > > > > [...] > > > [...]