Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp360206ybg; Fri, 12 Jun 2020 03:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk6vPoz//cCZqTyjwKJpKg4fJjlr1bjVXWZU9PcNJWXMn52TUEeAJIDJU37GXBzrEgZl8d X-Received: by 2002:a17:906:7c56:: with SMTP id g22mr12285926ejp.507.1591958021868; Fri, 12 Jun 2020 03:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591958021; cv=none; d=google.com; s=arc-20160816; b=jYfPa96m8TC/GSIYI+mQRniU60zSiGJ6vaDxVp2LgHr6Q1q2cVoxkrqpT9iXCX/Sb2 UO2cpkTtuleDSoJqtmu2hG7HjSA4sys1oDDjmYwHxk3YCeT+Q6jLcBLBZV+xYaEYwOzb e3pqoDmz0IoXDIRLgzJYpQuEYF+weLltB6PUePRWwo/S0CM2GjVbtCednUAi+jXtQo+e kbYHQEeyEKShG19Bda4gYoF6TCHv4VXKTQu6nClryqMgsLxTTvVr0adbupetzznroyzB KHRl9ZWZv8BstRtAk5GYv19/A37mdaewb2yf46UlTc3jj5/BmXKogzsJUbzT05kp90ag MH8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=o7UN/+59jkeaPqoaczEtUQvHKsv5LwsHUt9vk7uxbjY=; b=X2Y9T3Dh6APTPJxrYqPw7uiYNEcaRfM+5XjbFhQuTvEMyFQct5JX9ZGodOsYw6Afs/ 1raNaUnEnTYlxWGlNIUSvh6WWRHYYphJo4XefJrg3/dLYku8/OIPFHnsgZZw3TqvZpHA oibwgISiwTWh9ul6MYwXSAfJFiz/WXcgrwlKbofjlS/t868wBYM45zOS0/GE/iUWVLet 94q+W0sddgi9ZwpefocUW+n+bhoMpk9jLAV0g59+CNU8P5sDy/nDlCQ9UsMRxy40qNQN 7QVpSBvfepH72siGl6MPeYNBZo1m3F4sYjHmP3cNdpKAayI4EibnlFZErKv4IbGjOOHA U7WA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id um13si3787010ejb.173.2020.06.12.03.33.19; Fri, 12 Jun 2020 03:33:41 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbgFLKa6 (ORCPT + 99 others); Fri, 12 Jun 2020 06:30:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:34372 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgFLKa5 (ORCPT ); Fri, 12 Jun 2020 06:30:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 27B6CAEFA; Fri, 12 Jun 2020 10:30:59 +0000 (UTC) Subject: Re: [PATCH] mm, page_alloc: capture page in task context only To: Hugh Dickins , Mel Gorman Cc: Andrew Morton , Li Wang , Alex Shi , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: From: Vlastimil Babka Message-ID: <01287865-153d-42e7-afd8-1178ec6bc5b9@suse.cz> Date: Fri, 12 Jun 2020 12:30:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/10/20 10:48 PM, Hugh Dickins wrote: > While stressing compaction, one run oopsed on NULL capc->cc in > __free_one_page()'s task_capc(zone): compact_zone_order() had been > interrupted, and a page was being freed in the return from interrupt. > > Though you would not expect it from the source, both gccs I was using > (a 4.8.1 and a 7.5.0) had chosen to compile compact_zone_order() with > the ".cc = &cc" implemented by mov %rbx,-0xb0(%rbp) immediately before > callq compact_zone - long after the "current->capture_control = &capc". > An interrupt in between those finds capc->cc NULL (zeroed by an earlier > rep stos). Ugh, nasty. Same here with gcc 10. > This could presumably be fixed by a barrier() before setting > current->capture_control in compact_zone_order(); but would also need > more care on return from compact_zone(), in order not to risk leaking > a page captured by interrupt just before capture_control is reset. I was hoping a WRITE_ONCE(current->capture_control) would be enough, but apparently it's not (I tried). > Maybe that is the preferable fix, but I felt safer for task_capc() to > exclude the rather surprising possibility of capture at interrupt time. > Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction") > Cc: stable@vger.kernel.org # 5.1+ > Signed-off-by: Hugh Dickins Acked-by: Vlastimil Babka But perhaps I would also make sure that we don't expose the half initialized capture_control and run into this problem again later. It's not like this is a fast path where barriers hurt. Something like this then? (with added comments) diff --git a/mm/compaction.c b/mm/compaction.c index fd988b7e5f2b..c89e26817278 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2316,15 +2316,17 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, .page = NULL, }; - current->capture_control = &capc; + barrier(); + + WRITE_ONCE(current->capture_control, &capc); ret = compact_zone(&cc, &capc); VM_BUG_ON(!list_empty(&cc.freepages)); VM_BUG_ON(!list_empty(&cc.migratepages)); - *capture = capc.page; - current->capture_control = NULL; + WRITE_ONCE(current->capture_control, NULL); + *capture = READ_ONCE(capc.page); return ret; }