From patchwork Tue Jun 30 11:50:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1319775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=H2Sz3Clp; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49x2k76jjPz9sSd for ; Tue, 30 Jun 2020 21:50:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732201AbgF3Luz (ORCPT ); Tue, 30 Jun 2020 07:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729580AbgF3Luz (ORCPT ); Tue, 30 Jun 2020 07:50:55 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C29D1C061755 for ; Tue, 30 Jun 2020 04:50:54 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id j18so18519918wmi.3 for ; Tue, 30 Jun 2020 04:50:54 -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=V4SU3OF/zJe1fJ6egxvJOApF/dMKKTgsz1S+z/74N+c=; b=H2Sz3ClpDISYRlki9h23iR9TnzE7RgM52S3Q1vNAaD5IWvwRci2G48OsUcMRrEUqee suhkYHoPCWHRUAsyppDFRV06QgPphnStvEgubMdnKrVgvvPYbnmo0UNx2jU494FZskpf xIWI0Uq9U85cf1khmo7HSTgUKPzaG8uYRT0gWdN93UtqAuwkPhwCggxUE1i+x5IRe5Ut tXpvc24Nib+WcH6YtoAnNFN2AZcv4jvv90pv/bqy4u7T8uxR7ZK2j2lHl0XzPeiFnTE6 6OSTPAj9h+1hIC51RvB5AFaTeDZhhAODcXOgvfOuLvrut+Z4xWwGmjP2tSFlpn0I+kJt yzYA== 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=V4SU3OF/zJe1fJ6egxvJOApF/dMKKTgsz1S+z/74N+c=; b=RcNiZwOoVKN47toxbTnlqUDs7qvUxmp4H9vzdS2TGfuB2B2qGc31ZSq6bgjS6fZ1zP 3iy5SozPlk8Ze4WLJ+QIghMz9sku1RuWVa+j+qIc6oAEdHjq9Cfdw52mDwq1dtazYycW E3gPz83wl5me6RJbaepTML2ArHprjKmpw1WtyadH6ZSCq6ZSBGWFuEVjsuxjlyZX6q1e eFBIDzXm72jHQvNgvr8WJG5n7eqe8MXS/OLskymx3gItYm2TfWhekdb0ejV8MR20ar5t nx5acwhmkkNEmRyhRyJW9fJFtviiPhF5K/KU649Do57PJtGRTSnrstM6/QVsOmlb2168 5gIg== X-Gm-Message-State: AOAM531XKQ4evToyxRmlSz570+OxW6NBWgNavXDus2Nb/TorUUvVL9mB wf58gGw63oPtm7LEgfidwfPxpKsF X-Google-Smtp-Source: ABdhPJyMoS0lRy5/48s00HBSycE/0Z4AK9VHlJ2fU7LI/SS3pY39ovn7E7KelfFiKMET0/Qzqw4FFA== X-Received: by 2002:a7b:c8c2:: with SMTP id f2mr20203918wml.57.1593517853476; Tue, 30 Jun 2020 04:50:53 -0700 (PDT) Received: from bobo.ibm.com (61-68-186-125.tpgi.com.au. [61.68.186.125]) by smtp.gmail.com with ESMTPSA id c25sm3133673wml.46.2020.06.30.04.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 04:50:52 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Cc: Nicholas Piggin , Michael Ellerman , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Anton Blanchard , David Gibson , Paul Mackerras , kvm-ppc@vger.kernel.org Subject: [PATCH v2 1/3] powerpc: inline doorbell sending functions Date: Tue, 30 Jun 2020 21:50:31 +1000 Message-Id: <20200630115034.137050-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200630115034.137050-1-npiggin@gmail.com> References: <20200630115034.137050-1-npiggin@gmail.com> MIME-Version: 1.0 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org These are only called in one place for a given platform, so inline them for performance. Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/dbell.h | 63 ++++++++++++++++++++++++++++++-- arch/powerpc/kernel/dbell.c | 55 ---------------------------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h index 4ce6808deed3..f19d2282e3f8 100644 --- a/arch/powerpc/include/asm/dbell.h +++ b/arch/powerpc/include/asm/dbell.h @@ -13,6 +13,7 @@ #include #include +#include #define PPC_DBELL_MSG_BRDCAST (0x04000000) #define PPC_DBELL_TYPE(x) (((x) & 0xf) << (63-36)) @@ -87,9 +88,6 @@ static inline void ppc_msgsync(void) #endif /* CONFIG_PPC_BOOK3S */ -extern void doorbell_global_ipi(int cpu); -extern void doorbell_core_ipi(int cpu); -extern int doorbell_try_core_ipi(int cpu); extern void doorbell_exception(struct pt_regs *regs); static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag) @@ -100,4 +98,63 @@ static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag) _ppc_msgsnd(msg); } +#ifdef CONFIG_SMP + +/* + * Doorbells must only be used if CPU_FTR_DBELL is available. + * msgsnd is used in HV, and msgsndp is used in !HV. + * + * These should be used by platform code that is aware of restrictions. + * Other arch code should use ->cause_ipi. + * + * doorbell_global_ipi() sends a dbell to any target CPU. + * Must be used only by architectures that address msgsnd target + * by PIR/get_hard_smp_processor_id. + */ +static inline void doorbell_global_ipi(int cpu) +{ + u32 tag = get_hard_smp_processor_id(cpu); + + kvmppc_set_host_ipi(cpu); + /* Order previous accesses vs. msgsnd, which is treated as a store */ + ppc_msgsnd_sync(); + ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag); +} + +/* + * doorbell_core_ipi() sends a dbell to a target CPU in the same core. + * Must be used only by architectures that address msgsnd target + * by TIR/cpu_thread_in_core. + */ +static inline void doorbell_core_ipi(int cpu) +{ + u32 tag = cpu_thread_in_core(cpu); + + kvmppc_set_host_ipi(cpu); + /* Order previous accesses vs. msgsnd, which is treated as a store */ + ppc_msgsnd_sync(); + ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag); +} + +/* + * Attempt to cause a core doorbell if destination is on the same core. + * Returns 1 on success, 0 on failure. + */ +static inline int doorbell_try_core_ipi(int cpu) +{ + int this_cpu = get_cpu(); + int ret = 0; + + if (cpumask_test_cpu(cpu, cpu_sibling_mask(this_cpu))) { + doorbell_core_ipi(cpu); + ret = 1; + } + + put_cpu(); + + return ret; +} + +#endif /* CONFIG_SMP */ + #endif /* _ASM_POWERPC_DBELL_H */ diff --git a/arch/powerpc/kernel/dbell.c b/arch/powerpc/kernel/dbell.c index f17ff1200eaa..52680cf07c9d 100644 --- a/arch/powerpc/kernel/dbell.c +++ b/arch/powerpc/kernel/dbell.c @@ -18,61 +18,6 @@ #ifdef CONFIG_SMP -/* - * Doorbells must only be used if CPU_FTR_DBELL is available. - * msgsnd is used in HV, and msgsndp is used in !HV. - * - * These should be used by platform code that is aware of restrictions. - * Other arch code should use ->cause_ipi. - * - * doorbell_global_ipi() sends a dbell to any target CPU. - * Must be used only by architectures that address msgsnd target - * by PIR/get_hard_smp_processor_id. - */ -void doorbell_global_ipi(int cpu) -{ - u32 tag = get_hard_smp_processor_id(cpu); - - kvmppc_set_host_ipi(cpu); - /* Order previous accesses vs. msgsnd, which is treated as a store */ - ppc_msgsnd_sync(); - ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag); -} - -/* - * doorbell_core_ipi() sends a dbell to a target CPU in the same core. - * Must be used only by architectures that address msgsnd target - * by TIR/cpu_thread_in_core. - */ -void doorbell_core_ipi(int cpu) -{ - u32 tag = cpu_thread_in_core(cpu); - - kvmppc_set_host_ipi(cpu); - /* Order previous accesses vs. msgsnd, which is treated as a store */ - ppc_msgsnd_sync(); - ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag); -} - -/* - * Attempt to cause a core doorbell if destination is on the same core. - * Returns 1 on success, 0 on failure. - */ -int doorbell_try_core_ipi(int cpu) -{ - int this_cpu = get_cpu(); - int ret = 0; - - if (cpumask_test_cpu(cpu, cpu_sibling_mask(this_cpu))) { - doorbell_core_ipi(cpu); - ret = 1; - } - - put_cpu(); - - return ret; -} - void doorbell_exception(struct pt_regs *regs) { struct pt_regs *old_regs = set_irq_regs(regs); From patchwork Tue Jun 30 11:50:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1319776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=L0USudye; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49x2kF0ftqz9sT2 for ; Tue, 30 Jun 2020 21:51:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732251AbgF3LvA (ORCPT ); Tue, 30 Jun 2020 07:51:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729580AbgF3LvA (ORCPT ); Tue, 30 Jun 2020 07:51:00 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA0EC061755 for ; Tue, 30 Jun 2020 04:50:59 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id b6so19784829wrs.11 for ; Tue, 30 Jun 2020 04:50:59 -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=kcYsmTzhEp8xx6FEht3XE+3X/L1jPFAQ52+7Dv3gK8g=; b=L0USudyektF2Cc8Oup2k3fOqJKuxbgAL6rtTM3p5xDeRowJaRXpKY/T8KI426Sp1jE 2PR54w14o8dItuxcEdBI0+BQYsiOyKKNX2EOL0RfyLq5WQnp9w6FW2H2ztBg/OxwqAx/ uL/y8tgrdyyth8wqHhXWm1fk+KS7Wrisj0IQ9T92S1d+jcQ+NBDHhjjfC168APoHxugz x+i4/WVZltTEReZHuyRj5BeSKdiBbMX39pgfaitRG2QbGV6XxkJ6M2nVpPGjqXdbZd01 B+S7FP4p9/6a3HfFhmlPMo5BBsXvBdXXU9s/SgwdlG/+wAFOGqojiSWdEPy2aq3a7IkL OPzA== 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=kcYsmTzhEp8xx6FEht3XE+3X/L1jPFAQ52+7Dv3gK8g=; b=id0Zrajk/3aFUFbxj9jIR1V6BdFfPVEfXkrke5qyu74J4SxuJcDMXVYujeLeDOWzIL ZXQWOQqddrjV1/L1C742+QgFKV1wuBnE0x8me5TLnAjEDwZyIqiu/TNSQiow6CGZXu4a 1hviDXE/paeq4O9qBaO0K13ROKOPISBTj9BdP6nuSnJHJWFyd7lLHfFgB6apWAXKHqEJ C8rl/FvyKzcLihPAQUJYftmwwM+BIJDdDUAE0GzQiHlUbmmllwoGev1wfsQq2CbOTHuN 92cgg+RsX3yGS2h3xxARm5SC71kjNii/yqKT5RKojYyVbQS7wtCG8Qq0d9Bwq186IMdy yhKA== X-Gm-Message-State: AOAM531pmeK4lFY9xr+3i+9BxyEmufPPwXd5QOjy3oZ+no2pgpFWpHzm jTvJyPUTm61lDK+Py8lauai1/IqJ X-Google-Smtp-Source: ABdhPJxsML2kYOdlBwOJzT3J7t3FBvtGvblzJuhLM37QcRd+9XTNE9Km6/om/xujUR3CzYW4TeJ8BA== X-Received: by 2002:adf:dfd1:: with SMTP id q17mr20337495wrn.94.1593517858603; Tue, 30 Jun 2020 04:50:58 -0700 (PDT) Received: from bobo.ibm.com (61-68-186-125.tpgi.com.au. [61.68.186.125]) by smtp.gmail.com with ESMTPSA id c25sm3133673wml.46.2020.06.30.04.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 04:50:58 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Cc: Nicholas Piggin , Michael Ellerman , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Anton Blanchard , David Gibson , Paul Mackerras , kvm-ppc@vger.kernel.org Subject: [PATCH v2 2/3] powerpc/pseries: Use doorbells even if XIVE is available Date: Tue, 30 Jun 2020 21:50:32 +1000 Message-Id: <20200630115034.137050-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200630115034.137050-1-npiggin@gmail.com> References: <20200630115034.137050-1-npiggin@gmail.com> MIME-Version: 1.0 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org KVM supports msgsndp in guests by trapping and emulating the instruction, so it was decided to always use XIVE for IPIs if it is available. However on PowerVM systems, msgsndp can be used and gives better performance. On large systems, high XIVE interrupt rates can have sub-linear scaling, and using msgsndp can reduce the load on the interrupt controller. So switch to using core local doorbells even if XIVE is available. This reduces performance for KVM guests with an SMT topology by about 50% for ping-pong context switching between SMT vCPUs. An option vector (or dt-cpu-ftrs) could be defined to disable msgsndp to get KVM performance back. Signed-off-by: Nicholas Piggin --- arch/powerpc/platforms/pseries/smp.c | 54 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c index 6891710833be..67e6ad5076ce 100644 --- a/arch/powerpc/platforms/pseries/smp.c +++ b/arch/powerpc/platforms/pseries/smp.c @@ -188,13 +188,16 @@ static int pseries_smp_prepare_cpu(int cpu) return 0; } -static void smp_pseries_cause_ipi(int cpu) +/* Cause IPI as setup by the interrupt controller (xics or xive) */ +static void (*ic_cause_ipi)(int cpu) __ro_after_init; + +/* Use msgsndp doorbells target is a sibling, else use interrupt controller */ +static void dbell_or_ic_cause_ipi(int cpu) { - /* POWER9 should not use this handler */ if (doorbell_try_core_ipi(cpu)) return; - icp_ops->cause_ipi(cpu); + ic_cause_ipi(cpu); } static int pseries_cause_nmi_ipi(int cpu) @@ -218,26 +221,41 @@ static int pseries_cause_nmi_ipi(int cpu) return 0; } -static __init void pSeries_smp_probe_xics(void) -{ - xics_smp_probe(); - - if (cpu_has_feature(CPU_FTR_DBELL) && !is_secure_guest()) - smp_ops->cause_ipi = smp_pseries_cause_ipi; - else - smp_ops->cause_ipi = icp_ops->cause_ipi; -} - static __init void pSeries_smp_probe(void) { if (xive_enabled()) - /* - * Don't use P9 doorbells when XIVE is enabled. IPIs - * using MMIOs should be faster - */ xive_smp_probe(); else - pSeries_smp_probe_xics(); + xics_smp_probe(); + + /* No doorbell facility, must use the interrupt controller for IPIs */ + if (!cpu_has_feature(CPU_FTR_DBELL)) + return; + + /* Doorbells can only be used for IPIs between SMT siblings */ + if (!cpu_has_feature(CPU_FTR_SMT)) + return; + + /* + * KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp faults + * to the hypervisor which then reads the instruction from guest + * memory. This can't be done if the guest is secure, so don't use + * doorbells in secure guests. + * + * Under PowerVM, FSCR[MSGP] is enabled so doorbells could be used + * by secure guests if we distinguished this from KVM. + */ + if (is_secure_guest()) + return; + + /* + * The guest can use doobells for SMT sibling IPIs, which stay in + * the core rather than going to the interrupt controller. This + * tends to be slower under KVM where doorbells are emulated, but + * faster for PowerVM where they're enabled. + */ + ic_cause_ipi = smp_ops->cause_ipi; + smp_ops->cause_ipi = dbell_or_ic_cause_ipi; } static struct smp_ops_t pseries_smp_ops = { From patchwork Tue Jun 30 11:50:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1319777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UFTQXMvw; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49x2kN48rSz9s6w for ; Tue, 30 Jun 2020 21:51:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733147AbgF3LvH (ORCPT ); Tue, 30 Jun 2020 07:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729580AbgF3LvF (ORCPT ); Tue, 30 Jun 2020 07:51:05 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF8BC061755 for ; Tue, 30 Jun 2020 04:51:04 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id z15so8540161wrl.8 for ; Tue, 30 Jun 2020 04:51:04 -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=/ZvoHqaUW6Z01Z7DFD/cW0QsTS+b1yJKdzwareCSkvw=; b=UFTQXMvwLVHO1kNl3Rry/GdrxedirPtrLvrs6nNuKtiR3A2zpWLeM2X/gbvgkMI175 7junVDkpGxxG9f3b6FItmnHg2tx7XatfU1YGqOuL79Yk5wCsL76ybu1wVxExM78ZItdF i366yaTG90HiATBliZCYyHuOnieAYeNXzUKtpCqqi0qaFly416UR/lqKdnsjQWIy+jgh 5SUCEKFS/fM37hDaE8cTJdSasI3MVN7XsVadbBaq655k4YhEz8ZpPb1AjeExyXR5jb18 /Qioparz3SJbia9I0qhZO/V7SQLLxtmmyAN9GDtW9LnFno0nOg0iJuo42wvMyUCAEWzJ utiQ== 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=/ZvoHqaUW6Z01Z7DFD/cW0QsTS+b1yJKdzwareCSkvw=; b=AMOPjWVgOXCCYbbq886u1GnOgUMnX5lhPtzxfGnWigggi3Cv57zTGTcbU8pW/uoyi+ hgWdmj9bW0wDWqwzsVhGIVzJ+JPPPBtKdjCj9IrygLzAYi8l256pEtHGEOiV8KYUaC7s ez9Acc5bIiGELOc1ut1tozqbJkOZBN15bDtZkZbB7YfV4L2YFh4Kzufm9aJowobPrLOe 7cn4LMIxEb1hwJKSLPSQYjDVT0mLIV6IHmx622yKxHUXQ+5yU7Pw71FiWmRV4sMF6gjY /sERTqyIx03pt38JY236lhfJJWYmXlGXQTy3h0/SlIh/2FGqXVT8V0YAV93/ClSCLEf+ B3gA== X-Gm-Message-State: AOAM530NtUlBztbfmKzb6jHgo4/lM6u+V7ZEq3EM3y+qCi30KtgAVpDP ge+gXrY7QkPJhtvnvP8CeyA= X-Google-Smtp-Source: ABdhPJwrMWQUzc6lbQklBcL5rkYLMNe0pz8zwpFEx0i1mU0oWoLLGWl3ye0Ck3Scq1afFphqMxNEQw== X-Received: by 2002:a05:6000:1c8:: with SMTP id t8mr23047565wrx.73.1593517863466; Tue, 30 Jun 2020 04:51:03 -0700 (PDT) Received: from bobo.ibm.com (61-68-186-125.tpgi.com.au. [61.68.186.125]) by smtp.gmail.com with ESMTPSA id c25sm3133673wml.46.2020.06.30.04.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 04:51:03 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Cc: Nicholas Piggin , Michael Ellerman , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Anton Blanchard , David Gibson , Paul Mackerras , kvm-ppc@vger.kernel.org Subject: [PATCH v2 3/3] powerpc/pseries: Add KVM guest doorbell restrictions Date: Tue, 30 Jun 2020 21:50:33 +1000 Message-Id: <20200630115034.137050-4-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200630115034.137050-1-npiggin@gmail.com> References: <20200630115034.137050-1-npiggin@gmail.com> MIME-Version: 1.0 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org KVM guests have certain restrictions and performance quirks when using doorbells. This patch moves the EPAPR KVM guest test so it can be shared with PSERIES, and uses that in doorbell setup code to apply the KVM guest quirks and improves IPI performance for two cases: - PowerVM guests may now use doorbells even if they are secure. - KVM guests no longer use doorbells if XIVE is available. There is a valid complaint that "KVM guest" is not a very reasonable thing to test for, it's preferable for the hypervisor to advertise particular behaviours to the guest so they could change if the hypervisor implementation or configuration changes. However in this case we were already assuming a KVM guest worst case, so this patch is about containing those quirks. If KVM later advertises fast doorbells, we should test for that and override the quirks. Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/firmware.h | 6 +++++ arch/powerpc/include/asm/kvm_para.h | 26 +++---------------- arch/powerpc/kernel/Makefile | 5 ++-- arch/powerpc/kernel/firmware.c | 19 ++++++++++++++ arch/powerpc/platforms/pseries/smp.c | 38 +++++++++++++++++----------- 5 files changed, 53 insertions(+), 41 deletions(-) diff --git a/arch/powerpc/include/asm/firmware.h b/arch/powerpc/include/asm/firmware.h index 6003c2e533a0..f67efbaba17f 100644 --- a/arch/powerpc/include/asm/firmware.h +++ b/arch/powerpc/include/asm/firmware.h @@ -132,6 +132,12 @@ extern int ibm_nmi_interlock_token; extern unsigned int __start___fw_ftr_fixup, __stop___fw_ftr_fixup; +#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST) +bool is_kvm_guest(void); +#else +static inline bool is_kvm_guest(void) { return false; } +#endif + #ifdef CONFIG_PPC_PSERIES void pseries_probe_fw_features(void); #else diff --git a/arch/powerpc/include/asm/kvm_para.h b/arch/powerpc/include/asm/kvm_para.h index 9c1f6b4b9bbf..744612054c94 100644 --- a/arch/powerpc/include/asm/kvm_para.h +++ b/arch/powerpc/include/asm/kvm_para.h @@ -8,35 +8,15 @@ #ifndef __POWERPC_KVM_PARA_H__ #define __POWERPC_KVM_PARA_H__ -#include - -#ifdef CONFIG_KVM_GUEST - -#include - -static inline int kvm_para_available(void) -{ - struct device_node *hyper_node; - - hyper_node = of_find_node_by_path("/hypervisor"); - if (!hyper_node) - return 0; +#include - if (!of_device_is_compatible(hyper_node, "linux,kvm")) - return 0; - - return 1; -} - -#else +#include static inline int kvm_para_available(void) { - return 0; + return IS_ENABLED(CONFIG_KVM_GUEST) && is_kvm_guest(); } -#endif - static inline unsigned int kvm_arch_para_features(void) { unsigned long r; diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 244542ae2a91..852164439dcb 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -45,11 +45,10 @@ obj-y := cputable.o syscalls.o \ signal.o sysfs.o cacheinfo.o time.o \ prom.o traps.o setup-common.o \ udbg.o misc.o io.o misc_$(BITS).o \ - of_platform.o prom_parse.o + of_platform.o prom_parse.o firmware.o obj-y += ptrace/ obj-$(CONFIG_PPC64) += setup_64.o \ - paca.o nvram_64.o firmware.o note.o \ - syscall_64.o + paca.o nvram_64.o note.o syscall_64.o obj-$(CONFIG_COMPAT) += sys_ppc32.o signal_32.o obj-$(CONFIG_VDSO32) += vdso32/ obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o diff --git a/arch/powerpc/kernel/firmware.c b/arch/powerpc/kernel/firmware.c index cc4a5e3f51f1..fe48d319d490 100644 --- a/arch/powerpc/kernel/firmware.c +++ b/arch/powerpc/kernel/firmware.c @@ -11,8 +11,27 @@ #include #include +#include #include +#ifdef CONFIG_PPC64 unsigned long powerpc_firmware_features __read_mostly; EXPORT_SYMBOL_GPL(powerpc_firmware_features); +#endif + +#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST) +bool is_kvm_guest(void) +{ + struct device_node *hyper_node; + + hyper_node = of_find_node_by_path("/hypervisor"); + if (!hyper_node) + return 0; + + if (!of_device_is_compatible(hyper_node, "linux,kvm")) + return 0; + + return 1; +} +#endif diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c index 67e6ad5076ce..7af0003b40b6 100644 --- a/arch/powerpc/platforms/pseries/smp.c +++ b/arch/powerpc/platforms/pseries/smp.c @@ -236,24 +236,32 @@ static __init void pSeries_smp_probe(void) if (!cpu_has_feature(CPU_FTR_SMT)) return; - /* - * KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp faults - * to the hypervisor which then reads the instruction from guest - * memory. This can't be done if the guest is secure, so don't use - * doorbells in secure guests. - * - * Under PowerVM, FSCR[MSGP] is enabled so doorbells could be used - * by secure guests if we distinguished this from KVM. - */ - if (is_secure_guest()) - return; + if (is_kvm_guest()) { + /* + * KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp + * faults to the hypervisor which then reads the instruction + * from guest memory, which tends to be slower than using XIVE. + */ + if (xive_enabled()) + return; + + /* + * XICS hcalls aren't as fast, so we can use msgsndp (which + * also helps exercise KVM emulation), however KVM can't + * emulate secure guests because it can't read the instruction + * out of their memory. + */ + if (is_secure_guest()) + return; + } /* - * The guest can use doobells for SMT sibling IPIs, which stay in - * the core rather than going to the interrupt controller. This - * tends to be slower under KVM where doorbells are emulated, but - * faster for PowerVM where they're enabled. + * Under PowerVM, FSCR[MSGP] is enabled as guest vCPU siblings are + * gang scheduled on the same physical core, so doorbells are always + * faster than the interrupt controller, and they can be used by + * secure guests. */ + ic_cause_ipi = smp_ops->cause_ipi; smp_ops->cause_ipi = dbell_or_ic_cause_ipi; }