Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2113610pxb; Fri, 25 Mar 2022 11:19:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9s+wF/bOw7xeM9AiPOXE1C4jQS808Ri9UqkjBB2ET1pi+SD5Z4J8nIpusE2O//QjrU/C2 X-Received: by 2002:a17:902:ec8d:b0:154:7f38:cd40 with SMTP id x13-20020a170902ec8d00b001547f38cd40mr13038632plg.40.1648232361850; Fri, 25 Mar 2022 11:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648232361; cv=none; d=google.com; s=arc-20160816; b=jT5WT1j6Xx/caGmU5FPqZ0ayPGGsFRdeTNgY6QNzkUXkhQ1jyYkoGPihTxzHp/iRXs LCLgdTiHiN4bweQr1R9iRgNgxD0qEyyMJDgyCvugttHhTBngFSH61InwLdlto+VXJOcC rBox8gjJLAwYuuPbV+LjbVhNBzfn2+tefkQiaWyRvJg8DS9SEVjIT08FcOryW/dN56Ds TjuRTc2li/HCyZAvp0MiVzO9GQ1gtelQsQJu1Kqcx0X2o2YANQEfvDwMyZmNyF9YE6Vc zhXi2xMpr8Neq8xAkbw18oI2Hn64Qegj5v9TCL4d0gBKuOi1ObQY6TDAGePENhb0+2rm Q2Iw== 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=sxKFEDtkVHDp152TUqHwV7Qynzuw7D2VF2jr802SS7Q=; b=oIw0nl71srLHKCvcaK/+KuwmOg1p+gXjmqAmF2AANalNgcHjdUwWyNucaaTKMmKpfT vB1HNh2gVY0bnIfsR3aRPSfUvrvVZ+L+l6bCTA0yGbQSxi1EsYeIM0aoda/XbYgaYohj jFIv31gNm8hkKYtcpiZkXF77ZvzsHJ2hijf12jsh81ix8Zi1NRZR2ZWFcuLGsUv6sM/C 7GHbpaSriF0WeNVIQvMecPYIG0+g6dmtgnJZa+XLCVUecKH7STmS8eTDzOz6Y8AnejdT FowPAMkT8DbUlSMqmIdP7NjaLiUxcVWosb0fX3zLfXdr+u54vreYBGqTuzkpwpLfatdJ /C1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eGwnJZJl; 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=pass (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 k14-20020a170902ba8e00b00153b2d16441si3007950pls.73.2022.03.25.11.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:19:21 -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=@redhat.com header.s=mimecast20190719 header.b=eGwnJZJl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6CBC16219A; Fri, 25 Mar 2022 10:47:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355725AbiCYL2o (ORCPT + 99 others); Fri, 25 Mar 2022 07:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238578AbiCYL2m (ORCPT ); Fri, 25 Mar 2022 07:28:42 -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 3C94A70CF0 for ; Fri, 25 Mar 2022 04:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648207627; 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=sxKFEDtkVHDp152TUqHwV7Qynzuw7D2VF2jr802SS7Q=; b=eGwnJZJl3nDl/l+GagqjGfqgyCW1sGnoKry9Et9lwfsDqH2ZwRMjKXnkgbSfoAfrNjI0T3 r5zMZLOksjeZAStC6w4DIFllkGYSCrxIpFL2UsE7IY+QmTEm81GqJWvkJlWVt8X2Ux9el9 YFp2ha8wJhc/dQ6cOvPt7bjxwdceWUw= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-381-2xk_WrfuMyyccUwkDZI8ZQ-1; Fri, 25 Mar 2022 07:27:05 -0400 X-MC-Unique: 2xk_WrfuMyyccUwkDZI8ZQ-1 Received: by mail-ej1-f72.google.com with SMTP id i14-20020a17090639ce00b006dabe6a112fso3925627eje.13 for ; Fri, 25 Mar 2022 04:27:05 -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=sxKFEDtkVHDp152TUqHwV7Qynzuw7D2VF2jr802SS7Q=; b=GnxCtp5Ga0KevnQAcrxEDpjx2UeSS2zp3qJJX7W8604AEsdbaM6kQDzF8GqbJGcWbp ZQcqI7afQnhrH+1CVYiW2cH+bLO43CEmuux4Ti7AGybRks0hf+EaZ8C1iQnhVXsFzE8g 63+670iboitqaf6uzA8vn2675jt7vR+t6L0wyO3kzFfAGGT/dXRK47r4v03FgleBI3oy IpY7vLxk6IQm6ONOm+8chQ6Wp/9UXUHq6QaBk3wSHi13yHcQ1kCSdo9RwcO+8OvgfJnZ 4ySN+5lYZ9PDWxtYfOLhSeWvrPlYFAEG2SnW/NMjjoBaQYm+WwzlW3HZj9OPubPabXIM v00A== X-Gm-Message-State: AOAM530dZMka8XOBwtiu1a4CCEkIqsa0D/Estgm2Y0p8PRP4GDF0VdAx rV8wpkPf+IjlqaNzGApzM/wxnlzLMz4FKxOY8CPMX4sa+m+iumAb6sCi9iFeBUTsB6Bqq3Tgeul R0au4xrX+6O6oWGxDKi5Jekd/ X-Received: by 2002:a17:906:4ad0:b0:6e0:12aa:a911 with SMTP id u16-20020a1709064ad000b006e012aaa911mr11177145ejt.455.1648207624526; Fri, 25 Mar 2022 04:27:04 -0700 (PDT) X-Received: by 2002:a17:906:4ad0:b0:6e0:12aa:a911 with SMTP id u16-20020a1709064ad000b006e012aaa911mr11177120ejt.455.1648207624243; Fri, 25 Mar 2022 04:27:04 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:1c09:f536:3de6:228c? ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.googlemail.com with ESMTPSA id bm23-20020a170906c05700b006d597fd51c6sm2254888ejb.145.2022.03.25.04.27.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Mar 2022 04:27:03 -0700 (PDT) Message-ID: Date: Fri, 25 Mar 2022 12:26:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] KVM: x86/mmu: Don't rebuild page when the page is synced and no tlb flushing is required Content-Language: en-US To: Sean Christopherson , Hou Wenlong Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Lai Jiangshan , linux-kernel@vger.kernel.org References: <0dabeeb789f57b0d793f85d073893063e692032d.1647336064.git.houwenlong.hwl@antgroup.com> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 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/24/22 21:17, Sean Christopherson wrote: >> +static int kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, >> struct list_head *invalid_list) >> { >> int ret = vcpu->arch.mmu->sync_page(vcpu, sp); >> >> - if (ret < 0) { >> + if (ret < 0) >> kvm_mmu_prepare_zap_page(vcpu->kvm, sp, invalid_list); >> - return false; >> - } >> - >> - return !!ret; >> + return ret; > Hrm, this creates an oddity in mmu_sync_children(), which does a logical-OR of > the result into a boolean. It doesn't actually change the functionality since > kvm_mmu_remote_flush_or_zap() will prioritize invalid_list, but it's weird. > > What about checking invalid_list directly and keeping the boolean return? Compile > tested only. It's even better to check flush |= kvm_sync_page(vcpu, sp, &invalid_list) > 0; in mmu_sync_children. If the returned value is <0, then the page is added to invalid_list and there is no need to set flush = true, just like there is no need to call kvm_flush_remote_tlbs() in kvm_mmu_get_page(). Paolo