From patchwork Mon Oct 17 08:12:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfeng Ye X-Patchwork-Id: 3265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1328742wrs; Mon, 17 Oct 2022 01:16:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6eQxCV/kyO0d2U05V72WFNhXxmz+HQh+2JDta1FIBIzd9VhvL3tw9xI2t8Q0SUUnB08whc X-Received: by 2002:a17:902:7104:b0:17f:cdc1:f4c3 with SMTP id a4-20020a170902710400b0017fcdc1f4c3mr10630387pll.149.1665994565989; Mon, 17 Oct 2022 01:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665994565; cv=none; d=google.com; s=arc-20160816; b=Pt3YX4xbNn4IPYS02OHJOb8mj+bFTylDM+zQiGzkNrrRbrnDv5O+NaCjUi/SSKF1DU gYBEHFOboYB4e7tNLRwQhGD5s/zOj4GmGSr1DEWMTWAAV0KnO7STHxJOoYtToietLl9j BnIhlabDgscp63F6DaY2Ji894K1MHhh7jjOv+hfZ67xhxIfULQp5CevaGmBD1awUqvSD 5U9jJcbvs8Ju3YZv7fKCyN2IIG1XS8gWRbVC7eJWBEXXdqymMJSsC7iYyMubziy5+QVQ WGWoJVlgqX+ZCWXR2A8zwCjXSyC7E013i47ceYwWlHvBb+PppOzY7Yb2ojITT0hPyI1K 2k5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=6Z8Sgf3+GM2e/85SKhfDPYv3Tncqk9eUSqze23soaV4=; b=H4j2EwSgQJA6bzXWp1o109QfhXUGTouTl3zn605rUdSEaAtnqnGm26QSDNwmS0rrVs Cw9Qtx23YKtyypESd4pPUfMpW4AM4rKX16ilYpv5K5f8kgN95PPUU4CRvm6sdo/6wYg7 6H76K1BmpgiNaDi6l/1FMmfjX0IGnVi0hzHbv0MahAb+q5aikNN6HmpZqxRKFj98K1dU pelV4/2Ejdoxnv5m9lzd1q3BMHPkESNbFGmzhTEvjYhNXdaK8imSyqxTiDJ36AhnEJAF J0qMhOkF81lYzQxeY6olaDu/i5Dk2SRTXRMJw551Sc6ne2BnocZT9ZcldsEjcglhCzvJ PGyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s10-20020a170902ea0a00b0018010c3d7e3si12965632plg.404.2022.10.17.01.15.53; Mon, 17 Oct 2022 01:16:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbiJQINq (ORCPT + 99 others); Mon, 17 Oct 2022 04:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbiJQINi (ORCPT ); Mon, 17 Oct 2022 04:13:38 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B48B35C372 for ; Mon, 17 Oct 2022 01:13:36 -0700 (PDT) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MrV4h2sCDz1P7YB; Mon, 17 Oct 2022 16:08:52 +0800 (CST) Received: from huawei.com (10.44.134.232) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 17 Oct 2022 16:13:03 +0800 From: y00318929 To: , , , , , Subject: [PATCH 2/5] arm64: mm: Extract the processing of asid_generation Date: Mon, 17 Oct 2022 16:12:55 +0800 Message-ID: <20221017081258.3678830-3-yeyunfeng@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221017081258.3678830-1-yeyunfeng@huawei.com> References: <20221017081258.3678830-1-yeyunfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.44.134.232] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746921917888999578?= X-GMAIL-MSGID: =?utf-8?q?1746921917888999578?= From: Yunfeng Ye To prepare for supporting ASID isolation feature, extract the processing of asid_generation. it is convenient to modify the asid_generation centrally. By the way, It is clearer to put flush_generation() into flush_context(). Signed-off-by: Yunfeng Ye --- arch/arm64/mm/context.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index 8549b5f30352..380c7b05c36b 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -102,14 +102,40 @@ static void set_reserved_asid_bits(void) bitmap_clear(asid_map, 0, NUM_USER_ASIDS); } -#define asid_gen_match(asid) \ - (!(((asid) ^ atomic64_read(&asid_generation)) >> asid_bits)) +static void asid_generation_init(void) +{ + atomic64_set(&asid_generation, ASID_FIRST_VERSION); +} + +static void flush_generation(void) +{ + /* We're out of ASIDs, so increment the global generation count */ + atomic64_add_return_relaxed(ASID_FIRST_VERSION, + &asid_generation); +} + +static inline u64 asid_read_generation(void) +{ + return atomic64_read(&asid_generation); +} + +static inline bool asid_match(u64 asid, u64 genid) +{ + return (!(((asid) ^ (genid)) >> asid_bits)); +} + +static inline bool asid_gen_match(u64 asid) +{ + return asid_match(asid, asid_read_generation()); +} static void flush_context(void) { int i; u64 asid; + flush_generation(); + /* Update the list of reserved ASIDs and the ASID bitmap. */ set_reserved_asid_bits(); @@ -163,7 +189,7 @@ static u64 new_context(struct mm_struct *mm) { static u32 cur_idx = 1; u64 asid = atomic64_read(&mm->context.id); - u64 generation = atomic64_read(&asid_generation); + u64 generation = asid_read_generation(); if (asid != 0) { u64 newasid = asid2ctxid(ctxid2asid(asid), generation); @@ -202,14 +228,12 @@ static u64 new_context(struct mm_struct *mm) if (asid != NUM_USER_ASIDS) goto set_asid; - /* We're out of ASIDs, so increment the global generation count */ - generation = atomic64_add_return_relaxed(ASID_FIRST_VERSION, - &asid_generation); flush_context(); /* We have more ASIDs than CPUs, so this will always succeed */ asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1); + generation = asid_read_generation(); set_asid: __set_bit(asid, asid_map); cur_idx = asid; @@ -405,7 +429,8 @@ arch_initcall(asids_update_limit); static int asids_init(void) { asid_bits = get_cpu_asid_bits(); - atomic64_set(&asid_generation, ASID_FIRST_VERSION); + asid_generation_init(); + asid_map = bitmap_zalloc(NUM_USER_ASIDS, GFP_KERNEL); if (!asid_map) panic("Failed to allocate bitmap for %lu ASIDs\n",