From patchwork Tue Nov 13 05:51:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90A4513BB for ; Tue, 13 Nov 2018 05:52:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80E9B2A3B1 for ; Tue, 13 Nov 2018 05:52:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E7A52A3B9; Tue, 13 Nov 2018 05:52:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0037F2A3B1 for ; Tue, 13 Nov 2018 05:52:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 700276B0285; Tue, 13 Nov 2018 00:51:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6D7DD6B0286; Tue, 13 Nov 2018 00:51:57 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59E616B0287; Tue, 13 Nov 2018 00:51:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 139766B0285 for ; Tue, 13 Nov 2018 00:51:57 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id i19-v6so9561377pfi.21 for ; Mon, 12 Nov 2018 21:51:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=/uJLzkGdLWM/XWSM2u3mmnrZlh5dEIkBVnU3pTKL7fM=; b=gEWpn4QnjlCgFlFIHeFkPfcN2LrNfQ9iXDZ/pqVgGYTkdh8UYGZLU1v31z8/H4t38/ 7jP/qxmwaO5S/y0BRAV5sHbS7Ncphf7yOpXCz44cmG6qLPL17O3WBdtX2Tx24icL8MuZ U15VaW0vdbpXIgZmz8JqC3GNRc3+NO2dAhJHhnznuSKfSv2WLZLajNqg60uvuBkrsEko Lx3TyFQ+ucEWGlL8vkFheoDLXLuyuY2vzKF76tJjhpNeaChQQR277LEppIvgSmQxkyBG Bk1B+P67x0GHrStQ/N7VvV0X9WfbJrLH4jjkwzTCIxw93XdNwLspCA3j8WbKPQ2wexNB 13fw== X-Gm-Message-State: AGRZ1gIOkNZwrN6CRM+43Hqh752ZD8i6VMaz8QdK6jHgttbSBZR/58mO vB/Sv5nnV2fOmW7qWlM1EO5/ddyFZzgiv7GvTrezWAfiDjrniVpiW3XH5Un2qEekQOAeIEWcP6c 23oWMGfWBb6nCiNhvhRjsuEXf9e3NnHSHfiPkrW8wx7b+BkLXluFWeIYszTAS1ca/Xw== X-Received: by 2002:a62:c42:: with SMTP id u63-v6mr3828751pfi.43.1542088316767; Mon, 12 Nov 2018 21:51:56 -0800 (PST) X-Google-Smtp-Source: AJdET5fsIjasKCF4Vj67yGDgdEQl6zH8AJ+Vkj3y6l6KQ9PjJ/+FhAGc4vWbH+7drGaBhLCm+4kl X-Received: by 2002:a62:c42:: with SMTP id u63-v6mr3828719pfi.43.1542088315915; Mon, 12 Nov 2018 21:51:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088315; cv=none; d=google.com; s=arc-20160816; b=OMEVIx69UJ0c0vklO6ilq+cuCcPH69s4p6DJTwDkVk8s8ccmAb6I6CfS2wRPKKBzKQ JgnA6GsnH18OUibVTq4sVd6v0aSWAGQluPfXLf8+XjokxFu/WBt8atw/eyXMS469oNfj ln4sAl5mWslkkGwWJGvLvNyvIWEjHSvdF+mAT4cZDJCpxxsBBG9ixItnaRXQAQMe1XAO xqka7STKIvMh4j0jDJJhRQNbjA3trgRT0VUQM0TwOitpeJGJ7hrTD5b3Kir5hlyukfh/ 30xdccYeL25JX6Uh2tJU9au5tBGC6Pm9poo5q+QIXGcfZmgmMDekKBIv3BQGiF/ljG4J 2vWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/uJLzkGdLWM/XWSM2u3mmnrZlh5dEIkBVnU3pTKL7fM=; b=rCeKtP34O9Z+DQ6fuX9t0GtSr1eLgti5Z/uam6I9BMwOvu3LvLYrRaeJEUc7d/Hqqv gDDJ3IgDNB32Uf+L424a9T0thV855UQ5lwOeT6uwel2J7c7egDZmymO+0+9/h3+d2smk F0CPEpQivqeXp5JaJt1/cMQNc/VkCB0uPVyfALhVMJ7SrRCI370EYQXaTqYf+riP6pbc jgq1XFyxwEtXKriwIUMW0HRV+Zhp86BWfoJhOjV0MvTX+2q3w9XUEPkuK7yoT8Bxumir 4hLjJQO47O0X+/iqwKSJz6yzreOMLyN/fS3KpKA3n/dkEkl0FRmxVBOWPWNcJDHvy9H/ TWNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="BEz873R/"; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id p1-v6si18209903pfa.120.2018.11.12.21.51.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:51:55 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="BEz873R/"; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66F282250E; Tue, 13 Nov 2018 05:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088315; bh=qvhnOLe0Amh57SirA8Nn66irwBqaiSvMQYW06ao7ULA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BEz873R/l1uWUV6t4y/pVwd/icU39bD9HAyo7KIRzsoLNrgYJNUFjUYaO+TjOAiG9 45CkFS0ryv/gEbbbd9E7y+my1m6ifBjCw/4jjVMWmDZ0bMv4r2V5B7bXS7MBpxPsRm cR33vnPlVDn59tC5QAjOyi1hlqSSfRh68UgCAqw8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jan Kara , Ross Zwisler , Dan Williams , Dave Jiang , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 07/26] mm: Fix warning in insert_pfn() Date: Tue, 13 Nov 2018 00:51:31 -0500 Message-Id: <20181113055150.78773-7-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Jan Kara [ Upstream commit f2c57d91b0d96aa13ccff4e3b178038f17b00658 ] In DAX mode a write pagefault can race with write(2) in the following way: CPU0 CPU1 write fault for mapped zero page (hole) dax_iomap_rw() iomap_apply() xfs_file_iomap_begin() - allocates blocks dax_iomap_actor() invalidate_inode_pages2_range() - invalidates radix tree entries in given range dax_iomap_pte_fault() grab_mapping_entry() - no entry found, creates empty ... xfs_file_iomap_begin() - finds already allocated block ... vmf_insert_mixed_mkwrite() - WARNs and does nothing because there is still zero page mapped in PTE unmap_mapping_pages() This race results in WARN_ON from insert_pfn() and is occasionally triggered by fstest generic/344. Note that the race is otherwise harmless as before write(2) on CPU0 is finished, we will invalidate page tables properly and thus user of mmap will see modified data from write(2) from that point on. So just restrict the warning only to the case when the PFN in PTE is not zero page. Link: http://lkml.kernel.org/r/20180824154542.26872-1-jack@suse.cz Signed-off-by: Jan Kara Reviewed-by: Andrew Morton Cc: Ross Zwisler Cc: Dan Williams Cc: Dave Jiang Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 93d5d324904b..9c0172a4d9bf 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1804,10 +1804,15 @@ static int insert_pfn(struct vm_area_struct *vma, unsigned long addr, * in may not match the PFN we have mapped if the * mapped PFN is a writeable COW page. In the mkwrite * case we are creating a writable PTE for a shared - * mapping and we expect the PFNs to match. + * mapping and we expect the PFNs to match. If they + * don't match, we are likely racing with block + * allocation and mapping invalidation so just skip the + * update. */ - if (WARN_ON_ONCE(pte_pfn(*pte) != pfn_t_to_pfn(pfn))) + if (pte_pfn(*pte) != pfn_t_to_pfn(pfn)) { + WARN_ON_ONCE(!is_zero_pfn(pte_pfn(*pte))); goto out_unlock; + } entry = *pte; goto out_mkwrite; } else From patchwork Tue Nov 13 05:51:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47ECE13B5 for ; Tue, 13 Nov 2018 05:52:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 370D12A312 for ; Tue, 13 Nov 2018 05:52:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34CE52A3B1; Tue, 13 Nov 2018 05:52:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4231A2A312 for ; Tue, 13 Nov 2018 05:52:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99A346B0287; Tue, 13 Nov 2018 00:52:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 948396B0288; Tue, 13 Nov 2018 00:52:02 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80EC86B0289; Tue, 13 Nov 2018 00:52:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 3C4926B0287 for ; Tue, 13 Nov 2018 00:52:02 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id i19-v6so9561502pfi.21 for ; Mon, 12 Nov 2018 21:52:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=E3pLyImoxCJ6IWs3GS5iyhrqwy74dhaAy+xDqAsgCok=; b=BC3pbjddrrYs5w0lLOJ5OK8S3zqfh4rCAEJPvDRTq91nOCTmj/5pKqe5W2AfVZ0XCu yx9mvAwzU6td9HJ8XdJX+06uSLGtUDNP1f001KNlfeDlO+t7fVaFwADtcBc9HkqDB+m/ pllLy4dcgfssWCDnbB7DGvogbHkR3fFj9NyVfgOkHHa6EbQ+EXgicAmPDFPk8Urs02ig zo/MJlTLUAG97mFgCISYj0Lzj+nkJPe24rMCnqYii8n3lmQsqS6lu24il0E6vr4JXw6G +Z+xYQh8co0ln7ZwIAPx6e8i/jgwZPYnwGd5xVD2FifV+tzBNYj0N+SXO6zLjHLfU0Cb BTUg== X-Gm-Message-State: AGRZ1gJos6Kh5Nk+IH9LY4yGb6uvb/kHNahpRarwrH00YCY91skO/dnX Fk30vTLfn7FLiv/0qnGZwgW6/tSzvaNMZxu0E5xqmi1OnfaibIPcaK6dDb1G/r+wAKca6h75u3h D/d1pWcfwL+kBMnquJC2MWgchvsbpCGfwlIrK35J1t2/pIrFX6Wqis7ntOH0GlQqcug== X-Received: by 2002:a63:6506:: with SMTP id z6-v6mr3305033pgb.219.1542088321889; Mon, 12 Nov 2018 21:52:01 -0800 (PST) X-Google-Smtp-Source: AJdET5eFXRhj9iuYowztrBu5jVFHp8xsCcs6zLgQHjz9sUqU4OFR/Hsz6daNZtO1DIdjbqJdHE/B X-Received: by 2002:a63:6506:: with SMTP id z6-v6mr3305006pgb.219.1542088321127; Mon, 12 Nov 2018 21:52:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088321; cv=none; d=google.com; s=arc-20160816; b=KePsDP+g6/FsLyPmQYwDaSaRqBAJuYWwRrPd89bIq7EgFcjub0FOJWvrqjOM24mKY+ ZoCojdWGSUwBM9VcpLG0ej2idOc53p+BrR3jEekU1eudQgHwmKAeEBprcg93KG5NJY0a I6c433deU+mo77tjYJUnhA7O8zAkEjxwWf6bVb302uZjibQ/1knvq6vpiwriUqfVWRry ZG8XFyLPPnofZHzIH/t/eLNhF8aCVXgX8fC6cQUlWbEuOXXCD+gSUg+b27OHABF0afoH uWPClbFYSuQQbT1n/89u/QzTJfY6lHS4k2r5mJ9eICPERp9iWOByUTlHz6xCW8exzeND Fg5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E3pLyImoxCJ6IWs3GS5iyhrqwy74dhaAy+xDqAsgCok=; b=Fhv4E97pX66n8kL2NjG32IhHZEUldfy9SGmaGd8MGGjcQFs2TYIRfMQCsF/o69JC7X AbFa2ZpmsGQxie+YLdP1wyWphqeAWJLdF2p6tlYPPI+9wg89DBzwaTVJO3tod8S99m7g t/kK8O4fcAhLCCwGTN4WjxbY9LW3xg3ic+leHAoDOSxpP/B6GL4CXYBBOR8eWG9vfSxD YhbESuKv4K2WZjtNUgx+BS77A0L8pDYjme8kNaDcUh0xAQMR/0sfcly2J2R1h7dwJr35 SLFbhSMXIQKOI7Ivmh5oDPEy2QXfw6kW4lnPTIwTncJBrSp1mHAO2LC+pD28Gt/lmokW Cogg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OXfAn86H; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id b13-v6si21459755pfc.156.2018.11.12.21.52.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:01 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OXfAn86H; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E35C72250E; Tue, 13 Nov 2018 05:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088320; bh=G0rtieCTs+2MB/XSLV2mduzEoQTupZgtep6myjSfa0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXfAn86HBfj3VKrU0ll77idA0aAxgxTFj2E2HkaLj7LbflYd/ZtWexyTf44BfPl6h N5/J4IfN8H9di06pzacoWLOT1GCk0z0UKroT78xFGVpI90hRcdkaJpOsLrQfYp2Ybu QXJ3k0cGMokjZDunfEb73PqpgcljO2qWeamAxnGM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Boris Ostrovsky , Juergen Gross , Nathan Fontenot , John Allen , Michal Hocko , Dan Williams , Joonsoo Kim , Vlastimil Babka , Mathieu Malaterre , Pavel Tatashin , YASUAKI ISHIMATSU , Balbir Singh , Haiyang Zhang , Heiko Carstens , Jonathan Corbet , Kate Stewart , "K. Y. Srinivasan" , Martin Schwidefsky , Michael Neuling , Philippe Ombredanne , Stephen Hemminger , Thomas Gleixner , Andrew Morton , Linus Torvalds , Sasha Levin , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 08/26] mm/memory_hotplug: make add_memory() take the device_hotplug_lock Date: Tue, 13 Nov 2018 00:51:32 -0500 Message-Id: <20181113055150.78773-8-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: David Hildenbrand [ Upstream commit 8df1d0e4a265f25dc1e7e7624ccdbcb4a6630c89 ] add_memory() currently does not take the device_hotplug_lock, however is aleady called under the lock from arch/powerpc/platforms/pseries/hotplug-memory.c drivers/acpi/acpi_memhotplug.c to synchronize against CPU hot-remove and similar. In general, we should hold the device_hotplug_lock when adding memory to synchronize against online/offline request (e.g. from user space) - which already resulted in lock inversions due to device_lock() and mem_hotplug_lock - see 30467e0b3be ("mm, hotplug: fix concurrent memory hot-add deadlock"). add_memory()/add_memory_resource() will create memory block devices, so this really feels like the right thing to do. Holding the device_hotplug_lock makes sure that a memory block device can really only be accessed (e.g. via .online/.state) from user space, once the memory has been fully added to the system. The lock is not held yet in drivers/xen/balloon.c arch/powerpc/platforms/powernv/memtrace.c drivers/s390/char/sclp_cmd.c drivers/hv/hv_balloon.c So, let's either use the locked variants or take the lock. Don't export add_memory_resource(), as it once was exported to be used by XEN, which is never built as a module. If somebody requires it, we also have to export a locked variant (as device_hotplug_lock is never exported). Link: http://lkml.kernel.org/r/20180925091457.28651-3-david@redhat.com Signed-off-by: David Hildenbrand Reviewed-by: Pavel Tatashin Reviewed-by: Rafael J. Wysocki Reviewed-by: Rashmica Gupta Reviewed-by: Oscar Salvador Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: "Rafael J. Wysocki" Cc: Len Brown Cc: Greg Kroah-Hartman Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Nathan Fontenot Cc: John Allen Cc: Michal Hocko Cc: Dan Williams Cc: Joonsoo Kim Cc: Vlastimil Babka Cc: Mathieu Malaterre Cc: Pavel Tatashin Cc: YASUAKI ISHIMATSU Cc: Balbir Singh Cc: Haiyang Zhang Cc: Heiko Carstens Cc: Jonathan Corbet Cc: Kate Stewart Cc: "K. Y. Srinivasan" Cc: Martin Schwidefsky Cc: Michael Neuling Cc: Philippe Ombredanne Cc: Stephen Hemminger Cc: Thomas Gleixner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- .../platforms/pseries/hotplug-memory.c | 2 +- drivers/acpi/acpi_memhotplug.c | 2 +- drivers/base/memory.c | 9 ++++++-- drivers/xen/balloon.c | 3 +++ include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 22 ++++++++++++++++--- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 1d48ab424bd9..c197ea8dde01 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -784,7 +784,7 @@ static int dlpar_add_lmb(struct of_drconf_cell *lmb) nid = memory_add_physaddr_to_nid(lmb->base_addr); /* Add the memory */ - rc = add_memory(nid, lmb->base_addr, block_sz); + rc = __add_memory(nid, lmb->base_addr, block_sz); if (rc) { dlpar_remove_device_tree_lmb(lmb); return rc; diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 6b0d3ef7309c..2ccfbb61ca89 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c @@ -228,7 +228,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) if (node < 0) node = memory_add_physaddr_to_nid(info->start_addr); - result = add_memory(node, info->start_addr, info->length); + result = __add_memory(node, info->start_addr, info->length); /* * If the memory block has been used by the kernel, add_memory() diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 1d60b58a8c19..9a9aebb4bd19 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -517,15 +517,20 @@ memory_probe_store(struct device *dev, struct device_attribute *attr, if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) return -EINVAL; + ret = lock_device_hotplug_sysfs(); + if (ret) + goto out; + nid = memory_add_physaddr_to_nid(phys_addr); - ret = add_memory(nid, phys_addr, - MIN_MEMORY_BLOCK_SIZE * sections_per_block); + ret = __add_memory(nid, phys_addr, + MIN_MEMORY_BLOCK_SIZE * sections_per_block); if (ret) goto out; ret = count; out: + unlock_device_hotplug(); return ret; } diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 065f0b607373..6e39a0c10f93 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -401,7 +401,10 @@ static enum bp_state reserve_additional_memory(void) * callers drop the mutex before trying again. */ mutex_unlock(&balloon_mutex); + /* add_memory_resource() requires the device_hotplug lock */ + lock_device_hotplug(); rc = add_memory_resource(nid, resource, memhp_auto_online); + unlock_device_hotplug(); mutex_lock(&balloon_mutex); if (rc) { diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 58e110aee7ab..d36a02935391 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -316,6 +316,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {} extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn, void *arg, int (*func)(struct memory_block *, void *)); +extern int __add_memory(int nid, u64 start, u64 size); extern int add_memory(int nid, u64 start, u64 size); extern int add_memory_resource(int nid, struct resource *resource, bool online); extern int arch_add_memory(int nid, u64 start, u64 size, bool want_memblock); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index d4b5f29906b9..dc60f2f27389 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1109,7 +1109,12 @@ static int online_memory_block(struct memory_block *mem, void *arg) return device_online(&mem->dev); } -/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ +/* + * NOTE: The caller must call lock_device_hotplug() to serialize hotplug + * and online/offline operations (triggered e.g. by sysfs). + * + * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG + */ int __ref add_memory_resource(int nid, struct resource *res, bool online) { u64 start, size; @@ -1202,9 +1207,9 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) mem_hotplug_done(); return ret; } -EXPORT_SYMBOL_GPL(add_memory_resource); -int __ref add_memory(int nid, u64 start, u64 size) +/* requires device_hotplug_lock, see add_memory_resource() */ +int __ref __add_memory(int nid, u64 start, u64 size) { struct resource *res; int ret; @@ -1218,6 +1223,17 @@ int __ref add_memory(int nid, u64 start, u64 size) release_memory_resource(res); return ret; } + +int add_memory(int nid, u64 start, u64 size) +{ + int rc; + + lock_device_hotplug(); + rc = __add_memory(nid, start, size); + unlock_device_hotplug(); + + return rc; +} EXPORT_SYMBOL_GPL(add_memory); #ifdef CONFIG_MEMORY_HOTREMOVE From patchwork Tue Nov 13 05:51:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9302D13BB for ; Tue, 13 Nov 2018 05:52:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C252A318 for ; Tue, 13 Nov 2018 05:52:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FFC92A3A1; Tue, 13 Nov 2018 05:52:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0826D2A318 for ; Tue, 13 Nov 2018 05:52:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48F456B028B; Tue, 13 Nov 2018 00:52:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 467396B028C; Tue, 13 Nov 2018 00:52:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 357896B028D; Tue, 13 Nov 2018 00:52:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id E7E916B028B for ; Tue, 13 Nov 2018 00:52:18 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id y8so7366752pgq.12 for ; Mon, 12 Nov 2018 21:52:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=jARXeZJp5qP7dOhf6T/Pc+WoCM4YnZkLLP7pm2cSN2M=; b=bMfnYdvRaYUKld+CCIzUtaeeliSrEKm9TJuJ6eGkkj9/zz6S1Ab6st3Qk7340ckQCr ofH9KwMQJMCJ82Kuq5U9kgsn2QroWvaMnkaZsx8i6mnxVZR4CGSs3F30W2VkPpk2kUns 5a5tt02nj+vHrus67tt6dtbKNA0CyOFfkYwNz+vHinGOr0HbH/EEVSngwU6/NkVGk764 L9cOOmMOcBIwT4QQJRdVwxCFxkDoS9o67+dX7hbxbQWVp/joVAWyVEP4kcUbbwleAwah vvbdi05ctclGAt6QqPvECEXk3VriuH0rSuEolpeMR4btHRe1aHQDyIQBYI+xbjxmx7uT y0Ow== X-Gm-Message-State: AGRZ1gK26UvX3BQDBXDtezxuL1olFxXdZ5HS+JA79CvL5DIuWludCDEC VE5hnVXuBF4GiqPZ/WYvV7zp/K4lLf/iLc1yP0oSFJnTRSt5FEWdY2MaKr3B0VXNf2+nz1H3gN9 iM3rDAc65LoH6XQXle8ZTD5KmvDnNaClF0cmx6JYxF4mcioYiLhBDTEPFl9JgbiqwUg== X-Received: by 2002:a17:902:aa4b:: with SMTP id c11-v6mr3495855plr.303.1542088338630; Mon, 12 Nov 2018 21:52:18 -0800 (PST) X-Google-Smtp-Source: AJdET5f3o51d4v26eysK02xTylU5kzoWdi/n2HXaOJ6zRO+Rv/mIVyBGc8bRhHfzR88XL55W73ny X-Received: by 2002:a17:902:aa4b:: with SMTP id c11-v6mr3495840plr.303.1542088338083; Mon, 12 Nov 2018 21:52:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088338; cv=none; d=google.com; s=arc-20160816; b=dc6nBodsZhwt2HKdvtNf0i1kWzNhDb2knkjF+iTM2Wl0gGXd6Y9LNpgA3BlsD+FB/1 d33eEjFtu1xBWeYZ04daMnj2SABvqQYevGeQlzSzSMu7y12XB2cYNHVCYJsnadL1VJTi /79q+V5NgUdrNk4nzqIPxtZAH3tUPy7rk+VLcSat8s6VaUlt7nTJlBvy7V5SMnKONllU iibCRONdbi9qOJ++xac64ex4faorOjE+2rI5xKpZjO6A6R09eDgLIt7Fu/HvOD4E3z40 VbzVcTZ8SS6BBetsphebIO7OXFiw3dlfYtttAoNXe2pygBmWuRGzre3ICosruk+2ESI9 6rTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jARXeZJp5qP7dOhf6T/Pc+WoCM4YnZkLLP7pm2cSN2M=; b=QEnOZlhfYsvQdrn53pMEYqIBICKP+eSlilUTu0jjZZSxvyd3ahOKeTHGV3yQq9OJk7 D4F9ZA1D6jpoCqdoKz4Nkc2bz6r/XdbrPd6dF15kENuprsEvoV8XtDWndgWyqFM4umM4 PS0bXV2t8AjDerlSvUxMJf4T/PbpUbtBPdh3dCDiOoEjAPirTOsayBMZfQuRqrz048oL rcDabL4jEmKGI2E+KHBeQeLkk23oZwCqxLKk0Da2j8JCqxYw4DUrQZFnfaJgKnfhOxOu E8l8aVG1353Ys5wYXFpwx6gcGo307j+upwPgjXrp3Fy77vIePqtSxnxBgxNmoc6lqcn4 ky3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nXvhkx0J; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id f1-v6si17328649pgv.468.2018.11.12.21.52.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:18 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nXvhkx0J; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 86CBA2245E; Tue, 13 Nov 2018 05:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088337; bh=Epzgz9r88xp5A2BHFVWE3DXRPqA8Ihl5VjdNLUz6VmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nXvhkx0JBpHQ6gO95XyWrxChHILNGe3hZ9mhOKPZujs60Taj3Z/sznUL2m8VanSP5 cQ/CuFFCovp0biRV/AJ999RXz6rbKu1zEGcA/3JCL+wp77VsZjz/aDFUxPMC2IlJpi XGGh88UMN6W3mgU/ksXa3MdWIhGnAbock9MuPND4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jann Horn , Davidlohr Bueso , Oleg Nesterov , Christoph Lameter , Kemi Wang , Andy Lutomirski , Ingo Molnar , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 23/26] mm/vmstat.c: assert that vmstat_text is in sync with stat_items_size Date: Tue, 13 Nov 2018 00:51:47 -0500 Message-Id: <20181113055150.78773-23-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Jann Horn [ Upstream commit f0ecf25a093fc0589f0a6bc4c1ea068bbb67d220 ] Having two gigantic arrays that must manually be kept in sync, including ifdefs, isn't exactly robust. To make it easier to catch such issues in the future, add a BUILD_BUG_ON(). Link: http://lkml.kernel.org/r/20181001143138.95119-3-jannh@google.com Signed-off-by: Jann Horn Reviewed-by: Kees Cook Reviewed-by: Andrew Morton Acked-by: Roman Gushchin Acked-by: Michal Hocko Cc: Davidlohr Bueso Cc: Oleg Nesterov Cc: Christoph Lameter Cc: Kemi Wang Cc: Andy Lutomirski Cc: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/vmstat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/vmstat.c b/mm/vmstat.c index 527ae727d547..d7901f1691a8 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1630,6 +1630,8 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) stat_items_size += sizeof(struct vm_event_state); #endif + BUILD_BUG_ON(stat_items_size != + ARRAY_SIZE(vmstat_text) * sizeof(unsigned long)); v = kmalloc(stat_items_size, GFP_KERNEL); m->private = v; if (!v) From patchwork Tue Nov 13 05:51:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3B3E13BB for ; Tue, 13 Nov 2018 05:52:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E26D92A3AA for ; Tue, 13 Nov 2018 05:52:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D53692A264; Tue, 13 Nov 2018 05:52:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D43F2A3AA for ; Tue, 13 Nov 2018 05:52:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30C2F6B028C; Tue, 13 Nov 2018 00:52:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2929B6B028E; Tue, 13 Nov 2018 00:52:21 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 099A56B028F; Tue, 13 Nov 2018 00:52:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id B77916B028C for ; Tue, 13 Nov 2018 00:52:20 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id t2so698442pfj.15 for ; Mon, 12 Nov 2018 21:52:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=X238rF2zIuPmXp/Z/syy+HQIkRRwRFt5Yr4FVtMHjIQ=; b=AaiAPQ1ZCZTyeabRMwv4wD+1SlipLr6CquVoG89ez9iA28q9oVVvsDiOe+rgvUEtI1 cnD2B1kEX7h+tnOges31+uEMv4JmAq+NFZNy/jx+6i08V0HIS7Ze9ZcIqt8iDqNs37oN YD4nRS+7FhARf+tBaVnJzroRlrtwOY7enePBaMS28JIVfFD3piWLhDObshzSHBs1CkFH kyJztaoJ+UkqnmlAtGMjFFr1Ll8PNTaUQH+7wIAsB0jdwABG612avTNKLeRYh+jzFuk8 GkZPUREzVFTADN7raa5gT05uu0lDlXP4Uo+a62pP6JZyRElENabK9UIsQI2RtrhYAOce Waqw== X-Gm-Message-State: AGRZ1gKkJD8+6oqDFqtxxNhNvwdIAHGgflkoM//6nlMxZbZLBCun+jzk EqCtPQraAlglCvLwmPBXEkDATAp1PN6JVQavwMfjHa7zshUwmJpGDMLfkuCe++YhjKKXMYzs70V 7y2Ak8CDW6o4cZpz+5EdyXoj2s1mnMGuAcBOzQYG7RRE2CxnBkM/xclFOouNDxZ//fg== X-Received: by 2002:a62:4784:: with SMTP id p4-v6mr3731168pfi.257.1542088340356; Mon, 12 Nov 2018 21:52:20 -0800 (PST) X-Google-Smtp-Source: AJdET5fL4LLD/LxVRtN/VE7Ptqyz1elQfo6uTKARXWV6cNI6Q0KdiOEOJi6Lg1q/xanNFFSr1GWs X-Received: by 2002:a62:4784:: with SMTP id p4-v6mr3731146pfi.257.1542088339461; Mon, 12 Nov 2018 21:52:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088339; cv=none; d=google.com; s=arc-20160816; b=0g1ZtZatqyFwBEW9POG1uTYnJ8ubgT4fP6h4U/SxKEL1wVPX3ZpfzLeNKyNlMW7unW FOLEu1/G58jktSQ+Zo3X3qLCxtYOA9x7Gl1rxWRQZv6Lw8iE37cUmwuyVHT9K3ceAgjn 47j5RPNi5RMPjTpHmUQoB3HUjCf5dDy0ze5uMvXQtOHXjINJStdIJW8ad3JGMG6al30d GMyQsKdu+i/Y6CNGFxQMHlxhpG1jisJTIMbcU6dS9UoBxUFXr2S29dd99f4RNCmwGoGD Qtr6k5MLpsDREBPlA0oqDgE6MLH9wp2Bf+v/8AZKR5LrSFmzpv2rC4nsLUD+rhzL9bPB qKVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X238rF2zIuPmXp/Z/syy+HQIkRRwRFt5Yr4FVtMHjIQ=; b=ssi76PsoblRl39Q8VZWKjV5wFcQmJ2UuqQ1LzZc3dFuf8Im2ml5h77k4yRCQ8Mozc7 vjmdc6HEuQ+nlOagkqLWvwnvTpCQ84EXM3zqrVnL6V6F9Ku7ijFBjz31bXwdlJ1LO7IW 1KDe8zCVz2WXdpmm+1VhlvbwW72gTvTlNadrz0Lgjvn3K1QVq6WfweyiSHxz+5SbX27F LEKt+9kd/JvsJib0egLFe1n8eY0SQ/kURkqefVI/XcHuc9FogvymXDMkfdaDgWtHYU+O 6ICwBhqvsd6JF6XPzSNH416CjoGWd89VI1bw9VsghRdLbvpIGuj0CGqB1CC7j7G8cb6s qdwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cWYczi3h; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id z189-v6si20844666pfz.32.2018.11.12.21.52.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:19 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cWYczi3h; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1399B22526; Tue, 13 Nov 2018 05:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088339; bh=4BLeI+QKojb6hOzqP8825G8fRG2v3A7srOzewaBl+bI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWYczi3hs8saY+X9W0JIsZAxqvODl1+vp7Bxw2UE7SUHlcOGqTsCGBUV7cGglUQIf H0p2RyeK5bdnevsuSvXaDEMjA3ATnHdmUnrFxuCKjIqHyXR7oECK3Fqj8wFLdM0ABx iJi+douQZocQzEJ1X7KpX9kBAID0Qd3kRhkr8nK8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 24/26] userfaultfd: allow get_mempolicy(MPOL_F_NODE|MPOL_F_ADDR) to trigger userfaults Date: Tue, 13 Nov 2018 00:51:48 -0500 Message-Id: <20181113055150.78773-24-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Andrea Arcangeli [ Upstream commit 3b9aadf7278d16d7bed4d5d808501065f70898d8 ] get_mempolicy(MPOL_F_NODE|MPOL_F_ADDR) called a get_user_pages that would not be waiting for userfaults before failing and it would hit on a SIGBUS instead. Using get_user_pages_locked/unlocked instead will allow get_mempolicy to allow userfaults to resolve the fault and fill the hole, before grabbing the node id of the page. If the user calls get_mempolicy() with MPOL_F_ADDR | MPOL_F_NODE for an address inside an area managed by uffd and there is no page at that address, the page allocation from within get_mempolicy() will fail because get_user_pages() does not allow for page fault retry required for uffd; the user will get SIGBUS. With this patch, the page fault will be resolved by the uffd and the get_mempolicy() will continue normally. Background: Via code review, previously the syscall would have returned -EFAULT (vm_fault_to_errno), now it will block and wait for an userfault (if it's waken before the fault is resolved it'll still -EFAULT). This way get_mempolicy will give a chance to an "unaware" app to be compliant with userfaults. The reason this visible change is that becoming "userfault compliant" cannot regress anything: all other syscalls including read(2)/write(2) had to become "userfault compliant" long time ago (that's one of the things userfaultfd can do that PROT_NONE and trapping segfaults can't). So this is just one more syscall that become "userfault compliant" like all other major ones already were. This has been happening on virtio-bridge dpdk process which just called get_mempolicy on the guest space post live migration, but before the memory had a chance to be migrated to destination. I didn't run an strace to be able to show the -EFAULT going away, but I've the confirmation of the below debug aid information (only visible with CONFIG_DEBUG_VM=y) going away with the patch: [20116.371461] FAULT_FLAG_ALLOW_RETRY missing 0 [20116.371464] CPU: 1 PID: 13381 Comm: vhost-events Not tainted 4.17.12-200.fc28.x86_64 #1 [20116.371465] Hardware name: LENOVO 20FAS2BN0A/20FAS2BN0A, BIOS N1CET54W (1.22 ) 02/10/2017 [20116.371466] Call Trace: [20116.371473] dump_stack+0x5c/0x80 [20116.371476] handle_userfault.cold.37+0x1b/0x22 [20116.371479] ? remove_wait_queue+0x20/0x60 [20116.371481] ? poll_freewait+0x45/0xa0 [20116.371483] ? do_sys_poll+0x31c/0x520 [20116.371485] ? radix_tree_lookup_slot+0x1e/0x50 [20116.371488] shmem_getpage_gfp+0xce7/0xe50 [20116.371491] ? page_add_file_rmap+0x1a/0x2c0 [20116.371493] shmem_fault+0x78/0x1e0 [20116.371495] ? filemap_map_pages+0x3a1/0x450 [20116.371498] __do_fault+0x1f/0xc0 [20116.371500] __handle_mm_fault+0xe2e/0x12f0 [20116.371502] handle_mm_fault+0xda/0x200 [20116.371504] __get_user_pages+0x238/0x790 [20116.371506] get_user_pages+0x3e/0x50 [20116.371510] kernel_get_mempolicy+0x40b/0x700 [20116.371512] ? vfs_write+0x170/0x1a0 [20116.371515] __x64_sys_get_mempolicy+0x21/0x30 [20116.371517] do_syscall_64+0x5b/0x160 [20116.371520] entry_SYSCALL_64_after_hwframe+0x44/0xa9 The above harmless debug message (not a kernel crash, just a dump_stack()) is shown with CONFIG_DEBUG_VM=y to more quickly identify and improve kernel spots that may have to become "userfaultfd compliant" like this one (without having to run an strace and search for syscall misbehavior). Spots like the above are more closer to a kernel bug for the non-cooperative usages that Mike focuses on, than for for dpdk qemu-cooperative usages that reproduced it, but it's still nicer to get this fixed for dpdk too. The part of the patch that caused me to think is only the implementation issue of mpol_get, but it looks like it should work safe no matter the kind of mempolicy structure that is (the default static policy also starts at 1 so it'll go to 2 and back to 1 without crashing everything at 0). [rppt@linux.vnet.ibm.com: changelog addition] http://lkml.kernel.org/r/20180904073718.GA26916@rapoport-lnx Link: http://lkml.kernel.org/r/20180831214848.23676-1-aarcange@redhat.com Signed-off-by: Andrea Arcangeli Reported-by: Maxime Coquelin Tested-by: Dr. David Alan Gilbert Reviewed-by: Mike Rapoport Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/mempolicy.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index ecbda7f5d494..c19864283a8e 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -821,16 +821,19 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes) } } -static int lookup_node(unsigned long addr) +static int lookup_node(struct mm_struct *mm, unsigned long addr) { struct page *p; int err; - err = get_user_pages(addr & PAGE_MASK, 1, 0, &p, NULL); + int locked = 1; + err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked); if (err >= 0) { err = page_to_nid(p); put_page(p); } + if (locked) + up_read(&mm->mmap_sem); return err; } @@ -841,7 +844,7 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, int err; struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; - struct mempolicy *pol = current->mempolicy; + struct mempolicy *pol = current->mempolicy, *pol_refcount = NULL; if (flags & ~(unsigned long)(MPOL_F_NODE|MPOL_F_ADDR|MPOL_F_MEMS_ALLOWED)) @@ -881,7 +884,16 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, if (flags & MPOL_F_NODE) { if (flags & MPOL_F_ADDR) { - err = lookup_node(addr); + /* + * Take a refcount on the mpol, lookup_node() + * wil drop the mmap_sem, so after calling + * lookup_node() only "pol" remains valid, "vma" + * is stale. + */ + pol_refcount = pol; + vma = NULL; + mpol_get(pol); + err = lookup_node(mm, addr); if (err < 0) goto out; *policy = err; @@ -916,7 +928,9 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, out: mpol_cond_put(pol); if (vma) - up_read(¤t->mm->mmap_sem); + up_read(&mm->mmap_sem); + if (pol_refcount) + mpol_put(pol_refcount); return err; } From patchwork Tue Nov 13 05:51:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6983F13B5 for ; Tue, 13 Nov 2018 05:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A04C2A3AB for ; Tue, 13 Nov 2018 05:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EB762A34B; Tue, 13 Nov 2018 05:52:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAC972A278 for ; Tue, 13 Nov 2018 05:52:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA6076B028E; Tue, 13 Nov 2018 00:52:23 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E07886B0290; Tue, 13 Nov 2018 00:52:23 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D25AF6B0291; Tue, 13 Nov 2018 00:52:23 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 8DD526B028E for ; Tue, 13 Nov 2018 00:52:23 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id g63-v6so9569614pfc.9 for ; Mon, 12 Nov 2018 21:52:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=fcNopMamqapVYz9HdjRONdtNOXGiQC20MRPm+JqCNYY=; b=AtxmOVRizuPEJdpfqdRVNmJ6osUf8XhcQ3l6qX+3x5YD4rlu5ySsogBc5IlmiBZqgL NFU7vTHhHq2LtK7h4xqAPNhkZWyJu7bocyy0gwbTBksPslBLmJUHEUqJ6EAHdr0Epmeu QoPx8i8OKA1eMdeHXVJtguMwuupfcfubfD6Tb9EIQPxY2S65O8IsmPsdI3QWZOoOrEPo SRxfoGo3Dl+eDo/gjm44Yu4xWxS1wscfl5VxG4ZOZsHZgnJrvwaQ9LkkG54j6fEn02zE V0rIeMMx2lqYXw3cN8T7kGwrr+dFQCCH/knQSPDufd1nf5+SiqCxuG9JuJZDe25y9eny rKPw== X-Gm-Message-State: AGRZ1gLZMepr8E5hfPOVK4Awc3Tb8rFTqzv+Jq1DEpzQDy1BW77YrTC4 uFGjCcBgeP17vVFAM0qGM+fCMP5qC4/yjc1zB7mh4VIj7JVzo8DpdxV6XGyKHLoxAfcIU7LsjYw nQ3KBzJIfpp6TRT3LaGvDsQbiB/iNXv3SFfMpPLA53gb1H2oUdNWv4tBE98bPPkAAlQ== X-Received: by 2002:a63:344e:: with SMTP id b75mr3427560pga.184.1542088343256; Mon, 12 Nov 2018 21:52:23 -0800 (PST) X-Google-Smtp-Source: AJdET5f4iL/yFfONYqMuU1E1sm/FMyAPcHYQWqZg1f3QT6pyB5cQuwAqArpCj6uPYt06mGKw7Yxu X-Received: by 2002:a63:344e:: with SMTP id b75mr3427540pga.184.1542088342555; Mon, 12 Nov 2018 21:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088342; cv=none; d=google.com; s=arc-20160816; b=WpsBlub7NA9acTISfqukixl8KULDbBm5yy/UlJDET3W9TNO+FgxwI4de/8mzzwl2j9 LHszmPI8bHj727GxpJ0d4gsbH4xCsQnOMjiZjHvqmsdC3PYMEYYV63kn8eMdg2zgZ/Hb 8tuuHZRvb+SRyHT0gWCqMhu95c6OPa64klMre+zLZUZcdTIjzGwD+vM6KdvnuLsN1ARa Hjwh9BEr6hGCIBz4ZZsoZAT5Y3kwi5SRRVV5YcK2pQj8Vxdca93vf4rcj2HFD2KCRLfG HE+nCmRHyHEI1M0qVSVmBFU+t+zcmFDx8oYGW/mqxym7u8aujdaL/hkwVkXE2zrPcUQs /H2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fcNopMamqapVYz9HdjRONdtNOXGiQC20MRPm+JqCNYY=; b=TACK+weX+wrq17PdM+hBh752ByK4UeO1lnAjFPPmAMp+V1ss3OQyX5rDi+dMvKSB8b bdy50aYnowyIlzMl5zu0hqZi31d3ArPtR85K0ROBBq0kd8vvfwEirMSri3qX5nOsTPJj OPKe7zJ+0UUFBX0ArrmxYGNcruQ1j73fDUX3UErQ4KF/n9Jo57lEKmMCiJ0UXu/3ayti dl/TMKArIk8MQFLcol8pDw4cyiuSQfjgB3n4ZzNydNGjtq1S+DLuCTARKDne3IVPfUef kJukVffOEJ4vBOt3u4rEBZFhW8K+ESDx42YJqcr6wupfDjqwqMQRp5krVeKesElcK8XG L+hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ynvul6Qg; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id 185-v6si14322704pff.77.2018.11.12.21.52.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:22 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ynvul6Qg; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 192D622507; Tue, 13 Nov 2018 05:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088342; bh=9dH0lsyD10h8yVXMzJ7Xjtl0we3Me20hRIgdPeiXvpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ynvul6QgrEZCrINCz9RtbJqrtbf4rBEz0X/1qkxmW6l8IOXBjEacvF81AanMN9TK+ HrS0OzjE+VkYmg/b8ZVPFgq6FFoZ3zVOr2NWzEpbTPWlZ3sej0MwMWGpZu+3ja2/l8 UAmBcK7C0nNLz7VTVj8KyPnZKg+yW72IGiupEMRY= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Roman Gushchin , Johannes Weiner , Michal Hocko , Tejun Heo , Rik van Riel , Konstantin Khlebnikov , Matthew Wilcox , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 25/26] mm: don't miss the last page because of round-off error Date: Tue, 13 Nov 2018 00:51:49 -0500 Message-Id: <20181113055150.78773-25-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Roman Gushchin [ Upstream commit 68600f623d69da428c6163275f97ca126e1a8ec5 ] I've noticed, that dying memory cgroups are often pinned in memory by a single pagecache page. Even under moderate memory pressure they sometimes stayed in such state for a long time. That looked strange. My investigation showed that the problem is caused by applying the LRU pressure balancing math: scan = div64_u64(scan * fraction[lru], denominator), where denominator = fraction[anon] + fraction[file] + 1. Because fraction[lru] is always less than denominator, if the initial scan size is 1, the result is always 0. This means the last page is not scanned and has no chances to be reclaimed. Fix this by rounding up the result of the division. In practice this change significantly improves the speed of dying cgroups reclaim. [guro@fb.com: prevent double calculation of DIV64_U64_ROUND_UP() arguments] Link: http://lkml.kernel.org/r/20180829213311.GA13501@castle Link: http://lkml.kernel.org/r/20180827162621.30187-3-guro@fb.com Signed-off-by: Roman Gushchin Reviewed-by: Andrew Morton Cc: Johannes Weiner Cc: Michal Hocko Cc: Tejun Heo Cc: Rik van Riel Cc: Konstantin Khlebnikov Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/math64.h | 3 +++ mm/vmscan.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/math64.h b/include/linux/math64.h index 082de345b73c..3a7a14062668 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -254,4 +254,7 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor) } #endif /* mul_u64_u32_div */ +#define DIV64_U64_ROUND_UP(ll, d) \ + ({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); }) + #endif /* _LINUX_MATH64_H */ diff --git a/mm/vmscan.c b/mm/vmscan.c index be56e2e1931e..9734e62654fa 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2367,9 +2367,11 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, /* * Scan types proportional to swappiness and * their relative recent reclaim efficiency. + * Make sure we don't miss the last page + * because of a round-off error. */ - scan = div64_u64(scan * fraction[file], - denominator); + scan = DIV64_U64_ROUND_UP(scan * fraction[file], + denominator); break; case SCAN_FILE: case SCAN_ANON: From patchwork Tue Nov 13 05:51:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8F96109C for ; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D811129FAC for ; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC0492A264; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F15A29FAC for ; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B2636B029E; Tue, 13 Nov 2018 00:56:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 462A96B02A0; Tue, 13 Nov 2018 00:56:25 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 305656B02A1; Tue, 13 Nov 2018 00:56:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id DB7086B029E for ; Tue, 13 Nov 2018 00:56:24 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 94-v6so8779808pla.5 for ; Mon, 12 Nov 2018 21:56:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=QIvKUw06n8Jw1tPXgvlWbpq7rNpI7b9HD6USl64l0qQ=; b=bZp8+R9j171/TDnJiUTG+hKkLISdB7lxfgVdz/npE2JXlmLrxhPUyCbmiDO1A1iGPi jUCPyQM3AayeJ7AtlfP3lF8CfbB3vwZeFFbkRZFEUQymlnPEQfCdXIU9hKh/ISMsxLiM neZx/UB3SuY7XYdvKQ7dZeyKzet8vQqvk4Ij4izUkRwSuTjlojDcahSrlYq54wPQc93C XsfPGns6ecEFR2GnJr4U0rrl6xw528z6j7Rf78wPNPCEZgc/J3NpQydE6eYo7vg8RX/a UfP+MjuaGSG++Wbv4BtvWP7XJDO7/YbDOjxrMZvvfgiZZAZvcaDyY0jywxkgXwJIDnE5 coQQ== X-Gm-Message-State: AGRZ1gIyjouKClLQ/+XNw7zq2Rqa5x4beNjS5mXvFW8Tnau6aDv3c8aV YewAhkbY8wjtT3CaL3GlGUFYP8bAL+x70hz3CPYEq+b0shVhyGZJTK/n9/kWyH8tPRThTV7TFGP lbekfBfdIOjTrgAGf9+siMYwx1qhHR4KZ4+ES5eVBDbYUnPkFsVpUV5UcZK2HbdkQSUtyoONOhU H1aU/gVVohHUWPl3xQ+n7H9YfXj4eWxOCiPgMnXAMVWLDrHlEalOJGR8T1MOv5LzgPaijVQ/GXj 83+QQvdZqLWgJjPlC23axaeB419aqvEquQUaGxCVdMdMDI140UjihxCMYWmAZjng0vQ8yWjxg7s Cd1hN0uPh+R67uK4OTJxUvbVBXCxcE7UKUKIOLNiPq1Ro3vCmPAEVe7OCpA1T7RABEPC+Dj0I3v l X-Received: by 2002:a17:902:1123:: with SMTP id d32-v6mr3746309pla.62.1542088344305; Mon, 12 Nov 2018 21:52:24 -0800 (PST) X-Received: by 2002:a17:902:1123:: with SMTP id d32-v6mr3746300pla.62.1542088344151; Mon, 12 Nov 2018 21:52:24 -0800 (PST) X-Google-Smtp-Source: AJdET5dkpvT32pUNjz7CmD7vcrasdjUzGttav/jqKX4eAr/wJG8AmLPD5TtmyXQpNDb73qpdb3zI X-Received: by 2002:a17:902:1123:: with SMTP id d32-v6mr3746257pla.62.1542088342925; Mon, 12 Nov 2018 21:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088342; cv=none; d=google.com; s=arc-20160816; b=E95lMnh8fkib2iLdj3iCr/JXZXlofKz7nVBPMA51pOEr9GRYC2V28NR+dPJEloNwDe hKtzqyBEzNfVqqCk5sUI+9cfz/0hgknkaCgCdZNuPUFtRig5LZ/h+b4aJimgdDUHCkIc A94XQgCSDC+XQ2axbiHl5WLRYGQ79L54lXL7wfkXYfOdzEdc0FdQdJaESGI4lfU9uMfL 8P50FcVfqOtfptT44nZs44FYNU+z0dOU5mF7fgpChEhu+TKa3DOTBskKjgJYNtPSnDt6 QEMSiynmmujpAZ20Juc2W7HITANnrMSwNnfBWGd50JPoxCENV4QbgYycloP3oO5bjyqn nacw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QIvKUw06n8Jw1tPXgvlWbpq7rNpI7b9HD6USl64l0qQ=; b=vn8TIiihpMjtblRsxAudGQdCTIlpN+Lk25e+1b1CjAoWfTotpbCtwZ7AacTky5PTm4 xuiY9+c72kQL8yXb+vPHDw6OQVD2BWSgoJwixw9W5ODyJAqtPTB/fOW5ECKZjkrFiRIm AUo+aCOZ3dDprI1QzcC2h7dErdG17XSGm0YpAk47T6JD7/n4YX0vZjpz6GwLLtqtHcw3 7IyEw1SQqantPwZm0yLNxXjiUfM4Ys6t7oU6wMD4NCkajjaDgxQNbMvR1n48OZ38/0N9 3XJUgJcqzBDFbr2A/cXX7O+q7PB3DEZtbAaN/AucUbjbPzzIY6Uh9NvEj0Z/8OgbJwId zw5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XDsfCc2Z; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id e68-v6si21220794plb.172.2018.11.12.21.52.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:22 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XDsfCc2Z; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 790552251D; Tue, 13 Nov 2018 05:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088342; bh=g4oRi6iD6jYnZXzqC9XJfHAoZ363ncG3WwRFG+WbXic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XDsfCc2ZNmxw7TtGqMCssYA0xyyGlF3io9ukb5dYHvkl2W1v/KTNRuyTUUg5Km6hI WuDKeMjwXnQVZZ9oHcaG/wD85scaq9ktUdogQzilGUvLzvkZQ8iHrsmUsLYzVQwAuf 69mUtuLEig7x+tY3BK08RLSpYJTFNJb+U7SxFxig= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 26/26] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:51:50 -0500 Message-Id: <20181113055150.78773-26-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Vyukov [ Upstream commit 61448479a9f2c954cde0cfe778cb6bec5d0a748d ] Slub does not call kmalloc_slab() for sizes > KMALLOC_MAX_CACHE_SIZE, instead it falls back to kmalloc_large(). For slab KMALLOC_MAX_CACHE_SIZE == KMALLOC_MAX_SIZE and it calls kmalloc_slab() for all allocations relying on NULL return value for over-sized allocations. This inconsistency leads to unwanted warnings from kmalloc_slab() for over-sized allocations for slab. Returning NULL for failed allocations is the expected behavior. Make slub and slab code consistent by checking size > KMALLOC_MAX_CACHE_SIZE in slab before calling kmalloc_slab(). While we are here also fix the check in kmalloc_slab(). We should check against KMALLOC_MAX_CACHE_SIZE rather than KMALLOC_MAX_SIZE. It all kinda worked because for slab the constants are the same, and slub always checks the size against KMALLOC_MAX_CACHE_SIZE before kmalloc_slab(). But if we get there with size > KMALLOC_MAX_CACHE_SIZE anyhow bad things will happen. For example, in case of a newly introduced bug in slub code. Also move the check in kmalloc_slab() from function entry to the size > 192 case. This partially compensates for the additional check in slab code and makes slub code a bit faster (at least theoretically). Also drop __GFP_NOWARN in the warning check. This warning means a bug in slab code itself, user-passed flags have nothing to do with it. Nothing of this affects slob. Link: http://lkml.kernel.org/r/20180927171502.226522-1-dvyukov@gmail.com Signed-off-by: Dmitry Vyukov Reported-by: syzbot+87829a10073277282ad1@syzkaller.appspotmail.com Reported-by: syzbot+ef4e8fc3a06e9019bb40@syzkaller.appspotmail.com Reported-by: syzbot+6e438f4036df52cbb863@syzkaller.appspotmail.com Reported-by: syzbot+8574471d8734457d98aa@syzkaller.appspotmail.com Reported-by: syzbot+af1504df0807a083dbd9@syzkaller.appspotmail.com Acked-by: Christoph Lameter Acked-by: Vlastimil Babka Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/slab.c | 4 ++++ mm/slab_common.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 198c1e2c5358..68ab88e2920e 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3670,6 +3670,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) struct kmem_cache *cachep; void *ret; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; @@ -3705,6 +3707,8 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, struct kmem_cache *cachep; void *ret; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; diff --git a/mm/slab_common.c b/mm/slab_common.c index 91d271b90600..f6764cf162b8 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -971,18 +971,18 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) { int index; - if (unlikely(size > KMALLOC_MAX_SIZE)) { - WARN_ON_ONCE(!(flags & __GFP_NOWARN)); - return NULL; - } - if (size <= 192) { if (!size) return ZERO_SIZE_PTR; index = size_index[size_index_elem(size)]; - } else + } else { + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) { + WARN_ON(1); + return NULL; + } index = fls(size - 1); + } #ifdef CONFIG_ZONE_DMA if (unlikely((flags & GFP_DMA)))