Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp45264rwd; Mon, 12 Jun 2023 09:54:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wwXHSBEhAKPGojXeEWsmKdKFzJxRPjrmcKroFCQLyn1eyB4XiCAO6oHZytOvw9ZhD4FUQ X-Received: by 2002:a05:6a20:8e1b:b0:11a:dbb3:6ff7 with SMTP id y27-20020a056a208e1b00b0011adbb36ff7mr3835566pzj.24.1686588880320; Mon, 12 Jun 2023 09:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686588880; cv=none; d=google.com; s=arc-20160816; b=wVROKM23cG+aWFtC0D1SjpeHykeNlh29zCDqHxfmeGyNFrbFLzi01Ri0Ez+Dkf0AYI sqwiSHgFCvIaY8NoMyizmHn6BBFNwl25BD8N/OWgMgUkzS8duDTQ5Jneuqg6x7CVpYI1 4BqGHUqWv+RaUf9uZ1cXSGpDszQjtwVGLZxrdV7IRoHxOzyLjZohE1mi6ZXxHDfjpAqy JnzqhoAf38rvHLtcl18Ta3USXGqDPKkL2tFUtyA7HTYJzeEiSUbYEU0ca+MgkjZbnULy lZCg2+CPfla0jkPyjTHPdb46EGlcAznZ8Utl/w6Tancl0CpDix9Tz1PH1VVj0HMsmXRn xUag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WQi6jtfU5Lynaf+sn5nkLvTDsBxdvtzSQejpmjCr2Yk=; b=ORzR164lGlE2igC6zTQBhBgsFZR/m13J9lpMpHrLx6s7cyrX4qF5FhZmHVJgvWqgZ5 OFv8zBDKKKQguA58ZaTal2MplZsi11+aoH7nHo5Zc848agL9POXci8MCrAqckMxA8mVh lNMb/U6xUHplwICg3gWFLy79AxVQTw2x5knOPNrlNAcj5W7kjrZBbH6Sz4GF2P2bjmUw z/r9g5OFe2Xl1r1ZLelJheFXwBp4DZ69xS+Ry1I1s2E1MpEVXUJAkjGB1CfnugEjbP0p FkFSPktHQWQgPUc7Ao/BhSPteqv7tSfi6i4Xj4oOQDXwrv6CNgc6KsLKQy7VSDrEX/Km N/og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ldreut73; 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 g25-20020a633759000000b00547b25ea099si3844442pgn.682.2023.06.12.09.54.27; Mon, 12 Jun 2023 09:54: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=@google.com header.s=20221208 header.b=ldreut73; 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 S229877AbjFLQHy (ORCPT + 99 others); Mon, 12 Jun 2023 12:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjFLQHw (ORCPT ); Mon, 12 Jun 2023 12:07:52 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60074187 for ; Mon, 12 Jun 2023 09:07:51 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-bc43a73ab22so3380438276.0 for ; Mon, 12 Jun 2023 09:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686586070; x=1689178070; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WQi6jtfU5Lynaf+sn5nkLvTDsBxdvtzSQejpmjCr2Yk=; b=ldreut73mQ7n/9Rvm35cqn0sTfKZnyPz57sJzkjPKlUTacxjPpUB5qkwnYpLz04nWi etFQJKZhaKM8I3MOmegKu7fthVQ/JMQuXCm6jC38J9kuoI/EMC3pMvYK+vY9AR2Ql5Xa 2dlFgBYdbZf7n2dEgfiM9BGZ2Tpj4YP/zi0kGVstPMQMpehVlj50D1EdTzepJ62GTwup FW7M5iNYbJHM0V6JmYakSx4GA32k7dqw2SItmTaCXruIDP1rVcX9geye6IGVemMdhv2O 6NNRFtmxfN2FO6ThSPmu98Sg0XT9rAhG+dD5vcE3CDKtgx9wopSLfGr6RrhBAUJAG4uw wXSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686586070; x=1689178070; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WQi6jtfU5Lynaf+sn5nkLvTDsBxdvtzSQejpmjCr2Yk=; b=GEgilWe+VQWaIE1VsQMo0PsLUnyv8LdnsF/bIPB+VHds28bSG4fglt/a3NCiHAgn2r lnzX/Gpe9tPnVIxLoBLLVBmaMi9URXHpfbMA+4uxto7gReNtQeRs99mvYNW/UKHDDOTz X68FsUhdGZHbK76CtPuvD5zsjNSytYNIr8F9NvLTAgZ8QLuowikNbzS2fvHHXNxwLt34 18Oqry/uM0bxvFD6pdRzdv2VwGBSZ1B/21oYV0VM+I4ugkvcAFtYJUr/IJjqY7ZeprpT ZXb8ARXY7iu9DxhXsrzZfUP/Cs05zXPHmmWOZTvMJWTbQgE4TrVY9+oNbmjqWbB06met WpUA== X-Gm-Message-State: AC+VfDwuL0OCWtsvtnxObLXhrvVLrxsgknMD05D6xLLyvDs8QbaLRfNw zMCXt3v3Up9ZTh/wqIU/rzvgPpNGheYssNY0QPerBA== X-Received: by 2002:a5b:a06:0:b0:bb1:76ca:d1f9 with SMTP id k6-20020a5b0a06000000b00bb176cad1f9mr11770295ybq.20.1686586070336; Mon, 12 Jun 2023 09:07:50 -0700 (PDT) MIME-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> <20230609005158.2421285-5-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 12 Jun 2023 09:07:38 -0700 Message-ID: Subject: Re: [PATCH v2 4/6] mm: drop VMA lock before waiting for migration To: Peter Xu Cc: akpm@linux-foundation.org, 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, 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, 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Mon, Jun 12, 2023 at 6:36=E2=80=AFAM Peter Xu wrote: > > On Fri, Jun 09, 2023 at 06:29:43PM -0700, Suren Baghdasaryan wrote: > > On Fri, Jun 9, 2023 at 3:30=E2=80=AFPM Suren Baghdasaryan wrote: > > > > > > On Fri, Jun 9, 2023 at 1:42=E2=80=AFPM Peter Xu w= rote: > > > > > > > > On Thu, Jun 08, 2023 at 05:51:56PM -0700, Suren Baghdasaryan wrote: > > > > > migration_entry_wait does not need VMA lock, therefore it can be = dropped > > > > > before waiting. Introduce VM_FAULT_VMA_UNLOCKED to indicate that = VMA > > > > > lock was dropped while in handle_mm_fault(). > > > > > Note that once VMA lock is dropped, the VMA reference can't be us= ed as > > > > > there are no guarantees it was not freed. > > > > > > > > Then vma lock behaves differently from mmap read lock, am I right? = Can we > > > > still make them match on behaviors, or there's reason not to do so? > > > > > > I think we could match their behavior by also dropping mmap_lock here > > > when fault is handled under mmap_lock (!(fault->flags & > > > FAULT_FLAG_VMA_LOCK)). > > > I missed the fact that VM_FAULT_COMPLETED can be used to skip droppin= g > > > mmap_lock in do_page_fault(), so indeed, I might be able to use > > > VM_FAULT_COMPLETED to skip vma_end_read(vma) for per-vma locks as wel= l > > > instead of introducing FAULT_FLAG_VMA_LOCK. I think that was your ide= a > > > of reusing existing flags? > > Sorry, I meant VM_FAULT_VMA_UNLOCKED, not FAULT_FLAG_VMA_LOCK in the > > above reply. > > > > I took a closer look into using VM_FAULT_COMPLETED instead of > > VM_FAULT_VMA_UNLOCKED but when we fall back from per-vma lock to > > mmap_lock we need to retry with an indication that the per-vma lock > > was dropped. Returning (VM_FAULT_RETRY | VM_FAULT_COMPLETE) to > > indicate such state seems strange to me ("retry" and "complete" seem > > Not relevant to this migration patch, but for the whole idea I was thinki= ng > whether it should just work if we simply: > > fault =3D handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LO= CK, regs); > - vma_end_read(vma); > + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) > + vma_end_read(vma); > > ? Today when we can't handle a page fault under per-vma locks we return VM_FAULT_RETRY, in which case per-vma lock is dropped and the fault is retried under mmap_lock. The condition you suggest above would not drop per-vma lock for VM_FAULT_RETRY case and would break the current fallback mechanism. However your suggestion gave me an idea. I could indicate that per-vma lock got dropped using vmf structure (like Matthew suggested before) and once handle_pte_fault(vmf) returns I could check if it returned VM_FAULT_RETRY but per-vma lock is still held. If that happens I can call vma_end_read() before returning from __handle_mm_fault(). That way any time handle_mm_fault() returns VM_FAULT_RETRY per-vma lock will be already released, so your condition in do_page_fault() will work correctly. That would eliminate the need for a new VM_FAULT_VMA_UNLOCKED flag. WDYT? > > GUP may need more caution on NOWAIT, but vma lock is only in fault paths = so > IIUC it's fine? > > -- > Peter Xu > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >