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=-8.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 91C5AC2D0A3 for ; Fri, 6 Nov 2020 09:36:45 +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 F244B206FA for ; Fri, 6 Nov 2020 09:36:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="sOn49/Kv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F244B206FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.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.20545.46523 (Exim 4.92) (envelope-from ) id 1kayAc-00018Y-0O; Fri, 06 Nov 2020 09:36:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 20545.46523; Fri, 06 Nov 2020 09:36:33 +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 1kayAb-00018Q-TR; Fri, 06 Nov 2020 09:36:33 +0000 Received: by outflank-mailman (input) for mailman id 20545; Fri, 06 Nov 2020 09:36:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kayAa-00017l-Ol for xen-devel@lists.xenproject.org; Fri, 06 Nov 2020 09:36:32 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 22abde42-bc10-405d-a9ce-afd285c90d4b; Fri, 06 Nov 2020 09:36:29 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 16E0AABB2; Fri, 6 Nov 2020 09:36:29 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kayAa-00017l-Ol for xen-devel@lists.xenproject.org; Fri, 06 Nov 2020 09:36:32 +0000 X-Inumbo-ID: 22abde42-bc10-405d-a9ce-afd285c90d4b Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 22abde42-bc10-405d-a9ce-afd285c90d4b; Fri, 06 Nov 2020 09:36:29 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1604655389; 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=JtLLY79rVz1/b+gt5Ib9A6igOOIy5NEZdkH5oVbCQnk=; b=sOn49/Kv4bzE9dwrFdp7rPduHiaOUosQ6zk0SNy8925zZjyHbA6O0CahuD4p3U3yXkJdLf CJFwYxBkJ6j8y+qCqNnuNK6Ma/saDQ6m2NU2uFNrCxR0MId2N3+PE1YwD1+F20dqOgKo6o 1/8vJzt3QR0lbB5jYe1nSBOU49iY/ww= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 16E0AABB2; Fri, 6 Nov 2020 09:36:29 +0000 (UTC) Subject: [PATCH v2 4/9] x86/HAP: move nested-P2M flush calculations out of locked region From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , George Dunlap References: <4b63025f-164c-2e93-3d54-7a7f145ad046@suse.com> Message-ID: Date: Fri, 6 Nov 2020 10:36:28 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <4b63025f-164c-2e93-3d54-7a7f145ad046@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit By latching the old MFN into a local variable, these calculations don't depend on anything but local variables anymore. Hence the point in time when they get performed doesn't matter anymore, so they can be moved past the locked region. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -780,7 +780,7 @@ hap_write_p2m_entry(struct p2m_domain *p { struct domain *d = p2m->domain; uint32_t old_flags; - bool_t flush_nestedp2m = 0; + mfn_t omfn; int rc; /* We know always use the host p2m here, regardless if the vcpu @@ -790,21 +790,11 @@ hap_write_p2m_entry(struct p2m_domain *p paging_lock(d); old_flags = l1e_get_flags(*p); - - if ( nestedhvm_enabled(d) && (old_flags & _PAGE_PRESENT) - && !p2m_get_hostp2m(d)->defer_nested_flush ) { - /* We are replacing a valid entry so we need to flush nested p2ms, - * unless the only change is an increase in access rights. */ - mfn_t omfn = l1e_get_mfn(*p); - mfn_t nmfn = l1e_get_mfn(new); - - flush_nestedp2m = !(mfn_eq(omfn, nmfn) - && perms_strictly_increased(old_flags, l1e_get_flags(new)) ); - } + omfn = l1e_get_mfn(*p); rc = p2m_entry_modify(p2m, p2m_flags_to_type(l1e_get_flags(new)), p2m_flags_to_type(old_flags), l1e_get_mfn(new), - l1e_get_mfn(*p), level); + omfn, level); if ( rc ) { paging_unlock(d); @@ -817,7 +807,14 @@ hap_write_p2m_entry(struct p2m_domain *p paging_unlock(d); - if ( flush_nestedp2m ) + if ( nestedhvm_enabled(d) && (old_flags & _PAGE_PRESENT) && + !p2m_get_hostp2m(d)->defer_nested_flush && + /* + * We are replacing a valid entry so we need to flush nested p2ms, + * unless the only change is an increase in access rights. + */ + (!mfn_eq(omfn, l1e_get_mfn(new)) || + !perms_strictly_increased(old_flags, l1e_get_flags(new))) ) p2m_flush_nestedp2m(d); return 0;