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: 39458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp228151wrt; Thu, 5 Jan 2023 02:23:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvyTcTmL23lisD7p5Osg11lXWCo9bBmVOXmGUXWbUbH/ZXcf1CO0DV2b1ABreyP286cmouz X-Received: by 2002:a05:6a20:43aa:b0:af:7336:f468 with SMTP id i42-20020a056a2043aa00b000af7336f468mr65969070pzl.20.1672914230748; Thu, 05 Jan 2023 02:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672914230; cv=none; d=google.com; s=arc-20160816; b=1ID+jOu5kGXwDxIuCw72fE4ppZZ7as399NsOadVUg46YYkwKNuHqLb51NkKAwIkUOu 9aEgbXDKLLRY7jywF4bFvqGjfUBEynTbRDCilGWpC0GuxZKsKDgR61+zTPdb2YKReb31 PKWY9XkEApBxLx4RbCKz1Q6AuZV9QiPZI0lNo0zHJ3UJc3HmprJPndGcLYvL9QuLODFL mYesVSffvbxZ1bxgHo8kLxbVanY3sCaRQEgRWLtoi2n0F36TuwQDI9fEYoqX18mZYeKl qJXg62XKd8SagnrsJct8wVBW1dbwiJc+oVp5A0YRPyl722BNAvUh5+qZW7f6M+72+VR9 FeAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=zCmSbITJPCJiNnskiU3UeHLtqxSjqb+c0ixZX/ofLl4=; b=XdpSO+xsSLfoXNuGtnjhGmFjLEns1falHvSyf29HI27cuvhM9N0c9mJlezcU42UlSB ppzLfvm/QMXq7ffQiRwsJ140Tgxdii4vBt8RHm4R2br5d+408Lsui17xijAQtrrPZYsr zc71ogq9zxdX3XgkMW6+7/xjjzXb9Sp4ZUfiWPtO3DWYI+UaJS/tUl4j6cKH4DVpB0jJ Nm+dAiuZiM4nzyPstY4+EMQqk1sPfM4xQzwTIecQKsBokQAWg1of1PEbElbua5OMDT4A PJWUd01xAmy1Z+CbgfF7mP/zLQVHG9LIYGBH9guWED0ygY0G25smsJ1WxZCXc08zaO2l 8Xgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lJAnXXDa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a656b85000000b00439fb921f8fsi37050023pgw.460.2023.01.05.02.23.38; Thu, 05 Jan 2023 02:23:50 -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=@google.com header.s=20210112 header.b=lJAnXXDa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232996AbjAEKWs (ORCPT + 99 others); Thu, 5 Jan 2023 05:22:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232921AbjAEKVJ (ORCPT ); Thu, 5 Jan 2023 05:21:09 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16BDC5831B for ; Thu, 5 Jan 2023 02:19:44 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id z17-20020a25e311000000b00719e04e59e1so36650445ybd.10 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=YeW62+CoHH4lNTYNWYaLBcy4Xl8oVz/2dW+ROprR6V6PoeVZ29IDaRoVLZ0CNJjkDn PGGzljPay8NqxToUdiHEeCrIi0DeLn/xhb/N6K2FSB+ZljkFKEOmAKuw81SqAyOHp3nm Iw7qPiRrsDc8fSx8gquXAhov5p3KCHOUTaBJf39ouOYxLw5aoJirz+Lfln+i+jx1r49E QMAvEwFOJL0UsgVjlgObTLGBG4ztGFhRfBOAuOk41s7Uou12m89wLf7OxVUPbycLxfhi ooRzUWtPtgdcii+4QfGIaNpiknTkahM/0sj7nsiafTvOAoTnr5QoW++v4kYhEjgu2qE+ irag== X-Gm-Message-State: AFqh2kqceEh9qYmGoYMyI5SHzLk2LL63ZEz7YDCjmLTaO6yNtSb2+4Bc Vk9T5CgafEi1CAA/D2QPyUaVNkTzgXNCxk/+ 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1754177712082686641?= X-GMAIL-MSGID: =?utf-8?q?1754177712082686641?= 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