Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2321466ybb; Sat, 21 Mar 2020 19:05:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuAs5J15SSrMx/U6ek19eScBYOuoFDAmxLwwfPpbKzjtjdGUGUzuPOb7bisPt/HsyD9LkUo X-Received: by 2002:a05:6830:13d5:: with SMTP id e21mr13224493otq.37.1584842717517; Sat, 21 Mar 2020 19:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584842717; cv=none; d=google.com; s=arc-20160816; b=hpHW3fzLHlt/z0VBPJGYe1EXOK62VaKJwSVuK6TVlm4oYKzyu+w154VfqT0Uxgta2Q +fa/QXN7MACijTO64xvxVcy7zFheomqYiUti0EEHJmRadGePZmYvbb5oLxyFQS6D3GzA YBqe4J0GP9QEtO5sshzBkM4D+X6t+RKflkE4V/3aXJv/1UP9egT9FtVVy4ZqyEw+iTOw fNojclZjnoUKDfXIHVZDYn641hTSOyk02m/EmLjWuG05d2oCHRgUaYba3rxGEcU3pYO/ HhZRiea8voXJdH0oawiRDi1CODhNHuBZfmgULMve8iSFNHlEKC2gDBzavmbecHGJtKhh 9Uiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=0oLEv6h2GsY7etmwcwb3B6JzIa6mncrHOx3tmzkR0Og=; b=SZKUHyvYm8M2oobVIwMrWX/UUkkSR6ljgOCJE7tff0d90XupfR1OWwtWso8UCgeHkY dWDESjCIKii9nKI4dpE4yCV722WcnQsJPZXIqrUeZeH9FX+oT5uOos/8+OoG6NVWHgBW w6nfUUTVGVj5zkJ7O4MWRp8d57LwfLSXgzOtYswaPVxdzIsjElYhdjHRSroHEK2HU4ym Fk2v0HsmmhwM9UKBLNw30B8TO/Tphhkczr2ePwulkXOY5KU5w3l3MPn7dLTE6+f1qLwN A3hl1PSqtOSvSF77HXuMWDUYIxcpFbP0bPi4jHWHxeALeGR++L4qA7XDsSrCzdPxudvF v2Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MS5OrLk5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b197si5036004oii.198.2020.03.21.19.04.52; Sat, 21 Mar 2020 19:05:17 -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=@redhat.com header.s=mimecast20190719 header.b=MS5OrLk5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728134AbgCVCDf (ORCPT + 99 others); Sat, 21 Mar 2020 22:03:35 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:54011 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726409AbgCVCDe (ORCPT ); Sat, 21 Mar 2020 22:03:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584842613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0oLEv6h2GsY7etmwcwb3B6JzIa6mncrHOx3tmzkR0Og=; b=MS5OrLk5EyGD1XDlCS6+Jw7wTIrvqSiml17fywinmm22gZqhnwJY2Oovb8P1hhBiyHhNSq jxb/ovz7henItus+B73rmgYWLmg+yTWM89D9d6h865cscpzcuFsmqNYkVFOydczw1RuOrK CoVCahdRoahZFwYeMcYvpOPQrnOlwr4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-382-UOWmatbmNBC-pPp3B53xHg-1; Sat, 21 Mar 2020 22:03:31 -0400 X-MC-Unique: UOWmatbmNBC-pPp3B53xHg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 922BC189F760; Sun, 22 Mar 2020 02:03:30 +0000 (UTC) Received: from t490s (ovpn-112-44.phx2.redhat.com [10.3.112.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAF2B73884; Sun, 22 Mar 2020 02:03:29 +0000 (UTC) Date: Sat, 21 Mar 2020 22:03:26 -0400 From: Rafael Aquini To: Andrew Morton 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: <20200322020326.GB1068248@t490s> References: <20200322013525.1095493-1-aquini@redhat.com> <20200321184352.826d3dba38aecc4ff7b32e72@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200321184352.826d3dba38aecc4ff7b32e72@linux-foundation.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 21, 2020 at 06:43:52PM -0700, Andrew Morton wrote: > 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? > Mostly it's there to provide a sleeping gap after the fault, whithout actually adding an arbitrary value with usleep(). It's not a hard requirement, but, in some of the tests I performed (whithout that sleeping gap) I would still see around 1% chance of hitting the false-negative. After adding it I could not hit the issue anymore. > > 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); >