Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6359316pxb; Tue, 15 Feb 2022 00:10:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJ0EZyRygSDZY1xAAi3uWy8kfWnpbyvI2gM/3UVUJNDhq3TXw7Qex/7ApafR04QDL1yDLd X-Received: by 2002:a17:907:c15:: with SMTP id ga21mr2038040ejc.80.1644912630847; Tue, 15 Feb 2022 00:10:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644912630; cv=none; d=google.com; s=arc-20160816; b=y3xWnGg3jeiX0PDuJ/HRSLu0pTUelHiT5xqBmy/PhhVgGtn50/00b75si4MAIOd5PH vUV3vfdr5wQPHCP35wtf541EbHW1QmKlcCnhlHfBpoyXysHj07rGxxpbQfPQNWwtG0W1 pa4txTkmMA1WRBoIIkyTLG6DTH8iURM+1kLtJyYs+lOdnXt7kCgkdcIbc+kDDNdYJjyC O7WLyBktApkWqFbv+fbaX8Jd0V6FiHvGr8XbRfVLK2F9qi3PipUtvs0PEX2Zfx9Pk7wi Fe+2uuP1GyY+/5suqMflEgFiXDGCoUVYxkHcuTccOPDnRtGaMlcuHxoR66A5Ei99H5w4 BOBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=a92+EmiKlZ0uaPz1xv1lNAFMmP75113AV1BF3YGwZk4=; b=CasumEyqFk2nsutfW25h8qQKRY+/0Ixei68Zp6xwxIrADUl336cYjlsB+wmxPCpk63 UfnYU8u2RcTXFErgY5i8P0+tkz0FeS0fB0U3e+OJb/tKbo1M1unFMFSXRe/5pZ1Yscwk iqf1rG8KbLjHa4Y7WsjF8hNFVOFSJkgC3BBUiJ2bp8s6HvzMMcTkrafuCcZhGWRH/ZDp jdZ1ou2+NLIQszfI8t415UsSQmTKDYLC/Ffsn0KHvb586EEF1dm9cm/g2jOpi9/n/G6H Y7HfzOq0AKkOK6w6aeH7CWch97NISS7j73j0iSoU7S36AWPYwI9D0Rjp4zm95j5QakcG a0+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AuaIm1/q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9si15047685edc.631.2022.02.15.00.10.07; Tue, 15 Feb 2022 00:10:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AuaIm1/q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233456AbiBOCLl (ORCPT + 99 others); Mon, 14 Feb 2022 21:11:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232846AbiBOCLk (ORCPT ); Mon, 14 Feb 2022 21:11:40 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B0D19C3A; Mon, 14 Feb 2022 18:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644891091; x=1676427091; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=+HeZRAeKFxW/cwuCZBqN2uQwwndDLWRt5wIFdHPT7oM=; b=AuaIm1/q2OT+wy9PW+hgjnMIe7bEwjz7GYjQ21mcIsPrGAkCK5iylBVS KpsmX9MNuK/ZWgogrIn+VAWfGzQOo0p1uR6dAyJpNKRLAAomLtVB9xQ6L 7nOgKIE4oTNy6Zv//HGT19Mm0ItMxUaMqwyNaJFzCIMqlYQybNdLEFAs6 epNKKhaE3ToKkSi65rh7XDtRDpICr9dbxyrHwph3AWKhgTTltN731u2ns uWRB1jx3TWhLPoanDEaHwTv58xLc1FRdS0mk62y2z2nR161wyxI72nazz Dym4s/EJztdhyOJDsaslFZYuclyFJXvRX+3j6dEqFwmcCeWa0fgoLtPSP w==; X-IronPort-AV: E=McAfee;i="6200,9189,10258"; a="230867125" X-IronPort-AV: E=Sophos;i="5.88,369,1635231600"; d="scan'208";a="230867125" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Feb 2022 18:11:31 -0800 X-IronPort-AV: E=Sophos;i="5.88,369,1635231600"; d="scan'208";a="703381197" Received: from gao-cwp.sh.intel.com (HELO gao-cwp) ([10.239.159.105]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Feb 2022 18:11:27 -0800 Date: Tue, 15 Feb 2022 10:22:23 +0800 From: Chao Gao To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zeng Guang , Maxim Levitsky Subject: Re: [PATCH 02/11] KVM: VMX: Handle APIC-write offset wrangling in VMX code Message-ID: <20220215022221.GA28478@gao-cwp> References: <20220204214205.3306634-1-seanjc@google.com> <20220204214205.3306634-3-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220204214205.3306634-3-seanjc@google.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 >--- a/arch/x86/kvm/vmx/vmx.c >+++ b/arch/x86/kvm/vmx/vmx.c >@@ -5302,9 +5302,16 @@ static int handle_apic_eoi_induced(struct kvm_vcpu *vcpu) > static int handle_apic_write(struct kvm_vcpu *vcpu) > { > unsigned long exit_qualification = vmx_get_exit_qual(vcpu); >- u32 offset = exit_qualification & 0xfff; > >- /* APIC-write VM exit is trap-like and thus no need to adjust IP */ >+ /* >+ * APIC-write VM-Exit is trap-like, KVM doesn't need to advance RIP and >+ * hardware has done any necessary aliasing, offset adjustments, etc... >+ * for the access. I.e. the correct value has already been written to >+ * the vAPIC page for the correct 16-byte chunk. KVM needs only to >+ * retrieve the register value and emulate the access. >+ */ >+ u32 offset = exit_qualification & 0xff0; Can we take this opportunity to remove offset/exit_qualification? They are used just once. >+ > kvm_apic_write_nodecode(vcpu, offset); > return 1; > } >-- >2.35.0.263.gb82422642f-goog >