Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2591721rdb; Wed, 15 Nov 2023 05:27:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvgVpjbjv+tTo0ddTgeDVEuCuZlguTO2wIvlxIVhF8nQnwRygNb3lhbLwZ72SG4DR0R3ip X-Received: by 2002:a05:6a21:a598:b0:186:7842:ad0f with SMTP id gd24-20020a056a21a59800b001867842ad0fmr11054133pzc.31.1700054846535; Wed, 15 Nov 2023 05:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700054846; cv=none; d=google.com; s=arc-20160816; b=jR+d7oEM5JlZKRLM+liZx4PWTHE28EK7xTjV9twMAaiNTFqBTYBQ4PrPCExyMpnOwa Pwu+hYI5YvGU4CJfDDSRbNcatAMzhufL4AfG11m21H6e6PuRf7dAjnL/40l/uj+DpyUA Cqgpzajo7OqL1Aq+sPv1HxwK8OizMRZ2rEqSClemabIFftqkSAWGx5eRjMFzqWYjMaLd A0lTBZHD4J76dUSvLaCdrtBhD73blJIPF8NQWGaBDKnlu7DN3AmSXHaWGiFiUI+Hfk4f oW7racx91zwdoOK1j99HDtjMWQojWSrmr4Qqq9oxljMI1LpxDj4lzld3j4DO1PKkxTBd MKKA== 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=67VCtaGV/e+lwlaWVR9CnUK5q5agNeqRm+nDDRKAEZQ=; fh=1UuEv+2MuGIVEgR7n1M4X/QmnSF0kji7mR5NmKwlVpU=; b=INf68kDdJ9HvsNjrsooCGVRxJ6Bsb27L02bE5Ftw+QP5Zf3jNVsBFY3oFP54CERLdr PS1ZVGp3dFGS5gueuFNMryPNs7O28RbWniNkmHXbRd65RLINUMIO0sx1DNEsAyJCYG/a JnUN9dh0flxfVDdaNiyKAhRYliVa0w7N3/G0ajSj/IgtqbogiLSZbCMAZnwR9qQKwPPo PKMCdwrAKRNuiZzFlhehKm4hdB9qPLVEQCp1mzLNurNVJzXjtrSEl2tnFcfqieo/78PM /JbN+srcN3JqpbHH2+0M/q8kT98+Y915RBQs510xV3H+FuCL2mZYexmDZpm2ct8cEoDw Etdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="a/oJLhc+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a191-20020a6390c8000000b00563e283786esi9907955pge.104.2023.11.15.05.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:27:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="a/oJLhc+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id DF23180C6EB7; Wed, 15 Nov 2023 05:27:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343781AbjKON1Q (ORCPT + 99 others); Wed, 15 Nov 2023 08:27:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343686AbjKON1P (ORCPT ); Wed, 15 Nov 2023 08:27:15 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51CEEA6 for ; Wed, 15 Nov 2023 05:27:12 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-6c7c6ae381fso2356591b3a.2 for ; Wed, 15 Nov 2023 05:27:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700054832; x=1700659632; 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=67VCtaGV/e+lwlaWVR9CnUK5q5agNeqRm+nDDRKAEZQ=; b=a/oJLhc+8u1hy/keGxA5NPp0JULrhJVoRy1ikQCIK6eSYcCg0NLr1oG4tmnt973Wop sZ9SxAfwO6j03IV26rt0JeLRUyERcA0/8VVr8ca2Us12xd6rUzCjmHWlljMPbLxJUWgP PNmg4cKhkMoSbBD5SOgNutWOcMVDINCUg+Pd/MGoyeXmiV0ISo+xyI7f5KwrILT5nBvG eMRZE1SHurgbvnkMrRFco0Q2bgTvg8zxJIZ4o9MUY3aqZXEzDm29mEx3bYj2o6E3PZae 1zVNauyCXIUHZCWt7TaVijMdwGcw+WrgTFYFEdREmB5SdUdZmvST0/iPO84BAY7d2r+i umDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700054832; x=1700659632; 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=67VCtaGV/e+lwlaWVR9CnUK5q5agNeqRm+nDDRKAEZQ=; b=dn+Q9EbtUM95pYyF/WKEb9FaRHVpmt1AmtJbFx+WSVSQTFu6TkvoPt70/I6gBsbo93 rxhJh2vYUQPgjwwH4RgYHSx1NPbKFB8MhWJpNPb/hOztS2WzjTzNNiYBWRSRgTqe7t7K 0c5/WBuQfVVuSOk3jD8HzqQbr6gQb3+oYJMTUKlMy6IWPsKcX1CwMRn5R7lPbGQmK5Zy zWxc1H2/S9wKDr2CzxX++1ALWaSt3Fi+Fx+tNlbmE7i6ngjh7TsEoB/ZFQI71OKa44Go bgKRAQi7iHOohTPjX4ysRlewCJuvEJfAEsSu8BJGbutp+SC/016tRIWvKIO0WfMHiYhl +wIg== X-Gm-Message-State: AOJu0YxC4eO8Xt9oXYnwzHD0tdyW8PtNY1fM6V6Q/2guGB5YtCGMglsv veFnYmvqsrshLbVsk+DV5N+cDSLylYQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:8b83:b0:6c0:ec5b:bb2d with SMTP id ig3-20020a056a008b8300b006c0ec5bbb2dmr3053306pfb.2.1700054831789; Wed, 15 Nov 2023 05:27:11 -0800 (PST) Date: Wed, 15 Nov 2023 05:27:10 -0800 In-Reply-To: Mime-Version: 1.0 References: <20230914063325.85503-1-weijiang.yang@intel.com> <20230914063325.85503-25-weijiang.yang@intel.com> Message-ID: Subject: Re: [PATCH v6 24/25] KVM: nVMX: Introduce new VMX_BASIC bit for event error_code delivery to L1 From: Sean Christopherson To: Weijiang Yang Cc: Chao Gao , pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, peterz@infradead.org, rick.p.edgecombe@intel.com, john.allen@amd.com 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,T_SCC_BODY_TEXT_LINE, 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 15 Nov 2023 05:27:24 -0800 (PST) On Wed, Nov 15, 2023, Weijiang Yang wrote: > On 11/1/2023 12:21 PM, Chao Gao wrote: > > On Thu, Sep 14, 2023 at 02:33:24AM -0400, Yang Weijiang wrote: > > > @@ -2846,12 +2846,16 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu, > > > CC(intr_type == INTR_TYPE_OTHER_EVENT && vector != 0)) > > > return -EINVAL; > > > > > > - /* VM-entry interruption-info field: deliver error code */ > > > - should_have_error_code = > > > - intr_type == INTR_TYPE_HARD_EXCEPTION && prot_mode && > > > - x86_exception_has_error_code(vector); > > > - if (CC(has_error_code != should_have_error_code)) > > > - return -EINVAL; > > > + if (!prot_mode || intr_type != INTR_TYPE_HARD_EXCEPTION || > > > + !nested_cpu_has_no_hw_errcode_cc(vcpu)) { > > > + /* VM-entry interruption-info field: deliver error code */ > > > + should_have_error_code = > > > + intr_type == INTR_TYPE_HARD_EXCEPTION && > > > + prot_mode && > > > + x86_exception_has_error_code(vector); > > > + if (CC(has_error_code != should_have_error_code)) > > > + return -EINVAL; > > > + } > > prot_mode and intr_type are used twice, making the code a little hard to read. > > > > how about: > > /* > > * Cannot deliver error code in real mode or if the > > * interruption type is not hardware exception. For other > > * cases, do the consistency check only if the vCPU doesn't > > * enumerate VMX_BASIC_NO_HW_ERROR_CODE_CC. > > */ > > if (!prot_mode || intr_type != INTR_TYPE_HARD_EXCEPTION) { > > if (CC(has_error_code)) > > return -EINVAL; > > } else if (!nested_cpu_has_no_hw_errcode_cc(vcpu)) { > > if (CC(has_error_code != x86_exception_has_error_code(vector))) > > return -EINVAL; > > } Or maybe go one step further and put the nested_cpu_has...() check inside the CC() macro so that it too will be captured on error. It's a little uglier though, and I doubt providing that extra information will matter in practice, so definitely feel free to stick with Chao's version. if (!prot_mode || intr_type != INTR_TYPE_HARD_EXCEPTION) { if (CC(has_error_code)) return -EINVAL; } else if (CC(!nested_cpu_has_no_hw_errcode_cc(vcpu) && has_error_code != x86_exception_has_error_code(vector))) { return -EINVAL; }