Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2310969ybb; Sat, 21 Mar 2020 18:45:22 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs6e9GtNQQ26LNblN8QeYz9wnYi8Nk3Y2ar4X7WyMtyY4xrCs6DCQRt2ufmX8Nz/qSyWfq3 X-Received: by 2002:aca:cf0d:: with SMTP id f13mr12088854oig.162.1584841522657; Sat, 21 Mar 2020 18:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584841522; cv=none; d=google.com; s=arc-20160816; b=WmO5tm5ifZ0QSTIyraMJaEIYZue7VD7GTpPhXsJ3jIEr46aI7UB7LjgNyz4sXDvq/E /3h4uoRF/kBOD1pATQq2G3TqeN7ByF09V4efLqYriY8xA+OoCfPNqxApuKTd7ndEtFF9 NMn/hgfBW0GnbZEqFb6HpIZ8JDVJeNtYaN1Mhw3d4bB4iGIYTKZWdSG9LZ0I5qP31ZSM Fd61+bU69fdfe5xYYBOS03ruwNw8rwDnRlxUVs7mjs0IPXOo1Kex3vwNQQuyH5fWAOOr 2KnD63r6ywDRynIoOti09IHZLXqPzYeH3o7D11B9EiZv908I45G6oxmwL3OcvbFoUWUj Xk/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=yOXMDbPQ14ob4JoEcXAR82wZiiuSyPotF0tHUa+vy4k=; b=d9a1LV9z4tagM2Kck/FWfObGXGpQUV0JGTJEAlnP1K0/tkhQQyZiqWxL90O2EiXNtB 6v6HhZ0/nCnkdE5p1q2CTMG4rc64gO7S7+rmOcOdO0fvtvV5BocmL6o7bzGO2kNPtCEO M7qunz56UsKS4LDwPQ/8mIizRS25eHGIZw6VeFGZpcjKABedWHbh4+aqf3eOi0WWGcf3 AY0XPumbrnyoFJ2aDWZwnkR7q3jWwfQqfItbhGKyuzkDJaoifNUmmofC1ag6vgwFAMBe 26qGc0EKRDC8ko9E0HkgOosA7zdqwIQ3Zfi0JQfP3EqyGemDm0mG0ARRxUTLGDPJPIqL 5L/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x8BOMsYz; 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 c10si5275285oif.81.2020.03.21.18.45.10; Sat, 21 Mar 2020 18:45:22 -0700 (PDT) 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=pass header.i=@kernel.org header.s=default header.b=x8BOMsYz; 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 S1728111AbgCVBnx (ORCPT + 99 others); Sat, 21 Mar 2020 21:43:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:50280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbgCVBnx (ORCPT ); Sat, 21 Mar 2020 21:43:53 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F013520754; Sun, 22 Mar 2020 01:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584841433; bh=Q13b5glXHFBJZs1KR/nBSkLQOAK6lOsqQAlibGsDiWU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=x8BOMsYzf23Ri1SZ98QIxxvV84n0HJHGdEmX14iaF5afC8+0ple2Y5EIotpsEt4H8 7Kq0tTfa4BqpLHdDMnMpiMfwl2gmY9LWDgD8l/h5RX20/dpyIAKQ187qNOqmmWCk11 TXOr85yg95o5fw8xXEi+IeXo80241NgGjbivE71g= Date: Sat, 21 Mar 2020 18:43:52 -0700 From: Andrew Morton To: Rafael Aquini Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org, shakeelb@google.com Subject: Re: [PATCH] tools/testing/selftests/vm/mlock2-tests: fix mlock2 false-negative errors Message-Id: <20200321184352.826d3dba38aecc4ff7b32e72@linux-foundation.org> In-Reply-To: <20200322013525.1095493-1-aquini@redhat.com> References: <20200322013525.1095493-1-aquini@redhat.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 21 Mar 2020 21:35:25 -0400 Rafael Aquini wrote: > Changes for commit 9c4e6b1a7027f ("mm, mlock, vmscan: no more skipping pagevecs") > break this test expectations on the behavior of mlock syscall family immediately > inserting the recently faulted pages into the UNEVICTABLE_LRU, when MCL_ONFAULT is > passed to the syscall as part of its flag-set. > > There is no functional error introduced by the aforementioned commit, > but it opens up a time window where the recently faulted and locked pages > might yet not be put back into the UNEVICTABLE_LRU, thus causing a > subsequent and immediate PFN flag check for the UNEVICTABLE bit > to trip on false-negative errors, as it happens with this test. > > This patch fix the false negative by forcefully resorting to a code path that > will call a CPU pagevec drain right after the fault but before the PFN flag > check takes place, sorting out the race that way. > > > +/* > + * After commit 9c4e6b1a7027f ("mm, mlock, vmscan: no more skipping pagevecs") > + * changes made by calls to mlock* family might not be immediately reflected > + * on the LRUs, thus checking the PFN flags might race against pagevec drain. > + * > + * In order to sort out that race, and get the after fault checks consistent, > + * the "quick and dirty" trick below is required in order to force a call to > + * lru_add_drain_all() to get the recently MLOCK_ONFAULT pages moved to > + * the unevictable LRU, as expected by the checks in this selftest. > + */ > +static void force_lru_add_drain_all(void) > +{ > + sched_yield(); > + system("echo 1 > /proc/sys/vm/compact_memory"); > +} What is the sched_yield() for? > static int onfault_check(char *map) > { > unsigned long page_size = getpagesize(); > @@ -343,6 +360,9 @@ static int onfault_check(char *map) > } > > *map = 'a'; > + > + force_lru_add_drain_all(); > + > page1_flags = get_pageflags((unsigned long)map); > page2_flags = get_pageflags((unsigned long)map + page_size); > > @@ -465,6 +485,8 @@ static int test_lock_onfault_of_present() > goto unmap; > } > > + force_lru_add_drain_all(); > + > page1_flags = get_pageflags((unsigned long)map); > page2_flags = get_pageflags((unsigned long)map + page_size); > page1_flags = get_kpageflags(page1_flags & PFN_MASK);