From patchwork Wed Apr 5 20:47:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahesh J Salgaonkar X-Patchwork-Id: 9665743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DF5960353 for ; Wed, 5 Apr 2017 20:47:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F75226AE3 for ; Wed, 5 Apr 2017 20:47:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 144502858F; Wed, 5 Apr 2017 20:47:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0C8726AE3 for ; Wed, 5 Apr 2017 20:47:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932258AbdDEUrb (ORCPT ); Wed, 5 Apr 2017 16:47:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56493 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934053AbdDEUra (ORCPT ); Wed, 5 Apr 2017 16:47:30 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v35KhrwB168102 for ; Wed, 5 Apr 2017 16:47:30 -0400 Received: from e28smtp06.in.ibm.com (e28smtp06.in.ibm.com [125.16.236.6]) by mx0b-001b2d01.pphosted.com with ESMTP id 29mydsbymg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 05 Apr 2017 16:47:30 -0400 Received: from localhost by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 6 Apr 2017 02:17:26 +0530 Received: from d28relay05.in.ibm.com (9.184.220.62) by e28smtp06.in.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 6 Apr 2017 02:17:25 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v35KlJcW18415736; Thu, 6 Apr 2017 02:17:19 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v35KlMC4009951; Thu, 6 Apr 2017 02:17:24 +0530 Received: from jupiter.in.ibm.com ([9.79.194.254]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v35KlM72009945; Thu, 6 Apr 2017 02:17:22 +0530 Subject: [PATCH v7 2/3] powerpc/powernv: Introduce a machine check hook for Guest MCEs. From: Mahesh J Salgaonkar To: gleb@kernel.org, agraf@suse.de, KVM-PPC , linuxppc-dev , Paul Mackerras , pbonzini@redhat.com Cc: KVM , david@gibson.dropbear.id.au Date: Thu, 06 Apr 2017 02:17:22 +0530 In-Reply-To: <149142508580.28284.10052904644951828717.stgit@jupiter.in.ibm.com> References: <149142508580.28284.10052904644951828717.stgit@jupiter.in.ibm.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-MML: disable x-cbid: 17040520-0020-0000-0000-000000E1113D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17040520-0021-0000-0000-000002A02CDD Message-Id: <149142524189.28284.14876788789820474952.stgit@jupiter.in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-05_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704050173 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mahesh Salgaonkar This patch introduces a mce hook which is invoked at the time of guest exit to facilitate the host-side handling of machine check exception before the exception is passed on to the guest. This hook will be invoked from host virtual mode from KVM (before exiting the guest with KVM_EXIT_NMI reason) for machine check exception that occurs in the guest. Signed-off-by: Mahesh Salgaonkar --- arch/powerpc/include/asm/machdep.h | 7 +++++++ arch/powerpc/include/asm/opal.h | 4 ++++ arch/powerpc/platforms/powernv/opal.c | 26 ++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/setup.c | 3 +++ 4 files changed, 40 insertions(+) diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h index 5011b69..9d74e7a 100644 --- a/arch/powerpc/include/asm/machdep.h +++ b/arch/powerpc/include/asm/machdep.h @@ -15,6 +15,7 @@ #include #include +#include /* We export this macro for external modules like Alsa to know if * ppc_md.feature_call is implemented or not @@ -112,6 +113,12 @@ struct machdep_calls { /* Called during machine check exception to retrive fixup address. */ bool (*mce_check_early_recovery)(struct pt_regs *regs); +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE + /* Called after KVM interrupt handler finishes handling MCE for guest */ + int (*machine_check_exception_guest) + (struct machine_check_event *evt); +#endif + /* Motherboard/chipset features. This is a kind of general purpose * hook used to control some machine specific features (like reset * lines, chip power control, etc...). diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h index 1ff03a6..9b1fcbf 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h @@ -17,6 +17,7 @@ #ifndef __ASSEMBLY__ #include +#include /* We calculate number of sg entries based on PAGE_SIZE */ #define SG_ENTRIES_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct opal_sg_entry)) @@ -273,6 +274,9 @@ extern int opal_hmi_handler_init(void); extern int opal_event_init(void); extern int opal_machine_check(struct pt_regs *regs); +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +extern int opal_machine_check_guest(struct machine_check_event *evt); +#endif extern bool opal_mce_check_early_recovery(struct pt_regs *regs); extern int opal_hmi_exception_early(struct pt_regs *regs); extern int opal_handle_hmi_exception(struct pt_regs *regs); diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index e0f856b..5e633a4 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -479,6 +479,32 @@ int opal_machine_check(struct pt_regs *regs) return 0; } +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +/* + * opal_machine_check_guest() is a hook which is invoked at the time + * of guest exit to facilitate the host-side handling of machine check + * exception before the exception is passed on to the guest. This hook + * is invoked from host virtual mode from KVM (before exiting the guest + * with KVM_EXIT_NMI reason) for machine check exception that occurs in + * the guest. + * + * Currently no action is performed in the host other than printing the + * event information. The machine check exception is passed on to the + * guest kernel and the guest kernel will attempt for recovery. + */ +int opal_machine_check_guest(struct machine_check_event *evt) +{ + /* Print things out */ + if (evt->version != MCE_V1) { + pr_err("Machine Check Exception, Unknown event version %d !\n", + evt->version); + return 0; + } + machine_check_print_event_info(evt); + return 0; +} +#endif + /* Early hmi handler called in real mode. */ int opal_hmi_exception_early(struct pt_regs *regs) { diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index d50c7d9..333ee09 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -264,6 +264,9 @@ static void __init pnv_setup_machdep_opal(void) ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery; ppc_md.hmi_exception_early = opal_hmi_exception_early; ppc_md.handle_hmi_exception = opal_handle_hmi_exception; +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE + ppc_md.machine_check_exception_guest = opal_machine_check_guest; +#endif } static int __init pnv_probe(void)