From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AF53C55179 for ; Wed, 21 Oct 2020 16:53:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 041782173E for ; Wed, 21 Oct 2020 16:53:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="IJCj2Tjk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 041782173E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.10118.26720 (Exim 4.92) (envelope-from ) id 1kVHMs-0002NA-M3; Wed, 21 Oct 2020 16:53:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 10118.26720; Wed, 21 Oct 2020 16:53:42 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVHMs-0002N3-Ig; Wed, 21 Oct 2020 16:53:42 +0000 Received: by outflank-mailman (input) for mailman id 10118; Wed, 21 Oct 2020 16:53:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVHMr-0002My-Uy for xen-devel@lists.xenproject.org; Wed, 21 Oct 2020 16:53:42 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8675a79f-4375-439e-86e0-7001351bea17; Wed, 21 Oct 2020 16:53:40 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVHMr-0002My-Uy for xen-devel@lists.xenproject.org; Wed, 21 Oct 2020 16:53:42 +0000 X-Inumbo-ID: 8675a79f-4375-439e-86e0-7001351bea17 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8675a79f-4375-439e-86e0-7001351bea17; Wed, 21 Oct 2020 16:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1603299220; h=subject:from:to:cc:references:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=pGLUYrgKfbt27QziQs8IU9vQTxO7MYaXgcxQoQKaQgI=; b=IJCj2TjkjeBARGp0LZHpY7wjM8bloYvyKe1L/StFEnlUqL4emnpo07UF K1kuygdILVVMumfi/oZv9bL9c8x8LFSAxduMbIqBsXuFmSMRr8laqPh71 qnpPZN9sLaVL6lpTKyOI1hXTfzkhEJoBkzRyvzUwLY0RMTbXxFTuiPi57 w=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: xwtpIL3xebimPrSkhT64oPOtMbqNU22vaZVVDEEbYF5vua5ZBvjXlYkV/Hq4M03rkOG/kkRD6V SX96RV4KWkVIPXtQrpdhE0vPJPcqnixZtBayMYa4vXuZ6j8we9ZdfKbg/hChtkkZcHDV1T8Z09 iB4JeCaSe/NeVnJUaI4t9wjZXX/88cmWhyCRmPNFc3S5F+8K2E2SwdCL+XxgDFSN4GNV4+ycg+ JWxXo4xqTbAqha2gj3QWKXm8HJonWY16C4i+5U8nBNpDwWgQmge1ScyBIkiiSNRjdR8GB0Wo/b UnI= X-SBRS: 2.5 X-MesageID: 29833932 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.77,401,1596513600"; d="scan'208";a="29833932" Subject: Re: [PATCH] x86/pv: Flush TLB in response to paging structure changes From: Andrew Cooper To: Jan Beulich CC: Xen-devel , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , Wei Liu References: <20201021130708.12249-1-andrew.cooper3@citrix.com> <7967fa6e-213d-50e2-87d3-dbd319aa2060@suse.com> <9fe3d967-6bfe-71ef-6430-029de97dca8c@citrix.com> Message-ID: <72c9dfbd-3ace-ee66-51a6-9490cdf5ffc9@citrix.com> Date: Wed, 21 Oct 2020 17:53:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: en-GB X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To FTLPEX02CL05.citrite.net (10.13.108.178) On 21/10/2020 16:55, Andrew Cooper wrote: > On 21/10/2020 16:39, Andrew Cooper wrote: >>>> @@ -4051,27 +4057,28 @@ long do_mmu_update( >>>> break; >>>> rc = mod_l4_entry(va, l4e_from_intpte(req.val), mfn, >>>> cmd == MMU_PT_UPDATE_PRESERVE_AD, v); >>>> - if ( !rc && pt_owner->arch.pv.xpti ) >>>> + /* Paging structure maybe changed. Flush linear range. */ >>>> + if ( !rc ) >>>> { >>>> - bool local_in_use = false; >>>> + bool local_in_use = mfn_eq( >>>> + pagetable_get_mfn(curr->arch.guest_table), mfn); >>>> >>>> - if ( mfn_eq(pagetable_get_mfn(curr->arch.guest_table), >>>> - mfn) ) >>>> - { >>>> - local_in_use = true; >>>> - get_cpu_info()->root_pgt_changed = true; >>>> - } >>>> + flush_flags_all |= FLUSH_TLB; >>>> + >>>> + if ( local_in_use ) >>>> + flush_flags_local |= FLUSH_TLB | FLUSH_ROOT_PGTBL; >>> Aiui here (and in the code consuming the flags) you build upon >>> flush_flags_local, when not zero, always being a superset of >>> flush_flags_all. I think this is a trap to fall into when later >>> wanting to change this code, but as per below this won't hold >>> anymore anyway, I think. Hence here I think you want to set >>> FLUSH_TLB unconditionally, and above for L3 and L2 you want to >>> set it in both variables. Or, if I'm wrong below, a comment to >>> that effect may help people avoid falling into this trap. >>> >>> An alternative would be to have >>> >>> flush_flags_local |= (flush_flags_all & FLUSH_TLB); >>> >>> before doing the actual flush. > Also, what I forgot to say in the previous reply, this is still buggy if > hypothetically speaking FLUSH_CACHE had managed to be accumulated in > flush_flags_all. > > You cannot have general accumulation logic, a special case for local, > and any catch-all logic like that, because the only correct way to do > the catch-all logic will clobber the special case for local. I'm going to try a 3rd time with flush_flags and local_may_skip which defaults to GLOBAL|ROOT_PGTBL, and may get clobbered. This seems like it might be a less fragile way of expressing the optimisation. ~Andrew