From patchwork Mon Dec 16 16:26:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22522 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f69.google.com (mail-qe0-f69.google.com [209.85.128.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1C9FF23FC7 for ; Mon, 16 Dec 2013 16:26:48 +0000 (UTC) Received: by mail-qe0-f69.google.com with SMTP id 1sf9639475qec.4 for ; Mon, 16 Dec 2013 08:26:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=ug0fBZuWJh0SXTCp4Yef1cV4/7PFpg6A9c+2BPFr/t0=; b=V0lsiSiszeuk9dGIESR+LMVqk9I0EPAyI6dR68lmx2C2/mkvhPDipmpKCFinr2ukvN YO2QdVV2SC3u6Tc3s2zdTA908FB8ZnB++0KUa2lO1X+z6WDkf4VEsMff2ayTe0C8I1hB Pjg5N4PfYiUWUfLDlDxlY8YHtLbLbuH/OTnIqszfbLTq1BhXSh4epRXr1+yrLxwaErrz PkmgSo/F4fST0yI5jTTwNb3PbnyGjVfpWO6XI1fv3p/GhnY96D++L+n5I63iTZx+cmz5 WAX4G9tZBWvgau9/lkYPkY2O5XCLzmlYdYjX/u0/Q4v0ML7r0Hh+bfYBTu594Df1AdUV PmaQ== X-Gm-Message-State: ALoCoQmq1Br8Cr32Z/EygE8pz/TsT9dQtkEZqeqMxBn6yQRCB3NraeTwUi6kersfC4lyCNr2dbtp X-Received: by 10.236.131.202 with SMTP id m50mr5346268yhi.42.1387211207874; Mon, 16 Dec 2013 08:26:47 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.15.234 with SMTP id a10ls2166879qed.92.gmail; Mon, 16 Dec 2013 08:26:47 -0800 (PST) X-Received: by 10.52.249.105 with SMTP id yt9mr664977vdc.67.1387211207760; Mon, 16 Dec 2013 08:26:47 -0800 (PST) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id n17si4105915vcq.135.2013.12.16.08.26.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:26:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so3271859vcb.22 for ; Mon, 16 Dec 2013 08:26:47 -0800 (PST) X-Received: by 10.221.42.133 with SMTP id ty5mr700797vcb.61.1387211207679; Mon, 16 Dec 2013 08:26:47 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp1291vcz; Mon, 16 Dec 2013 08:26:47 -0800 (PST) X-Received: by 10.204.164.145 with SMTP id e17mr629954bky.136.1387211206584; Mon, 16 Dec 2013 08:26:46 -0800 (PST) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id ov3si4173193bkb.77.2013.12.16.08.26.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:26:46 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.214.50; Received: by mail-bk0-f50.google.com with SMTP id e11so2415900bkh.37 for ; Mon, 16 Dec 2013 08:26:46 -0800 (PST) X-Received: by 10.204.59.198 with SMTP id m6mr20803bkh.177.1387211205884; Mon, 16 Dec 2013 08:26:45 -0800 (PST) Received: from [192.168.0.2] (cpc8-cmbg15-2-0-cust169.5-4.cable.virginm.net. [86.30.140.170]) by mx.google.com with ESMTPSA id mf4sm10950249bkb.7.2013.12.16.08.26.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:26:45 -0800 (PST) Message-ID: <52AF29C3.1030700@linaro.org> Date: Mon, 16 Dec 2013 16:26:43 +0000 From: Julien Grall User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Ian Campbell CC: Tim Deegan , xen-devel@lists.xenproject.org, patches@linaro.org, stefano.stabellini@citrix.com, Jan Beulich , Keir Fraser Subject: Re: [PATCH v4 08/11] xen/arm: Handle remove foreign mapping References: <1386963461-6520-1-git-send-email-julien.grall@linaro.org> <1386963461-6520-9-git-send-email-julien.grall@linaro.org> <20131216115131.GB35881@deinos.phlegethon.org> <52AF1D6E.7080402@linaro.org> <1387208403.21086.12.camel@kazak.uk.xensource.com> In-Reply-To: <1387208403.21086.12.camel@kazak.uk.xensource.com> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 12/16/2013 03:40 PM, Ian Campbell wrote: > On Mon, 2013-12-16 at 15:34 +0000, Julien Grall wrote: >> >> On 12/16/2013 11:51 AM, Tim Deegan wrote: >>> At 19:37 +0000 on 13 Dec (1386959858), Julien Grall wrote: >>>> @@ -693,12 +694,21 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) >>>> return rc; >>>> } >>>> >>>> - page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC); >>>> + /* >>>> + * If autotranslate guest, (eg pvh), the gfn could be mapped to a mfn >>>> + * from foreign domain by the user space tool during domain creation. >>>> + * We need to check for that, free it up from the p2m, and release >>>> + * refcnt on it. In such a case, page would be NULL and the following >>>> + * call would not have refcnt'd the page. >>>> + */ >>>> + page = get_page_from_gfn(d, xrfp.gpfn, &p2mt, P2M_ALLOC); >>>> if ( page ) >>>> { >>>> guest_physmap_remove_page(d, xrfp.gpfn, page_to_mfn(page), 0); >>>> put_page(page); >>>> } >>>> + else if ( p2m_is_foreign(p2mt) ) >>>> + rc = p2m_remove_foreign(d, xrfp.gpfn); >>> >>> This doesn't seem like the right interface -- having special cases >>> like this in the callers is something we slipped into in x86 for a lot >>> of the paging/sharing code and it's not nice. I think maybe we can >>> just have get_page_from_gfn() DTRT for foreign (and grant) entries. >>> >>> Also, the comment will have been out of data by the time the x86 >>> version of this code is finished, as we won't be handling the refcount >>> at this level. :) >> >> I will remove the comment and modify get_page_from_gfn to handle foreign >> mapping. > > You'll want to coordinate with Mukesh on that latter I think. > > Ian. > > I have reworked this patch. I get a simpler patch: commit aab2e5d2ae7d0fa87c74cae2f22044f87be33f70 Author: Julien Grall Date: Fri Dec 13 16:51:03 2013 +0000 xen/arm: Handle remove foreign mapping Modify get_page_from_gfn to take reference on foreign mapping. This will avoid specific handling in the common code. Signed-off-by: Julien Grall --- Changes in v5: - Remove specific p2m handling in common code - Handle foreign mapping in get_page_from_gfn Changes in v4: - Split patch #6 from dom0 pvh series v6.2 to retrieve only common code. - Rework commit title - Rename xen_rem_foreign_from_p2m in p2m_remove_foreign - Get the mfn from the pte. We are not sure that maddr given in parameters is valid Changes in v3: - Move put_page in create_p2m_entries - Move xenmem_rem_foreign_from_p2m in arch/arm/p2m.c Changes in v2: - Introduce the patch diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 39d8a03..f7bd7e2 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -317,10 +317,21 @@ static int create_p2m_entries(struct domain *d, break; case REMOVE: { - lpae_t pte; + lpae_t pte = third[third_table_offset(addr)]; + unsigned long mfn; + + maddr = (pte.bits & PADDR_MASK & PAGE_MASK); + mfn = paddr_to_pfn(maddr); + + /* TODO: Handle other p2m type */ + if ( pte.p2m.valid && p2m_is_foreign(pte.p2m.type) ) + { + ASSERT(mfn_valid(mfn)); + put_page(mfn_to_page(mfn)); + } + memset(&pte, 0x00, sizeof(pte)); write_pte(&third[third_table_offset(addr)], pte); - maddr += PAGE_SIZE; } break; } diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 0eb07a8..e0b58da 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -122,9 +122,21 @@ static inline struct page_info *get_page_from_gfn( if ( !mfn_valid(mfn) ) return NULL; page = mfn_to_page(mfn); - if ( !get_page(page, d) ) - return NULL; - return page; + + if ( get_page(page, d) ) + return page; + + /* get_page won't work on foreign mapping because the page doesn't + * belong to the current domain. + */ + if ( p2mt == p2m_map_foreign ) + { + struct domain *fdom = page_get_owner_and_reference(page); + ASSERT(fdom != NULL); + return page; + } + + return NULL; } int get_page_type(struct page_info *page, unsigned long type);