Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3289205pxk; Mon, 21 Sep 2020 09:47:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1rbKYIX+GapGEFHLTg67GIQvZf8oJ4pUUZof55BcXYREMSMPJfeznPoaRcX8QOk4J44qV X-Received: by 2002:aa7:c98d:: with SMTP id c13mr549193edt.199.1600706857637; Mon, 21 Sep 2020 09:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706857; cv=none; d=google.com; s=arc-20160816; b=M290UOuD+wdUGH2pfwh2IzK/bq64fzLAWVDFSnwFd1Cq3FX/0evfGronIC4fNr1+M8 ZlcAZq31cUPu88GiF7dwvfuYA6Qb0ul9dvNodOoU+ZY7oB7d3DRUKmOg4h1xuVVj5OHp EW/kbO8E7QzL7p7Sw1tDGxzGNibsJwVpAgjn9QbhvfV6qyjPF7HxJblQdIbAgsm60Nb5 aMVlN1DVPYMU5pPjTuBakDkaFgyjbKQq5L+gPURCSbODVaAe9txiRu70qfHQTdmUpdYC sEuD9Dpyw9kmACGRb+GKFPVuexyQWqNdZVnE2Gu/riqNPGx+SbAL0xuS8hVL0/0mQ6IA tDzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9hJUvTCg+6bCaGuDIhUHz+1CCriomXFutgUEc4klMLY=; b=fR407pRF86jv+jin5+m14ljldz3zCtdV0ebpmeXvSgacrc5/QKS43aXxDT9SCYRom/ KFpc9zL7nosQXbuI6oStM4/NhikXrQBAHy6B2NIBgf3yfg/fVcm7uEfzcMSPYkXWI09P V8h8qToHsnsQzluWf7hO/uV0/OS0l4Tl1yv7uK0l558lKldKBTY791A7V+CSlSQUhBoP 13TlJMEQBB4+1cPKCHslUBDFJbG1EENZ0TnSSi3QY0SZ2AlSTa30PQZJV7jGrUWzX74P 10KdHFAdFpoyAKp3Eyn1CQIcSDY0CTy8ZQ6ODP9eJ1JkYU0R6xY4aGSxX1MeOEJXj6xI Jq0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O5igfEFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm17si7590582ejb.356.2020.09.21.09.47.13; Mon, 21 Sep 2020 09:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O5igfEFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729418AbgIUQoH (ORCPT + 99 others); Mon, 21 Sep 2020 12:44:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:48986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729655AbgIUQoA (ORCPT ); Mon, 21 Sep 2020 12:44:00 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B8D9B238E6; Mon, 21 Sep 2020 16:43:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706639; bh=OfGD2NmQi/dzHK4CFANYl88bZ5RChIHLeDbSAu2jVUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O5igfEFtIX8BAGYf6aN0auiyA6POdwXpCJQZ9rpivAHEUfbttV1ZqBlggVPk87ESJ QydkPxNzFI6ZikGZrZcPbGVtUjx7dOs0QL1V9m3RRIYOtRAoMMEEL/TX+u7Z/pqG8c ukNU3GRqMGj6jzicqiHnnCGfHWbs6HbI16SlqhOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haiwei Li , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.8 034/118] KVM: Check the allocation of pv cpu mask Date: Mon, 21 Sep 2020 18:27:26 +0200 Message-Id: <20200921162037.894223054@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Haiwei Li [ Upstream commit 0f990222108d214a0924d920e6095b58107d7b59 ] check the allocation of per-cpu __pv_cpu_mask. Initialize ops only when successful. Signed-off-by: Haiwei Li Message-Id: Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kernel/kvm.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index df63786e7bfa4..d6219f3181d63 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -638,7 +638,6 @@ static void __init kvm_guest_init(void) } if (pv_tlb_flush_supported()) { - pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; pv_ops.mmu.tlb_remove_table = tlb_remove_table; pr_info("KVM setup pv remote TLB flush\n"); } @@ -750,6 +749,14 @@ static __init int activate_jump_labels(void) } arch_initcall(activate_jump_labels); +static void kvm_free_pv_cpu_mask(void) +{ + unsigned int cpu; + + for_each_possible_cpu(cpu) + free_cpumask_var(per_cpu(__pv_cpu_mask, cpu)); +} + static __init int kvm_alloc_cpumask(void) { int cpu; @@ -768,11 +775,20 @@ static __init int kvm_alloc_cpumask(void) if (alloc) for_each_possible_cpu(cpu) { - zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu), - GFP_KERNEL, cpu_to_node(cpu)); + if (!zalloc_cpumask_var_node( + per_cpu_ptr(&__pv_cpu_mask, cpu), + GFP_KERNEL, cpu_to_node(cpu))) { + goto zalloc_cpumask_fail; + } } + apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself; + pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; return 0; + +zalloc_cpumask_fail: + kvm_free_pv_cpu_mask(); + return -ENOMEM; } arch_initcall(kvm_alloc_cpumask); -- 2.25.1