From patchwork Mon Nov 5 16:55:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jordan X-Patchwork-Id: 10668677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BAC12175A for ; Mon, 5 Nov 2018 16:57:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9915293D9 for ; Mon, 5 Nov 2018 16:57:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D1242946D; Mon, 5 Nov 2018 16:57:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3938129463 for ; Mon, 5 Nov 2018 16:57:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3B986B0276; Mon, 5 Nov 2018 11:56:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A8D866B027A; Mon, 5 Nov 2018 11:56:44 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A5306B0278; Mon, 5 Nov 2018 11:56:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f69.google.com (mail-yw1-f69.google.com [209.85.161.69]) by kanga.kvack.org (Postfix) with ESMTP id 4C7186B0277 for ; Mon, 5 Nov 2018 11:56:44 -0500 (EST) Received: by mail-yw1-f69.google.com with SMTP id a62-v6so7834645ywf.16 for ; Mon, 05 Nov 2018 08:56:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pFJTplxowb9ZeUGTgNoJLdHdBNDs48jVBVOWfuQrUbk=; b=hJ7lqfqcuP7H5a6kyyz+mdvqWMfa7yIF0jgkNag5ARnI7VhAoGFKW3GOFO63JHqY/k JjYfLMKGrYYTEVDwXTyIYUzbmehfBTvtBMWHWmsL/GLl82JTYpuGT9i/KIjEtL/8P+jd 9JnSHULqmD2meuIX71E6nj6XVCx8PeL5ZK8Q07IRLguvH/tSV8pZ99hbVjgDje6zpfk+ LHpIUJspE0BJNu6+TucQJ+brGTaGbYnmOGQpYNNO/STKC2/xl02jvCQ4HwXHSYrNx3Kp WtQ0gXghtwbcNfCRnrU1wSMFFzKGRweLEp3l80g735XEXmWrDVk82Ewog19LElB1zMgz amBg== X-Gm-Message-State: AGRZ1gKXPyO9gJreNnMp6Xy8wItfLhd5jTnfLUfZ3FQXBBKaKngiifg0 HeIcv/14hFGCwQWrZQkE95iO3WwrGB0phlYciYUh+W2PweWq6IUPcFxeVKnG5izmlzZWUJVQMtj 0vEeA2sH2cYSlpD02hZyL8s8Q0Pw4XxuYZQAeWOKdLGwdvLojGjZ6vRo9WW4DKx62rA== X-Received: by 2002:a81:e4d:: with SMTP id 74-v6mr21840774ywo.162.1541437003985; Mon, 05 Nov 2018 08:56:43 -0800 (PST) X-Google-Smtp-Source: AJdET5dPPDxNphfM4bBdCk+lk3XFiN0blBdYzWKQN+wsp7p5KCr8lDlg72LhZsFe8PwLY0eRou+O X-Received: by 2002:a81:e4d:: with SMTP id 74-v6mr21840713ywo.162.1541437003109; Mon, 05 Nov 2018 08:56:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541437003; cv=none; d=google.com; s=arc-20160816; b=RN3QbuP+D/p70mTcvvIU/gaj2+LrVBZH06URDXIGVwLda16+35PnyiT9bGnODucDeq iHmWjFGlFQLHWbsjmQIFD7OVDiYky6iK2o2txO4H+xAOExs3AjEx1RcX0Q6uZkYMiRxW GoiGWAyRbHZKYPlrfFt5OlCZmh/JCcOo4bujedrkNHrviIj2nJ3LXVv0dZTCYzwjVQYA g8iTYlbhh/vy965bQvqbwbx/AsUfrjaFxYlHzwQmj7ETIgD6bDy8YCpBJa5rozyxjzbi i4yT/VgpPO43D3NGmLgSnd+NNnRglKMw7tdwNk2eRM6l2R8Rqf4RRFlDGBiLFb83SXZN SRLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=pFJTplxowb9ZeUGTgNoJLdHdBNDs48jVBVOWfuQrUbk=; b=xmBdqDY/TEBkZLkaTeXNCS4roshXxRZmH3ZpFfczdm3dBcV09Mk/1I78b89f+cU4mg tttHQnW2IbNBpTCGbFR4LhmcQ0xqLfyX9wh+LIXBpdHQFsvp242tchga+2faEjBZHkIF Hgv1FZj2ZAwm8e2HMpqD6WQbd6NRy/gaH9ESGDFqsi2YUtmUkeu9vhNQwD5UROpdwqaw 9+DS8UMcQZIWAPo5wq6/JRkWWFRZFERQLWT3VCwKIQlCg3FLdqRSpw/TAiQFAWycPvvg tD7FJ5sIW5uYooesVMxgRrLi9fKLaH5Z25Cbv0v9cm4tHbFDqUKN4rIvzplixqvk4sxJ vkmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=UEDXi9JQ; spf=pass (google.com: domain of daniel.m.jordan@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=daniel.m.jordan@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id r4-v6si23252143yba.429.2018.11.05.08.56.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 08:56:43 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.m.jordan@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=UEDXi9JQ; spf=pass (google.com: domain of daniel.m.jordan@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=daniel.m.jordan@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wA5Gs4bK052321; Mon, 5 Nov 2018 16:56:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=pFJTplxowb9ZeUGTgNoJLdHdBNDs48jVBVOWfuQrUbk=; b=UEDXi9JQkI61IrVjTEL9K2GK2kUyKmRXKt4ss+WNs6+EK0pNVLSyhLeGQntyiJM5cEIY 1QTs2L+45uBq0NzchVRwPJe6uRKAwuGgqm6hOlQix9uyUSXu592okWo3iSWYTsl/qaw3 8mNuLrR1FcUPpxeOoXm4mDjSV9FxagWh8aPyOdKt8PLonHdEZfXgPE4AltLy3UCoTOeK jUog8/C/ZgDbE8JAsDhSMmGritc7Bt190iR/MqdkBatkrFyrFLNaYl5BAZlh0Py/U64X SJ8E5YAvEUlYnM8jGUjYCG6xNTBhW9MI0wXB7jXzKedma3SvDo9hFnWSZZv5KHpQC47Q JQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2nh4aqg2e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Nov 2018 16:56:26 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wA5GuKSY024985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Nov 2018 16:56:20 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wA5GuJFq008435; Mon, 5 Nov 2018 16:56:19 GMT Received: from localhost.localdomain (/73.60.114.248) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Nov 2018 08:56:19 -0800 From: Daniel Jordan To: linux-mm@kvack.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: aarcange@redhat.com, aaron.lu@intel.com, akpm@linux-foundation.org, alex.williamson@redhat.com, bsd@redhat.com, daniel.m.jordan@oracle.com, darrick.wong@oracle.com, dave.hansen@linux.intel.com, jgg@mellanox.com, jwadams@google.com, jiangshanlai@gmail.com, mhocko@kernel.org, mike.kravetz@oracle.com, Pavel.Tatashin@microsoft.com, prasad.singamsetty@oracle.com, rdunlap@infradead.org, steven.sistare@oracle.com, tim.c.chen@intel.com, tj@kernel.org, vbabka@suse.cz Subject: [RFC PATCH v4 08/13] vfio: remove unnecessary mmap_sem writer acquisition around locked_vm Date: Mon, 5 Nov 2018 11:55:53 -0500 Message-Id: <20181105165558.11698-9-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105165558.11698-1-daniel.m.jordan@oracle.com> References: <20181105165558.11698-1-daniel.m.jordan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9068 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811050153 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Now that mmap_sem is no longer required for modifying locked_vm, remove it in the VFIO code. [XXX Can be sent separately, along with similar conversions in the other places mmap_sem was taken for locked_vm. While at it, could make similar changes to pinned_vm.] Signed-off-by: Daniel Jordan --- drivers/vfio/vfio_iommu_type1.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index f307dc9d5e19..9e52a24eb45b 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -258,7 +258,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn) static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) { struct mm_struct *mm; - int ret; + long locked_vm; + int ret = 0; if (!npage) return 0; @@ -267,24 +268,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) if (!mm) return -ESRCH; /* process exited */ - ret = down_write_killable(&mm->mmap_sem); - if (!ret) { - if (npage > 0) { - if (!dma->lock_cap) { - unsigned long limit; - - limit = task_rlimit(dma->task, - RLIMIT_MEMLOCK) >> PAGE_SHIFT; + locked_vm = atomic_long_add_return(npage, &mm->locked_vm); - if (atomic_long_read(&mm->locked_vm) + npage > limit) - ret = -ENOMEM; - } + if (npage > 0 && !dma->lock_cap) { + unsigned long limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >> + PAGE_SHIFT; + if (locked_vm > limit) { + atomic_long_sub(npage, &mm->locked_vm); + ret = -ENOMEM; } - - if (!ret) - atomic_long_add(npage, &mm->locked_vm); - - up_write(&mm->mmap_sem); } if (async)