Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp61340lfe; Fri, 15 Apr 2022 19:33:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt6Ps649UGwJ20RLjE6Ky0INKY//Ymfpq+B96h80Wg1PwHim+TvbbIy8SlBWX4q0T5PjRN X-Received: by 2002:a17:90b:1803:b0:1c7:24c4:ab52 with SMTP id lw3-20020a17090b180300b001c724c4ab52mr1815700pjb.240.1650076381341; Fri, 15 Apr 2022 19:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076381; cv=none; d=google.com; s=arc-20160816; b=y3Tj2wt5OszSkkMDtRiWcglXC46qo91LzjvRicUGUMIWgeA/JHExshuBbkqOkvnehJ Nx/9TYItD47umvrNoO+1PWqtYEl15b6A/aarO9heMSOiDtU3ObIP1YXHJznAZ2B8mbxS ef60c7WGoEE0nUitwCiPKhX76Q0NDSSt/UUU5Seq1vSgm2Ntf4jNAsr/4dsNW4cvdaf/ 7NaSGgHPvgZ0vfY/QjPu4Ra+GqmaJZQEv1Tf9HwGNSJNZQt4V047pfwEO48TIMYfGlcO c7enN+CaF48S9dAjHFFmAEU/9HcId2FPiK2q+imHojFh207JwX1bIbsU+XBwdRAYJ62s u7WQ== 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=5CJKuH7khF1y3DizoabvaS6odECAtRFkcRZfxb+4uoM=; b=YBTDRkGLveXz4q35hoqXIYNMMt3Ofq+S1X1Po9LjHoO+SqCCCUDuxYRwxJLLAT9VUj z7167NVHGwr9qWLptUlYNpFW1k20wNU8tEn/iYIJpjdxD8hXNzLPAi1d5ykLAWvi5Moo IdigxJwrCAWDiaix8zWC/yV7MqEaE69aeyVSr1rLBU4IZ5qPh/c8AvaSMKMcdQ+sJxe0 WH7oNOad/xD2xXzHppcyeTkS5VqwmNGLCF36Hh+7qeV1PMVZLwRTez5BrFQKSfRVPKk6 xoussmXogdp61gTwtJ8AGIxbcsPloXXRQqAwvVP4I2aiMocf9XlvAYGY58v4hdYRyDei OEGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eVIE5dV1; 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 y6-20020a1709029b8600b001584ee3ba07si2741822plp.439.2022.04.15.19.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:33:01 -0700 (PDT) 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=eVIE5dV1; 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 37A49165E7B; Fri, 15 Apr 2022 18:42:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354571AbiDOOi0 (ORCPT + 99 others); Fri, 15 Apr 2022 10:38:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354522AbiDOOiV (ORCPT ); Fri, 15 Apr 2022 10:38:21 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 525034667A for ; Fri, 15 Apr 2022 07:35:53 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id k29so7389651pgm.12 for ; Fri, 15 Apr 2022 07:35:53 -0700 (PDT) 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=5CJKuH7khF1y3DizoabvaS6odECAtRFkcRZfxb+4uoM=; b=eVIE5dV1M83IQmQu3BKM+cGuaxyk8PaG6cAjk96I2yBD3kYCMUhK85oHRfsWEVHNuy CX2nRUI6Q+D0RuUb61rnfe0/YeUKnil8pDz34ySN+2gO+D4JxGC4+3TDi1WqLQyHyRgp 8S2R9haf472bv/J995Ch9pE9tcdEgz1hwsPKjtNGc/l/koy4kOqnBYQH3TebTU40jLiR r7rHZStdDWvNSxILsuSov8AddPbZrC/5CmEmhcDBcOIQ6HZYDNKMM+v2binSPPAgP2id e4Zmn6SDnDMvbxvf5XUNnF9ib9ov21ZTT8UHyKRXFl0XwYWqwa9OzVdgq6xYqJKOHvvQ 4CYQ== 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=5CJKuH7khF1y3DizoabvaS6odECAtRFkcRZfxb+4uoM=; b=O5RZnJrsRN26c2YrnSeK6kVKVS65ICdLpnTOafJMF/+rXTiL4JKVU1xvUEz/cc8ygp UuVkX+eiwq7zjJtrzX6zAosyngx2Sq6ZZTf35dM0BSLL2y0ZIwVOBBoLvrrPMiDvBDL5 9iK0HOAKOXb40k9wtcekfKJawRLUPcscVmDAYTWoNlYidkhj2k9XI+zCmIcr3nIcKm2f P+5krQvXU0E953wBeL7b5WCUsKMtIUUecO5rN4Hl+cowzPQMfnla0gQPId66zPhhIHGU 4fJC75c3SdkHtmIjBXNp3EqDukgLFVrFeGYTUUnPRIkNApOlS+OYuai3HloSV76yXCDC diUg== X-Gm-Message-State: AOAM5319cLqWZZ6P+fbxdg9cakJtHo/HKBUWdWydx4gEsj3ZcuptBFGx soSwXYAHVnwKJYyrE997t5r0Vg== X-Received: by 2002:a65:480a:0:b0:39c:c745:6f59 with SMTP id h10-20020a65480a000000b0039cc7456f59mr6432618pgs.33.1650033352643; Fri, 15 Apr 2022 07:35:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id y15-20020a17090a1f4f00b001c7ecaf9e13sm5045100pjy.35.2022.04.15.07.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 07:35:51 -0700 (PDT) Date: Fri, 15 Apr 2022 14:35:48 +0000 From: Sean Christopherson To: Zeng Guang Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "kvm@vger.kernel.org" , Dave Hansen , "Luck, Tony" , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , "Huang, Kai" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "Hu, Robert" , "Gao, Chao" Subject: Re: [PATCH v7 8/8] KVM: VMX: enable IPI virtualization Message-ID: References: <20220304080725.18135-1-guang.zeng@intel.com> <20220304080725.18135-9-guang.zeng@intel.com> <54df6da8-ad68-cc75-48db-d18fc87430e9@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Sat, Apr 09, 2022, Zeng Guang wrote: > > On 4/5/2022 1:57 AM, Sean Christopherson wrote: > > On Sun, Apr 03, 2022, Zeng Guang wrote: > > > On 4/1/2022 10:37 AM, Sean Christopherson wrote: > > > > > @@ -4219,14 +4226,21 @@ static void vmx_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu) > > > > > pin_controls_set(vmx, vmx_pin_based_exec_ctrl(vmx)); > > > > > if (cpu_has_secondary_exec_ctrls()) { > > > > > - if (kvm_vcpu_apicv_active(vcpu)) > > > > > + if (kvm_vcpu_apicv_active(vcpu)) { > > > > > secondary_exec_controls_setbit(vmx, > > > > > SECONDARY_EXEC_APIC_REGISTER_VIRT | > > > > > SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY); > > > > > - else > > > > > + if (enable_ipiv) > > > > > + tertiary_exec_controls_setbit(vmx, > > > > > + TERTIARY_EXEC_IPI_VIRT); > > > > > + } else { > > > > > secondary_exec_controls_clearbit(vmx, > > > > > SECONDARY_EXEC_APIC_REGISTER_VIRT | > > > > > SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY); > > > > > + if (enable_ipiv) > > > > > + tertiary_exec_controls_clearbit(vmx, > > > > > + TERTIARY_EXEC_IPI_VIRT); > > > > Oof. The existing code is kludgy. We should never reach this point without > > > > enable_apicv=true, and enable_apicv should be forced off if APICv isn't supported, > > > > let alone seconary exec being support. > > > > > > > > Unless I'm missing something, throw a prep patch earlier in the series to drop > > > > the cpu_has_secondary_exec_ctrls() check, that will clean this code up a smidge. > > > cpu_has_secondary_exec_ctrls() check can avoid wrong vmcs write in case mistaken > > > invocation. > > KVM has far bigger problems on buggy invocation, and in that case the resulting > > printk + WARN from the failed VMWRITE is a good thing. > > SDM doesn't define VMWRITE failure for such case. Yes it absolutely does. cpu_has_secondary_exec_ctrls() checks if the VMCS field _exists_, not if it's being used by KVM (though that's a moot point since KVM always enables secondary controls when it's supported). VMWRITE to non-existent fields cause VM-Fail. ELSIF secondary source operand does not correspond to any VMCS field THEN VMfailValid(VMREAD/VMWRITE from/to unsupported VMCS component);