From patchwork Mon Oct 3 15:56:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12997652 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 2E817C433FE for ; Mon, 3 Oct 2022 15:56:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D81EE6B0073; Mon, 3 Oct 2022 11:56:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE27A8E0003; Mon, 3 Oct 2022 11:56:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0E6F6B0075; Mon, 3 Oct 2022 11:56:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9D3EF6B0073 for ; Mon, 3 Oct 2022 11:56:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 48D491C5B41 for ; Mon, 3 Oct 2022 15:56:39 +0000 (UTC) X-FDA: 79980090918.26.AF0DBD6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id D334440017 for ; Mon, 3 Oct 2022 15:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664812598; 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=MLutX1nsPeGms5FwSsl0JmsXVFj0AoP8lzGgDk/TtB5zS/YfxRC1r47fNGYAsoBKKktAKg N2r6Sbb4l0/lDAqpA7gMlRUyNj/dNGwKazc/EStk+BLHiCfbHhaVLtvZ2i8lBV75uWy0uO eW0l5/Ksm1N7HFlAdIX8C5Jyk4dN7sQ= 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-501-ZMSBlpLDPmS4K6MZl3LTsA-1; Mon, 03 Oct 2022 11:56:37 -0400 X-MC-Unique: ZMSBlpLDPmS4K6MZl3LTsA-1 Received: by mail-qk1-f199.google.com with SMTP id k2-20020a05620a414200b006ceec443c8bso9453322qko.14 for ; Mon, 03 Oct 2022 08:56:37 -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=y69HTDt0QPz9PbQXcIfo4C2T57HX0cdpT9jBolBMK3WDsk8/d+6yTwX+I6Mt8+yoaK funa2IkczaO5TM6FL/oLQlEqu676QbrwIS0MXrkee7ZErQNx9mljRGMufdIyy5a9Njsb vJEgpIEiKuqbrA+ZlJXxTBB4PcUnWGWePKD2fY+Fvz5pGINp9IMCC+VQSwV3fk0tn+v0 Kd31gy5rpPlPaz1n5i2DaueflIozvmCq2+fWsjaW6TPQuTkEOz6Ir/nt7HYkk3idWlG5 xovXWQR0jcOfMPIXTTHqtoBNqPltJ5wu3TJF3s8LcbjgOp1sHlXboBFw/zBRNFRqpM/n kWiA== X-Gm-Message-State: ACrzQf1ngVmWi5tohQIs8/oL7uhwPPovM4QBauKk/5A/D4bpEOELXHfF M2oNzyKPXgFIQW5XhURmCIWzbC5dT9ROEQMr5JP0KAXDZstkZ3GLbjbB9gamp4ge/22yQeyO7xk QA1DpWv97D6Q= X-Received: by 2002:a05:620a:15d2:b0:6cf:2d38:9c0d with SMTP id o18-20020a05620a15d200b006cf2d389c0dmr14084013qkm.426.1664812596882; Mon, 03 Oct 2022 08:56:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YdLVN5mgUHqMX9gMAFXtuu3DO1SuWxQNyQcY/m8UTnt2zEXiE/KDGL7J7kdUZbNlU/tPU6w== X-Received: by 2002:a05:620a:15d2:b0:6cf:2d38:9c0d with SMTP id o18-20020a05620a15d200b006cf2d389c0dmr14083998qkm.426.1664812596639; Mon, 03 Oct 2022 08:56:36 -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 bs18-20020a05620a471200b006cf38fd659asm10956732qkb.103.2022.10.03.08.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:56:36 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: peterx@redhat.com, Andrea Arcangeli , Mike Rapoport , David Hildenbrand , Andrew Morton , Axel Rasmussen , Mike Kravetz , Nadav Amit Subject: [PATCH 3/3] mm/selftest: uffd: Explain the write missing fault check Date: Mon, 3 Oct 2022 11:56:30 -0400 Message-Id: <20221003155630.469263-4-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003155630.469263-1-peterx@redhat.com> References: <20221003155630.469263-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=1664812598; 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=i30/7hIJAxGluVjMbZUy18b9w77Q8Iq3oaJeBGdsbX6dx9oWNf1F4BmO7uIwnws1KHHxOR 5bdykaP/CExAfSmh5PUw1GFuANCFIPq3WzQO7HH/4hjE9v92X17rRbwuMNuaF38CHLN1IS Z4NfWuLuLaUEZZ/uQHE/oSYGSaUitzc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MLutX1ns; spf=pass (imf07.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=1664812598; a=rsa-sha256; cv=none; b=G6hl98XqfSdCH0PxXHVU60EYFA2s6vTin7AOK74JzIdePOVa4LfiLWDrmbfHeBjBTfQBKn lfWnbH/JIFnhxjrHLO3xGhEgpn5+iCKgoJXo2JBH4JlLfrv0OjkoX2HfibBwlKQPRxnjnc A8LTe7ABDtmh4ny2GPGZMO/fcRj/1eU= X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MLutX1ns; spf=pass (imf07.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: rspam12 X-Rspamd-Queue-Id: D334440017 X-Stat-Signature: hjbd4ic8n8m39wi6w336fpgxpsxxt3py X-HE-Tag: 1664812598-458433 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 --- 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");