From patchwork Sat Oct 22 07:19:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1097026wrr; Sat, 22 Oct 2022 01:06:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YS5wr0vSJUdYS3N12q+2Zb0B6ybVIWblOOgrbFYVxmr2m9aamb6dGeWVQrvOe7SxjXHNT X-Received: by 2002:a17:90b:1a8d:b0:210:822a:3cae with SMTP id ng13-20020a17090b1a8d00b00210822a3caemr18199419pjb.243.1666425998970; Sat, 22 Oct 2022 01:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425998; cv=none; d=google.com; s=arc-20160816; b=SRfivMVZFJEbuirgcvODmSfWhoCgBZyuySejrVcKWKTwsjz/yrzm8rllcZdFgvh5pw 8yBvczlZNWFtZqfroI5A6IgFbPbUz4ipyou2QW5nx5gJ+yHLxmCtgiMTS3lLOsRzll6w BTSve2T4za3Ogtj3wPqx6ey27i3eQ40IRavnShmJdEFzi5W1b5xKqakSDwSzKeK1CkBp V5R1f4o3mpn2VFrFUzrQS+mcVdtkGjxtVo95VUvHXW5V1k18P7ik4ps9JMR5CRhNZDQJ AQ/b0JfGcnXIgwYZBzmoElxQ3KhEf1aIcPMnVfHOQh5OkDcss/IbMNHYovuEvrotLUL+ E3AA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Te+Y4lI7QUYO6h6tgWxLLog9g6dQRCS/db8GJxv9zZ4=; b=tYcY5NLASlsWC0qLT0lSe0utwMS6avfdVH9A7eE4IwgTsPNmx01yX2rGOclp56zssT +aJFW49Nt95FcBetr0dDHADKVjEF7I9iqG3CcIwF4UMbeDS9fcG3niRtGkdrvm21/KID xqL/vF6xbIBLf8hPsyKxgqQpHASXGQ3TnNMIxv58KeaEQazYWj994aLfts79XOqnPh6e b8Ppw0M9ppr8BxizUbR1iVKgqzo0ahiOMk7npEv2Nc0o3Ftg2TjGZA4dPkHwCCJfSOOh aEiP8Evqr9jehcQHpwCrKnOiZjjph07zhy9DvOnuzpxJgKEChbmWvlnG+JZ1jo3RT+A/ 6Lxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w+PhC6HF; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u191-20020a6385c8000000b0046ec3853223si3836291pgd.1.2022.10.22.01.06.24; Sat, 22 Oct 2022 01:06:38 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=w+PhC6HF; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232744AbiJVIFs (ORCPT + 99 others); Sat, 22 Oct 2022 04:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232634AbiJVH7T (ORCPT ); Sat, 22 Oct 2022 03:59:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36905B13D; Sat, 22 Oct 2022 00:49:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2895D60ADD; Sat, 22 Oct 2022 07:37:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 102DAC433D6; Sat, 22 Oct 2022 07:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424250; bh=cjJig+87pqcbv+kjMiMoyf8RM/C0BbUjoCrUc892frE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w+PhC6HFR1LUVGd8CiTwD5Na87jaOZ4d4OGgBfymoFMgJBAEWeRgDDZDP7RKctugH ZfWR7VM8HUVL5DmOYwfoThGk4+C9frion3VRaDzTGPrWWRmEECMTbXB66EejNb8DGG 1yVhAnGXv7wARXPp/aOO8slN/pyRbKyNGeOtOrBI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Xu , syzbot+2b9b4f0895be09a6dec3@syzkaller.appspotmail.com, Axel Rasmussen , Brian Geffon , Edward Liaw , Liu Shixin , Mike Kravetz , Andrew Morton Subject: [PATCH 5.19 077/717] mm/uffd: fix warning without PTE_MARKER_UFFD_WP compiled in Date: Sat, 22 Oct 2022 09:19:16 +0200 Message-Id: <20221022072428.861512299@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747374308596924823?= X-GMAIL-MSGID: =?utf-8?q?1747374308596924823?= From: Peter Xu commit 515778e2d790652a38a24554fdb7f21420d91efc upstream. When PTE_MARKER_UFFD_WP not configured, it's still possible to reach pte marker code and trigger an warning. Add a few CONFIG_PTE_MARKER_UFFD_WP ifdefs to make sure the code won't be reached when not compiled in. Link: https://lkml.kernel.org/r/YzeR+R6b4bwBlBHh@x1n Fixes: b1f9e876862d ("mm/uffd: enable write protection for shmem & hugetlbfs") Signed-off-by: Peter Xu Reported-by: Cc: Axel Rasmussen Cc: Brian Geffon Cc: Edward Liaw Cc: Liu Shixin Cc: Mike Kravetz Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 4 ++++ mm/memory.c | 2 ++ mm/mprotect.c | 2 ++ 3 files changed, 8 insertions(+) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5050,6 +5050,7 @@ static void __unmap_hugepage_range(struc * unmapped and its refcount is dropped, so just clear pte here. */ if (unlikely(!pte_present(pte))) { +#ifdef CONFIG_PTE_MARKER_UFFD_WP /* * If the pte was wr-protected by uffd-wp in any of the * swap forms, meanwhile the caller does not want to @@ -5061,6 +5062,7 @@ static void __unmap_hugepage_range(struc set_huge_pte_at(mm, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); else +#endif huge_pte_clear(mm, address, ptep, sz); spin_unlock(ptl); continue; @@ -5089,11 +5091,13 @@ static void __unmap_hugepage_range(struc tlb_remove_huge_tlb_entry(h, tlb, ptep, address); if (huge_pte_dirty(pte)) set_page_dirty(page); +#ifdef CONFIG_PTE_MARKER_UFFD_WP /* Leave a uffd-wp pte marker if needed */ if (huge_pte_uffd_wp(pte) && !(zap_flags & ZAP_FLAG_DROP_MARKER)) set_huge_pte_at(mm, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); +#endif hugetlb_count_sub(pages_per_huge_page(h), mm); page_remove_rmap(page, vma, true); --- a/mm/memory.c +++ b/mm/memory.c @@ -1385,10 +1385,12 @@ zap_install_uffd_wp_if_needed(struct vm_ unsigned long addr, pte_t *pte, struct zap_details *details, pte_t pteval) { +#ifdef CONFIG_PTE_MARKER_UFFD_WP if (zap_drop_file_uffd_wp(details)) return; pte_install_uffd_wp_if_needed(vma, addr, pte, pteval); +#endif } static unsigned long zap_pte_range(struct mmu_gather *tlb, --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -222,6 +222,7 @@ static unsigned long change_pte_range(st } else { /* It must be an none page, or what else?.. */ WARN_ON_ONCE(!pte_none(oldpte)); +#ifdef CONFIG_PTE_MARKER_UFFD_WP if (unlikely(uffd_wp && !vma_is_anonymous(vma))) { /* * For file-backed mem, we need to be able to @@ -233,6 +234,7 @@ static unsigned long change_pte_range(st make_pte_marker(PTE_MARKER_UFFD_WP)); pages++; } +#endif } } while (pte++, addr += PAGE_SIZE, addr != end); arch_leave_lazy_mmu_mode();