From patchwork Tue Mar 12 07:29:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 10848675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3129E1390 for ; Tue, 12 Mar 2019 07:37:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CDC0293DA for ; Tue, 12 Mar 2019 07:37:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10FED293EE; Tue, 12 Mar 2019 07:37:43 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 7DAE1293DA for ; Tue, 12 Mar 2019 07:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbfCLHhl (ORCPT ); Tue, 12 Mar 2019 03:37:41 -0400 Received: from mx137-tc.baidu.com ([61.135.168.137]:55565 "EHLO tc-sys-mailedm02.tc.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726614AbfCLHhl (ORCPT ); Tue, 12 Mar 2019 03:37:41 -0400 X-Greylist: delayed 514 seconds by postgrey-1.27 at vger.kernel.org; Tue, 12 Mar 2019 03:37:40 EDT Received: from localhost (cp01-cos-dev01.cp01.baidu.com [10.92.119.46]) by tc-sys-mailedm02.tc.baidu.com (Postfix) with ESMTP id 02F0011C0086; Tue, 12 Mar 2019 15:29:27 +0800 (CST) From: Li RongQing To: x86@kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: fix error handling in svm_hardware_setup Date: Tue, 12 Mar 2019 15:29:26 +0800 Message-Id: <1552375767-27828-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Li Rongqing free all memory if fail to setup, otherwise they will be leaked Signed-off-by: Li Rongqing Signed-off-by: Zhang Yu --- arch/x86/kvm/svm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 1787a484d21c..b80a11d99a2a 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1396,6 +1396,12 @@ static __init int svm_hardware_setup(void) return 0; err: + if (svm_sev_enabled()) + bitmap_free(sev_asid_bitmap); + + for_each_possible_cpu(cpu) + svm_cpu_uninit(cpu); + __free_pages(iopm_pages, IOPM_ALLOC_ORDER); iopm_base = 0; return r;