Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp21423pxb; Wed, 14 Apr 2021 08:31:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIQ6YyAJ6aZ/CZXlwu7BNpbMqca2qKKiq0KzBuYhPr24CqTyORx0JO2qVfLjIygfS07+et X-Received: by 2002:a17:906:98c1:: with SMTP id zd1mr18012481ejb.447.1618414309800; Wed, 14 Apr 2021 08:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618414309; cv=none; d=google.com; s=arc-20160816; b=pOyDvhulUUDmvR6RJo2bYQPVPKxnjxP3ieLD0NJJq5jr09GeKz2YSIMkH0NVBWJtkO wEQ7jMDS0WB9KSaeZHLGroF9XZWUkCgFb7KmDXm+DXdH8CIAyeWVOsgOR2T237YPBb46 a0LPG1E7IjrjZ+HQnI+/Khqb7FPyJxdAh1dHr9RMf8wSJUdWaZqAKg8C6lTez3afqQGa dQjKVQiF7JHw+HJJlA5bjagGrahoKvtwcfzKRFsf0E+qBuINMoiVG/A3zoiqTZ/zWfWg KCUlfY6dtFV4PLggKhq2vbYpmbjVewgh4TZWNcez+CVS7zj4yolLiZDxfi59SnBf9zBv rP0A== 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=rxwo2BrbSFHCdplYfEyxQVyzMwcqJgIOXqedaFAvHvo=; b=lYcyr8PzMlhqChob6OSjSj/ZmpLl9N5ILhBPQzXYAp2QdJ8BB+T6SbLBQ03f6tVHMx OYClR2mZ4klBSo2ND57mSNVGFG10l+xzmogJ9hLqndX96v1uyp2Ei5QuUSdWcuh31ORq rlizl/94av48YHAitpUyJ30c+BtIHzIMyKD7cOaMmOB50dgsFHjLc1x8HGyVk6AjX5pe B1zZBNuh2Hh6gngs+y5fG0z82CC7rU4okuqtiRf9JaY+RBoTTpSbynvVVgnwcJ8TI2b3 iQIKiHZ/gV9Vg0qyhotXK/1uAAiYjzoMULG0/VlvQDK478Np6K0xaT31Tt+BX8MqaPZ1 CXZg== 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 u16si14207357eje.499.2021.04.14.08.31.18; Wed, 14 Apr 2021 08:31:49 -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 S1350504AbhDNL0Y (ORCPT + 99 others); Wed, 14 Apr 2021 07:26:24 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:16912 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349023AbhDNLZh (ORCPT ); Wed, 14 Apr 2021 07:25:37 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FL0TQ3NHCzkjcG; Wed, 14 Apr 2021 19:23:22 +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:25:04 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , Subject: [PATCH v4 10/16] arm64/mm: Split the arm64_mm_context_get/put Date: Wed, 14 Apr 2021 12:23:06 +0100 Message-ID: <20210414112312.13704-11-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 Keep only the mm specific part in arm64_mm_context_get/put and move the rest to generic functions. Signed-off-by: Shameer Kolothum --- arch/arm64/mm/context.c | 53 +++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index 40ef013c90c3..901472a57b5d 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -307,20 +307,21 @@ void check_and_switch_context(struct mm_struct *mm) cpu_switch_mm(mm->pgd, mm); } -unsigned long arm64_mm_context_get(struct mm_struct *mm) +static unsigned long asid_context_pinned_get(struct asid_info *info, + atomic64_t *pasid, + refcount_t *pinned) { unsigned long flags; u64 asid; - struct asid_info *info = &asid_info; if (!info->pinned_map) return 0; raw_spin_lock_irqsave(&info->lock, flags); - asid = atomic64_read(&mm->context.id); + asid = atomic64_read(pasid); - if (refcount_inc_not_zero(&mm->context.pinned)) + if (refcount_inc_not_zero(pinned)) goto out_unlock; if (info->nr_pinned_asids >= info->max_pinned_asids) { @@ -333,45 +334,61 @@ unsigned long arm64_mm_context_get(struct mm_struct *mm) * We went through one or more rollover since that ASID was * used. Ensure that it is still valid, or generate a new one. */ - asid = new_context(info, &mm->context.id, &mm->context.pinned); - atomic64_set(&mm->context.id, asid); + asid = new_context(info, pasid, pinned); + atomic64_set(pasid, asid); } info->nr_pinned_asids++; __set_bit(asid2idx(info, asid), info->pinned_map); - refcount_set(&mm->context.pinned, 1); + refcount_set(pinned, 1); out_unlock: raw_spin_unlock_irqrestore(&info->lock, flags); - asid &= ~ASID_MASK(info); - - /* Set the equivalent of USER_ASID_BIT */ - if (asid && arm64_kernel_unmapped_at_el0()) - asid |= 1; - return asid; } -EXPORT_SYMBOL_GPL(arm64_mm_context_get); -void arm64_mm_context_put(struct mm_struct *mm) +static void asid_context_pinned_put(struct asid_info *info, atomic64_t *pasid, + refcount_t *pinned) { unsigned long flags; - struct asid_info *info = &asid_info; - u64 asid = atomic64_read(&mm->context.id); + u64 asid = atomic64_read(pasid); if (!info->pinned_map) return; raw_spin_lock_irqsave(&info->lock, flags); - if (refcount_dec_and_test(&mm->context.pinned)) { + if (refcount_dec_and_test(pinned)) { __clear_bit(asid2idx(info, asid), info->pinned_map); info->nr_pinned_asids--; } raw_spin_unlock_irqrestore(&info->lock, flags); } + +unsigned long arm64_mm_context_get(struct mm_struct *mm) +{ + u64 asid; + struct asid_info *info = &asid_info; + + asid = asid_context_pinned_get(info, &mm->context.id, + &mm->context.pinned); + + /* Set the equivalent of USER_ASID_BIT */ + if (asid && arm64_kernel_unmapped_at_el0()) + asid |= 1; + + return asid; +} +EXPORT_SYMBOL_GPL(arm64_mm_context_get); + +void arm64_mm_context_put(struct mm_struct *mm) +{ + struct asid_info *info = &asid_info; + + asid_context_pinned_put(info, &mm->context.id, &mm->context.pinned); +} EXPORT_SYMBOL_GPL(arm64_mm_context_put); /* Errata workaround post TTBRx_EL1 update. */ -- 2.17.1