From patchwork Wed Apr 1 11:39:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11469015 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 78F3381 for ; Wed, 1 Apr 2020 11:40:52 +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 5E5E420776 for ; Wed, 1 Apr 2020 11:40:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E5E420776 Authentication-Results: mail.kernel.org; dmarc=none (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 localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jJbiL-0006mG-G2; Wed, 01 Apr 2020 11:39:21 +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.89) (envelope-from ) id 1jJbiJ-0006m9-Ps for xen-devel@lists.xenproject.org; Wed, 01 Apr 2020 11:39:19 +0000 X-Inumbo-ID: 6c1cd318-740d-11ea-baa1-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6c1cd318-740d-11ea-baa1-12813bfff9fa; Wed, 01 Apr 2020 11:39:19 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 487BAACCA; Wed, 1 Apr 2020 11:39:18 +0000 (UTC) Subject: [PATCH 2/5] x86/p2m: don't assert that the passed in MFN matches for a remove From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <3fbe1d2e-034a-31d7-7207-52ef8b335529@suse.com> Message-ID: Date: Wed, 1 Apr 2020 13:39:16 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <3fbe1d2e-034a-31d7-7207-52ef8b335529@suse.com> Content-Language: en-US X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" guest_physmap_remove_page() gets handed an MFN from the outside, yet takes the necessary lock to prevent further changes to the GFN <-> MFN mapping itself. While some callers, in particular guest_remove_page() (by way of having called get_gfn_query()), hold the GFN lock already, various others (most notably perhaps the 2nd instance in xenmem_add_to_physmap_one()) don't. While it also is an option to fix all the callers, deal with the issue in p2m_remove_page() instead: Replace the ASSERT() by a conditional and split the loop into two, such that all checking gets done before any modification would occur. Signed-off-by: Jan Beulich Reviewed-by: Paul Durrant Acked-by: Andrew Cooper --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -773,7 +773,6 @@ p2m_remove_page(struct p2m_domain *p2m, { unsigned long i; gfn_t gfn = _gfn(gfn_l); - mfn_t mfn_return; p2m_type_t t; p2m_access_t a; @@ -784,15 +783,26 @@ p2m_remove_page(struct p2m_domain *p2m, ASSERT(gfn_locked_by_me(p2m, gfn)); P2M_DEBUG("removing gfn=%#lx mfn=%#lx\n", gfn_l, mfn); + for ( i = 0; i < (1UL << page_order); ) + { + unsigned int cur_order; + mfn_t mfn_return = p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0, + &cur_order, NULL); + + if ( p2m_is_valid(t) && + (!mfn_valid(_mfn(mfn)) || mfn + i != mfn_x(mfn_return)) ) + return -EILSEQ; + + i += (1UL << cur_order) - ((gfn_l + i) & ((1UL << cur_order) - 1)); + } + if ( mfn_valid(_mfn(mfn)) ) { for ( i = 0; i < (1UL << page_order); i++ ) { - mfn_return = p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0, - NULL, NULL); + p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0, NULL, NULL); if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) ) set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY); - ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) ); } } return p2m_set_entry(p2m, gfn, INVALID_MFN, page_order, p2m_invalid,