From patchwork Sat Feb 18 00:27:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 58816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp142366wrn; Fri, 17 Feb 2023 16:30:29 -0800 (PST) X-Google-Smtp-Source: AK7set+cVxa3PFmnQZ3Yzmr3jXfFxcoJXUsYFe1xrWO0NHAwaknxzLPEgJUjzLKSj2y9J859NA+D X-Received: by 2002:a17:907:7e8e:b0:885:fb8a:7c3f with SMTP id qb14-20020a1709077e8e00b00885fb8a7c3fmr3421567ejc.65.1676680229487; Fri, 17 Feb 2023 16:30:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676680229; cv=none; d=google.com; s=arc-20160816; b=HIgMan7ltOJ7IBvf/fHbKa57B1GdhcHZn7Eytrkd9JJQgW4V7RtZL4fnkF/IKPE6cs +ljDZu2r9XiSzA/HIEm89d8p0GQjkNfMvT9yuSYzCEAtSw9vWR4vNY+69xu8GMaDQJUd vdUu5C8+1HhYoKotYjcpGHOa9X13DrNnYSgTkSaqeES/L3ebzNDWHdlPmhQcalegghKf N1ciULsZcA4JKA1UEcS2kn+SLScvFRtLjMbbqECPWa46NJipOjnXPnV1T6vEN2vWJLol 7vP7Q8mftBx4KqfbAn3TXtOvhN4OTxrGM+TTyD58PKdIAZj4eYW6aA8N19dprbW9Dqe8 pEWA== 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=5Xd63Fapv1zuFib4b0fw8zL6DTisPv2GzpUTcimolMg=; b=hmDcANRjsvOmpUka6RAuM6GmkhPAU+OlFlV10iLAPAOivqU6+tbCIf0t6VxCkCahPT 0D31o4ocNmwxvzgDJTsC1Qgzt9lQ3ZbXnXHiSG6sKowNSFCSXHwUrg6vJHipKKCL5N/+ Z+g5YCxlgCdYO4cx/FNMDEd63kQFZGwSqAtilMEr6qcNOw/9AJEict4DE49GtzmJ092s be3BgRvoj8+Nu9zxY1pyq0H8wi9rQU57RgrQ+hkiQaU/JbzCozCPlEom/fd6d53DtUy5 V9sMa24is0wIT1QMglbnWMSo2khZtgxAIEy0XuTAl8f3JDlaO+WPOMUyVg7tDbhE8bE0 O4Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=G9OKNC7M; 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 mz9-20020a1709071b8900b008b158cf34a7si6698156ejc.540.2023.02.17.16.30.05; Fri, 17 Feb 2023 16:30:29 -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=G9OKNC7M; 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 S229508AbjBRA30 (ORCPT + 99 others); Fri, 17 Feb 2023 19:29:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjBRA3Q (ORCPT ); Fri, 17 Feb 2023 19:29:16 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9149A5BDB0 for ; Fri, 17 Feb 2023 16:28:54 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 64-20020a250243000000b007eba3f8e3baso2483973ybc.4 for ; Fri, 17 Feb 2023 16:28:54 -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=5Xd63Fapv1zuFib4b0fw8zL6DTisPv2GzpUTcimolMg=; b=G9OKNC7MB5QZ1WtbCVd/b4GGEEQxFMkkCyh9YPN/SaI+Iv0UY6xpXV4C/bjLuR5GX/ xT5jqUIS0kJvgcXBGXG6eGMOl41EQ+9+EPXqDEN8/E+QrPDYAERgHP5tENbu09gPxEEE J2plHmBfhFP7cLD9TJAsfNCeQfwyLgPfEiNyKU7bNFt6UToPyOfI/Tv35qpqCPqZOx+3 BkeCahUvSvDUjoiOquOpSnIGEQ48uVtj2zGVrhp8k95YXggqw2b91kgnZMkucKn+Y1SW QrvcwU7NPBdC0gLOUvUCZFlWQklPf0wCQDXXAGua2AKBXeE+nHdPEk2ToJ76Lq1odat1 0YNw== 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=5Xd63Fapv1zuFib4b0fw8zL6DTisPv2GzpUTcimolMg=; b=7Y0mktldTTNqhkx9PjBuw4/RXIRzAz0HFpcWlWOETlIMoi+/HPZv9MAiqlXzyoitcX LJBiy8pnWi6I4yyKq03SvrwibNymU1jdYjA1zjy82gLlLs2zQs41FMVj+hmZgFQU0laC 1VoZ/wHL9T99Jg1Qlnyh4/nGW6B7tLWhISLXohsy+097XllhkUIvQ1CefkzO7y5ufWGC OpPEEmkYq979LXoKrKgblCDSEdulYqnh8uROkrtPYpo8YTXl+rEKQxUWx9IxY2DSsoDu lOFxMsXanWtqzYfe3jNsv2G8ROpnAmHU1FMtwbdU42+I+smlVrv9G/eM9bAzrlfWblPJ EKPA== X-Gm-Message-State: AO0yUKXLbnQJsWPrxZtLUhRSFIY4Bjh2Gu6EGoYvJ4H8kGV653+9FyYe ItmULVBeE+0AIQRGgSda5aSyEACxgMMUeZe2 X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a81:b60f:0:b0:52a:92e9:27c1 with SMTP id u15-20020a81b60f000000b0052a92e927c1mr279953ywh.10.1676680133715; Fri, 17 Feb 2023 16:28:53 -0800 (PST) Date: Sat, 18 Feb 2023 00:27:43 +0000 In-Reply-To: <20230218002819.1486479-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230218002819.1486479-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218002819.1486479-11-jthoughton@google.com> Subject: [PATCH v2 10/46] hugetlb: make huge_pte_lockptr take an explicit shift argument From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu , Andrew Morton 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 , Frank van der Linden , Jiaqi Yan , 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?1758126648554155863?= X-GMAIL-MSGID: =?utf-8?q?1758126648554155863?= This is needed to handle PTL locking with high-granularity mapping. We won't always be using the PMD-level PTL even if we're using the 2M hugepage hstate. It's possible that we're dealing with 4K PTEs, in which case, we need to lock the PTL for the 4K PTE. Reviewed-by: Mina Almasry Acked-by: Mike Kravetz Signed-off-by: James Houghton diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index cb2dcdb18f8e..035a0df47af0 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -261,7 +261,8 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, psize = hstate_get_psize(h); #ifdef CONFIG_DEBUG_VM - assert_spin_locked(huge_pte_lockptr(h, vma->vm_mm, ptep)); + assert_spin_locked(huge_pte_lockptr(huge_page_shift(h), + vma->vm_mm, ptep)); #endif #else diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index efd2635a87f5..a1ceb9417f01 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -958,12 +958,11 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) return modified_mask; } -static inline spinlock_t *huge_pte_lockptr(struct hstate *h, +static inline spinlock_t *huge_pte_lockptr(unsigned int shift, struct mm_struct *mm, pte_t *pte) { - if (huge_page_size(h) == PMD_SIZE) + if (shift == PMD_SHIFT) return pmd_lockptr(mm, (pmd_t *) pte); - VM_BUG_ON(huge_page_size(h) == PAGE_SIZE); return &mm->page_table_lock; } @@ -1173,7 +1172,7 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) return 0; } -static inline spinlock_t *huge_pte_lockptr(struct hstate *h, +static inline spinlock_t *huge_pte_lockptr(unsigned int shift, struct mm_struct *mm, pte_t *pte) { return &mm->page_table_lock; @@ -1230,7 +1229,7 @@ static inline spinlock_t *huge_pte_lock(struct hstate *h, { spinlock_t *ptl; - ptl = huge_pte_lockptr(h, mm, pte); + ptl = huge_pte_lockptr(huge_page_shift(h), mm, pte); spin_lock(ptl); return ptl; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0576dcc98044..5ca9eae0ac42 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5017,7 +5017,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, } dst_ptl = huge_pte_lock(h, dst, dst_pte); - src_ptl = huge_pte_lockptr(h, src, src_pte); + src_ptl = huge_pte_lockptr(huge_page_shift(h), src, src_pte); spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); entry = huge_ptep_get(src_pte); again: @@ -5098,7 +5098,8 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, /* Install the new hugetlb folio if src pte stable */ dst_ptl = huge_pte_lock(h, dst, dst_pte); - src_ptl = huge_pte_lockptr(h, src, src_pte); + src_ptl = huge_pte_lockptr(huge_page_shift(h), + src, src_pte); spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); entry = huge_ptep_get(src_pte); if (!pte_same(src_pte_old, entry)) { @@ -5152,7 +5153,7 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, pte_t pte; dst_ptl = huge_pte_lock(h, mm, dst_pte); - src_ptl = huge_pte_lockptr(h, mm, src_pte); + src_ptl = huge_pte_lockptr(huge_page_shift(h), mm, src_pte); /* * We don't have to worry about the ordering of src and dst ptlocks diff --git a/mm/migrate.c b/mm/migrate.c index b0f87f19b536..9b4a7e75f6e6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -363,7 +363,8 @@ void __migration_entry_wait_huge(struct vm_area_struct *vma, void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte) { - spinlock_t *ptl = huge_pte_lockptr(hstate_vma(vma), vma->vm_mm, pte); + spinlock_t *ptl = huge_pte_lockptr(huge_page_shift(hstate_vma(vma)), + vma->vm_mm, pte); __migration_entry_wait_huge(vma, pte, ptl); }