From patchwork Fri Dec 15 10:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1876527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ss4Z02Kqmz23nt for ; Fri, 15 Dec 2023 21:04:07 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rE52w-00024d-0Q; Fri, 15 Dec 2023 10:03:54 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rE52s-00024C-FX for kernel-team@lists.ubuntu.com; Fri, 15 Dec 2023 10:03:50 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 554E43F29E for ; Fri, 15 Dec 2023 10:03:50 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-5c668dc7f7bso657578a12.3 for ; Fri, 15 Dec 2023 02:03:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702634628; x=1703239428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A5ts0psIN8Tlw3H1Phb4MXqJvWsAF4sdS5900ZHGtpI=; b=LV2APQ2aRwWheItbAyzvK8kIlWtLF7wObUW/kDwSQFGd4oqYVT1qJ1OG/vKXaht0o+ wTbzRcAJh6EpU+CZutiEF5DqlNy8TCQKePc/SfJtvcVXO/Q20Ulkg+o5nec1cm4Z1O/u aQGwA+0K+o2hE0aY/tQDmHi/ZjCC9abFQSLCz1fKqS39PW43FVjFJsRGVLF/yHHZttd4 Tmc8Rmi6TlArL8f/8LnRHWCgggVMwzvRh1rqD9rwbeQxntdLKe5HgVU477tgG7Swf6HC aGALc3J0XX2hX7ErwMUy8yOZf4EghAQqVUMBxyjDQe8GScYfPhoeBIJ/r2CEsdtlqlog aMjw== X-Gm-Message-State: AOJu0Yz0nZLTIV51wXxZWUEOI/N7caCUW2ijPD8XQGP2p25v+vnliq3B zWh9/PaZY3OQxWDHgv0wpp6D2AZLcLXGCn1nC/Wl/HFeMxenRPmL9MhWqeaxQKVQW+fs5//iyLN S9JNrtl7fM6BQZm2S3YU4wuQIcg366PXQutT50+47sIoXlchXmQ== X-Received: by 2002:a17:903:32c5:b0:1d0:a53e:2662 with SMTP id i5-20020a17090332c500b001d0a53e2662mr13203167plr.104.1702634628271; Fri, 15 Dec 2023 02:03:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQrPvcVogN5hjtZpufFD6LuaGPVpgYI23iq2L1MM9L/KMmDb/vFgOxyFx2DgBv2AwDuHpWQA== X-Received: by 2002:a17:903:32c5:b0:1d0:a53e:2662 with SMTP id i5-20020a17090332c500b001d0a53e2662mr13203156plr.104.1702634627962; Fri, 15 Dec 2023 02:03:47 -0800 (PST) Received: from chengendu.. (111-248-156-5.dynamic-ip.hinet.net. [111.248.156.5]) by smtp.gmail.com with ESMTPSA id u15-20020a17090341cf00b001d0acd4e707sm13969580ple.176.2023.12.15.02.03.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 02:03:47 -0800 (PST) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 1/1] RDMA/odp: Ensure the mm is still alive before creating an implicit child Date: Fri, 15 Dec 2023 18:03:43 +0800 Message-Id: <20231215100343.32480-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215100343.32480-1-chengen.du@canonical.com> References: <20231215100343.32480-1-chengen.du@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2046534 Registration of a mmu_notifier requires the caller to hold a mmget() on the mm as registration is not permitted to race with exit_mmap(). There is a BUG_ON inside the mmu_notifier to guard against this. Normally creating a umem is done against current which implicitly holds the mmget(), however an implicit ODP child is created from a pagefault work queue and is not guaranteed to have a mmget(). Call mmget() around this registration and abort faulting if the MM has gone to exit_mmap(). Before the patch below the notifier was registered when the implicit ODP parent was created, so there was no chance to register a notifier outside of current. Fixes: c571feca2dc9 ("RDMA/odp: use mmu_notifier_get/put for 'struct ib_ucontext_per_mm'") Link: https://lore.kernel.org/r/20200227114118.94736-1-leon@kernel.org Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe (backported from commit a4e63bce1414df7ab6eb82ca9feb8494ce13e554) [chengen - remove tgid-related code and adjust jump label from out_tgid to out_mmput] Signed-off-by: Chengen Du --- drivers/infiniband/core/umem_odp.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c index 615e4ce0343b..0e9445cb5627 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -356,12 +356,26 @@ struct ib_umem_odp *ib_umem_odp_alloc_child(struct ib_umem_odp *root, umem->owning_mm = root->umem.owning_mm; odp_data->page_shift = PAGE_SHIFT; - ret = ib_init_umem_odp(odp_data); - if (ret) { - kfree(odp_data); - return ERR_PTR(ret); + /* + * A mmget must be held when registering a notifier, the owming_mm only + * has a mm_grab at this point. + */ + if (!mmget_not_zero(umem->owning_mm)) { + ret = -EFAULT; + goto out_free; } + + ret = ib_init_umem_odp(odp_data); + if (ret) + goto out_mmput; + mmput(umem->owning_mm); return odp_data; + +out_mmput: + mmput(umem->owning_mm); +out_free: + kfree(odp_data); + return ERR_PTR(ret); } EXPORT_SYMBOL(ib_umem_odp_alloc_child);