From: "Jan Beulich" Subject: Re: [PATCH v12] introduce XENMEM_reserved_device_memory_map Date: Wed, 22 Jul 2015 07:03:24 -0600 Message-ID: <55AFB0BC02000078000940BA@prv-mh.provo.novell.com> References: <1437528607-19315-1-git-send-email-tiejun.chen@intel.com> <1437528607-19315-2-git-send-email-tiejun.chen@intel.com> <55AF8F9B0200007800093F69@prv-mh.provo.novell.com> <55AF92AF.4080107@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <55AF92AF.4080107@intel.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Tiejun Chen Cc: Kevin Tian , Keir Fraser , Tim Deegan , Ian Jackson , xen-devel@lists.xen.org, Ian Campbell , Yang Z Zhang List-Id: xen-devel@lists.xenproject.org >>> On 22.07.15 at 14:55, wrote: >> +#ifdef HAS_PASSTHROUGH >> + case XENMEM_reserved_device_memory_map: >> + { >> + struct get_reserved_device_memory grdm; >> + >> + if ( unlikely(start_extent) ) >> + return -ENOSYS; >> + >> + if ( copy_from_guest(&grdm.map, compat, 1) || >> + !compat_handle_okay(grdm.map.buffer, grdm.map.nr_entries) > ) >> + return -EFAULT; >> + >> + if ( grdm.map.flags & ~XENMEM_RDM_ALL ) >> + return -EINVAL; >> + >> + grdm.used_entries = 0; >> + rc = iommu_get_reserved_device_memory(get_reserved_device_memory, >> + &grdm); >> + > > Just as you asked me previously, > > Here if RDM doesn't exist, so > > grdm.map.nr_entries = grdm.used_entries = 0, and rc = 0, right? No, grdm.map.nr_entries still holds whatever the caller passed. >> + if ( !rc && grdm.map.nr_entries < grdm.used_entries ) >> + rc = -ENOBUFS; >> + grdm.map.nr_entries = grdm.used_entries; >> + if ( __copy_to_guest(compat, &grdm.map, 1) ) > > So can we still do this copy here? We not only can, we need to. The only case where we might skip it is when the incoming grdm.map.nr_entries is unchanged. Jan