From patchwork Tue Oct 4 19:34:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12998647 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 51456C433F5 for ; Tue, 4 Oct 2022 19:34:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64BE28E0001; Tue, 4 Oct 2022 15:34:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49BF68E0002; Tue, 4 Oct 2022 15:34:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11DD68E0001; Tue, 4 Oct 2022 15:34:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E53006B0078 for ; Tue, 4 Oct 2022 15:34:09 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B87A440179 for ; Tue, 4 Oct 2022 19:34:09 +0000 (UTC) X-FDA: 79984267818.30.66C91A3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 23E3E18001E for ; Tue, 4 Oct 2022 19:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664912048; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ifodv0MqT+m7iheWymJyjwtmpsW2iF/ZrnT+XTcpadM=; b=d9bqvHzOhvjAjaAowAOgLbQHIYHrP2vCIVNUVKlxP2ESgp4TtQejHTmjV6FZeipTXu9Ymz 4xLntxeBBCfYlqudq8UE3uKeuy4CX+b4vUCN4IbkmgDtSYnCcEPNIFhgr3OR7JAsicpi1L 15P+edQIQvH0hZkSqe1jjgaFDu5AuyM= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-645-cZZ7uSVQNDq2mclvU5BzXA-1; Tue, 04 Oct 2022 15:34:07 -0400 X-MC-Unique: cZZ7uSVQNDq2mclvU5BzXA-1 Received: by mail-qk1-f200.google.com with SMTP id bs33-20020a05620a472100b006cef8cfabe2so12450570qkb.12 for ; Tue, 04 Oct 2022 12:34:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ifodv0MqT+m7iheWymJyjwtmpsW2iF/ZrnT+XTcpadM=; b=OteJk0uXZD3NtEY64CQNc+4S2TMOU1sNVBkh3ACg3BxaYHS2oXj5j12dhLXsj2W3fA VRqPpNngzeT88btqxcnVyJ/Evh+km0Dh4dMV+V0Ih3GSoLTCcFLDqtsG+Tt44f6/vCNI 9sfrpCAbgcUHFEUI3ZW+0I8UT7JD4Y1LqrhHH/GVEkyLYj1w/8oqQ69/9nt+hq1eA8zB 5vvYPHr09K9ASNyj/kmmNKnxWXM5V5FjarC026RoVEXTh+IOLdFFwWjItxK4qX5WTDdL xR9w7TlSt4OWHkx+6lNjYgDcbsU52j/xr5jBrrS2Tt6CjPIL8rfAdcFeeTwDe5ddimiQ qfMw== X-Gm-Message-State: ACrzQf0XrmWrHq7eB5tonkye8ptSgdCphORXWql32pQLJNL9g0MOT6n7 KFEkQbbZRJuhx/SpbTRluiezyQBzCIZPP46Y8c+ubPrn/WurwVf+koCMP06Po6vIjlg+83heX62 NS1xohulpgpBroKIuwAbjgHOTeU/4JlQ/cVIDLZiJcmfd2crhd2KDtk+jpQTi X-Received: by 2002:a05:622a:164e:b0:35b:a852:52ca with SMTP id y14-20020a05622a164e00b0035ba85252camr20719345qtj.2.1664912046785; Tue, 04 Oct 2022 12:34:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4arrLFNIId2qTFtBrd4SBa+FZyl8Drmu4Nnvp22VTiLuMn7OhMRWmkaEkQqUdfhfxWBgrhdQ== X-Received: by 2002:a05:622a:164e:b0:35b:a852:52ca with SMTP id y14-20020a05622a164e00b0035ba85252camr20719325qtj.2.1664912046503; Tue, 04 Oct 2022 12:34:06 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id z5-20020a05622a028500b00342fb07944fsm13299811qtw.82.2022.10.04.12.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 12:34:06 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Rapoport , peterx@redhat.com, David Hildenbrand , Andrew Morton , Andrea Arcangeli , Nadav Amit , Axel Rasmussen , Mike Kravetz Subject: [PATCH v3 3/3] mm/selftest: uffd: Explain the write missing fault check Date: Tue, 4 Oct 2022 15:34:00 -0400 Message-Id: <20221004193400.110155-4-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004193400.110155-1-peterx@redhat.com> References: <20221004193400.110155-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664912049; 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=ifodv0MqT+m7iheWymJyjwtmpsW2iF/ZrnT+XTcpadM=; b=2J4RLHSh9VLUoYC+iy84J5tylca22V8on5Qj7n6OJZXa2gbySNexXL29U+J47HYZT2HORa 149pm0TioBycpcWan4Dx7hGHJkRzAZktV/wctGfw04LZvtRRkOua4bUWZOROhYzoFQqz95 RrTNgMvls0N6mAcZUeonLcy/o2EvQSU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=d9bqvHzO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664912049; a=rsa-sha256; cv=none; b=hhYg9OZwXgTCy0Jq4jnp47mEh5U4BtvEcKeWH7PTXIVJot9uvUT44wPcmJabPm9B1TzXiI PwkEMNcwiB1+1f8G3XihJhYsIm5qaKgAZaN5NWJ3rdR2e7ImCfXtXNpQN6yJ7CRWy6xUep u5hq1v/vnmGZCUf1eo55HGmKGFGF7Lo= X-Stat-Signature: 9ek3gjx61jn9ngiyuy83kjqfh5z6o176 X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 23E3E18001E Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=d9bqvHzO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1664912048-856312 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: It's not obvious why we had a write check for each of the missing messages, especially when it should be a locking op. Add a rich comment for that, and also try to explain its good side and limitations, so that if someone hit it again for either a bug or a different glibc impl there'll be some clue to start with. Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 74babdbc02e5..297f250c1d95 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -774,7 +774,27 @@ static void uffd_handle_page_fault(struct uffd_msg *msg, continue_range(uffd, msg->arg.pagefault.address, page_size); stats->minor_faults++; } else { - /* Missing page faults */ + /* + * Missing page faults. + * + * Here we force a write check for each of the missing mode + * faults. It's guaranteed because the only threads that + * will trigger uffd faults are the locking threads, and + * their first instruction to touch the missing page will + * always be pthread_mutex_lock(). + * + * Note that here we relied on an NPTL glibc impl detail to + * always read the lock type at the entry of the lock op + * (pthread_mutex_t.__data.__type, offset 0x10) before + * doing any locking operations to guarantee that. It's + * actually not good to rely on this impl detail because + * logically a pthread-compatible lib can implement the + * locks without types and we can fail when linking with + * them. However since we used to find bugs with this + * strict check we still keep it around. Hopefully this + * could be a good hint when it fails again. If one day + * it'll break on some other impl of glibc we'll revisit. + */ if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) err("unexpected write fault");