Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17131589rwd; Mon, 26 Jun 2023 21:36:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6i21yUjMozMf9aJHZU0PuytmVNfeVaeAwp27CZqNMd/ZVevIgKQ+NLXSxXX9iFCMHQ/Cc7 X-Received: by 2002:a17:907:72d3:b0:98c:f606:80cd with SMTP id du19-20020a17090772d300b0098cf60680cdmr14389228ejc.37.1687840590121; Mon, 26 Jun 2023 21:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687840590; cv=none; d=google.com; s=arc-20160816; b=zwQsBlTM5Kcyr4gkMtZTfsIZlaRVOs+tnO3cK4eKHaiqbkOYmgm1qU/gdY8pb+2hd8 9i03255DMTnFVBvj0p9fDegWDdObDT6DUHehmfmArOEJqFqnbPT9J7MnwWPmC19hcw3W oI4y97pCAPUVZNdwxlHzla/LgRs9OLAH8Etmr4M5INyui9VhVmWGnkZgr5tvL9h5bZ71 2cegus2ukWwFp13HYkRG1i+GRssmOCg93T/+cTHacdSwVVZMA8pS8A9HKakz8/fc6NJC I6rV8fqYGKWnZZpjLJc2P4a9H9W+MTt3cLPrWPsZQC9hgl6xjMCrbr3JJ+zzlLMOrx2q Wv0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; fh=RMSYO7NH5mgRq+Q9Sd8uvtKjjFjspH3ZqZT6M3GUwas=; b=UL2eCAWazp4aT2SalU4tpQv13pDBVsayUF2xik3e6ieX89RL9XySUpHoZTCMUtBRYL 3t8z3GuLU+BcbpDi9z1iYhNa1tX6wxs5r6Qoll4hLmCpDQ5v0AzT2QAa2XuvFj+mZtKh qVoKI3rSA+TIVN2k/87hh88WbG/hx9YemhQNrwN9IQqF23a2xVM5Ey4/23V9N0Nj4F1z nZcDzZ3IcWt3xx9SOjv89iRJivo+UQFpJQMUODRQpjU+oO2sPKZnrLz/kF+P9LeRXYPR ujPu3nnQDTYRzie1jlPa36qPwlaLDGRQ5FUAhe1ChCqvST8iuOr+54lJTNXq10NZUx+t y0VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=uyhBbu35; 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=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020a170906719400b0098e78ef7e98si2364233ejk.233.2023.06.26.21.36.05; Mon, 26 Jun 2023 21:36:30 -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=@google.com header.s=20221208 header.b=uyhBbu35; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230507AbjF0EYn (ORCPT + 99 others); Tue, 27 Jun 2023 00:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbjF0EXt (ORCPT ); Tue, 27 Jun 2023 00:23:49 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCCA4199A for ; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-c17812e30b4so3259242276.1 for ; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839820; x=1690431820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=uyhBbu35AtD8uFc7lNVRhrhL9FZssNEc1U3YlNjnS6/vWb6a5ERBcwBMaYSPxjJ/Mk Qe5HTpNa5XqvLjiojjNbFmZN0xmWKkvRVR4N08jGcpfsLakGmZkxol+hWOUA2MEdPtG3 CCWMkRdx3oFd6/Dcq2ziTDhiHH5hTD+8UeRRw0fdTOeqAixqf3jfdQ7B3ZgYpw+aT0x0 7n1tbaJiroElOh+0zEGZhbUInAo3kZrsUt6r5yZG0ZhF8kLRGvyK6fttt1xmJKJlC+bc 8aGAiRC7PO3v1V82sW0UO8XGuG6YrM7whEZUcc8FMaVdHAxabZ1AEzNvmsHlLQ8otu9G mugQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839820; x=1690431820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=IsalEZ8WhjpXnE3lEDLtF7rwFjRLHo5Wu1hLStJclC3x66eZyrLjsXHl2n+6tY+HuF /pyQZKk6prAF4bo+Etik669Lubzot4AaU658Q1hXSuXX5pklqYKd0yz209bvvXl6qFu6 yl3BlHdhrU3Ldo0J8bLDJ2VnK9BHP9naNJWdulUOPJ9iYtVrut93d19avEskOT2YN220 xsrTv76xRpbOzgiM0MrDH49d9gl3RxsZJ5v9WpPexBl3hpPMtgy2egKI1xBVBQYtigQG LgJ3bHGgJHfbVXGeWp/UnhcoPEkhSR53dsZpHurJAfD9LTuMt6UH7h83zaA43nIJTlRR n6bQ== X-Gm-Message-State: AC+VfDwrPdq0ZATwkhyR+O6qUVBK7m3n7hDHwTLN/Vq7Wzze3bkVNH3l jloxGnpcBxBmxiFNzck85cHALDYQe/8= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:e78a:0:b0:bc4:ef98:681c with SMTP id e132-20020a25e78a000000b00bc4ef98681cmr6584157ybh.13.1687839820015; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:20 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-8-surenb@google.com> Subject: [PATCH v3 7/8] mm: drop VMA lock before waiting for migration From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 migration_entry_wait does not need VMA lock, therefore it can be dropped before waiting. Signed-off-by: Suren Baghdasaryan --- mm/memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 5caaa4c66ea2..bdf46fdc58d6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3715,8 +3715,18 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) entry = pte_to_swp_entry(vmf->orig_pte); if (unlikely(non_swap_entry(entry))) { if (is_migration_entry(entry)) { - migration_entry_wait(vma->vm_mm, vmf->pmd, - vmf->address); + /* Save mm in case VMA lock is dropped */ + struct mm_struct *mm = vma->vm_mm; + + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + /* + * No need to hold VMA lock for migration. + * WARNING: vma can't be used after this! + */ + vma_end_read(vma); + ret |= VM_FAULT_COMPLETED; + } + migration_entry_wait(mm, vmf->pmd, vmf->address); } else if (is_device_exclusive_entry(entry)) { vmf->page = pfn_swap_entry_to_page(entry); ret = remove_device_exclusive_entry(vmf); -- 2.41.0.178.g377b9f9a00-goog