Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp790985imm; Mon, 2 Jul 2018 23:24:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLma+skS8xkBw130jXW+BwbOgfPZWpuQ9Lns9GwXvAqRbTxmc3SAc76RGYxDNDEsOlIS38g X-Received: by 2002:a65:5106:: with SMTP id f6-v6mr23971872pgq.72.1530599054177; Mon, 02 Jul 2018 23:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530599054; cv=none; d=google.com; s=arc-20160816; b=uf7AT6e/oHV7PeSpoK4pFFlW5//ztDrxsyXO+GNDCmkLyu1pplnhlrItEi1M54s3lr oC808qJqUn6bJlzX30pMoqNuN2AQ4yOwBmw4WuCVsku3p2AR1KZdsIkfYxkY7M3745HC ei4bWY1l6C/QO932RFdlrXYaBoLEkrRMpq1TQt/kOLbucqag79x+wosZ7iTc0E7Yq5NN o0Un8g5Ubb/KS9pyPYaz3NfPLcKKtQTR5mkmLzmKK8429jqYppk40ZgriidYkeBgAsKB /QRoC3V7AN7rnDzWBHYUDrYCQr7uI9J90X+JRDD5qPIkIVme7Nd4G+7cmcydN7qFEKq2 /1nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=WNr5GLoJJSKFnf6nkwAKd/Dw6Pj5dKd0EWzz2EuueJg=; b=IKKmKCntnI53wpjGYDudIaOhhTxBptKlZLLb+n2VCrxur0TAUzOHLfO7EDIac42/a7 yzRa3LTUiHN9+rqbZmEqs6QvHQ7okOmnhbGNLaN9MSGHJDwuYLDtXF0eHjl90aWhLCsY u2pTVpZ+WLDEvie2WkVvZ+8XOTYH3W0fa96f6SzE7xkBN3SKCDFSxd4qUFEi256gr5e4 bB6MKxyamVA6jj800cyO7phLNNggRmPdizszIret90yvtYqVXsumg58IS+rkl6WlPFmX p6Op9vH7zFhBm5XQtjv3HXGgT9aozbqSzYqK+jtgda08qdpKoC8QELnyltzhnVDABWyG T8AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K8f9uPge; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i184-v6si371017pge.405.2018.07.02.23.23.59; Mon, 02 Jul 2018 23:24:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K8f9uPge; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933469AbeGCGWl (ORCPT + 99 others); Tue, 3 Jul 2018 02:22:41 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:36238 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933231AbeGCGVm (ORCPT ); Tue, 3 Jul 2018 02:21:42 -0400 Received: by mail-pl0-f66.google.com with SMTP id a7-v6so506888plp.3; Mon, 02 Jul 2018 23:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WNr5GLoJJSKFnf6nkwAKd/Dw6Pj5dKd0EWzz2EuueJg=; b=K8f9uPge0mRUq5cSMWo1USb+Pz9HYCAhRz0G3Hf2o5OpqJKW6BhsbDuL6HDMymAm7g MhkJp3JX9FbR8k8F7ZgshoVkfma92AkyuBzicaSx3yCZe3ba843wl1ZWgXjpIqXkk/tz aZ2wapytsC4JngVSnDq6A49ZDFDKIndv/W+LxraO7Khs+PRj6pgwDyba/0+KyY+uZe+y WDpjXoFH/LB0nF4SG/mTKL2HWBFumYb5vzsA8v66Xr5KvOeYBpOTu6rS38UI19WhZYDY JVx+GfdDO7ISxzoETlNhtNMCrGAWv2Vr4YyC6hwlLSo/tmTpAQVd+NsjpVkqndExKzca 54Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WNr5GLoJJSKFnf6nkwAKd/Dw6Pj5dKd0EWzz2EuueJg=; b=Y03zVV+TerHtw3919ngDITleS/20GXKQFULxzoaEVksK+8OVikpREAvtb7wVoEbErJ ahcPClGiQhC8KviMuWT9oHEH/n+M0BeuSPK3zjSCknD4Q99IJa+SpGjQFccdEzwD3zkc xzDJMlXdWHrnMqSUtMBmVJkBwNVCRLR74HJxU2R8P7t96WiCAba+v3HmLmPB20nculuq XZTfSV0I5mN0t7r7JB+D41SWsI0DDY41jCt01wG/GmxEaWvwpfrBI07Z/DcOFneWoq8I Q1gMGbW9OhkYVTGXWd0iJPfwer6XX+avSS4B/XVB1TZITI83rjno58ml7QwK3JYsC02r DYNg== X-Gm-Message-State: APt69E0EqpV6kx70/MFDMFKX8GvglhSXodMZOwV88PurNLUkf17QXoXK Pempi0QJxDXLZhi7JRADJKK0RA== X-Received: by 2002:a17:902:be0b:: with SMTP id r11-v6mr29657143pls.182.1530598901733; Mon, 02 Jul 2018 23:21:41 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id v89-v6sm1766427pfd.64.2018.07.02.23.21.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 23:21:41 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Vitaly Kuznetsov Subject: [PATCH v3 3/6] KVM: X86: Fallback to original apic hooks when bad happens Date: Tue, 3 Jul 2018 14:21:28 +0800 Message-Id: <1530598891-21370-4-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530598891-21370-1-git-send-email-wanpengli@tencent.com> References: <1530598891-21370-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li Fallback to original apic hooks when apic id is sparse and larger than 128 or kvm fails to add the pending IRQ to lapic. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 2fe1420..81be75b 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -47,6 +47,7 @@ #include #include +static struct apic orig_apic; static int kvmapf = 1; static int __init parse_no_kvmapf(char *arg) @@ -456,13 +457,13 @@ static void __init sev_map_percpu_data(void) #ifdef CONFIG_SMP #ifdef CONFIG_X86_64 -static void __send_ipi_mask(const struct cpumask *mask, int vector) +static int __send_ipi_mask(const struct cpumask *mask, int vector) { unsigned long flags, ipi_bitmap_low = 0, ipi_bitmap_high = 0; - int cpu, apic_id; + int cpu, apic_id, ret = 0; if (cpumask_empty(mask)) - return; + return 0; local_irq_save(flags); @@ -472,16 +473,23 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector) __set_bit(apic_id, &ipi_bitmap_low); else if (apic_id < 2 * BITS_PER_LONG) __set_bit(apic_id - BITS_PER_LONG, &ipi_bitmap_high); + else { + ret = -EFAULT; + goto irq_restore_exit; + } } - kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, vector); + ret = kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, vector); +irq_restore_exit: local_irq_restore(flags); + return ret; } static void kvm_send_ipi_mask(const struct cpumask *mask, int vector) { - __send_ipi_mask(mask, vector); + if (__send_ipi_mask(mask, vector)) + orig_apic.send_IPI_mask(mask, vector); } static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector) @@ -493,7 +501,8 @@ static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector) cpumask_copy(&new_mask, mask); cpumask_clear_cpu(this_cpu, &new_mask); local_mask = &new_mask; - __send_ipi_mask(local_mask, vector); + if (__send_ipi_mask(local_mask, vector)) + orig_apic.send_IPI_mask_allbutself(mask, vector); } static void kvm_send_ipi_allbutself(int vector) @@ -503,7 +512,8 @@ static void kvm_send_ipi_allbutself(int vector) static void kvm_send_ipi_all(int vector) { - __send_ipi_mask(cpu_online_mask, vector); + if (__send_ipi_mask(cpu_online_mask, vector)) + orig_apic.send_IPI_all(vector); } /* @@ -511,6 +521,8 @@ static void kvm_send_ipi_all(int vector) */ static void kvm_setup_pv_ipi(void) { + orig_apic = *apic; + apic->send_IPI_mask = kvm_send_ipi_mask; apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself; apic->send_IPI_allbutself = kvm_send_ipi_allbutself; -- 2.7.4