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  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]
Date:	Mon, 6 Oct 2014 23:27:07 +0200
From:	Borislav Petkov <bp@...en8.de>
To:	Chen Yucong <slaoub@...il.com>
Cc:	Tony Luck <tony.luck@...il.com>,
	"linux-edac@...r.kernel.org" <linux-edac@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86, MCE, AMD: move invariant code out from loop body

On Thu, Oct 02, 2014 at 11:20:12PM +0800, Chen Yucong wrote:
> From: Chen Yucong <slaoub@...il.com>
> Subject: [PATCH] x86, MCE, AMD: move invariant code out from loop body
> 
> "mce_threshold_vector = amd_threshold_interrupt;" is loop invariant code
> in mce_amd_feature_init(). So it should be moved out from loop body.
> 
> Signed-off-by: Chen Yucong <slaoub@...il.com>
> ---
>  arch/x86/kernel/cpu/mcheck/mce_amd.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
> index 5d4999f..f727701 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
> @@ -253,9 +253,10 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
>  			}
>  
>  			mce_threshold_block_init(&b, offset);
> -			mce_threshold_vector = amd_threshold_interrupt;
>  		}
>  	}
> +
> +	mce_threshold_vector = amd_threshold_interrupt;

Looking at this more, it is theoretically possible that we break out
of the both loops without *any* thresholding registers detected and to
still assign a thresholding interrupt vector which would be clearly
wrong.

Thus I think something like below should be much safer (I tried it with
a label and goto already but it is uglier):

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 9ce64955559d..9af7bd74828b 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -253,7 +253,9 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
 			}
 
 			mce_threshold_block_init(&b, offset);
-			mce_threshold_vector = amd_threshold_interrupt;
+
+			if (mce_threshold_vector != amd_threshold_interrupt)
+				mce_threshold_vector = amd_threshold_interrupt;
 		}
 	}
 }

Looking at the asm, we still go and fetch those addresses so not really
a win:

	cmpq	$amd_threshold_interrupt, mce_threshold_vector(%rip)	#, mce_threshold_vector
	je	.L235	#,
	incl	%r13d	# block
	movq	$amd_threshold_interrupt, mce_threshold_vector(%rip)	#, mce_threshold_vector
	cmpl	$9, %r13d	#, block

but this way the code is relatively clean. Unless you can come up with
a nicer, cleaner version to handle the breaking out in the success and
failure case...

Hmmm.

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists