From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Chen, Tiejun" Subject: Re: [PATCH v12] introduce XENMEM_reserved_device_memory_map Date: Wed, 22 Jul 2015 21:20:13 +0800 Message-ID: <55AF988D.9020709@intel.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> <55AFB0BC02000078000940BA@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <55AFB0BC02000078000940BA@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich 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 2015/7/22 21:03, Jan Beulich wrote: >>>> 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. What if the caller pass "0" like raising an inquiry? Indeed, this is what we did in patch #11. I think this is reasonable since the caller always doesn't know how much buffers should be allocated beforehand, so instead, the caller prefer to make this sort of inquiry without any buffers. > >>> + 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. If what I'm saying above is right, __copy_to_guest() would return a error in this case, right? I don't think this make sense. Thanks Tiejun