Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10627632rwr; Fri, 12 May 2023 10:32:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gbxcGc5MV1fKAYadl9HxIXx+7yXTJzz+kr/G0u+unn7c/rHF1pj49LwBAcrdlTZ1iYCcM X-Received: by 2002:a05:6a20:72a8:b0:104:2896:a61 with SMTP id o40-20020a056a2072a800b0010428960a61mr6649771pzk.19.1683912760823; Fri, 12 May 2023 10:32:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683912760; cv=pass; d=google.com; s=arc-20160816; b=inbZh8+iFPrvz7pYu8rCGD36d7Ne59xqUnmz0jtUoRa8e3KJYViCSVPwuNys6Gtaxs hPDR9unOmIoykJxmJHPT+YYG9Zr9OirEibBFnfeLGM4kBsj3FyOHBfa7UmyBI/EMltMF 6lmdfUpmcExyKsuceWATP5k2VtZPj2aIeEYiLN2bSgqTCKxo6BIDWmnQP2Z4HQpXACAP kL3bItNBuNHkdwfPiJTZDs+0MhrHfMNbNrSl427lxSIEnHs5vuFdv/dBq/4+iNq32dVr qOFcd3SuvzdOb8X2nyNH4q9q6g4kI5NHkhkc2SxBvzjEMfE0E2aN2WSTiO/6tpyLnyh1 yU2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=o76Y+eO7z+00ukKNdRV7fXABofAudxnBIvLOwFisq5M=; b=xk8j1sbVMPDtAo83biutffWGAp42W4mQg20V+a/4QmcMyKeuGrHzImifE7WwYCTBfM qLr2wYjPsUtJZKsh4/wfzmIzhFRKfho7C8Y15Dqsj7337COk8twmlbxc5UO22Lcnx+av 6WsjJcLYUvIlgiW99adggNlLbGlyshu+sChYoykYDvOa54Hkc9tLyW+b4ktmrEpA6ahm RQ6o/Sgkf/QvZGrYiMdTwSxAtflUVGX+HdUYOWMDNlFA7wAXMiiHumjC9ftjJBwDN+1M QtZa7jrkSqzGGsklqg/d1vRYp1VJwj4Lc/zyVQxv8n5Io2+zwkkE4yzcSUAvODPZRKsN CM6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=nwUfodiv; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u71-20020a63854a000000b0052c40a97d97si9954264pgd.5.2023.05.12.10.32.26; Fri, 12 May 2023 10:32:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=nwUfodiv; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237840AbjELRGr (ORCPT + 99 others); Fri, 12 May 2023 13:06:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237820AbjELRGo (ORCPT ); Fri, 12 May 2023 13:06:44 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2084.outbound.protection.outlook.com [40.107.243.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D6AE50 for ; Fri, 12 May 2023 10:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LhojvMbaXYC/GwMr2PelorM0flGF9GVTTL2QgDX1dD7xdpqrSJ7/O2zY+Vp3Od7KlXVSzePZfht1VpdGepo5LBD0BtySMfc9VRn+G+yno6BKy1oNGsWVp4vnjS7QfXCmc/c7l6EQJ7cHzxy//G0jRb4/+Qnh61ROFq9muyS9GHVvk05qr3TlN0Pc/+glQYJ3wM43K92Hs8t30J2FTQ1bDBZdH62hv08tcJN7OmgawJXH6DXK7QnSZHEa6r40UrSdngKmSxONnuWeMzbnA7+0Aj3+st7VnItOfHXUzrM8p1hM8twj6R6iNyH5M2YoBEy83Wo96/U2V0ffKnUWiJ3Avg== 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=o76Y+eO7z+00ukKNdRV7fXABofAudxnBIvLOwFisq5M=; b=E7pMxwjwI3aj4hkEzF1wwL5djWf7RSYfe1I07+yRWLPYJOX35fpVoJzHCllgBb8iKTupurC7mWdl4MjhpElzKjYxATpXU/anXmYrWZPapCXWfMWUJe2+XPfAFIQ54rjc3k1/4vg2cXhQBxSfdDaDldL7qdNHyW8Qpmq/5KeYvHn8FDVKGBJDik9VlEIBpzKvTKlT6qB3mYPDv4KL1vCCwQnTX8TqbXZx2tEYxZXxZIu4BC30pWMgbXK7LziCFuwYp3UL6+TJ4oQU+2PMKn0vfEyd0BXJU8XA/zOsS8mI+HjV834nxE3ktQ7Rx+Vf2hCI2miuixBz8799aPaUcV9aQA== 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=o76Y+eO7z+00ukKNdRV7fXABofAudxnBIvLOwFisq5M=; b=nwUfodivGEepRG9WAUKhuugXrKDIoOdCLhZbXtDmtZgynBHRpxcg8ux8DURb7WKF0wDYxMPzJCbUSkU+jf4BLz0TCd8Lh8k69l9JcEQiX+hwQdnaFskgfpPny3A0XQr6lcP80JgEOljtvOqY0pJrFJxu8d+nhGVexSi8P9IE8m/9CT3UCLyQlqUW0VcxgMMga0Wm7AVuYRqqN8DDVY7ORU6ICf+UlwjaMUHy63fXigjTNiu5s49519udsO7GAA0+ea6cOEuR3G+VkyAHC7isupumypcx48qmtYkom7RAmfMbpk10GWpazwdRrtQqrxTJ3a8glJ4SAH/T0rHM6KeTwQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by IA1PR12MB8587.namprd12.prod.outlook.com (2603:10b6:208:450::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20; Fri, 12 May 2023 17:06:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6387.021; Fri, 12 May 2023 17:06:39 +0000 Date: Fri, 12 May 2023 14:06:36 -0300 From: Jason Gunthorpe To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard , Andrew Morton , "Kirill A . Shutemov" , Lorenzo Stoakes , David Hildenbrand Subject: Re: [PATCH] mm/gup: Fixes FOLL_UNLOCKABLE against FOLL_NOWAIT Message-ID: References: <20230512003102.3149737-1-peterx@redhat.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230512003102.3149737-1-peterx@redhat.com> X-ClientProxiedBy: YQZPR01CA0136.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:87::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB8587:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b55660b-085b-443e-fc87-08db530b4052 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vUSjn2y6SIoQx4J5ek/1vMaNdIxH15y7O/jiMHVcbn4iSaVYZZxnNTmx3cYKKSIjTGRlONEQ0TaOIynvhWOyFYg3pTQ/4U+vUUswVM2tQjK393ltt1m0goKwiRRnbbxTF9FiAczGvvbidIjw9Bprj9i+wPndqmgcUTPgyiUnnOqQ4L0DuyE5FST+jJCUtalk72oKdscLIJgaeDpCbv6EBNLhi+q+xbhSsoNZocdw1wHLO5VdaIfDINRn+g64hIyPxDG+moL3qAVGew1wM128olOhN/dkY71qtNpLFeXHjzzLVHzXkIuRU6pXcF+8RbO3lKl/IzjGv6hH8RakJEImRUlt27jk7QpUIY48Z3dzUThNRAX/ptWbD2C+xNlintQP+zs8NqdEWrF0XBsTKs5pYhDMJ4D25ET31i8rTqvPC/D60+Kv+96V+Fqzvr7G6shDIBkXwkcqJcOGAOLIogiFh2ZRhcb3y8iOF/AJXi2aJTiTBUxV8o2Dqpnlig7pHrlT1KAbLRNn0lfEJZa4uhjjwZQuaa5AdBRi81jVnQUsyhe4Db+oAXaiEUmYJwP9At/o 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:(13230028)(4636009)(39860400002)(136003)(396003)(376002)(366004)(346002)(451199021)(186003)(2616005)(2906002)(83380400001)(38100700002)(86362001)(36756003)(6486002)(8936002)(41300700001)(316002)(8676002)(6666004)(5660300002)(478600001)(54906003)(6916009)(66556008)(66476007)(4326008)(66946007)(26005)(6512007)(6506007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?IML6g+CLYyKRgJbTEwEMZbTMgHYNG0jjCJv9rB9r0V0iacT/W6k8sJaeJ280?= =?us-ascii?Q?CTgwODVMLgQ/EJJyTWw+RyLpSX/ZjC+YiwLMi2Q+ILfhcypQUIvfNIV9VYYq?= =?us-ascii?Q?n5HSsVycn5AJfDaZoB4BOPULII+0kvtCIOH1I57qc71sz28GjuNkfXq3cj+2?= =?us-ascii?Q?Gzo9rLilxTrjsgv3yZLyd3WNmmEKXtri8HhEJ0OE4mkWGNAFid7y85kD+ypP?= =?us-ascii?Q?aYar6CAe2140EHzgtlYiHLv4D66vhI57l/7hIP/Ki1UJRn4zyjNpMPPlxU1E?= =?us-ascii?Q?hnZZr9p3oMiJzrxlDkjDldkD8Ox80mtYrPXcJcJMLCHgCfFbVDBLrjziSwAA?= =?us-ascii?Q?Qa5Gxd8w2Bh4osgaWMZGv1xnISCwf3/31KQ1WqnOdI9cLYN6ivHhTQiI4TRL?= =?us-ascii?Q?Nkl/frBlDUKnGoNO9nC+Q9tjGjXMzM1OMaf7ES9uttmCJ7RIfHFppTDBILq2?= =?us-ascii?Q?Klg97ZV7E+uvYUP5L+U+feMpQQ9qSVifhHZPskwUWBmu9tpB7BjNSJDZkzxf?= =?us-ascii?Q?kGD3b453nmuieIy6YZ6QR8xuEp/endhemMYfTy5gRrBWj3szwVcv1LNEcQVf?= =?us-ascii?Q?kUmBnk/zHLQO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tkin?= =?us-ascii?Q?3MgHMbHJ6bku5z9GdqbutS4To3a3V5cS3L8xoiAujxwsJAlo3jpLh6UL86rI?= =?us-ascii?Q?d5trtpxymXnntR9AlAY=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b55660b-085b-443e-fc87-08db530b4052 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2023 17:06:39.3333 (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: Nv+gxzC1pjHnpX7CVmAgxhbotw9uXXVFKK6xZqZe5i47NcNdHi9kdav6ZcX439Vp X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8587 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 11, 2023 at 08:31:02PM -0400, Peter Xu wrote: > E.g., with current code we could at last have FAULT_FLAG_RETRY_NOWAIT set > even if with a FOLL_UNLOCKABLE gup which doesn't make a lot of > sense. I would say NOWAIT and UNLOCKABLE are different things. UNLOCKABLE says the mmap sem is allowed to be unlocked, which is true, and NOWAIT says it shouldn't "wait" (which is something more nebulous than just sleep). In FOLL_ flag terms it would be fine if the mmap sem was unlocked while doing NOWAIT - even though the fault hanlder will not doe this. The only caller is fine with this too. !UNLOCKABLE literally means not to ever drop the mmap lock which is not something KVM needs at all. So I'd say it is fine as is. A caller should never assume that calling an unlocked function or passing null locked means that the mmap sem won't be unlocked while running indirectly because of other GUP flags. If it wants this behavior it needs to ask for it explicitly with a locked GUP call and a NULL locked. > Since at it, the same commit added unconditional FOLL_UNLOCKABLE in > faultin_vma_page_range(), which is code-wise correct becuase the helper > only has one user right now and it always has "locked" set. Not quite, it is correct because that is the API contract of this function. The caller must provide a non-NULL locked and non-NULL locked at the external interfaces always mean it can be unlocked while running. > However it can be abused if someone reuse faultin_vma_page_range() > in other call sites in the future. Add a sanity check for that, > also add the missing comment for UNLOCKABLE. Then we have bigger problems because the API has become confusing if a non-NULL locked somehow means 'don't ever unlock', but only sometimes. Jason