Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01595C33C9E for ; Thu, 30 Jan 2020 08:10:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AF959206F0 for ; Thu, 30 Jan 2020 08:10:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="L7Zk41Fj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF959206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix4u5-0007zv-VD for qemu-devel@archiver.kernel.org; Thu, 30 Jan 2020 03:10:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52228) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix4tH-0007AN-8f for qemu-devel@nongnu.org; Thu, 30 Jan 2020 03:09:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix4tE-0004iQ-Tb for qemu-devel@nongnu.org; Thu, 30 Jan 2020 03:09:30 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:42745 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix4tE-0004hx-Q5 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 03:09:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580371768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=bfVIdWy0t6kqeapVNDNqNUop2EHFowr0MydCfhy4QmU=; b=L7Zk41FjZNQZxXvj3sf8T02v8CogtrpZ9WQHEdpMMUfFEJrcbNnt4Fu1QAf+I/fg/suETv A9kn6RHBNvCVClW83O43uVNI/FVkn5Gm2urS+ryjttdtpMCWo0xA0JrE4tQb2Msvf1Znqk XB/XmmpmP9Z9iCSGIAy/69RPkDXucNQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-_6WMvPrSNZWcvav0fLEM2A-1; Thu, 30 Jan 2020 03:09:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A385C800D48; Thu, 30 Jan 2020 08:09:22 +0000 (UTC) Received: from [10.36.116.229] (ovpn-116-229.ams2.redhat.com [10.36.116.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91C0619488; Thu, 30 Jan 2020 08:09:18 +0000 (UTC) Subject: Re: [PATCH] spapr: Enable DD2.3 accelerated count cache flush in pseries-5.0 machine To: David Gibson , mpe@ellerman.id.au, groug@kaod.org, clg@kaod.org References: <20200130012622.8564-1-david@gibson.dropbear.id.au> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; prefer-encrypt=mutual; keydata= mQINBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWdj75cDNQx UZ9XXbXEKY9MHX83Uy7JFoiFDMOVHn55HnncflUncO0zDzY7CxFeQFwYRbsCXOUL9yBtqLer Ky8/yjBskIlNrp0uQSt9LMoMsdSjYLYhvk1StsNPg74+s4u0Q6z45+l8RAsgLw5OLtTa+ePM JyS7OIGNYxAX6eZk1+91a6tnqfyPcMbduxyBaYXn94HUG162BeuyBkbNoIDkB7pCByed1A7q q9/FbuTDwgVGVLYthYSfTtN0Y60OgNkWCMtFwKxRaXt1WFA5ceqinN/XkgA+vf2Ch72zBkJL RBIhfOPFv5f2Hkkj0MvsUXpOWaOjatiu0fpPo6Hw14UEpywke1zN4NKubApQOlNKZZC4hu6/ 8pv2t4HRi7s0K88jQYBRPObjrN5+owtI51xMaYzvPitHQ2053LmgsOdN9EKOqZeHAYG2SmRW LOxYWKX14YkZI5j/TXfKlTpwSMvXho+efN4kgFvFmP6WT+tPnwARAQABtCNMYXVyZW50IFZp dmllciA8bHZpdmllckByZWRoYXQuY29tPokCOAQTAQIAIgUCVgVQgAIbAwYLCQgHAwIGFQgC CQoLBBYCAwECHgECF4AACgkQ8ww4vT8vvjwpgg//fSGy0Rs/t8cPFuzoY1cex4limJQfReLr SJXCANg9NOWy/bFK5wunj+h/RCFxIFhZcyXveurkBwYikDPUrBoBRoOJY/BHK0iZo7/WQkur 6H5losVZtrotmKOGnP/lJYZ3H6OWvXzdz8LL5hb3TvGOP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nTBFmxN5FFtIWlEuY8+YMiWRykd8Ln9RJ/98/ghABHz9TN8TRo2b 6WimV64FmlVn17Ri6FgFU3xNt9TTEChqAcNg88eYryKsYpFwegGpwUlaUaaGh1m9OrTzcQy+ klVfZWaVJ9Nw0keoGRGb8j4XjVpL8+2xOhXKrM1fzzb8JtAuSbuzZSQPDwQEI5CKKxp7zf76 J21YeRrEW4WDznPyVcDTa+tz++q2S/BpP4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjX EYRWdiCxN7ca5iPml5gLtuvhJMSy36glU6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2Tx L8enfx40PrfbDtWwqRID3WY8jLrjKfTdR3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/ jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPMoDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1 pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyxFCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbL XiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsBkmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZ D+Ofp0T3KOr1RUHvCZoLURfFhSQ= Message-ID: Date: Thu, 30 Jan 2020 09:09:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200130012622.8564-1-david@gibson.dropbear.id.au> Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: _6WMvPrSNZWcvav0fLEM2A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aik@ozlabs.ru, paulus@samba.org, qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 30/01/2020 02:26, David Gibson wrote: > For POWER9 DD2.2 cpus, the best current Spectre v2 indirect branch > mitigation is "count cache disabled", which is configured with: > -machine cap-ibs=fixed-ccd > However, this option isn't available on DD2.3 CPUs with KVM, because they > don't have the count cache disabled. > > For POWER9 DD2.3 cpus, it is "count cache flush with assist", configured > with: > -machine cap-ibs=workaround,cap-ccf-assist=on > However this option isn't available on DD2.2 CPUs with KVM, because they > don't have the special CCF assist instruction this relies on. > > On current machine types, we default to "count cache flush w/o assist", > that is: > -machine cap-ibs=workaround,cap-ccf-assist=off > This runs, with mitigation on both DD2.2 and DD2.3 host cpus, but has a > fairly significant performance impact. > > It turns out we can do better. The special instruction that CCF assist > uses to trigger a count cache flush is a no-op on earlier CPUs, rather than > trapping or causing other badness. It doesn't, of itself, implement the > mitigation, but *if* we have count-cache-disabled, then the count cache > flush is unnecessary, and so using the count cache flush mitigation is > harmless. > > Therefore for the new pseries-5.0 machine type, enable cap-ccf-assist by > default. Along with that, suppress throwing an error if cap-ccf-assist > is selected but KVM doesn't support it, as long as KVM *is* giving us > count-cache-disabled. To allow TCG to work out of the box, even though it > doesn't implement the ccf flush assist, downgrade the error in that case to > a warning. This matches several Spectre mitigations where we allow TCG > to operate for debugging, since we don't really make guarantees about TCG > security properties anyway. > > While we're there, make the TCG warning for this case match that for other > mitigations. > > Signed-off-by: David Gibson > --- > hw/ppc/spapr.c | 5 ++++- > hw/ppc/spapr_caps.c | 26 ++++++++++++++++++++++---- > 2 files changed, 26 insertions(+), 5 deletions(-) > > I have put this into my ppc-for-5.0 tree already, and hope to send a > pull request tomorrow (Jan 31). > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 02cf53fc5b..deaa44f1ab 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -4397,7 +4397,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) > smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 16; /* 64kiB */ > smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV] = SPAPR_CAP_OFF; > smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_ON; > - smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF; > + smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_ON; > spapr_caps_add_properties(smc, &error_abort); > smc->irq = &spapr_irq_dual; > smc->dr_phb_enabled = true; > @@ -4465,8 +4465,11 @@ DEFINE_SPAPR_MACHINE(5_0, "5.0", true); > */ > static void spapr_machine_4_2_class_options(MachineClass *mc) > { > + SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc); > + > spapr_machine_5_0_class_options(mc); > compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len); > + smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF; > } > > DEFINE_SPAPR_MACHINE(4_2, "4.2", false); > diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c > index 481dfd2a27..d0d4b32a40 100644 > --- a/hw/ppc/spapr_caps.c > +++ b/hw/ppc/spapr_caps.c > @@ -482,18 +482,36 @@ static void cap_large_decr_cpu_apply(SpaprMachineState *spapr, > static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, > Error **errp) > { > + Error *local_err = NULL; > uint8_t kvm_val = kvmppc_get_cap_count_cache_flush_assist(); > > if (tcg_enabled() && val) { > - /* TODO - for now only allow broken for TCG */ > - error_setg(errp, > -"Requested count cache flush assist capability level not supported by tcg," > - " try appending -machine cap-ccf-assist=off"); > + /* TCG doesn't implement anything here, but allow with a warning */ > + error_setg(&local_err, > + "TCG doesn't support requested feature, cap-ccf-assist=on"); > } else if (kvm_enabled() && (val > kvm_val)) { > + uint8_t kvm_ibs = kvmppc_get_cap_safe_indirect_branch(); > + > + if (kvm_ibs == SPAPR_CAP_FIXED_CCD) { > + /* > + * If we don't have CCF assist on the host, the assist > + * instruction is a harmless no-op. It won't correctly > + * implement the cache count flush *but* if we have > + * count-cache-disabled in the host, that flush is > + * unnnecessary. So, specifically allow this case. This > + * allows us to have better performance on POWER9 DD2.3, > + * while still working on POWER9 DD2.2 and POWER8 host > + * cpus. > + */ > + return; > + } > error_setg(errp, local_err? ... > "Requested count cache flush assist capability level not supported by kvm," > " try appending -machine cap-ccf-assist=off"); > } > + > + if (local_err != NULL) > + warn_report_err(local_err); ... or why don't you put warn_report_err() in the first part of the "if" as this is the only place where it is used? Thanks, Laurent