Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4730349imw; Tue, 19 Jul 2022 12:06:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tz9XUfkZJSkp6vuYc8bq6La9+ObYRaP1x2x7sKgON7wn8P9T7X82gs4YwxEioicUyCVvgd X-Received: by 2002:a05:6402:2cd:b0:43a:70f7:1af2 with SMTP id b13-20020a05640202cd00b0043a70f71af2mr45788862edx.357.1658257587774; Tue, 19 Jul 2022 12:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658257587; cv=none; d=google.com; s=arc-20160816; b=lsNdo19WQmthEyiJF2TPQZWG4HAMsNV4e7+vFGiZ1NqDjXmshEFxGc5F/R8rEEdXmf shle4UXIj+H2kM7lxudTJ+HcUozw8V4NKCdoPgmYG7CouVjTe7IPS2Tr5bwzUtImtY9N Khnwegv14j8PAcTC4Swp5mSF+x36c9UFO+v9P4mc9GL5uPFM0KvYrEv1eldO8Vq3sBIP +lmcFSyLbJGKAdUZ4x59Loffj+wXlfn4Kab/H8PNIWB16Fb4m0iwRVV0UY50FUzh76im yM1mkr9Yd4PP4wjWJJZI7Pyt1OeAcECglciQefWZNt/noHGIW6epvPOWuTG82dHkotrX r85w== 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=lx48cK2mO82aDssLzSprNsDu8ZPznwsFdIksxVa34nI=; b=H8bDq9S7U04X+H1fxCAfiwjDETOOyh35fAQdRWANkXPv8uv5zbKpLpl+nXQhNaido9 g9ZF4It8TZawHJwUXygdOqA4mE6TakNRMtPZ5T8F0pIDeRS9iQYo8wbgLhOWxb7f8w5p j6Ud3qC6IYYGY5YHXvpOn6HnMMwhongqQXRctGRYyZpD8uZqNHyknPCrYfzZU4aPO019 xwUrpME4TtmmLH30jlPhwPCT+DgUBfZ7vx56xrpAWd+QP6JMYRbJqxpnk4+yzrZxWNf+ hbCdyVyFgpowGAfi1TqVqaUExdPAHV/ki05cT3YaX+6lkoT3Tx9W/KTiLkjSTq0s59EW o9OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p9TgEkgH; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d16-20020a170906545000b007262944c626si16278368ejp.873.2022.07.19.12.06.01; Tue, 19 Jul 2022 12:06:27 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=p9TgEkgH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239942AbiGSSND (ORCPT + 99 others); Tue, 19 Jul 2022 14:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232034AbiGSSM7 (ORCPT ); Tue, 19 Jul 2022 14:12:59 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13E0D545C7; Tue, 19 Jul 2022 11:12:59 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id e16so14295588pfm.11; Tue, 19 Jul 2022 11:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lx48cK2mO82aDssLzSprNsDu8ZPznwsFdIksxVa34nI=; b=p9TgEkgHFMpUpt8wgKRPpuHLgFeJrKGezWQlCxEX4DQ61ebKgRddD+aVPtRsontDul ca6oZocVqAoNx70rWVOPSck2idBpruWwjRF9/JkYWKsGBmaMfTEM3C8tRdIK4wqUFqIk xwx/4slk+6G8ioesR/3sUY6aMNII0OK8U20ktYgy4P2zwOQJXhwUPn4bvnxege9pKhCa axHzwWGGfXo6/nTXsj7Scbu9BzLt4/rG8nwQ6z6PFTx7HmmVS+mWLpvD0KQ0jBJFenTD x7+1Kddu5yczhWCu0Oj84gAxY91LaMtowvXKmeSe1bkWmciLyy0NdzEl63mv7nLMf3e9 jG1w== 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=lx48cK2mO82aDssLzSprNsDu8ZPznwsFdIksxVa34nI=; b=TN+/Q8PGXkIpquw5O6fXtwJ7feybXBR71T7+KVyav8fh6gcAn54q/as9fF2eCe1ffA kfQNJbHREAdEbqRba5rRv5K2hlbnpQeHPq5bKUxL+8jXdr6caFqtVvSlD2eJn+C/6RVx 7d3oO3Coq3yc+I6xfEWYHHP23DjEphYoBxiYgVV4+neOc7Mv1JQ24hAQgPJW5rhzJHkw v69Bn/z5I6jPW4FioVO/5uNTK9TDgJoY17prom9VWhLLj6jSKspReeKUKSDa25LLXBE3 +n+mjvzGnoALBs7vdCC1Ug92Ia7epXjFHfmOrK0JqB2aYsscvzdcfXDTT4zEsCCDcqtz BnvQ== X-Gm-Message-State: AJIora9BMDDesmPPxVEkxiFwePioNnYPXb9pdqSObsypcACjydeeFCFm RHIGxekMuD9KUhaKbwpVlfY= X-Received: by 2002:a63:5810:0:b0:40d:77fb:1c25 with SMTP id m16-20020a635810000000b0040d77fb1c25mr30287980pgb.570.1658254378556; Tue, 19 Jul 2022 11:12:58 -0700 (PDT) Received: from localhost (fmdmzpr02-ext.fm.intel.com. [192.55.54.37]) by smtp.gmail.com with ESMTPSA id n12-20020a170902f60c00b0016d0beb6ce0sm1897179plg.246.2022.07.19.11.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 11:12:58 -0700 (PDT) Date: Tue, 19 Jul 2022 11:12:56 -0700 From: Isaku Yamahata To: Chao Gao Cc: Yuan Yao , isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini Subject: Re: [PATCH v7 053/102] KVM: TDX: don't request KVM_REQ_APIC_PAGE_RELOAD Message-ID: <20220719181256.GB1379820@ls.amr.corp.intel.com> References: <20220712034743.glrfvpx54ja6jrzg@yy-desk-7060> <20220712061439.GA28707@gao-cwp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220712061439.GA28707@gao-cwp> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 On Tue, Jul 12, 2022 at 02:14:45PM +0800, Chao Gao wrote: > On Tue, Jul 12, 2022 at 11:47:43AM +0800, Yuan Yao wrote: > >On Mon, Jun 27, 2022 at 02:53:45PM -0700, isaku.yamahata@intel.com wrote: > >> From: Isaku Yamahata > >> > >> TDX doesn't need APIC page depending on vapic and its callback is > >> WARN_ON_ONCE(is_tdx). To avoid unnecessary overhead and WARN_ON_ONCE(), > >> skip requesting KVM_REQ_APIC_PAGE_RELOAD when TD. > > !kvm_gfn_shared_mask() doesn't ensure the VM is a TD. Right? That's right. I changed the check as follows. commit 6753fc53f3b3fcbbd07ac688578ff5fb7f7f7d96 (HEAD) Author: Isaku Yamahata Date: Wed Mar 30 22:32:03 2022 -0700 KVM: TDX: don't request KVM_REQ_APIC_PAGE_RELOAD TDX doesn't need APIC page depending on vapic and its callback is WARN_ON_ONCE(is_tdx). To avoid unnecessary overhead and WARN_ON_ONCE(), skip requesting KVM_REQ_APIC_PAGE_RELOAD when TD. WARNING: arch/x86/kvm/vmx/main.c:696 vt_set_apic_access_page_addr+0x3c/0x50 [kvm_intel] RIP: 0010:vt_set_apic_access_page_addr+0x3c/0x50 [kvm_intel] Call Trace: vcpu_enter_guest+0x145d/0x24d0 [kvm] kvm_arch_vcpu_ioctl_run+0x25d/0xcc0 [kvm] kvm_vcpu_ioctl+0x414/0xa30 [kvm] __x64_sys_ioctl+0xc0/0x100 do_syscall_64+0x39/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae Signed-off-by: Isaku Yamahata diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 51ba2d163ec4..bfd7ed6ba385 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10045,7 +10045,9 @@ void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, * Update it when it becomes invalid. */ apic_address = gfn_to_hva(kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT); - if (start <= apic_address && apic_address < end) + /* TDX doesn't need APIC page. */ + if (kvm->arch.vm_type != KVM_X86_TDX_VM && + start <= apic_address && apic_address < end) kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD); } -- Isaku Yamahata