From nobody Mon Apr 29 04:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563392113; cv=none; d=zoho.com; s=zohoarc; b=lg4odEb9cxTddYs0+1vLNwfHy59msgmLmS3CBrJAX/NJeVWQzpjjX7bwbk2mDBYVTLoW+z2t8bjDhzO8RmlVdR3DtdwkZgZlolv7IoqaAxyPTeqXoiXZ7IG7fxAVhyc/m0gWGMvFWIxY2O1fk0loUixmB7CsCG/3Cmq/wZ19JC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563392113; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=E5dI/1iIWAx4u+hXOcbgCbtGG7wFIk84R/ZYx8uT2xo=; b=CgBLumCS64YTSv6QjdrvudN8sYMJ770jzKJCSqcRjtqgetXoBfOOtbqFv6sKG8Rl91RQN7LsoFOCb8ws4xWsgJYVg0trwRfOpbTW3rhQR+WaVemZaFNc81cq2cBVmZbLZb/II9dkK/2II0PTEf4QKYVjJrBoNrDR9eRqlNXrUvk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563392113910615.1066612991686; Wed, 17 Jul 2019 12:35:13 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnpgf-0000Hd-01; Wed, 17 Jul 2019 19:34:00 +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 1hnpgd-0000HL-KS for xen-devel@lists.xenproject.org; Wed, 17 Jul 2019 19:33:59 +0000 Received: from mail-io1-f68.google.com (unknown [209.85.166.68]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d0043070-a8c9-11e9-be02-ebb5fa9022dc; Wed, 17 Jul 2019 19:33:54 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id k20so47594701ios.10 for ; Wed, 17 Jul 2019 12:33:54 -0700 (PDT) Received: from l1.lan (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id v13sm21743421ioq.13.2019.07.17.12.33.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 12:33:53 -0700 (PDT) X-Inumbo-ID: d0043070-a8c9-11e9-be02-ebb5fa9022dc X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JBw7l33La8xVqfg8L17ATjz/BcMg+hI1A6l2yXVZeo0=; b=Y3zTD7jqvwRSnSm5ATNyLUuheKGYsi1AD5YmxIE/F4OQUc3Q4wcfTT6cmG3Dgr3o58 euNHSEUvjBEfKtQ+y7v02eFIH8YF9WE1H3KdjRMCSuQU0BWBOMkYt2H7v5HWv66s6xBn eNC1rJbvY82Bbx81fevk2vOu9TDayhssYJRIqDgYU+JNlHwpX+9nU6ubSx3BIANUMb5R J7xySNEulGo4+EBR++qrAnrV9YzAmcoQLhHMvEjN7pg0qBBs/8kMlC4XhNojR4H1HLx3 FBsOkXVwtOVk4dmpPG9/mFBQqueKq1qRxTbfEXiway20YIjwAMIJkVM3P7/AHO0pxcrx n/oA== X-Gm-Message-State: APjAAAVis7ZJD6SQiY0iK/X0JkX513j17YvQLIHY8YkrA6cg+lM9zx60 ULIt25LZZOfQOfbO73QYFOsUExKq X-Google-Smtp-Source: APXvYqxg5NYQFGxMFuUPXTARLsjdGTi74JswUYe2OqezGVQUMo2s4PVGcQioR4sbN17+sHslUc7/+g== X-Received: by 2002:a6b:b985:: with SMTP id j127mr38797426iof.186.1563392033796; Wed, 17 Jul 2019 12:33:53 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 17 Jul 2019 13:33:31 -0600 Message-Id: <20190717193335.11991-2-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717193335.11991-1-tamas@tklengyel.com> References: <20190717193335.11991-1-tamas@tklengyel.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 1/5] x86/mem_sharing: reorder when pages are unlocked and released 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: Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Calling _put_page_type while also holding the page_lock for that page can cause a deadlock. The comment being dropped is incorrect since it's now out-of-date. Signed-off-by: Tamas K Lengyel Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap Cc: Wei Liu Cc: Roger Pau Monne --- v6: rebase on staging v5: BUG_ON early before releasing references --- xen/arch/x86/mm/mem_sharing.c | 40 +++++++++++------------------------ 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 58d9157fa8..6c033d1488 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -648,10 +648,6 @@ static int page_make_private(struct domain *d, struct = page_info *page) return -EBUSY; } =20 - /* We can only change the type if count is one */ - /* Because we are locking pages individually, we need to drop - * the lock here, while the page is typed. We cannot risk the=20 - * race of page_unlock and then put_page_type. */ expected_type =3D (PGT_shared_page | PGT_validated | PGT_locked | 2); if ( page->u.inuse.type_info !=3D expected_type ) { @@ -660,12 +656,11 @@ static int page_make_private(struct domain *d, struct= page_info *page) return -EEXIST; } =20 + mem_sharing_page_unlock(page); + /* Drop the final typecount */ put_page_and_type(page); =20 - /* Now that we've dropped the type, we can unlock */ - mem_sharing_page_unlock(page); - /* Change the owner */ ASSERT(page_get_owner(page) =3D=3D dom_cow); page_set_owner(page, d); @@ -900,6 +895,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, s= hr_handle_t sh, p2m_type_t smfn_type, cmfn_type; struct two_gfns tg; struct rmap_iterator ri; + unsigned long put_count =3D 0; =20 get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn, cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg); @@ -964,15 +960,6 @@ static int share_pages(struct domain *sd, gfn_t sgfn, = shr_handle_t sh, goto err_out; } =20 - /* Acquire an extra reference, for the freeing below to be safe. */ - if ( !get_page(cpage, dom_cow) ) - { - ret =3D -EOVERFLOW; - mem_sharing_page_unlock(secondpg); - mem_sharing_page_unlock(firstpg); - goto err_out; - } - /* Merge the lists together */ rmap_seed_iterator(cpage, &ri); while ( (gfn =3D rmap_iterate(cpage, &ri)) !=3D NULL) @@ -984,13 +971,14 @@ static int share_pages(struct domain *sd, gfn_t sgfn,= shr_handle_t sh, * Don't change the type of rmap for the client page. */ rmap_del(gfn, cpage, 0); rmap_add(gfn, spage); - put_page_and_type(cpage); + put_count++; d =3D get_domain_by_id(gfn->domain); BUG_ON(!d); BUG_ON(set_shared_p2m_entry(d, gfn->gfn, smfn)); put_domain(d); } ASSERT(list_empty(&cpage->sharing->gfns)); + BUG_ON(!put_count); =20 /* Clear the rest of the shared state */ page_sharing_dispose(cpage); @@ -1001,7 +989,9 @@ static int share_pages(struct domain *sd, gfn_t sgfn, = shr_handle_t sh, =20 /* Free the client page */ put_page_alloc_ref(cpage); - put_page(cpage); + + while ( put_count-- ) + put_page_and_type(cpage); =20 /* We managed to free a domain page. */ atomic_dec(&nr_shared_mfns); @@ -1165,19 +1155,13 @@ int __mem_sharing_unshare_page(struct domain *d, { if ( !last_gfn ) mem_sharing_gfn_destroy(page, d, gfn_info); - put_page_and_type(page); + mem_sharing_page_unlock(page); + if ( last_gfn ) - { - if ( !get_page(page, dom_cow) ) - { - put_gfn(d, gfn); - domain_crash(d); - return -EOVERFLOW; - } put_page_alloc_ref(page); - put_page(page); - } + + put_page_and_type(page); put_gfn(d, gfn); =20 return 0; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 04:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563392111; cv=none; d=zoho.com; s=zohoarc; b=PnXYC4vMiUB+NhxpeXaHJ7cEUdMMTkRH5rLXJxpKoS1mtHA1sT//a4AKW/dPmjoXqNBsqi/LYV4cgnjX4szC9bauD/0kS8Oq1gGA4Mv5aGLny7pAkC51tAat611irtGjwg5h0xZRs9WiaC033MMJLQBuBsCfgd6NS9RjB7oZsjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563392111; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=eXfcQABZhRT6xClAUV/3WzKSevNyvYL1BFC0Zbwm+Fo=; b=aXHM8N82Np79752/m1GE5aMtC+CO2EkHh5EGBRjY8z++Z5dA0qyXJJhIl+Bu3Feq4QrKr0EtI8YXY3hpSn1VFY5GanZu+lCbETLurfoBud97SmI3RjalAjvvTLXQT/jEdv6/Qw4KGyq3B6cgE3Q7pzxhLS/mzb7GIofEoPloRdo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563392111805984.8912977815693; Wed, 17 Jul 2019 12:35:11 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnpgf-0000Hl-9N; Wed, 17 Jul 2019 19:34:01 +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 1hnpgd-0000HM-L8 for xen-devel@lists.xenproject.org; Wed, 17 Jul 2019 19:33:59 +0000 Received: from mail-io1-f65.google.com (unknown [209.85.166.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d0f0b3d2-a8c9-11e9-8afc-8b45d339bfd7; Wed, 17 Jul 2019 19:33:56 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id j5so43432508ioj.8 for ; Wed, 17 Jul 2019 12:33:56 -0700 (PDT) Received: from l1.lan (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id v13sm21743421ioq.13.2019.07.17.12.33.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 12:33:54 -0700 (PDT) X-Inumbo-ID: d0f0b3d2-a8c9-11e9-8afc-8b45d339bfd7 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cEs8uh0BztRP1QpWyft084vesYDg1M1kqUeeQXfN2QA=; b=ieA41QAFnlXUtVqAb+JM6NPJ4gWcqmHfiLDuuZ3iucw+LaWk7zKtSfmUw4iAoi3pBC jhGsaqYnfM+Kgn21fINAQd38j+mumJoF7CyWIehRF1F4tEgdVcghF2yYB8lvnxGkfVaT DnB7NoqS6doyPLU/QFpYrNbB8/ntQUUU0XwvcegkrYb2G37Cjg3LN6qPlLOxssv8Xf7l 5+qDz9MAiVI9yZfaiwAwZHAI9MOUaUeTVaZN9e0rpjcN+NGphbdibLHs5udUlnlfCoie kNG48U8xca1lS71GRtLYoF7K53YfnT6h9H+eeCNWdr6EkX7ROvdgXvchzPie5OYRY7aj KAEg== X-Gm-Message-State: APjAAAU6TJuvUIvZ08AtbumGIsLhe4CuGXk5KXYT2M7GoPGrtm4+CU4f qoci8nyeslbzRr6Dbt4aL9k7ImU/ X-Google-Smtp-Source: APXvYqw1wWU9j0YZB4Yq3mDafb2VrcuUm21sJeF1GN2DXWDhPfQoz1P2dGTt837ss9tBcNz4Ph5HSQ== X-Received: by 2002:a5e:de4d:: with SMTP id e13mr16737420ioq.272.1563392035325; Wed, 17 Jul 2019 12:33:55 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 17 Jul 2019 13:33:32 -0600 Message-Id: <20190717193335.11991-3-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717193335.11991-1-tamas@tklengyel.com> References: <20190717193335.11991-1-tamas@tklengyel.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 2/5] x86/mem_sharing: copy a page_lock version to be internal to memshr 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: Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Patch cf4b30dca0a "Add debug code to detect illegal page_lock and put_page_= type ordering" added extra sanity checking to page_lock/page_unlock for debug bu= ilds with the assumption that no hypervisor path ever locks two pages at once. This assumption doesn't hold during memory sharing so we copy a version of page_lock/unlock to be used exclusively in the memory sharing subsystem without the sanity checks. Signed-off-by: Tamas K Lengyel Acked-by: Jan Beulich Cc: George Dunlap Cc: Andrew Cooper Cc: Wei Liu Cc: Roger Pau Monne --- v6: adjust comment according to Jan's suggestion --- xen/arch/x86/mm/mem_sharing.c | 54 ++++++++++++++++++++++++++++++++--- xen/include/asm-x86/mm.h | 15 ++-------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 6c033d1488..a5fe89e339 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -112,13 +112,59 @@ static inline void page_sharing_dispose(struct page_i= nfo *page) =20 #endif /* MEM_SHARING_AUDIT */ =20 -static inline int mem_sharing_page_lock(struct page_info *pg) +/* + * Private implementations of page_lock/unlock to bypass PV-only + * sanity checks not applicable to mem-sharing. + * + * _page_lock is used in memory sharing to protect addition (share) and re= moval + * (unshare) of (gfn,domain) tupples to a list of gfn's that the shared pa= ge is + * currently backing. + * Nesting may happen when sharing (and locking) two pages. + * Deadlock is avoided by locking pages in increasing order. + * All memory sharing code paths take the p2m lock of the affected gfn bef= ore + * taking the lock for the underlying page. We enforce ordering between pa= ge_lock + * and p2m_lock using an mm-locks.h construct. + * + * TODO: Investigate if PGT_validated is necessary. + */ +static inline bool _page_lock(struct page_info *page) { - int rc; + unsigned long x, nx; + + do { + while ( (x =3D page->u.inuse.type_info) & PGT_locked ) + cpu_relax(); + nx =3D x + (1 | PGT_locked); + if ( !(x & PGT_validated) || + !(x & PGT_count_mask) || + !(nx & PGT_count_mask) ) + return false; + } while ( cmpxchg(&page->u.inuse.type_info, x, nx) !=3D x ); + + return true; +} + +static inline void _page_unlock(struct page_info *page) +{ + unsigned long x, nx, y =3D page->u.inuse.type_info; + + do { + x =3D y; + ASSERT((x & PGT_count_mask) && (x & PGT_locked)); + + nx =3D x - (1 | PGT_locked); + /* We must not drop the last reference here. */ + ASSERT(nx & PGT_count_mask); + } while ( (y =3D cmpxchg(&page->u.inuse.type_info, x, nx)) !=3D x ); +} + +static inline bool mem_sharing_page_lock(struct page_info *pg) +{ + bool rc; pg_lock_data_t *pld =3D &(this_cpu(__pld)); =20 page_sharing_mm_pre_lock(); - rc =3D page_lock(pg); + rc =3D _page_lock(pg); if ( rc ) { preempt_disable(); @@ -135,7 +181,7 @@ static inline void mem_sharing_page_unlock(struct page_= info *pg) page_sharing_mm_unlock(pld->mm_unlock_level,=20 &pld->recurse_count); preempt_enable(); - page_unlock(pg); + _page_unlock(pg); } =20 static inline shr_handle_t get_next_handle(void) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 6c14635270..087ad97351 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -356,24 +356,15 @@ struct platform_bad_page { const struct platform_bad_page *get_platform_badpages(unsigned int *array_= size); =20 /* Per page locks: - * page_lock() is used for two purposes: pte serialization, and memory sha= ring. + * page_lock() is used for pte serialization. * * All users of page lock for pte serialization live in mm.c, use it * to lock a page table page during pte updates, do not take other locks w= ithin * the critical section delimited by page_lock/unlock, and perform no * nesting. * - * All users of page lock for memory sharing live in mm/mem_sharing.c. Pag= e_lock - * is used in memory sharing to protect addition (share) and removal (unsh= are) - * of (gfn,domain) tupples to a list of gfn's that the shared page is curr= ently - * backing. Nesting may happen when sharing (and locking) two pages -- dea= dlock - * is avoided by locking pages in increasing order. - * All memory sharing code paths take the p2m lock of the affected gfn bef= ore - * taking the lock for the underlying page. We enforce ordering between pa= ge_lock - * and p2m_lock using an mm-locks.h construct. - * - * These two users (pte serialization and memory sharing) do not collide, = since - * sharing is only supported for hvm guests, which do not perform pv pte u= pdates. + * The use of PGT_locked in mem_sharing does not collide, since mem_sharin= g is + * only supported for hvm guests, which do not have PV PTEs updated. */ int page_lock(struct page_info *page); void page_unlock(struct page_info *page); --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 04:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563392113; cv=none; d=zoho.com; s=zohoarc; b=CHqZx008/jAPhXS6DVrYUlgyx3CIlb8tkCAlyc5I9zveO5i1cjtu3oUFfhMCSQYKQhuj9rxaRDJ4aA26TuNaz5c47UdYOYm/+YVV7jkamk00F2u613JO2A80VQhQIzvx5+cQDLQ9oea8uMaBsmHvE2UKOOqOtvgTunW0aiHZx0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563392113; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FMPq3aBKHV3qvT3fO2U2Xiw607sqOStEKF/CoxhJHHw=; b=U8h/y0O6Yn50k2KkF8wjZTzGp2MsiM1Jc6TfEBTZRkNX0PAs6bUsKr4ZH8yslPkKJS7Xo0yiwiLJFt7a/aTLtU2FxON3Dj/KYzqfi1QVx6ObIfjiyH70iBm7gurUIdSFRQPPEF9RJ5hqDcIsawdVxKkJjZCipQRris4eKL9Iyfk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563392113877299.7515027465271; Wed, 17 Jul 2019 12:35:13 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnpgf-0000I6-NO; Wed, 17 Jul 2019 19:34:01 +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 1hnpge-0000HY-S5 for xen-devel@lists.xenproject.org; Wed, 17 Jul 2019 19:34:00 +0000 Received: from mail-io1-f46.google.com (unknown [209.85.166.46]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d1b9fad0-a8c9-11e9-b1fa-239cefdce2bf; Wed, 17 Jul 2019 19:33:57 +0000 (UTC) Received: by mail-io1-f46.google.com with SMTP id k20so47594915ios.10 for ; Wed, 17 Jul 2019 12:33:57 -0700 (PDT) Received: from l1.lan (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id v13sm21743421ioq.13.2019.07.17.12.33.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 12:33:56 -0700 (PDT) X-Inumbo-ID: d1b9fad0-a8c9-11e9-b1fa-239cefdce2bf X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QETwMaZ1/fKFNeTqiJ8Ul71lh14Z/VE7ZvRMcOw3JcI=; b=S68CrYm4zRlMrgSGQSukOdusbX3mHSqXCiufgoZfUoeTchRwkJ3lJlCVltIC2lzoFf y4Ic8TAtvfwvV5pIyBYJR7YlwMg7PvRL6hgcx2GjVDooyCUwF0pLqvdWDOntPkJx0B8z 4gKXloa+6VMYurG/XCGAbldfd78G2iiwiwk3cqSar1q5mRAwAB9Wt+BtTSnzDkYNuvMA zgwq+4Z6zhVwacFkVCuoHNE+1LgypqlIURNJS0tzWXHbm6kDpxROquwr+B15w/dP6vhb mYaLoUXsDNuGdczn4fQqQHehpvHJolnWOl6XwuUQZa3B25r5IkuL7k43x4lLYcz6eHcj iRjw== X-Gm-Message-State: APjAAAUf7YvhYMz1UodXHQFhMHLV83HQtUrNI3kIjsEUSrhXsLdyhXEu O940s65i6OZ8T3v92Iv8AWcxV93E X-Google-Smtp-Source: APXvYqzjVjorbwpqQfSra1qhunjoOrVEu+JGhAndJEAN19qgBuyUhs219TP6oJ81kLqgltJH7XQtJA== X-Received: by 2002:a5d:885a:: with SMTP id t26mr33729373ios.218.1563392036708; Wed, 17 Jul 2019 12:33:56 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 17 Jul 2019 13:33:33 -0600 Message-Id: <20190717193335.11991-4-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717193335.11991-1-tamas@tklengyel.com> References: <20190717193335.11991-1-tamas@tklengyel.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 3/5] x86/mem_sharing: enable mem_share audit mode only in debug builds 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 , Tamas K Lengyel , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Improves performance for release builds. Signed-off-by: Tamas K Lengyel Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: Roger Pau Monne --- v6: patch ping --- xen/include/asm-x86/mem_sharing.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index 9f9f7e93e3..afd0c17292 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -25,7 +25,11 @@ #include =20 /* Auditing of memory sharing code? */ +#ifndef NDEBUG #define MEM_SHARING_AUDIT 1 +#else +#define MEM_SHARING_AUDIT 0 +#endif =20 typedef uint64_t shr_handle_t;=20 =20 --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 04:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563392129; cv=none; d=zoho.com; s=zohoarc; b=EhPIScMb15ai7yEIsGUlCFfnWsLcQ+eujTplJRgtqA/LWfsA4bo4HNaE1VTw7rWYZF0SGWbZfhxsIAB5oyR7f1XtUYCdE08ApwIWNkRkITbM0zCwpB+w/3K70SW4db007E6h2Cs+C/r4RUJVfowMz9EREFMuxz3My1/yzNo8RSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563392129; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ppE+Vf8NsZ6lWnx2E/GCe7At7nm3QTwHSNNpgQCJa9o=; b=Dfr37r0BBouX7Olzc/ELLwj9CKwzyOnmOzMvl9GVuB0Mr97TlbZWGN/cyWK89fTCkQ6K78kKl52AduVSbKFVKSp8uaAI4OKZHoDSvGnr6Qf9JF0bPnvcCQYRbLEJeJAOHcmee9phKkF/aFsTPJ+IChYbUtd2bhI8TrnAqHpbxXY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563392129900317.63851060093236; Wed, 17 Jul 2019 12:35:29 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnpgh-0000IV-13; Wed, 17 Jul 2019 19:34:03 +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 1hnpgg-0000IL-3M for xen-devel@lists.xenproject.org; Wed, 17 Jul 2019 19:34:02 +0000 Received: from mail-io1-f66.google.com (unknown [209.85.166.66]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d2f84668-a8c9-11e9-b34d-ef1fc16ccd93; Wed, 17 Jul 2019 19:33:59 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id o9so47686592iom.3 for ; Wed, 17 Jul 2019 12:33:59 -0700 (PDT) Received: from l1.lan (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id v13sm21743421ioq.13.2019.07.17.12.33.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 12:33:57 -0700 (PDT) X-Inumbo-ID: d2f84668-a8c9-11e9-b34d-ef1fc16ccd93 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bhWcJS8ddgdUot0n7cOWsB1nWNTTcu28PhAqbt9unzE=; b=rce9aksren0NUfpFpaHvSv5PuZS+YsziuobuSK+M36Qj5BJrEbILpuadtSAql1CuMQ M+qmg8y0mo8iZnKbRhM63PicD1dseSt/MLElvotlNyr4dwYuaeKZMzTJtZbOedAbGlHS yOK57++MAZgCKwhPIyKsPyWfUq8SBw6tpifHnx1Kq5KjNLwB8L5gMXltz6zVMNtH6lY0 vktqKeQD5TphJrGz61MCR58Doq/csFneYlOiDZoVpX3/RATuwyhIBmgD5ktJemvRmGt9 hToHHNxUyub5nFtpe1KDd5Bk5vE/l53swImeY7JTXkkId31kXjcrshJVJi0jFC0ciusv XVWA== X-Gm-Message-State: APjAAAUaoEJV2naFtcbiF3rYYgdDBxmDvqxqud7weV5kYdUbahHvxad6 1eCsk+618EyM6Kx1UONHqNFAHVn8hTQ= X-Google-Smtp-Source: APXvYqzrM8D7/bpoymNk7/JIn6lgsbg1TXAklNJxkyfJnaG4sM7EImy+PUeVAPjyK7Hwmcn2ZiWtGQ== X-Received: by 2002:a5d:8794:: with SMTP id f20mr37851018ion.128.1563392038669; Wed, 17 Jul 2019 12:33:58 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 17 Jul 2019 13:33:34 -0600 Message-Id: <20190717193335.11991-5-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717193335.11991-1-tamas@tklengyel.com> References: <20190717193335.11991-1-tamas@tklengyel.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 4/5] x86/mem_sharing: compile mem_sharing subsystem only when kconfig is enabled 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: Tamas K Lengyel , Wei Liu , Razvan Cojocaru , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Stefano Stabellini , Jan Beulich , Daniel De Graaf , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Disable it by default as it is only an experimental subsystem. Signed-off-by: Tamas K Lengyel Acked-by: Daniel De Graaf Acked-by: Razvan Cojocaru Acked-by: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: Roger Pau Monne Cc: George Dunlap Cc: Ian Jackson Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: George Dunlap ---- v6: rebase on staging --- xen/arch/x86/Kconfig | 6 +++++- xen/arch/x86/domain.c | 2 ++ xen/arch/x86/domctl.c | 2 ++ xen/arch/x86/mm/Makefile | 2 +- xen/arch/x86/x86_64/compat/mm.c | 2 ++ xen/arch/x86/x86_64/mm.c | 2 ++ xen/common/Kconfig | 3 --- xen/common/domain.c | 6 +++--- xen/common/grant_table.c | 2 +- xen/common/memory.c | 2 +- xen/common/vm_event.c | 6 +++--- xen/include/asm-x86/mem_sharing.h | 28 ++++++++++++++++++++++++++++ xen/include/asm-x86/mm.h | 3 +++ xen/include/xen/mm.h | 2 +- xen/include/xen/sched.h | 2 +- xen/include/xsm/dummy.h | 2 +- xen/include/xsm/xsm.h | 4 ++-- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 4 ++-- 19 files changed, 61 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index f502d765ba..288dc6c042 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -18,7 +18,6 @@ config X86 select HAS_KEXEC select MEM_ACCESS_ALWAYS_ON select HAS_MEM_PAGING - select HAS_MEM_SHARING select HAS_NS16550 select HAS_PASSTHROUGH select HAS_PCI @@ -199,6 +198,11 @@ config PV_SHIM_EXCLUSIVE firmware, and will not function correctly in other scenarios. =20 If unsure, say N. + +config MEM_SHARING + bool "Xen memory sharing support" if EXPERT =3D "y" + depends on HVM + endmenu =20 source "common/Kconfig" diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index e791d86892..ea55160887 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2095,6 +2095,7 @@ int domain_relinquish_resources(struct domain *d) d->arch.auto_unmask =3D 0; } =20 +#ifdef CONFIG_MEM_SHARING PROGRESS(shared): =20 if ( is_hvm_domain(d) ) @@ -2105,6 +2106,7 @@ int domain_relinquish_resources(struct domain *d) if ( ret ) return ret; } +#endif =20 spin_lock(&d->page_alloc_lock); page_list_splice(&d->arch.relmem_list, &d->page_list); diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index c827790202..2d45e5b8a8 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1236,9 +1236,11 @@ long arch_do_domctl( break; } =20 +#ifdef CONFIG_MEM_SHARING case XEN_DOMCTL_mem_sharing_op: ret =3D mem_sharing_domctl(d, &domctl->u.mem_sharing_op); break; +#endif =20 #if P2M_AUDIT && defined(CONFIG_HVM) case XEN_DOMCTL_audit_p2m: diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile index 5a17646f98..5010a29d6c 100644 --- a/xen/arch/x86/mm/Makefile +++ b/xen/arch/x86/mm/Makefile @@ -6,7 +6,7 @@ obj-$(CONFIG_HVM) +=3D guest_walk_2.o guest_walk_3.o guest_= walk_4.o obj-$(CONFIG_SHADOW_PAGING) +=3D guest_walk_2.o guest_walk_3.o guest_walk_= 4.o obj-$(CONFIG_MEM_ACCESS) +=3D mem_access.o obj-y +=3D mem_paging.o -obj-y +=3D mem_sharing.o +obj-$(CONFIG_MEM_SHARING) +=3D mem_sharing.o obj-y +=3D p2m.o p2m-pt.o obj-$(CONFIG_HVM) +=3D p2m-ept.o p2m-pod.o obj-y +=3D paging.o diff --git a/xen/arch/x86/x86_64/compat/mm.c b/xen/arch/x86/x86_64/compat/m= m.c index 32410ed273..d4c6be3032 100644 --- a/xen/arch/x86/x86_64/compat/mm.c +++ b/xen/arch/x86/x86_64/compat/mm.c @@ -152,8 +152,10 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST= _HANDLE_PARAM(void) arg) case XENMEM_paging_op: return mem_paging_memop(guest_handle_cast(arg, xen_mem_paging_op_t= )); =20 +#ifdef CONFIG_MEM_SHARING case XENMEM_sharing_op: return mem_sharing_memop(guest_handle_cast(arg, xen_mem_sharing_op= _t)); +#endif =20 default: rc =3D -ENOSYS; diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 899b883b2d..1919cae18b 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -993,8 +993,10 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HA= NDLE_PARAM(void) arg) case XENMEM_paging_op: return mem_paging_memop(guest_handle_cast(arg, xen_mem_paging_op_t= )); =20 +#ifdef CONFIG_MEM_SHARING case XENMEM_sharing_op: return mem_sharing_memop(guest_handle_cast(arg, xen_mem_sharing_op= _t)); +#endif =20 default: rc =3D -ENOSYS; diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 912630a4fb..16829f6274 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -48,9 +48,6 @@ config MEM_ACCESS config HAS_MEM_PAGING bool =20 -config HAS_MEM_SHARING - bool - config HAS_PDX bool =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 8a5fa8662b..55aa759b75 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -74,7 +74,7 @@ integer_param("hardware_dom", hardware_domid); /* Private domain structs for DOMID_XEN, DOMID_IO, etc. */ struct domain *__read_mostly dom_xen; struct domain *__read_mostly dom_io; -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING struct domain *__read_mostly dom_cow; #endif =20 @@ -549,7 +549,7 @@ void __init setup_system_domains(void) if ( IS_ERR(dom_io) ) panic("Failed to create d[IO]: %ld\n", PTR_ERR(dom_io)); =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING /* * Initialise our COW domain. * This domain owns sharable pages. @@ -966,7 +966,7 @@ static void complete_domain_destroy(struct rcu_head *he= ad) xfree(d->vm_event_paging); #endif xfree(d->vm_event_monitor); -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING xfree(d->vm_event_share); #endif =20 diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index b6b45c21e1..97695a221a 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -3798,7 +3798,7 @@ void grant_table_init_vcpu(struct vcpu *v) v->maptrack_tail =3D MAPTRACK_TAIL; } =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, gfn_t *gfn, uint16_t *status) { diff --git a/xen/common/memory.c b/xen/common/memory.c index 30d210fc08..d9b35a608c 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1676,7 +1676,7 @@ int check_get_page_from_gfn(struct domain *d, gfn_t g= fn, bool readonly, return -EAGAIN; } #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING if ( (q & P2M_UNSHARE) && p2m_is_shared(p2mt) ) { if ( page ) diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index e8726805e7..2a1c87e44b 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -531,7 +531,7 @@ static void monitor_notification(struct vcpu *v, unsign= ed int port) vm_event_resume(v->domain, v->domain->vm_event_monitor); } =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING /* Registered with Xen-bound event channel for incoming notifications. */ static void mem_sharing_notification(struct vcpu *v, unsigned int port) { @@ -561,7 +561,7 @@ void vm_event_cleanup(struct domain *d) destroy_waitqueue_head(&d->vm_event_monitor->wq); (void)vm_event_disable(d, &d->vm_event_monitor); } -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING if ( vm_event_check_ring(d->vm_event_share) ) { destroy_waitqueue_head(&d->vm_event_share->wq); @@ -703,7 +703,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl= _vm_event_op *vec) } break; =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING case XEN_DOMCTL_VM_EVENT_OP_SHARING: { rc =3D -EINVAL; diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index afd0c17292..db22468744 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -24,6 +24,8 @@ #include #include =20 +#ifdef CONFIG_MEM_SHARING + /* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1 @@ -99,4 +101,30 @@ int mem_sharing_domctl(struct domain *d, */ int relinquish_shared_pages(struct domain *d); =20 +#else + +static inline unsigned int mem_sharing_get_nr_saved_mfns(void) +{ + return 0; +} +static inline unsigned int mem_sharing_get_nr_shared_mfns(void) +{ + return 0; +} +static inline int mem_sharing_unshare_page(struct domain *d, + unsigned long gfn, + uint16_t flags) +{ + ASSERT_UNREACHABLE(); + return -EOPNOTSUPP; +} +static inline int mem_sharing_notify_enomem(struct domain *d, unsigned lon= g gfn, + bool allow_sleep) +{ + ASSERT_UNREACHABLE(); + return -EOPNOTSUPP; +} + +#endif + #endif /* __MEM_SHARING_H__ */ diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 087ad97351..35c2527265 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -127,6 +127,8 @@ struct page_info /* For non-pinnable single-page shadows, a higher entry that points * at us. */ paddr_t up; + +#ifdef CONFIG_MEM_SHARING /* For shared/sharable pages, we use a doubly-linked list * of all the {pfn,domain} pairs that map this page. We also inclu= de * an opaque handle, which is effectively a version, so that clien= ts @@ -134,6 +136,7 @@ struct page_info * This list is allocated and freed when a page is shared/unshared. */ struct page_sharing_info *sharing; +#endif }; =20 /* Reference count and various PGC_xxx flags and fields. */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 47c8412b3a..977e45aae7 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -275,7 +275,7 @@ struct npfec { =20 /* Private domain structs for DOMID_XEN, DOMID_IO, etc. */ extern struct domain *dom_xen, *dom_io; -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING extern struct domain *dom_cow; #else # define dom_cow NULL diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 97a3ab55aa..b40c8fd138 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -459,7 +459,7 @@ struct domain /* Various vm_events */ =20 /* Memory sharing support */ -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING struct vm_event_domain *vm_event_share; #endif /* Memory paging support */ diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 01d2814fed..ef52bb1764 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -597,7 +597,7 @@ static XSM_INLINE int xsm_mem_paging(XSM_DEFAULT_ARG st= ruct domain *d) } #endif =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING static XSM_INLINE int xsm_mem_sharing(XSM_DEFAULT_ARG struct domain *d) { XSM_ASSERT_ACTION(XSM_DM_PRIV); diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index b6141f6ab1..e22d6160b5 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -150,7 +150,7 @@ struct xsm_operations { int (*mem_paging) (struct domain *d); #endif =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING int (*mem_sharing) (struct domain *d); #endif =20 @@ -597,7 +597,7 @@ static inline int xsm_mem_paging (xsm_default_t def, st= ruct domain *d) } #endif =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING static inline int xsm_mem_sharing (xsm_default_t def, struct domain *d) { return xsm_ops->mem_sharing(d); diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index c9a566f2b5..5705e52791 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -128,7 +128,7 @@ void __init xsm_fixup_ops (struct xsm_operations *ops) set_to_dummy_if_null(ops, mem_paging); #endif =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING set_to_dummy_if_null(ops, mem_sharing); #endif =20 diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index a7d690ac3c..791c1f66af 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1262,7 +1262,7 @@ static int flask_mem_paging(struct domain *d) } #endif =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING static int flask_mem_sharing(struct domain *d) { return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__MEM_SHARING); @@ -1829,7 +1829,7 @@ static struct xsm_operations flask_ops =3D { .mem_paging =3D flask_mem_paging, #endif =20 -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING .mem_sharing =3D flask_mem_sharing, #endif =20 --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Mon Apr 29 04:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563392114; cv=none; d=zoho.com; s=zohoarc; b=nOJP6Gcm95B/SvOP7H99rk/sfFCxRNDSj7Xt9Ar60X4g1TYOz7xHFIY9bUvQm6CqsC+4njIsrG0YmPpaP0mmibcDZMSombX01w2JXkJnmg7D0me1FH6m585UUJ+XsTU8rru36itYPbg1J6WeJdmzkKZugXgWBwBYGc6g+SOtRU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563392114; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zI3opuuhjr0reYrMRNLZfDDB1z3bt4L+4pH9/Td6XtE=; b=WWq6duWO8ju8nZsSnXAs6XblKBSRfCi1bpizLP7fTjssf7P/XlYAqFF0EpjPPABeBJKO4ynfv8YvLX3l3bZFJU8wOictwkyBNZJRSx5KLoqPkY3VE8+kbEVXkwwYvi34lhXk9EHi9tACZUrLFcU6e2RTWpbDLOjZ2TFIeBOP+w4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563392114125556.9411633254708; Wed, 17 Jul 2019 12:35:14 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnpgk-0000KX-B5; Wed, 17 Jul 2019 19:34:06 +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 1hnpgj-0000Ju-2C for xen-devel@lists.xenproject.org; Wed, 17 Jul 2019 19:34:05 +0000 Received: from mail-io1-f68.google.com (unknown [209.85.166.68]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d4362ae0-a8c9-11e9-8c7b-2bb8db163187; Wed, 17 Jul 2019 19:34:01 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id i10so47542946iol.13 for ; Wed, 17 Jul 2019 12:34:01 -0700 (PDT) Received: from l1.lan (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id v13sm21743421ioq.13.2019.07.17.12.33.58 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 12:33:59 -0700 (PDT) X-Inumbo-ID: d4362ae0-a8c9-11e9-8c7b-2bb8db163187 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DZeS6BHvOxQrDAME9IQTHZlH+LOilULLIYwYdA0+/Qg=; b=XiPw7HuCNpZwtHhs2saUqrwAoPzK0EhLqmI22OTnJTc08nINU6q25wX9FXGEyjNkcp +vriEDEnuwWZob6Kvh71hSofILwXFXOOi/Rw8yUUEhljDbEe0GqOs1yf41WQgbt+jNfe qT/vfI6QzN3rXB2HwVhZL272usgDxZlayA5EcHwJM1HARSbDNun4kt5qbeKhbFQZX5yP zVQNwNVtS0sqylBEDqYC8507hPwgbmwCTNA3oYOr6akgpiSZmKj0r8eOMtf3E39HtSSN q4buqWXQx+5Cg/UH2umcQkmikUBcvazRxIq2vSU+bn4ZVWyqk/7KqSob1673omAdWmbJ b2ew== X-Gm-Message-State: APjAAAW7gWb37BIU5bF7W6cV87JCt3i8DNn1PW9bbNDtz69LfvngBjW5 0sUZInmASt8OJh+yOuYdq50HEv5f X-Google-Smtp-Source: APXvYqztdtJ/vOpct7p7oU8uFaGuVm+k56N2dMhnDiDrrQuJ2Kb+UdTum51T4dLHh53zjL4Nndiydw== X-Received: by 2002:a5e:881a:: with SMTP id l26mr14801631ioj.185.1563392040268; Wed, 17 Jul 2019 12:34:00 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 17 Jul 2019 13:33:35 -0600 Message-Id: <20190717193335.11991-6-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717193335.11991-1-tamas@tklengyel.com> References: <20190717193335.11991-1-tamas@tklengyel.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 5/5] x86/mem_sharing: style cleanup 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: Tamas K Lengyel Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional change Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 265 ++++++++++++++++++---------------- 1 file changed, 138 insertions(+), 127 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index a5fe89e339..aaf8c2f2c8 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -42,7 +42,8 @@ =20 static shr_handle_t next_handle =3D 1; =20 -typedef struct pg_lock_data { +typedef struct pg_lock_data +{ int mm_unlock_level; unsigned short recurse_count; } pg_lock_data_t; @@ -88,8 +89,8 @@ static inline void page_sharing_dispose(struct page_info = *page) { /* Unlikely given our thresholds, but we should be careful. */ if ( unlikely(RMAP_USES_HASHTAB(page)) ) - free_xenheap_pages(page->sharing->hash_table.bucket,=20 - RMAP_HASHTAB_ORDER); + free_xenheap_pages(page->sharing->hash_table.bucket, + RMAP_HASHTAB_ORDER); =20 spin_lock(&shr_audit_lock); list_del_rcu(&page->sharing->entry); @@ -105,8 +106,8 @@ static inline void page_sharing_dispose(struct page_inf= o *page) { /* Unlikely given our thresholds, but we should be careful. */ if ( unlikely(RMAP_USES_HASHTAB(page)) ) - free_xenheap_pages(page->sharing->hash_table.bucket,=20 - RMAP_HASHTAB_ORDER); + free_xenheap_pages(page->sharing->hash_table.bucket, + RMAP_HASHTAB_ORDER); xfree(page->sharing); } =20 @@ -136,8 +137,8 @@ static inline bool _page_lock(struct page_info *page) cpu_relax(); nx =3D x + (1 | PGT_locked); if ( !(x & PGT_validated) || - !(x & PGT_count_mask) || - !(nx & PGT_count_mask) ) + !(x & PGT_count_mask) || + !(nx & PGT_count_mask) ) return false; } while ( cmpxchg(&page->u.inuse.type_info, x, nx) !=3D x ); =20 @@ -168,7 +169,7 @@ static inline bool mem_sharing_page_lock(struct page_in= fo *pg) if ( rc ) { preempt_disable(); - page_sharing_mm_post_lock(&pld->mm_unlock_level,=20 + page_sharing_mm_post_lock(&pld->mm_unlock_level, &pld->recurse_count); } return rc; @@ -178,7 +179,7 @@ static inline void mem_sharing_page_unlock(struct page_= info *pg) { pg_lock_data_t *pld =3D &(this_cpu(__pld)); =20 - page_sharing_mm_unlock(pld->mm_unlock_level,=20 + page_sharing_mm_unlock(pld->mm_unlock_level, &pld->recurse_count); preempt_enable(); _page_unlock(pg); @@ -186,19 +187,18 @@ static inline void mem_sharing_page_unlock(struct pag= e_info *pg) =20 static inline shr_handle_t get_next_handle(void) { - /* Get the next handle get_page style */=20 + /* Get the next handle get_page style */ uint64_t x, y =3D next_handle; do { x =3D y; - } - while ( (y =3D cmpxchg(&next_handle, x, x + 1)) !=3D x ); + } while ( (y =3D cmpxchg(&next_handle, x, x + 1)) !=3D x ); return x + 1; } =20 #define mem_sharing_enabled(d) \ (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled) =20 -static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0);=20 +static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0); static atomic_t nr_shared_mfns =3D ATOMIC_INIT(0); =20 /** Reverse map **/ @@ -210,7 +210,7 @@ static atomic_t nr_shared_mfns =3D ATOMIC_INIT(0); typedef struct gfn_info { unsigned long gfn; - domid_t domain;=20 + domid_t domain; struct list_head list; } gfn_info_t; =20 @@ -225,7 +225,7 @@ rmap_init(struct page_info *page) #define HASH(domain, gfn) \ (((gfn) + (domain)) % RMAP_HASHTAB_SIZE) =20 -/* Conversions. Tuned by the thresholds. Should only happen twice=20 +/* Conversions. Tuned by the thresholds. Should only happen twice * (once each) during the lifetime of a shared page */ static inline int rmap_list_to_hash_table(struct page_info *page) @@ -288,13 +288,13 @@ rmap_count(struct page_info *pg) } =20 /* The page type count is always decreased after removing from the rmap. - * Use a convert flag to avoid mutating the rmap if in the middle of an=20 + * Use a convert flag to avoid mutating the rmap if in the middle of an * iterator, or if the page will be soon destroyed anyways. */ static inline void rmap_del(gfn_info_t *gfn_info, struct page_info *page, int convert) { if ( RMAP_USES_HASHTAB(page) && convert && - (rmap_count(page) <=3D RMAP_LIGHT_SHARED_PAGE) ) + (rmap_count(page) <=3D RMAP_LIGHT_SHARED_PAGE) ) rmap_hash_table_to_list(page); =20 /* Regardless of rmap type, same removal operation */ @@ -308,30 +308,30 @@ rmap_add(gfn_info_t *gfn_info, struct page_info *page) struct list_head *head; =20 if ( !RMAP_USES_HASHTAB(page) && - (rmap_count(page) >=3D RMAP_HEAVY_SHARED_PAGE) ) + (rmap_count(page) >=3D RMAP_HEAVY_SHARED_PAGE) ) /* The conversion may fail with ENOMEM. We'll be less efficient, * but no reason to panic. */ (void)rmap_list_to_hash_table(page); =20 head =3D (RMAP_USES_HASHTAB(page)) ? - page->sharing->hash_table.bucket +=20 - HASH(gfn_info->domain, gfn_info->gfn) : - &page->sharing->gfns; + page->sharing->hash_table.bucket + + HASH(gfn_info->domain, gfn_info->gfn) : + &page->sharing->gfns; =20 INIT_LIST_HEAD(&gfn_info->list); list_add(&gfn_info->list, head); } =20 static inline gfn_info_t * -rmap_retrieve(uint16_t domain_id, unsigned long gfn,=20 - struct page_info *page) +rmap_retrieve(uint16_t domain_id, unsigned long gfn, + struct page_info *page) { gfn_info_t *gfn_info; struct list_head *le, *head; =20 head =3D (RMAP_USES_HASHTAB(page)) ? - page->sharing->hash_table.bucket + HASH(domain_id, gfn) : - &page->sharing->gfns; + page->sharing->hash_table.bucket + HASH(domain_id, gfn) : + &page->sharing->gfns; =20 list_for_each(le, head) { @@ -358,7 +358,8 @@ static inline int rmap_has_entries(struct page_info *pa= ge) =20 /* The iterator hides the details of how the rmap is implemented. This * involves splitting the list_for_each_safe macro into two steps. */ -struct rmap_iterator { +struct rmap_iterator +{ struct list_head *curr; struct list_head *next; unsigned int bucket; @@ -368,9 +369,9 @@ static inline void rmap_seed_iterator(struct page_info *page, struct rmap_iterator *ri) { ri->curr =3D (RMAP_USES_HASHTAB(page)) ? - page->sharing->hash_table.bucket : - &page->sharing->gfns; - ri->next =3D ri->curr->next;=20 + page->sharing->hash_table.bucket : + &page->sharing->gfns; + ri->next =3D ri->curr->next; ri->bucket =3D 0; } =20 @@ -378,8 +379,8 @@ static inline gfn_info_t * rmap_iterate(struct page_info *page, struct rmap_iterator *ri) { struct list_head *head =3D (RMAP_USES_HASHTAB(page)) ? - page->sharing->hash_table.bucket + ri->bucket : - &page->sharing->gfns; + page->sharing->hash_table.bucket + ri->bucket= : + &page->sharing->gfns; =20 retry: if ( ri->next =3D=3D head) @@ -394,7 +395,8 @@ retry: ri->curr =3D head; ri->next =3D ri->curr->next; goto retry; - } else + } + else /* List exhausted */ return NULL; } @@ -406,13 +408,13 @@ retry: } =20 static inline gfn_info_t *mem_sharing_gfn_alloc(struct page_info *page, - struct domain *d, - unsigned long gfn) + struct domain *d, + unsigned long gfn) { gfn_info_t *gfn_info =3D xmalloc(gfn_info_t); =20 if ( gfn_info =3D=3D NULL ) - return NULL;=20 + return NULL; =20 gfn_info->gfn =3D gfn; gfn_info->domain =3D d->domain_id; @@ -426,8 +428,8 @@ static inline gfn_info_t *mem_sharing_gfn_alloc(struct = page_info *page, } =20 static inline void mem_sharing_gfn_destroy(struct page_info *page, - struct domain *d, - gfn_info_t *gfn_info) + struct domain *d, + gfn_info_t *gfn_info) { /* Decrement the number of pages. */ atomic_dec(&d->shr_pages); @@ -437,15 +439,15 @@ static inline void mem_sharing_gfn_destroy(struct pag= e_info *page, xfree(gfn_info); } =20 -static struct page_info* mem_sharing_lookup(unsigned long mfn) +static struct page_info *mem_sharing_lookup(unsigned long mfn) { if ( mfn_valid(_mfn(mfn)) ) { - struct page_info* page =3D mfn_to_page(_mfn(mfn)); + struct page_info *page =3D mfn_to_page(_mfn(mfn)); if ( page_get_owner(page) =3D=3D dom_cow ) { /* Count has to be at least two, because we're called - * with the mfn locked (1) and this is supposed to be=20 + * with the mfn locked (1) and this is supposed to be * a shared page (1). */ unsigned long t =3D read_atomic(&page->u.inuse.type_info); ASSERT((t & PGT_type_mask) =3D=3D PGT_shared_page); @@ -486,44 +488,44 @@ static int audit(void) /* If we can't lock it, it's definitely not a shared page */ if ( !mem_sharing_page_lock(pg) ) { - MEM_SHARING_DEBUG("mfn %lx in audit list, but cannot be locked = (%lx)!\n", + MEM_SHARING_DEBUG("mfn %lx in audit list, but cannot be locked= (%lx)!\n", mfn_x(mfn), pg->u.inuse.type_info); - errors++; - continue; + errors++; + continue; } =20 - /* Check if the MFN has correct type, owner and handle. */=20 + /* Check if the MFN has correct type, owner and handle. */ if ( (pg->u.inuse.type_info & PGT_type_mask) !=3D PGT_shared_page ) { - MEM_SHARING_DEBUG("mfn %lx in audit list, but not PGT_shared_pa= ge (%lx)!\n", + MEM_SHARING_DEBUG("mfn %lx in audit list, but not PGT_shared_p= age (%lx)!\n", mfn_x(mfn), pg->u.inuse.type_info & PGT_type= _mask); - errors++; - continue; + errors++; + continue; } =20 /* Check the page owner. */ if ( page_get_owner(pg) !=3D dom_cow ) { - MEM_SHARING_DEBUG("mfn %lx shared, but wrong owner (%hu)!\n", - mfn_x(mfn), page_get_owner(pg)->domain_id); - errors++; + MEM_SHARING_DEBUG("mfn %lx shared, but wrong owner (%hu)!\n", + mfn_x(mfn), page_get_owner(pg)->domain_id); + errors++; } =20 /* Check the m2p entry */ if ( !SHARED_M2P(get_gpfn_from_mfn(mfn_x(mfn))) ) { - MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\n= ", - mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn))); - errors++; + MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\= n", + mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn))); + errors++; } =20 /* Check we have a list */ if ( (!pg->sharing) || !rmap_has_entries(pg) ) { - MEM_SHARING_DEBUG("mfn %lx shared, but empty gfn list!\n", - mfn_x(mfn)); - errors++; - continue; + MEM_SHARING_DEBUG("mfn %lx shared, but empty gfn list!\n", + mfn_x(mfn)); + errors++; + continue; } =20 /* We've found a page that is shared */ @@ -545,7 +547,7 @@ static int audit(void) errors++; continue; } - o_mfn =3D get_gfn_query_unlocked(d, g->gfn, &t);=20 + o_mfn =3D get_gfn_query_unlocked(d, g->gfn, &t); if ( !mfn_eq(o_mfn, mfn) ) { MEM_SHARING_DEBUG("Incorrect P2M for d=3D%hu, PFN=3D%lx." @@ -568,7 +570,7 @@ static int audit(void) { MEM_SHARING_DEBUG("Mismatched counts for MFN=3D%lx." "nr_gfns in list %lu, in type_info %lx\n", - mfn_x(mfn), nr_gfns,=20 + mfn_x(mfn), nr_gfns, (pg->u.inuse.type_info & PGT_count_mask)); errors++; } @@ -596,15 +598,16 @@ int mem_sharing_notify_enomem(struct domain *d, unsig= ned long gfn, { struct vcpu *v =3D current; int rc; - vm_event_request_t req =3D { + vm_event_request_t req =3D + { .reason =3D VM_EVENT_REASON_MEM_SHARING, .vcpu_id =3D v->vcpu_id, .u.mem_sharing.gfn =3D gfn, .u.mem_sharing.p2mt =3D p2m_ram_shared }; =20 - if ( (rc =3D __vm_event_claim_slot(d,=20 - d->vm_event_share, allow_sleep)) < 0 ) + if ( (rc =3D __vm_event_claim_slot(d, + d->vm_event_share, allow_sleep)) < 0 ) return rc; =20 if ( v->domain =3D=3D d ) @@ -629,9 +632,9 @@ unsigned int mem_sharing_get_nr_shared_mfns(void) } =20 /* Functions that change a page's type and ownership */ -static int page_make_sharable(struct domain *d,=20 - struct page_info *page,=20 - int expected_refcnt) +static int page_make_sharable(struct domain *d, + struct page_info *page, + int expected_refcnt) { bool_t drop_dom_ref; =20 @@ -684,7 +687,7 @@ static int page_make_private(struct domain *d, struct p= age_info *page) =20 if ( !get_page(page, dom_cow) ) return -EINVAL; - =20 + spin_lock(&d->page_alloc_lock); =20 if ( d->is_dying ) @@ -729,7 +732,7 @@ static inline struct page_info *__grab_shared_page(mfn_= t mfn) return NULL; pg =3D mfn_to_page(mfn); =20 - /* If the page is not validated we can't lock it, and if it's =20 + /* If the page is not validated we can't lock it, and if it's * not validated it's obviously not shared. */ if ( !mem_sharing_page_lock(pg) ) return NULL; @@ -754,12 +757,12 @@ static int debug_mfn(mfn_t mfn) return -EINVAL; } =20 - MEM_SHARING_DEBUG(=20 - "Debug page: MFN=3D%lx is ci=3D%lx, ti=3D%lx, owner_id=3D%d\n", - mfn_x(page_to_mfn(page)),=20 - page->count_info,=20 - page->u.inuse.type_info, - page_get_owner(page)->domain_id); + MEM_SHARING_DEBUG( + "Debug page: MFN=3D%lx is ci=3D%lx, ti=3D%lx, owner_id=3D%d\n", + mfn_x(page_to_mfn(page)), + page->count_info, + page->u.inuse.type_info, + page_get_owner(page)->domain_id); =20 /* -1 because the page is locked and that's an additional type ref */ num_refs =3D ((int) (page->u.inuse.type_info & PGT_count_mask)) - 1; @@ -775,7 +778,7 @@ static int debug_gfn(struct domain *d, gfn_t gfn) =20 mfn =3D get_gfn_query(d, gfn_x(gfn), &p2mt); =20 - MEM_SHARING_DEBUG("Debug for dom%d, gfn=3D%" PRI_gfn "\n",=20 + MEM_SHARING_DEBUG("Debug for dom%d, gfn=3D%" PRI_gfn "\n", d->domain_id, gfn_x(gfn)); num_refs =3D debug_mfn(mfn); put_gfn(d, gfn_x(gfn)); @@ -796,10 +799,10 @@ static int debug_gref(struct domain *d, grant_ref_t r= ef) d->domain_id, ref, rc); return rc; } - =20 + MEM_SHARING_DEBUG( - "=3D=3D> Grant [dom=3D%d,ref=3D%d], status=3D%x. ",=20 - d->domain_id, ref, status); + "=3D=3D> Grant [dom=3D%d,ref=3D%d], status=3D%x. ", + d->domain_id, ref, status); =20 return debug_gfn(d, gfn); } @@ -824,12 +827,14 @@ static int nominate_page(struct domain *d, gfn_t gfn, goto out; =20 /* Return the handle if the page is already shared */ - if ( p2m_is_shared(p2mt) ) { + if ( p2m_is_shared(p2mt) ) + { struct page_info *pg =3D __grab_shared_page(mfn); if ( !pg ) { gprintk(XENLOG_ERR, - "Shared p2m entry gfn %" PRI_gfn ", but could not grab= mfn %" PRI_mfn " dom%d\n", + "Shared p2m entry gfn %" PRI_gfn ", but could not grab= mfn %" PRI_mfn + " dom%d\n", gfn_x(gfn), mfn_x(mfn), d->domain_id); BUG(); } @@ -876,12 +881,12 @@ static int nominate_page(struct domain *d, gfn_t gfn, =20 /* Try to convert the mfn to the sharable type */ page =3D mfn_to_page(mfn); - ret =3D page_make_sharable(d, page, expected_refcnt);=20 - if ( ret )=20 + ret =3D page_make_sharable(d, page, expected_refcnt); + if ( ret ) goto out; =20 - /* Now that the page is validated, we can lock it. There is no=20 - * race because we're holding the p2m entry, so no one else=20 + /* Now that the page is validated, we can lock it. There is no + * race because we're holding the p2m entry, so no one else * could be nominating this gfn */ ret =3D -ENOENT; if ( !mem_sharing_page_lock(page) ) @@ -889,8 +894,8 @@ static int nominate_page(struct domain *d, gfn_t gfn, =20 /* Initialize the shared state */ ret =3D -ENOMEM; - if ( (page->sharing =3D=20 - xmalloc(struct page_sharing_info)) =3D=3D NULL ) + if ( (page->sharing =3D + xmalloc(struct page_sharing_info)) =3D=3D NULL ) { /* Making a page private atomically unlocks it */ BUG_ON(page_make_private(d, page) !=3D 0); @@ -900,7 +905,7 @@ static int nominate_page(struct domain *d, gfn_t gfn, rmap_init(page); =20 /* Create the handle */ - page->sharing->handle =3D get_next_handle(); =20 + page->sharing->handle =3D get_next_handle(); =20 /* Create the local gfn info */ if ( mem_sharing_gfn_alloc(page, d, gfn_x(gfn)) =3D=3D NULL ) @@ -946,7 +951,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, s= hr_handle_t sh, get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn, cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg); =20 - /* This tricky business is to avoid two callers deadlocking if=20 + /* This tricky business is to avoid two callers deadlocking if * grabbing pages in opposite client/source order */ if ( mfn_eq(smfn, cmfn) ) { @@ -972,7 +977,9 @@ static int share_pages(struct domain *sd, gfn_t sgfn, s= hr_handle_t sh, mem_sharing_page_unlock(spage); goto err_out; } - } else { + } + else + { ret =3D XENMEM_SHARING_OP_C_HANDLE_INVALID; cpage =3D firstpg =3D __grab_shared_page(cmfn); if ( cpage =3D=3D NULL ) @@ -1010,7 +1017,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn,= shr_handle_t sh, rmap_seed_iterator(cpage, &ri); while ( (gfn =3D rmap_iterate(cpage, &ri)) !=3D NULL) { - /* Get the source page and type, this should never fail:=20 + /* Get the source page and type, this should never fail: * we are under shr lock, and got a successful lookup */ BUG_ON(!get_page_and_type(spage, dom_cow, PGT_shared_page)); /* Move the gfn_info from client list to source list. @@ -1043,14 +1050,15 @@ static int share_pages(struct domain *sd, gfn_t sgf= n, shr_handle_t sh, atomic_dec(&nr_shared_mfns); atomic_inc(&nr_saved_mfns); ret =3D 0; - =20 + err_out: put_two_gfns(&tg); return ret; } =20 -int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_= handle_t sh, - struct domain *cd, unsigned long cgfn)=20 +int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, + shr_handle_t sh, + struct domain *cd, unsigned long cgfn) { struct page_info *spage; int ret =3D -EINVAL; @@ -1101,7 +1109,9 @@ int mem_sharing_add_to_physmap(struct domain *sd, uns= igned long sgfn, shr_handle { mem_sharing_gfn_destroy(spage, cd, gfn_info); put_page_and_type(spage); - } else { + } + else + { /* There is a chance we're plugging a hole where a paged out page = was */ if ( p2m_is_paging(cmfn_type) && (cmfn_type !=3D p2m_ram_paging_ou= t) ) { @@ -1136,10 +1146,10 @@ err_out: /* A note on the rationale for unshare error handling: * 1. Unshare can only fail with ENOMEM. Any other error conditions BUG_O= N()'s * 2. We notify a potential dom0 helper through a vm_event ring. But we - * allow the notification to not go to sleep. If the event ring is ful= l=20 + * allow the notification to not go to sleep. If the event ring is full * of ENOMEM warnings, then it's on the ball. * 3. We cannot go to sleep until the unshare is resolved, because we mig= ht - * be buried deep into locks (e.g. something -> copy_to_user -> __hvm_= copy)=20 + * be buried deep into locks (e.g. something -> copy_to_user -> __hvm_= copy) * 4. So, we make sure we: * 4.1. return an error * 4.2. do not corrupt shared memory @@ -1147,19 +1157,20 @@ err_out: * 4.4. let the guest deal with it if the error propagation will reach= it */ int __mem_sharing_unshare_page(struct domain *d, - unsigned long gfn,=20 - uint16_t flags) + unsigned long gfn, + uint16_t flags) { p2m_type_t p2mt; mfn_t mfn; struct page_info *page, *old_page; int last_gfn; gfn_info_t *gfn_info =3D NULL; - =20 + mfn =3D get_gfn(d, gfn, &p2mt); - =20 + /* Has someone already unshared it? */ - if ( !p2m_is_shared(p2mt) ) { + if ( !p2m_is_shared(p2mt) ) + { put_gfn(d, gfn); return 0; } @@ -1168,7 +1179,7 @@ int __mem_sharing_unshare_page(struct domain *d, if ( page =3D=3D NULL ) { gdprintk(XENLOG_ERR, "Domain p2m is shared, but page is not: " - "%lx\n", gfn); + "%lx\n", gfn); BUG(); } =20 @@ -1176,12 +1187,12 @@ int __mem_sharing_unshare_page(struct domain *d, if ( unlikely(gfn_info =3D=3D NULL) ) { gdprintk(XENLOG_ERR, "Could not find gfn_info for shared gfn: " - "%lx\n", gfn); + "%lx\n", gfn); BUG(); } =20 /* Do the accounting first. If anything fails below, we have bigger - * bigger fish to fry. First, remove the gfn from the list. */=20 + * bigger fish to fry. First, remove the gfn from the list. */ last_gfn =3D rmap_has_one_entry(page); if ( last_gfn ) { @@ -1195,7 +1206,7 @@ int __mem_sharing_unshare_page(struct domain *d, else atomic_dec(&nr_saved_mfns); =20 - /* If the GFN is getting destroyed drop the references to MFN=20 + /* If the GFN is getting destroyed drop the references to MFN * (possibly freeing the page), and exit early */ if ( flags & MEM_SHARING_DESTROY_GFN ) { @@ -1212,7 +1223,7 @@ int __mem_sharing_unshare_page(struct domain *d, =20 return 0; } -=20 + if ( last_gfn ) { /* Making a page private atomically unlocks it */ @@ -1222,7 +1233,7 @@ int __mem_sharing_unshare_page(struct domain *d, =20 old_page =3D page; page =3D alloc_domheap_page(d, 0); - if ( !page )=20 + if ( !page ) { /* Undo dec of nr_saved_mfns, as the retry will decrease again. */ atomic_inc(&nr_saved_mfns); @@ -1240,11 +1251,11 @@ int __mem_sharing_unshare_page(struct domain *d, mem_sharing_page_unlock(old_page); put_page_and_type(old_page); =20 -private_page_found: =20 +private_page_found: if ( p2m_change_type_one(d, gfn, p2m_ram_shared, p2m_ram_rw) ) { - gdprintk(XENLOG_ERR, "Could not change p2m type d %hu gfn %lx.\n",=20 - d->domain_id, gfn); + gdprintk(XENLOG_ERR, "Could not change p2m type d %hu gfn %lx.\n", + d->domain_id, gfn); BUG(); } =20 @@ -1270,7 +1281,7 @@ int relinquish_shared_pages(struct domain *d) =20 p2m_lock(p2m); for ( gfn =3D p2m->next_shared_gfn_to_relinquish; - gfn <=3D p2m->max_mapped_pfn; gfn++ ) + gfn <=3D p2m->max_mapped_pfn; gfn++ ) { p2m_access_t a; p2m_type_t t; @@ -1283,8 +1294,8 @@ int relinquish_shared_pages(struct domain *d) if ( mfn_valid(mfn) && (t =3D=3D p2m_ram_shared) ) { /* Does not fail with ENOMEM given the DESTROY flag */ - BUG_ON(__mem_sharing_unshare_page(d, gfn,=20 - MEM_SHARING_DESTROY_GFN)); + BUG_ON(__mem_sharing_unshare_page(d, gfn, + MEM_SHARING_DESTROY_GFN)); /* Clear out the p2m entry so no one else may try to * unshare. Must succeed: we just read the old entry and * we hold the p2m lock. */ @@ -1454,8 +1465,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 if ( XENMEM_SHARING_OP_FIELD_IS_GREF(mso.u.share.source_gfn) ) { - grant_ref_t gref =3D (grant_ref_t)=20 - (XENMEM_SHARING_OP_FIELD_GET_GREF( + grant_ref_t gref =3D (grant_ref_t) + (XENMEM_SHARING_OP_FIELD_GET_GREF( mso.u.share.source_gfn)); rc =3D mem_sharing_gref_to_gfn(d->grant_table, gref, &sgfn, NULL); @@ -1470,8 +1481,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 if ( XENMEM_SHARING_OP_FIELD_IS_GREF(mso.u.share.client_gfn) ) { - grant_ref_t gref =3D (grant_ref_t)=20 - (XENMEM_SHARING_OP_FIELD_GET_GREF( + grant_ref_t gref =3D (grant_ref_t) + (XENMEM_SHARING_OP_FIELD_GET_GREF( mso.u.share.client_gfn)); rc =3D mem_sharing_gref_to_gfn(cd->grant_table, gref, &cgf= n, NULL); @@ -1534,7 +1545,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) sh =3D mso.u.share.source_handle; cgfn =3D mso.u.share.client_gfn; =20 - rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn);=20 + rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn); =20 rcu_unlock_domain(cd); } @@ -1547,8 +1558,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 rc =3D -EINVAL; if ( mso.u.range._pad[0] || mso.u.range._pad[1] || - mso.u.range._pad[2] ) - goto out; + mso.u.range._pad[2] ) + goto out; =20 /* * We use opaque for the hypercall continuation value. @@ -1557,8 +1568,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) * that it's at least in range. */ if ( mso.u.range.opaque && - (mso.u.range.opaque < mso.u.range.first_gfn || - mso.u.range.opaque > mso.u.range.last_gfn) ) + (mso.u.range.opaque < mso.u.range.first_gfn || + mso.u.range.opaque > mso.u.range.last_gfn) ) goto out; =20 if ( !mem_sharing_enabled(d) ) @@ -1593,7 +1604,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) * the duration of this op. */ if ( !atomic_read(&d->pause_count) || - !atomic_read(&cd->pause_count) ) + !atomic_read(&cd->pause_count) ) { rcu_unlock_domain(cd); rc =3D -EINVAL; @@ -1604,9 +1615,9 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) max_cgfn =3D domain_get_maximum_gpfn(cd); =20 if ( max_sgfn < mso.u.range.first_gfn || - max_sgfn < mso.u.range.last_gfn || - max_cgfn < mso.u.range.first_gfn || - max_cgfn < mso.u.range.last_gfn ) + max_sgfn < mso.u.range.last_gfn || + max_cgfn < mso.u.range.first_gfn || + max_cgfn < mso.u.range.last_gfn ) { rcu_unlock_domain(cd); rc =3D -EINVAL; @@ -1657,9 +1668,9 @@ int mem_sharing_domctl(struct domain *d, struct xen_d= omctl_mem_sharing_op *mec) =20 /* Only HAP is supported */ if ( !hap_enabled(d) ) - return -ENODEV; + return -ENODEV; =20 - switch(mec->op) + switch (mec->op) { case XEN_DOMCTL_MEM_SHARING_CONTROL: { --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel