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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 0E208C4320A for ; Wed, 28 Jul 2021 07:38:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECAC060F23 for ; Wed, 28 Jul 2021 07:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235011AbhG1HiS (ORCPT ); Wed, 28 Jul 2021 03:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234976AbhG1HiQ (ORCPT ); Wed, 28 Jul 2021 03:38:16 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7C3AC061760 for ; Wed, 28 Jul 2021 00:38:13 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id v16-20020a0562140510b029032511e85975so1425187qvw.23 for ; Wed, 28 Jul 2021 00:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=asLoTJNqDsfECIu06kGnrrPYYB9PZTwQlOwbk5q3NAY=; b=qukG12Z/5Nrd4x0xu8iYn5S/7pdbbT9yVlD/dAdygZX9/E3KtDj1aTiTrta9NVNUQ1 E+Op3DmX9UhPs9Gil54NdVZwtGzEz36g5x1l6vva1RSX5V6jrOmKITvwF/+PIfeCTHZ2 5tZJS/ss5EflJYoLz8ZzxBDDAeW2YxAyT+R+vpchq3RJtcTWK23D3SL+4+D4jrDQNCbD eGz+Vi6+dqBeI1HBbLb3doTUY1XKMpxDES4PMJ8xi3GeoHBkGrYwL89RlPuts9xTM1ee gMiaeB3PukYt+hbONAJ5GzkJJXZzUlTR+4CDgZlultHHbNNxSwAqqSH/AmMf7dauH4xk uzcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=asLoTJNqDsfECIu06kGnrrPYYB9PZTwQlOwbk5q3NAY=; b=HWLu0UUkcesvNrmHtwOLVyEmSbrjsW3oyr6LF7hgLegZRVZ4lc0nbqHuSyJmkiZTSZ bGYQtvKROy3FVrVivKITiQNjmnfRpgat6qgJE7VYOs0b/d5n7I7mryjUZISd6W7Tqkou 81pLiXac5HzMB3rInTtjW39Vl77BFQBqAgHkFAD+cCAVxGTdz2vFOdgEQ21AO0wSPP1s gcOYYLyaomDgEty+W/n6G+Eo65lTHmoEWrrt48l2GDejiSQVYy4iKnDVduc0E693t4EI 1RzyDqcL7PKdaNkRH+4grNasaOHcwrVrYJRKc64K9Oy2TJ+O9Sow2kOP/6GdYOaIpgky f/FQ== X-Gm-Message-State: AOAM530nYoSZ1rOi7zx1rbApwmy3BNXPbvPHgc+RcBDsSitCoqhi16nz ibeIarisg3JX3ipNQvsHIQWl1R+MPZYWag== X-Google-Smtp-Source: ABdhPJx5VvLxvtRUc/taUqbearHx8itI0n4tywtAKoa5QJvM9uPJ919xyloKTTne7y5kiE3u02U5EN/OEdmD2Q== X-Received: from suleiman1.tok.corp.google.com ([2401:fa00:8f:203:44f4:48a1:aec5:6e5b]) (user=suleiman job=sendgmr) by 2002:a05:6214:9d2:: with SMTP id dp18mr2657261qvb.46.1627457893101; Wed, 28 Jul 2021 00:38:13 -0700 (PDT) Date: Wed, 28 Jul 2021 16:37:00 +0900 In-Reply-To: <20210728073700.120449-1-suleiman@google.com> Message-Id: <20210728073700.120449-3-suleiman@google.com> Mime-Version: 1.0 References: <20210728073700.120449-1-suleiman@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [RFC PATCH 2/2] kvm,x86: Report preempt_count to host. From: Suleiman Souhlal To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Cc: ssouhlal@FreeBSD.org, joelaf@google.com, senozhatsky@chromium.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Suleiman Souhlal Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When KVM_PREEMPT_COUNT_REPORTING is enabled, the host can use preempt_count to determine if the guest is in a critical section, if it also has CONFIG_KVM_HETEROGENEOUS_RT enabled, in order to use heterogeneous RT VCPU configurations. Signed-off-by: Suleiman Souhlal --- arch/x86/Kconfig | 11 +++++++++++ arch/x86/kernel/kvm.c | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 49270655e827..d8b62789df57 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -846,6 +846,17 @@ config PARAVIRT_TIME_ACCOUNTING config PARAVIRT_CLOCK bool +config KVM_PREEMPT_COUNT_REPORTING + bool "KVM preempt_count reporting to the host" + depends on KVM_GUEST && PREEMPT_COUNT + default n + help + Select this option to enable KVM preempt_count reporting to the host, + which can be useful in cases where some VCPUs are RT and the rest + aren't. + + If in doubt, say N here. + config JAILHOUSE_GUEST bool "Jailhouse non-root cell support" depends on X86_64 && PCI diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index a26643dc6bd6..7ec53ea3f979 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -363,6 +363,16 @@ static void kvm_guest_cpu_init(void) if (has_steal_clock) kvm_register_steal_time(); + +#ifdef CONFIG_KVM_PREEMPT_COUNT_REPORTING + if (kvm_para_has_feature(KVM_FEATURE_PREEMPT_COUNT)) { + unsigned long pa; + + pa = slow_virt_to_phys(this_cpu_ptr(&__preempt_count)) | + KVM_MSR_ENABLED; + wrmsrl(MSR_KVM_PREEMPT_COUNT, pa); + } +#endif } static void kvm_pv_disable_apf(void) -- 2.32.0.432.gabb21c7263-goog