From patchwork Thu Apr 28 13:24:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 8971171 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A69F9BF29F for ; Thu, 28 Apr 2016 14:12:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C9E59202AE for ; Thu, 28 Apr 2016 14:12:48 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D90A7200E1 for ; Thu, 28 Apr 2016 14:12:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3SE8qWf014073; Thu, 28 Apr 2016 10:08:52 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3SDOSTQ007241 for ; Thu, 28 Apr 2016 09:24:28 -0400 Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3SDOSwh028219 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 28 Apr 2016 09:24:28 -0400 Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C84181123; Thu, 28 Apr 2016 13:24:27 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id e201so76638057wme.0; Thu, 28 Apr 2016 06:24:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fsvST+Wql6wC3GUMmCeHl8qh9tNfvELCX4xxD/OudoM=; b=Je41frLItH3Ub6ld20Y4+E8I/QUvuSOCxvEmBbtLjI1MCmZz/VnoreGKLxGVsPDm36 koLty0ORT5LjGs4WbFe++v93/lpIyYyL/R1/HKJLO5ebKnXftAh+S7b4Ua7ZUT8CRqAP XS47ZWStEueHTVECq2KkpaWCXfCTKHDMC0xgGn/7gmzeZ4VBlsZqT/gBKea4dQNuD7kY muFBHvsbAneS8xsHRoeAM5lrQXB5CISNX6DHesZgbJ4VQVZn4zzgywbiG2jM/o2H4FyO kQks4ShZ79PDnIvkE5q6q11YtrIhRh6gdPzT6FIk/oPYVRhubFSG9VBCczISLER1EkwE 7s3g== X-Gm-Message-State: AOPr4FVbWqhdB4ZCTkdvH/7f/YXXWPzGZc6tvdy9siP3yEEI3PLmPibaoUAKdofC/pJuaA== X-Received: by 10.28.156.195 with SMTP id f186mr16153592wme.74.1461849865942; Thu, 28 Apr 2016 06:24:25 -0700 (PDT) Received: from tiehlicka.suse.cz (nat1.scz.suse.com. [213.151.88.250]) by smtp.gmail.com with ESMTPSA id m6sm9697699wje.21.2016.04.28.06.24.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 06:24:25 -0700 (PDT) From: Michal Hocko To: Andrew Morton Date: Thu, 28 Apr 2016 15:24:04 +0200 Message-Id: <1461849846-27209-19-git-send-email-mhocko@kernel.org> In-Reply-To: <1461849846-27209-1-git-send-email-mhocko@kernel.org> References: <1461849846-27209-1-git-send-email-mhocko@kernel.org> X-RedHat-Spam-Score: -0.12 (BAYES_50, DCC_REPUT_00_12, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.48 mail-wm0-f48.google.com 74.125.82.48 mail-wm0-f48.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.76 on 10.5.110.27 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Thu, 28 Apr 2016 10:08:22 -0400 Cc: Michal Hocko , LKML , linux-mm@kvack.org, dm-devel@redhat.com, Mikulas Patocka , Shaohua Li Subject: [dm-devel] [PATCH 18/20] dm: clean up GFP_NIO usage X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko copy_params uses GFP_NOIO for explicit allocation requests because this might be called from the suspend path. To quote Mikulas: : The LVM tool calls suspend and resume ioctls on device mapper block : devices. : : When a device is suspended, any bio sent to the device is held. If the : resume ioctl did GFP_KERNEL allocation, the allocation could get stuck : trying to write some dirty cached pages to the suspended device. : : The LVM tool and the dmeventd daemon use mlock to lock its address space, : so the copy_from_user/copy_to_user call cannot trigger a page fault. Relying on the mlock is quite fragile and we have a better way in kernel to enfore NOIO which is already used for the vmalloc fallback. Just use memalloc_noio_{save,restore} around the whole copy_params function which will force the same also to the page fult paths via copy_{from,to}_user. While we are there we can also remove __GFP_NOMEMALLOC because copy_params is never called from MEMALLOC context (e.g. during the reclaim). Cc: Shaohua Li Cc: Mikulas Patocka Cc: dm-devel@redhat.com Signed-off-by: Michal Hocko --- drivers/md/dm-ioctl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 2c7ca258c4e4..fe0b57d7573c 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1715,16 +1715,13 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern */ dmi = NULL; if (param_kernel->data_size <= KMALLOC_MAX_SIZE) { - dmi = kmalloc(param_kernel->data_size, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); + dmi = kmalloc(param_kernel->data_size, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); if (dmi) *param_flags |= DM_PARAMS_KMALLOC; } if (!dmi) { - unsigned noio_flag; - noio_flag = memalloc_noio_save(); - dmi = __vmalloc(param_kernel->data_size, GFP_NOIO | __GFP_HIGH | __GFP_HIGHMEM, PAGE_KERNEL); - memalloc_noio_restore(noio_flag); + dmi = __vmalloc(param_kernel->data_size, GFP_KERNEL | __GFP_HIGH | __GFP_HIGHMEM, PAGE_KERNEL); if (dmi) *param_flags |= DM_PARAMS_VMALLOC; } @@ -1801,6 +1798,7 @@ static int ctl_ioctl(uint command, struct dm_ioctl __user *user) ioctl_fn fn = NULL; size_t input_param_size; struct dm_ioctl param_kernel; + unsigned noio_flag; /* only root can play with this */ if (!capable(CAP_SYS_ADMIN)) @@ -1832,9 +1830,12 @@ static int ctl_ioctl(uint command, struct dm_ioctl __user *user) } /* - * Copy the parameters into kernel space. + * Copy the parameters into kernel space. Make sure that no IO is triggered + * from the allocation paths because this might be called during the suspend. */ + noio_flag = memalloc_noio_save(); r = copy_params(user, ¶m_kernel, ioctl_flags, ¶m, ¶m_flags); + memalloc_noio_restore(noio_flag); if (r) return r;