Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752554AbbFBU1M (ORCPT ); Tue, 2 Jun 2015 16:27:12 -0400 Received: from mail-bn1on0135.outbound.protection.outlook.com ([157.56.110.135]:22624 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751881AbbFBU0S (ORCPT ); Tue, 2 Jun 2015 16:26:18 -0400 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; alien8.de; dkim=none (message not signed) header.d=none; X-WSS-ID: 0NPC3FQ-07-71B-02 X-M-MSG: From: Aravind Gopalakrishnan To: , , CC: , , Subject: [PATCH V2 3/9] edac, mce_amd_inj: Modify flags attrigute to use string arguments Date: Tue, 2 Jun 2015 15:35:56 -0500 Message-ID: <1433277362-10911-4-git-send-email-Aravind.Gopalakrishnan@amd.com> X-Mailer: git-send-email 2.4.0 In-Reply-To: <1433277362-10911-1-git-send-email-Aravind.Gopalakrishnan@amd.com> References: <1433277362-10911-1-git-send-email-Aravind.Gopalakrishnan@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD038;1:awajPsSm+ihi2sbZGkk5hnP8ofjQMULFSEPXqFZKITlF6Fpkt59K4gSxQBosDxRlrxR7+8TIwik2JlRDQO46Fkd69B3i/KrP9B1aJpbgKn3Yr5uiXxmLxTt7XY+uf0o6FhUQJIf4vWjlOdmtJENCgt7Gf6ZkZURJ7U2h5fd4CcHtXYQSrSvmdNhVlu/mgxKpJjIqsmVwG7MgLrwBjQhYNXsNfYw2W6Qd8mlVdrY5yXQzL6asKlIHYDXtOWLgEKuw7/mliUH2k8VKbOu1onYJkQ== X-Forefront-Antispam-Report: CIP:165.204.84.221;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(428002)(199003)(189002)(64706001)(53416004)(2950100001)(76176999)(68736005)(229853001)(62966003)(101416001)(50226001)(87936001)(50466002)(19580395003)(19580405001)(46102003)(50986999)(77096005)(48376002)(106466001)(36756003)(92566002)(5001860100001)(189998001)(97736004)(105586002)(2201001)(77156002)(4001540100001)(5001770100001)(47776003)(5001830100001)(86362001);DIR:OUT;SFP:1102;SCL:1;SRVR:BY1PR02MB1113;H:atltwp01.amd.com;FPR:;SPF:None;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR02MB1113; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)(3002001);SRVR:BY1PR02MB1113;BCL:0;PCL:0;RULEID:;SRVR:BY1PR02MB1113; X-Forefront-PRVS: 05954A7C45 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2015 20:26:15.3811 (UTC) X-MS-Exchange-CrossTenant-Id: fde4dada-be84-483f-92cc-e026cbee8e96 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fde4dada-be84-483f-92cc-e026cbee8e96;Ip=[165.204.84.221];Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR02MB1113 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3821 Lines: 150 Use char values such as "hw" or "sw" to indicate the type of error injection to be performed. Current flags attribute derives the meanings of values that can be programmed into it from asm/mce.h. Moving to defined strings for the atribute allows this module to be self sufficient and removes the dependency. Also, we can introduce new flags as and when needed without having to worry about conflicting with the flags already defined in asm/mce.h Also, modify do_inject() to use the newly defined injection_type enum to figure out the injection mechanism we need to use Suggested-by: Borislav Petkov Signed-off-by: Aravind Gopalakrishnan --- drivers/edac/mce_amd_inj.c | 82 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c index 15f6aa1..c129a8d 100644 --- a/drivers/edac/mce_amd_inj.c +++ b/drivers/edac/mce_amd_inj.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include "mce_amd.h" @@ -27,6 +29,23 @@ static struct dentry *dfs_inj; static u8 n_banks; +#define MAX_FLAG_OPT_SIZE 3 + +enum injection_type { + SW_INJ = 0, /* SW injection, simply decode the error */ + HW_INJ, /* Trigger a #MC */ + N_INJ_TYPES, +}; + +static const char * const flags_options[] = { + [SW_INJ] = "sw", + [HW_INJ] = "hw", + NULL +}; + +/* Set default injection to SW_INJ */ +enum injection_type inj_type = SW_INJ; + #define MCE_INJECT_SET(reg) \ static int inj_##reg##_set(void *data, u64 val) \ { \ @@ -81,24 +100,67 @@ static int toggle_hw_mce_inject(unsigned int cpu, bool enable) return err; } -static int flags_get(void *data, u64 *val) +static int __set_inj(const char *buf) { - struct mce *m = (struct mce *)data; + int i; - *val = m->inject_flags; + for (i = 0; i < N_INJ_TYPES; i++) { + if (!strncmp(flags_options[i], buf, + strlen(flags_options[i]))) { + inj_type = i; + return 0; + } + } + return -EINVAL; +} - return 0; +static ssize_t flags_read(struct file *filp, char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + char buf[MAX_FLAG_OPT_SIZE]; + int n; + + n = sprintf(buf, "%s\n", flags_options[inj_type]); + + return simple_read_from_buffer(ubuf, cnt, ppos, buf, n); } -static int flags_set(void *data, u64 val) +static ssize_t flags_write(struct file *filp, const char __user *ubuf, + size_t cnt, loff_t *ppos) { - struct mce *m = (struct mce *)data; + char buf[MAX_FLAG_OPT_SIZE]; + int err; + size_t ret; - m->inject_flags = (u8)val; - return 0; + if (cnt > MAX_FLAG_OPT_SIZE) + cnt = MAX_FLAG_OPT_SIZE; + + ret = cnt; + + if (copy_from_user(&buf, ubuf, cnt)) + return -EFAULT; + + buf[cnt - 1] = 0; + + /* strip whitespaces.. */ + strstrip(buf); + + err = __set_inj(buf); + if (err) { + pr_err("%s: Invalid flags value: %s\n", __func__, buf); + return err; + } + + *ppos += ret; + + return ret; } -DEFINE_SIMPLE_ATTRIBUTE(flags_fops, flags_get, flags_set, "%llu\n"); +static const struct file_operations flags_fops = { + .read = flags_read, + .write = flags_write, + .llseek = generic_file_llseek, +}; /* * On which CPU to inject? @@ -130,7 +192,7 @@ static void do_inject(void) unsigned int cpu = i_mce.extcpu; u8 b = i_mce.bank; - if (!(i_mce.inject_flags & MCJ_EXCEPTION)) { + if (inj_type == SW_INJ) { amd_decode_mce(NULL, 0, &i_mce); return; } -- 2.4.0 -- 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/