Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp94731imm; Thu, 21 Jun 2018 14:35:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIY9h+PMKCwVLJ5n+SCotesa0a4PNSlWl+CTF97THEtoVgXqSahV6RyegQkdr/6BMfY7Gro X-Received: by 2002:a65:4382:: with SMTP id m2-v6mr3014666pgp.68.1529616900857; Thu, 21 Jun 2018 14:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529616900; cv=none; d=google.com; s=arc-20160816; b=kws7EKiK6FbwaVIjM7RtdPxncAA9bJ9XPJzGBvYW5XOc7+SJBXDrCCk7HwkPTz9kvT bVzwD4ml0TR4sxdKpokIe0NtYuRo5C1wTMOtbrLYFyFwGBG/wdokK/BjwtsnTIzOQL7B YlDD8yfqVzJop41Tmiv7Ddm50jhuoxB4V51ej3qyyoew9Zc6WWOnPBlw2JbxN2JMMeRT xw67WYBU0OAG4f9KNH5RMcXhbHo3mcVHQb/zme5BDY7bUZ6lF+6lzMr1NnYDYlZnvB9w /NL/b+QQcw8exuDBYxqHkLOhLH7dwBZ+2FRfM4qju4TH3pI4n86H9DFaRC3FLes0hwkr rDCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=u4pWhv/Ox/6vMdukP9HQnAGQXeBsSLLtCnwBKGoq2GQ=; b=bhkNd2ux+WcD81J7rVC92Iziol0RLSwSsUvmOwoYseRtoomC5MpmETwIIl9vR3geJO feJN8Vt2iNqav3VLca/WSVpyZiVJlXjGFrpKl+CeeQGPU7tsDzhqAH7SX0Fo8L/h5YWM Vn6RBWMi6MC9XcG40SzvbPc8sOElba9xTyrn06MnGBSl8KHP6hmbi+HYukG2U4F1pCJH dVlt/vGBE0wSCRS3U+5rsdaRRBRP6wpDNl3b3mrOJwPodwJvfHBdPNCxqGAIqQxVXFC6 IDEbrTP/m1Wwoi9bfj9N2hs7bxJgqqj88s5NG+SIfIO6FtFKgIBW+do3O/YEkuDan+lh 5d+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XUW3s9pF; 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 k12-v6si4700852pgo.405.2018.06.21.14.34.46; Thu, 21 Jun 2018 14:35:00 -0700 (PDT) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XUW3s9pF; 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 S934087AbeFUVc4 (ORCPT + 99 others); Thu, 21 Jun 2018 17:32:56 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41794 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933962AbeFUV3K (ORCPT ); Thu, 21 Jun 2018 17:29:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=u4pWhv/Ox/6vMdukP9HQnAGQXeBsSLLtCnwBKGoq2GQ=; b=XUW3s9pFjzZ8uvOrslZPfk+j5 VohCz8aDrwdeiLEhWQcGRzIIhJjcjzr6xjd3Wvyg02dV0TLdf+grz8ONMAg3y2b4wjrb04bEWBW70 I7JLyipi7mr56+q7Xp0gAVQXuPrXD93OMg3MqLG73NKcTrdQ+huwBHy9rkiOPgi9JfHkJ0PqwgFjY 6Li+FZZVuMrn4xCm5EetXF/EILy83ikPwm2CtofdI0ZAFI4V4JWrS9kPzWWzfRUPlZsVxM961YUcH O8nmUVFCiWV7ZD6+zZ8hzNMb1gRoraOLi2t6JISZq3qaKk2PM4vNJVxVbBwaTRpBuZ9ULL2Y1VQeR 2Jqz9lOXg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW78f-0001br-87; Thu, 21 Jun 2018 21:29:09 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Aneesh Kumar K.V" , Nicholas Piggin , Thiago Jung Bauermann , Ram Pai , linuxppc-dev@lists.ozlabs.org Subject: [PATCH 13/26] ppc: Convert mmu context allocation to new IDA API Date: Thu, 21 Jun 2018 14:28:22 -0700 Message-Id: <20180621212835.5636-14-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180621212835.5636-1-willy@infradead.org> References: <20180621212835.5636-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ida_alloc_range is the perfect fit for this use case. Eliminates a custom spinlock, a call to ida_pre_get and a local check for the allocated ID exceeding a maximum. Signed-off-by: Matthew Wilcox --- arch/powerpc/mm/mmu_context_book3s64.c | 44 +++----------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/arch/powerpc/mm/mmu_context_book3s64.c b/arch/powerpc/mm/mmu_context_book3s64.c index f3d4b4a0e561..5a0cf2cc8ba0 100644 --- a/arch/powerpc/mm/mmu_context_book3s64.c +++ b/arch/powerpc/mm/mmu_context_book3s64.c @@ -26,48 +26,16 @@ #include #include -static DEFINE_SPINLOCK(mmu_context_lock); static DEFINE_IDA(mmu_context_ida); static int alloc_context_id(int min_id, int max_id) { - int index, err; - -again: - if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL)) - return -ENOMEM; - - spin_lock(&mmu_context_lock); - err = ida_get_new_above(&mmu_context_ida, min_id, &index); - spin_unlock(&mmu_context_lock); - - if (err == -EAGAIN) - goto again; - else if (err) - return err; - - if (index > max_id) { - spin_lock(&mmu_context_lock); - ida_remove(&mmu_context_ida, index); - spin_unlock(&mmu_context_lock); - return -ENOMEM; - } - - return index; + return ida_alloc_range(&mmu_context_ida, min_id, max_id, GFP_KERNEL); } void hash__reserve_context_id(int id) { - int rc, result = 0; - - do { - if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL)) - break; - - spin_lock(&mmu_context_lock); - rc = ida_get_new_above(&mmu_context_ida, id, &result); - spin_unlock(&mmu_context_lock); - } while (rc == -EAGAIN); + int result = ida_alloc_range(&mmu_context_ida, id, id, GFP_KERNEL); WARN(result != id, "mmu: Failed to reserve context id %d (rc %d)\n", id, result); } @@ -172,9 +140,7 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm) void __destroy_context(int context_id) { - spin_lock(&mmu_context_lock); - ida_remove(&mmu_context_ida, context_id); - spin_unlock(&mmu_context_lock); + ida_free(&mmu_context_ida, context_id); } EXPORT_SYMBOL_GPL(__destroy_context); @@ -182,13 +148,11 @@ static void destroy_contexts(mm_context_t *ctx) { int index, context_id; - spin_lock(&mmu_context_lock); for (index = 0; index < ARRAY_SIZE(ctx->extended_id); index++) { context_id = ctx->extended_id[index]; if (context_id) - ida_remove(&mmu_context_ida, context_id); + ida_free(&mmu_context_ida, context_id); } - spin_unlock(&mmu_context_lock); } static void pte_frag_destroy(void *pte_frag) -- 2.17.1