Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5016583pxv; Wed, 28 Jul 2021 00:40:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXBclSyJ0p0SW55LnpINFTxOdfyoegyE8EfOqKiombuYHs6Q3+9pgt3Iq3Y8ubUahRcrCm X-Received: by 2002:a05:6402:517c:: with SMTP id d28mr33020472ede.299.1627458021197; Wed, 28 Jul 2021 00:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627458021; cv=none; d=google.com; s=arc-20160816; b=EuT9cyJ1ARKZJ0yAJT+I8zqN5nxpXh+ekwbNCMScfORwU9R3T2qNH2nGswpHkg74p7 sHvO7U02p6qYYAK/IAxstoSt/laJQlxvFn9cALnDvMYavrdasVn9+uKlj/0Sh//EjAZz dcGJld1lCi0mx46rd1BO0Lv79L5UT9iam3UZYE8yMRf/FjLIGGsg1/LARaZz9XiRHHRg fPO2OkzERRUlP+ODXXATjBLJQyUpdBNgVMviRmLiJeewpqqdrWUdXeeqHfS/97u4+ybj +TZL7S3hWCfR7cS2R3y+1w9eNLqnfzZ7Des1h2eqZXbILbAK1LhNk/WHuWQMbKWzCgbx ggHQ== 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:dkim-signature; bh=asLoTJNqDsfECIu06kGnrrPYYB9PZTwQlOwbk5q3NAY=; b=XB2VlYlAvQpQr6Ftytio6QiWDshx8gOhI0N/X58jyAnUSbYSj4kxSibZQmkM8eWE27 epeKgqOJg6rJTYzEhMxZZvN3KJSgADcUj7DjE84DrB/16DGXAiz3AnoNH7BKDlTRt3uY Bsa9pNbrrCLg35dflg6RmAt7iDVTEgsk/jj9SIet3un2koMDhO4ie6ic3F80I9RChGQ6 5Nu5CsHGeI9SSPr0FT/KJHSAOOUOIo9SS6kXAJNI2h25L5zZbUxjwUXziXkesWn08lk3 kLtTTtEeGZEV3Mwr+71PQDcW13QJbnhr7og1TXh2x39brgDDjABUjoC590EUGDaQozWX SAaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="qukG12Z/"; 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 n14si2124097edv.569.2021.07.28.00.39.58; Wed, 28 Jul 2021 00:40:21 -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="qukG12Z/"; 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 S235001AbhG1HiR (ORCPT + 99 others); Wed, 28 Jul 2021 03:38:17 -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-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