MCE_INJECT_SET(misc);
 MCE_INJECT_SET(addr);
 MCE_INJECT_SET(synd);
-MCE_INJECT_SET(ipid);
 
 #define MCE_INJECT_GET(reg)                                            \
 static int inj_##reg##_get(void *data, u64 *val)                       \
 DEFINE_SIMPLE_ATTRIBUTE(misc_fops, inj_misc_get, inj_misc_set, "%llx\n");
 DEFINE_SIMPLE_ATTRIBUTE(addr_fops, inj_addr_get, inj_addr_set, "%llx\n");
 DEFINE_SIMPLE_ATTRIBUTE(synd_fops, inj_synd_get, inj_synd_set, "%llx\n");
+
+/* Use the user provided IPID value on a sw injection. */
+static int inj_ipid_set(void *data, u64 val)
+{
+       struct mce *m = (struct mce *)data;
+
+       if (cpu_feature_enabled(X86_FEATURE_SMCA)) {
+               if (inj_type == SW_INJ)
+                       m->ipid = val;
+       }
+
+       return 0;
+}
+
 DEFINE_SIMPLE_ATTRIBUTE(ipid_fops, inj_ipid_get, inj_ipid_set, "%llx\n");
 
 static void setup_inj_struct(struct mce *m)
        }
 
        m->bank = val;
+
+       /*
+        * sw-only injection allows to write arbitrary values into the MCA
+        * registers because it tests only the decoding paths.
+        */
+       if (inj_type == SW_INJ)
+               goto inject;
+
+       /*
+        * Read IPID value to determine if a bank is populated on the target
+        * CPU.
+        */
+       if (cpu_feature_enabled(X86_FEATURE_SMCA)) {
+               u64 ipid;
+
+               if (rdmsrl_on_cpu(m->extcpu, MSR_AMD64_SMCA_MCx_IPID(val), &ipid)) {
+                       pr_err("Error reading IPID on CPU%d\n", m->extcpu);
+                       return -EINVAL;
+               }
+
+               if (!ipid) {
+                       pr_err("Cannot inject into unpopulated bank %llu\n", val);
+                       return -ENODEV;
+               }
+       }
+
+inject:
        do_inject();
 
        /* Reset injection struct */