Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4129592rwi; Mon, 17 Oct 2022 01:44:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6JCoj5WpaketzBek6wv8y/uLW9seR8+ewFvelTjxdoO+2CdJeHdB3qiUbETWhh7+j0DBp8 X-Received: by 2002:a17:907:1689:b0:78d:e460:1d98 with SMTP id hc9-20020a170907168900b0078de4601d98mr7592613ejc.451.1665996297066; Mon, 17 Oct 2022 01:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665996297; cv=none; d=google.com; s=arc-20160816; b=nKIcFYWCmrCqIrglXCQ4m9TsjALFA+SsOmfGE32ev6pze508fK+R+6QJLaDM3vqctp X4RQ/muTXHDbSA/+DSHN9Rt8rtM8h/JoYRIrufq/x3B86DKJwwthogAQ41hs0/X/GN+Q FTpff2r9RPcyXRqRh/1RzE29qD9eONRbjSGWVYuLoW1lOAlc14Lsq0puzMsNRwcHDgU3 0RVzjMkmxLv7k+GuYC9B3OjlLgsTc3w8TZYV/iIKe2IcRl3yLkXkr/AFJjmZOF5giU28 Rb/ikLLQvIHMdcX+XRf5WHbZpI/VyqSwA3mSVzp3qPSqoPCtDG25q3/Ay90bf+y6QVHI jllQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a056402525200b00459ad800c2csi9795852edd.589.2022.10.17.01.44.30; Mon, 17 Oct 2022 01:44:57 -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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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", -- 2.27.0