public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: Tony Luck <tony.luck@intel.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	Chen Gong <gong.chen@linux.intel.com>,
	"Huang, Ying" <ying.huang@intel.com>,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Subject: Re: [PATCH] x86/mce: Need to let kill_proc() send signal to doomed process
Date: Tue, 10 Jul 2012 20:36:26 +0200	[thread overview]
Message-ID: <20120710183626.GA4419@aftab.osrc.amd.com> (raw)
In-Reply-To: <CA+8MBbKU5AB5zpYQB6pHegA2V1=8q123fxyFERsHjWCLK5iCsw@mail.gmail.com>

On Tue, Jul 10, 2012 at 10:12:17AM -0700, Tony Luck wrote:
> On Tue, Jul 10, 2012 at 8:44 AM, Borislav Petkov <bp@amd64.org> wrote:
> > Acked-by: Borislav Petkov <borislav.petkov@amd.com>
> 
> Thanks for the Ack.
> 
> +       doit = !!PageDirty(ppage) || !!(flags & MF_MUST_KILL);
> 
> Thinking about this some more, the "!!" are redundant
> and are an impediment to readability. We started with
> !!PageDirty(ppage) when we were passing an argument
> directly to kill_procs() and wanted to make sure we had a
> nice boolean value. But the result of the "||" is boolean,
> so we don't need to double negate.
> 
> I'm going to change it to:
>        doit = PageDirty(ppage) || (flags & MF_MUST_KILL);

Ok, so out of curiosity I took a look at compiler output and both
versions are identical:


> +       doit = !!PageDirty(ppage) || !!(flags & MF_MUST_KILL);

	.loc 1 974 0
	movl	$1, %edx	#, doit
	testb	$16, %al	#, D.28886
	jne	.L196	#,
	movl	-196(%rbp), %ecx	# %sfp,
	xorl	%edx, %edx	# doit
	testl	%ecx, %ecx	#
	setne	%dl	#, doit

>        doit = PageDirty(ppage) || (flags & MF_MUST_KILL);

	.loc 1 974 0
	movl	$1, %edx	#, doit
	testb	$16, %al	#, D.28886
	jne	.L196	#,
	movl	-196(%rbp), %ecx	# %sfp,
	xorl	%edx, %edx	# doit
	testl	%ecx, %ecx	#
	setne	%dl	#, doit

In both cases you get your standard shortcutting OR logic:

.loc 1 974 0
	movl	$1, %edx	#, doit		<--- preset doit
	testb	$16, %al	#, D.28886	<--- PG_dirty
	jne	.L196	#,			<--- ZF=0, shortcut out to kill_procs
	movl	-196(%rbp), %ecx	# %sfp, <--- get value of (flags & MF_MUST_KILL) which we computed earlier in the function and saved on stack
	xorl	%edx, %edx	# doit		<--- clear doit
	testl	%ecx, %ecx	#		<--- check above (flags & MF_MUST_KILL) is not 0
	setne	%dl	#, doit			<--- prep doit for kill_procs

so the compiler is pretty smart already.

You could go another step further by declaring

	bool doit;

and changing kill_procs() argument to bool too so that the booleanness
is really explicit.

This saves you the xor:

        .loc 1 975 0
        movl    $1, %edx        #, prephitmp.124
        testb   $16, %al        #, D.28891
        jne     .L196   #,
        movl    -196(%rbp), %ecx        # %sfp,
        testl   %ecx, %ecx      #
        setne   %dl     #, prephitmp.124

because we're using explicitly bools which are u8s, apparently, in this
case and we're reusing the 1 we wrote into edx at the beginning of the
block.

Oh well, enough fun.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551

      reply	other threads:[~2012-07-10 18:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06 21:33 [PATCH] x86/mce: Need to let kill_proc() send signal to doomed process Tony Luck
2012-07-07  4:38 ` Borislav Petkov
2012-07-09 16:22   ` Luck, Tony
2012-07-09 20:34     ` Tony Luck
2012-07-10 15:44       ` Borislav Petkov
2012-07-10 17:12         ` Tony Luck
2012-07-10 18:36           ` Borislav Petkov [this message]

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=20120710183626.GA4419@aftab.osrc.amd.com \
    --to=bp@amd64.org \
    --cc=gong.chen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=tony.luck@intel.com \
    --cc=ying.huang@intel.com \
    /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