Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp330553lqs; Thu, 13 Jun 2024 11:11:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhGdj/UfViuMNtfKJAdR1U7pptqFcetbqpd1deQZtUhki987bMIa2H3fCEZtaOjy9eAEJvYPxVIMVt/9dGF+VqTOVDB92aPVXW+y6X7g== X-Google-Smtp-Source: AGHT+IF/zxFnNedPyHBKTm8PupqmVurrupO3bQOHhQo8JoKKkvMiWjLxXLPRZ4nJGwOyxbBagI9w X-Received: by 2002:a50:9b45:0:b0:57c:74ed:88c5 with SMTP id 4fb4d7f45d1cf-57cbd665244mr367998a12.13.1718302315581; Thu, 13 Jun 2024 11:11:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718302315; cv=pass; d=google.com; s=arc-20160816; b=ZwXaFP9TDHstyMiq5zzereDklOAuhUvc9Sc3mclxpYhOwBkX2YBY/mV9qiGT7A4vqR B0GNGK1+RvV2My+jrBFdjQit4QBnIIFzZwX8wlqf5Mqha92gmKsMh/41FWBvGPg5TBej TX26pve7p2MH/AxkG3kQDhN1jWeXoXYT7zriYrB8Xae6soDxsGWBF7Q5R5bS2ZLVHxfD c+dVsJcU7SUrwtsymtd4JGyerukXB9gPkQ7tInS3YMNfHnYGGTZOIM74HJ4TevSaSB92 +ozgTubj7s/HgXKC0dQ5e94a2bjj9GRDsAhXwhEw/PI5BI9Je8qiuUL3P3quyHD6ZoAv oAPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=Gk7J+8BbLxtOtkAajMM7yjvy9BH01Nbjlz3KRlct3ug=; fh=uzCrZMsEnMDs/MfHVUnv96LpYzP7XoyfHkNMvKnZn4s=; b=rp2Ko5LsqnEEapAkKCBswqwplMBkv7kCyzTsTQCWYIY2w47UQCHox/TV/BJoSHjhCm g5IQFyzus7VoMx277KuCAtPUaoZXBG70nTHeEzlhn/vBuYzfNZLq5Vl6ieBSy4Mjtgoq +0xWMRKnGStJ2+18VN6ioPGrqENP09BCcpVmwXMKber+R+8P7EYFjtpyW06+HOytUgdN 176Pj4+V+HA0aMDvYlIybZquS06gn5mjHfd1/Hj6LwOzJKjHvLb+aTDxMVIjb0fGOaNu bce1DdD9Trqf/EV2dnwViLLWMv8/1htZ3vXnoz5socx9ALW4B5kx/gZKPHtbhkbcfZ3/ LCmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=g7UtXrQm; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-213793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb7478fbfsi976055a12.674.2024.06.13.11.11.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 11:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=g7UtXrQm; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-213793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4D5121F22F17 for ; Thu, 13 Jun 2024 18:11:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 649AA14AD23; Thu, 13 Jun 2024 18:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="g7UtXrQm" Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF1F614A4F0 for ; Thu, 13 Jun 2024 18:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718302306; cv=none; b=iUJHWBQQf1t8H0DNQBFxfrVOw51z4Jvg479EpHpLUM70DZiCWyxLq8uaSf10BYgq3DJnnsaeghr6qPvBAtmT4NsOY/toqwUfwL+qVuRHiQ0nNPjOBal26ukY0GcwY8cz7QZM49VKgYu+6NEh/8K0mo1I9uuS7bDTowTrDTuyhJI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718302306; c=relaxed/simple; bh=Uu68SQerv1eT74j5km+BfiY4zyB89y2nPa1tlbQp+kI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Aey6K/k2qtN4Vw3hU7p/KuRSyF4uxfG/0A1UNkcEeJ7ouXd7V5vC4JLgToLzvwTD6x9ungczhaTgZ/S/DkD6yw6EjR22/alJSBFK8i8qwXkfCJaQNxKPYbn/tafo+Cri9rR/Zgg0Ah7cOAz2CXO6aO8uCrengxHtN7a+5xZhaDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=g7UtXrQm; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7043008f4beso1106672b3a.2 for ; Thu, 13 Jun 2024 11:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718302303; x=1718907103; 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=Gk7J+8BbLxtOtkAajMM7yjvy9BH01Nbjlz3KRlct3ug=; b=g7UtXrQm37ym/wAOavx/bPMBWS7ssUaYMUDUwpr+tR/XZdGaOER/npNTx2JrRc9n0w RI2Jp74o9jAAAeIk2iRi/7U58jINPT+Mv9Yo2OVG8zr6MQKm7QIzejEY9+SRwGALcFyt 29LA80kFZ5Xq+vf75Yp9wSAGzmZ52OH9Vau+QlCT22m2xCYAAfacgcV9o9MEBcN2YRoj m5lwH2AUeuQ1uzJGaaL6gwhb9DOW+VDwNyLUvmcATZvZD0mV7WWlIX+1tetA1oaC3CFs a8zF0bm9Y5pQYKusS8FxwGOyYW5vGL2WrQEgoTKWf2uId48sPDhH/Kqij/i+vROuTiGb UYiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718302303; x=1718907103; 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=Gk7J+8BbLxtOtkAajMM7yjvy9BH01Nbjlz3KRlct3ug=; b=XWGYgkErhj3ArRagmg3l0E9xLpjceaueOlEncOZw5IkHz1I0063z6tAtmKY9hOabRZ mfnwOGXGXY8ucH+4dN4KoKvadkEjY7PMmeGgnkUM/YuZpRjoj3N8h+jwJRlZYjHdTvi5 9bX8D0EH/8pBXQRH/jaCrfmoPOcxfbimHZXUA5LfkKB4yhX+IAG4Ts7fPOYeYtH7YNOF rtqIL6uTqsxTFEVuIRldUvQCgwoXOA29BLEurkUzEv7EWKTz6LxTJ3+bjbkWUmPcuIrP konaxwQJRyzWxIlSon+ccVjTYUJ55WJiS09piqsBqEwxHAgPHb2UozzN/9l0BB9+m/LO iUEg== X-Gm-Message-State: AOJu0Yz4F5EazzerRthW0SWNujJKT9qA4zPkWKjrGgOJJblBowcmykbd bKVwW08IjHSZDhMsO7uf7LqH1F60jPVaKDEW1+YCEnd9FcDhX50DxKZmb3+tkmy6RgdKMcYiMlr leg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2da1:b0:705:d750:83f4 with SMTP id d2e1a72fcca58-705d7508823mr1219b3a.3.1718302303033; Thu, 13 Jun 2024 11:11:43 -0700 (PDT) Date: Thu, 13 Jun 2024 11:11:41 -0700 In-Reply-To: <20240207172646.3981-18-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240207172646.3981-1-xin3.li@intel.com> <20240207172646.3981-18-xin3.li@intel.com> Message-ID: Subject: Re: [PATCH v2 17/25] KVM: nVMX: Add support for the secondary VM exit controls From: Sean Christopherson To: Xin Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, shuah@kernel.org, vkuznets@redhat.com, peterz@infradead.org, ravi.v.shankar@intel.com, xin@zytor.com Content-Type: text/plain; charset="us-ascii" On Wed, Feb 07, 2024, Xin Li wrote: > @@ -6856,13 +6865,17 @@ static void nested_vmx_setup_exit_ctls(struct vmcs_config *vmcs_conf, > VM_EXIT_HOST_ADDR_SPACE_SIZE | > #endif > VM_EXIT_LOAD_IA32_PAT | VM_EXIT_SAVE_IA32_PAT | > - VM_EXIT_CLEAR_BNDCFGS; > + VM_EXIT_CLEAR_BNDCFGS | VM_EXIT_ACTIVATE_SECONDARY_CONTROLS; > msrs->exit_ctls_high |= > VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR | > VM_EXIT_LOAD_IA32_EFER | VM_EXIT_SAVE_IA32_EFER | > VM_EXIT_SAVE_VMX_PREEMPTION_TIMER | VM_EXIT_ACK_INTR_ON_EXIT | > VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL; > > + /* secondary exit controls */ Drop the comment, it's pretty obvious what field is being setup. > + if (msrs->exit_ctls_high & VM_EXIT_ACTIVATE_SECONDARY_CONTROLS) > + rdmsrl(MSR_IA32_VMX_EXIT_CTLS2, msrs->secondary_exit_ctls); This is wrong, the resulting msrs->secondary_exit_ctls needs to be sanitized based on what KVM supports for nVMX. On a very related topic, this should not do a raw RDMSR. One of the reasons why KVM uses vmcs_config as the base is to avoid advertising features to L1 that KVM itself doesn't support, e.g. because the expected entry+exit pairs aren't supported. And by pulling state from vmcs_conf->secondary_exit_ctls there's no need to check the activation bit. I.e. literaly just this: msrs->secondary_exit_ctls = vmcs_conf->secondary_exit_ctls; msrs->secondary_exit_ctls &= 0; and then when nVMX FRED support is ready, it becomes: msrs->secondary_exit_ctls = vmcs_conf->secondary_exit_ctls; msrs->secondary_exit_ctls &= SECONDARY_VM_EXIT_SAVE_IA32_FRED | SECONDARY_VM_EXIT_LOAD_IA32_FRED;