Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4754300ybl; Tue, 4 Feb 2020 01:12:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxQxSb8c3s2QOYNQCnm84VQjVaDZ1EMrzfq5txwYqgTzCl0WD+Oihytlv+xXi3p2t4OvOV1 X-Received: by 2002:a9d:5888:: with SMTP id x8mr20355495otg.361.1580807575148; Tue, 04 Feb 2020 01:12:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580807575; cv=none; d=google.com; s=arc-20160816; b=t7XW8AvECDaKzy1Wb00s1XQ+QjX1R//3KPK/K8P6tXCAh72Q0PEhc7QSKbbLrrfVAq Zu1xl/UdRowtOci5pbXECaUhGreS9/bPSpyods9pPJqywy4T+muSdWflivg84DqTo0J6 hybY3Y3siySDYrMOQoep99OgKB2DLn1Wn1Vou6XRUpEKFLeqDawjqy+NxJPbZhihyPaM 4WVzk5RIwLcHlZBDLGjAyDlLBysk7lx61UZcdpLbk6W2bSROZ/IpzUNg25eHk/rYIutR cKNGtCcMMmBNErJF5vhaD9x4Rh1RsfqcYSoINAvKwJX5VMe4m52zGoIzbFX/wDVjSnEk lFRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JMgX31ZcwOo34A354crObqeIGCt2Ve1eIZr7TGY9QYg=; b=UzWmuofUWRFtEcm9dSFuinEENDnIQbspRtmJuWyF3/AeCylBlkXVsmd+es9Hz5J/DQ giFfK+xtPnxFr18wHsVQ9ZjhFw7crqCZf0GDmBpKW7uTLqyB25TWmjmI7CcQIxNirWxu QY5CgdGDCNijB7Ce3fFD2MiWLsyhGrhtuUf5egJkWW6FLjC7qrstWYmRzx10ekIfI18Q 3x9qFJrjHMIsssbi08+3HBgSoX1ntljaJ8Y3jh7LEPeOSxjj0xB9jWi4Enk/HEGerTBz YTtyPXW8hxj726bYvLgWXWPaT415/pmQh4ar0JIMbZYtd7FNlCwH0fXqvyNgIKLSdedy Fm9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si9677338oir.9.2020.02.04.01.12.43; Tue, 04 Feb 2020 01:12:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbgBDJLs (ORCPT + 99 others); Tue, 4 Feb 2020 04:11:48 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9692 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726513AbgBDJLr (ORCPT ); Tue, 4 Feb 2020 04:11:47 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D4AA320A607416FCA880; Tue, 4 Feb 2020 17:11:43 +0800 (CST) Received: from DESKTOP-8RFUVS3.china.huawei.com (10.173.222.27) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Tue, 4 Feb 2020 17:11:36 +0800 From: Zenghui Yu To: , CC: , , , , , Zenghui Yu Subject: [PATCH RFC 3/5] irqchip/gic-v4.1: Ensure L2 vPE table is allocated at RD level Date: Tue, 4 Feb 2020 17:09:38 +0800 Message-ID: <20200204090940.1225-4-yuzenghui@huawei.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20200204090940.1225-1-yuzenghui@huawei.com> References: <20200204090940.1225-1-yuzenghui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.173.222.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In GICv4, we will ensure that level2 vPE table memory is allocated for the specified vpe_id on all v4 ITS, in its_alloc_vpe_table(). This still works well for the typical GICv4.1 implementation, where the new vPE table is shared between the ITSs and the RDs. To make things explicit, introduce allocate_vpe_l1_table_entry() to make sure that the L2 tables are allocated on all v4.1 RDs. We're likely not need to allocate memory in it because the vPE table is shared and (L2 table is) already allocated at ITS level, except for the case where the ITS doesn't share anything (say SVPET == 0, practically unlikely but architecturally allowed). The implementation of allocate_vpe_l1_table_entry() is mostly copied from its_alloc_table_entry(). Signed-off-by: Zenghui Yu --- drivers/irqchip/irq-gic-v3-its.c | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 0f1fe56ce0af..c1d01454eec8 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -2443,6 +2443,64 @@ static u64 inherit_vpe_l1_table_from_rd(cpumask_t **mask) return 0; } +static int allocate_vpe_l1_table_entry(int cpu, u32 id) +{ + void __iomem *base = gic_data_rdist_cpu(cpu)->rd_base; + u64 val, gpsz, npg; + unsigned int psz, esz, idx; + struct page *page; + __le64 *table; + + if (!gic_rdists->has_rvpeid) + return true; + + val = gits_read_vpropbaser(base + SZ_128K + GICR_VPROPBASER); + + esz = FIELD_GET(GICR_VPROPBASER_4_1_ENTRY_SIZE, val) + 1; + gpsz = FIELD_GET(GICR_VPROPBASER_4_1_PAGE_SIZE, val); + npg = FIELD_GET(GICR_VPROPBASER_4_1_SIZE, val) + 1; + + switch (gpsz) { + default: + WARN_ON(1); + /* fall through */ + case GIC_PAGE_SIZE_4K: + psz = SZ_4K; + break; + case GIC_PAGE_SIZE_16K: + psz = SZ_16K; + break; + case GIC_PAGE_SIZE_64K: + psz = SZ_64K; + break; + } + + /* Don't allow vpe_id that exceeds single, flat table limit */ + if (!(val & GICR_VPROPBASER_4_1_INDIRECT)) + return (id < (npg * psz / (esz * SZ_8))); + + /* Compute 1st level table index & check if that exceeds table limit */ + idx = id >> ilog2(psz / (esz * SZ_8)); + if (idx >= (npg * psz / GITS_LVL1_ENTRY_SIZE)) + return false; + + table = gic_data_rdist_cpu(cpu)->vpe_l1_base; + + /* Allocate memory for 2nd level table */ + if (!table[idx]) { + page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(psz)); + if (!page) + return false; + + table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID); + + /* Ensure updated table contents are visible to RD hardware */ + dsb(sy); + } + + return true; +} + static int allocate_vpe_l1_table(void) { void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); @@ -2957,6 +3015,7 @@ static bool its_alloc_device_table(struct its_node *its, u32 dev_id) static bool its_alloc_vpe_table(u32 vpe_id) { struct its_node *its; + int cpu; /* * Make sure the L2 tables are allocated on *all* v4 ITSs. We @@ -2979,6 +3038,15 @@ static bool its_alloc_vpe_table(u32 vpe_id) return false; } + /* + * Make sure the L2 tables are allocated for all copies of + * the L1 table on *all* v4.1 RDs. + */ + for_each_possible_cpu(cpu) { + if (!allocate_vpe_l1_table_entry(cpu, vpe_id)) + return false; + } + return true; } -- 2.19.1