Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp50964rwl; Wed, 4 Jan 2023 15:03:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXvaPRGX4oz9saEitxknckzmBwk37YNhPDxepuUyNnuCg9ILc2WJ6MMWhnxXAsYkxnryJ4gl X-Received: by 2002:a17:907:8b09:b0:7c0:e5c8:d439 with SMTP id sz9-20020a1709078b0900b007c0e5c8d439mr45789761ejc.3.1672873407567; Wed, 04 Jan 2023 15:03:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672873407; cv=none; d=google.com; s=arc-20160816; b=ie8wTk5CS0mQEQiA+ZpUuaCSBSwrvXka5s4jVA+4fsCBpiacVnzt1vxeOp94C34lLR aYBs6FsyJxQce0U1cJOili2mnQTBRPMat0AJD7uGZj9dpnEBJmYqH8QtBZYcTadlCMSa hATr0bLlp7i01GZK9UZgxYL9fnW5svobyvoor4bRClqFT8Dt84EiZnsfb7WCaNB9Q9LE HmkFhUBJvt0CUn2LsWgP3386P4ZCtJHx0kkUT+U6HVZ1w+3AfH7y/Kr/tUokmRASn8sc IvxYufo0zUDUSFO3fnVYoQWoGEykOHwwvkuzsL/gaV2PVhwQqyJXGMyJpTK+OkTK2X1A Y+KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iUQecF0p0KDaGb3ic+3dlRjRyqZfOtSt4XLNwuIXR0Y=; b=m+E7z9zLxa92IJL6zWh7LnuZN+D586wxPAhrU8tG+wqOCfDAlXcId31v8IOystmrnv ztNBiPwc6CIdECfG7QEqO5JazylZhf35KAS5TzLNnvE94aFWB5HgZb9pVxWfx0eE49cE lSmCA1bc9H//mwF6yX5O9L5siPiNQg4JMxQ7LHZIKjlycIjjfMzO9KvbCm9qzPoepD2z 4I+mfKi0tb/KAmf9pmPKlTjQP+MIoLBYk//AWBdtej/heO6/UTyHC2jVVPS4w+42n+36 BJGu2reNqpr0frnKuNkrIzIVWIx2RA7JHopqIfKIdYb+7o//w/ewzqgn0phyblpI6LtX jGuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eKUy64Rd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a170906945000b007269ef1872esi25852106ejx.897.2023.01.04.15.03.12; Wed, 04 Jan 2023 15:03:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eKUy64Rd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234653AbjADW41 (ORCPT + 56 others); Wed, 4 Jan 2023 17:56:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234576AbjADW4L (ORCPT ); Wed, 4 Jan 2023 17:56:11 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CFE24437D for ; Wed, 4 Jan 2023 14:55:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672872924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iUQecF0p0KDaGb3ic+3dlRjRyqZfOtSt4XLNwuIXR0Y=; b=eKUy64RdDxZuGHGRVfko63JMu8nXyYKDgA8xffbzTgoMxxK91i7THAk2ztsUgR8iQWuRY7 AMD/ucEp788aDf49h0BvU8D8XSF/maGYquUYrc7dhfv4uEhGesHBlB4TsDxKiiJuO3TKyb 3E5aVl5MGn7yBzDPKPDvrlkS3pWiNhY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-625-QnrUK-fnMuKlk5MHAX28yA-1; Wed, 04 Jan 2023 17:52:13 -0500 X-MC-Unique: QnrUK-fnMuKlk5MHAX28yA-1 Received: by mail-qv1-f69.google.com with SMTP id o95-20020a0c9068000000b005320eb4e959so471614qvo.16 for ; Wed, 04 Jan 2023 14:52:13 -0800 (PST) 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:message-id:reply-to; bh=iUQecF0p0KDaGb3ic+3dlRjRyqZfOtSt4XLNwuIXR0Y=; b=65SkchlFOIpuEPwKDD5DPfLgCYckfo+sd+ZF6TfIyGW6TBTH/pm4a5wsIS12kn57uf it9/pYGKv267DB/G0Q/820LcVk+DWsvRSittCkm3Tf5Aylk4jsTncfe5tdu9oKHHbBvl Zi96C2F8tUMmaTGglZIIzH0X44SjfBJLRAsv0fFoxJEs1xwGGnwt0VshHub3e+GQwUL/ 1T8KofVkaKSMi9UIktQgEumSb/+K65z9ii3loN3le9x7dSJfEdEt7PQRXbNz1YFJ4OBV IV0sISWZV5X/e7J5w7QNGHCmAHuPCf77dmGbPEVPz27pJJUwiso8uhNOLTP0PS52x0e2 RmQA== X-Gm-Message-State: AFqh2kr8gz9TT5gE2WiDLi3acFTEZ3dkncx9OhqsFvs3Qz1DidDYj4LI r42Y0hOV01p/ZqvPaC7k0gtyK3n9lxkN/v1FBOHi55n8qhZDiSUAQhhAVzmWNkmTo1mZDxJc9sb sQ2nWn4XSzl73OsYKqpo8FIoQ X-Received: by 2002:a0c:f3ce:0:b0:531:7b1e:cdaa with SMTP id f14-20020a0cf3ce000000b005317b1ecdaamr56474332qvm.44.1672872732866; Wed, 04 Jan 2023 14:52:12 -0800 (PST) X-Received: by 2002:a0c:f3ce:0:b0:531:7b1e:cdaa with SMTP id f14-20020a0cf3ce000000b005317b1ecdaamr56474310qvm.44.1672872732634; Wed, 04 Jan 2023 14:52:12 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-39-70-52-228-144.dsl.bell.ca. [70.52.228.144]) by smtp.gmail.com with ESMTPSA id r1-20020a05620a298100b006eeb3165565sm24654710qkp.80.2023.01.04.14.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 14:52:11 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Kravetz , Muchun Song , peterx@redhat.com, Nadav Amit , Andrea Arcangeli , David Hildenbrand , James Houghton , Axel Rasmussen , Andrew Morton , linux-stable Subject: [PATCH 1/3] mm/hugetlb: Pre-allocate pgtable pages for uffd wr-protects Date: Wed, 4 Jan 2023 17:52:05 -0500 Message-Id: <20230104225207.1066932-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230104225207.1066932-1-peterx@redhat.com> References: <20230104225207.1066932-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Userfaultfd-wp uses pte markers to mark wr-protected pages for both shmem and hugetlb. Shmem has pre-allocation ready for markers, but hugetlb path was overlooked. Doing so by calling huge_pte_alloc() if the initial pgtable walk fails to find the huge ptep. It's possible that huge_pte_alloc() can fail with high memory pressure, in that case stop the loop immediately and fail silently. This is not the most ideal solution but it matches with what we do with shmem meanwhile it avoids the splat in dmesg. Cc: linux-stable # 5.19+ Fixes: 60dfaad65aa9 ("mm/hugetlb: allow uffd wr-protect none ptes") Reported-by: James Houghton Signed-off-by: Peter Xu --- mm/hugetlb.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bf7a1f628357..017d9159cddf 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6649,8 +6649,17 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, spinlock_t *ptl; ptep = hugetlb_walk(vma, address, psize); if (!ptep) { - address |= last_addr_mask; - continue; + if (!uffd_wp) { + address |= last_addr_mask; + continue; + } + /* + * Userfaultfd wr-protect requires pgtable + * pre-allocations to install pte markers. + */ + ptep = huge_pte_alloc(mm, vma, address, psize); + if (!ptep) + break; } ptl = huge_pte_lock(h, mm, ptep); if (huge_pmd_unshare(mm, vma, address, ptep)) { -- 2.37.3