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 F1D66C4332F for ; Thu, 6 Oct 2022 09:29:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7666E8E0002; Thu, 6 Oct 2022 05:29:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 716C18E0001; Thu, 6 Oct 2022 05:29:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B6D28E0002; Thu, 6 Oct 2022 05:29:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4764A8E0001 for ; Thu, 6 Oct 2022 05:29:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 169ABC10C5 for ; Thu, 6 Oct 2022 09:29:37 +0000 (UTC) X-FDA: 79990001994.07.934BB19 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 3D8EF20023 for ; Thu, 6 Oct 2022 09:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665048575; 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=+smpxbXq4s4VZXWHyY6FHA0tm1OoQPC2gTDZdrKKgFc=; b=DdAjqBcrgvwx19qFteCVEVdmnbafw2e4HtYDpoBv21ey0nE3bnE+XvsN2RG6a6oC+P58sO ZhpT+C8G4UZECdTIWNmQVsGu2r+qyteCmpMjL1vRrRUnt8DEmwKOSu5tyHVcluKQI+uvEl DDm++fFHf/GWfvbGXsrSbPdk0RHFIDw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-481-7jv2B6PxO2O6X9n791n5eg-1; Thu, 06 Oct 2022 05:29:32 -0400 X-MC-Unique: 7jv2B6PxO2O6X9n791n5eg-1 Received: by mail-wr1-f70.google.com with SMTP id e11-20020adfa74b000000b0022e39e5c151so303617wrd.3 for ; Thu, 06 Oct 2022 02:29:32 -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:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=+smpxbXq4s4VZXWHyY6FHA0tm1OoQPC2gTDZdrKKgFc=; b=fQI6jgPOw65vgOIbhMnLEsqNVdNxY+JBYFUzS2gw/kzk00CEoqPJgJOjq6Ha9UWEaI Wi0FoPLkGtg4NCmZzfTEflgB1HASZ3D5G0ZFpZfVn+K0VhUWCAuJ0v7zvpFOKUEtiakd ytg91M/6MGQAeZm6lxmveORzHC3R2u+mZSXkVcA7Aqd5ARDZZQqELhWgaKoP+TBVLclk jM9SEcT0DRhNjUO01mtF+zHCFTtUN1GPSjLYb3JC+9CBoc/yv5x8p7xlyDCbIhsXDhsY qBOktsRdntSoq/55FLbflZWwz/v+ImrTrVFZV6XzXyxha6SJTMNMTpw8BpZAe7nVJEbp TBFg== X-Gm-Message-State: ACrzQf2KgEdO0EVo0MjhF5KDlnhAYJUSayBVyDSUd8PxBmbr2jw/5GUx yAQzMp1QGieEzslJOQeROR3mMqe0+tN7PDSWv1OCuXrxW7IyojadTFJjcHrUVWfItDPtWVOu7eS sLftf+dylGuI= X-Received: by 2002:a5d:51c2:0:b0:22e:3c45:9eff with SMTP id n2-20020a5d51c2000000b0022e3c459effmr2417259wrv.118.1665048571476; Thu, 06 Oct 2022 02:29:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4sLsL83Bl3DnANSzkrKeNP7L6BNgjr9mJL7tkJpTRVq2QeiBP58gaQpBqj4Eq8uMYVJLrszg== X-Received: by 2002:a5d:51c2:0:b0:22e:3c45:9eff with SMTP id n2-20020a5d51c2000000b0022e3c459effmr2417236wrv.118.1665048571137; Thu, 06 Oct 2022 02:29:31 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:3700:aed2:a0f8:c270:7f30? (p200300cbc7053700aed2a0f8c2707f30.dip0.t-ipconnect.de. [2003:cb:c705:3700:aed2:a0f8:c270:7f30]) by smtp.gmail.com with ESMTPSA id k16-20020adfd850000000b0022e3538d305sm14750024wrl.117.2022.10.06.02.29.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Oct 2022 02:29:30 -0700 (PDT) Message-ID: Date: Thu, 6 Oct 2022 11:29:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , "Matthew Wilcox (Oracle)" , Jason Gunthorpe , John Hubbard References: <20220930141931.174362-1-david@redhat.com> <20220930141931.174362-5-david@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1 4/7] mm/ksm: fix KSM COW breaking with userfaultfd-wp via FAULT_FLAG_UNSHARE In-Reply-To: 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=1665048576; 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=+smpxbXq4s4VZXWHyY6FHA0tm1OoQPC2gTDZdrKKgFc=; b=a3U2AAJjSlgNwkOOt6bcn3kqkjR12pBE+82ldS1XUmrdM8SdXagwOQc9BXi9fmX/8G4cWg 1J9FGeCK5mHczgggzTrEda51UypTUx3pJ5Y4CdbbYoRiNs1pa6z6VWRqZd8Pb7mNGH12YN uSHm+HgbjrE/lF8vHbCZilqxXUHmucE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DdAjqBcr; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665048576; a=rsa-sha256; cv=none; b=mRgxNDYUsfF9+sGa0/bfr9O5MbVMksjSvMyvgy8qbeMiNSqcZttp+w3fgxCKoM6q+S6PwW nc1TXL0PYtcZGxQVbq9mkoleZz6uVnEb4mDRWUcXsi7AsHwnm1ioByHKw285gQ5M8eQeZ1 hAfbibevo3/tUBlOyACnrgeUfz5I8gc= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3D8EF20023 X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DdAjqBcr; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Stat-Signature: eqtjxr5wu1s7p7ojf3zqfggfkb1u5jkc X-HE-Tag: 1665048576-114500 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 05.10.22 22:35, Peter Xu wrote: > On Fri, Sep 30, 2022 at 04:19:28PM +0200, David Hildenbrand wrote: >> Let's stop breaking COW via a fake write fault and let's use >> FAULT_FLAG_UNSHARE instead. This avoids any wrong side effects of the fake >> write fault, such as mapping the PTE writable and marking the pte >> dirty/softdirty. >> >> Also, this fixes KSM interaction with userfaultfd-wp: when we have a KSM >> page that's write-protected by userfaultfd, break_ksm()->handle_mm_fault() >> will fail with VM_FAULT_SIGBUS and will simpy return in break_ksm() with 0. >> The warning in dmesg indicates this wrong handling: >> >> [ 230.096368] FAULT_FLAG_ALLOW_RETRY missing 881 >> [ 230.100822] CPU: 1 PID: 1643 Comm: ksm-uffd-wp [...] >> [ 230.110124] Hardware name: [...] >> [ 230.117775] Call Trace: >> [ 230.120227] >> [ 230.122334] dump_stack_lvl+0x44/0x5c >> [ 230.126010] handle_userfault.cold+0x14/0x19 >> [ 230.130281] ? tlb_finish_mmu+0x65/0x170 >> [ 230.134207] ? uffd_wp_range+0x65/0xa0 >> [ 230.137959] ? _raw_spin_unlock+0x15/0x30 >> [ 230.141972] ? do_wp_page+0x50/0x590 >> [ 230.145551] __handle_mm_fault+0x9f5/0xf50 >> [ 230.149652] ? mmput+0x1f/0x40 >> [ 230.152712] handle_mm_fault+0xb9/0x2a0 >> [ 230.156550] break_ksm+0x141/0x180 >> [ 230.159964] unmerge_ksm_pages+0x60/0x90 >> [ 230.163890] ksm_madvise+0x3c/0xb0 >> [ 230.167295] do_madvise.part.0+0x10c/0xeb0 >> [ 230.171396] ? do_syscall_64+0x67/0x80 >> [ 230.175157] __x64_sys_madvise+0x5a/0x70 >> [ 230.179082] do_syscall_64+0x58/0x80 >> [ 230.182661] ? do_syscall_64+0x67/0x80 >> [ 230.186413] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > Since it's already there, worth adding the test into ksm_test.c? Yes, I can give it a try. What I dislike about ksm_test is that it's a mixture of benchmarks and test cases that have to explicitly triggered by parameters. It's not a simple "run all available test cases" tests as we know it. So maybe something separate (or having it as part of the uffd tests) makes more sense. > >> >> Consequently, we will no longer trigger a fake write fault and break COW >> without any such side-effects. >> >> This is primarily a fix for KSM+userfaultfd-wp, however, the fake write >> fault was always questionable. As this fix is not easy to backport and it's >> not very critical, let's not cc stable. > > A patch to cc most of the stable would probably need to still go with the > old write approach but attaching ALLOW_RETRY. But I agree maybe that may > not need to bother, or a report should have arrived earlier.. The unshare > approach looks much cleaner indeed. A fix without FAULT_FLAG_UNSHARE is not straight forward. We really don't want to notify user space about write events here (because there is none). And there is no way around the uffd handling in WP code without that. FAULT_FLAG_ALLOW_RETRY would rely on userfaultfd triggering and having to resolve the WP event. > >> >> Fixes: 529b930b87d9 ("userfaultfd: wp: hook userfault handler to write protection fault") >> Signed-off-by: David Hildenbrand > > Acked-by: Peter Xu > Thanks! -- Thanks, David / dhildenb