From patchwork Fri Aug 2 16:16:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11073857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D7391395 for ; Fri, 2 Aug 2019 16:18:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1145286C6 for ; Fri, 2 Aug 2019 16:18:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4CD028875; Fri, 2 Aug 2019 16:18:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C5BA286C6 for ; Fri, 2 Aug 2019 16:18:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htaEA-00022b-M8; Fri, 02 Aug 2019 16:16:22 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htaE9-00022S-6s for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 16:16:21 +0000 X-Inumbo-ID: dcdcffd5-b540-11e9-8980-bc764e045a96 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id dcdcffd5-b540-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 16:16:20 +0000 (UTC) Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: hAcvFRb5TIqJOsVdWHhDr7f7WeHBHABccqioPSVd6tDJPs2QfJ9G6v63iH1e1fDO9belvulNtP vissyUhsVxX/3aXOPSXW3XPXeyX2sZYYQWqJwaMl5TzRapMmT04OoGpm7RVkQZcV6Y5peYHv47 uQ/mB11x+goSlvVSmBKDFUPJ3s+hhft5cnVrMV6MFCykEj9x6YSo/++qsdaPy3Shiqwx3Llwn+ t4azuAoJUSlp8N12Fe0Wg1ipnclFVHvcc+05pCqXYJWSRPRxwLZTbrIvD8ZuE1lqdxgoXxEjcp Q+4= X-SBRS: 2.7 X-MesageID: 3952364 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3952364" From: George Dunlap To: Date: Fri, 2 Aug 2019 17:16:11 +0100 Message-ID: <20190802161611.4145-1-george.dunlap@citrix.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] mm: Safe to clear PGC_allocated on xenheap pages without an extra reference 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 , Paul Durrant , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Commits ec83f825627 "mm.h: add helper function to test-and-clear _PGC_allocated" (and subsequent fix-up 44a887d021d "mm.h: fix BUG_ON() condition in put_page_alloc_ref()") introduced a BUG_ON() to detect unsafe behavior of callers. Unfortunately this condition still turns out to be too strict. xenheap pages are somewhat "magic": calling free_domheap_pages() on them will not cause free_heap_pages() to be called: whichever part of Xen allocated them specially must call free_xenheap_pages() specifically. (They'll also be handled appropriately at domain destruction time.) Only crash Xen when put_page_alloc_ref() finds only a single refcount if the page is not a xenheap page. Signed-off-by: George Dunlap Reviewed-by: Jan Beulich --- NB this has been compile-tested only. CC: Andrew Cooper CC: Jan Beulich CC: Paul Durrant --- xen/include/xen/mm.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 977e45aae7..297fc6ad7b 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -666,15 +666,20 @@ static inline void share_xen_page_with_privileged_guests( static inline void put_page_alloc_ref(struct page_info *page) { /* - * Whenever a page is assigned to a domain then the _PGC_allocated bit - * is set and the reference count is set to at least 1. This function - * clears that 'allocation reference' but it is unsafe to do so without - * the caller holding an additional reference. I.e. the allocation - * reference must never be the last reference held. + * Whenever a page is assigned to a domain then the _PGC_allocated + * bit is set and the reference count is set to at least 1. This + * function clears that 'allocation reference' but it is unsafe to + * do so to domheap pages without the caller holding an additional + * reference. I.e. the allocation reference must never be the last + * reference held. + * + * (It's safe for xenheap pages, because put_page() will not cause + * them to be freed.) */ if ( test_and_clear_bit(_PGC_allocated, &page->count_info) ) { - BUG_ON((page->count_info & PGC_count_mask) <= 1); + BUG_ON((page->count_info & PGC_count_mask) <= 1 && + !(page->count_info & PGC_xen_heap)); put_page(page); } }