From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D319CEB64DC for ; Tue, 11 Jul 2023 22:21:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 601726B0072; Tue, 11 Jul 2023 18:21:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 596206B0075; Tue, 11 Jul 2023 18:21:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452AD6B0078; Tue, 11 Jul 2023 18:21:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2ECBF6B0072 for ; Tue, 11 Jul 2023 18:21:35 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A3AAB1A03B8 for ; Tue, 11 Jul 2023 22:21:34 +0000 (UTC) X-FDA: 81000753708.02.B591FEF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 8F45E16000E for ; Tue, 11 Jul 2023 22:21:32 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Tgb8CHjS; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689114093; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=L7QxufRYBrm2R49RiLdI2ro6bMw/p3cgbOZIdsttM+k=; b=vObf5XJIrDm8XwQsQq9i1JkNMfIIix0Kgb/T1nm3iVb5Y0ZC9b51OS+Xb7q1uDcUnznOyN qdRN6PkXPmGzmuBBzT2cF1RKTwAYkRxSF74xf/VlzJRG8jw+OgA0d7s/HJGrnSMfChJKbr iESvTpre9iBoGC4vl2aQnxIiHCIfU/k= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Tgb8CHjS; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689114093; a=rsa-sha256; cv=none; b=2YGEW++1Vi763+vWKCBV9XPLSf6KYI+VU+24PB9g/jawoW1a8d7y+kn1biTnyRP3bNvRZC 3Q4VHJnyrs2hFLpJK7vk4c6rLHd4DVElTWasnPKEIBmgKwBDOSsR4tvqmp+LED9BXrUfWY 7jLcvR752MKVY/nAH2aF6YL41P+gmzY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=L7QxufRYBrm2R49RiLdI2ro6bMw/p3cgbOZIdsttM+k=; b=Tgb8CHjS9/5gZKWnhQNj3hy5UG zYwy+F9/w6AQhoFDhX9wpDEAlpD7KPY/ghIul9QK67qWBBvtWBRsCx6jSwg722I3aP8DQd9yjnV7R 92fMaKIBgUDN0MJd4ifZkmYoJ1Z8z3a7Yil7ofh2sexSMHlod1Oqh/Iv76QtMgW6U+mNx8hLfvCmR JeC1qebXRwnMfb549VeEa1h9ivhsbdn68SMCOdakGVeAYc78nTq3l5VVIm1YJCPNzgQqN5b7DyXCK Cso84r2F9mCH2NMtnCakPCtcMGe4aRxt2B6zpaYJBVvoT2buv51Ml2Cv5SgSsJBuJFQe+cFr2DOLM 6fXD4EhQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qJLja-00G68z-L6; Tue, 11 Jul 2023 22:21:26 +0000 Date: Tue, 11 Jul 2023 23:21:26 +0100 From: Matthew Wilcox To: Suren Baghdasaryan Cc: Dan Carpenter , linux-mm@kvack.org, Andrew Morton , "Liam R. Howlett" , Laurent Dufour , Michel Lespinasse , Jerome Glisse , Michal Hocko , Vlastimil Babka , Johannes Weiner , Peter Xu , David Hildenbrand , Dimitri Sivanich , Mike Travis , Steve Wahl Subject: Re: [bug report] mm: replace vma->vm_flags direct modifications with modifier calls Message-ID: References: <9704a138-60e6-4ede-91f0-844e1df2ad84@moroto.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 8F45E16000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7snj7dh4jgu7iatkhnntuutusj95n7uu X-HE-Tag: 1689114092-738192 X-HE-Meta: U2FsdGVkX18KETJcO5YvBE9ivVDAvctVhPv5Rh4VuxtZ1bQEYz+Vf402Kh7H+TWPZfHxUTJ40cS47bJgkKp7ExsNnfpwwVZ6yu6saKb3cINh0ir2LdjFHHlTdzoylAOqWwKrUfYCAsD0tRw0uoZQ9nseIhp3LMxV6U/cxIvp1HYm6fMfs6pFaqgxxujgtPUIZBWo9GZYq3hPdZYpfmiQ673jby7G8cWO/wS+DjQnwsDRKPjXT9teEnasvXu0ra+Wv8AoUDqbA8Kl3Lk5g18O+nYCHgbXJghUDxtBVcfbzGkSAvMVYzMqycpJCw87kerE+3DRRnaumc3StGYYUlv0mFAvEvSIuITy2QeyGvmpUl6Kw/SOA+N8oVWrZOC5ArprqfAr5ZERNYO1pDdi3MCLtAixX5wxxdaJs6EANFFdS0k0NVj81icVfX3r9g/Z/3vK9x5uYgagx4aMtlTE3B83auJLqL0TQd4p/Wub2ACLqf40V0+3AKM6q/+Qwz4h5rIPUhnId0KwB9jAXMHATwncZ0Z/0xNFlFnXJFgJ063IBmj9WvpqSSG9PHd9JDfwJH6fTTRSC0QF/aUPVXJUF3WKxvqi/761gi7wQq0EO5SUZCZfhrGrGhA2co4DSIlH7H6/y1kCrZOalRXoBWU6GS7F7PyV9974lcIjEVe57TQyOo9Jg1ShWr3C/wc1lag3MKgh1beohBCrpL4UHbttJhDfZ8Fz30AQurfjWiLeCdXOrn1vZZcxxuB0QlPXUJCKJxQ+qZUN6m5XMdpQmW8U9l8Ye0QnsvOtCSXL/fvK3yPHY/Z+W/K5XUzJlFTKE0g/XRUtAqKpMi8ZTYVFL5uLhcYQ1fPi091fDWlxCr1CelXZ40bHuEjA+OmCUZy6mKjErtNdsclVNlcrVqasB7lavE6CZ5i4z2g922ma8rwbtKJN9ZtcaAzoT1fR7iyfCIlhEq5ipZ3FzFhurr24yiuPUYI fMpTkqhH V+eJxlAeovnAXEiSFqbQAkWxdrqkJA25j1T3og3n6uR/BG3FKA68vq4N9RqS/APIcgpLw07nY3UgzJ5TFW2iGyIMJ7BARiJBOsRs0+THwmkOFSLaHcla+Mdm3hBeJwOFUQw0POrPSj8zvGUoA/yA5auy9slNbKhwQ3pG9r7lNAlERBnvBM8vBM5+WjfwtxndfHgs+9v0oylb95/6HrBCsHvDXOBd2nmpHHy33UHViQjNToWFymiQRtg0nLg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jul 11, 2023 at 02:55:20PM -0700, Suren Baghdasaryan wrote: > On Tue, Jul 11, 2023 at 12:21 AM Dan Carpenter wrote: > > > > Hello Suren Baghdasaryan, > > > > The patch 1c71222e5f23: "mm: replace vma->vm_flags direct > > modifications with modifier calls" from Jan 26, 2023, leads to the > > following Smatch static checker warning: > > > > ./include/linux/mm.h:729 vma_start_write() > > warn: sleeping in atomic context > > > > include/linux/mm.h > > 722 static inline void vma_start_write(struct vm_area_struct *vma) > > 723 { > > 724 int mm_lock_seq; > > 725 > > 726 if (__is_vma_write_locked(vma, &mm_lock_seq)) > > 727 return; > > 728 > > --> 729 down_write(&vma->vm_lock->lock); > > 730 vma->vm_lock_seq = mm_lock_seq; > > 731 up_write(&vma->vm_lock->lock); > > 732 } > > > > The call tree is: > > > > gru_fault() <- disables preempt > > -> remap_pfn_range() > > -> track_pfn_remap() > > -> remap_pfn_range_notrack() > > -> vm_flags_set() > > -> vma_start_write() > > > > Before track_pfn_remap() and remap_pfn_range_notrack() would just do |= > > to set the flags but now they use vm_flags_set() so there is a potential > > they could sleep. > > Hi Dan, > Thanks for reporting! Looks like the page fault handler is modifying > the VMA flags, which has to be done under write-locked mmap_lock and I > don't see that being done here... I wonder if that should be allowed. > I'm CC'ing some MM folks to check if this is a valid VMA modification > and should be allowed. Matthew, this might be especially interesting > for you since gru_fault() handles file-backed page faults AFAIKT. I don't run the ->fault handler under RCU, only the ->map_pages() method. I don't intend to change that. > Back to the issue at hand. If such modification should be indeed > allowed then the simplest fix I think would be to add new > remap_pfn_range_locked() function to be called from gru_fault() which > would use __vm_flags_mod() instead of vm_flags_set(). __vm_flags_mod() > does not lock the VMA, so would not have this issue. If the conclusion > is that this is a valid scenario then I can post a fix I described. I'm not certain, but calling remap_pfn_range() in the fault handler is definitely weird. It's normally called _instead_ of having a fault handler. The fault handler usually calls set_pte_at() directly.