From mboxrd@z Thu Jan 1 00:00:00 1970 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 50E40C433FE for ; Tue, 4 Oct 2022 12:20:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7D866B0072; Tue, 4 Oct 2022 08:20:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2D216B0074; Tue, 4 Oct 2022 08:20:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA6AC6B0075; Tue, 4 Oct 2022 08:20:58 -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 A601E6B0072 for ; Tue, 4 Oct 2022 08:20:58 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 53350C0994 for ; Tue, 4 Oct 2022 12:20:58 +0000 (UTC) X-FDA: 79983176196.20.74E55CE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id DF2DC40014 for ; Tue, 4 Oct 2022 12:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664886057; 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=FmYbzauBro8vmjMuuRDX3URZE5ffnFmx7G/2HXpXgtM=; b=EGQSKKfcmXsvvsilIEXJNhB5foV6OGR45br6N5oGeAfEc5wz0O60mEjD/qVq4OV/GOR7U0 bi8ct4LeIHgfrKWmmyM582EMWeEVZJUWI+w2HRGEma4HdQOLm5swOkU2oCvNbvFc1xTZty 3A+8E/rrXllVuHZwHNf2NuP7sAqKPLA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-38-jnNNq_p2PQ2x5uqvWEZAOQ-1; Tue, 04 Oct 2022 08:20:54 -0400 X-MC-Unique: jnNNq_p2PQ2x5uqvWEZAOQ-1 Received: by mail-wr1-f69.google.com with SMTP id s5-20020adf9785000000b0022e1af0e7e8so2476261wrb.11 for ; Tue, 04 Oct 2022 05:20:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=FmYbzauBro8vmjMuuRDX3URZE5ffnFmx7G/2HXpXgtM=; b=DwjnE36gxaoPfMWxd/u55w+zAUEul2lYfTQg4AhjZjCCCexSRl5U7TcFw8mbuqHPYO ysWH90oM3+b0k56y1Jw+jkio6uNjkceRP/gWPUk9MtyL3UJZtX/hUc0ydzktAx5EQhlu 0tB+X46PYHdIVJIXszaMnfRCVMpap5TQW5GCfTS0fspLds/F93iEOedNbfeKtODH+BZG gBVdzMQgbl8BqEONDjyTAeC8Tzb+ErnZS6xjI2A7vjcwHjgDhNOjDSF6RjIeQseii5Rs jBXhSmLlCi1yDI27PM91cF0udIHg0oEugG+vTQ/DpghQwIM0MBfE35utHPrs/LKkUgnq ymmA== X-Gm-Message-State: ACrzQf11hEwq3Bh1zUhSql4v/dAw/iuUO2n33JUgUNHShxy28GztMbmQ Bg261ey69Q//VXRLyX/kXAhoUKhh8MbtXN0XEs0fH+FmH1Nbla5Sh7kX3xDLLETTS3Rt0nyhyFf +Jh7NJ45Lcis= X-Received: by 2002:a05:600c:3d86:b0:3b4:b65f:a393 with SMTP id bi6-20020a05600c3d8600b003b4b65fa393mr10217711wmb.0.1664886053225; Tue, 04 Oct 2022 05:20:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63LSNpJtRkOtNEv1B4u9KA+okwjGBtQbtCq0O81IXbU5C07q3ECIIrQhYometIdTC4zPA2Bg== X-Received: by 2002:a05:600c:3d86:b0:3b4:b65f:a393 with SMTP id bi6-20020a05600c3d8600b003b4b65fa393mr10217689wmb.0.1664886052961; Tue, 04 Oct 2022 05:20:52 -0700 (PDT) Received: from ?IPV6:2003:cb:c706:5000:4fff:1dd6:7868:a36? (p200300cbc70650004fff1dd678680a36.dip0.t-ipconnect.de. [2003:cb:c706:5000:4fff:1dd6:7868:a36]) by smtp.gmail.com with ESMTPSA id z15-20020a056000110f00b0022e0580b7a9sm3697476wrw.17.2022.10.04.05.20.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Oct 2022 05:20:52 -0700 (PDT) Message-ID: <87c2ce28-41fa-cc10-8c8f-3b831621df35@redhat.com> Date: Tue, 4 Oct 2022 14:20:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH v2 3/3] mm/selftest: uffd: Explain the write missing fault check To: Peter Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Nadav Amit , Mike Kravetz , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport References: <20221004003705.497782-1-peterx@redhat.com> <20221004003705.497782-4-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221004003705.497782-4-peterx@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664886057; 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=FmYbzauBro8vmjMuuRDX3URZE5ffnFmx7G/2HXpXgtM=; b=ZsxYFZc7W3yh6RK3jdEyDUX4E90iL71yJUy/0fvydkPJPMkmTaXsQR0O7KfqgfEeU7DUeO /3WEhuwSwttSEHzVpDtknLEHdjENhXynGUYkxwcDxF1EAeEP9J8z8P/fZgo5fUmSxLHCpG EQy7W7vTENHdAWwVnsmU1kPZrH1ZpEo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EGQSKKfc; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664886057; a=rsa-sha256; cv=none; b=y20qoA/kDSpA/Ug7nhhQQEfCMHh/XX5EckPuo0/xPzloQddo3Wwr9OD3i3oX8qggoTqQ+f 17Rb2PlBe8b+HS/V+84Pb3UQCo+JWByTOGwldqBuF2yrzRa1gxc204uDYd9W/TcGjZaC9u mlpzrIoIB6KG6mNi7IHwmuWa8YRj/ks= X-Stat-Signature: 7wgbw3baj3tnywynqa9bekzikdwhz55t X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DF2DC40014 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EGQSKKfc; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-HE-Tag: 1664886057-171258 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: On 04.10.22 02:37, Peter Xu wrote: > 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"); > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb