Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4304554pxy; Tue, 27 Apr 2021 01:35:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGRWM0kI7+fJPud2Dk4NwRjLNGvkPG5PxcvHMUfhbgisssgWuBnI6pEVrj+2SUbkSmg/wL X-Received: by 2002:a17:906:953:: with SMTP id j19mr22512865ejd.56.1619512520121; Tue, 27 Apr 2021 01:35:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619512520; cv=none; d=google.com; s=arc-20160816; b=y18F2unAIq5FqX6vt+grK7p8tYvtJ5A6zDRK9OfeokdUH9CRXPqSEHVkk4ndnYQh7f bGM8IXCiYLa+Or7TYg2oNPphs6s2SeqGmFw+vJh3KXc+Z6974J0MilEgJ32Gm5Cv0N0F GwQN8fgYh9n7HWNLdzEAjySGp79Kxa4CdPNlqi5mepEkzmq7sxsggWZrqGDjNfK5Iy24 /gnPUle0kO3xDZaaL3qiHjdltxnA9wkrSPkSEOyXVoUYeKWaol5ww7qsYokcc8L0hL1a NgxlKuVTLMTv3wPMeztqXt6DT85pdMSUi554KWPvsPkB9b18Xg2OVz37+3vGmjYyj0zi T00Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=hoPNhiMsM1pUtiuXL0GShz3v/uYFYmScDq4SjTofHug=; b=jN0e6s4fs8Ka8fX90P0DU5q+lowJhZL1lnrdUdWfBNwETueSJpUVhkboodK7iXvKkh UPHLiLUALYqueMl5Qw0mV05SM4yZUCQDkRPmNbgqUhWrUtaqam/862+02qyONk24jdS8 6T/V75qNgVjj1Lxpu0g6rDBuWMcpzkYaS0nlZVhwksxJ7RmmK1gmmJRFG+gn4PTjIf+W usiAELBPW+6sM9AojVbhYRrhKVCOVfjMMBZjNJrq7n7vO2Ss1tXgToV7chD6WVYhLrDA Dw9lAIi3grvRzAUhACzltjArSfydjq0k6eG2/QawSgyQKjDUL2EG9NSo3um9Y0tI3Gwi RFTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m5si15103225ejo.329.2021.04.27.01.34.56; Tue, 27 Apr 2021 01:35:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235189AbhD0Iea (ORCPT + 99 others); Tue, 27 Apr 2021 04:34:30 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17043 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234975AbhD0Iea (ORCPT ); Tue, 27 Apr 2021 04:34:30 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FTw2701V6zPrfX; Tue, 27 Apr 2021 16:30:39 +0800 (CST) Received: from huawei.com (10.175.112.208) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Tue, 27 Apr 2021 16:33:38 +0800 From: Wang Wensheng To: , , , , CC: Subject: [PATCH] mm/sparse: Fix flags overlap in section_mem_map Date: Tue, 27 Apr 2021 08:30:19 +0000 Message-ID: <20210427083019.110184-1-wangwensheng4@huawei.com> X-Mailer: git-send-email 2.9.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.208] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The section_mem_map member of struct mem_section stores some flags and the address of struct page array of the mem_section. Additionally the node id of the mem_section is stored during early boot, where the struct page array has not been allocated. In other words, the higher bits of section_mem_map are used for two purpose, and the node id should be clear properly after the early boot. Currently the node id field is overlapped with the flag field and cannot be clear properly. That overlapped bits would then be treated as mem_section flags and may lead to unexpected side effects. Define SECTION_NID_SHIFT using order_base_2 to ensure that the node id field always locates after flags field. That's why the overlap occurs - forgetting to increase SECTION_NID_SHIFT when adding new mem_section flag. Fixes: 326e1b8f83a4 ("mm/sparsemem: introduce a SECTION_IS_EARLY flag") Signed-off-by: Wang Wensheng --- include/linux/mmzone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 47946ce..b01694d 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1325,7 +1325,7 @@ extern size_t mem_section_usage_size(void); #define SECTION_TAINT_ZONE_DEVICE (1UL<<4) #define SECTION_MAP_LAST_BIT (1UL<<5) #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) -#define SECTION_NID_SHIFT 3 +#define SECTION_NID_SHIFT order_base_2(SECTION_MAP_LAST_BIT) static inline struct page *__section_mem_map_addr(struct mem_section *section) { -- 2.9.4