linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: Michal Hocko <mhocko@kernel.org>,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	mgorman@suse.de
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, selinux@tycho.nsa.gov
Subject: Re: suspicious __GFP_NOMEMALLOC in selinux
Date: Thu, 3 Aug 2017 14:17:26 -0400	[thread overview]
Message-ID: <CAHC9VhQ_TtFPQL76OEui8_rfvDJ5i6AEdPdYLSHtn1vtWEKTOA@mail.gmail.com> (raw)
In-Reply-To: <20170803110548.GK12521@dhcp22.suse.cz>

On Thu, Aug 3, 2017 at 7:05 AM, Michal Hocko <mhocko@kernel.org> wrote:
> On Thu 03-08-17 19:44:46, Tetsuo Handa wrote:
>> Michal Hocko wrote:
>> > On Thu 03-08-17 19:02:57, Tetsuo Handa wrote:
>> > > On 2017/08/03 17:11, Michal Hocko wrote:
>> > > > [CC Mel]
>> > > >
>> > > > On Wed 02-08-17 17:45:56, Paul Moore wrote:
>> > > >> On Wed, Aug 2, 2017 at 6:50 AM, Michal Hocko <mhocko@kernel.org> wrote:
>> > > >>> Hi,
>> > > >>> while doing something completely unrelated to selinux I've noticed a
>> > > >>> really strange __GFP_NOMEMALLOC usage pattern in selinux, especially
>> > > >>> GFP_ATOMIC | __GFP_NOMEMALLOC doesn't make much sense to me. GFP_ATOMIC
>> > > >>> on its own allows to access memory reserves while the later flag tells
>> > > >>> we cannot use memory reserves at all. The primary usecase for
>> > > >>> __GFP_NOMEMALLOC is to override a global PF_MEMALLOC should there be a
>> > > >>> need.
>> > > >>>
>> > > >>> It all leads to fa1aa143ac4a ("selinux: extended permissions for
>> > > >>> ioctls") which doesn't explain this aspect so let me ask. Why is the
>> > > >>> flag used at all? Moreover shouldn't GFP_ATOMIC be actually GFP_NOWAIT.
>> > > >>> What makes this path important to access memory reserves?
>> > > >>
>> > > >> [NOTE: added the SELinux list to the CC line, please include that list
>> > > >> when asking SELinux questions]
>> > > >
>> > > > Sorry about that. Will keep it in mind for next posts
>> > > >
>> > > >> The GFP_ATOMIC|__GFP_NOMEMALLOC use in SELinux appears to be limited
>> > > >> to security/selinux/avc.c, and digging a bit, I'm guessing commit
>> > > >> fa1aa143ac4a copied the combination from 6290c2c43973 ("selinux: tag
>> > > >> avc cache alloc as non-critical") and the avc_alloc_node() function.
>> > > >
>> > > > Thanks for the pointer. That makes much more sense now. Back in 2012 we
>> > > > really didn't have a good way to distinguish non sleeping and atomic
>> > > > with reserves allocations.
>> > > >
>> > > >> I can't say that I'm an expert at the vm subsystem and the variety of
>> > > >> different GFP_* flags, but your suggestion of moving to GFP_NOWAIT in
>> > > >> security/selinux/avc.c seems reasonable and in keeping with the idea
>> > > >> behind commit 6290c2c43973.
>> > > >
>> > > > What do you think about the following? I haven't tested it but it should
>> > > > be rather straightforward.
>> > >
>> > > Why not at least __GFP_NOWARN ?
>> >
>> > This would require an additional justification.
>>
>> If allocation failure is not a problem, printing allocation failure messages
>> is nothing but noisy.
>
> That alone is not a sufficient justification. An allocation warning
> might still tell you that something is not configured properly. Note
> that I am not objecting that __GFP_NOWARN is wrong it should just not be
> added blindly withtout deep understanding of the code which I do not
> have.

I understand the concern about noise from failed memory allocations,
but I tend to agree with the argument that notification of these
failures could be useful to admins/devs who are trying to diagnose
problems; let's *not* use __GFP_NOWARN in the SELinux AVC code.

>> > > And why not also __GFP_NOMEMALLOC ?
>> >
>> > What would be the purpose of __GFP_NOMEMALLOC? In other words which
>> > context would set PF_NOMEMALLOC so that the flag would override it?
>> >
>>
>> When allocating thread is selected as an OOM victim, it gets TIF_MEMDIE.
>> Since that function might be called from !in_interrupt() context, it is
>> possible that gfp_pfmemalloc_allowed() returns true due to TIF_MEMDIE and
>> the OOM victim will dip into memory reserves even when allocation failure
>> is not a problem.
>
> Yes this is possible but I do not see any major problem with that.
> I wouldn't add __GFP_NOMEMALLOC unless there is a real runaway of some
> sort that could be abused.

Adding __GFP_NOMEMALLOC would not hurt anything would it?

>> Thus, I think that majority of plain GFP_NOWAIT users want to use
>> GFP_NOWAIT | __GFP_NOWARN | __GFP_NOMEMALLOC.

-- 
paul moore
www.paul-moore.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-08-03 18:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 10:50 Michal Hocko
2017-08-02 21:45 ` Paul Moore
2017-08-03  8:11   ` Michal Hocko
2017-08-03  8:56     ` Mel Gorman
2017-08-03 10:02     ` Tetsuo Handa
2017-08-03 10:33       ` Michal Hocko
2017-08-03 10:44         ` Tetsuo Handa
2017-08-03 11:05           ` Michal Hocko
2017-08-03 18:17             ` Paul Moore [this message]
2017-08-04  7:56               ` Michal Hocko
2017-08-04 17:12                 ` Paul Moore
2017-08-07  6:58                   ` Michal Hocko
2017-08-08 13:34                     ` Paul Moore
2017-08-10  7:02                       ` Michal Hocko
2017-08-10 13:49                         ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHC9VhQ_TtFPQL76OEui8_rfvDJ5i6AEdPdYLSHtn1vtWEKTOA@mail.gmail.com \
    --to=paul@paul-moore.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox