From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 B4F77426693 for ; Tue, 14 Jul 2026 08:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784018635; cv=none; b=EDXNieyPi20BpR2bg3g7si6VqOTZGx13tZJ518Gbcv9LMca+YJwJzX2YqP6d6RaHlWmNvBfWrqGnaGloxY462bV4kCB6CthoeCNoKaq5g+dJjCNBQdEpAl2PcVshzGSKquGcqvCVLWgbcc2etVxNefrgZWYrj0m4U2sw9MdhzWg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784018635; c=relaxed/simple; bh=LW7r6RfvIDbXgE6CChJMnLdwS5MHDeWEV+jm5LGMJ04=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SKw25R3ecqZ4uLMiUQZ6f/Dly//rdF1vGXovWY4NhfEpt3jDBBEJUC4/fBbw+oScfJ12cT4iz3BGm4tVa/bVGHKC1z11IuP9iBsew9yLjL8lCHV0U2ZqpoDH4SEXh/l646rY/MnK4CYXR/LX4W/6tJ7HZmkl8VUZdH0jeQQK0Io= 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=DJo//kiX; arc=none smtp.client-ip=209.85.221.46 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="DJo//kiX" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-47df6a5202bso2401994f8f.0 for ; Tue, 14 Jul 2026 01:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784018630; x=1784623430; 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=+HCqftvyh10fMpY6IqpqVPtQHg/FJB6+bDbXuzWB9b8=; b=DJo//kiXSm6aN5MiIyc3RWAIG3fUPlNnI5Rk0A5mxrvOd9lslrcLztZLSG5EC8lT8J jsRBTBX+INxeuTgndGRQeu1Th+WGu0Cdu44JXVpEUq+NCJlDU4j20IXHEJ7XKVbhZVeV a30Kv8gfgX/4hE0u82T9wZ85x/DHRythHUkFOB1cjIVkp8VQEli9NoClGyXQ5THSqDit diAFrCUjpeY0NduBqaiHyvgOLCN/Siv+qSeTYsRaUsqXDin/LMxFEiOpuWctfCymkVYb UopvifRhg8y+wbPGGEsWSJi4cEYNGZTVX3pMf0HjNzkwQmk5wVBF4xIbKrIQd21Ze4JX 2ckQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784018630; x=1784623430; 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=+HCqftvyh10fMpY6IqpqVPtQHg/FJB6+bDbXuzWB9b8=; b=R8k298KbmtAxvgszb3Jg6mBwd3h2iQETdeZiGOadg2RjYpcIgMS8zmxt2fQs75HZet uF3Wz+V4YgJRDpw+Gojp0zKG924+30ripIFnrRxBJJz0sGaRDFkJKQimiW/U7S6UEPb7 rIXMLyN3n1wR8j0tepBYHgTnGS00IvAJGCsiuLQq1GnPcU2okJx8in7buw6msOszI40h P+z28GzxN39WRycN4Drr6z/Pez7+rD3aQWtw1fruijaIV3lgzWEZXIlW/7ZQRv3O/0sT v3mPFMtrTwcvLo2fRwG4l5aC/uQ8eSwOlo0gCwTfgt7tEqAqhpCd8zgt5Ony5AXL7UmF nkMg== X-Forwarded-Encrypted: i=1; AHgh+RoCc3RBB/KC/2yZJ9UaV0zwwpb6Ii6sJIXpgSKPFIUmfAdks4lBiYNQghplOrsMKvsLm+XqiJBpldV3tEM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxd1LkucKYnT0lu1GmWbRhRdk0OkPPzKSJpgAzTsoHvi+aOGzG2 r4RXjMrKlfjZtWibf0wGdMx7vmdugVcWAu3p1hBrxphWzh42yW6kvrSJgUIPwR8Tkw== X-Gm-Gg: AfdE7clTE5AHTswuWtrU0Hl5l2PdRaXXIxdSmfJEoCkkH8utsiUsycSQCRou1ySN0Cm 9feYkKjVyUsAf0B9RklkoL1bpCChhY1r8GI+6AJb13ixT7z1AqOEyURv0ceGiShCH0vNaM2OO+q PKWN9iIbV8EI3Dk9TSiqr3Y8Zm0T4hmXRbLlyGyPS/gVMrpz33z+YejwOMt/4TRJcSC9rzygqlj ruBZ99EkwCtKU6LJ5NpCCo0UWCwOyIR1t7WzpLJqZ4ODk+eGzMMipMv0FDopjVo5EhLPYGJy9JT k2hbBLgn7QPv3yMb0Sq/lWXK7T8XWpRiQnj6uaVnXPrmULaiaNY2MgVg9Xc8a3HR5eSgnswD6r8 4Z8wvZmtvssD3pkhtU/bbxh5uhH3f3HL/FrChRxvWr7w6w/NirYCxTyDN0zwzEjvAl7JMAO0Kib JaFiD1IMRJN68cRs776LMwqYKc1+73IjDvec+pqir1v4e5qJtK3SY= X-Received: by 2002:a05:6000:2006:b0:47d:edab:a721 with SMTP id ffacd0b85a97d-47f2dce9698mr13848050f8f.31.1784018629391; Tue, 14 Jul 2026 01:43:49 -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-47f464c7c96sm6294914f8f.33.2026.07.14.01.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 01:43:48 -0700 (PDT) Date: Tue, 14 Jul 2026 09:43:44 +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 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: [...] > > 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. 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"? > > At the moment, this is set from the command line which is not really > best effort as the driver later confirms how much memory it needs. > > > > > > + > > > +/* Number of pages to reserve for iommu pool*/ > > > +static int __init early_hyp_iommu_pages(char *arg) > > > +{ > > > + if (!arg) > > > + return -EINVAL; > > > + > > > + return kstrtouint(arg, 0, &kvm_nvhe_sym(hyp_kvm_iommu_pages)); > > > > How about using a memory size here with memparse()? This would be more > > transparent for the commandline which can work on different page-size systems. > > Makes sense, will do. > > Thanks, > Mostafa