Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2193383pxb; Wed, 9 Feb 2022 12:54:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyh680AAzdL6fkajG6d4CZZT31TWRjdZasH/Pgt+QB+z69UdxE3eezfYvsk77IOQ1zasZ6 X-Received: by 2002:a17:902:bf02:: with SMTP id bi2mr3975892plb.139.1644440078396; Wed, 09 Feb 2022 12:54:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644440078; cv=none; d=google.com; s=arc-20160816; b=TYC7TQf6eA/zKgO7WBQcO7svBXRkTYwCGVTZMy2d90PLoH6vpZl0Be9OOaeVzARwV1 7F9cY/VyxX9bd8MY/+a8fGHUgv/Uuljwsl3RzUXxXGF8icP/kCd/GSCMwafLGGRym90H SyrOJOeDOYjE6BGfT6aXdrqf3u8iWgL4bh1dTx/CpSmQeHjmGm56O0iTQrhgyfqicOmQ qGk70BCT22vNS/CXVHZzCRadhSqOLL2bqjXUaVZWnynP7t3Vox4C+fFcCPRJhUHl4e0d IG4y2XL+olkjRVmH3v451KtktPkycvDNeeygvocaPTmWijWaxQUyjzsiFHXR765uQBvT aOiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=usai5WVQErwk4Ew2fX/fOjUw6I8vvZIt0nVcprr1jB8=; b=ScpEHRAM+XZfDVzqnFe8gIv2VKhzDsg9Knn3eOQrOLdNamg0W9LipSNz/GOeB27ORm snttHb85aHW1GDHbUq8aI/kYihX2nV72LFmh+CnuxlnfgHaZtXfPNr8KSWvaYIRQbIaG jSf2JAtzQrv9Ubi8sAvjVqqYVf/ox1fLe7ROw9OwHgiKWnwj2dljxrKhoYoFZOiro6Rv RHW5K7hB89UOnPlss1BT0jjbXgrrG0TOzF20xlYgtfc+o6YZBshAThGlxhJw40zmKZ8/ kY/Vd1915urfZe7bBeJ5xAO+O6eeX/InmsvRGTEhUs+4z4Wl8kh4fJPcEsi3Fx2jryVo De+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VqQ4AQV9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w71si5613235pgd.275.2022.02.09.12.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 12:54:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VqQ4AQV9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99E0FC0045C1; Wed, 9 Feb 2022 12:51:03 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbiBIUtZ (ORCPT + 99 others); Wed, 9 Feb 2022 15:49:25 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:50532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232367AbiBIUtX (ORCPT ); Wed, 9 Feb 2022 15:49:23 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86809C05CBA0 for ; Wed, 9 Feb 2022 12:49:26 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id y17so3337061plg.7 for ; Wed, 09 Feb 2022 12:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=usai5WVQErwk4Ew2fX/fOjUw6I8vvZIt0nVcprr1jB8=; b=VqQ4AQV9kyt+0LUwBHfYIcCdy6HaR52lzHPXQid7Q9Se19pBiE9Mi/rh3L+BTrlcsA 3zhWV/p7cu/zpDWzo7seoNfyvraJeUxi6CYB6mkMUCbqqhUhq6m/rjbyx/IUrHKoVXof lSkYyXL/SVmmvlJQ902YhuNCzptvPCHTOSwCPPsN8v87m068+MhEZHA/NU8a1bXJaf9P uKu6stWAubyB61SmQAKl0PriItNTzKJNWLayosXH27IGEVSnYux3NhyrI5glY56g2pAl uGtJ7pB8scL4hzREiHv7FcQjA7rxLGqS4qtNTCbZKzEmQmICwvLEIphJRmERaAHp85uu QD5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=usai5WVQErwk4Ew2fX/fOjUw6I8vvZIt0nVcprr1jB8=; b=vB2XsxerdzsmFrU0xmoEhq00aMPLTl8OQ6+kv9BuQX+afgzyF5uMUDfJjZjDiQDsoa M5mwS4h80ILhZEBJ76KePtDToacBQu+zOftbf1e2tgLaQT2Ov1gaNiFLfP0476+e4mf0 A4zDqM/XrFSbCIitJ61ET+Eej8a9auQgz6/I8mZj9SeixvhvdFV3SRy+I/ZZMf579CH3 aHV/OAcPPaEE2LVCtEN+JDES5i7cy7dmi+0Pb3ssNTqR1BC4EpTgDc5dg9lZvpbOyywW sKTH9fUiudzmaGPNnYcfLXJxI5aO2Rt1A6AiVRpxUEQ5TZJ2uWP1PJ+AT5Aegmm4U8AC CRaA== X-Gm-Message-State: AOAM533ZiTjWTkW27CC9f4roFQywPZTP9lZMpX7XX20wgIAShEg3geHN cYqWfqLpzb+NcVWnwvjO0HqcpA== X-Received: by 2002:a17:90a:ab90:: with SMTP id n16mr5432152pjq.229.1644439765909; Wed, 09 Feb 2022 12:49:25 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id j15sm22379244pfj.102.2022.02.09.12.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 12:49:25 -0800 (PST) Date: Wed, 9 Feb 2022 20:49:21 +0000 From: Sean Christopherson To: Chao Gao Cc: kvm@vger.kernel.org, pbonzini@redhat.com, kevin.tian@intel.com, tglx@linutronix.de, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 5/5] KVM: Do compatibility checks on hotplugged CPUs Message-ID: References: <20220209074109.453116-1-chao.gao@intel.com> <20220209074109.453116-6-chao.gao@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220209074109.453116-6-chao.gao@intel.com> X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 09, 2022, Chao Gao wrote: > At init time, KVM does compatibility checks to ensure that all online > CPUs support hardware virtualization and a common set of features. But > KVM uses hotplugged CPUs without such compatibility checks. On Intel > CPUs, this leads to #GP if the hotplugged CPU doesn't support VMX or > vmentry failure if the hotplugged CPU doesn't meet minimal feature > requirements. > > Do compatibility checks when onlining a CPU and abort the online process > if the hotplugged CPU is incompatible with online CPUs. > > CPU hotplug is disabled during hardware_enable_all() to prevent the corner > case as shown below. A hotplugged CPU marks itself online in > cpu_online_mask (1) and enables interrupt (2) before invoking callbacks > registered in ONLINE section (3). So, if hardware_enable_all() is invoked > on another CPU right after (2), then on_each_cpu() in hardware_enable_all() > invokes hardware_enable_nolock() on the hotplugged CPU before > kvm_online_cpu() is called. This makes the CPU escape from compatibility > checks, which is risky. > > start_secondary { ... > set_cpu_online(smp_processor_id(), true); <- 1 > ... > local_irq_enable(); <- 2 > ... > cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); <- 3 > } > > Keep compatibility checks at KVM init time. It can help to find > incompatibility issues earlier and refuse to load arch KVM module > (e.g., kvm-intel). > > Loosen the WARN_ON in kvm_arch_check_processor_compat so that it > can be invoked from KVM's CPU hotplug callback (i.e., kvm_online_cpu). > > Opportunistically, add a pr_err() for setup_vmcs_config() path in > vmx_check_processor_compatibility() so that each possible error path has > its own error message. Convert printk(KERN_ERR ... to pr_err to please > checkpatch.pl > > Signed-off-by: Chao Gao > --- Reviewed-by: Sean Christopherson