From patchwork Thu Nov 4 12:54:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1550906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Zyv4+Ci0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HlNtK3whbz9s0r for ; Thu, 4 Nov 2021 23:56:09 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1micHd-0005Aq-CV; Thu, 04 Nov 2021 12:55:57 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1micH5-0004Tw-ST for kernel-team@lists.ubuntu.com; Thu, 04 Nov 2021 12:55:23 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id B2E613F1F5 for ; Thu, 4 Nov 2021 12:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1636030522; bh=kTnMDT4l1EAiyFcsSCwOeX0nCOSQYNblX/u9RkOBkZ4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zyv4+Ci068YIbpTZDehcIlRWhjuLKBu+FAjiKqg/SpqmkO/UOZE8DTQJ3N69JICVP k6xDGUlZcOBrFia+jnpyFljxmZH+HDgGByuIREJbG7evQtAI23aPbeS3l62PUOTE9R azKplRk8J+f8Cnycm2AbxcmC22C5rmybk2VAPJKu9Rq3vdWh1iJ8H2PSNi28JtDl7s aotK/batJcFWOEtpX5Zyw59DmZQVYm6KmrP1tf64tYRtt/jFSG+JCcugjExsWbw4QU x2YjbgnIPoU+2JltqS/aM25d8+dmjFodvMNIqzFk3wpI9MyNtVaTHUiq3u4qwK7dvY agOSCuITdoPyQ== Received: by mail-pf1-f197.google.com with SMTP id 134-20020a62198c000000b0047bf0981003so3757085pfz.4 for ; Thu, 04 Nov 2021 05:55:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kTnMDT4l1EAiyFcsSCwOeX0nCOSQYNblX/u9RkOBkZ4=; b=CA09xJZM5XP261iDXd24eMfVt6G7T+CsJyMIDTY0guPBC78S2UfLbFky09zPFI5RZn BWJY9q4Fc35mc/FiEZ+TzKm+d42V4EH8SCXwbgAARJMRO7xtE/267PGk0tbk/O5JFtvy bxPTFQTlPR+3GLXiKKamBYeoohDpbnyGVm3GX9ZgwngI4gnnIkdACW3tMxhu6ADWfr0d xgV+BAGh9zWiSmWKQEdtT3ZpovaA6N5tnc4+kVO0HpL7khxTS6MVQsKP901cAP4HexxK MeqEgqxuN/e6YEsAyroyGcisN4Ofx2e487yFqWhhvDdKIo4G0jQJA7R3RbtMNAMfR3Ow cjUQ== X-Gm-Message-State: AOAM5311E4rCk67e79MXN80cqkCqXKIpweA215PWJD9ij5wYKf39RM2a MPE4m8mP3CsrFcPltogbMuVT+p5wBmLpI78/GWhhH0g7JwxWhQfROQBUlZfNPaetqvnQIoFO8l4 U/j2p9N1j9Q1stElJDfEvCZopeh2mgCwqbStImBNraA== X-Received: by 2002:a63:8143:: with SMTP id t64mr12287322pgd.43.1636030520926; Thu, 04 Nov 2021 05:55:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI+zZSvhjZVQHZi//gNYBWxZgulAB8ImJb6WBgweT2AZr88O1qXTJJZEvOwihONE2cRyXu/A== X-Received: by 2002:a63:8143:: with SMTP id t64mr12287309pgd.43.1636030520670; Thu, 04 Nov 2021 05:55:20 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id y4sm5283859pfi.178.2021.11.04.05.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 05:55:20 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 12/41] clocksource/drivers/hyper-v: Set clocksource rating based on Hyper-V feature Date: Thu, 4 Nov 2021 06:54:20 -0600 Message-Id: <20211104125449.16540-13-tim.gardner@canonical.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211104125449.16540-1-tim.gardner@canonical.com> References: <20211104125449.16540-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Michael Kelley BugLink: https://bugs.launchpad.net/bugs/1949770 On x86/x64, the TSC clocksource is available in a Hyper-V VM only if Hyper-V provides the TSC_INVARIANT flag. The rating on the Hyper-V Reference TSC page clocksource is currently set so that it will not override the TSC clocksource in this case. Alternatively, if the TSC clocksource is not available, then the Hyper-V clocksource is used. But on ARM64, the Hyper-V Reference TSC page clocksource should override the ARM arch counter, since the Hyper-V clocksource provides scaling and offsetting during live migrations that is not provided for the ARM arch counter. To get the needed behavior for both x86/x64 and ARM64, tweak the logic by defaulting the Hyper-V Reference TSC page clocksource rating to a large value that will always override. If the Hyper-V TSC_INVARIANT flag is set, then reduce the rating so that it will not override the TSC. While the logic for getting there is slightly different, the net result in the normal cases is no functional change. Signed-off-by: Michael Kelley Acked-by: Daniel Lezcano Link: https://lore.kernel.org/r/1614721102-2241-10-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu (cherry picked from commit 4c78738ead4e195c7032c31fe56135c1b00e1784) Signed-off-by: Marcelo Henrique Cerri --- drivers/clocksource/hyperv_timer.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 10eb5c645141..7a9030ca68c4 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -302,14 +302,6 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup); * the other that uses the TSC reference page feature as defined in the * TLFS. The MSR version is for compatibility with old versions of * Hyper-V and 32-bit x86. The TSC reference page version is preferred. - * - * The Hyper-V clocksource ratings of 250 are chosen to be below the - * TSC clocksource rating of 300. In configurations where Hyper-V offers - * an InvariantTSC, the TSC is not marked "unstable", so the TSC clocksource - * is available and preferred. With the higher rating, it will be the - * default. On older hardware and Hyper-V versions, the TSC is marked - * "unstable", so no TSC clocksource is created and the selected Hyper-V - * clocksource will be the default. */ u64 (*hv_read_reference_counter)(void); @@ -380,7 +372,7 @@ static int hv_cs_enable(struct clocksource *cs) static struct clocksource hyperv_cs_tsc = { .name = "hyperv_clocksource_tsc_page", - .rating = 250, + .rating = 500, .read = read_hv_clock_tsc_cs, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, @@ -417,7 +409,7 @@ static u64 notrace read_hv_sched_clock_msr(void) static struct clocksource hyperv_cs_msr = { .name = "hyperv_clocksource_msr", - .rating = 250, + .rating = 500, .read = read_hv_clock_msr_cs, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, @@ -458,6 +450,17 @@ static bool __init hv_init_tsc_clocksource(void) if (hv_root_partition) return false; + /* + * If Hyper-V offers TSC_INVARIANT, then the virtualized TSC correctly + * handles frequency and offset changes due to live migration, + * pause/resume, and other VM management operations. So lower the + * Hyper-V Reference TSC rating, causing the generic TSC to be used. + * TSC_INVARIANT is not offered on ARM64, so the Hyper-V Reference + * TSC will be preferred over the virtualized ARM64 arch counter. + */ + if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) + hyperv_cs_tsc.rating = 250; + hv_read_reference_counter = read_hv_clock_tsc; phys_addr = virt_to_phys(hv_get_tsc_page());