Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2190507iof; Tue, 7 Jun 2022 22:40:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxquDkqUsG0vFZtJV/5U3lFfpHjr/MJd3yjoeweC9druu68/Y8S+iH4tsa3GFsIN2SWDg3e X-Received: by 2002:a63:6a43:0:b0:3fd:913e:9b02 with SMTP id f64-20020a636a43000000b003fd913e9b02mr15392950pgc.540.1654666858499; Tue, 07 Jun 2022 22:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666858; cv=none; d=google.com; s=arc-20160816; b=iTc9euyIQQZvKwN7QQIAnBDdWCLxCUjhTYMRstoUAQyj0dd4XJBS1XY7kgQbRt+gD0 HLAvLc8T41zJrfvJ4QV2ZyrBCwezV/sl3F2dLONE5pu5rvfdyaj6Bq4fkUqyH1WXX3Cn gXiDiDHpGgPaiVzgEkEDVTojcqFBE1jdNm0Gwrs6+IFz7s3icLHUnZcLoPrja78x0Bt7 AqJ4FKEYBATAbOzJomi5Bhs6bTzTO3ewU8WfcYiUFcA6L4aOdDnCjejk7VJP0DlUpf0A OPsGfvEBGXMtKFvNLztw5wTxCOoszSeVzvre+cAT2Rna8ZjHhqfN1VzNH8ORjjyUJYMh UtSw== 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=MP8d8T6GlyFypW4AGRkUCKk70Z9qfKaxiN/OF9IHajc=; b=sXl/ol3bfZPdjon64/5S+EDkfTtx0/A4YRgXE2biWe2/uCSckukVpBbkK0nbIBH6QQ f9Vlp1NuLr4lOc6jHyrngu2fR8CIJaVeRLKAtiQLoXE7MCa4+gncis3R17rw9wGWSl4h NxhuytoEL5GgPHNG4YrlLH8Xoalx/Q+pEeURGV6wEGdT9m+9j9NSYir8s8h5IYhD72YZ QjecneuLcR4onbwh1Ls6F+kWDhNV+PrPYx/F9R8GxkvcMINMU3A1OMG3E9Pi6nkqcXC+ OI4+rIlBrjxTv+5kxLwYydOP5iY2Ue98+Dw5ndqdJOf8I50RqsqnPztnK+H8tRFJeQds Rn8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zBPkegn/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n15-20020a170902d2cf00b00163656b8644si31906927plc.576.2022.06.07.22.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:40:58 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zBPkegn/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E55638FB9C; Tue, 7 Jun 2022 22:06:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350448AbiFGSGF (ORCPT + 99 others); Tue, 7 Jun 2022 14:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349095AbiFGRqp (ORCPT ); Tue, 7 Jun 2022 13:46:45 -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 3A360764A; Tue, 7 Jun 2022 10:36:45 -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 D36EE614D8; Tue, 7 Jun 2022 17:36:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6193C385A5; Tue, 7 Jun 2022 17:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623404; bh=c5+zOy+1lyAaxZtwws/4oxbj2X7+DJiWWXy825tMdNI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zBPkegn/p9JTu/0gCmtEBNv008rR3qKwiBD4WaUu7XqzIeh5FC296QsqtzQ8LDCof D+IL/dBRjRY5o3aLw0bXsVmXGKEfNrvU+V+uZDVQ4s0RN32RAzyhwJasEEEr+TQL0T QIBvQg+6p6vYtwtu/XnRiin447VQtHzQPpNrvDQM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Kravetz , Muchun Song , Andrew Morton Subject: [PATCH 5.10 404/452] hugetlb: fix huge_pmd_unshare address update Date: Tue, 7 Jun 2022 19:04:21 +0200 Message-Id: <20220607164920.599354616@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Mike Kravetz commit 48381273f8734d28ef56a5bdf1966dd8530111bc upstream. The routine huge_pmd_unshare() is passed a pointer to an address associated with an area which may be unshared. If unshare is successful this address is updated to 'optimize' callers iterating over huge page addresses. For the optimization to work correctly, address should be updated to the last huge page in the unmapped/unshared area. However, in the common case where the passed address is PUD_SIZE aligned, the address is incorrectly updated to the address of the preceding huge page. That wastes CPU cycles as the unmapped/unshared range is scanned twice. Link: https://lkml.kernel.org/r/20220524205003.126184-1-mike.kravetz@oracle.com Fixes: 39dde65c9940 ("shared page table for hugetlb page") Signed-off-by: Mike Kravetz Acked-by: Muchun Song Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5465,7 +5465,14 @@ int huge_pmd_unshare(struct mm_struct *m pud_clear(pud); put_page(virt_to_page(ptep)); mm_dec_nr_pmds(mm); - *addr = ALIGN(*addr, HPAGE_SIZE * PTRS_PER_PTE) - HPAGE_SIZE; + /* + * This update of passed address optimizes loops sequentially + * processing addresses in increments of huge page size (PMD_SIZE + * in this case). By clearing the pud, a PUD_SIZE area is unmapped. + * Update address to the 'last page' in the cleared area so that + * calling loop can move to first page past this area. + */ + *addr |= PUD_SIZE - PMD_SIZE; return 1; } #define want_pmd_share() (1)