From patchwork Tue Oct 4 00:37:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12997903 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 E64DCC433F5 for ; Tue, 4 Oct 2022 00:37:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80C776B0075; Mon, 3 Oct 2022 20:37:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BBF76B0078; Mon, 3 Oct 2022 20:37:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65CD86B007B; Mon, 3 Oct 2022 20:37:16 -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 577456B0075 for ; Mon, 3 Oct 2022 20:37:16 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2B036A024D for ; Tue, 4 Oct 2022 00:37:16 +0000 (UTC) X-FDA: 79981402872.26.0A191F7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id C26D9140017 for ; Tue, 4 Oct 2022 00:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843835; 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=/5RzxXUZxi/MrG066VL+DnGEo1qQl33988Rm0NK9+zA=; b=DPf/j94C6+6CGdgVPxH/Nsb88vKxSg+Go+vg29C9i4208SXa2hXJdyuwzdfTbGACy9sa3O f2/tNaiqb8f/Q2P45bAzLj9a+Sp182TYPqJmaAd/NjYsxN06FV23l4KaDN44j2plvyAL4D SBMwr+jjhRLw3PIF/h4Hh5uCsPCazo4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-627-FKMt01wyPI-HYbqRCYfeWA-1; Mon, 03 Oct 2022 20:37:12 -0400 X-MC-Unique: FKMt01wyPI-HYbqRCYfeWA-1 Received: by mail-qk1-f199.google.com with SMTP id j13-20020a05620a288d00b006be7b2a758fso10282922qkp.1 for ; Mon, 03 Oct 2022 17:37:12 -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=/5RzxXUZxi/MrG066VL+DnGEo1qQl33988Rm0NK9+zA=; b=qfwc6BlcUeG5wuJ3lmGZfsYvxLoeDEoFJ7jrCjTzjSQGZ7Dtplb1sGTfn9+4QElivY 8S/FkCTxH/xHuZynRb6cUcmRhLiP9DGg2v4kOfYLXO78SROlbuw2s9HdJ9HRyK1WqLMP 463WkcEkKcMXXxAEJIf4uVTCQDzRkHy2tvkz5C+tPEKTBB+TjKJCbXblDIlVxZI+PHCV leUAjEyL9b2JP3ngrlnsih+NNxNNo53k4ssDwq5bPLMHOP72azTnzKGrFms8HWft5Ih7 0zznMq2jlIeTPwlknf5lD9D2so3wMJe/6le7fpUPH53PSeAZ3h278SjOqFCAK5+F8R4h 1Heg== X-Gm-Message-State: ACrzQf3wY3Dzgez83iuTb1MaMtp8ai2iiuaSnp6HfSAKl3eu2l8O7Ohb CjeeGUHyAahdnGcjdhby/YEk8BSs0kOZsk0mcq3BDsftKGS9uyhYnQ/IymN/kIuD6+xHGj54dJs knR4+n/dVQPk= X-Received: by 2002:a05:620a:46a4:b0:6ce:c4af:5a54 with SMTP id bq36-20020a05620a46a400b006cec4af5a54mr15459014qkb.377.1664843831965; Mon, 03 Oct 2022 17:37:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UooKxylyfkc7pYh77HC484ZRa3g4v9oRRuF3krQ3VgFlBVG5fQ7DBFiKYYqVi1SHhupwxmg== X-Received: by 2002:a05:620a:46a4:b0:6ce:c4af:5a54 with SMTP id bq36-20020a05620a46a400b006cec4af5a54mr15459007qkb.377.1664843831739; Mon, 03 Oct 2022 17:37:11 -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 u30-20020a37ab1e000000b006bb9125363fsm12228104qke.121.2022.10.03.17.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 17:37:11 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: peterx@redhat.com, Andrew Morton , David Hildenbrand , Nadav Amit , Mike Kravetz , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport Subject: [PATCH v2 3/3] mm/selftest: uffd: Explain the write missing fault check Date: Mon, 3 Oct 2022 20:37:05 -0400 Message-Id: <20221004003705.497782-4-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004003705.497782-1-peterx@redhat.com> References: <20221004003705.497782-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=1664843835; 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=/5RzxXUZxi/MrG066VL+DnGEo1qQl33988Rm0NK9+zA=; b=hd/gJbuCqvFIypWK1ZL3FnBQjiXdX4NVkaotc6O3cj+GwrqFX9wKFleVgKMSXH729ka73R 4MOq32xBZ1WjF3y/leY9zjv1YqGB3Kfpu+dRNBxHOEkHHNM6Rw6HFfNUjL3lIjqvqDFb1K 1BBnUTWReMZUmb7LZSilNwb/Uy5MQ7s= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="DPf/j94C"; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664843835; a=rsa-sha256; cv=none; b=GhZomRwoAe4Ch2hl+vuHG+TKjub3jPApOxCHzesRUKuLKpF2XN2wPGI311FDnhQGsLDfxu jHKa5DWQau3wLeNNioBZqhrqEYpc/P/x89I7bh+UnP0B/It4o/XsEIcROJm0RR4o3pCsyC p9dH/t1n1PpiG7dUCfdTgx57wE1fm7Q= X-Rspamd-Queue-Id: C26D9140017 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="DPf/j94C"; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: tc7wmxh4cbj553rpj7gcye1bkf9xwqeh X-HE-Tag: 1664843835-160592 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. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand --- 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");