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 5F678C433F5 for ; Mon, 3 Oct 2022 15:24:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B28816B0071; Mon, 3 Oct 2022 11:24:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD8968E0001; Mon, 3 Oct 2022 11:24:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92BBF6B0074; Mon, 3 Oct 2022 11:24:27 -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 7EB386B0071 for ; Mon, 3 Oct 2022 11:24:27 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 45C121A0A36 for ; Mon, 3 Oct 2022 15:24:27 +0000 (UTC) X-FDA: 79980009774.26.1D85500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id D914C100017 for ; Mon, 3 Oct 2022 15:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664810666; 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: in-reply-to:in-reply-to:references:references; bh=3AwdTyRgIKZxfca+bCraTzGFElDPhfgV2yzBJDWIiIc=; b=MeTJxrm57KLc2WsITx0z9zSK+syKfY91RbufTAYXNQ4T/wWjjdY8uiNYCXH9vTWLOCeKol 4lYExmnwFHq8h4ZJdCuKYiyR7VVh68YmXjTeCN8loIJhldIGxFZ8XHEiuQmdb3uvqdD520 67aFv3VfBX4NkcqBuPAuvF/2qi94q8Y= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-594-Z-TnEoxoOPy27tri5Sx2qg-1; Mon, 03 Oct 2022 11:24:25 -0400 X-MC-Unique: Z-TnEoxoOPy27tri5Sx2qg-1 Received: by mail-qt1-f198.google.com with SMTP id s21-20020a05622a1a9500b0035bb9e79172so7560108qtc.20 for ; Mon, 03 Oct 2022 08:24:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=3AwdTyRgIKZxfca+bCraTzGFElDPhfgV2yzBJDWIiIc=; b=ArFUM+jd5NWgWtOgKcm+pOD6BM8H5V9i8dPgFGx9BkMdkh82yRh4vdVwn7E/7qQLXu Q++cjVlsedOphPbvxk4N35UDLqDJIfkRPmumXLu+eHFDIA1rPiy6B2iBRzjxpbt35ywJ FlZIb7Bnq9kmSIXFrPJJMM05wK1DS157W35Y1mdKJOdIUZyr8m+UygnfcLuWNLhdAS5b NAorq+fyrGnXz0AIu2XIvtTlU1gu88F2vV+YRW0cyH6OmQZUes8QrhBlaps0k1Zb7Qmy mh9vzblH2pzqaikH+eYCFxuwOGz3AArnROdMHUIOncoOrOZ0PBsG/z/ondZgLbeGOXPu CdYg== X-Gm-Message-State: ACrzQf3zfyoa6sizftkES7dE+au7ZeP6/iQGLZWNTGVmtOkt1ceRtbf0 tsGlvNYONHQi6FxkEvRG3RpzOowNReOLV9rdrZkOnDzoXARwV2RqJLgurbB1Iyv9UCxrQTGSekT 7+58XWb/GxNg= X-Received: by 2002:ac8:7c52:0:b0:35c:e867:e5dc with SMTP id o18-20020ac87c52000000b0035ce867e5dcmr16317161qtv.433.1664810663650; Mon, 03 Oct 2022 08:24:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM75+guqfvitKMHt9acY1KnWc0Ffw2urIGw9EPlUgaFxrFqUOb0XvvvW82FgW2oMKtjOW6O2Ww== X-Received: by 2002:ac8:7c52:0:b0:35c:e867:e5dc with SMTP id o18-20020ac87c52000000b0035ce867e5dcmr16317135qtv.433.1664810663435; Mon, 03 Oct 2022 08:24:23 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id o15-20020a05620a22cf00b006bb78d095c5sm10613381qki.79.2022.10.03.08.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:24:22 -0700 (PDT) Date: Mon, 3 Oct 2022 11:24:21 -0400 From: Peter Xu To: Mike Kravetz Cc: Hugh Dickins , Axel Rasmussen , Yang Shi , Matthew Wilcox , syzbot , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, nathan@kernel.org, ndesaulniers@google.com, songmuchun@bytedance.com, syzkaller-bugs@googlegroups.com, trix@redhat.com Subject: Re: [syzbot] general protection fault in PageHeadHuge Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664810667; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3AwdTyRgIKZxfca+bCraTzGFElDPhfgV2yzBJDWIiIc=; b=eEklVMsK5cylS20celRM9vRb1+7r42ryrCCkeERGz7KUQDk8L3lSVUbi2Ne18+/iuvCO9C ncULt/Gf48H/kGaWVbZ0wf22V2rzonh+JkK7ML5UBOqOzAuI5utSVP6cYUV+T+OSY7gi09 8m+nANnX2+08rRK0aeGRZkX86gJDYUY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MeTJxrm5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664810667; a=rsa-sha256; cv=none; b=YQNJp13cmo/+1O1DZyM3KSnquZYfR6W0Dy+B4Kg00/La9kpRLo9r78BsSdtllgFyXWya77 V7GITrmL1oq7VS2O5UG7pbEs935hVkJR3kCXmrmhafMtwujLDBF7pDtCGMnRHEnoeL/NqF /vxzL8vuzEU6bkJr7LXQw+W2tgg5tbU= X-Stat-Signature: 38mpik3ds48j3sm47wncpx36sund6apq X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D914C100017 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MeTJxrm5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1664810666-354186 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 Sun, Oct 02, 2022 at 06:16:53PM -0700, Mike Kravetz wrote: > On 09/30/22 23:01, Peter Xu wrote: > > On Fri, Sep 30, 2022 at 10:47:45PM -0400, Peter Xu wrote: > > From fe9e50551f3fdb7107315784affca4f9b1c4720f Mon Sep 17 00:00:00 2001 > > From: Peter Xu > > Date: Fri, 30 Sep 2022 22:22:44 -0400 > > Subject: [PATCH] mm/hugetlb: Fix race condition of uffd missing handling > > Content-type: text/plain > > > > Signed-off-by: Peter Xu > > --- > > mm/hugetlb.c | 36 +++++++++++++++++++++++++++++++++--- > > 1 file changed, 33 insertions(+), 3 deletions(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index dd29cba46e9e..5015d8aa5da4 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -5557,9 +5557,39 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, > > if (!page) { > > /* Check for page in userfault range */ > > if (userfaultfd_missing(vma)) { > > - ret = hugetlb_handle_userfault(vma, mapping, idx, > > - flags, haddr, address, > > - VM_UFFD_MISSING); > > + bool same; > > + > > + /* > > + * Since hugetlb_no_page() was examining pte > > + * without pgtable lock, we need to re-test under > > + * lock because the pte may not be stable and could > > + * have changed from under us. Try to detect > > + * either changed or during-changing ptes and bail > > + * out properly. > > + * > > + * One example of changing pte is in-progress CoW > > + * of private mapping, which will clear+flush pte > > + * then reinstall the new one. > > + * > > + * Note that userfaultfd is actually fine with > > + * false positives (e.g. caused by pte changed), > > + * but not wrong logical events (e.g. caused by > > + * reading a pte during changing). The latter can > > + * confuse the userspace, so the strictness is very > > + * much preferred. E.g., MISSING event should > > + * never happen on the page after UFFDIO_COPY has > > + * correctly installed the page and returned. > > + */ > > Thanks Peter! > > The wording and pte_same check here is better than what I proposed. I think > that last paragraph above should go into the commit message as it describes > user visible effects (missing event after UFFDIO_COPY has correctly installed > the page and returned). Will do. > > This seems to have existed since hugetlb userfault support was added. It just > became exposed recently due to locking changes going into 6.1. However, I > think it may have existed in the window after hugetlb userfault support was > added and before current i_mmap_sema locking for pmd sharing was added. Agreed. > Just a long way of saying I am not sure cc stable if of much value. Logically the change is stable material. I had worry that after uffd-wp intergration with hugetlb it's indeed possible to trigger on the CoWs we're encountering already, so IMO still something good to have for 5.19. I just saw that you proposed a similar fix in 4643d67e8cb0b35 on a similar page migration race three years ago. I'm not sure whether it also can happen with uffd missing modes too even before uffd-wp introduced. I think I'll first post the patch with Fixes attached without having stable tagged, but let me know your thoughts. No worry on the backport, I can take care of doing that and tests. I also plan to add your co-devel tag if you're fine with it because this patch is a collaboration effort IMO, but please let me know either here or directly replying to the patch if it's posted if you think that's inproper in any form. Thanks Mike! -- Peter Xu