From patchwork Wed Dec 1 14:30:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12650031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 325F8C433EF for ; Wed, 1 Dec 2021 14:37:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B3996B0088; Wed, 1 Dec 2021 09:31:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1380C6B008C; Wed, 1 Dec 2021 09:31:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA4D16B008A; Wed, 1 Dec 2021 09:31:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id D7C1B6B0087 for ; Wed, 1 Dec 2021 09:31:05 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9EB4D8249980 for ; Wed, 1 Dec 2021 14:30:55 +0000 (UTC) X-FDA: 78869462070.19.A302C7E Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf03.hostedemail.com (Postfix) with ESMTP id C51293001A15 for ; Wed, 1 Dec 2021 14:30:54 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1B1EOuJH023540; Wed, 1 Dec 2021 14:30:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=rhXNmZnznFRovzMMcOQhdBZ1NLEbsCl4mmlB08V3TTU=; b=mXPzUkI/2LasuZ5o3UVqYYNiu/frSmeMZp9rFxbvhwkpW2OBia4QIVm8aKlJGH5Zy4PN chP1/wReG0k/hZ2kDOGg8OqsIv3vvaHUFcwLWLzzbto1CnY9Gol6irQE31GIfOFrbycr qk7TTDa1D/UWb6r0+92lv8o6xKU401r78XGw4pYFjDovJIfmPcSRUnvt6rshmX54X/0f bihAGxOp/3ALjRmO9YJRLyCC7ZVp4Q79w4aKg0gDnuYCFthKpPAkHDK5Q0TV5W0BF1Lg +MIOIigmXzyxgBedSs13cpGo/p9S8aNMRZQQOYeZN07oCmegLcT/RWE5mQkbq2CVYcLZ 5g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3cp9gkgghu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Dec 2021 14:30:44 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1B1EBl7Y109791; Wed, 1 Dec 2021 14:30:43 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2102.outbound.protection.outlook.com [104.47.70.102]) by aserp3020.oracle.com with ESMTP id 3cnhveqcc9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Dec 2021 14:30:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ARgJ3Ww3LLkxZcF8OpPVIlXy7yUAhISILtL/IOW1pTAifbBA4kJiyBdofoN7hocd5PF8tULH8yn6u4gW5xz4EWQfjwcNqEM5xp953a5fo0OiQmXrFdrAZxWvxaQZnH0zupnNkBtCmDMkJR3PWUNbE2IXmXyNvnjGIvQdfbk0BecASyOO6mkGk2bYJy3KpRHCH1jBLMN4ghFPMZk3XMwR+wY09PrYEEKCUphfMpzHtCBH+IcCBM7wIfGTY6sXRqJG25UephQZRja+C88MWaAew9oT+qnMhGRkXlVd4uXJhzbZroleHgfhHSbUiGYoqBkIXIMdHrsTwfpXYsnnkbhDwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rhXNmZnznFRovzMMcOQhdBZ1NLEbsCl4mmlB08V3TTU=; b=cjCIF2E/C1XbKjD8pXSjKs9YjYyv7jscIhrzI8xjz0PAC0JAeKnCYNswr5WZNxlzHincI4hikqoOVzjKdCHmZg6f7kHB4+dAFoFN+GvMfXSlsrfpvMx/7pfHmfp/nEuJ9gRHg23NJlp8RkPLH7W9nLQpP/1LtqZ7jJ5cysxFRcGmojMu0At2xzUTHSqbU2OkGfCmsw6CZrnXFAkv07l4PTq+u0CoMGBV2UsR8smB3csL9u750NSqAJTwoxa+6mJoD239OxZP3O3Lz+U1QDddsHp17PN4t6vwtMLOnbJ6LAl4X80dd3+8yGtU2c9HFZ8DQhbJixDILdBuzLE6DM7yFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rhXNmZnznFRovzMMcOQhdBZ1NLEbsCl4mmlB08V3TTU=; b=iBJ4Oz8RiWIgZCYO6OBnIvwxH0XzG8X/HZzbq1ZIqMfliaa3s1qqEN/W97p3Q37MMYiS26Cjqz0WuzBe6xV+yOUP3i9sIFmjf1wlONPFQ+11PYirmCfW8fgNmQNZxPhsMOwCxeFjfYHa8s6e1htVCtuc1sSLT9vAioUNbQOumG4= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SA2PR10MB4508.namprd10.prod.outlook.com (2603:10b6:806:11d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Wed, 1 Dec 2021 14:30:37 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::c4d0:8291:84d:ac66]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::c4d0:8291:84d:ac66%7]) with mapi id 15.20.4734.027; Wed, 1 Dec 2021 14:30:37 +0000 From: Liam Howlett To: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton CC: Song Liu , Davidlohr Bueso , "Paul E . McKenney" , Matthew Wilcox , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Vlastimil Babka , Rik van Riel , Peter Zijlstra , Michel Lespinasse , Jerome Glisse , Minchan Kim , Joel Fernandes , Rom Lemarchand , Liam Howlett Subject: [PATCH v4 38/66] coredump: Remove vma linked list walk Thread-Topic: [PATCH v4 38/66] coredump: Remove vma linked list walk Thread-Index: AQHX5r/wcwICCKzeIEWkD/OHNmLUUw== Date: Wed, 1 Dec 2021 14:30:08 +0000 Message-ID: <20211201142918.921493-39-Liam.Howlett@oracle.com> References: <20211201142918.921493-1-Liam.Howlett@oracle.com> In-Reply-To: <20211201142918.921493-1-Liam.Howlett@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.30.2 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6e2fd9d0-b557-4f2a-716f-08d9b4d724ae x-ms-traffictypediagnostic: SA2PR10MB4508: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: W3Q3wuYLnOyOioGRHSut9IjGXO5IqdbxxeQ3mtpzn3WZOYkxYCWMYsvA8KeZn1oi6VI5x+t8rHqWGGb0GclELRA7Py3bqQxwBs2MF4Vlb4IrLqYXd4kzY2zo5CQOlnEEcXKFmMFGuh2dP9NMoBR4K7r8/UgBwKPwNec31Z5l7RM2f4H4GkdvDvPXCEipLWvD9Ou+Hck8/VaBRGiI8lytakDQ7Gr/4aAVk2WCbzRLYnixvZ+1dBwbW1Adzc1uoHJ27AQUtuw18pnIOVAcdY+v14smuxVH2hyu58u4gku0eYFl0T/UaP1I4LQ1PneYpjlXwPnWsSDJt3QjgBBOW+ZEyoKMUsGulIrbnlSY9kO8Ri5l4D2sFnhJnQl6cJk8gQek4DJfZ6wmi71tRyW0lv8NOIZOSusIEmnx3xzWuLNz/XPlX8LDG+8W/RzFCmQpld/TOfczo8xdfdpCudla9i6RJK6Au3MCYJ9XAxp3gxJ8MAQAS+pdIEEEMEhd/QABcc4Udg+vA23vkrAWQg91nzq+2Rp/ctzi6pWJfQtvRB5SNsvribJ99LJ/0arZnm5YZgLD2ZwjMXwH2JqM9R4AtGxGzF/p3Vxx4YXZBU19TlzcaJ5YB2bRM+XpYQYm0PBTppySqsC9kDWQ8jEO2R4kPcNxV56x1w8tR71F8sLE0dw9O4ryK1xD84k8OSJmR7L6uYgK6wMspQ3Sh7i5vNiAIbBm4w== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(186003)(26005)(7416002)(1076003)(2906002)(8936002)(54906003)(83380400001)(2616005)(38100700002)(71200400001)(66946007)(86362001)(66446008)(8676002)(6506007)(38070700005)(6512007)(6666004)(122000001)(508600001)(110136005)(6486002)(64756008)(66556008)(76116006)(91956017)(107886003)(316002)(5660300002)(44832011)(36756003)(4326008)(66476007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?Rz34BZ+7a6AwJMnqSSBL5Iz?= =?iso-8859-1?q?kzn7QNjrJUMJTuJbyUj4I6eXUqNtGraO0InZPQvMnbzz0psYdpNOmEsmJh1v?= =?iso-8859-1?q?vZ0aWMUEweKYH3hhZ97qDC8M2MMMKkWUtTJb5fxAqwmoOW+PSjC8+2Ip0skR?= =?iso-8859-1?q?6vSslMeBJ+IVrbMQoSYT82b4cJ4GeTSugjKhotCjwnFiWxK5356aR+8T4/8f?= =?iso-8859-1?q?CHXl5iizKGGRn/aUJp7+jV9NHea9hchkknsVoz75RUVJHy+fk+6TLVeNeKK8?= =?iso-8859-1?q?w9F2Xfq9NtoVqlwq3csfNLoV4F1v6Hz22y7XRzVARgjhktFxwGsm+WIX/E0s?= =?iso-8859-1?q?2v558lY9lL+CZGq45nWZU+bavo6vEJvi1QuNhbCLs4k+D+wXzU1GBXfOr8lF?= =?iso-8859-1?q?qvmIV3EBoZfCWPuwfUJgcLsLjJ+En+88ikwhO98bPexmHDWblhX+pZCXLRnv?= =?iso-8859-1?q?+GHzi54xcXb9YqYtnUz+siICFqdMdJazpkCY6F7HRMkZY69/rNe4UfrjI+l/?= =?iso-8859-1?q?8P8xJKuGeefhojaMUxkg+5sO7mzrGpK/+M9sPMpR3n+yaWbzjCBt+nj2aBj2?= =?iso-8859-1?q?S6Odl53UY5pBg8dfmhcLTPFTssO5vJFEZy14wZQoN9EiNApmTlOS7FRFjd1G?= =?iso-8859-1?q?AjyPHSU5u/08+8PRaiHK9kbZOkcLSTyhS6ftCh2Xu4TPUurYjeL0B7F0gMZW?= =?iso-8859-1?q?C/NXdo4ug8NJzbY1liAgMfGjyzuYk3blyVoliTZVk4kTD5xHrtqVDZUb8veG?= =?iso-8859-1?q?Gb+l4cY8bBEXAiWEfvG8hZJVT5THhnTtgK4ePsL+/nAusbvdaIzfseO462yy?= =?iso-8859-1?q?JjAow1pMSCu5yIUsJUOD6+sTYAWh7/CD9JQxooD1z+uGIIxdxEItWrvLlY+o?= =?iso-8859-1?q?fhIRblsuOUxuIjXQlS2FurG2f9gXKfmacnDb/KNzwQ9pV9euAstWnexx0V6r?= =?iso-8859-1?q?mPIcHWRyDYYvqao/9XHwkyCHc6tSid0AwwGjR9Ws02q8H4Owy/wu9pWGR0nn?= =?iso-8859-1?q?rSSkPtmPpGGOKmMk776JMAQ7eJrIR2k1xejdBwqVTsukvrwfOMfrXR6isvmL?= =?iso-8859-1?q?1tuI+tKp1h7EDhEObEcH2kNuhSrRreNc+rATG471DaZ8oNhsYS/TWNYUGdWr?= =?iso-8859-1?q?dMLEmRb9bxKJOsF+YxZPW7U5FaW4fPgjFq1j5twmwkzJ8u25a8/GkeXSe6zS?= =?iso-8859-1?q?5FOPcXLdqxaO8FjJ+KjwDcn7vNOf9FV59kRMWzuuFfBMl6L3LonpjkCpAvDc?= =?iso-8859-1?q?7nuAisudUGTBvmrWlJt0TRlyz4QWzdmhx98Mrsp9AyJ7Gj2USISt0rq5Q1dT?= =?iso-8859-1?q?XXuT6nVPGiDcGr631giP0k6dE6ZqgsPPrNWS5qAuTUZDEmKbiDS+kJLjRZQT?= =?iso-8859-1?q?Fqnb+4sInug0K66WHVohVDd7Zx0VczjLz4AyHtiXv/ELy/10M601H6GBhZFF?= =?iso-8859-1?q?SPtMOGOraILqwXlD+TdKm+cIYPuml2XNP6CqiQCjNtfnLfypS63B+21MSK3M?= =?iso-8859-1?q?/ML2hetbjE8xyA4ivRD9+6pNGVbcnilI7m6oHR8+4L+xXfaVTNWUP+S10Gd3?= =?iso-8859-1?q?G9CDzC74L/8If4Gyto+mQtwrZbqm6OA519q6De4FR/iVzffxO5ILZFOIgZ+V?= =?iso-8859-1?q?yGqTQDucO1x149o0BqFmo0pz7eBmurjb/hFFTI/rYVx69vN5kNvUoThET680?= =?iso-8859-1?q?=3D?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e2fd9d0-b557-4f2a-716f-08d9b4d724ae X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2021 14:30:08.3113 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 78SGGdgW+dnNYevJ2Bx2FJNEz3jpus6EWNnHY6JXA0MBEY41ILr5jrGQZ1idL5/clmZhrSmRQ4TocD9rqfthsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4508 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10184 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112010081 X-Proofpoint-ORIG-GUID: wwEYJpbBJp9mpZWUPbZmDUPWKSzKYT1O X-Proofpoint-GUID: wwEYJpbBJp9mpZWUPbZmDUPWKSzKYT1O X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C51293001A15 X-Stat-Signature: 6fqc6m6pecau3t9ckt5brtmfm9ub99ht Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b="mXPzUkI/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=iBJ4Oz8R; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf03.hostedemail.com: domain of liam.howlett@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=liam.howlett@oracle.com X-HE-Tag: 1638369054-782518 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" Use the Maple Tree iterator instead. This is too complicated for the VMA iterator to handle, so let's open-code it for now. If this turns out to be a common pattern, we can migrate it to common code. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Liam R. Howlett --- fs/coredump.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index a6b3c196cdef..59347e42048d 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -997,30 +997,20 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, return vma->vm_end - vma->vm_start; } -static struct vm_area_struct *first_vma(struct task_struct *tsk, - struct vm_area_struct *gate_vma) -{ - struct vm_area_struct *ret = tsk->mm->mmap; - - if (ret) - return ret; - return gate_vma; -} - /* * Helper function for iterating across a vma list. It ensures that the caller * will visit `gate_vma' prior to terminating the search. */ -static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma, +static struct vm_area_struct *coredump_next_vma(struct ma_state *mas, + struct vm_area_struct *vma, struct vm_area_struct *gate_vma) { - struct vm_area_struct *ret; - - ret = this_vma->vm_next; - if (ret) - return ret; - if (this_vma == gate_vma) + if (vma == gate_vma) return NULL; + + vma = mas_next(mas, ULONG_MAX); + if (vma) + return vma; return gate_vma; } @@ -1032,9 +1022,10 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count, struct core_vma_metadata **vma_meta, size_t *vma_data_size_ptr) { - struct vm_area_struct *vma, *gate_vma; + struct vm_area_struct *gate_vma, *vma = NULL; struct mm_struct *mm = current->mm; - int i; + MA_STATE(mas, &mm->mm_mt, 0, 0); + int i = 0; size_t vma_data_size = 0; /* @@ -1054,8 +1045,7 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count, return -ENOMEM; } - for (i = 0, vma = first_vma(current, gate_vma); vma != NULL; - vma = next_vma(vma, gate_vma), i++) { + while ((vma = coredump_next_vma(&mas, vma, gate_vma)) != NULL) { struct core_vma_metadata *m = (*vma_meta) + i; m->start = vma->vm_start; @@ -1064,6 +1054,7 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count, m->dump_size = vma_dump_size(vma, cprm->mm_flags); vma_data_size += m->dump_size; + i++; } mmap_write_unlock(mm);