From mboxrd@z Thu Jan 1 00:00:00 1970 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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 D9CF1C433E7 for ; Mon, 19 Oct 2020 17:19:42 +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 F343421741 for ; Mon, 19 Oct 2020 17:19:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XzfBQVFl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F343421741 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUYou-0003ed-R5 for qemu-devel@archiver.kernel.org; Mon, 19 Oct 2020 13:19:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUYm1-00012v-Tp for qemu-devel@nongnu.org; Mon, 19 Oct 2020 13:16:41 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:34237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kUYlx-0003J8-Mp for qemu-devel@nongnu.org; Mon, 19 Oct 2020 13:16:41 -0400 Received: by mail-ed1-x542.google.com with SMTP id x1so127500eds.1 for ; Mon, 19 Oct 2020 10:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VccOzqRTahoJBssQpE8H5vS+Wi/1LUL9l2I4wA3LzOg=; b=XzfBQVFl7UgGVSnL4bYO3O8cs5Z8/S4r4EExVGnDEMIsYtxUTQKUZlPJ9JUvv7HHhJ 4ypeIMXcuT00rW8sZVN32/rShweimSHUA31nwCEOzTRSgIgHt/7YxI3gUpPjnUNiC1Ou 0IsKY0HoNhoHXRrB8qvVXb3hJwuHcVhwE+qLVF/LFxYjUVnoIuwdg3R/S9CTZKfuLgri fPfAsO3GQn5QzSJ8iJRo4G6Hq/hhkQRVTvMi2yc+M8PP9tpTtFS1bKEnBLBNIENTBxNN SxnBB0KuLzNR9pmz9VjZdPWSVfa6PpflQ0QNDn9Vu1/dchvDMLebJJM+Uh6c4zpxLYA+ 7koA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VccOzqRTahoJBssQpE8H5vS+Wi/1LUL9l2I4wA3LzOg=; b=Y0DtEOI5uFkPF/75XcADLE6QilW/+mgusfkCyCou/dvZO9tF3QjGVtJUMX3z68SaLN oFpJEqc7LUZwZ55UjUgMebXTjRdIKUBxSA7NMuXiGqW+8n2Dfyspl/9RUM3BGYAKikTh dFqFTRfuzKJi7nnkpVB+NpK6cX9a3VhLsX2RKXhYSNpIKE9cGzwdWFhB+YQlFDjIpGM9 FRIIsgd49zBZgWJBmpUjCGa9XCI038b17wFgWSXbhJDjMDa9CJUdA0R6slIZJp4yn+R4 MG51prfxEaJHwJ0MJBKZmOg3eF/LMfIbpAZIi9BDT5IfAMsETo9AiD5sqFAWjaSAfFi0 lFXQ== X-Gm-Message-State: AOAM531wjB+Lf4K7sjMxZBsTl2Jm5LmZgxXsIT8WtwtUtrCOYTMc4Wo9 1WLCuvoQVQSttAZiQIlSDuFkMUr8JM/VfTQZIigxuK6li04= X-Google-Smtp-Source: ABdhPJxYStgkTjIoOcaQJ1mzJb+lL/modMLUlgmNMB+bwiRn8tp3xQwchX11uSi6WWsWSklnEUtodBtSA4uf7eGMNfQ= X-Received: by 2002:a50:9548:: with SMTP id v8mr810826eda.115.1603127794312; Mon, 19 Oct 2020 10:16:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Owen Anderson Date: Mon, 19 Oct 2020 10:16:23 -0700 Message-ID: Subject: Re: [RFC] Don't lookup full CPU state in the indirect branch fast path on AArch64 when running in user mode. To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , rth@twiddle.net Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::542; envelope-from=oanderso@google.com; helo=mail-ed1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -175 X-Spam_score: -17.6 X-Spam_bar: ----------------- X-Spam_report: (-17.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Ping On Mon, Oct 12, 2020 at 1:52 PM Owen Anderson wrote: > > Ping. > > I'd like to get feedback on how/whether this could be developed into a > landable version. > > Thanks, > > --Owen > > On Tue, Sep 29, 2020 at 2:32 PM Owen Anderson wrote: > > > > Hello, > > > > I would like to request feedback on the following patch, which I do > > not believe should be applied to master as-is. The idea here is to > > avoid gathering the full CPU state in the fast path of an indirect > > branch lookup when running in user mode on a platform where the flags > > can only be changed in privileged mode. I believe this is true on the > > AArch64 scenario that I care about, but clearly not true in general. > > I'm particularly seeking feedback on how to clean this up into a > > version that checks the correct necessary and sufficient conditions to > > allow all users that can benefit from it to do so. > > > > On the workload that I am targeting (aarch64 on x86), this patch > > reduces execution wall time by approximately 20%, and eliminates > > indirect branch lookups from the hot stack traces entirely. > > > > Thank you, > > > > --Owen > > > > From 3d96db17d3baacb92ef1bc5e70ef06b97d06a0ae Mon Sep 17 00:00:00 2001 > > From: Owen Anderson > > Date: Tue, 29 Sep 2020 13:47:00 -0700 > > Subject: [RFC] Don't lookup full CPU state in the indirect branch fast path on > > AArch64 when running in user mode. > > > > Most of the CPU state can't be changed in user mode, so this is useless work. > > > > Signed-off-by: Owen Anderson > > --- > > include/exec/tb-lookup.h | 15 +++++++++++++++ > > 1 file changed, 15 insertions(+) > > > > diff --git a/include/exec/tb-lookup.h b/include/exec/tb-lookup.h > > index 9cf475bb03..f4ea0eb4c0 100644 > > --- a/include/exec/tb-lookup.h > > +++ b/include/exec/tb-lookup.h > > @@ -25,7 +25,15 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong > > *pc, target_ulong *cs_base, > > TranslationBlock *tb; > > uint32_t hash; > > > > +#if !defined(TARGET_ARM) || !defined(CONFIG_USER_ONLY) > > cpu_get_tb_cpu_state(env, pc, cs_base, flags); > > +#else > > + if (is_a64(env)) { > > + *pc = env->pc; > > + } else { > > + *pc = env->regs[15]; > > + } > > +#endif > > hash = tb_jmp_cache_hash_func(*pc); > > tb = qatomic_rcu_read(&cpu->tb_jmp_cache[hash]); > > > > @@ -34,12 +42,19 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong > > *pc, target_ulong *cs_base, > > > > if (likely(tb && > > tb->pc == *pc && > > +#if !defined(TARGET_ARM) || !defined(CONFIG_USER_ONLY) > > tb->cs_base == *cs_base && > > tb->flags == *flags && > > +#endif > > tb->trace_vcpu_dstate == *cpu->trace_dstate && > > (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) == cf_mask)) { > > return tb; > > } > > + > > +#ifdef CONFIG_USER_ONLY > > + cpu_get_tb_cpu_state(env, pc, cs_base, flags); > > +#endif > > + > > tb = tb_htable_lookup(cpu, *pc, *cs_base, *flags, cf_mask); > > if (tb == NULL) { > > return NULL; > > -- > > 2.28.0.709.gb0816b6eb0-goog -- --Owen