From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D27C4C83F11 for ; Mon, 28 Aug 2023 15:21:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2822C8E0027; Mon, 28 Aug 2023 11:21:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 230D78E001A; Mon, 28 Aug 2023 11:21:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 120218E0027; Mon, 28 Aug 2023 11:21:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 01EF38E001A for ; Mon, 28 Aug 2023 11:21:26 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C11911C950E for ; Mon, 28 Aug 2023 15:21:26 +0000 (UTC) X-FDA: 81173877372.23.9BF5E52 Received: from out-242.mta0.migadu.com (out-242.mta0.migadu.com [91.218.175.242]) by imf15.hostedemail.com (Postfix) with ESMTP id CABDCA0008 for ; Mon, 28 Aug 2023 15:21:24 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=U3iDCIMz; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 91.218.175.242 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693236085; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lAXqRb7f3TkLKfxHc6WqM603wFyJETSjvqftd5xFDu8=; b=Y8GItLzr6e+aIrblTkW1LSIrJyzgUZE/bFjx3RsRzzT8yH3oecU3uvZER0v/148AyHJnKY Syjq96fSe8sPWSLUHdI2yGHKRuNHt3oiozsXSQBVgJe7lLAgNi2LzKK3mOzz5CQmDjCsna H6wwY1Q8IwbtrGkEsLeTUp8SSNK0O8k= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=U3iDCIMz; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 91.218.175.242 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693236085; a=rsa-sha256; cv=none; b=PhlNiCx0slt5Qx0Z1y9U/2kayfJf4r5BpN8rHF6RPIfaTEekEIlCPK4WaxTSLlhbsvDDrn bzwaw0MCPC8TWcQgj4d5Mp3VJBL1eoXN1kK2enjHQ3Xhas4WVt0D8dFlF8NPaR+hS9Rr53 8jgymEi9mv+cqSnc6rKVYZaLoaLHmis= Date: Tue, 29 Aug 2023 00:21:13 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693236082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lAXqRb7f3TkLKfxHc6WqM603wFyJETSjvqftd5xFDu8=; b=U3iDCIMzNv/u2zstS1bYaiv1hU43uCxMGdgZcvAyRvAIZUV5zbKaT7TwpUse7q9NGPgWk9 pSBdcdma2iTsVz3KhuPFqRQNmtb7eOv8B7ku/+6o+VyA0So+lsJEdo0Z68iEb5RaU/ShMU Xd5Ln5mKPYDHlvqYOLys31RrQyijDEQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Naoya Horiguchi To: Kemeng Shi Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, willy@infradead.org, naoya.horiguchi@nec.com, osalvador@suse.de Subject: Re: [PATCH v2 1/3] mm/page_alloc: correct start page when guard page debug is enabled Message-ID: <20230828152113.GA886794@ik1-406-35019.vs.sakura.ne.jp> References: <20230826154745.4019371-1-shikemeng@huaweicloud.com> <20230826154745.4019371-2-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230826154745.4019371-2-shikemeng@huaweicloud.com> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: 465z9ixwqntiff3aq3wuc65gkp164hap X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CABDCA0008 X-HE-Tag: 1693236084-254283 X-HE-Meta: U2FsdGVkX1+e1jhCSqpp8f59We+B7+uHkJsItT6NrLTI0rocgZ9XxDB8OhT0B1VWs5T8YiSV92aYNPVFDkby0D51d3XLhwOfP6g5D/czGavZLplREACUQemcJdJbf/I+j/cU60eEFbqeiGu8XjUhVRo5lyNCdNZimBN9nuqvQXAUI0w5l/qat2KdIWhip8FcEG8FuFEEC0fIgB73wnNpnQAGHOg4yWqIW2TNuCoAsWwpfTrwJQbNWAsyT4HDI2BNzoMSe8nowQS2UzEUPchPOqOY4gJfW5IxUwl8EVb196PFv/nAxmbOaujSWJ5xAIz7qSeUwD5zJ1CjgJDfK6oxJg9/dnkemnSqnU5b7D4QVivxe9tMXsf3MdRNZlkUxEdpXkjpv/Y7L3OvzywgAJ2ySSRNKvuw9i/AZSwXTKrHeDjy8rTESht99ct3Srj23fUbf2DdK9BqK+GurnAESIfmnDGi4PqhfZbdqfd58T7hj6ySzVOL5/lLSS8rAyG8TzTuDRPL3rjZ5fT9qIJULAX+une3N9Yv3Xo4TMNVhatnISBTSrYtSduyXVnJvqADK0E4FDk5rxZwwJX3S+ea2Ny67S8dQOm/srDyFrxBJLxFqH9ziWcPfRPXiJ2ZQenJBinTSpyyfU+Kjxgj8CQPE9SxU/G5YQXo2aWAS/nYlZL36QEgEbtzuHUWNNOESPUuX1cInSRnIGLnG0qHhPxRGvWgHAtS90Rs7VO6mryNwg+f2lIHNoovs+LmAk+5a6asFfbnYVef+g86UXfttuVAfqeCaoHQs1gUFgDXzSuuXFwIDlECb/Gsm8OBCG+atrd1YA4kqD/J55hYMXU+WtzCOYk6D+lLoS3e3fXFEcaTmzHbEDkfsPbpwd4gqINkTpzrabK226GLCyidVClHJMw34LlKNoMCQq6MWmApsbaFUtmCXZ/dFL3BSiAKOKThU7YeGkaU4+nc/+a3W80FftncNvm D+d9Iilc 9DybvdG/wT6uRtm6I2/l4E15jdaDMgJlFMBAzuAyVUM/mbeuxkxHLjdVcpy+C3TvezRftqVtHH/+4P33sqF86M1iem3cFq8mM3+lqcFGUfBsXBsU0qFgY7MJwEaWmY4hRSKDAuqSIYsEVo18Fjfk57c0pKVZPMaa+2OQ5 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: On Sat, Aug 26, 2023 at 11:47:43PM +0800, Kemeng Shi wrote: > When guard page debug is enabled and set_page_guard returns success, we > miss to forward page to point to start of next split range and we will do > split unexpectedly in page range without target page. Move start page > update before set_page_guard to fix this. > > As we split to wrong target page, then splited pages are not able to merge > back to original order when target page is put back and splited pages > except target page is not usable. To be specific: > > Consider target page is the third page in buddy page with order 2. > | buddy-2 | Page | Target | Page | > > After break down to target page, we will only set first page to Guard > because of bug. > | Guard | Page | Target | Page | > > When we try put_page_back_buddy with target page, the buddy page of target > if neither guard nor buddy, Then it's not able to construct original page > with order 2 > | Guard | Page | buddy-0 | Page | > > All pages except target page is not in free list and is not usable. > > Fixes: 06be6ff3d2ec ("mm,hwpoison: rework soft offline for free pages") > Signed-off-by: Kemeng Shi Thank you for finding the problem and writing patches. I think the patch fixes the reported problem, But I wonder that we really need guard page mechanism in break_down_buddy_pages() which is only called from memory_failure. As stated in Documentation/admin-guide/kernel-parameters.txt, this is a debugging feature to detect memory corruption due to buggy kernel or drivers code. So if HW memory failrue seems to be out of the scope, and I feel that we could simply remove it from break_down_buddy_pages(). debug_guardpage_minorder= [KNL] When CONFIG_DEBUG_PAGEALLOC is set, this parameter allows control of the order of pages that will be intentionally kept free (and hence protected) by the buddy allocator. Bigger value increase the probability of catching random memory corruption, but reduce the amount of memory for normal system use. The maximum possible value is MAX_ORDER/2. Setting this parameter to 1 or 2 should be enough to identify most random memory corruption problems caused by bugs in kernel or driver code when a CPU writes to (or reads from) a random memory location. Note that there exists a class of memory corruptions problems caused by buggy H/W or F/W or by drivers badly programming DMA (basically when memory is written at bus level and the CPU MMU is bypassed) which are not detectable by CONFIG_DEBUG_PAGEALLOC, hence this option will not help tracking down these problems. If you have any idea about how guard page mechanism helps memory_failrue, could you share it? Thanks, Naoya Horiguchi > --- > mm/page_alloc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index fefc4074d9d0..88c5f5aea9b0 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -6505,6 +6505,7 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page, > next_page = page; > current_buddy = page + size; > } > + page = next_page; > > if (set_page_guard(zone, current_buddy, high, migratetype)) > continue; > @@ -6512,7 +6513,6 @@ static void break_down_buddy_pages(struct zone *zone, struct page *page, > if (current_buddy != target) { > add_to_free_list(current_buddy, zone, high, migratetype); > set_buddy_order(current_buddy, high); > - page = next_page; > } > } > } > -- > 2.30.0 > > >