From patchwork Fri Feb 18 08:10:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 12751057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B66C6C433EF for ; Fri, 18 Feb 2022 08:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbiBRILs (ORCPT ); Fri, 18 Feb 2022 03:11:48 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbiBRILr (ORCPT ); Fri, 18 Feb 2022 03:11:47 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C650A6527; Fri, 18 Feb 2022 00:11:30 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id f8so7193867pgc.8; Fri, 18 Feb 2022 00:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=bXsJR1hdtDvMtwp7yRC+IBrb2NPsW+Emms20iVxrSMU=; b=AaBFLmiOGsUkw4+8UvUdL+L5kkVxHOj1Npl1IXE6YoKWXYSl/9K3tUdIfZ4RO6foc5 fonKpoD6m+5CQSiabZVRp2mpP0AEIycjGJHGIuxkpBRbgoFtbzS6jl0R2XZadf34rg04 BEtiiX6bSLhmQsgz/61xruiUuQMCe9vD69ARsBpJekQRpqt8cOSobfTjaHFWITJerM97 07WsrQVX/pvu4jBCyzwicR4yAgM4ZQ8fZV/k4hj5Nx1pC7v8kaoRZLW6+gGRVfnoCG9V noWENnvIpDCzOyl07mlvHCv7Sz1a0MQ9LcP0rwB+gHx4WUw2J9e2tw/s2BPSS1xc9tfb e/aw== 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; bh=bXsJR1hdtDvMtwp7yRC+IBrb2NPsW+Emms20iVxrSMU=; b=r75EKQn9zJFIzalGKrtWLhJDL9DK6N1FfYzWrm3qG7b7SRDsoSi97sQq+iDdmiBaed htJstcVYAUPq5/6iGlIBol1cPtKqDMeVBjW7EI5X8RLYMfWaImzKOqktUlf/M/VbxWIw EHiOOVVJQwpftONDgYxfwTCOU6kT/ykCcAB+/NGZlAGg/JB2K8XCojNVMMz0Wq3UMGpe Ok56KTkQqWJUXKMvPxsMiYsCkDfsYXlqxbkv7ki//tg4aFHvxGquFiVy065nPVFimAyE Y0SySgfDGILxlnUlrM/iN5vpqo4ZbiFwAdscCVKbGu8E5ikYVOJWFzvQQwvFyqD+bk3I ngGw== X-Gm-Message-State: AOAM532bvpKWGq3PdZlQNBnPpsHgtymsB/ha/OOrepCi74U8LFS6rL8d j+yzRLoD1nevlCOzKtVt0m243n94o6U= X-Google-Smtp-Source: ABdhPJwRUo2LbLZ8iHn9ZB7+3ee+Hfk4AOhSTzpGDqcHJojFIKF0Ywl1WCJUSiXWUQjWfHRD5nxCfQ== X-Received: by 2002:a63:f00e:0:b0:373:9fdb:ce03 with SMTP id k14-20020a63f00e000000b003739fdbce03mr5474869pgh.518.1645171889241; Fri, 18 Feb 2022 00:11:29 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.googlemail.com with ESMTPSA id l8sm10673665pgt.77.2022.02.18.00.11.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Feb 2022 00:11:28 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: [PATCH] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU Date: Fri, 18 Feb 2022 00:10:38 -0800 Message-Id: <1645171838-2855-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanpeng Li Inspired by commit 3553ae5690a (x86/kvm: Don't use pvqspinlock code if only 1 vCPU), on a VM with only 1 vCPU, there is no need to enable pv tlb/ipi/sched_yield and we can save the memory for __pv_cpu_mask. Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index a438217cbfac..f734e3b0cfec 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -462,19 +462,22 @@ 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)); + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) && + (num_possible_cpus() != 1)); } static bool pv_ipi_supported(void) { - return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI); + return (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) && + (num_possible_cpus() != 1)); } static bool pv_sched_yield_supported(void) { return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) && !kvm_para_has_hint(KVM_HINTS_REALTIME) && - kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) && + (num_possible_cpus() != 1)); } #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)