Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp94441imm; Thu, 21 Jun 2018 14:34:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIR71FNlFBTI5dl8SB1Po9Mw9a6zfYq5UxH9b7hUwCV6jaok9fxQOYjmgRTMd7/F/sYH8zC X-Received: by 2002:a65:4042:: with SMTP id h2-v6mr23291608pgp.78.1529616880831; Thu, 21 Jun 2018 14:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529616880; cv=none; d=google.com; s=arc-20160816; b=Rkq/JivPQK/L3ChRrKb+EHR9d0FPzibejDe6edG7V1BvDS1AAgpdLXTV6gDlYckpay HA56PMfy3YXEOdA8b4YCFH82ZlWuUVRvRh4lHXgo6QvQqJsm++UdrXJ+CBjX7xKY1OAI h1tz6FdlUViTleF672o7EM2NuUEs+FeV9d6DIUMwtxbprjmlPeNW9EEf6fYgP5+HvYCZ GK4IzyKcwg3cG31ZT2ZOavszyf+svSKbRrbiAHZkOQoGhppconkOyy0E2sUBAaQdzMte ooXx6ejGT6kQyf7wDBVH/rUb11Jc2WlZxu5QLVFBxdrbgf8EmU9U67Le96/vZaVHV1tC I4kA== 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=1EaM/i1jLGF7+lD9c29vyKvpm+6T4mHOB7ylOLRXdo4=; b=h68Ya2c8KroARX6FD7L5UzIwX0ZoTi5HQKQAxnkk/5aPLcIMFj+IF6nhdD3VtjdQvB oq3NX5RJUjIefE/1jRgUVTbiA+QKrUfFgv7iInR+uBgK4/5gOll//+V1Onyo6Jpmu2F8 0n85+nPmuQ0vAyJGjA5mnLiuGbc9zTQI867Rk8U2rPM0ZOCl9cplUC9XKzYjMez8MWz6 eC8rtsBNAqDhfeuaa04dqCaARq+VJT22HxX66W7IflJ223Kz8oyaxgEr+Y1RjAefuSa+ Hs4NsVxZFpVOnj7YNLSHeFvUFIWHOmZZ+O2P3vWcR/lCvR5Uwe7pvzDtQ1Gmai0htzlY faeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=csxFjey8; 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 x32-v6si5555945pld.435.2018.06.21.14.34.26; Thu, 21 Jun 2018 14:34:40 -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=csxFjey8; 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 S933983AbeFUV3L (ORCPT + 99 others); Thu, 21 Jun 2018 17:29:11 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41760 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933879AbeFUV3I (ORCPT ); Thu, 21 Jun 2018 17:29:08 -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=1EaM/i1jLGF7+lD9c29vyKvpm+6T4mHOB7ylOLRXdo4=; b=csxFjey8zI5Ni6w6tEyuaEn4z L9mYMfOnv0xJShdI5ZzbnxCSngz9171iy1QFPPKvV/El7FzDLbDftphOqirkVH2h6JZnLnAyjLmUw bc40Xsh/8nIyXKU37YZ0ZaqXxkvmO5hV763f8jiSPmz39R1g1DT6EEv/0jtn9u80sRcD62MwlJ9GN v9psYBHskGfTu7L8Ph6OJEqGxE1nuPxE9ohqdZ/U78DxM9y2WbXAE0zMnVaejBOwt/5S+MAkNq5ct TpoCn4oxt1nlw/ehfFlyNS/lyzZdstb5Mf0bN0U6Ga2A2lE5mR39JQZ1zaUxgdPpIOIGd3PLxfTAn Wpw6PJULA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW78e-0001b2-3G; Thu, 21 Jun 2018 21:29:08 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , "Eric W. Biederman" , Christian Brauner , Greg Kroah-Hartman , Eric Biggers Subject: [PATCH 07/26] devpts: Convert to new IDA API Date: Thu, 21 Jun 2018 14:28:16 -0700 Message-Id: <20180621212835.5636-8-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_max() matches what this driver wants to do. Also removes a call to ida_pre_get(). We no longer need the protection of the mutex, so convert pty_count to an atomic_t and remove the mutex entirely. Signed-off-by: Matthew Wilcox --- fs/devpts/inode.c | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index e072e955ce33..c53814539070 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -46,7 +46,7 @@ static int pty_limit = NR_UNIX98_PTY_DEFAULT; static int pty_reserve = NR_UNIX98_PTY_RESERVE; static int pty_limit_min; static int pty_limit_max = INT_MAX; -static int pty_count; +static atomic_t pty_count = ATOMIC_INIT(0); static struct ctl_table pty_table[] = { { @@ -93,8 +93,6 @@ static struct ctl_table pty_root_table[] = { {} }; -static DEFINE_MUTEX(allocated_ptys_lock); - struct pts_mount_opts { int setuid; int setgid; @@ -533,44 +531,25 @@ static struct file_system_type devpts_fs_type = { int devpts_new_index(struct pts_fs_info *fsi) { - int index; - int ida_ret; - -retry: - if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL)) - return -ENOMEM; - - mutex_lock(&allocated_ptys_lock); - if (pty_count >= (pty_limit - - (fsi->mount_opts.reserve ? 0 : pty_reserve))) { - mutex_unlock(&allocated_ptys_lock); - return -ENOSPC; - } + int index = -ENOSPC; - ida_ret = ida_get_new(&fsi->allocated_ptys, &index); - if (ida_ret < 0) { - mutex_unlock(&allocated_ptys_lock); - if (ida_ret == -EAGAIN) - goto retry; - return -EIO; - } + if (atomic_inc_return(&pty_count) >= (pty_limit - + (fsi->mount_opts.reserve ? 0 : pty_reserve))) + goto out; - if (index >= fsi->mount_opts.max) { - ida_remove(&fsi->allocated_ptys, index); - mutex_unlock(&allocated_ptys_lock); - return -ENOSPC; - } - pty_count++; - mutex_unlock(&allocated_ptys_lock); + index = ida_alloc_max(&fsi->allocated_ptys, fsi->mount_opts.max - 1, + GFP_KERNEL); + +out: + if (index < 0) + atomic_dec(&pty_count); return index; } void devpts_kill_index(struct pts_fs_info *fsi, int idx) { - mutex_lock(&allocated_ptys_lock); - ida_remove(&fsi->allocated_ptys, idx); - pty_count--; - mutex_unlock(&allocated_ptys_lock); + ida_free(&fsi->allocated_ptys, idx); + atomic_dec(&pty_count); } /** -- 2.17.1