Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp21382pxb; Wed, 14 Apr 2021 08:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTJoZVgYjm0xgQ7EsjUNEfB5mSirONqoZvQkK/bMuV0i0dx6+kb8RMAlO8d2jI85jA+F0l X-Received: by 2002:a05:6402:1ad9:: with SMTP id ba25mr32174098edb.264.1618414307255; Wed, 14 Apr 2021 08:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618414307; cv=none; d=google.com; s=arc-20160816; b=IiyAxUpnBX/SUUOHOksOmIC/KCdSmsbJ2nmru1x+uY8K2iRt6tjuh4yeOg9s3LwlWe yGAsvX3oVDAnwCN5Z/nUlaydlurO2YC7I2bFVGsQHExvorIUhHguxV3+rpgzCiYpDidc 03w7jt9EMfZkiVtOjlaKYZ8vKvH16oftxjcxLh8Mui/ub6vb50UwdlTvVH69IGLzrOhZ F2Y5KbIYNI7JMkzSfyAt8jInI+9T8n+Xdl80FN5NWY2SLTPklhYEDR2YU+s/CK3K+dKn /9Dix3fU7XbUptpGiYQxNpDwZwLwQRrVGY39gvfzIwkOmrz240PNlbBAcNipuMOWrKKX k+aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=8Dck1aGAF9pMfcgXcTXkcWdI6ZRxgpnEF/q2x/fG1Nk=; b=ntIaSJiXe5fVv6/gMcpYwSDlGCOblElGhZXay/aKR0JfNDU2TX8MZXqmvUTAomnGuF wlOpJF5aNO28VS9sRmIzNn+0RvY08r1Egyd3mKqbZxHyBIwDrq6PYvXnCXE6peCIfXxI cctF5KqHCOj2X07yqM2e4zwbVcQdBxP6euBuHr3AgfV4HmNMsU3bMprnXS1te9CGgVZs ZzC5vsWVv6VJ0F+orEnvtIZKsTQ9WfMferX5oNSOEbuIgQ8bNU0wHAlYAwlHsqRBx+b+ CIE53aA17RIiOMaY/Cx7zBDwdkwu2TkwU5M7hyWKQRtm/IbM2s1Oto6OKehUoUPGfGN3 vtCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si12394931ejq.139.2021.04.14.08.31.14; Wed, 14 Apr 2021 08:31:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232040AbhDNL0M (ORCPT + 99 others); Wed, 14 Apr 2021 07:26:12 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17334 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350478AbhDNLZ0 (ORCPT ); Wed, 14 Apr 2021 07:25:26 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FL0Sk5KsszB0mp; Wed, 14 Apr 2021 19:22:46 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.82.32) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Wed, 14 Apr 2021 19:24:56 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , Subject: [PATCH v4 08/16] arm64/mm: Split asid_inits in 2 parts Date: Wed, 14 Apr 2021 12:23:04 +0100 Message-ID: <20210414112312.13704-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210414112312.13704-1-shameerali.kolothum.thodi@huawei.com> References: <20210414112312.13704-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.47.82.32] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Julien Grall Move out the common initialization of the ASID allocator in a separate function. Signed-off-by: Julien Grall Signed-off-by: Shameer Kolothum --- v3-->v4 -dropped asid_per_ctxt and added pinned asid map init. --- arch/arm64/mm/context.c | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index 8af54e06f5bc..041c3c5e0216 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -412,26 +412,50 @@ static int asids_update_limit(void) } arch_initcall(asids_update_limit); -static int asids_init(void) +/* + * Initialize the ASID allocator + * + * @info: Pointer to the asid allocator structure + * @bits: Number of ASIDs available + * @pinned: Support for Pinned ASIDs + */ +static int asid_allocator_init(struct asid_info *info, u32 bits, bool pinned) { - struct asid_info *info = &asid_info; + info->bits = bits; - info->bits = get_cpu_asid_bits(); + /* + * Expect allocation after rollover to fail if we don't have at least + * one more ASID than CPUs. ASID #0 is always reserved. + */ + WARN_ON(NUM_CTXT_ASIDS(info) - 1 <= num_possible_cpus()); atomic64_set(&info->generation, ASID_FIRST_VERSION(info)); info->map = kcalloc(BITS_TO_LONGS(NUM_CTXT_ASIDS(info)), sizeof(*info->map), GFP_KERNEL); if (!info->map) - panic("Failed to allocate bitmap for %lu ASIDs\n", - NUM_CTXT_ASIDS(info)); + return -ENOMEM; info->map_idx = 1; - info->active = &active_asids; - info->reserved = &reserved_asids; raw_spin_lock_init(&info->lock); - info->pinned_map = kcalloc(BITS_TO_LONGS(NUM_CTXT_ASIDS(info)), - sizeof(*info->pinned_map), GFP_KERNEL); - info->nr_pinned_asids = 0; + if (pinned) { + info->pinned_map = kcalloc(BITS_TO_LONGS(NUM_CTXT_ASIDS(info)), + sizeof(*info->pinned_map), GFP_KERNEL); + info->nr_pinned_asids = 0; + } + + return 0; +} + +static int asids_init(void) +{ + struct asid_info *info = &asid_info; + + if (asid_allocator_init(info, get_cpu_asid_bits(), true)) + panic("Unable to initialize ASID allocator for %lu ASIDs\n", + NUM_CTXT_ASIDS(info)); + + info->active = &active_asids; + info->reserved = &reserved_asids; /* * We cannot call set_reserved_asid_bits() here because CPU -- 2.17.1