Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp959425pxb; Wed, 6 Apr 2022 05:20:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwojGNNy3WGrGl7F2XRuo9qWk9v7ipNljDg+8rEY4HuWlCracMYq3yH+d+GpeONpu+4aT/6 X-Received: by 2002:a17:902:ea04:b0:154:54f0:172b with SMTP id s4-20020a170902ea0400b0015454f0172bmr8220208plg.149.1649247657874; Wed, 06 Apr 2022 05:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649247657; cv=none; d=google.com; s=arc-20160816; b=Zbtp9lzmpO0Afgl5eUbfALNGycdZkAuEQYbNrPTwCWC5BKSEKIJdPc3qS4Pv10Kkk/ dPU/jCIineT9hJIPH1P4+5weNWVrd3wcHMAoB5PgpMabfpCw3IH8rcwkgpIOhk6yz2op g65TPmcCyl4+3jqKqjJSwPSSY9siPPZPPoidoVlPaOfrRHHk0OHhd0nNbXDxxIfSKy/h Mks5J4lUWmqKWZMu/cGBwbhCteTCcWPbSLUlp8Qmfew7dLkEi4UaAAUH9iGtMcQmfsY1 Bpqa0xDjqT5MZvMA0NRNd59bxwk0drHt7x71RdCQzksuYt7wYBbX7pu4ePO4sazAAkZk uiSg== 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:sender:dkim-signature; bh=+obo3dTEvSnGwmrHTDGj7IsutLaAztXJd9lK133Uuvo=; b=R/ciHXDQzc5t0mhM+wJycCM7p3H8IvS7WF4mPChfiS/whVHU7jGVg7vvD5ruXr4hf+ O+9VWNXZlPnXrhLqoccz+4lJLtK3ZBbFH+sZHMkbhPVF5anUCLbJ1t82RNh5YHdoF4GQ /gt9Yk51kdt0G/Sz9RsOC7GAXJRDvaHnEGu55aPqPtSIQBr90F/PtwxE+TwPhdpwBChb C2ZdGVxwAUQ6rHgctmYmw2TkJhE3gOXiqg97l6Y5vVXhXNCaln7HeRVoz4/XT8zTbB3s MRWrMdlgCeq/QhcsvjMrQd5K/OUCM5GHg85lz7jxU726yLLJVbvRl7sFHJFTEM9u/msU oOXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VfYxeW30; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 24-20020a631858000000b003823e1bfe39si15463587pgy.650.2022.04.06.05.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:20:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VfYxeW30; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (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 57ED65DE28A; Wed, 6 Apr 2022 04:17:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239086AbiDFBVz (ORCPT + 99 others); Tue, 5 Apr 2022 21:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1446290AbiDEPo0 (ORCPT ); Tue, 5 Apr 2022 11:44:26 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6873EF4E; Tue, 5 Apr 2022 07:13:36 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id k124-20020a1ca182000000b0038c9cf6e2a6so1758569wme.0; Tue, 05 Apr 2022 07:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=+obo3dTEvSnGwmrHTDGj7IsutLaAztXJd9lK133Uuvo=; b=VfYxeW309B7qGu5esco2QMkFCu6G6mGgJZ/7v8UJu4M3oqeTqLdCKy+aQe2MCk7aMO kMEbJrfpFmDIoqqmXEHM59o6bABYuWObSqmDEae2x33PnucQV4FLMP4dzti02kwmj16w Mi+f22V0Fo38phqCCyN1uib5VBjnpc4qiJHd7UpVqU2QJqWCF+MzPB53V6j7v3K4PgDS jEhde1If7rpH2oZQ4zWvTsFrR7kMoiXns+bzZ7Ir5ppm+1rBWQVEQznuQWv4Y3EesLHW TxVy/QJsb/wO9Xc+h3lcNoySiXAg7iH6z834ZpXcL2pGo5mzQyyhDmciuc6dJvXNEEV2 GU5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=+obo3dTEvSnGwmrHTDGj7IsutLaAztXJd9lK133Uuvo=; b=2SRcwYRL20JefCtUvoxJ5wH6USX9NQcVU/6I2U3SBR7RqOxJoFI5sB2VQQmKTRU4n0 s4+dUNviplt6pun83JzNWPHJlpHWu8oIDYfROqziJJuT1nZc/MC/H0FyG9hqQgdyh3up /LI63tz0F2Hp6JqU/2C2BgIvr5euAP4rnUlz+Ca4JOw5QYSd1AyPpkTe46wIYmHLgFJ3 HD6ozh9rXS6jN05kMZhp03NzBKM3ZnOc0N6r/1UjhexYSLOzIxiyKbxG0LMpK+wDiEC2 CeT/BVAbcPH4LDweTWmuxCqnMd+80UI+/07Quz0h7AAj1jzRPUbNaDYlnUijY9pYVQ1E w0YQ== X-Gm-Message-State: AOAM5307FeNzsOsgV6fbrZ67YKmceo5vLP1qq/JdN+6cFzrYtzRbURaM ejy+AQl6155uXun0MI+M8UY= X-Received: by 2002:a05:600c:3c9b:b0:38e:4c59:68b9 with SMTP id bg27-20020a05600c3c9b00b0038e4c5968b9mr3333948wmb.105.1649168014583; Tue, 05 Apr 2022 07:13:34 -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 p18-20020a1c5452000000b0038e70261309sm2347702wmi.1.2022.04.05.07.13.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Apr 2022 07:13:34 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <9dfc44d6-6b20-e864-8d4f-09ab7d489b97@redhat.com> Date: Tue, 5 Apr 2022 16:13:33 +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 037/104] KVM: x86/mmu: Allow non-zero init value for shadow PTE Content-Language: en-US To: Kai Huang , 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: <968de4765e63d8255ae1b3ac7062ffdca64706e4.camel@intel.com> From: Paolo Bonzini In-Reply-To: <968de4765e63d8255ae1b3ac7062ffdca64706e4.camel@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 4/1/22 07:13, Kai Huang wrote: >> @@ -617,9 +617,9 @@ static int mmu_spte_clear_track_bits(struct kvm *kvm, u64 *sptep) >> int level = sptep_to_sp(sptep)->role.level; >> >> if (!spte_has_volatile_bits(old_spte)) >> - __update_clear_spte_fast(sptep, 0ull); >> + __update_clear_spte_fast(sptep, shadow_init_value); >> else >> - old_spte = __update_clear_spte_slow(sptep, 0ull); >> + old_spte = __update_clear_spte_slow(sptep, shadow_init_value); (FWIW this one should also assume that the init_value is zero, and WARN if not). > I guess it's better to have some comment here. Allow non-zero init value for > shadow PTE doesn't necessarily mean the initial value should be used when one > PTE is zapped. I think mmu_spte_clear_track_bits() is only called for mapping > of normal (shared) memory but not MMIO? Then perhaps it's better to have a > comment to explain we want "suppress #VE" set to get a real EPT violation for > normal memory access from guest? > >> >> if (!is_shadow_present_pte(old_spte)) >> return old_spte; >> @@ -651,7 +651,7 @@ static int mmu_spte_clear_track_bits(struct kvm *kvm, u64 *sptep) >> */ >> static void mmu_spte_clear_no_track(u64 *sptep) >> { >> - __update_clear_spte_fast(sptep, 0ull); >> + __update_clear_spte_fast(sptep, shadow_init_value); >> } > Similar here. Seems mmu_spte_clear_no_track() is used to zap non-leaf PTE which > doesn't require state tracking, so theoretically it can be set to 0. But this > seems is also called to zap MMIO PTE so looks need to set to shadow_init_value. > Anyway looks deserve a comment? > > Btw, Above two changes to mmu_spte_clear_track_bits() and > mmu_spte_clear_track_bits() seems a little bit out-of-scope of what this patch > claims to do. Allow non-zero init value for shadow PTE doesn't necessarily mean > the initial value should be used when one PTE is zapped. Maybe we can further > improve the patch title and commit message a little bit. Such as: Allow non- > zero value for empty (or invalid?) PTE? Non-present seems doesn't fit here. I think shadow_init_value is not named well. Let's rename it to shadow_nonpresent_value, and the commit to "Allow non-zero value for non-present SPTE". That explains why it's used for zapping. Paolo