From patchwork Wed Feb 17 18:49:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12092051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A5E0C433E0 for ; Wed, 17 Feb 2021 18:49:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 72E3A64E4A for ; Wed, 17 Feb 2021 18:49:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72E3A64E4A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A70766B0006; Wed, 17 Feb 2021 13:49:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A21A36B006C; Wed, 17 Feb 2021 13:49:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E8BC8D0001; Wed, 17 Feb 2021 13:49:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 74F2C6B0006 for ; Wed, 17 Feb 2021 13:49:44 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2FB2E52CE for ; Wed, 17 Feb 2021 18:49:44 +0000 (UTC) X-FDA: 77828648688.20.89C0A56 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf27.hostedemail.com (Postfix) with ESMTP id 4155580192D8 for ; Wed, 17 Feb 2021 18:49:39 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11HIhrQ1041668; Wed, 17 Feb 2021 18:49:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=YrbqfKqMpmcE3gvWEAtP5ZU15hRGe56Dl1Rq+gBAZBo=; b=WPtIIOG23auuVFBpRs7TTK3mCNAHYpEjSnbax9pj+vZu2l74/tbAwnCB49kv3MD6k8pd 97XVsqDL2q2w76DxEEhqA6kCSTOUhiHemHaYEbbbTMCgGzmnSZpOdR1NQZRmo6H0SP0k GknrHn8M8VsMAEQ7wF5/x49iF9e7O16/Ycb28A3TVE8Auq+x4k8sWW42lhJMV646jNMg 7+BomDRk+1e4yj8eEgw/toWOQBipAdbxNVktGP7qBySwOVAon0H/BStZiQLNF2zqq9TN t/Oy0YraCU5OCBqk/zw/D+VyX5UB7fMSfqf5ZCdww7IKw4E3Wo4fJzPEepg+vhC0cHCj uw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 36pd9aay6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Feb 2021 18:49:40 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11HIk7sb061146; Wed, 17 Feb 2021 18:49:39 GMT Received: from nam04-sn1-obe.outbound.protection.outlook.com (mail-sn1nam04lp2057.outbound.protection.outlook.com [104.47.44.57]) by userp3030.oracle.com with ESMTP id 36prpyg5x9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Feb 2021 18:49:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MXD5Me5iZDgJ7eZPrZvB8EpIpLbCBKrmDUUh3N+RYFW09YfzbLHMXk8psx/i74G01vvZ0XGzZTz+lnKHIR/MY7DFCtUO40zw4cFZtwPZZkzrG/tV7SqUXwLYnxuihMMv7RQlIsac4WtBN9buFFjxpCnbRBlFRGERa5ktqdV8eA3ONJMeD5xIXan5LA9DmzqOCMnxpOpZsAdXJ0Ac2cAU35Ll3YeuerUam5Xl4bKqLnEi2D9OPWVQe7FuBY0n1//OVoLn9pnZFdYmnPgfvAfbcyCGblvZIvf90H9JssBDw2Xm8NiP1eBu0e8tLNTpbOPMeDl4XGbIJNC1pkS5iSigOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YrbqfKqMpmcE3gvWEAtP5ZU15hRGe56Dl1Rq+gBAZBo=; b=D3C4DQTAvZ5091uk9k6dZiDuGJ7vAqbH5HzWVau2S5PFKwEhodGT6xhufp6s/DrFh4qClb/8SyhKTati5PoBky/1ObtqDykTpOZF9IrDqLz/o/wVr/2lhGhI7Gu/vIrFXMQ/Ng/rOyESuHGaOrM+hjJyV2jmrYB9RORa5jYXC3ef9nuy76K0Ov92AfNcitPqHlesnFRrdE1cX+JkIRhnc3EoGEMT4/fKbi5amGbXwXMkiuveLdz/LwZrGTsj30WaiZAHiVIdVFbeP66w7Zd/2Ns9w1lELFrPtArj3nr6W/Oa+QIIisWSJP4amEX0osCkauPdmqAmMzT4Hf+N0jTXNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YrbqfKqMpmcE3gvWEAtP5ZU15hRGe56Dl1Rq+gBAZBo=; b=ao5gQMqyKRm+rUrgjGHfs+9kqbP5+Z/+UFoqsf+Ee+CczV2QWEsXVyQYeHQTaJXPqm/7tr/tXsofn+ajtEQiU1+UZxGdgbzqWplHyR/cz8U4D/CF9ZKfzouvmXnFb0A8B9feLNjnwc8YNlFxiIufm5pX7YXNUlUjqyjJB4GNmtY= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BYAPR10MB3589.namprd10.prod.outlook.com (2603:10b6:a03:129::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.30; Wed, 17 Feb 2021 18:49:37 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::e035:c568:ac66:da00]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::e035:c568:ac66:da00%4]) with mapi id 15.20.3846.041; Wed, 17 Feb 2021 18:49:37 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Zi Yan , Davidlohr Bueso , "Kirill A . Shutemov" , Andrea Arcangeli , Matthew Wilcox , Oscar Salvador , Joao Martins , Andrew Morton , Mike Kravetz , stable@vger.kernel.org Subject: [PATCH 1/2] hugetlb: fix update_and_free_page contig page struct assumption Date: Wed, 17 Feb 2021 10:49:25 -0800 Message-Id: <20210217184926.33567-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.29.2 X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MW2PR16CA0050.namprd16.prod.outlook.com (2603:10b6:907:1::27) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from monkey.oracle.com (50.38.35.18) by MW2PR16CA0050.namprd16.prod.outlook.com (2603:10b6:907:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Wed, 17 Feb 2021 18:49:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 08a07dc0-f47f-4370-149d-08d8d374c65b X-MS-TrafficTypeDiagnostic: BYAPR10MB3589: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XqIiUK9AiB4tRhs3QNOjIP122WlBy5VzRZEqPaVIkBqhsVKcBR395j05TQDzF6VWBqus1UHCJm2+PBS7FwLKVOINqQ49ylEvRZuO+nQ/evTDnreGQu3xJX1KhGvzJaubI49e0GXAtUYlfyxymo3IkO7O2o2xkKLc/zRfaGjSY2/LdPlSq/NgDyPGXQoD517Vcr5tFCUQKtxQ2So+AXTLExchd0g1+mwvJVGmD5nY7WnQ4sLLDdAGspDqeHH8YTYqOIaojvSYP1iLKgma6EfVxFVVaDfe6Z6iCs0Zn8/lprAkY1QtMtWAV991lZ1JB9ehkh1urYpfvVzo0e3B7ih1depkxmjKCyLIfM0Cx971gHwfxy/dRxEaO/j5uLUZWzUjygj2gQiVOENgSeEYH78qVpHBp7v/i5vbZrLVXq7LpaVV89vfnJfvDG+0Jq/HbbXOxn2+b7dPsjt0EyjvQSNHihiOZLXV3wquN7O/Pa4xJXlNoA7PQeHinQaJ9qi2NZ8O6MRll2+IP/eCi+QvBgbyBh10jQcnqcRORm9NpqXeDm53EmmWWYFWmn+Q5LjslowC+d6IBy4qJB7sTKXj5TGB/1q5hq3XvMi0dfAgciHGptg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(366004)(136003)(39860400002)(396003)(376002)(1076003)(4326008)(83380400001)(36756003)(6486002)(186003)(6666004)(2906002)(26005)(316002)(5660300002)(966005)(2616005)(54906003)(16526019)(7416002)(66946007)(15650500001)(66556008)(478600001)(52116002)(7696005)(8936002)(956004)(8676002)(44832011)(86362001)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?vLYGkvZ4wNte/eqz2Rr9BTO5wzcPr5?= =?utf-8?q?Nj5R5LFpyKTR6CqJ6le4323zHrm1OJWgAWvWgVJ0YbC3lAn8QKrvTadbcPKv/X2K2?= =?utf-8?q?L5m9PVKdxgwXq251aOmslpE0PV1tRy7SKVg+ePptTSS/3ZjiqQlMBMmE5FJQ2aQYU?= =?utf-8?q?jLHzLnaBJFr863PmBGKZyCoy5+I7+RHQXx/nAcjPq+3l8S2fSlnNT6/nXxY7P3wev?= =?utf-8?q?sMj2HhYLjcKgj0cdMSgHn0EdGCtMXRnzOLsqVKvc/qgAVGwndS+U7z0YimzWWwyqQ?= =?utf-8?q?yFabRMk/cp4pOkppW5MV9euCNULeHN2MSRDo8QQjIru3m5U7OZbCgay09o52NK0Dp?= =?utf-8?q?J3wkTHVU3+iikwtowegzrAzU+56BPlM1o+QTh00zdgnteO8u8iZawSHaLuAyiaNwh?= =?utf-8?q?V25P1fFawfTYPrl4n77KI6oJJ3Tdw3Tm/u7xh8MMeb5uIs8qRsvLRd/4696eT9Eut?= =?utf-8?q?iMoGdmGBe0L4gicuDrgsrLX6Vlsw4srF1W9nI+LbZpLpxJCudRZvCKCSbGOxp1sWE?= =?utf-8?q?LCMiDhKUDMzSRLSDj9WCHdN4Pb7BHQIQ9WOLAoC+DXYFwrmRCsiGy98XhibRKIdtN?= =?utf-8?q?LGIuMJcD+MP5yG5QPvRoDVwRR8mvIaUxWp/ZRVjZudZjfhhmqY9g6Zui2GdB755fv?= =?utf-8?q?5KmWHCAPwgoaR7yILnl6Z+t1aUjRywCe1wKCFc3RreL0O+rq447v7D8PcVPVeBJ0U?= =?utf-8?q?6rOFocQkVo4wez7POtYci1tTsEopk/FgeAdnzjVIboQdmQTPQG5E7DyhxDEODMWQD?= =?utf-8?q?t5wGMF0uwZgfc6xBWiK6Yof08BXBomci9NDIm2289rnsf12+Ugx9rNOmWX8uj9f0L?= =?utf-8?q?hLQM5gIuubiQOFFhqk104h8Of4usjDHXeJkM4vzOM837SJWvNI8ZZ2SGvL0Dy2Shh?= =?utf-8?q?sjUgRyT5qdhznb3QfSLvo0JGann4E3/HUw/aireEI0Jl2iioAynO4C7m4ZyRFoObt?= =?utf-8?q?6MOKNzfFlqtHCQOxZ0gUQHwu0TTlpmExq11uGapeIGDcFyjJLwYeXXHJpiNKTTfNn?= =?utf-8?q?oj8/AbvPh9LGuKQ/C0qw/0Beyi6wD50xHq1DR+5ghW6mStY66rcPU7aix8S8CD2I9?= =?utf-8?q?gIA8w+WPDlmLIxvKk5EGbHsWRtcH9goIE/VW9j6y3cbiZfdnBSqIKnjI5IANd0ngZ?= =?utf-8?q?/MY2H/oRIsj93ALj4bmeFP23+bj2V7Nj6C5Gz3faOmv24DLW73/FLZWoJHHPzp/ne?= =?utf-8?q?07z08eaTFBb9GQpjk/vqtEEplUXtwbJv8SKac8KNHqxhqNQzyPH+IdUqXfsAhCYGl?= =?utf-8?q?ZZUy7FCxIpznOj?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08a07dc0-f47f-4370-149d-08d8d374c65b X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2021 18:49:37.3277 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lrp7fCGvrEBvXH0d162YCN58kGFcC1ODWOX9iyCiumsEX/R+t24tLqDYdCQkMVJE67gRMk6SbzQ1qspLY2Y24w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3589 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9898 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 phishscore=0 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102170135 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9898 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1011 impostorscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102170135 X-Stat-Signature: xm5xe6i7m466xqsuwqfao3azh7zbxypa X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4155580192D8 Received-SPF: none (oracle.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=aserp2120.oracle.com; client-ip=141.146.126.78 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613587779-374740 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: page structs are not guaranteed to be contiguous for gigantic pages. The routine update_and_free_page can encounter a gigantic page, yet it assumes page structs are contiguous when setting page flags in subpages. If update_and_free_page encounters non-contiguous page structs, we can see “BUG: Bad page state in process …” errors. Non-contiguous page structs are generally not an issue. However, they can exist with a specific kernel configuration and hotplug operations. For example: Configure the kernel with CONFIG_SPARSEMEM and !CONFIG_SPARSEMEM_VMEMMAP. Then, hotplug add memory for the area where the gigantic page will be allocated. Zi Yan outlined steps to reproduce here [1]. [1] https://lore.kernel.org/linux-mm/16F7C58B-4D79-41C5-9B64-A1A1628F4AF2@nvidia.com/ Fixes: 944d9fec8d7a ("hugetlb: add support for gigantic page allocation at runtime") Signed-off-by: Zi Yan Signed-off-by: Mike Kravetz Cc: Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4bdb58ab14cb..94e9fa803294 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1312,14 +1312,16 @@ static inline void destroy_compound_gigantic_page(struct page *page, static void update_and_free_page(struct hstate *h, struct page *page) { int i; + struct page *subpage = page; if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; h->nr_huge_pages--; h->nr_huge_pages_node[page_to_nid(page)]--; - for (i = 0; i < pages_per_huge_page(h); i++) { - page[i].flags &= ~(1 << PG_locked | 1 << PG_error | + for (i = 0; i < pages_per_huge_page(h); + i++, subpage = mem_map_next(subpage, page, i)) { + subpage->flags &= ~(1 << PG_locked | 1 << PG_error | 1 << PG_referenced | 1 << PG_dirty | 1 << PG_active | 1 << PG_private | 1 << PG_writeback);