From patchwork Thu Jan 5 10:18:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13089668 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 9341CC3DA7D for ; Thu, 5 Jan 2023 10:19:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE9CF94001D; Thu, 5 Jan 2023 05:19:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DFC38940008; Thu, 5 Jan 2023 05:19:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC52494001D; Thu, 5 Jan 2023 05:19:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AB6BF940008 for ; Thu, 5 Jan 2023 05:19:45 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8F478120C72 for ; Thu, 5 Jan 2023 10:19:45 +0000 (UTC) X-FDA: 80320349130.07.45DCB28 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf26.hostedemail.com (Postfix) with ESMTP id 0F413140003 for ; Thu, 5 Jan 2023 10:19:43 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lJAnXXDa; spf=pass (imf26.hostedemail.com: domain of 3P6S2YwoKCIYt3ry4qr3yxqyyqvo.mywvsx47-wwu5kmu.y1q@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3P6S2YwoKCIYt3ry4qr3yxqyyqvo.mywvsx47-wwu5kmu.y1q@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672913984; a=rsa-sha256; cv=none; b=dS9rjM4waF5I4LafGefznOhIUy7H2L04fPnTsZBEABzKCBX9NcDjYl75E3scOixYe9+lgF cW6V+DbE3gmFtWhLBeQvLHgClFPaW5GB2NLQkI5d4vy9cy0hGw5MNQSS69wxAoR9lEjsKC ZYGdHZI/6rSya7SpjgodgT/eQmUcQXw= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lJAnXXDa; spf=pass (imf26.hostedemail.com: domain of 3P6S2YwoKCIYt3ry4qr3yxqyyqvo.mywvsx47-wwu5kmu.y1q@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3P6S2YwoKCIYt3ry4qr3yxqyyqvo.mywvsx47-wwu5kmu.y1q@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672913984; 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=zCmSbITJPCJiNnskiU3UeHLtqxSjqb+c0ixZX/ofLl4=; b=NKjGPohf2cWm4nij/Sv4jeK4XD3bee6tgRE+9rMIUfVP6q/dJBBYOdEN9jy2tMxZsnNaQp 2GKu2OG0z3O5UbnLUgnj2m1NsIcGLzF8eKOQ+v3rqgcvnjlxLrVs0cFeafitjEGBjI98v5 U+fzyxpFXYrAOscucHrPFt7brdky3UA= Received: by mail-yb1-f201.google.com with SMTP id b4-20020a253404000000b006fad1bb09f4so36049511yba.1 for ; Thu, 05 Jan 2023 02:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zCmSbITJPCJiNnskiU3UeHLtqxSjqb+c0ixZX/ofLl4=; b=lJAnXXDaHr20zsyaBijCW0KfmxNaRfjZpxfzb+EmrpYOQBN9AQ+W3KqrhpFEfEMu4i +7s1tvD7xS0kP2x25VUp+DunUaseeJKeyN1avNtBeuFHDsiHsskzjfBlou/AESX/+GyZ Yno3ggoNr2tSyK2HIjIkjbcpNd8owTXKEPNm9MytpSANgE4bv5+upiaLxV9VBMb4i1Xe S8lJoonIgUC5GAtZGJIrTMLDZnJTnMIHM2tRy+FWyrtFT6x4k3aGvbCYpCKZhQPF1Ozf oa94HBmejEbGCXSYJeddbV1BbDR2UK5+OlrJ4o06xbexPYzwtOlvGFmkuLgDAu3Jz91E fNDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zCmSbITJPCJiNnskiU3UeHLtqxSjqb+c0ixZX/ofLl4=; b=DyWaDZ6ZdXDmDuz48Jc0z3dlR8n0nINEaK+PX8e69mk2L4pZ2roZLIyLNCMJ0mfdXV 955MqkHuVeZJHIi0Eq6eJBFNXZLpLTumS/o4gDAE+j6nKRivgKt/760vwkt4P6nE4C/X gu1cmOQOJGDW3ndmiNXTkSKBIcCKJh4FG2Bvq1WZ3R3b47cZYyh2ru2BPk2sGPu3gKR5 QpyyrFJvBuEETfOznl6aA/TFgIrSbPstL+dy/+wbH0j6d/mB8II6OI+NZdm9hcRDV+wi KLIt0Qu2TddF7qPcZXRe8Nebr8uVE47I4zSTBn0w1HBaMUfFoAS9/wRlo1fCi77sl0wq qwOA== X-Gm-Message-State: AFqh2kqcbgX9CmsKVLl6mBMWrAmhOQL1AuqBR+h+CeLU/iz+r21MEcC/ Zq35bYQ+aOkC8bhadBqMDz7FleiZmNSyTZhi X-Google-Smtp-Source: AMrXdXvfobcg0pSW7Zq/998deX0KaxCoddWWbcyCzeLy3zOMp15r6k8px++xOzaFbco23vhIryJAmAiJaJYBCriJ X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a81:688a:0:b0:3b7:e501:90cf with SMTP id d132-20020a81688a000000b003b7e50190cfmr2167375ywc.501.1672913983311; Thu, 05 Jan 2023 02:19:43 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:32 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-35-jthoughton@google.com> Subject: [PATCH 34/46] hugetlb: userfaultfd: when using MADV_SPLIT, round addresses to PAGE_SIZE From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0F413140003 X-Stat-Signature: nuek71xkrgq76zck6ue4houz7mtymgk8 X-HE-Tag: 1672913983-40610 X-HE-Meta: U2FsdGVkX1/q9hvQdo5DlbZxEqsB8AQScfolME/PDB0ZhHKmYbotx8MGhDvoh0dqaOkxEk1fDy7TxX5MxCk+S2R8sy28AHC1aaYpe32EZN/jcQj+gPv3iKMuFAUEP+SzUcEyqUuk2wbVCmDSAZCvAwbx/8NaKFmYxUO+mDE0/q+GWgjJpQwHV1VAtBIEu2GIsDJb5KCiqUqyruzGXdFxP0Q5KBDm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/9rK2mVI9HmH+4Zwpy1jB9OfLplwadsIkpdHg0KSFkgKSkZSl9FBC0KpqEZIKAiJr9CfzUEJXohMed07qVEL4mZi7aqwVY3tDpAJIcII8YIcvrynftYqyjj4T9iULkD3aW8jE8 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: MADV_SPLIT enables HugeTLB HGM which allows for UFFDIO_CONTINUE in PAGE_SIZE chunks. If a huge-page-aligned address were to be provided, userspace would be completely unable to take advantage of HGM. That would then require userspace to know to provide UFFD_FEATURE_EXACT_ADDRESS. This patch would make it harder to make a mistake. Instead of requiring userspace to provide UFFD_FEATURE_EXACT_ADDRESS, always provide a usable address. Signed-off-by: James Houghton --- mm/hugetlb.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5af6db52f34e..5b6215e03fe1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5936,28 +5936,27 @@ static inline vm_fault_t hugetlb_handle_userfault(struct vm_area_struct *vma, unsigned long addr, unsigned long reason) { + u32 hash; + struct vm_fault vmf; + /* * Don't use the hpage-aligned address if the user has explicitly * enabled HGM. */ if (hugetlb_hgm_advised(vma) && reason == VM_UFFD_MINOR) - haddr = address & PAGE_MASK; - - u32 hash; - struct vm_fault vmf = { - .vma = vma, - .address = haddr, - .real_address = addr, - .flags = flags, + haddr = addr & PAGE_MASK; - /* - * Hard to debug if it ends up being - * used by a callee that assumes - * something about the other - * uninitialized fields... same as in - * memory.c - */ - }; + vmf.vma = vma; + vmf.address = haddr; + vmf.real_address = addr; + vmf.flags = flags; + /* + * Hard to debug if it ends up being + * used by a callee that assumes + * something about the other + * uninitialized fields... same as in + * memory.c + */ /* * vma_lock and hugetlb_fault_mutex must be dropped before handling