From mboxrd@z Thu Jan 1 00:00:00 1970 From: Li Zhong Subject: Re: [PATCH v3 x86 1/2] fix page faults by nmiaction in nmi if kmemcheck is enabled Date: Fri, 09 Mar 2012 04:52:36 -0500 Message-ID: <1331286756.13274.26.camel@ThinkPad-T420> References: <1329717665.3448.28.camel@ThinkPad-T61> <1329735648.2293.307.camel@twins> <1329788560.3448.45.camel@ThinkPad-T61> <1329819437.2293.382.camel@twins> <1329990828.19165.36.camel@ThinkPad-T61> <1330340324.11248.60.camel@twins> <1330941917.24353.63.camel@ThinkPad-T61> <1330969747.11248.250.camel@twins> <20120305214545.GH3083@redhat.com> <1331028583.15778.3.camel@ThinkPad-T61> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Vegard Nossum Cc: Don Zickus , Peter Zijlstra , LKML , tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, paulus@samba.org, mingo@elte.hu, acme@ghostprotocols.net, tony.luck@intel.com, bp@amd64.org, robert.richter@amd.com, lenb@kernel.org, minyard@acm.org, wim@iguana.be, linux-edac@vger.kernel.org, oprofile-list@lists.sf.net, linux-acpi@vger.kernel.org, openipmi-developer@lists.sourceforge.net, linux-watchdog@vger.kernel.org, Pekka Enberg List-Id: linux-acpi@vger.kernel.org On Tue, 2012-03-06 at 11:27 +0100, Vegard Nossum wrote: > On 6 March 2012 11:09, Li Zhong wrote: > > This patch tries to fix the problem of page fault exception caused by > > accessing nmiaction structure in nmi if kmemcheck is enabled. > > > > If kmemcheck is enabled, the memory allocated through slab are in pages > > that are marked non-present, so that some checks could be done in the > > page fault handling code ( e.g. whether the memory is read before > > written to ). > > As nmiaction is allocated in this way, so it resides in a non-present > > page. Then there is a page fault while the nmi code accessing the > > nmiaction structure, which would then cause a warning by > > WARN_ON_ONCE(in_nmi()) in kmemcheck_fault(), called by do_page_fault(). > > > > v2: as Peter suggested, changed the nmiaction to use static storage. > > > > v3: as Peter suggested, use macro to shorten the codes. Also keep the > > original usage of register_nmi_handler, so users of this call doesn't > > need change. > > > > Signed-off-by: Li Zhong > > Looks like you've solved this now. Thanks. There is still one place [2/2] not solved ... and I guess it might need the way you suggested below. > > For the record, another way to prevent the page fault from happening > in the first place is to set up a new slab cache with the flag > SLAB_NOTRACK. This is different from the GFP_NOTRACK flag which, as > you noted, doesn't prevent page faults, just inhibits > checking/warnings for those memory areas. > > It's a bit of a hassle, I admit. Maybe we could create an additional, > separate set of slab caches (using SLAB_NOTRACK) and a new GFP flag > which selects this set of caches instead. This would allow anything > that takes a gfp_t to allocate memory that is guaranteed not to page > fault when using kmemcheck. Pekka, any thoughts? > I'm not sure whether I understand it correctly? If CONFIG_KMEMCHECK is enabled, create another two sets of malloc_sizes caches, one for cs_cachep, one for cs_dmacachep, both with SLAB_NOTRACK flag. Create a new GFP flag, like __GFP_NO_PF for those places where page fault is not allowed, and return memory from the caches created above. This new GFP flag is set to 0 if CONFIG_KMEMCHECK is not enabled. I think there shouldn't be many such cases, so most of these caches wouldn't actually be used ... Thanks, Zhong > > Vegard >