Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp688272ybe; Wed, 11 Sep 2019 03:10:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/OdpZrEDvMuWSoERgwg4oqOhEqY2zgQ73aQoLIYMRfEhy5ERaLN5qi/U32MY2gTmVA6H1 X-Received: by 2002:a50:da02:: with SMTP id z2mr35347775edj.254.1568196659728; Wed, 11 Sep 2019 03:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568196659; cv=none; d=google.com; s=arc-20160816; b=LdKEc2viDErHtV8hVWkJ4htbYGYAa2HKJlNIXPk1CxRebmkzT93QK28B0FXnbv5kpB eRYAVXbKsFbyEYrFdJZ90Q8+WCIHboT6LGud/HtdHDz62erllNvfewJLTWXZhxxBOJYK E/XkrOyCTfNTvyhL2VadDpj+IudNOiQGOWY9lowjssdYNfDi6ZPgVkX3w+KTo0bRozzj Wy95T1K/6WZLtyjV+pz+2L7KV2iIKe881TPkq0wcdlDOVo9//D26Y5E1wW8caj8/o0aV MCi566mMvK9GBUYOvcY90BJAfEOeblB3KEnTds3r2Tp8f3Ifxhu4il/4Atm7IYIFCTRl rUeg== 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=LF/FqMTPkvjg7yiq8CiFdPUOVLthYphsISQWUeR1Vkc=; b=eG2+MrmCFha3E1t9XDSpli7/7eNtWIB2vLNHiGfqIgV7tvtw7PJxW78AbdSd/6w0RP Okbum/KQVhJQozM/WHvS/C9OAEDn3gIherintPkKACNuikQiVNyiuwatlFKdypZJJPnR BdUhqZXBJAxKvFjAT288biajfUsQhHsAbjzmNlQg7GQcOAPAYk6jrqie6vsbWnX3mXQQ KFa58PKg8069tU/cw89pVLg8++cc82HPv95TqEzvNw16CWuOkiFKXk3oXkZx7R/leat7 PDjSIlO7X1lmRBI7ZTeCXLjEgA+R1E6Fmcytz6+WOVax6aNzKmcx2aSxvF4fk7ilV3lk TbdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id um3si11070148ejb.391.2019.09.11.03.10.35; Wed, 11 Sep 2019 03:10:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727663AbfIKKID (ORCPT + 99 others); Wed, 11 Sep 2019 06:08:03 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:64208 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbfIKKIC (ORCPT ); Wed, 11 Sep 2019 06:08:02 -0400 Received: from fsav302.sakura.ne.jp (fsav302.sakura.ne.jp [153.120.85.133]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x8BA7cIq048562; Wed, 11 Sep 2019 19:07:38 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav302.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav302.sakura.ne.jp); Wed, 11 Sep 2019 19:07:38 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav302.sakura.ne.jp) Received: from [192.168.1.8] (softbank126227201116.bbtec.net [126.227.201.116]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x8BA7YlU048512 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NO); Wed, 11 Sep 2019 19:07:38 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Subject: Re: [RFC PATCH] Add proc interface to set PF_MEMALLOC flags To: Hillf Danton , Mike Christie Cc: "Kirill A. Shutemov" , axboe@kernel.dk, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Linux-MM References: <20190911031348.9648-1-hdanton@sina.com> From: Tetsuo Handa Message-ID: Date: Wed, 11 Sep 2019 19:07:34 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20190911031348.9648-1-hdanton@sina.com> 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 2019/09/11 12:13, Hillf Danton wrote: > > On Tue, 10 Sep 2019 11:06:03 -0500 From: Mike Christie >> >>> Really? Without any privilege check? So any random user can tap into >>> __GFP_NOIO allocations? >> >> That was a mistake on my part. I will add it in. >> > You may alternatively madvise a nutcracker as long as you would have > added a sledgehammer under /proc instead of a gavel. > > --- a/include/uapi/asm-generic/mman-common.h > +++ b/include/uapi/asm-generic/mman-common.h > @@ -45,6 +45,7 @@ > #define MADV_SEQUENTIAL 2 /* expect sequential page references */ > #define MADV_WILLNEED 3 /* will need these pages */ > #define MADV_DONTNEED 4 /* don't need these pages */ > +#define MADV_NOIO 5 /* set PF_MEMALLOC_NOIO */ > > /* common parameters: try to keep these consistent across architectures */ > #define MADV_FREE 8 /* free pages only if memory pressure */ > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -716,6 +716,7 @@ madvise_behavior_valid(int behavior) > case MADV_WILLNEED: > case MADV_DONTNEED: > case MADV_FREE: > + case MADV_NOIO: > #ifdef CONFIG_KSM > case MADV_MERGEABLE: > case MADV_UNMERGEABLE: > @@ -813,6 +814,11 @@ SYSCALL_DEFINE3(madvise, unsigned long, > if (!madvise_behavior_valid(behavior)) > return error; > > + if (behavior == MADV_NOIO) { > + current->flags |= PF_MEMALLOC_NOIO; Yes, for "modifying p->flags when p != current" is not permitted. But I guess that there is a problem. Setting PF_MEMALLOC_NOIO causes current_gfp_context() to mask __GFP_IO | __GFP_FS, but the OOM killer cannot be invoked when __GFP_FS is masked. As a result, any userspace thread which has PF_MEMALLOC_NOIO cannot invoke the OOM killer. If the userspace thread which uses PF_MEMALLOC_NOIO is involved in memory reclaiming activities, the memory reclaiming activities won't be able to make forward progress when the userspace thread triggered e.g. a page fault. Can the "userspace components that can run in the IO path" survive without any memory allocation? > + return 0; > + } > + > if (start & ~PAGE_MASK) > return error; > len = (len_in + ~PAGE_MASK) & PAGE_MASK;