From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480983; cv=none; d=zohomail.com; s=zohoarc; b=j0j0zkZkcLS7U7VqftrUhoxjx+il0bulXu7HvECeLJXaJOx6oB5TK0M3traGRSrTPlFwTQHFYbSwPzO52Q06CZOu9GVMfEuHL31EuTMULkO0GSVn/8ghntrLEJypIGpva3vPNxSEeKERdcpcmg4Z+3X1JVP5PaSHu2JUis4n52Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480983; 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; bh=KyJyJAAofd6nSp/ad2sVTz+Yb/mwYdzHVzNAsJfQROw=; b=DwWH7T3FqCdE6LUF3N4RfPjCADEZI8IW1qmMqd/xxHR9GThdvaJVP5etzDiv3bg3ksGoN+24gDsoMl6iE10cT8B53DkypyK/VbG1IOhm17otVaxQkbw+yljVbW1gm7wJMWmX0PtafEi758MPcHXUgzwpRmj+QHNkjTMWJi6g9pg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480983031288.83145752776045; Tue, 12 Jan 2021 11:49:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65966.117004 (Exim 4.92) (envelope-from ) id 1kzPfU-0006bC-7U; Tue, 12 Jan 2021 19:49:28 +0000 Received: by outflank-mailman (output) from mailman id 65966.117004; Tue, 12 Jan 2021 19:49:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfU-0006b2-3K; Tue, 12 Jan 2021 19:49:28 +0000 Received: by outflank-mailman (input) for mailman id 65966; Tue, 12 Jan 2021 19:49:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfT-00064W-9x for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:27 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0d843cb8-1e7a-4e10-97f5-df9f4a6e9bae; Tue, 12 Jan 2021 19:49:05 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 0d843cb8-1e7a-4e10-97f5-df9f4a6e9bae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480945; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QP34gUd0yVaYagIl+iAquadIBVEzTLaCpk9INm1PzbU=; b=UiRAtP14rF8+Aaen6AXCdpOEyQquQc9B4Kkn4DecxEVE+XCf46oPhFnS Mmc6ILvMLewLFugsl6mutFVlqIJH3x0R0J+etGWw7C9Io4uk/Ml3wZFEy zGyduw6V0HPiZ2Xh2nebpyLPl30kaD2oeSnZpvN+VEj8IDTn/B7u1CxEk o=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: hbTK65Tba221UsgBf/E7NkDFhhPx7vv8w4GZdv6KpeizVuIybV1NjGFvm6dLQzidSeN3AH8i4l h9C4nSyLBJdDbA//nIFpDIvIaGS9tHXlWVFgQbBKdycCS6rthe3Mpi2lKyU5UJQrBXRlhXAsZV xgfEuWqxXlkkr6OSl8u4PHFEgYJuQ5PstqxzpqiZK47pFlClTLvEtoe3FHfDkEXzTIdw0XW/vU BPUT+Jj6pU6vpiNHaUGJ/SqwUKKJtK1OX5mSTEIfhGA40HWG0aCKZZCX0FIAh8B7lowZIHwuVj uy4= X-SBRS: 5.2 X-MesageID: 36235817 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.79,342,1602561600"; d="scan'208";a="36235817" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 1/7] xen/gnttab: Rework resource acquisition Date: Tue, 12 Jan 2021 19:48:35 +0000 Message-ID: <20210112194841.1537-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) The existing logic doesn't function in the general case for mapping a guests grant table, due to arbitrary 32 frame limit, and the default grant table limit being 64. In order to start addressing this, rework the existing grant table logic by implementing a single gnttab_acquire_resource(). This is far more efficient than the previous acquire_grant_table() in memory.c because it doesn't take the grant table write lock, and attempt to grow the table, for every single frame. The new gnttab_acquire_resource() function subsumes the previous two gnttab_get_{shared,status}_frame() helpers. No functional change. Signed-off-by: Andrew Cooper Acked-by: Ian Jackson Reviewed-by: Jan Beulich --- CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Paul Durrant CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel v3: * Fold switch statements in gnttab_acquire_resource() --- xen/common/grant_table.c | 80 ++++++++++++++++++++++++++++-----------= ---- xen/common/memory.c | 42 ++--------------------- xen/include/xen/grant_table.h | 19 ++++------ 3 files changed, 62 insertions(+), 79 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index a5d3ed8bda..f560c250d7 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -4013,6 +4013,59 @@ static int gnttab_get_shared_frame_mfn(struct domain= *d, return 0; } =20 +int gnttab_acquire_resource( + struct domain *d, unsigned int id, unsigned long frame, + unsigned int nr_frames, xen_pfn_t mfn_list[]) +{ + struct grant_table *gt =3D d->grant_table; + unsigned int i =3D nr_frames, tot_frames; + mfn_t tmp; + void **vaddrs; + int rc; + + /* Overflow checks */ + if ( frame + nr_frames < frame ) + return -EINVAL; + + tot_frames =3D frame + nr_frames; + if ( tot_frames !=3D frame + nr_frames ) + return -EINVAL; + + /* Grow table if necessary. */ + grant_write_lock(gt); + rc =3D -EINVAL; + switch ( id ) + { + case XENMEM_resource_grant_table_id_shared: + vaddrs =3D gt->shared_raw; + rc =3D gnttab_get_shared_frame_mfn(d, tot_frames - 1, &tmp); + break; + + case XENMEM_resource_grant_table_id_status: + if ( gt->gt_version !=3D 2 ) + break; + + /* Check that void ** is a suitable representation for gt->status.= */ + BUILD_BUG_ON(!__builtin_types_compatible_p( + typeof(gt->status), grant_status_t **)); + vaddrs =3D (void **)gt->status; + rc =3D gnttab_get_status_frame_mfn(d, tot_frames - 1, &tmp); + break; + } + + /* Any errors? Bad id, or from growing the table? */ + if ( rc ) + goto out; + + for ( i =3D 0; i < nr_frames; ++i ) + mfn_list[i] =3D virt_to_mfn(vaddrs[frame + i]); + + out: + grant_write_unlock(gt); + + return rc; +} + int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, mfn_t= *mfn) { int rc =3D 0; @@ -4047,33 +4100,6 @@ int gnttab_map_frame(struct domain *d, unsigned long= idx, gfn_t gfn, mfn_t *mfn) return rc; } =20 -int gnttab_get_shared_frame(struct domain *d, unsigned long idx, - mfn_t *mfn) -{ - struct grant_table *gt =3D d->grant_table; - int rc; - - grant_write_lock(gt); - rc =3D gnttab_get_shared_frame_mfn(d, idx, mfn); - grant_write_unlock(gt); - - return rc; -} - -int gnttab_get_status_frame(struct domain *d, unsigned long idx, - mfn_t *mfn) -{ - struct grant_table *gt =3D d->grant_table; - int rc; - - grant_write_lock(gt); - rc =3D (gt->gt_version =3D=3D 2) ? - gnttab_get_status_frame_mfn(d, idx, mfn) : -EINVAL; - grant_write_unlock(gt); - - return rc; -} - static void gnttab_usage_print(struct domain *rd) { int first =3D 1; diff --git a/xen/common/memory.c b/xen/common/memory.c index b21b6c452d..82cf7b41ee 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1052,44 +1052,6 @@ static long xatp_permission_check(struct domain *d, = unsigned int space) return xsm_add_to_physmap(XSM_TARGET, current->domain, d); } =20 -static int acquire_grant_table(struct domain *d, unsigned int id, - unsigned long frame, - unsigned int nr_frames, - xen_pfn_t mfn_list[]) -{ - unsigned int i =3D nr_frames; - - /* Iterate backwards in case table needs to grow */ - while ( i-- !=3D 0 ) - { - mfn_t mfn =3D INVALID_MFN; - int rc; - - switch ( id ) - { - case XENMEM_resource_grant_table_id_shared: - rc =3D gnttab_get_shared_frame(d, frame + i, &mfn); - break; - - case XENMEM_resource_grant_table_id_status: - rc =3D gnttab_get_status_frame(d, frame + i, &mfn); - break; - - default: - rc =3D -EINVAL; - break; - } - - if ( rc ) - return rc; - - ASSERT(!mfn_eq(mfn, INVALID_MFN)); - mfn_list[i] =3D mfn_x(mfn); - } - - return 0; -} - static int acquire_resource( XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) { @@ -1144,8 +1106,8 @@ static int acquire_resource( switch ( xmar.type ) { case XENMEM_resource_grant_table: - rc =3D acquire_grant_table(d, xmar.id, xmar.frame, xmar.nr_frames, - mfn_list); + rc =3D gnttab_acquire_resource(d, xmar.id, xmar.frame, xmar.nr_fra= mes, + mfn_list); break; =20 default: diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index 98603604b8..5a2c75b880 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -56,10 +56,10 @@ int mem_sharing_gref_to_gfn(struct grant_table *gt, gra= nt_ref_t ref, =20 int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, mfn_t *mfn); -int gnttab_get_shared_frame(struct domain *d, unsigned long idx, - mfn_t *mfn); -int gnttab_get_status_frame(struct domain *d, unsigned long idx, - mfn_t *mfn); + +int gnttab_acquire_resource( + struct domain *d, unsigned int id, unsigned long frame, + unsigned int nr_frames, xen_pfn_t mfn_list[]); =20 #else =20 @@ -93,14 +93,9 @@ static inline int gnttab_map_frame(struct domain *d, uns= igned long idx, return -EINVAL; } =20 -static inline int gnttab_get_shared_frame(struct domain *d, unsigned long = idx, - mfn_t *mfn) -{ - return -EINVAL; -} - -static inline int gnttab_get_status_frame(struct domain *d, unsigned long = idx, - mfn_t *mfn) +static inline int gnttab_acquire_resource( + struct domain *d, unsigned int id, unsigned long frame, + unsigned int nr_frames, xen_pfn_t mfn_list[]) { return -EINVAL; } --=20 2.11.0 From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480980; cv=none; d=zohomail.com; s=zohoarc; b=BJ3M4Bxmf6sP3udiHAsNvdstXjXJnv4qKHZEZDqkBvP+j/WJ/YEH5GSPylZKsgwrtqLVqIse8g5QAMNsL6+UU+YhmAilBGsOljcHxKibnz4RsHvoZjdvrx67ipC5IiwV907N+LA4u53b/YTV66Qlr3fIFZj9a3TZv7ynSPSp8UU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480980; 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; bh=8NQhvfCefpuWEAzOBC+rzob4RY9RIRKTchSCDontTCo=; b=Wf0PJVnLlXppbV2GBnYyS5YPLnNCfek6Zt6ovxAB6YfuFq/9LtGJ3QHaET3ixv5BiVODW2OoafzYDIxFxjWd9QhG1zomSnqecsNMgb+vW7ijst2o4bQDyTbBsZogxGsDLyBsRy/aiIXCmkKEinalTE62ES+bO9nOIrP8W3gMpW4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480980635542.8907864716725; Tue, 12 Jan 2021 11:49:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65963.116992 (Exim 4.92) (envelope-from ) id 1kzPfP-0006VR-RZ; Tue, 12 Jan 2021 19:49:23 +0000 Received: by outflank-mailman (output) from mailman id 65963.116992; Tue, 12 Jan 2021 19:49:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfP-0006VF-Nk; Tue, 12 Jan 2021 19:49:23 +0000 Received: by outflank-mailman (input) for mailman id 65963; Tue, 12 Jan 2021 19:49:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfO-00064W-9y for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:22 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7eab4440-a59f-415b-afa0-34947c85bb91; Tue, 12 Jan 2021 19:49:04 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 7eab4440-a59f-415b-afa0-34947c85bb91 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X/PbmeBQtvy5GUaatFDXs/925CHjaXa3SUYUSvIYvMM=; b=TN21oHGZ2S5vtOKscXv5estJXUrSyeBuCrudbzB8I/1g0MqHjs8cB7X8 8eIKoR3oxmhGXQ3mYP0ggzD0tbE9LLN8eFJIe72F04zdvf3j3GErm4P33 cHMyFcOyr056sl9yAlWrYnFffj7TDJGv/YoyGvpSBqxLQaBUFIzhGeKyj w=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: erp6TVIUXQsw2FD39zaUKacuDPNFyTXqH89xkma3aulfGmx5YlkArPzhtgL5Uz3cGPV9BnoFu7 sOfJ735l6Uzyy3TqfaogeolcLhCzovuwzLn50Ag6GzO+S2YBDDpetlZTriQ327YhgtFlobFlHn NT5YkPTctsYLJ+uq+TIZUvwQgALIq2KSPM5t3pYmDpAkfhTK/BB/8YdSVv/9/Pe6Ocma35So70 PmsnMb7fyeFH4UTlus6cW4hVvPFot44oOLGmr4tIKfvOPw8RiDPva5gbJcFQk8mQyhgs611/rI FLU= X-SBRS: 5.2 X-MesageID: 36235816 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.79,342,1602561600"; d="scan'208";a="36235816" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 2/7] xen/memory: Fix acquire_resource size semantics Date: Tue, 12 Jan 2021 19:48:36 +0000 Message-ID: <20210112194841.1537-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) Calling XENMEM_acquire_resource with a NULL frame_list is a request for the size of the resource, but the returned 32 is bogus. If someone tries to follow it for XENMEM_resource_ioreq_server, the acquire call will fail as IOREQ servers currently top out at 2 frames, and it is on= ly half the size of the default grant table limit for guests. Also, no users actually request a resource size, because it was never wired= up in the sole implementaion of resource acquisition in Linux. Introduce a new resource_max_frames() to calculate the size of a resource, = and implement it the IOREQ and grant subsystems. It is impossible to guarantee that a mapping call following a successful si= ze call will succeed (e.g. The target IOREQ server gets destroyed, or the doma= in switches from grant v2 to v1). Document the restriction, and use the flexibility to simplify the paths to be lockless. Signed-off-by: Andrew Cooper Reviewed-by: Paul Durrant Reviewed-by: Jan Beulich --- CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Paul Durrant CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel v3: * Use const struct domain * * Fold goto out paths v2: * Spelling fixes * Add more local variables. * Don't return any status frames on ARM where v2 support is compiled out. --- xen/arch/x86/mm.c | 20 +++++++++++++++++ xen/common/grant_table.c | 23 ++++++++++++++++++++ xen/common/memory.c | 50 ++++++++++++++++++++++++++++++++-------= ---- xen/include/asm-x86/mm.h | 3 +++ xen/include/public/memory.h | 16 ++++++++++---- xen/include/xen/grant_table.h | 8 +++++++ xen/include/xen/mm.h | 6 ++++++ 7 files changed, 109 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 63e9fae919..7a2e94cd6f 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4587,6 +4587,26 @@ static int handle_iomem_range(unsigned long s, unsig= ned long e, void *p) return err || s > e ? err : _handle_iomem_range(s, e, p); } =20 +unsigned int arch_resource_max_frames( + const struct domain *d, unsigned int type, unsigned int id) +{ + unsigned int nr =3D 0; + + switch ( type ) + { +#ifdef CONFIG_HVM + case XENMEM_resource_ioreq_server: + if ( !is_hvm_domain(d) ) + break; + /* One frame for the buf-ioreq ring, and one frame per 128 vcpus. = */ + nr =3D 1 + DIV_ROUND_UP(d->max_vcpus * sizeof(struct ioreq), PAGE_= SIZE); + break; +#endif + } + + return nr; +} + int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index f560c250d7..bd99dddbf6 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -4013,6 +4013,29 @@ static int gnttab_get_shared_frame_mfn(struct domain= *d, return 0; } =20 +unsigned int gnttab_resource_max_frames(const struct domain *d, unsigned i= nt id) +{ + const struct grant_table *gt =3D d->grant_table; + unsigned int nr =3D 0; + + /* Don't need the grant lock. This limit is fixed at domain create ti= me. */ + switch ( id ) + { + case XENMEM_resource_grant_table_id_shared: + nr =3D gt->max_grant_frames; + break; + + case XENMEM_resource_grant_table_id_status: + if ( GNTTAB_MAX_VERSION < 2 ) + break; + + nr =3D grant_to_status_frames(gt->max_grant_frames); + break; + } + + return nr; +} + int gnttab_acquire_resource( struct domain *d, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]) diff --git a/xen/common/memory.c b/xen/common/memory.c index 82cf7b41ee..beefa6a313 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1052,6 +1052,26 @@ static long xatp_permission_check(struct domain *d, = unsigned int space) return xsm_add_to_physmap(XSM_TARGET, current->domain, d); } =20 +/* + * Return 0 on any kind of error. Caller converts to -EINVAL. + * + * All nonzero values should be repeatable (i.e. derived from some fixed + * property of the domain), and describe the full resource (i.e. mapping t= he + * result of this call will be the entire resource). + */ +static unsigned int resource_max_frames(const struct domain *d, + unsigned int type, unsigned int id) +{ + switch ( type ) + { + case XENMEM_resource_grant_table: + return gnttab_resource_max_frames(d, id); + + default: + return arch_resource_max_frames(d, type, id); + } +} + static int acquire_resource( XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) { @@ -1063,6 +1083,7 @@ static int acquire_resource( * use-cases then per-CPU arrays or heap allocations may be required. */ xen_pfn_t mfn_list[32]; + unsigned int max_frames; int rc; =20 /* @@ -1079,19 +1100,6 @@ static int acquire_resource( if ( xmar.pad !=3D 0 ) return -EINVAL; =20 - if ( guest_handle_is_null(xmar.frame_list) ) - { - if ( xmar.nr_frames ) - return -EINVAL; - - xmar.nr_frames =3D ARRAY_SIZE(mfn_list); - - if ( __copy_field_to_guest(arg, &xmar, nr_frames) ) - return -EFAULT; - - return 0; - } - if ( xmar.nr_frames > ARRAY_SIZE(mfn_list) ) return -E2BIG; =20 @@ -1103,6 +1111,22 @@ static int acquire_resource( if ( rc ) goto out; =20 + max_frames =3D resource_max_frames(d, xmar.type, xmar.id); + + rc =3D -EINVAL; + if ( !max_frames ) + goto out; + + if ( guest_handle_is_null(xmar.frame_list) ) + { + if ( xmar.nr_frames ) + goto out; + + xmar.nr_frames =3D max_frames; + rc =3D __copy_field_to_guest(arg, &xmar, nr_frames) ? -EFAULT : 0; + goto out; + } + switch ( xmar.type ) { case XENMEM_resource_grant_table: diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index deeba75a1c..a40a7fa024 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -639,6 +639,9 @@ static inline bool arch_mfn_in_directmap(unsigned long = mfn) return mfn <=3D (virt_to_mfn(eva - 1) + 1); } =20 +unsigned int arch_resource_max_frames(const struct domain *d, + unsigned int type, unsigned int id); + int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]); diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 21d483298e..d7eb34f167 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -639,10 +639,18 @@ struct xen_mem_acquire_resource { #define XENMEM_resource_grant_table_id_status 1 =20 /* - * IN/OUT - As an IN parameter number of frames of the resource - * to be mapped. However, if the specified value is 0 and - * frame_list is NULL then this field will be set to the - * maximum value supported by the implementation on return. + * IN/OUT + * + * As an IN parameter number of frames of the resource to be mapped. + * + * When frame_list is NULL and nr_frames is 0, this is interpreted as a + * request for the size of the resource, which shall be returned in the + * nr_frames field. + * + * The size of a resource will never be zero, but a nonzero result doe= sn't + * guarantee that a subsequent mapping request will be successful. Th= ere + * are further type/id specific constraints which may change between t= he + * two calls. */ uint32_t nr_frames; uint32_t pad; diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index 5a2c75b880..015704bebc 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -57,6 +57,8 @@ int mem_sharing_gref_to_gfn(struct grant_table *gt, grant= _ref_t ref, int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, mfn_t *mfn); =20 +unsigned int gnttab_resource_max_frames(const struct domain *d, unsigned i= nt id); + int gnttab_acquire_resource( struct domain *d, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]); @@ -93,6 +95,12 @@ static inline int gnttab_map_frame(struct domain *d, uns= igned long idx, return -EINVAL; } =20 +static inline unsigned int gnttab_resource_max_frames( + const struct domain *d, unsigned int id) +{ + return 0; +} + static inline int gnttab_acquire_resource( struct domain *d, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index e62a5b726e..2a919fbcb4 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -703,6 +703,12 @@ static inline void put_page_alloc_ref(struct page_info= *page) } =20 #ifndef CONFIG_ARCH_ACQUIRE_RESOURCE +static inline unsigned int arch_resource_max_frames( + const struct domain *d, unsigned int type, unsigned int id) +{ + return 0; +} + static inline int arch_acquire_resource( struct domain *d, unsigned int type, unsigned int id, unsigned long fr= ame, unsigned int nr_frames, xen_pfn_t mfn_list[]) --=20 2.11.0 From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480972; cv=none; d=zohomail.com; s=zohoarc; b=mNpZ8Iim+RYzo0HOw8q8wcVrxlkWzH/8lHLp0ydpJzXayAbc2yt6OwJa/rTOw4dsKuZzging6ATrSqA1jwA9VePUVCUmoJqBcTuVIRNjTemINXJAXR/8ACZTBFUxKE/INwGz7Mhv6RDkxwRTZ0Y/m9jQsyIp35wuLnjSFiSvGio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480972; 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; bh=v8FZVQawRNw7z46TQdLsbTGKwRN7Av0SF9ttRLIH5AA=; b=mo5tc44zUK4WdYCeUQ37m6K9PKWIIGM+qF5TfwSEz+PSPk5yvJRlQESxfN/M7dNefkZT8FpQp2I9YdB3q9Qovot7a3zDHX9eRjUC06/SPvRkvBfmDAPMrfXqskj+8m95oLDKC/xu3cHSBFLWHajzzutKAVQ+Kl7FmmkqF1/AkFo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480972347803.9506712103719; Tue, 12 Jan 2021 11:49:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65957.116944 (Exim 4.92) (envelope-from ) id 1kzPfB-0006AD-A5; Tue, 12 Jan 2021 19:49:09 +0000 Received: by outflank-mailman (output) from mailman id 65957.116944; Tue, 12 Jan 2021 19:49:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfB-0006A1-6v; Tue, 12 Jan 2021 19:49:09 +0000 Received: by outflank-mailman (input) for mailman id 65957; Tue, 12 Jan 2021 19:49:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPf9-00064W-9U for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:07 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5d8dfaea-1a54-4d7d-9523-95be6ca97544; Tue, 12 Jan 2021 19:49:01 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 5d8dfaea-1a54-4d7d-9523-95be6ca97544 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480941; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KQLcpYmY2xOSiILZyQRhagK2YtSeU7ziJAAKnqO8LCQ=; b=NAEHsU6/5Imex/gD2jJXS9jHIZEX+wKY2VEWQIr71k/Gx8yF/Gu9jrzu cLcRwNY/xdf31yNMOuQTwW5cCWsvgHhGX2XvzhE4Lh7Pw7iNwrLaUqK+r S1fas3ASuxQbigxxJfpjkaUqOaWRUbr1+1vfFmoioh0Pi3n30Wx1ISbhG 0=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: z98sIzlr43XjwcMThKKI9UgCvy6P7JunM1ECjX0Ra8/9jp24ctsHSiCt70Z2CLrsN8iy39yPiM 5j7nHp1qzX3/FmDcep/aifvmuuMn9vByOHcSsckzMDZKB+gdb+8jJXXDz6gvSPrRlfvmeZiM/d W4ZVoDtig2YUAmq7DM0Pi4tkjH7NOjYCq50TgjHnA0lbmfNulozqI3OvRDzot37lNEjMf0WPoA 7F1TqMKHlv/lgVgygoX3qRKFZBzhYXtXRpJLN0F2NjxnK3PZkkQzdKzkMyJ0gR/a1+iWjnwlA4 ZEQ= X-SBRS: 5.2 X-MesageID: 36235805 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.79,342,1602561600"; d="scan'208";a="36235805" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Wei Liu , "Paul Durrant" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Juergen Gross , Ian Jackson , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 3/7] tools/foreignmem: Support querying the size of a resource Date: Tue, 12 Jan 2021 19:48:37 +0000 Message-ID: <20210112194841.1537-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) With the Xen side of this interface fixed to return real sizes, userspace needs to be able to make the query. Introduce xenforeignmemory_resource_size() for the purpose, bumping the library minor version. Update both Linux and FreeBSD's osdep_xenforeignmemory_map_resource() to understand size requests, skip the mmap() operation, and copy back the nr_frames field. Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monn=C3=A9 --- CC: Wei Liu CC: Paul Durrant CC: Roger Pau Monn=C3=A9 CC: Juergen Gross CC: Ian Jackson CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel This depends on a bugfix to the Linux IOCTL to understand size requests and pass them on to Xen. https://lore.kernel.org/xen-devel/20210112115358.23346-1-roger.pau@citrix= .com/T/#u v3: * Rewrite from scratch, to avoid breaking restricted domid situations. In particular, we cannot open a xencall interface and issue blind hypercall= s. --- tools/include/xenforeignmemory.h | 15 +++++++++++++++ tools/libs/foreignmemory/Makefile | 2 +- tools/libs/foreignmemory/core.c | 18 ++++++++++++++++++ tools/libs/foreignmemory/freebsd.c | 18 +++++++++++++++--- tools/libs/foreignmemory/libxenforeignmemory.map | 4 ++++ tools/libs/foreignmemory/linux.c | 18 +++++++++++++++--- 6 files changed, 68 insertions(+), 7 deletions(-) diff --git a/tools/include/xenforeignmemory.h b/tools/include/xenforeignmem= ory.h index d594be8df0..1ba2f5316b 100644 --- a/tools/include/xenforeignmemory.h +++ b/tools/include/xenforeignmemory.h @@ -179,6 +179,21 @@ xenforeignmemory_resource_handle *xenforeignmemory_map= _resource( int xenforeignmemory_unmap_resource( xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres); =20 +/** + * Determine the maximum size of a specific resource. + * + * @parm fmem handle to the open foreignmemory interface + * @parm domid the domain id + * @parm type the resource type + * @parm id the type-specific resource identifier + * + * Return 0 on success and fills in *nr_frames. Sets errno and return -1 = on + * error. + */ +int xenforeignmemory_resource_size( + xenforeignmemory_handle *fmem, domid_t domid, unsigned int type, + unsigned int id, unsigned long *nr_frames); + #endif =20 /* diff --git a/tools/libs/foreignmemory/Makefile b/tools/libs/foreignmemory/M= akefile index 13850f7988..90d80a49ae 100644 --- a/tools/libs/foreignmemory/Makefile +++ b/tools/libs/foreignmemory/Makefile @@ -2,7 +2,7 @@ XEN_ROOT =3D $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk =20 MAJOR =3D 1 -MINOR =3D 3 +MINOR =3D 4 =20 SRCS-y +=3D core.c SRCS-$(CONFIG_Linux) +=3D linux.c diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/cor= e.c index 63f12e2450..1e92c567e1 100644 --- a/tools/libs/foreignmemory/core.c +++ b/tools/libs/foreignmemory/core.c @@ -188,6 +188,24 @@ int xenforeignmemory_unmap_resource( return rc; } =20 +int xenforeignmemory_resource_size( + xenforeignmemory_handle *fmem, domid_t domid, unsigned int type, + unsigned int id, unsigned long *nr_frames) +{ + xenforeignmemory_resource_handle fres =3D { + .domid =3D domid, + .type =3D type, + .id =3D id, + }; + int rc =3D osdep_xenforeignmemory_map_resource(fmem, &fres); + + if ( rc ) + return rc; + + *nr_frames =3D fres.nr_frames; + return 0; +} + /* * Local variables: * mode: C diff --git a/tools/libs/foreignmemory/freebsd.c b/tools/libs/foreignmemory/= freebsd.c index 3d403a7cd0..9a2796f0b7 100644 --- a/tools/libs/foreignmemory/freebsd.c +++ b/tools/libs/foreignmemory/freebsd.c @@ -119,6 +119,10 @@ int osdep_xenforeignmemory_map_resource(xenforeignmemo= ry_handle *fmem, }; int rc; =20 + if ( !fres->addr && !fres->nr_frames ) + /* Request for resource size. Skip mmap(). */ + goto skip_mmap; + fres->addr =3D mmap(fres->addr, fres->nr_frames << PAGE_SHIFT, fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0); if ( fres->addr =3D=3D MAP_FAILED ) @@ -126,6 +130,7 @@ int osdep_xenforeignmemory_map_resource(xenforeignmemor= y_handle *fmem, =20 mr.addr =3D (uintptr_t)fres->addr; =20 + skip_mmap: rc =3D ioctl(fmem->fd, IOCTL_PRIVCMD_MMAP_RESOURCE, &mr); if ( rc ) { @@ -136,13 +141,20 @@ int osdep_xenforeignmemory_map_resource(xenforeignmem= ory_handle *fmem, else errno =3D EOPNOTSUPP; =20 - saved_errno =3D errno; - osdep_xenforeignmemory_unmap_resource(fmem, fres); - errno =3D saved_errno; + if ( fres->addr ) + { + saved_errno =3D errno; + osdep_xenforeignmemory_unmap_resource(fmem, fres); + errno =3D saved_errno; + } =20 return -1; } =20 + /* If requesting size, copy back. */ + if ( !fres->addr ) + fres->nr_frames =3D mr.num; + return 0; } =20 diff --git a/tools/libs/foreignmemory/libxenforeignmemory.map b/tools/libs/= foreignmemory/libxenforeignmemory.map index d5323c87d9..8aca341b99 100644 --- a/tools/libs/foreignmemory/libxenforeignmemory.map +++ b/tools/libs/foreignmemory/libxenforeignmemory.map @@ -19,3 +19,7 @@ VERS_1.3 { xenforeignmemory_map_resource; xenforeignmemory_unmap_resource; } VERS_1.2; +VERS_1.4 { + global: + xenforeignmemory_resource_size; +} VERS_1.3; diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/li= nux.c index fe73d5ab72..d0eead1196 100644 --- a/tools/libs/foreignmemory/linux.c +++ b/tools/libs/foreignmemory/linux.c @@ -312,6 +312,10 @@ int osdep_xenforeignmemory_map_resource( }; int rc; =20 + if ( !fres->addr && !fres->nr_frames ) + /* Request for resource size. Skip mmap(). */ + goto skip_mmap; + fres->addr =3D mmap(fres->addr, fres->nr_frames << PAGE_SHIFT, fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0); if ( fres->addr =3D=3D MAP_FAILED ) @@ -319,6 +323,7 @@ int osdep_xenforeignmemory_map_resource( =20 mr.addr =3D (uintptr_t)fres->addr; =20 + skip_mmap: rc =3D ioctl(fmem->fd, IOCTL_PRIVCMD_MMAP_RESOURCE, &mr); if ( rc ) { @@ -329,13 +334,20 @@ int osdep_xenforeignmemory_map_resource( else errno =3D EOPNOTSUPP; =20 - saved_errno =3D errno; - (void)osdep_xenforeignmemory_unmap_resource(fmem, fres); - errno =3D saved_errno; + if ( fres->addr ) + { + saved_errno =3D errno; + osdep_xenforeignmemory_unmap_resource(fmem, fres); + errno =3D saved_errno; + } =20 return -1; } =20 + /* If requesting size, copy back. */ + if ( !fres->addr ) + fres->nr_frames =3D mr.num; + return 0; } =20 --=20 2.11.0 From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480968; cv=none; d=zohomail.com; s=zohoarc; b=hSYKTlyE9ThOV5eqhwpDlq70rMgO5ObqzqOWdJV/yhD+GOORmVuDuk4T9vAfpacqPuDdjpsrU0T7OILIN1DRVhUDviVXi28Wjzk6/DqljKfvf3YiCP/hphiO+AlgKvtjonSYLzFiuK6xNnGWjge92NZKItVn2AxSYse81W+7JoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480968; 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; bh=XhbYzcV6jh2HyUvxvimwnZrP95Ui6TSPiEgh/AU85EA=; b=QvXbVraOKiEDiTuder3Rj1YKMKalr6LSsRMTqeZIC7iFSr4rDicdPTQAPkZPSMDX4TjEsQV9/SoratfaQzE3qIGqIcuale45vz3aTJVaF4n0HM4lnOdKa6QIu581KIiXdDUySYK0UC6sW7bmzEbwDSLMxYPHmu/pAzXqEc5p1QM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480967891923.762326953561; Tue, 12 Jan 2021 11:49:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65958.116956 (Exim 4.92) (envelope-from ) id 1kzPfC-0006Ca-Jb; Tue, 12 Jan 2021 19:49:10 +0000 Received: by outflank-mailman (output) from mailman id 65958.116956; Tue, 12 Jan 2021 19:49:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfC-0006CR-Fz; Tue, 12 Jan 2021 19:49:10 +0000 Received: by outflank-mailman (input) for mailman id 65958; Tue, 12 Jan 2021 19:49:09 +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.92) (envelope-from ) id 1kzPfB-00066z-5z for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:09 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bbf235d4-fe19-4919-9e9a-66968dfb69df; Tue, 12 Jan 2021 19:49:04 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: bbf235d4-fe19-4919-9e9a-66968dfb69df DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/lEUtHbPcN2XVh53IarWY1jBzQfcYRjmKojGzZEr8Dc=; b=AE1MI/iegWKgtsD+JPXaoKIgDwO701fRV4Fi9IA/rG0CkiEYQms2o1g/ 3DXUzynlX76fxwEAP3Xa2sNdKvyA3bgIwnXLmvHNYbs4/gMjPX7hJJpJu lMm7m0dqMfYlz83SU11okN1q3vXbOE6jpxh/wSO41XBiNpU9Ao8OGK3dC E=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: n3ZBGtGurNual2FwTY1cVU+Tl/bj7doQHUmwSmmGYZCz0wzxAKz81fomZupnJi6ug51g239N1k Eoepmqe8AmI/hXCrNjsYspx1SyKf8hE3s2AfU8Kud4NzDANc3UIu3rjI0c4lsnw0SJ5G8YK7hV fCADj3eCEBg0UOHbP+VzVX4hHuU9U/v2C/7dc90p1MfjwbYryvLXO1gFnS+nKYj/mW/Bt4Oe7a MnRPEuTUz/shF8l1VvjnDdMtltH23xQyAQ2bMM/xJNQcy6RmnUGJV+VGsDoH+WFwjsyB+NC2Nf 5KM= X-SBRS: 5.2 X-MesageID: 36235813 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.79,342,1602561600"; d="scan'208";a="36235813" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 4/7] xen/memory: Clarify the XENMEM_acquire_resource ABI description Date: Tue, 12 Jan 2021 19:48:38 +0000 Message-ID: <20210112194841.1537-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) This is how similar operations already operate, compatible with the sole implementation (in Linux), and explicitly gives us some flexibility. Signed-off-by: Andrew Cooper Reviewed-by: Paul Durrant --- CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Paul Durrant CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel --- xen/include/public/memory.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index d7eb34f167..c4c47a0b38 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -642,6 +642,7 @@ struct xen_mem_acquire_resource { * IN/OUT * * As an IN parameter number of frames of the resource to be mapped. + * This value may be updated during the course of the operation. * * When frame_list is NULL and nr_frames is 0, this is interpreted as a * request for the size of the resource, which shall be returned in the @@ -656,7 +657,8 @@ struct xen_mem_acquire_resource { uint32_t pad; /* * IN - the index of the initial frame to be mapped. This parameter - * is ignored if nr_frames is 0. + * is ignored if nr_frames is 0. This value may be updated + * during the course of the operation. */ uint64_t frame; =20 @@ -672,7 +674,8 @@ struct xen_mem_acquire_resource { * If -EIO is returned then the frame_list has only been * partially mapped and it is up to the caller to unmap all * the GFNs. - * This parameter may be NULL if nr_frames is 0. + * This parameter may be NULL if nr_frames is 0. This + * value may be updated during the course of the operation. */ XEN_GUEST_HANDLE(xen_pfn_t) frame_list; }; --=20 2.11.0 From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480973; cv=none; d=zohomail.com; s=zohoarc; b=ZIXIy0XLSWQZwbvMcm6CCHjFXBTWTpVZxE46BqTO7yTGi+gjQ3bAwFNVhAHfo+IOQvTdgg26lqgVYpSgJkMHwpbGkbGInHBqz2yLMIGtrb9yvKtG/2rm0LN1YYhlRFlB4dHvS3NOqMEIZvL2NNTzdFUve7LxNnq5FIKQHaGZydM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480973; 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; bh=PWsZLHvfJWqTk/YHWXOywvmmidDOtRAMDNYdicqYNkI=; b=FRlDGCwI67tGhJc0RnALKoPD/M2nZaGK2Yd9IIwQ2pfn2iQs7nEgm2opC+383osqt4LIevr6DbK1AL1U1to1OSjTpUjsMJxcMEUKjRi56xF2Iz/er1WHmN0FbWLzYsxh+Fc8UyLSN1AMmvPFcpd6Hvb3VWJDHcQsRVj0IAFqO7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480973817139.5887660078073; Tue, 12 Jan 2021 11:49:33 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65961.116980 (Exim 4.92) (envelope-from ) id 1kzPfL-0006Oy-IM; Tue, 12 Jan 2021 19:49:19 +0000 Received: by outflank-mailman (output) from mailman id 65961.116980; Tue, 12 Jan 2021 19:49:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfL-0006Ob-Cg; Tue, 12 Jan 2021 19:49:19 +0000 Received: by outflank-mailman (input) for mailman id 65961; Tue, 12 Jan 2021 19:49:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfJ-00064W-9l for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:17 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 106c2de9-507a-4377-82bf-b3d0916aba17; Tue, 12 Jan 2021 19:49:03 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 106c2de9-507a-4377-82bf-b3d0916aba17 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dQKNhP8sDS8/NNw+FPEKxJTqs+cEaD8DbMzBYrGIXcA=; b=etVESbrJmCDNsvpGpRab3vaCtGtXJx0Xy7TkGzCKOZhC/D8ZzkCa9WQk pG4ISFTsUoQ8fdlXNc3YNDHlDhC0FoFW5R/SwQQ/xLOvo4ixBh/O/4aWC cvXd5tpcSWMNK4Hwu6iO5ZE1iJir/co6At4J0VF0NAUSegxdCmzLahQZe 4=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: QYqpyNo1SW6zUx9eaBUQRfimvj8kxiucS0ZbUabB7XlyEZIiGlwxOJLgQJp9IXVzaYy1Dqi6tB gZqfG0U4K4O6WfCLUGNmbzp8SIJdpsFPts1Ww+C0WEmqMKAM2/rJi/LBdLTuAKj9P30Bhh6WVp hC9G/QsEOWMUbMdrmNBCsb2EZ7/F5dsE7ogbTqXOFGFziRg1iFIeLj+LaMVfy17o0RIKC1ztK3 dCI8udxBVAlSKCsINIyV3WwFr8bZjfIXOb1ySQ6RdvG15ppa3nJDZGpaxGDdGuAvyuQqKMdmK8 Ujw= X-SBRS: 5.2 X-MesageID: 36235810 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.79,342,1602561600"; d="scan'208";a="36235810" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 5/7] xen/memory: Improve compat XENMEM_acquire_resource handling Date: Tue, 12 Jan 2021 19:48:39 +0000 Message-ID: <20210112194841.1537-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) The frame_list is an input, or an output, depending on whether the calling domain is translated or not. The array does not need marshalling in both directions. Furthermore, the copy-in loop was very inefficient, copying 4 bytes at at time. Rewrite it to copy in all nr_frames at once, and then expand compat_pfn_t to xen_pfn_t in place. Re-position the copy-in loop to simplify continuation support in a future patch, and reduce the scope of certain variables. No change in guest observed behaviour. Signed-off-by: Andrew Cooper Reviewed-by: Paul Durrant --- CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Paul Durrant CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel --- xen/common/compat/memory.c | 65 ++++++++++++++++++++++++++++--------------= ---- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c index ed92e05b08..834c5e19d1 100644 --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -55,6 +55,8 @@ static int get_reserved_device_memory(xen_pfn_t start, xe= n_ulong_t nr, =20 int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) { + struct vcpu *curr =3D current; + struct domain *currd =3D curr->domain; int split, op =3D cmd & MEMOP_CMD_MASK; long rc; unsigned int start_extent =3D cmd >> MEMOP_EXTENT_SHIFT; @@ -399,7 +401,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE= _PARAM(void) compat) =20 case XENMEM_acquire_resource: { - xen_pfn_t *xen_frame_list; + xen_pfn_t *xen_frame_list =3D NULL; unsigned int max_nr_frames; =20 if ( copy_from_guest(&cmp.mar, compat, 1) ) @@ -417,28 +419,10 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HAND= LE_PARAM(void) compat) if ( cmp.mar.nr_frames > max_nr_frames ) return -E2BIG; =20 - if ( compat_handle_is_null(cmp.mar.frame_list) ) - xen_frame_list =3D NULL; - else - { + /* Marshal the frame list in the remainder of the xlat space. = */ + if ( !compat_handle_is_null(cmp.mar.frame_list) ) xen_frame_list =3D (xen_pfn_t *)(nat.mar + 1); =20 - if ( !compat_handle_okay(cmp.mar.frame_list, - cmp.mar.nr_frames) ) - return -EFAULT; - - for ( i =3D 0; i < cmp.mar.nr_frames; i++ ) - { - compat_pfn_t frame; - - if ( __copy_from_compat_offset( - &frame, cmp.mar.frame_list, i, 1) ) - return -EFAULT; - - xen_frame_list[i] =3D frame; - } - } - #define XLAT_mem_acquire_resource_HNDL_frame_list(_d_, _s_) \ set_xen_guest_handle((_d_)->frame_list, xen_frame_list) =20 @@ -446,6 +430,31 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDL= E_PARAM(void) compat) =20 #undef XLAT_mem_acquire_resource_HNDL_frame_list =20 + if ( xen_frame_list && cmp.mar.nr_frames ) + { + /* + * frame_list is an input for translated guests, and an ou= tput + * for untranslated guests. Only copy in for translated g= uests. + */ + if ( paging_mode_translate(currd) ) + { + compat_pfn_t *compat_frame_list =3D (void *)xen_frame_= list; + + if ( !compat_handle_okay(cmp.mar.frame_list, + cmp.mar.nr_frames) || + __copy_from_compat_offset( + compat_frame_list, cmp.mar.frame_list, + 0, cmp.mar.nr_frames) ) + return -EFAULT; + + /* + * Iterate backwards over compat_frame_list[] expanding + * compat_pfn_t to xen_pfn_t in place. + */ + for ( int x =3D cmp.mar.nr_frames - 1; x >=3D 0; --x ) + xen_frame_list[x] =3D compat_frame_list[x]; + } + } break; } default: @@ -590,8 +599,6 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE= _PARAM(void) compat) =20 case XENMEM_acquire_resource: { - const xen_pfn_t *xen_frame_list =3D (xen_pfn_t *)(nat.mar + 1); - compat_pfn_t *compat_frame_list =3D (compat_pfn_t *)(nat.mar += 1); DEFINE_XEN_GUEST_HANDLE(compat_mem_acquire_resource_t); =20 if ( compat_handle_is_null(cmp.mar.frame_list) ) @@ -601,9 +608,18 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDL= E_PARAM(void) compat) compat_mem_acquire_resource_t), nat.mar, nr_frames) ) return -EFAULT; + break; } - else + + /* + * frame_list is an input for translated guests, and an output= for + * untranslated guests. Only copy out for untranslated guests. + */ + if ( !paging_mode_translate(currd) ) { + const xen_pfn_t *xen_frame_list =3D (xen_pfn_t *)(nat.mar = + 1); + compat_pfn_t *compat_frame_list =3D (compat_pfn_t *)(nat.m= ar + 1); + /* * NOTE: the smaller compat array overwrites the native * array. @@ -625,7 +641,6 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE= _PARAM(void) compat) cmp.mar.nr_frames) ) return -EFAULT; } - break; } =20 --=20 2.11.0 From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480966; cv=none; d=zohomail.com; s=zohoarc; b=GSs4fAiT3lVD4fd1IkrQOeGgqsMqc3qXDPaiMuIj821R21QTwnHgzeEoFMqOkqIi4C3M53UeianzBCt9+dMPMmim2OhPYYb4YXK/ecUj9mZ3h/D1egYkP6ccvTr5cl0xmpxaN8DJUUG9zr+GbYlyr0q6cbLC7bo32hYP9CXeGyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480966; 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; bh=fnSWuu4s9VNjZiYTs1HLExzZSaUgM+5ZhQ11KIX2jPA=; b=YbrGWp6Yx0+C4cBo1+HElRMtAjxbzfi+LocIHKkTyhArK1xrGrLmfGFv3lvbFChR1cwYuMaP6PUvP59TM5/Uprwan7pC5p7W10QIB0O6Hzf3sfM7udZ5ZCZBNBeqreCAbiyFbDC7BnoRdVuXzVR9N1H1ZiHVydpLwpYRjF0X3W8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480966882494.9750433927444; Tue, 12 Jan 2021 11:49:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65956.116932 (Exim 4.92) (envelope-from ) id 1kzPf7-00067I-T0; Tue, 12 Jan 2021 19:49:05 +0000 Received: by outflank-mailman (output) from mailman id 65956.116932; Tue, 12 Jan 2021 19:49:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPf7-00067B-PC; Tue, 12 Jan 2021 19:49:05 +0000 Received: by outflank-mailman (input) for mailman id 65956; Tue, 12 Jan 2021 19:49:04 +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.92) (envelope-from ) id 1kzPf6-00066z-8q for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:04 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d94a7a39-d39c-4a0c-9503-0f7739b2ab27; Tue, 12 Jan 2021 19:49:02 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: d94a7a39-d39c-4a0c-9503-0f7739b2ab27 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CF1phv5+4uaV/bWMrtFd3nwHuj3efZew367gbS9TIow=; b=YJw0ODRweGkFOZmrH887XO7M7S2EF0XXtXaL+NNG3lLUq5Dh7OKFJxP7 mURKUc/I4BPT6Y+CxbUJRy8pSm4EORZxdAj+KPUBGfk0dGkM2LSDpPC0J 5JdotnPoshk3x+mmPNPNqaZazHu7UwJr+wxTipHUwaCNYV2RP9StG2Y0a 8=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: VPwpiSJwy7LLJcU6VbtVdFXN+Z8gRxPCOspOF8ZEIXVaERgIHiPnoRHACmqQoCmQT+rR8h81IG V34oSOgb/l4N1UNqSUfnlYTWe2grAAQcoNbsPLkrvIPYW34OluIoSvSMtnNpsc6Hrj/Fk00dh6 r8Ojk2mHuNtiGWb7EZhe4hB0O83kKzGVpvbQI4KF0qjgXhqTFObyGFqiRGc7cHKxF6W+YciEV6 e7RrLiN1izbFjv9hi0oUiEJ4dLsq4IHReL635JaIE1ZQM1BxAKcq4sJgGVVGCqhbCvTtrVL326 3YQ= X-SBRS: 5.2 X-MesageID: 36235809 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.79,342,1602561600"; d="scan'208";a="36235809" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 6/7] xen/memory: Indent part of acquire_resource() Date: Tue, 12 Jan 2021 19:48:40 +0000 Message-ID: <20210112194841.1537-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) Indent the middle of acquire_resource() inside a do {} while ( 0 ) loop. T= his is broken out specifically to make the following change readable. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Paul Durrant --- CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Paul Durrant CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel --- xen/common/memory.c | 66 +++++++++++++++++++++++++++----------------------= ---- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index beefa6a313..fd30eefa2e 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1127,44 +1127,46 @@ static int acquire_resource( goto out; } =20 - switch ( xmar.type ) - { - case XENMEM_resource_grant_table: - rc =3D gnttab_acquire_resource(d, xmar.id, xmar.frame, xmar.nr_fra= mes, - mfn_list); - break; + do { + switch ( xmar.type ) + { + case XENMEM_resource_grant_table: + rc =3D gnttab_acquire_resource(d, xmar.id, xmar.frame, xmar.nr= _frames, + mfn_list); + break; =20 - default: - rc =3D arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame, - xmar.nr_frames, mfn_list); - break; - } + default: + rc =3D arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame, + xmar.nr_frames, mfn_list); + break; + } =20 - if ( rc ) - goto out; + if ( rc ) + goto out; =20 - if ( !paging_mode_translate(currd) ) - { - if ( copy_to_guest(xmar.frame_list, mfn_list, xmar.nr_frames) ) - rc =3D -EFAULT; - } - else - { - xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)]; - unsigned int i; + if ( !paging_mode_translate(currd) ) + { + if ( copy_to_guest(xmar.frame_list, mfn_list, xmar.nr_frames) ) + rc =3D -EFAULT; + } + else + { + xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)]; + unsigned int i; =20 - if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames) ) - rc =3D -EFAULT; + if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames= ) ) + rc =3D -EFAULT; =20 - for ( i =3D 0; !rc && i < xmar.nr_frames; i++ ) - { - rc =3D set_foreign_p2m_entry(currd, gfn_list[i], - _mfn(mfn_list[i])); - /* rc should be -EIO for any iteration other than the first */ - if ( rc && i ) - rc =3D -EIO; + for ( i =3D 0; !rc && i < xmar.nr_frames; i++ ) + { + rc =3D set_foreign_p2m_entry(currd, gfn_list[i], + _mfn(mfn_list[i])); + /* rc should be -EIO for any iteration other than the firs= t */ + if ( rc && i ) + rc =3D -EIO; + } } - } + } while ( 0 ); =20 out: rcu_unlock_domain(d); --=20 2.11.0 From nobody Thu Apr 18 14:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1610480973; cv=none; d=zohomail.com; s=zohoarc; b=CLx8ZKDrN3xNqKTgdUAW/iN/Azh/IvZ8t2b4rfioeuGOxBhyJ6NvbvmEs4jWoTJ8oqRaPNDPP5pY3bupxkBpcBILtiLTbD7GEdDeFTv7o9qQKxYw5f++Nh+2H7FXs3MNqyjKNJE+ZLuBjqPn/TfTz5/oOeN+C1LnSY9UJ7jyJSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610480973; 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; bh=uR9xIqJridtqj7/ywfGBOx9kVEuazC76A8LmBhDI59Q=; b=h0XbvzHKOCzFzQzCWrZMfrYZnMDQotwOoJtm5tYe9M/sUSQt3jsBKnMj6/0jf/ps1+6olvidD3+Ifs1zRUec4wM2G5A0cHkYVUPcAl5aADval9kSeH70Fyj8ljrmQ1T2BGxjeULgoh99ze8ML9CfskSQDHkxCsj9FfW/eVFq56w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610480973448345.1642050823483; Tue, 12 Jan 2021 11:49:33 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.65959.116968 (Exim 4.92) (envelope-from ) id 1kzPfF-0006HK-VQ; Tue, 12 Jan 2021 19:49:13 +0000 Received: by outflank-mailman (output) from mailman id 65959.116968; Tue, 12 Jan 2021 19:49:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfF-0006H9-RZ; Tue, 12 Jan 2021 19:49:13 +0000 Received: by outflank-mailman (input) for mailman id 65959; Tue, 12 Jan 2021 19:49:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzPfE-00064W-9e for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 19:49:12 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3c23d0fb-1d60-4474-8e6c-0091daee9a30; Tue, 12 Jan 2021 19:49:02 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 3c23d0fb-1d60-4474-8e6c-0091daee9a30 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610480942; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h6cpYoyPql5rm/2pSTeQYJoN64UgrBzaPWo9HWd3Qlw=; b=Y8gHgi0UJsH2NhoaR2Nu9PLs6rGSquVCAfUQpeaZIQ+pEzhebMO/I5f7 G6bYavWWBApcud3jsx9tn2QQkhU7fRWvkQy86CQE7gwAHJbaO/+yEEUK/ 9jeuqFep5pyT4s4ignTuz7T5C6+z+Q+QiAFJ4b3qXpUVUdpbnhW6pKmxX M=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 5PQ3fF1pZ8VQKC2Db/6aWUTpoOQ3gJwK/divk7ZBTQAw9Ro3LbNlLtxL7Djgjtu/20xjoORY4F LkTYf3ssPCeMjS/MJ19gqdARyNpde0cGKCm+HEaiL5Bxp//nuoBdK3HRVAbf/HLf4FayNjT7wA vDOhD0bXFpjkqk0dPt+ofjK5sbKGpWy7zyD2xfq8uaCIDXeuZRBn/OCM1bc2Gr0tOfiVMu9x3I Ztf5xaItHfz5anBcddbuOv391Y2NGHLkqHM7i4s+9YpvPsH/go2Kw2twVRHnJkUjnCTtZgZsn7 j5k= X-SBRS: 5.2 X-MesageID: 35167851 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,342,1602561600"; d="scan'208";a="35167851" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel Subject: [PATCH v3 7/7] xen/memory: Fix mapping grant tables with XENMEM_acquire_resource Date: Tue, 12 Jan 2021 19:48:41 +0000 Message-ID: <20210112194841.1537-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210112194841.1537-1-andrew.cooper3@citrix.com> References: <20210112194841.1537-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) A guest's default number of grant frames is 64, and XENMEM_acquire_resource will reject an attempt to map more than 32 frames. This limit is caused by the size of mfn_list[] on the stack. Fix mapping of arbitrary size requests by looping over batches of 32 in acquire_resource(), and using hypercall continuations when necessary. To start with, break _acquire_resource() out of acquire_resource() to cope with type-specific dispatching, and update the return semantics to indicate the number of mfns returned. Update gnttab_acquire_resource() and x86's arch_acquire_resource() to match these new semantics. Have do_memory_op() pass start_extent into acquire_resource() so it can pick up where it left off after a continuation, and loop over batches of 32 until all the work is done, or a continuation needs to occur. compat_memory_op() is a bit more complicated, because it also has to marshal frame_list in the XLAT buffer. Have it account for continuation information itself and hide details from the upper layer, so it can marshal the buffer = in chunks if necessary. With these fixes in place, it is now possible to map the whole grant table = for a guest. Signed-off-by: Andrew Cooper --- CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Stefano Stabellini CC: Wei Liu CC: Julien Grall CC: Paul Durrant CC: Micha=C5=82 Leszczy=C5=84ski CC: Hubert Jasudowicz CC: Tamas K Lengyel v3: * Spelling fixes --- xen/arch/x86/mm.c | 4 +- xen/common/compat/memory.c | 94 +++++++++++++++++++++++++++++-------- xen/common/grant_table.c | 3 ++ xen/common/memory.c | 114 ++++++++++++++++++++++++++++++++++-------= ---- 4 files changed, 167 insertions(+), 48 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7a2e94cd6f..ad12429f6c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4628,7 +4628,6 @@ int arch_acquire_resource(struct domain *d, unsigned = int type, if ( id !=3D (unsigned int)ioservid ) break; =20 - rc =3D 0; for ( i =3D 0; i < nr_frames; i++ ) { mfn_t mfn; @@ -4639,6 +4638,9 @@ int arch_acquire_resource(struct domain *d, unsigned = int type, =20 mfn_list[i] =3D mfn_x(mfn); } + if ( i =3D=3D nr_frames ) + /* Success. Passed nr_frames back to the caller. */ + rc =3D nr_frames; break; } #endif diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c index 834c5e19d1..533db228e0 100644 --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -402,23 +402,10 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HAND= LE_PARAM(void) compat) case XENMEM_acquire_resource: { xen_pfn_t *xen_frame_list =3D NULL; - unsigned int max_nr_frames; =20 if ( copy_from_guest(&cmp.mar, compat, 1) ) return -EFAULT; =20 - /* - * The number of frames handled is currently limited to a - * small number by the underlying implementation, so the - * scratch space should be sufficient for bouncing the - * frame addresses. - */ - max_nr_frames =3D (COMPAT_ARG_XLAT_SIZE - sizeof(*nat.mar)) / - sizeof(*xen_frame_list); - - if ( cmp.mar.nr_frames > max_nr_frames ) - return -E2BIG; - /* Marshal the frame list in the remainder of the xlat space. = */ if ( !compat_handle_is_null(cmp.mar.frame_list) ) xen_frame_list =3D (xen_pfn_t *)(nat.mar + 1); @@ -432,6 +419,28 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDL= E_PARAM(void) compat) =20 if ( xen_frame_list && cmp.mar.nr_frames ) { + unsigned int xlat_max_frames =3D + (COMPAT_ARG_XLAT_SIZE - sizeof(*nat.mar)) / + sizeof(*xen_frame_list); + + if ( start_extent >=3D nat.mar->nr_frames ) + return -EINVAL; + + /* + * Adjust nat to account for work done on previous + * continuations, leaving cmp pristine. Hide the continau= tion + * from the native code to prevent double accounting. + */ + nat.mar->nr_frames -=3D start_extent; + nat.mar->frame +=3D start_extent; + cmd &=3D MEMOP_CMD_MASK; + + /* + * If there are two many frames to fit within the xlat buf= fer, + * we'll need to loop to marshal them all. + */ + nat.mar->nr_frames =3D min(nat.mar->nr_frames, xlat_max_fr= ames); + /* * frame_list is an input for translated guests, and an ou= tput * for untranslated guests. Only copy in for translated g= uests. @@ -444,14 +453,14 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HAND= LE_PARAM(void) compat) cmp.mar.nr_frames) || __copy_from_compat_offset( compat_frame_list, cmp.mar.frame_list, - 0, cmp.mar.nr_frames) ) + start_extent, nat.mar->nr_frames) ) return -EFAULT; =20 /* * Iterate backwards over compat_frame_list[] expanding * compat_pfn_t to xen_pfn_t in place. */ - for ( int x =3D cmp.mar.nr_frames - 1; x >=3D 0; --x ) + for ( int x =3D nat.mar->nr_frames - 1; x >=3D 0; --x ) xen_frame_list[x] =3D compat_frame_list[x]; } } @@ -600,9 +609,11 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDL= E_PARAM(void) compat) case XENMEM_acquire_resource: { DEFINE_XEN_GUEST_HANDLE(compat_mem_acquire_resource_t); + unsigned int done; =20 if ( compat_handle_is_null(cmp.mar.frame_list) ) { + ASSERT(split =3D=3D 0 && rc =3D=3D 0); if ( __copy_field_to_guest( guest_handle_cast(compat, compat_mem_acquire_resource_t), @@ -611,6 +622,21 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDL= E_PARAM(void) compat) break; } =20 + if ( split < 0 ) + { + /* Continuation occurred. */ + ASSERT(rc !=3D XENMEM_acquire_resource); + done =3D cmd >> MEMOP_EXTENT_SHIFT; + } + else + { + /* No continuation. */ + ASSERT(rc =3D=3D 0); + done =3D nat.mar->nr_frames; + } + + ASSERT(done <=3D nat.mar->nr_frames); + /* * frame_list is an input for translated guests, and an output= for * untranslated guests. Only copy out for untranslated guests. @@ -626,7 +652,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE= _PARAM(void) compat) */ BUILD_BUG_ON(sizeof(compat_pfn_t) > sizeof(xen_pfn_t)); =20 - for ( i =3D 0; i < cmp.mar.nr_frames; i++ ) + for ( i =3D 0; i < done; i++ ) { compat_pfn_t frame =3D xen_frame_list[i]; =20 @@ -636,15 +662,45 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HAND= LE_PARAM(void) compat) compat_frame_list[i] =3D frame; } =20 - if ( __copy_to_compat_offset(cmp.mar.frame_list, 0, + if ( __copy_to_compat_offset(cmp.mar.frame_list, start_ext= ent, compat_frame_list, - cmp.mar.nr_frames) ) + done) ) return -EFAULT; } - break; + + start_extent +=3D done; + + /* Completely done. */ + if ( start_extent =3D=3D cmp.mar.nr_frames ) + break; + + /* + * Done a "full" batch, but we were limited by space in the xl= at + * area. Go around the loop again without necesserily returni= ng + * to guest context. + */ + if ( done =3D=3D nat.mar->nr_frames ) + { + split =3D 1; + break; + } + + /* Explicit continuation request from a higher level. */ + if ( done < nat.mar->nr_frames ) + return hypercall_create_continuation( + __HYPERVISOR_memory_op, "ih", + op | (start_extent << MEMOP_EXTENT_SHIFT), compat); + + /* + * Well... Somethings gone wrong with the two levels of chunki= ng. + * My condolences to whomever next has to debug this mess. + */ + ASSERT_UNREACHABLE(); + goto crash; } =20 default: + crash: domain_crash(current->domain); split =3D 0; break; diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index bd99dddbf6..7c0481a05b 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -4083,6 +4083,9 @@ int gnttab_acquire_resource( for ( i =3D 0; i < nr_frames; ++i ) mfn_list[i] =3D virt_to_mfn(vaddrs[frame + i]); =20 + /* Success. Passed nr_frames back to the caller. */ + rc =3D nr_frames; + out: grant_write_unlock(gt); =20 diff --git a/xen/common/memory.c b/xen/common/memory.c index fd30eefa2e..bb4926fc30 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1072,17 +1072,31 @@ static unsigned int resource_max_frames(const struc= t domain *d, } } =20 +/* + * Returns -errno on error, or positive in the range [1, nr_frames] on + * success. Returning less than nr_frames contitutes a request for a + * continuation. + */ +static int _acquire_resource( + struct domain *d, unsigned int type, unsigned int id, unsigned long fr= ame, + unsigned int nr_frames, xen_pfn_t mfn_list[]) +{ + switch ( type ) + { + case XENMEM_resource_grant_table: + return gnttab_acquire_resource(d, id, frame, nr_frames, mfn_list); + + default: + return arch_acquire_resource(d, type, id, frame, nr_frames, mfn_li= st); + } +} + static int acquire_resource( - XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) + XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg, + unsigned long start_extent) { struct domain *d, *currd =3D current->domain; xen_mem_acquire_resource_t xmar; - /* - * The mfn_list and gfn_list (below) arrays are ok on stack for the - * moment since they are small, but if they need to grow in future - * use-cases then per-CPU arrays or heap allocations may be required. - */ - xen_pfn_t mfn_list[32]; unsigned int max_frames; int rc; =20 @@ -1100,9 +1114,6 @@ static int acquire_resource( if ( xmar.pad !=3D 0 ) return -EINVAL; =20 - if ( xmar.nr_frames > ARRAY_SIZE(mfn_list) ) - return -E2BIG; - rc =3D rcu_lock_remote_domain_by_id(xmar.domid, &d); if ( rc ) return rc; @@ -1119,7 +1130,7 @@ static int acquire_resource( =20 if ( guest_handle_is_null(xmar.frame_list) ) { - if ( xmar.nr_frames ) + if ( xmar.nr_frames || start_extent ) goto out; =20 xmar.nr_frames =3D max_frames; @@ -1127,26 +1138,47 @@ static int acquire_resource( goto out; } =20 + /* + * Limiting nr_frames at (UINT_MAX >> MEMOP_EXTENT_SHIFT) isn't ideal.= If + * it ever becomes a practical problem, we can switch to mutating + * xmar.{frame,nr_frames,frame_list} in guest memory. + */ + rc =3D -EINVAL; + if ( start_extent >=3D xmar.nr_frames || + xmar.nr_frames > (UINT_MAX >> MEMOP_EXTENT_SHIFT) ) + goto out; + + /* Adjust for work done on previous continuations. */ + xmar.nr_frames -=3D start_extent; + xmar.frame +=3D start_extent; + guest_handle_add_offset(xmar.frame_list, start_extent); + do { - switch ( xmar.type ) - { - case XENMEM_resource_grant_table: - rc =3D gnttab_acquire_resource(d, xmar.id, xmar.frame, xmar.nr= _frames, - mfn_list); - break; + /* + * Arbitrary size. Not too much stack space, and a reasonable str= ide + * for continuation checks. + */ + xen_pfn_t mfn_list[32]; + unsigned int todo =3D MIN(ARRAY_SIZE(mfn_list), xmar.nr_frames), d= one; =20 - default: - rc =3D arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame, - xmar.nr_frames, mfn_list); - break; - } + rc =3D _acquire_resource(d, xmar.type, xmar.id, xmar.frame, + todo, mfn_list); + if ( rc < 0 ) + goto out; =20 - if ( rc ) + done =3D rc; + rc =3D 0; + if ( done =3D=3D 0 || done > todo ) + { + ASSERT_UNREACHABLE(); + rc =3D -EINVAL; goto out; + } =20 + /* Adjust guest frame_list appropriately. */ if ( !paging_mode_translate(currd) ) { - if ( copy_to_guest(xmar.frame_list, mfn_list, xmar.nr_frames) ) + if ( copy_to_guest(xmar.frame_list, mfn_list, done) ) rc =3D -EFAULT; } else @@ -1154,10 +1186,10 @@ static int acquire_resource( xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)]; unsigned int i; =20 - if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames= ) ) + if ( copy_from_guest(gfn_list, xmar.frame_list, done) ) rc =3D -EFAULT; =20 - for ( i =3D 0; !rc && i < xmar.nr_frames; i++ ) + for ( i =3D 0; !rc && i < done; i++ ) { rc =3D set_foreign_p2m_entry(currd, gfn_list[i], _mfn(mfn_list[i])); @@ -1166,7 +1198,32 @@ static int acquire_resource( rc =3D -EIO; } } - } while ( 0 ); + + if ( rc ) + goto out; + + xmar.nr_frames -=3D done; + xmar.frame +=3D done; + guest_handle_add_offset(xmar.frame_list, done); + start_extent +=3D done; + + /* + * Explicit continuation request from _acquire_resource(), or we've + * still got more work to do. + */ + if ( done < todo || + (xmar.nr_frames && hypercall_preempt_check()) ) + { + rc =3D hypercall_create_continuation( + __HYPERVISOR_memory_op, "lh", + XENMEM_acquire_resource | (start_extent << MEMOP_EXTENT_SH= IFT), + arg); + goto out; + } + + } while ( xmar.nr_frames ); + + rc =3D 0; =20 out: rcu_unlock_domain(d); @@ -1633,7 +1690,8 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE= _PARAM(void) arg) =20 case XENMEM_acquire_resource: rc =3D acquire_resource( - guest_handle_cast(arg, xen_mem_acquire_resource_t)); + guest_handle_cast(arg, xen_mem_acquire_resource_t), + start_extent); break; =20 default: --=20 2.11.0