Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1528484pxj; Fri, 4 Jun 2021 17:43:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySWMaGQgu9ZfAHG8Aofug3bvkTs6wbsTmYjo14rZ4P+oM5t9cInUYZJzaIZ9/DVLTM2E6S X-Received: by 2002:aa7:c042:: with SMTP id k2mr7648319edo.21.1622853837805; Fri, 04 Jun 2021 17:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622853837; cv=none; d=google.com; s=arc-20160816; b=mmHyopDntF6wnIufxnhchH5PIFnu78+uO1Ok2ILSB5lnLztXcfRCz/pSdSCcFDg7f9 o0A5gMsylJQxEaNjtnBzDFmdxr2vh+anUadmYevE586AT2+Fa7LgJPYCr546z6MUQJ9q 6dkLCUpwf5jJKDLc+cnl1MFwTpluEuco2GDz+X+wvfQf4Siq8SdzKbkOby7xs9qeSNGx t/skmL7nvM3fuoYDAKD9f6I4Ooiz8C962W+0EjPL6kjXW9EsukzxNbJgGo7+gUTGeL3e yy+cAnGgulskyUYYJxrnM9FYZsylgWzvhubb2q47KIoiJxR0R/c6XQsgI+xNquF3/yyB jGVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=S0RNl1ValKKRLQbUx9zapSSxQl8HE3O+Grx55QC8BB8=; b=sikzc48S5xzc4I0ssPrp5w3EAk/6MEAfFsHm4ZF8P8Ipl3LIuZ92i7f+NWKluVc1iq g1gMyMiWSceWCp1+ZFIdROFc9B1f6tfCTcVkwz39rJxTI5WGFzRLFp6krnHbWdhlZ3z5 fatExEYx4pbVVZFx8Rw+OAuTfUJl1pAzLzeCenTSqmfY5PTc1WUkApC/iBDZZVhGFKIo vB81Jfna1EuSkEuypoUtD3eRUJw3N82vWWS8Rccl2SLlyJG9ef9PO0szljGBFvu6bKWM dsURSzHD64yVB/LaQ71wNjKBVv5hH8dpVEKvhPm8Mk0CBHj6DQZTrucmuX560cnK5WH3 W4iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ojqlPcYN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t16si7292355edi.299.2021.06.04.17.43.34; Fri, 04 Jun 2021 17:43:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ojqlPcYN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231197AbhFEAoQ (ORCPT + 99 others); Fri, 4 Jun 2021 20:44:16 -0400 Received: from mail-lj1-f181.google.com ([209.85.208.181]:33777 "EHLO mail-lj1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbhFEAoQ (ORCPT ); Fri, 4 Jun 2021 20:44:16 -0400 Received: by mail-lj1-f181.google.com with SMTP id o8so13826700ljp.0 for ; Fri, 04 Jun 2021 17:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=S0RNl1ValKKRLQbUx9zapSSxQl8HE3O+Grx55QC8BB8=; b=ojqlPcYN//lzjPCK23tdLtRIIYrgW9m/5kJ/xOjRInCF4R7iFC1/I0ZkVLmxGV8DXR MQWb07lHHZMwwI3mGCRqMAesfKm1mWvsT1fKDr2EyaZCEGoXBk5MRscqdZbVrfjd6byB UC2OAmXNTjZ1XXqU2QIkZUr+320CRdtEbj7InexW97stnDZxR/A2mRYURCjA4zPGoT8h zZKD7TJ6uy/9jzID2bu4rxwrKqn/bYNh5LMyz+lefblMFpIWrDYNy/UqqVnv9iY+GCYm zCIocFSTC5JEnil58sWiJDJ+0EtmDGYceal8ew26Jn/vZJQwmrzF2MxxEU2hsojtFjNK mK1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S0RNl1ValKKRLQbUx9zapSSxQl8HE3O+Grx55QC8BB8=; b=f4767xQtN0Z1qY+IJ40DiwY3nZMrylHHcIrynuS15mJKJAkQMW6J6Jum04KW99+n1U TPmrQ16Qb47Qk69M7T0tvw0BpdVVehGy/HBWm9AW6tvUIlWrJsPU3WT/a9M7WJ+jvkw8 dM66gCf4F6+u7Fv25aju6T/smlpgEV51PSo9KPxd4/uAP7ODeHsx7SX14b7u1obAQjYg Tz2r6LNvS3VQTxgQbQHT66uTMhee9YFltP6OJhVzhdAseiweVcz8qQpEWP6jbf8dJaqG yrg+4NoA247ODIi/xeISC3X0eMfFFEezYCbn4AkWYgjKejUgMfLAe7J6j/xp1hnMaUaV ZzvA== X-Gm-Message-State: AOAM530wHJj5JM7hkQgVGe2Hc8IVMgNuQMahsruGGDVSPt7PIWa2yKio n0SE2UhZ8p744In0xT0WEhcppStTttra03tKzgnc2w== X-Received: by 2002:a05:651c:292:: with SMTP id b18mr5197181ljo.456.1622853674402; Fri, 04 Jun 2021 17:41:14 -0700 (PDT) MIME-Version: 1.0 References: <20210524132725.12697-1-apopple@nvidia.com> <20210524132725.12697-4-apopple@nvidia.com> <20210525183710.fa2m2sbfixnhz7g5@revolver> <20210604204934.sbspsmwdqdtmz73d@revolver> In-Reply-To: <20210604204934.sbspsmwdqdtmz73d@revolver> From: Shakeel Butt Date: Fri, 4 Jun 2021 17:41:03 -0700 Message-ID: Subject: Re: [PATCH v9 03/10] mm/rmap: Split try_to_munlock from try_to_unmap To: Liam Howlett Cc: Alistair Popple , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "nouveau@lists.freedesktop.org" , "bskeggs@redhat.com" , "rcampbell@nvidia.com" , "linux-doc@vger.kernel.org" , "jhubbard@nvidia.com" , "bsingharora@gmail.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "hch@infradead.org" , "jglisse@redhat.com" , "willy@infradead.org" , "jgg@nvidia.com" , "peterx@redhat.com" , "hughd@google.com" , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 4, 2021 at 1:49 PM Liam Howlett wrote: > > * Shakeel Butt [210525 19:45]: > > On Tue, May 25, 2021 at 11:40 AM Liam Howlett wrote: > > > > > [...] > > > > > > > > +/* > > > > + * Walks the vma's mapping a page and mlocks the page if any locked vma's are > > > > + * found. Once one is found the page is locked and the scan can be terminated. > > > > + */ > > > > > > Can you please add that this requires the mmap_sem() lock to the > > > comments? > > > > > > > Why does this require mmap_sem() lock? Also mmap_sem() lock of which mm_struct? > > > Doesn't the mlock_vma_page() require the mmap_sem() for reading? The > mm_struct in vma->vm_mm; > We are traversing all the vmas where this page is mapped of possibly different mm_structs. I don't think we want to take mmap_sem() of all those mm_structs. The commit b87537d9e2fe ("mm: rmap use pte lock not mmap_sem to set PageMlocked") removed exactly that. > > From what I can see, at least the following paths have mmap_lock held > for writing: > > munlock_vma_pages_range() from __do_munmap() > munlokc_vma_pages_range() from remap_file_pages() > The following path does not hold mmap_sem: exit_mmap() -> munlock_vma_pages_all() -> munlock_vma_pages_range(). I would really suggest all to carefully read the commit message of b87537d9e2fe ("mm: rmap use pte lock not mmap_sem to set PageMlocked"). Particularly the following paragraph: ... Vlastimil Babka points out another race which this patch protects against. try_to_unmap_one() might reach its mlock_vma_page() TestSetPageMlocked a moment after munlock_vma_pages_all() did its Phase 1 TestClearPageMlocked: leaving PageMlocked and unevictable when it should be evictable. mmap_sem is ineffective because exit_mmap() does not hold it; page lock ineffective because __munlock_pagevec() only takes it afterwards, in Phase 2; pte lock is effective because __munlock_pagevec_fill() takes it to get the page, after VM_LOCKED was cleared from vm_flags, so visible to try_to_unmap_one. ... Alistair, please bring back the VM_LOCKED check with pte lock held and the comment "Holding pte lock, we do *not* need mmap_lock here". One positive outcome of this cleanup patch is the removal of unnecessary invalidation (unmapping for kvm case) of secondary mmus.