From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 18D6E42B750 for ; Tue, 14 Jul 2026 09:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784019693; cv=none; b=kdYEBc8j0kCEAMSB9F5sqXyl2nqbWSsHtzzSkbcnRqBEuwmSx58kb2y+0kzszqM570ynPj5MGjosU8kSuxlLGR1blribG2ky26q0xkoOqUNwzIMMcIfQq76bFsdRgpOUbuqxvhct2flPviaG8Cq8YTU21xI862+uAERdDxpyhmU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784019693; c=relaxed/simple; bh=kWVgGEIbpxAYFfST1lTz9GGVME1BqRppJ7/sq2UQtm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JqDl9fg68ONSeKWYEPu/Of9tuIDnIsi17LhJ6qrDmEmMKynbVNUvFT9Mi1fOh5TjF8tRReb2+iJw8ABu/puAF0HknXD+a6uNlUC21FjgTL0SW6+fc6TC408wBY3VUznflMVQ3AD77qQWLxBnCLTbkGQx98na21Un7n+aOF+XeCI= 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=lwyobcAm; arc=none smtp.client-ip=209.85.128.44 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="lwyobcAm" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493b8d99342so40885e9.1 for ; Tue, 14 Jul 2026 02:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784019689; x=1784624489; 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=2Qjndy5VhZcNYSpHMbWFubMhTfFLLtbQVF7eA7Tx3wM=; b=lwyobcAmbhPVi0y1e60H1Ydew0EEgjG+wskSD8yBRKzTG5BgYsJxvJGLhjjWzm/fve qmhqD7JJXDSlo9eA90Ws8R71QzBH4YMFVkPYaP1b9ncW4OUqkcnt2jhotf49dNPGLXmK q90E180GY8+tA7ZaUBWyil4hq5uRyzeEOIdIzM2BEpDkCdkcOCpXyVeyAIjLUdYZF1sM 1tKGq71DiejetOgwbCuaoWCNGAL763g/3vnK3Qg86x8Dy3qVNQTpN/qYUcF7R63KEZmy I59pd1LTJKbFcqiSzXEuGhkNvaa2keIm7jdCVYZWrqkPBZadM2MAx209ugJpSdY98KAp 2bzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784019689; x=1784624489; 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=2Qjndy5VhZcNYSpHMbWFubMhTfFLLtbQVF7eA7Tx3wM=; b=cudHzSpiQqlBDLGIXijwREKTzgxaBmSkKNFEWJfsL6aOXDVImJN/hKAKxReaFg4Bd8 X4S/XPx6/hWUA1b2hyC1anQ2k7prvIZlzDP/mPtF0j1drFfuEKHwq4AF6BEzv42O7vle ZxPWg2BTcs0SsP7J7X2trY2dETytxny2Yu+pXwi1fx+k2TfRpLZhJuKMQr/VR23jQTm4 eVhxoIIyu607ScyIuZ/3KGS2AEAk9hADxKjAaJ2MJxfDcMXNM2YgUseGKr9MbS51pshU HfKYwSwd66XkPUOv+PmxTbCYwuo77j74YovGpUXqOcfHL76i0vgbwPJAr3g+E8JFo44/ iq6w== X-Forwarded-Encrypted: i=1; AHgh+RokO+Om3PPFE+WeVNI8PPnqhoHTh2jj9GsuOos4+tAsOQnLq6rTV1IziC2rhe6wBe9ZvfoAj4FzFtznpYQ=@vger.kernel.org X-Gm-Message-State: AOJu0YweQS/Lkt+Q3CCXMdKNZGJ0pvDU4estPwWd1UOLwoCtafHeVn8+ C8iAT8qJr2noKEYxS83JdwEZ/izkNW14vZ5CNl5i9+6jvzmhdq/q5uzjSyVS+G1IWg== X-Gm-Gg: AfdE7cnXf0YORwHwVNcQ/1yD1+63cY88nsIEmUtWCsEVC9MrcNehAbj5O5b+AzC2ZeT tw85YltIzXgicbnRZ8+B966gLf21o6osj5Maqn2Tty/1Zg3AifZrmqsrXiHS7az/K6z+a/tvn8S jqS1H1oo86y0ki7R1bpWlJtkf8Zq9dErsJ6Ek5c2U4Bj1evxWMbRtEmdFHxmUmO05Jysr7i4O2p r6WXmr4GwcgkDuEQW9bYYHOB6bktr/a+777J82OIHotNqbu5NCSd8IG+CEv7d8iTFoCg0iFVTQA i9Zb502JKlhAxvypE5ODJ45kkfgb+w6tnwdoSiMyVeKmKDj12IGW2M4hgHNXqJOWsq5pki0ClTr kmdIaIlo4rKLKFDAG0VPgtXpPjQRkFOITLe1Oyf9kiQYQAYK8sMX1UVFvJNMG9/jkDRTd55xjzz mjao0OxK3epAKiwuhM73+uU177hvswhg09KwadXRcz0dknGHfm X-Received: by 2002:a05:600c:3589:b0:492:203f:a378 with SMTP id 5b1f17b1804b1-49465abb636mr1712515e9.8.1784019688365; Tue, 14 Jul 2026 02:01:28 -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-495087366c0sm116771555e9.7.2026.07.14.02.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 02:01:27 -0700 (PDT) Date: Tue, 14 Jul 2026 09:01:23 +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 09/25] KVM: arm64: iommu: Add memory pool Message-ID: References: <20260501111928.259252-1-smostafa@google.com> <20260501111928.259252-10-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:43:44AM +0100, Vincent Donnefort wrote: > [...] > > > > nit: kvm_iommu_init uses nr_pages. > > > > > > > { > > > > guard(mutex)(&kvm_iommu_reg_lock); > > > > > > > > @@ -21,6 +22,36 @@ int kvm_iommu_register_driver(struct kvm_iommu_ops *hyp_ops) > > > > if (kvm_nvhe_sym(kvm_iommu_ops)) > > > > return -EBUSY; > > > > > > > > + /* See kvm_iommu_pages() */ > > > > + if (pool_pages > kvm_nvhe_sym(hyp_kvm_iommu_pages)) { > > > > + kvm_err("Not enough memory for the IOMMU pool, need 0x%x pages, check kvm-arm.hyp_iommu_pages", > > > > + pool_pages); > > > > + return -ENOMEM; > > > > + } > > > > + > > > > kvm_nvhe_sym(kvm_iommu_ops) = hyp_ops; > > > > return 0; > > > > } > > > > + > > > > +unsigned int kvm_iommu_pages(void) > > > > +{ > > > > + /* > > > > + * This is used very early during setup_arch() before any initcalls > > > > + * or any drivers are registered. > > > > + * This value is set by a command line option. > > > > + * Later, when the driver is registered, it will pass the number > > > > + * pages needed for it's page tables, if it was less that what > > > > + * the system has already allocated, the registration will fail. > > > > + */ > > > > + return kvm_nvhe_sym(hyp_kvm_iommu_pages); > > > > +} > > > > > > Could we actually estimate the memory needed, based on the allocation for the > > > host stage-2 and an estimation of MMIO coverage? This would allow the whole > > > thing to run without setting this value as a best effort and to make it > > > optional, which is surely more user-friendly? > > > > Not really, this abstracts the IOMMU, so it does not have to match the > > host stage-2, in addition that the SMMUv3 driver requires extra pages > > for other in-memory data-structure. > > What I thought would be to take __hyp_pgtable_total_pages() and then add on top > of that memory to cover the MMIO region. As of "here's memory we think your > driver will need" and of course that can't take into account any > "driver"-specific struct. I wanted to isolate the concept of IOMMU and SMMUv3 in the core code, so we should not assume how large the page table would be (it does not have to match the CPU topology at all) > > To be fair, that is a bit weird to have memory reservation so early for a > "driver" but perhaps that is okay because the pKVM protection is only complete > if we have that "driver"? Yes, there has been multiple attempts in this series, we used to allocate this pool later which was worse in my opinion as it was not part of the pKVM carveout and still needed some hacks to make it work. Thanks, Mostafa