From nobody Fri May 3 12:50:49 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1566589006; cv=none; d=zoho.com; s=zohoarc; b=nX+1alwtJHQjylKYoNBMi7RBRyn9I6QsD7U7dJnT77RUvVwyu7wthVDV56uEWfkjMhJqtOymgiLOGOoYXwMlmQTmYpw18rlFWLqYNQQEU9pkWFl6psDY8yvLVXQRNzqww/Se5DnzvPTuAhiBdvlpI/5C67OiTkT2w5TjFTGLUwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566589006; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=dPN+hFLcEQOAvxfnIWxHMOBY/LCyWyFpmCKTlCaP5Vo=; b=X4oMiHJwp8nJVkvs/8BI92H5282o0PAs4h3MK1IYJcAOP1mx5ZmtgBMW537eKjMY1zDh4/n7EA5q6av5Iw0dnPNLO6OhlUcOUWqKYwflsjQLYlWu1+KFvgp06/EaWwfJtSQlA9wRovXEK0Ta4Bgx49K6A9omiAGusFHHJZy+pR8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1566589006782169.53306485852283; Fri, 23 Aug 2019 12:36:46 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i1FLK-0006Ij-VQ; Fri, 23 Aug 2019 19:35:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i1FLJ-0006Ie-S7 for xen-devel@lists.xenproject.org; Fri, 23 Aug 2019 19:35:25 +0000 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 26b64d2e-c5dd-11e9-ac23-bc764e2007e4; Fri, 23 Aug 2019 19:35:24 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id e24so9853929ljg.11 for ; Fri, 23 Aug 2019 12:35:24 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id p11sm776322ljg.56.2019.08.23.12.35.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Aug 2019 12:35:22 -0700 (PDT) X-Inumbo-ID: 26b64d2e-c5dd-11e9-ac23-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=fCVqVHEhBkanFdhxk/CCfvx1us5ijc5HbsAZWizYqh4=; b=m45kzTK9GWldQwwyn/B2e5Vq51m38dpx9uCgrpAI3JEYD4HQSFU9kzbSG4v/SvGeUI fq9IaOROfgI9S6xBuFJlYshRLQ82OgaxohFlAWCb+VVsNckIGOm57MBCbps6SQIW37i+ sbagMKXf6QfsgO5XrPq5idOzjx+ZK0dnUg9ATqo9HaONHnqyLBkQ8oR56iCtJa4XYr1/ sEUR3Yd13OeIoGJ0ksgRPuDhPoVv0KKNakUBesmdNkC5yXs7NR1t83ojEMpgej95ANlm wIaB/DYPJN6d2E3r8ZWSZoKAAm4bFH2aZwUCUICGKJI4L5+iOZpIqr4vm8v/NOG2kj9D S+1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fCVqVHEhBkanFdhxk/CCfvx1us5ijc5HbsAZWizYqh4=; b=ZtuZZnU54tgcnyC3d2a8WFPu98LS+D8+rZtmk4eZJZ2AXMyzvf136+mjKOofnDQKtG LWxeB3o4GAm3NETSn7JSXb8EK6TwwEAkyapYNh6FFln8F/c07uP6kjDfRCoozgigOpMf 8HlHRwpfn38btdfvrSeBCZoQnwQT2xKDSLyjC+GOS08C70sn8fWTS4ay0rQtE6LgRkij CaqQ6foz3D+gea64fXc2rdYb06xLZidIjzNgv0gYPCrOqi0Ts1eM/ZLtZLRu6APhBGbV g1YMuiZmJdPjDatb1WcVkerNMtpBskmZyAqYlCmlHFY9vaCHlSZUt2qHELPdbWKp2QBl Akqw== X-Gm-Message-State: APjAAAVmhkRQuGe3RIRXziLsZjrR+9WFq+RFD0taYiw8MLgxyQwegGcO gRPd9b0wk/N3frJ1isQcxv70Wpyo X-Google-Smtp-Source: APXvYqzOjqG7pb6ZMRBGO/8xpF7N1n6xV2zQEeHvdBNyarlb0aDm410yb4AMRnDGY1vtb1GwN03g4Q== X-Received: by 2002:a2e:948:: with SMTP id 69mr4027171ljj.39.1566588923235; Fri, 23 Aug 2019 12:35:23 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Fri, 23 Aug 2019 22:34:52 +0300 Message-Id: <1566588892-5305-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [Xen-devel] [PATCH] [RFC V2] xen/arm: Restrict "p2m_ipa_bits" according to the IOMMU requirements X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Oleksandr Tyshchenko There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "p2m_ipa_bits" value as is. But, there are cases when not. In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic. First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "pa_range" according to the restricted "p2m_ipa_bits". Signed-off-by: Oleksandr Tyshchenko CC: Julien Grall --- Still RFC: 1. Patch assumes that IPMMU support is already in. 2. Not checked for the SMMU. Changes since RFC V1 [1]: - Don't update p2m_ipa_bits by the IOMMU drivers directly, introduce p2m_restrict_ipa_bits() - Clarify patch subject/description - Add more comments to code - Check for equivalent "pabits" in setup_virt_paging() - Remove ASSERTs from the SMMU and IPMMU drivers [1] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg02078.h= tml --- xen/arch/arm/p2m.c | 33 ++++++++++++++++++++++++++++= ++-- xen/arch/arm/setup.c | 11 +++++++++-- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 19 ++++-------------- xen/drivers/passthrough/arm/smmu.c | 16 ++++++++-------- xen/include/asm-arm/p2m.h | 8 ++++++++ 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 2374e92..f742d9c 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -34,7 +34,8 @@ static unsigned int __read_mostly max_vmid =3D MAX_VMID_8= _BIT; =20 #define P2M_ROOT_PAGES (1<> ID2_IAS_SHIFT) & ID2_IAS_MASK); smmu->s1_output_size =3D min_t(unsigned long, PHYS_MASK_SHIFT, size); =20 - /* Xen: Stage-2 input size has to match p2m_ipa_bits. */ - if (size < p2m_ipa_bits) { - dev_err(smmu->dev, - "P2M IPA size not supported (P2M=3D%u SMMU=3D%lu)!\n", - p2m_ipa_bits, size); - return -ENODEV; - } - smmu->s2_input_size =3D p2m_ipa_bits; + /* + * Xen: + * Set maximum Stage-2 input size supported by the SMMU. We expect + * the P2M code will take into the account the IOMMU requirements and + * choose suitable "pa_range". + */ + p2m_restrict_ipa_bits(size); + smmu->s2_input_size =3D size; #if 0 /* Stage-2 input size limited due to pgd allocation (PTRS_PER_PGD) */ #ifdef CONFIG_64BIT diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index f970c53..cdcf83a 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -165,6 +165,14 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx) /* Not supported on ARM. */ } =20 +/* + * Helper to restrict "p2m_ipa_bits" according the IOMMU requirements. + * + * Each IOMMU driver should report the maximum IPA bits (Stage-2 input siz= e) + * it can support. + */ +void p2m_restrict_ipa_bits(unsigned int iommu_ipa_bits); + /* Second stage paging setup, to be called on all CPUs */ void setup_virt_paging(void); =20 --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel