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 7A938C433EF for ; Wed, 13 Jul 2022 16:10:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1934C94014E; Wed, 13 Jul 2022 12:10:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 11BD1940134; Wed, 13 Jul 2022 12:10:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED72894014E; Wed, 13 Jul 2022 12:10:11 -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 E007F940134 for ; Wed, 13 Jul 2022 12:10:11 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B179861241 for ; Wed, 13 Jul 2022 16:10:11 +0000 (UTC) X-FDA: 79682563422.08.95671DA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 0C66B100051 for ; Wed, 13 Jul 2022 16:10:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657728610; 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=ALptCerQqkMffu36Xn3Y1CRPKREEsyyCZnU0VjkcIA8=; b=S9t5TCPlMzpfB+S8rrhmnfsEm3VUNNaGVdQrF2jEB/B+ZmkR4BYZZaq+CDiq2HHUrZLhG+ VPrXSzoEWn/HVVvCb6Dhm9GJM4Eb2Cjwjayr4VZRlBQWXQXHEtcB2yKBRQawucxoB8zY6K DhL24qAl0SYFCTXmukxgcu9NmyOiTl0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-37-rHBqAnyEMoq4wk7gVaT2Vw-1; Wed, 13 Jul 2022 12:10:07 -0400 X-MC-Unique: rHBqAnyEMoq4wk7gVaT2Vw-1 Received: by mail-qk1-f198.google.com with SMTP id i15-20020a05620a404f00b006b55998179bso10170675qko.4 for ; Wed, 13 Jul 2022 09:10:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ALptCerQqkMffu36Xn3Y1CRPKREEsyyCZnU0VjkcIA8=; b=qWEv+JtYSBCiSs6Juzj451y3wm+27Q2V6jcZQ25XRjZ6zCGBtvDUqJ7KFvDrDaWDeg mYVkyVyqHzovmXZstaSBftd/GIoaKw30wAWWLsNJHbNQHD90vZ4CpIwKWLZNS/rMNsNK NIviPxPJ9GVnVhZI6hUAd/5t7Prn/qCm69QcljxlBHzPctf3THklJ3Lxw6YY5tK0cndM eMd43fRFWqSzw1Qa0TNhayi9m+WK4Hvg86gglR7QrQv+h8ipTM1R3bhoLjTHQsmF3Gle 6PjEqIHaR7hFvpZlrX9WhZO5qJjE20kTJm8FWb6vVn9DfF9IjKtLGAEFi0YL+UJjn8pJ n0cA== X-Gm-Message-State: AJIora9biveol+DkIm+9rpWtYLtRAKDbrymfkH65gu4m4OUzN7itcBE7 bSUO/Jfzy6vqHOpBbAgejpAOz7KkG9bPwq9ZZzQN0Ud82xC8e6bRqePs92EfeoL31SW2YvGjj0B 8et/vKnE4Gi0= X-Received: by 2002:a05:6214:c25:b0:473:2d88:f5ff with SMTP id a5-20020a0562140c2500b004732d88f5ffmr3632125qvd.101.1657728606563; Wed, 13 Jul 2022 09:10:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ul8BHSr77/iJFk9nlXeEoWmuR1sG3gYIi/uhiQ+9E69TxeU4UQI0JQyBlX4q1QqaFd6aVA6Q== X-Received: by 2002:a05:6214:c25:b0:473:2d88:f5ff with SMTP id a5-20020a0562140c2500b004732d88f5ffmr3632091qvd.101.1657728606154; Wed, 13 Jul 2022 09:10:06 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-37-74-12-30-48.dsl.bell.ca. [74.12.30.48]) by smtp.gmail.com with ESMTPSA id y17-20020a05620a25d100b006af20edff0csm12064402qko.58.2022.07.13.09.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 09:10:05 -0700 (PDT) Date: Wed, 13 Jul 2022 12:10:04 -0400 From: Peter Xu To: Mike Kravetz , Axel Rasmussen Cc: Miaohe Lin , akpm@linux-foundation.org, songmuchun@bytedance.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/hugetlb: avoid corrupting page->mapping in hugetlb_mcopy_atomic_pte Message-ID: References: <20220712130542.18836-1-linmiaohe@huawei.com> 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=1657728611; 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=ALptCerQqkMffu36Xn3Y1CRPKREEsyyCZnU0VjkcIA8=; b=SiHzOUi5sUFDJbgMYzw/gtjrQZ3Nj7IM6MV2MAu97WM0BF1tPwFM8uRb1lGycOvliMnFyU W9xcLLHqYWPX0ut76ZjLzHhnNsFA8RghOgFqEsgfnjy86BKM/T7jabF26s6hKLjeInlIH/ ZhB4Mfj/yF8nvjzlCnVlgyeda0eVu7s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657728611; a=rsa-sha256; cv=none; b=g0SyM87hodKHc5sg8hbx6RjsEe2XJbNZ2P2LzwdgfnNHgW/AD7z10LuH9jaqPv6TEqFB/V q+/BuMVySH2uDEXqYdwdTL22Jy8pmV6eIVTp3QcgUCPx9oGEX1FU426zIHSAvAmPudbkYc by1HEOqtcYu0pdAMY/TvPl91p/N9fVI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S9t5TCPl; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: f34u968fu4mj5i1ekzry8fomzjn64rs9 X-Rspamd-Queue-Id: 0C66B100051 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S9t5TCPl; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam05 X-HE-Tag: 1657728610-393349 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 Wed, Jul 13, 2022 at 10:24:09AM -0400, Peter Xu wrote: > On Tue, Jul 12, 2022 at 10:39:20AM -0700, Mike Kravetz wrote: > > On 07/12/22 21:05, Miaohe Lin wrote: > > > In MCOPY_ATOMIC_CONTINUE case with a non-shared VMA, pages in the page > > > cache are installed in the ptes. But hugepage_add_new_anon_rmap is called > > > for them mistakenly because they're not vm_shared. This will corrupt the > > > page->mapping used by page cache code. > > > > > > Fixes: f619147104c8 ("userfaultfd: add UFFDIO_CONTINUE ioctl") > > > Signed-off-by: Miaohe Lin > > > --- > > > mm/hugetlb.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > This looks correct to me. > > > > Reviewed-by: Mike Kravetz > > > > However, I am having a hard time wrapping my head around how UFFDIO_CONTINUE > > should work on non-anon private mappings. For example, a private mapping of > > a hugetlbfs file. I think we just map the page in the file/cache and do not > > set the write bit in the pte. So, yes we would want page_dup_file_rmap() > > in this case as shown below. > > > > Adding Axel and Peter on Cc: as they were more involved in adding that code > > and the design of UFFDIO_CONTINUE. > > Yes the change makes sense to me too. There's just one thing to check on > whether minor mode should support private mappings at all as it's probably > not in the major goal of when it's proposed. > > I don't see why it can't logically, but I think we should have failed the > uffdio-register already somewhere before when the vma was private and > registered with minor mode. It's just that I cannot quickly find it in the > code anywhere.. ideally it should be checked in vma_can_userfault() but it > seems not. > > Axel? > > PS: the minor mode man page update seems to be still missing. Oh I should have done a pull first on the man-page repo.. >From the man page indeed I didn't see anything mentioned on not allowing private mappings. There's the example given on using two mappings for modifying pages but logically that applies to private mappings too - we could have mapped the uffd region with private mappings but the other one shared, then we can modify page caches but later after pte installed it'll trigger cow for writes. So I think we need to confirm whether private mappings are supported. If no, we should be crystal clear in both the code and man page (we probably want a follow up patch to man-page to mention that too?). If yes, we'll need Miaohe's patch and also make sure they're enabled in the current code path. We'll also want to set test_uffdio_minor=1 for "hugetlb" test case in the userfaultfd kselftest (currently it's not there). -- Peter Xu