lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <878slzc1t0.fsf@ashishki-desk.ger.corp.intel.com>
Date:   Wed, 22 Jan 2020 10:50:35 +0200
From:   Alexander Shishkin <alexander.shishkin@...ux.intel.com>
To:     Song Liu <songliubraving@...com>
Cc:     linux-kernel <linux-kernel@...r.kernel.org>,
        Kernel Team <Kernel-team@...com>,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        alexander.shishkin@...ux.intel.com
Subject: Re: [PATCH] perf/core: fix mlock accounting in perf_mmap()

Song Liu <songliubraving@...com> writes:

> Actually, I think this is cleaner. 

I don't think multiple conditional blocks are cleaner, at least in this
case.

> diff --git i/kernel/events/core.c w/kernel/events/core.c
> index 2173c23c25b4..debd84fcf9cc 100644
> --- i/kernel/events/core.c
> +++ w/kernel/events/core.c
> @@ -5916,14 +5916,18 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
>          */
>         user_lock_limit *= num_online_cpus();
>
> -       user_locked = atomic_long_read(&user->locked_vm) + user_extra;
> +       user_locked = atomic_long_read(&user->locked_vm);
>
>         if (user_locked > user_lock_limit) {
> +               /* charge all to pinned_vm */
> +               extra = user_extra;
> +               user_extra = 0;
> +       } else if (user_lock + user_extra > user_lock_limit)

You probably mean "user_locked" here.

>                 /*
>                  * charge locked_vm until it hits user_lock_limit;
>                  * charge the rest from pinned_vm
>                  */
> -               extra = user_locked - user_lock_limit;
> +               extra = user_locked + user_extra - user_lock_limit;

To me, this is a bit harder to read.

>                 user_extra -= extra;
>         }
>
> Alexander, does this look good to you? 

I like to think of this as: we charge the pages to locked_vm until we
exhaust user_lock_limit, and the rest we charge to pinned_vm. Everything
else are just corner cases, and they fit into the same general case. When
we start calculating each corner case in its own block, we just multiply
the potential errors. And there have been errors in this particular path
before. So, the shorter, and the fewer the "if...else if..." statements,
the better it looks to me. Otherwise, it's a matter of preference.

Thanks,
--
Alex

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ