From patchwork Thu Aug 3 14:32:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13340195 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 04A85EB64DD for ; Thu, 3 Aug 2023 14:32:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81340280266; Thu, 3 Aug 2023 10:32:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C32728022C; Thu, 3 Aug 2023 10:32:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 664C6280266; Thu, 3 Aug 2023 10:32:29 -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 5A8A628022C for ; Thu, 3 Aug 2023 10:32:29 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 195B3121277 for ; Thu, 3 Aug 2023 14:32:29 +0000 (UTC) X-FDA: 81083034018.01.79E9B6B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 8CAFD1C003B for ; Thu, 3 Aug 2023 14:32:19 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S6EOtQ1r; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691073140; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=5fvDz/G2oKfYF1lRg/Bv4LyzGTOydxYCnQFLIhcefpU=; b=6/W2wr5fpPmF335H3KzDbinzx9oH7qsa5E4Dzv0Y2SmgEHxdANBXdR052ej5g7NoeRP4Gi G4RboS5NYWizu6n1Ksd/6J+uA4Yhst5hoQuCW73fH8qNIEvUwVx29CypttBm50LwbiNwUM RFi1ZAxqToisnXIZfMrUAdDM/x1xZtY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S6EOtQ1r; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691073140; a=rsa-sha256; cv=none; b=iY+DKEo7McEudJkdHHGZlTLTdaRH/LHEIKNMpA5nomikiw6n842QzOVqV9AzIqx/qw8wWn nYOYmGh+NDIrFtyrMn3xTDGn8wzwL0f81hXHHBHThs4XQoSmz0CZLysuAweLcSXg4NONfA HMqoCBMCFU7sHVeU7uv/D2rsNCLpTE8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691073139; 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; bh=5fvDz/G2oKfYF1lRg/Bv4LyzGTOydxYCnQFLIhcefpU=; b=S6EOtQ1rkYdFx/rCNxWApMwoUnlWtwoXspRmtd+lIljolvoVxMV6cwLdFyNVpRyLTnCqx0 6dE+t77sa/iSOMFWi35h0QYsM+hmDLeaGBBGYn3N72ehsg6dQ30vcMIG54/XxzznAxCvfw O/VthJZfpO2olx1YMy61EmrQ0kvrkOw= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-223-I45NiEcYM16tOhTdMPGmWQ-1; Thu, 03 Aug 2023 10:32:13 -0400 X-MC-Unique: I45NiEcYM16tOhTdMPGmWQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F8FB3C025BA; Thu, 3 Aug 2023 14:32:13 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6067200B66C; Thu, 3 Aug 2023 14:32:09 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Linus Torvalds , liubo , Peter Xu , Matthew Wilcox , Hugh Dickins , Jason Gunthorpe , John Hubbard , Mel Gorman , Shuah Khan , Paolo Bonzini Subject: [PATCH v3 0/7] smaps / mm/gup: fix gup_can_follow_protnone fallout Date: Thu, 3 Aug 2023 16:32:01 +0200 Message-ID: <20230803143208.383663-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 8CAFD1C003B X-Rspam-User: X-Stat-Signature: ssyzdh9oqgqtk1phmk7mui9i6ofm5msx X-Rspamd-Server: rspam01 X-HE-Tag: 1691073139-480800 X-HE-Meta: U2FsdGVkX1/s3Si8/wCK67sAbkTAtosn1BLHM1mwEwY+BPfHA3iE6uk8yeDpm4XPsNvYBzsCshTE6tlXGL9Ew66YPRear6Bpm3tvb5s6abENlRv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l8Plb++HePsO6g6l5lJt07a/5www2j88+fbWRCaIxdzArJXoXF6ifzVWKEeLGs4/I5U/xMTGPjcsYssdt7ROL6O79lu5+fSVpHzJ1/bTdOiHfoyCMi1aGtRGDk8xxeWj+Ic++FmrVz9nVq5//56R/zAOMm0hkeb1V+sHlPsYlAoLKMuWdVTMmnLuIDFATvtWw500VgP1HxwoT786xMKfuWQIjBay0xU2GKGE+xoW3ozPgIHAB8PYwKMwP1PEK2VYWxj8nB0T/n6nK2SwqQMpbPuLOIfbQZqeceROTEmQ8U9E9hgf3zgQagqJH2aWgTsznbmRCTQg== 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: This is agains mm/mm-unstable, but everything except patch #6 and #7 should apply on current master. Especially patch #1 and #2 should go upstream first, so we can let the other stuff mature a bit longer. Handle the fallout of 474098edac26 ("mm/gup: replace FOLL_NUMA by gup_can_follow_protnone()") where I accidentially missed that follow_page() and smaps implicitly kept the FOLL_NUMA flag clear by not setting it if FOLL_FORCE is absent, to not trigger faults on PROT_NONE-mapped PTEs. Patch #1 fixes the known issues by reintroducing FOLL_NUMA as FOLL_HONOR_NUMA_FAULT and decoupling it from FOLL_FORCE. Patch #2 is a cleanup that I think actually fixes some corner cases, so I added a Fixes: tag. Patch #3 makes KVM explicitly set FOLL_HONOR_NUMA_FAULT in the single case where it is required, and documents the situation. Patch #4 then stops implicitly setting FOLL_HONOR_NUMA_FAULT. But note that for FOLL_WRITE we always implicitly honor NUMA hinting faults. Patch #5 cleans up a comments. Patch #6 improves the KVM functional tests such that patch #7 can actually check for one of the known issues: KSM no longer working on PROT_NONE mappings on x86-64 with CONFIG_NUMA_BALANCING. v2 -> V3: * "mm/gup: reintroduce FOLL_NUMA as FOLL_HONOR_NUMA_FAULT" -> Squash one comment removal -> Adjust the KSM comment * smaps: use vm_normal_page_pmd() instead of follow_trans_huge_pmd() -> Move follow_trans_huge_pmd() to mm/internal.h Cc: Andrew Morton Cc: Linus Torvalds Cc: liubo Cc: Peter Xu Cc: Matthew Wilcox Cc: Hugh Dickins Cc: Jason Gunthorpe Cc: John Hubbard Cc: Mel Gorman Cc: Shuah Khan Cc: Paolo Bonzini David Hildenbrand (7): mm/gup: reintroduce FOLL_NUMA as FOLL_HONOR_NUMA_FAULT smaps: use vm_normal_page_pmd() instead of follow_trans_huge_pmd() kvm: explicitly set FOLL_HONOR_NUMA_FAULT in hva_to_pfn_slow() mm/gup: don't implicitly set FOLL_HONOR_NUMA_FAULT pgtable: improve pte_protnone() comment selftest/mm: ksm_functional_tests: test in mmap_and_merge_range() if anything got merged selftest/mm: ksm_functional_tests: Add PROT_NONE test fs/proc/task_mmu.c | 3 +- include/linux/huge_mm.h | 3 - include/linux/mm.h | 21 +++- include/linux/mm_types.h | 9 ++ include/linux/pgtable.h | 16 ++- mm/gup.c | 23 +++- mm/huge_memory.c | 3 +- mm/internal.h | 7 ++ .../selftests/mm/ksm_functional_tests.c | 106 ++++++++++++++++-- virt/kvm/kvm_main.c | 13 ++- 10 files changed, 171 insertions(+), 33 deletions(-)