Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1142257pxb; Thu, 15 Apr 2021 15:24:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEiy9mWUR5WehHMiuY5Am3MFq/Pe/siZSMLId8CGw9LBggFujZaVqwDc7sLhT8JLqGGh33 X-Received: by 2002:a17:902:be10:b029:e9:78a0:dd33 with SMTP id r16-20020a170902be10b02900e978a0dd33mr6155298pls.1.1618525490312; Thu, 15 Apr 2021 15:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618525490; cv=none; d=google.com; s=arc-20160816; b=qJQ9loUTBStT8vto9rs8gn7NLVAoeSQWFJVjqQU8Hcz6onl1KmU4RhDhDzG2krzUFm URp7Ufoi5WOEuJHUdWDfYGjVecqR6GpLGulFgu5bYgt7omGHqyfNz1u1YuUoOfnI4KtU gozc0EfVRk8fnAI9VIJimoj860sfDk3qOjixZxvMb0FbzdRedLvSSaDYCSKh5kvJOpaj gu2jqDy/M9LcP4OC8H5V/Q6ocTxjiMQI3zimAOC+UDnEBQH9PY6y8v3e0VCUGjEqqqEy bT8MzfA1O9LM802twa72P2h+d2U/9OlN8yR9SdO0Brozh0fMu2hSDWLPyiq/9RIPMZHt WYIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=5bZDkTOmF30k3ylXE7mjWEUF6Se+XKGXeTtOG326tls=; b=CkF4eXLqbEkr5K9B0dDJQAKXPMFOMx6QRKuTelAX/GFpAfLpI4A2T4AdAx9Sc7vodx lX2ZK2deEG3m6jOO6MlmRo6BNPOLmrc6lfu5zZZD0hMPF9rM/cCWz8r9ZPwM2uQFYNOA UTPk+dXEuSuYFe7LKlEKmfu2ZQzcSADCfd/DkU44uywMYfwzzMMiCJ3wiuJ+O1xzkzl2 srQx791y3JODS3PGSExmUa8XvbsHEd4HCsRv+DxClWOYyam/eRBrQXVoM0L7SlRKTVYe bs7IT0lX7TcHczwEIEVyOE8dN8WCoC40l4Rq0ZP+vrvzbGeip+naKjBJK/hAjfSxsjMx z4SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="u8/EHms+"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si4420294plm.175.2021.04.15.15.24.38; Thu, 15 Apr 2021 15:24:50 -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=@google.com header.s=20161025 header.b="u8/EHms+"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237465AbhDOWWQ (ORCPT + 99 others); Thu, 15 Apr 2021 18:22:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237401AbhDOWWA (ORCPT ); Thu, 15 Apr 2021 18:22:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5E0EC061763 for ; Thu, 15 Apr 2021 15:21:34 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v2so3937482ybc.17 for ; Thu, 15 Apr 2021 15:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=5bZDkTOmF30k3ylXE7mjWEUF6Se+XKGXeTtOG326tls=; b=u8/EHms+P5QHbtTJ6SsWhwk29xFysKHQdf/9xINwhk2Wxp21WIFSsVeUCy33wKtjFy lUmj0nJPEi1n3Oh0A/Bgumm6PBfeRQ6rZ6U/hC52JnbgBrzx6Jwpq61xXK+tFBYn07IA kAc09ehAkcpVLpAu8SPSKStvPEd9Ubx9twCwkgnSJZd30C8OLAntIF86x0Zdvht71NN5 s84XV5pqBHrcqFv2Av1nDsm/Dn5rp/O/+/cSldZguahj7hUC9TWg1fG2Nd5xxJ9MgVCK hmjkzhRlEIteP178WSGuZ8PcLY0tZW6hKtnGHn1ErP7Lmb892CbNGFt4X8R+qosWioiv 3SSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=5bZDkTOmF30k3ylXE7mjWEUF6Se+XKGXeTtOG326tls=; b=MDgrBykJziuHqBttvssIOAO4lBsRJlV2cl1LLXT56o/sHyK0I9Fb1iTO++a/kzpA/n tN1vQbAyRPOJlK7FC8MiTJa1AxL7S6smyT5gPdvwjLt7HMylHFbHKJYKOB/YLiKjPEGl ISIBuKSw7xUpcrVrlFWHu1mrWOrbOKWEX6ajUoJn1iZq1jLrgHmLCxgZIstZx5KEbu+s 3Gmb8J2Ab1VF5tZvZF/Lm2I7zjuofu8utp5/p/jzeO9DwqJ32m+RtJP4UQh1+Md2GACS v8Mlu08kELf/b2fLMp1DIGdYl7MpGCV9IYFG789gSlV/oiLrqrQDsKVw3QngFm5z5+Ri HTTg== X-Gm-Message-State: AOAM5333Jo34hQSQKBpBmglWKUWOLRM1emQStIR6DezgF4utUxXpFy0T WvuykB7y5MFw6Orbwz02oj8pLvrJlig= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:6c93:ada0:6bbf:e7db]) (user=seanjc job=sendgmr) by 2002:a25:f80e:: with SMTP id u14mr7738720ybd.428.1618525294052; Thu, 15 Apr 2021 15:21:34 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 15 Apr 2021 15:21:06 -0700 In-Reply-To: <20210415222106.1643837-1-seanjc@google.com> Message-Id: <20210415222106.1643837-10-seanjc@google.com> Mime-Version: 1.0 References: <20210415222106.1643837-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v3 9/9] KVM: Move instrumentation-safe annotations for enter/exit to x86 code From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Michael Tokarev , Christian Borntraeger Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drop the instrumentation_{begin,end}() annonations from the common KVM guest enter/exit helpers, and massage the x86 code as needed to preserve the necessary annotations. x86 is the only architecture whose transition flow is tagged as noinstr, and more specifically, it is the only architecture for which instrumentation_{begin,end}() can be non-empty. No other architecture supports CONFIG_STACK_VALIDATION=y, and s390 is the only other architecture that support CONFIG_DEBUG_ENTRY=y. For instrumentation annontations to be meaningful, both aformentioned configs must be enabled. Letting x86 deal with the annotations avoids unnecessary nops by squashing back-to-back instrumention-safe sequences. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.h | 4 ++-- include/linux/kvm_host.h | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 285953e81777..b17857ac540b 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -25,9 +25,9 @@ static __always_inline void kvm_guest_enter_irqoff(void) instrumentation_begin(); trace_hardirqs_on_prepare(); lockdep_hardirqs_on_prepare(CALLER_ADDR0); - instrumentation_end(); - guest_enter_irqoff(); + instrumentation_end(); + lockdep_hardirqs_on(CALLER_ADDR0); } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 444d5f0225cb..e5eb64019f47 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -339,9 +339,7 @@ static __always_inline void guest_enter_irqoff(void) * This is running in ioctl context so its safe to assume that it's the * stime pending cputime to flush. */ - instrumentation_begin(); vtime_account_guest_enter(); - instrumentation_end(); /* * KVM does not hold any references to rcu protected data when it @@ -351,21 +349,16 @@ static __always_inline void guest_enter_irqoff(void) * one time slice). Lets treat guest mode as quiescent state, just like * we do with user-mode execution. */ - if (!context_tracking_guest_enter_irqoff()) { - instrumentation_begin(); + if (!context_tracking_guest_enter_irqoff()) rcu_virt_note_context_switch(smp_processor_id()); - instrumentation_end(); - } } static __always_inline void guest_exit_irqoff(void) { context_tracking_guest_exit_irqoff(); - instrumentation_begin(); /* Flush the guest cputime we spent on the guest */ vtime_account_guest_exit(); - instrumentation_end(); } static inline void guest_exit(void) -- 2.31.1.368.gbe11c130af-goog