Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1005945pxb; Wed, 6 Apr 2022 06:32:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbvbEvlOVXo4NB06o+qhAiCAk5lw/WOg67DFe4QXvVvFKsBA3YLE1zCem15rPBZVMNfOCQ X-Received: by 2002:a63:185f:0:b0:386:1838:8d0 with SMTP id 31-20020a63185f000000b00386183808d0mr7114393pgy.161.1649251974429; Wed, 06 Apr 2022 06:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649251974; cv=none; d=google.com; s=arc-20160816; b=MwdvHjiRbE0F/R3Q9afWfTp36kEOSp6Nml0vfYYypLrieLhwIF6U57Vi7oxDzO53rk fFuZ3sz84dOazrkwRIIBSkuGKC/ZAnOwqtQPvMtFq5t7I/6FY2St5QPz5q3Xkl85st28 4YzAtaPAw3zOd1PorBKmNWa4/8SgYkqrSDQhG2gTQ3WeU5qLi7Jn6hj+pybT+rlh7o2N EjNpLfLDP8Yz3A/wwgDc4eXF82M+O7+k7ZH3JbJO+Vr3y7fW3/Sf0EWIx86uiqZyLV+N Y/CjJKvz+qdKEx9q2lBlI71ahkgkr6G/Ep7VdHNq6L0sQWEpTgJVacrViEy+oe+Osqis wRPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=NPr7NyzPsM6lb9uL4EUAQIbJ/AzbEssi4MJbl6X0Xkw=; b=niutd9WujKcFLFdagohds8pIG7PchWIFBXsuv+P3Ni373CpoMts08KVUunot24xTgI YbhL0vMU+U0IrPpeKx5p4tlIBJtoMo8jsMirGf3XZ3rPsoUE6vrkZ0BkDn3/k1+kofPy d59tyk1UAOQ68JnQ/Kh+iWMvcXJA19ijcr2dCv/uwsXeXZz44NLvuZ7weapATxFnHeSe AUAyqBUyYaqdwYDqR7opmbdoG4H8ZAWPeprCUd3anSGfL0ezrdllmQr20Ol8jHctiYtb XFe9FyfSbq6Y3fwUagpnILkDWHufiT1Pe3msWVUHzwV8BNwDPt9s/SpMryJBrW0uE7rl 3jTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gyfiaZjJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p3-20020a170903248300b00153b2d165c0si15162552plw.456.2022.04.06.06.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:32:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gyfiaZjJ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E48C95D3338; Wed, 6 Apr 2022 04:13:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444889AbiDEUIZ (ORCPT + 99 others); Tue, 5 Apr 2022 16:08:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388972AbiDEOln (ORCPT ); Tue, 5 Apr 2022 10:41:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9FCE612B767 for ; Tue, 5 Apr 2022 06:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649164633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NPr7NyzPsM6lb9uL4EUAQIbJ/AzbEssi4MJbl6X0Xkw=; b=gyfiaZjJmat9v0PEkyW5JNFs1MS19Ur+cA0Stj2apWveSJNIWM03RxuR/lH16CZp8ya/4S EIdfdRLo3HB9oBLTfpelAJX1Igmhl3R5qnFFCckaimVE8zIsir93jx33GqlFNe4ekpedt/ d+sZk+P7e5zIv4zmoF6daZyuq2hEzjA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-197-C5MEeRjqMN6bI0GoTEJNyA-1; Tue, 05 Apr 2022 09:17:12 -0400 X-MC-Unique: C5MEeRjqMN6bI0GoTEJNyA-1 Received: by mail-wm1-f72.google.com with SMTP id x8-20020a7bc768000000b0038e73173886so1238104wmk.6 for ; Tue, 05 Apr 2022 06:17:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=NPr7NyzPsM6lb9uL4EUAQIbJ/AzbEssi4MJbl6X0Xkw=; b=ooTvWU+5+uwieKLsbvTCCN4Cfuw2YuEgGnwpnb922sPNhY9I3ezEwgxXPTzDRrllzy IdiH62WgPxD8CU0NIDtZReV1Ma9OOOqvPgw+zdtcxYco23AdGA3uvt57ycvsKcU6rKsQ gVu5RfoifpXushA1czc4bvEbLPE3TVNOh7WotgFbu64w2Yr7SWskBBLH3UccFNZxI5n/ zVUZF6JdbiM1OUitO3gaBckdYRyNxzfCAVQ1nV9vrKr1812SwfPlNrMBohrTU/g6mZ/J f2+shn8AgbdJHGgyumJ5d96dMpMuat4JXV4Tx9BIopL/N5mna7o8cwzuj/BIM8AgYzDv PLZg== X-Gm-Message-State: AOAM533Bkxwg/6wvG5welr5vIuXodWIcgsnNEfEbxleri+tFb6Xu/E8k sqD/d1a8aHj0IT/LCFMY7j5f3ZEYBd2he1JMK+gbFQi5gsjnpvm0H1dVAMxZYN3spR00fZaGD5U PbOesCe8SvQ7E7dfuDKFFWtuh X-Received: by 2002:a7b:c0c9:0:b0:38e:7d65:6e7f with SMTP id s9-20020a7bc0c9000000b0038e7d656e7fmr3069459wmh.168.1649164631099; Tue, 05 Apr 2022 06:17:11 -0700 (PDT) X-Received: by 2002:a7b:c0c9:0:b0:38e:7d65:6e7f with SMTP id s9-20020a7bc0c9000000b0038e7d656e7fmr3069438wmh.168.1649164630849; Tue, 05 Apr 2022 06:17:10 -0700 (PDT) Received: from [10.32.181.87] (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.googlemail.com with ESMTPSA id n65-20020a1c2744000000b003862bfb509bsm2115805wmn.46.2022.04.05.06.17.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Apr 2022 06:17:10 -0700 (PDT) Message-ID: <68e1fd5f-d58b-695b-0fc7-bdc3e5491de7@redhat.com> Date: Tue, 5 Apr 2022 15:17:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [RFC PATCH v5 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault Content-Language: en-US To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson References: From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 3/4/22 20:48, isaku.yamahata@intel.com wrote: > From: Sean Christopherson > > Explicitly check for an MMIO spte in the fast page fault flow. TDX will > use a not-present entry for MMIO sptes, which can be mistaken for an > access-tracked spte since both have SPTE_SPECIAL_MASK set. > > The fast page fault handles the case of changing access bits without > obtaining mmu_lock. For example, clear write protect bit for dirty page > tracking. MMIO emulation is handled in a slow path. So it doesn't affect "MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so this patch does not affect them. TDX will handle MMIO emulation through a hypercall instead". For this comment, it is not necessary to talk about the slow path, since that is just where MMIO sptes are installed. If the slow path is reached, fast_page_fault must not have seen is_mmio_spte(spte). > @@ -3167,7 +3167,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > break; > > sp = sptep_to_sp(sptep); > - if (!is_last_spte(spte, sp->role.level)) > + if (!is_last_spte(spte, sp->role.level) || is_mmio_spte(spte)) > break; > > /* I would include the check a couple lines before: if (!is_shadow_present_pte(spte) || is_mmio_spte(spte)) This matches what is in the commit message: the problem is that MMIO SPTEs are present in the TDX case, so you need to check them even if is_shadow_present_pte(spte) returns true. Paolo