From patchwork Wed Oct 28 09:24:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11862639 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFEEC92C for ; Wed, 28 Oct 2020 09:25:24 +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 B2F0C24680 for ; Wed, 28 Oct 2020 09:25:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="VJI6vy9R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2F0C24680 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.13431.34069 (Exim 4.92) (envelope-from ) id 1kXhgk-0005Z6-BI; Wed, 28 Oct 2020 09:24:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 13431.34069; Wed, 28 Oct 2020 09:24:14 +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 1kXhgk-0005Yz-8I; Wed, 28 Oct 2020 09:24:14 +0000 Received: by outflank-mailman (input) for mailman id 13431; Wed, 28 Oct 2020 09:24:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kXhgj-0005Yr-IG for xen-devel@lists.xenproject.org; Wed, 28 Oct 2020 09:24:13 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ca21e3f6-7e57-4e2c-be35-2f85bffc0e51; Wed, 28 Oct 2020 09:24:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 14286ACAC; Wed, 28 Oct 2020 09:24:12 +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 1kXhgj-0005Yr-IG for xen-devel@lists.xenproject.org; Wed, 28 Oct 2020 09:24:13 +0000 X-Inumbo-ID: ca21e3f6-7e57-4e2c-be35-2f85bffc0e51 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ca21e3f6-7e57-4e2c-be35-2f85bffc0e51; Wed, 28 Oct 2020 09:24:12 +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=1603877052; 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=VJI6vy9R90Vs2E3wVekuCxGJTGtQbMA4OcA0MkysEL29mIv9ddl22Dg2FTzRuu9F7+yyZf YZXwFWeCwK6agSPEID1Bc/CPdV4b0T3p8fvmZN/JucbKeOGA2IhHk3RlzULuld3IebIm4u DDcocneMpPBPVgjW78gYTUevI12lO4Q= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 14286ACAC; Wed, 28 Oct 2020 09:24:12 +0000 (UTC) Subject: [PATCH 4/5] 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: <29d30de1-2a8d-aee2-d3c3-331758766fc9@suse.com> Message-ID: <551dc0a2-f5ef-a646-26eb-8a67ae428745@suse.com> Date: Wed, 28 Oct 2020 10:24:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <29d30de1-2a8d-aee2-d3c3-331758766fc9@suse.com> Content-Language: en-US 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 Acked-by: Roger Pau Monné --- 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;