From patchwork Tue Jan 17 15:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13104845 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 0E916C677F1 for ; Tue, 17 Jan 2023 15:59:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A73196B0080; Tue, 17 Jan 2023 10:58:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FC356B0082; Tue, 17 Jan 2023 10:58:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73C146B0085; Tue, 17 Jan 2023 10:58:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 583026B0080 for ; Tue, 17 Jan 2023 10:58:58 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 23D351A0768 for ; Tue, 17 Jan 2023 15:58:58 +0000 (UTC) X-FDA: 80364749556.03.02F7940 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2050.outbound.protection.outlook.com [40.107.94.50]) by imf05.hostedemail.com (Postfix) with ESMTP id 7BDBE100007 for ; Tue, 17 Jan 2023 15:58:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RLZ+3Z10; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf05.hostedemail.com: domain of jgg@nvidia.com designates 40.107.94.50 as permitted sender) smtp.mailfrom=jgg@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673971135; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v5o2IKvIXUjZnA3k5FObffCFUYi7W0moro08HtJtOww=; b=yoi/uF0PBj9cRtyTH0MSM3R1uhM49aN5tXn02mTxrvUv/cKmVplbslHuxV/8kgx5pvaHHC JSy9FwGZbZwZA4mTE2Hfg1qt7faJJ9akdo9xgkhMQmiqVvQoWhj3lC771eyoefePF7LCMO 4t13sDrSILIIaTEZrwKYeMYNh0CXaPs= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RLZ+3Z10; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf05.hostedemail.com: domain of jgg@nvidia.com designates 40.107.94.50 as permitted sender) smtp.mailfrom=jgg@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1673971135; a=rsa-sha256; cv=pass; b=ZopJ3yvFFSBjroNKEuM0hZcZjRqBpscBKKC5a22ykfDRQvRwE4zKCwMBVTjXYdE3pBHxJI beBGERRXcywyCcCfnS6bJIZECHRaWnPaKpSa54O+cUTc6Ful1U3nEiSY/d1fVKNoM/cHUz 7aZAkisiooV/uTJRol+L2yqd3djRLyE= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qsb+9XfgPnc4Cq4JiH4PAFF/8B/e1AAXNScpjigGDvqNOJO2twZFu7TPUVE33OcNCxIia8gLmXhRszA3gdf0aiRfKC8xvw4e+WtOllcbhboViXIDX4SwI68uUsgFedZBcS9XrQRMFmpKL20nanhSWgwuyXpaHr/0u3gcTcUFOQnzVUaxeVGRGhBvjsgluNwbx/Jyi5NYUu75+HqjYm3Kkbq5cpety9VER0zdiP5EckUfctovp1fRyzg3kuS3zpksH2n8gzq6LJdx5vpwxhmakFLnAFGytF1QBrjaQ0gVqsEjy0Hk7CLBhLsFkHDNeS2mz3fb0p8/eR0jaSA3Su7ATw== 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=v5o2IKvIXUjZnA3k5FObffCFUYi7W0moro08HtJtOww=; b=hcKiMlRXeMrdjwn0hj12hvoP8gL7kK4ntYq0m5eYod4wY5GhKIoK7YHXs2KwTiWqhLw8Dn0GM+jSnB8rccHVgp55Bj5mfCPCrecPOKkV3NwsI44ifSzhAjY8sy9cRuto1YWE2O+FQXXJ5kB50C/xV5FUccqgg94I3yX/MojEE1hcz88vbscpvBUm4+mJ3sj3cHYC/wJ4xW/RsD3rhi3XHFuONV8vKbs4Eer7c0gVt8ZUEt6QVdJ8SooE2V6egAIGF8dQFEPprHfCi5uigaNM3EJiA5/XljR9MKxir8Z3beRC/oYHWt4mGWWmWgOYmEwscuYXwYwcfFSjM7tSE1FFpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v5o2IKvIXUjZnA3k5FObffCFUYi7W0moro08HtJtOww=; b=RLZ+3Z10HEDBooQ9A7p2ZLkDruzu7DxBeVhWyJNDTTgZGgsv73jpyZBKSpsES0WhIyZfiD39SGYhu1y5M6PsvZh1lyLPEjcBP4//WchuGqOOJJyIXGeeJBIMB+AtcviuvRCkbzzVZAe2FMrrDLYuDb/ovpdYlp3Cz14Efm0yzDnEFrEdqO6tAhYlEZ4RAb5UAMnKEnxT/Fdq4B1N09ezi6J7u2Nkhkdg1cnpVMbkWBnIPujf+tpyI7XZquNP0eJ0kXJPbK6aMcuJTQlaqH4bBuHb96RBhbzZ8PFgbE53CfJhQH+mXvtpYDyEafCQl5eYceWvhJSb82P+nl+iDOvM6A== Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by IA1PR12MB8334.namprd12.prod.outlook.com (2603:10b6:208:3ff::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.23; Tue, 17 Jan 2023 15:58:45 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f8b0:df13:5f8d:12a]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f8b0:df13:5f8d:12a%9]) with mapi id 15.20.6002.013; Tue, 17 Jan 2023 15:58:45 +0000 From: Jason Gunthorpe To: Cc: Alistair Popple , John Hubbard , linux-mm@kvack.org Subject: [PATCH 4/8] mm/gup: add an assertion that the mmap lock is locked Date: Tue, 17 Jan 2023 11:58:35 -0400 Message-Id: <4-v1-dd94f8f0d5ad+716-gup_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-dd94f8f0d5ad+716-gup_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: CP5P284CA0091.BRAP284.PROD.OUTLOOK.COM (2603:10d6:103:92::23) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB8334:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b2b031c-b3b0-4987-3769-08daf8a3b6a6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PwJoXoAH7Mb39t+8eLwWdfJ0W27ReCJGkT+AK4CT0rOHArQUs/I2wDEkJic5/ds5V7afe6KGpaCQkuIdITNltUSxyuNCgItPsJLkIkuTHq63VKS4kbZAOytqu/HOtx/8/kMXpB1+fzkwbTs5dq/Ka7ULNn7x1ZCHsUHTqRD70JJDME6I8gmZVjix68lbS04eXJAVm5wV9/rkE2lYxLTnRZwEpfNpAAR0fTSI+sv64OR35UavS9OoC4RRVdlVRsoxzOBy0yNTs3eItyLqoQb6TMtYCiYtStrxucgEkFq3+zDrwnxmcAhma+LnSsF2r452ysI9wEFuZRYvMIbEqUEkfDMc6HITff9/XxUZeah9FTeyBd+SMx4BN31YyqDwvmU2YFz7bDbzK9i6xN7Bpm9PvTO6nCvRA40aNubw1o6nsE+GUwuKpOV7aIHKjn5b+4FM3nikZfpqL9QvBk7hgF38PjbHOaLdIdoouw1dp+n3SDUpV28oSSL4YR0cm6O6JnCE+cNTEUY/gHCMAISB3nEMreWut/v8E3J3m/R4uMBWnoZKPP+6mCjxjSvZi7uzcRKfrdrs+UVHubthZjBFx0QxV5/seKRYKmDMSs8uA69VDH8rxh9ulQ9hfhYE2OaZGQQlyY2KEQwFT+FduiHI0djT95VqSA2yGntoOPanPnUziqROzutEqdnByh9hqtSpAsQFrpspA/9WXfBp/8C1cnUNvg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(366004)(346002)(136003)(376002)(39860400002)(109986013)(451199015)(36756003)(86362001)(2616005)(66556008)(4326008)(26005)(8676002)(6512007)(186003)(66946007)(66476007)(41300700001)(83380400001)(6666004)(6506007)(316002)(54906003)(478600001)(4744005)(2906002)(6486002)(38100700002)(8936002)(5660300002)(4216001)(266003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-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vUFItgouG9Sk8LI6ZpWlxu6sfTgk50gfi9L/h0ZBrYcR5lmqFICoHPwIbmgdAc7c6U2UhdHhPtyYyBeq74URu++akKy/z3tw5SE4o8eKCWD+Z24FELi7srrd/zD6k/unebLa/TgyYzHk13ZSVdcU5ZR3dE+xLBc7do+9XchtA7t4NoXKfvz0mfibEbTP3lUDYKmfTFsNmdLPZ5GaGahYstkDFs//FRZsGs1k/CrU6IXht7czqQdVFyf/bMp0N6Is9bUB64oQgCg9QtKB9McEIyw5OQHGXWw43gDlzGe3674mj8Amy1Zw7QrCnVKUHjLGhgTevn+9DKjVRvr2H/jqXU76rdoY+u5lMFZ5fDqbGpB6Ky2XKqxabPHpgqV3xgK4UbdHp9pr+/pyBkA0KqJiix8sxU7uLPNOAw32gPINj1UlGmXNGPELvAKQNEEc3nTBynDgZLR8whnUX5jYDQxqA7R3BMR0chKXz1yfpJ4QuF8i93IXVmYfe2hLAyGZTSGqwUnwbSLVVzMhugvXED7ewzv0cs9oS4v7BCRSYO97Mz7i/IwgF X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b2b031c-b3b0-4987-3769-08daf8a3b6a6 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2023 15:58:45.5456 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zJQ2d3OYSVEQFjzqzFdFXcWO2XD6VhTdnKZskBKhsrWoZVSPu2m7GHdnX52tVB2Q X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8334 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7BDBE100007 X-Rspam-User: X-Stat-Signature: xh8s4wrww78inxmc5bhffxfh4h6k7abu X-HE-Tag: 1673971135-30500 X-HE-Meta: U2FsdGVkX18ht++9rosolemUdcusPJ1BOC2oFSYQu6aOI+U6FnUSt/ggOZytGoO7/tMvaCrsqeydkZ17MENrziq77u1eeCss3vJH/CZUVkRgoSrkM9+CL9A4Zaj7iyfmbmqJ0R4cCqApAGOJcLWXJb68jp+uGDDj+D2nxnTCAIhvFNtdcI8B5P5SKTLaTyMr2d2X7PL/A+TV3gDt1OPPwfcGWAmiKKPVYEVvru9CVIIP0NPxoRjTV2ka1M2v3OYe0+Sk4qYQ2QV+K2pakVhJqD3fTw572LcIzdgTP1hKHce9n/gWs/nT9Vg9CfKZh+wn4NtVJ55ZA2Jm15N5HZhxt+In7xPy5JiU42tUGA4npJfeTWN8Dy1x+Qw4i4KdT7DDBn82UiHI0mImYp55XxjpKUW5+n0kbAvrlapeBoZhpNh5kM+LIKL8FJei2finriWaDM5in2iRf8su1K3jAm1BxhpcNwvRh/Y44618v+xrMrOHe9Yb33nhCDTHnogSy0nUnmADYc1M30dGDQMOsqmnk8jAfxKcb+Fp1F920jQ/T9y70w2wWjoB4w3DeWl+OIydOFZ6vnejwB75EbZC3OuTFUcUz7wnH85kr+xv5IHK57xdLBx7fpgwq2BDvDcFXQe+9qS+o7ASPndXeSYYT++NuRnLLuC4WfcolQrKEPbXoblVzXJYXvZg/bqS3ljvGW61G05SWgermDjg+8++QA1olGTup0e0N2j8R0yIiOgb8J7uEF9tXL/Espii+Iy2+8RDRXCdnwAPuUAZDwGC9rThAzL7EU7k6Dafd258C8XGcfy4p1iTotgKlQtDohe8FgnYC2MAiFnQl4bmMNW6/I84kILuPtX6Bq1TGeZIU7f73+LDMVqV/W1CsHMlujRI7CAaonPDm1fnwVZqKn9d3sa7IGmEtMZPijSiFeKGKFVstcLoVAIVTp3fT2tb3vVGoESQEEidPUAOvL4= 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: This is always required, but we can't have a proper unguarded assertion because of a shortcut in fork. So, cover as much as we can for now. Signed-off-by: Jason Gunthorpe --- mm/gup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 9e332e3f6ea8e2..d203e268793b9c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1350,6 +1350,14 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, return -EAGAIN; lock_dropped = true; *locked = 1; + } else if (flags & FOLL_PIN) { + /* + * The mmap lock must be held when calling this function. This + * is true even for non-pin modes, but due to a shortcut in fork + * not taking the lock for the new mm we cannot check this + * comprehensively. + */ + mmap_assert_locked(mm); } if (flags & FOLL_PIN)