Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1270320rda; Mon, 23 Oct 2023 07:41:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVeAFU34+idmVkUaexbPsn71Mq/ktR+8ka0OdQEFrI4vGd9FrJ/Ti4E/rfBrMnMUnnCngE X-Received: by 2002:a05:6a00:24c5:b0:6bf:4cb1:e78 with SMTP id d5-20020a056a0024c500b006bf4cb10e78mr8027073pfv.6.1698072109555; Mon, 23 Oct 2023 07:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698072109; cv=none; d=google.com; s=arc-20160816; b=MyquLfSGiCA4ALKiVGnQEnShyRbafk1g0aFcuxKR60ltirnROBfisLvuKokSVk5IC1 BMbNJ7dfgqMZzu/v9PYf5b25QWl6lSZU3PHz/rHIgzknu95eAb/WlArcCPqG7t3OkAZG gRFw+ZdkU9KxqanRGBugQ5dlGw7IVpdhnyRt4GkrW+zz2gWPfaM6K1Ej9m/KYmJ/xsmr WHMW8IJHWTcZcLZBqftC34cael4pGdN7X/pKeThzKtAPYHAzuKaZMflNYbGR8G2WM31n aqXF4oEubCHug/FoxjX3f7C2AM5eDHhUwwcX9/3oHborYgB4nRb/vnGzkMGs06K9K4ef 29Kg== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=TOIO+H7vBCJRfyqao5vTRDK/ZnUXqp5753SeNzy629c=; fh=PA0Zgye0gHXlK4ZxNnECUg6MLEBoxBIg9EFJqsT0leE=; b=LiHFGvYrsfVN5RGB/OuCJSWjAf2tEFBTYZXrLFvuiF/lTS0M7dw20WBTJA/8HKlDYM OWPgPrGJ2Jl574vVvvi8UxXWRY1aEZPbtMqctSUmbj9MNjWiumDIuJebxwcWHn9WNmFC jZgB97viB5Muffd7/2Rf+pj8EooZEbHCJq49hhZsxYARPHi7MBGSMm5OdhZ+/M6Ubrnw p5FIn8sk+F51HSPklyB7Jk5GI0ZMFjeTONznx/BOkUJnc5bTCN4/FypI5sS4hxjoCAoc Q7EsPnNqJULHdDKz2fwU4pXGmsLXVhUW783oLJI4dAymiz+NytW1Fns0r23gx15c9G/b 0IQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=icPSHz+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id s4-20020aa78bc4000000b006b261e83225si6481476pfd.310.2023.10.23.07.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 07:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=icPSHz+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 618998074513; Mon, 23 Oct 2023 07:41:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbjJWOl3 (ORCPT + 99 others); Mon, 23 Oct 2023 10:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233822AbjJWOlF (ORCPT ); Mon, 23 Oct 2023 10:41:05 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE6A19A3 for ; Mon, 23 Oct 2023 07:40:54 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-56f75e70190so1764782a12.3 for ; Mon, 23 Oct 2023 07:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698072052; x=1698676852; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TOIO+H7vBCJRfyqao5vTRDK/ZnUXqp5753SeNzy629c=; b=icPSHz+UroMs95NxI4XfLTvL65qkzFMyB76dWy3dX7FOfk3GeCmT3+tlFRpq2ALk0B QQ2isgkhaL0kdWIlxrQ/9JzlXpfArq2tQlzMhOYN2KJRc1FfEMc+CthNH5BsZWDRVh70 d0qfTJQv71x5Zpi1ppXjrTMFbqFQ9c+//sDxqh0BNrCVmf1S7REZJ598uQ9/rjXrNCbC HgB4vPsH8F4yB9y2A1E3QiFezAXVyYzyXPtuXY5AwSICpUJfmwG/bsEOLxTcHx7pLv5o DqP8f5onetS06vqym3kjlmotfIesRYyQJp4wrHLIVrDGKept/baSWzMMJxruB0WNe3J6 PhGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698072052; x=1698676852; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TOIO+H7vBCJRfyqao5vTRDK/ZnUXqp5753SeNzy629c=; b=Flldu+ZocTaI1+/qdrR/ertuXpu/zNtli+tK8axfarqXnJM+SJYmHaM3qZfu5Zd8bF h7TbmMzH2cMDFwGHQZQHGedMhsPFn+v55M+NhrAc0H1nc0RGFgpCmeLos7OtckTb70qv mPOxw/x/DT/6vvjeOUBcu3G2v2h6SOyemZ5FR/SAqQX08W3ZNc7+54P2wMQMUuCduZcU y46ZqMCflmn2pepTI7G4nQyGPJq8x2R3CsMlPeW0fky1MtaNt+zvpfQW1VwAjy7CVn9A A1jkRHhex3x/0bpCTEO6jKTpW5rXYIs0G8oZXw1HFWzESaMZPlse2PSbNmTenhKCEpmC gwUQ== X-Gm-Message-State: AOJu0YylD3fWQydCaIcpUUg1OINRR/PeEGvqwYtWBv6JrMpJTwGbhnZe ZEPJQZOGL/1X9YfKia+2IGIareGjxZI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:e551:0:b0:584:dd94:24c1 with SMTP id z17-20020a63e551000000b00584dd9424c1mr155269pgj.11.1698072052492; Mon, 23 Oct 2023 07:40:52 -0700 (PDT) Date: Mon, 23 Oct 2023 07:40:50 -0700 In-Reply-To: <87r0ll4thx.fsf@redhat.com> Mime-Version: 1.0 References: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> <20231020151242.1814-5-kirill.shutemov@linux.intel.com> <87wmvh47zb.fsf@redhat.com> <87r0ll4thx.fsf@redhat.com> Message-ID: Subject: Re: [PATCHv2 04/13] x86/kvm: Do not try to disable kvmclock if it was not enabled From: Sean Christopherson To: Vitaly Kuznetsov Cc: "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , Ashish Kalra , Kai Huang , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Paolo Bonzini , Wanpeng Li Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 23 Oct 2023 07:41:45 -0700 (PDT) On Mon, Oct 23, 2023, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > On Fri, Oct 20, 2023, Vitaly Kuznetsov wrote: > >> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > >> index b8ab9ee5896c..1ee49c98e70a 100644 > >> --- a/arch/x86/kernel/kvm.c > >> +++ b/arch/x86/kernel/kvm.c > >> @@ -454,7 +454,9 @@ static void kvm_guest_cpu_offline(bool shutdown) > >> kvm_pv_disable_apf(); > >> if (!shutdown) > >> apf_task_wake_all(); > >> - kvmclock_disable(); > >> + if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2) || > >> + kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)) > >> + kvmclock_disable(); > >> } > > > > That would result in an unnecessray WRMSR in the case where kvmclock is disabled > > on the command line. It _should_ be benign given how the code is written, but > > it's not impossible to imagine a scenario where someone disabled kvmclock in the > > guest because of a hypervisor bug. And the WRMSR would become a bogus write to > > MSR 0x0 if someone made a "cleanup" to set msr_kvm_system_time if and only if > > kvmclock is actually used, e.g. if someone made Kirill's change sans the check in > > kvmclock_disable(). > > True but we don't have such module params to disable other PV features so > e.g. KVM_FEATURE_PV_EOI/KVM_FEATURE_MIGRATION_CONTROL are written to > unconditionally. Wouldn't it be better to handle parameters like > 'no-kvmclock' by clearing the feature bit in kvm_arch_para_features()'s > return value so all kvm_para_has_feature() calls for it just return > 'false'? We can even do an umbreall "no-kvm-features=" to cover > all possible debug cases. I don't know that it's worth the effort, or that it'd even be a net positive. Today, kvm_para_has_feature() goes through to CPUID every time, e.g. we'd have to add a small bit of infrastructure to snapshot and clear bits, or rework things to let kvm_para_has_feature peek at kvmclock. And things like KVM_FEATURE_PV_TLB_FLUSH would be quite weird, e.g. we either end up leaving the feature bit set while returning "false" for pv_tlb_flush_supported(), or we'd clear the feature bit for a rather large number of conditions that don't really have anything to do with KVM_FEATURE_PV_TLB_FLUSH being available. static bool pv_tlb_flush_supported(void) { return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && !kvm_para_has_hint(KVM_HINTS_REALTIME) && kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) && !boot_cpu_has(X86_FEATURE_MWAIT) && (num_possible_cpus() != 1)); }