Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754109AbZJIFqf (ORCPT ); Fri, 9 Oct 2009 01:46:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752734AbZJIFqe (ORCPT ); Fri, 9 Oct 2009 01:46:34 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:52125 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752474AbZJIFqd (ORCPT ); Fri, 9 Oct 2009 01:46:33 -0400 X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.3.1 Message-ID: <4ACECE09.8090408@jp.fujitsu.com> Date: Fri, 09 Oct 2009 14:45:45 +0900 From: Hidetoshi Seto User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Huang Ying CC: Ingo Molnar , "H. Peter Anvin" , Andi Kleen , "linux-kernel@vger.kernel.org" Subject: [PATCH 3/4] mce-inject: change msr_to_offset() to mce_get_fake_reg() References: <1254100882.15717.1312.camel@yhuang-dev.sh.intel.com> <4AC95F5A.4000708@jp.fujitsu.com> <4AC96391.1060001@jp.fujitsu.com> <1255053299.5228.28.camel@yhuang-dev.sh.intel.com> <4ACECC49.7000602@jp.fujitsu.com> In-Reply-To: <4ACECC49.7000602@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2488 Lines: 82 Introduce mce_get_fake_reg() which returns address of variable for faked register. Signed-off-by: Hidetoshi Seto --- arch/x86/kernel/cpu/mcheck/mce.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index 5a6f17d..edd2a82 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -301,20 +301,22 @@ static void mce_panic(char *msg, struct mce *final, char *exp) /* Support code for software error injection */ -static int msr_to_offset(u32 msr) +static u64 *mce_get_fake_reg(u32 msr) { unsigned bank = __get_cpu_var(mce_fake_banks).bank; + if (msr == rip_msr) - return offsetof(struct mce_fake_banks, ip); + return &__get_cpu_var(mce_fake_banks).ip; if (msr == MSR_IA32_MCx_STATUS(bank)) - return offsetof(struct mce_fake_banks, status); + return &__get_cpu_var(mce_fake_banks).status; if (msr == MSR_IA32_MCx_ADDR(bank)) - return offsetof(struct mce_fake_banks, addr); + return &__get_cpu_var(mce_fake_banks).addr; if (msr == MSR_IA32_MCx_MISC(bank)) - return offsetof(struct mce_fake_banks, misc); + return &__get_cpu_var(mce_fake_banks).misc; if (msr == MSR_IA32_MCG_STATUS) - return offsetof(struct mce_fake_banks, mcgstatus); - return -1; + return &__get_cpu_var(mce_fake_banks).mcgstatus; + + return NULL; } /* MSR access wrappers used for error injection */ @@ -323,12 +325,11 @@ static u64 mce_rdmsrl(u32 msr) u64 v; if (__get_cpu_var(mce_fake_banks).valid) { - int offset = msr_to_offset(msr); - char *m = (char *)&__get_cpu_var(mce_fake_banks); + u64 *reg = mce_get_fake_reg(msr); - if (offset < 0) + if (!reg) return 0; - return *(u64 *)(m + offset); + return *reg; } if (rdmsrl_safe(msr, &v)) { @@ -347,11 +348,10 @@ static u64 mce_rdmsrl(u32 msr) static void mce_wrmsrl(u32 msr, u64 v) { if (__get_cpu_var(mce_fake_banks).valid) { - int offset = msr_to_offset(msr); - char *m = (char *)&__get_cpu_var(mce_fake_banks); + u64 *reg = mce_get_fake_reg(msr); - if (offset >= 0) - *(u64 *)(m + offset) = v; + if (reg) + *reg = v; return; } wrmsrl(msr, v); -- 1.6.2.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/