Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1282183imb; Sat, 2 Mar 2019 09:12:02 -0800 (PST) X-Google-Smtp-Source: APXvYqzUW1bHJcfiM5N0YK1LDKE5iUO+MxjllAOrpm6tcCNLS9JbKDfChzmJ13H5n16Xjd70p0V6 X-Received: by 2002:a17:902:24c:: with SMTP id 70mr11886154plc.54.1551546722593; Sat, 02 Mar 2019 09:12:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551546722; cv=none; d=google.com; s=arc-20160816; b=Uj0EJppwv5EKeVixMLMfyZVEtWHs11/ukhYg8W1m6pMr69edtzpF1W48wgmN3T+F5L Yo9uFlYAHIHe5tWAkpWEZK6OYNdvUE+VY5m9oM3MRu0pLW0GPEHuYWlefNh5jw/yaNSg 8uZ5IjsA98hhoaWGGaVOWR84looQSLP5l5zcTnr89R2GtCag7Ecz1DBq8uQt/Cia9jF/ UhG0jhIXyP+JsOFP8kft3xoiLgmCg7laKmKxzwpkmsIUpwHuRYqghfLnnUxLyIp4tCaT +/1fn4/djI/RA4TtZvbze+23A/O/AkH0Qy86OsbAf908WHCKt17b+nhH7o5q4zQWv03G XdPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iUJpS9A7ZzMrJTMfM9wjaUGS6YRW/mugbkMQHwyjU3c=; b=tqYD0aOFd7jWjVQhiAx4iL3t//aTPzedEzVJoCiZ/GNFbndsfPr+ogAcgzR89jZVlI MHp8JnkauPyke/tsaeCCaSc55ZCLewWVInXewAHvyD+x2w5hI6g7MXOnCTtzFf+IysjO D6BJWaKyEgUWzX19dFLiGHK6u/ejJyC0gcQgdmTAcbtuXOSTVVHfohiWffKl3sgk9bWK odg2ifZIlFTjqy3ViT/gTzJquABVcf0YYPVqdI506uZYv8cDBefggKh8I1RiQbHVbczU /KEAFjFvWA+vrcHyuZxIhlS+rs2onoVWCFRcL6M74LN5ZtGIshVcv5kkVdawUs0u+vxk v/jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=E69ej4bw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11si994646plo.400.2019.03.02.09.11.47; Sat, 02 Mar 2019 09:12:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=E69ej4bw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726949AbfCBRLM (ORCPT + 99 others); Sat, 2 Mar 2019 12:11:12 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:58504 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfCBRLM (ORCPT ); Sat, 2 Mar 2019 12:11:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kl5e37WI7w9hPYD4s95DfL0cvVBczbmwLkcTsoBgW1o=; b=E69ej4bwFLApvoJgbCNCL59MA 09sYMmuFN2CRP+jsSrQ489rnRpZ+PxTpVsoa8+j9uB5h4i2twJJrUUr4pozB4CFd3tKbMhT8Vjr9h 71HnjqpdyASNmSFaF/SWjvkIsi+nucHv5h93bAkoNWm6TUQgBwGtbmfmNLln1k2qo6pURI13Ymn9A 3pdyMcBRbquct9OXX6mRNcdYt0E7wSb8jDCmGOEaDwUmaOxmp++RTfTzPmUtFN0kTGzM9mvncRoNJ yLLiOMFp6cm1hv/BJqG9d3Su7PqLLXpSzHiEQehqE6oxqxaHKek2RldjAQbW37hmwdIZLDjUZLOVG vvJcw3p1Q==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1h089s-0004Ts-1J; Sat, 02 Mar 2019 17:10:44 +0000 Date: Sat, 2 Mar 2019 09:10:43 -0800 From: Matthew Wilcox To: Jan Stancek Cc: linux-mm@kvack.org, akpm@linux-foundation.org, peterz@infradead.org, riel@surriel.com, mhocko@suse.com, ying.huang@intel.com, jrdr.linux@gmail.com, jglisse@redhat.com, aneesh.kumar@linux.ibm.com, david@redhat.com, aarcange@redhat.com, raquini@redhat.com, rientjes@google.com, kirill@shutemov.name, mgorman@techsingularity.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/memory.c: do_fault: avoid usage of stale vm_area_struct Message-ID: <20190302171043.GP11592@bombadil.infradead.org> References: <0b7a4604529e16ace8d65a42dac7c78582e7fb28.1551538524.git.jstancek@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0b7a4604529e16ace8d65a42dac7c78582e7fb28.1551538524.git.jstancek@redhat.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 02, 2019 at 04:11:26PM +0100, Jan Stancek wrote: > Problem is that "vmf->vma" used in do_fault() can become stale. > Because mmap_sem may be released, other threads can come in, > call munmap() and cause "vma" be returned to kmem cache, and > get zeroed/re-initialized and re-used: > This patch pins mm_struct and stores its value, to avoid using > potentially stale "vma" when calling pte_free(). OK, we need to cache the mm_struct, but why do we need the extra atomic op? There's surely no way the mm can be freed while the thread is in the middle of handling a fault. ie I would drop these lines: > + mmgrab(vm_mm); > + ... > + > + mmdrop(vm_mm); > +