[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linux pin_user_pages_fast fails on Xen


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Stefano Stabellini <stefano.stabellini@xxxxxxx>
  • Date: Wed, 14 Sep 2022 18:18:28 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4jBzfq64zbmPoO+yKEshyOUcrteWknczyvtCfQcmjcQ=; b=XAiIhU3quFhvtWE0CwmeWzD5RzJ7HPUzpaP5MTwPEJzTxQHcsM30qIdCw04nhymIGI3st2G2p2b1JXCJcRFLEeUbZ4NBWvACoLzemLBt/ZJGCCc49ljGjZ/hO+aCgJlpEYMHAVEsS6H2+blcU7ErZSIqMQuIqVOdTQWILTD777eBVxEeev5XXLKrQoCQBHVht2g6OQ/r/DmjvNxpeC27rMPjdFNGn75c16Z2gSYo0QHbXAA13V2dxm99B8HGxCiOrnvQnLogv826KIxEuXdFUYlfVVH0BePMgrK/D4tQ9TwB1o1XHcjfZuMpBD2+ImKDm+YSe8QxHWafBj3bZ5qGGw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RgxdrfDDuicq2VjnRv4jcbfmVPFIQoM3JyzcKW2qQDK4lbmhWPWcCLpRraFpcs2b3X78joY6Uu0QjtLVVsJkhbJ9fh7529N7e94lDV7Iu9WoAfQSasa9xvBpgkd4ZwCFd3T/UKemTUYOvRbVsTweR4cPyDku0Q5F4xY5EQeolPM25pJxIbgoiR1gN0r7vR6n3RQZOXSfJ2NKNy1y/hQjNb3tafde7i4KG+yWx/Q362P/UTD6jp67yG+4ujjFJ/w2n38WOIhdcAizzE2w04UiTPjXDtiGWO4O7YycsYvLgNlBiFhbcFov/dmmlO/NjAV4sf9TJLNyrJD9jQpHTTfcug==
  • Cc: Stefano Stabellini <stefano.stabellini@xxxxxxx>, "NK, JESHWANTHKUMAR (JESHWANTH KUMAR)" <JESHWANTHKUMAR.NK@xxxxxxx>, "boris.ostrovsky@xxxxxxxxxx" <boris.ostrovsky@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Rangasamy, Devaraj" <Devaraj.Rangasamy@xxxxxxx>, "Pandeshwara krishna, Mythri" <Mythri.Pandeshwarakrishna@xxxxxxx>, "SK, SivaSangeetha (Siva Sangeetha)" <SivaSangeetha.SK@xxxxxxx>, "Thomas, Rijo-john" <Rijo-john.Thomas@xxxxxxx>, "jgross@xxxxxxxx" <jgross@xxxxxxxx>
  • Delivery-date: Thu, 15 Sep 2022 01:18:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, 14 Sep 2022, Jan Beulich wrote:
> On 14.09.2022 01:31, Stefano Stabellini wrote:
> > The problem is that drivers/xen/privcmd.c:privcmd_mmap sets VM_IO |
> > VM_PFNMAP, and either flag would cause check_vma_flags to return
> > -EFAULT.
> > 
> > Do you know if it works if you remove VM_IO | VM_PFNMAP from
> > privcmd_mmap?
> 
> My Linux MM knowledge is certainly rusty, but I don't think this can
> work, at the very least not without further changes elsewhere.

The definition of VM_PFNMAP is:

    Page-ranges managed without "struct page", just pure PFN

So it made perfect sense to use VM_PFNMAP back in the day when we were
using address ranges without "struct page" for foreign mappings.


However, nowadays Linux drivers typically call
xen_alloc_unpopulated_pages to get local pages to be used for foreign
mappings. xen_alloc_unpopulated_pages should work for both PV and
autotranslated guests. So the local pages should have a regular "struct
page" backing them.

I noticed that privcmd calls
alloc_empty_pages->xen_alloc_unpopulated_pages only for autotranslated
guests. Do you guys think it is intentional? In theory,
xen_alloc_unpopulated_pages should work for PV guests too.

After that, privcmd calls xen_remap_domain_gfn_array, which calls
xen_xlate_remap_gfn_array or xen_remap_pfn depending on
PV or autotranslated.

But then I can see the following at the top of xlate_remap_gfn_array:

        /* Kept here for the purpose of making sure code doesn't break
           x86 PVOPS */
        BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));

and a similar one in arch/x86/xen/mmu_pv.c:xen_remap_pfn:

        BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_IO)) == (VM_PFNMAP | VM_IO)));


Given that the pages passed to xen_xlate_remap_gfn_array and
xen_remap_pfn could have been allocated with
xen_alloc_unpopulated_pages, why the BUG_ON?

Is this just legacy? In the sense that the following could work?

- privcmd calls xen_alloc_unpopulated_pages for both PV & autotranslated
- no setting VM_PFNMAP | VM_IO
- no BUG_ON in xlate_remap_gfn_array
- no BUG_ON in xen_remap_pfn

Am I missing something?


> I did look some at the specific use by the TEE subsystem, and it looks
> to me as if their "shared memory" machinery simply isn't meant to be
> used with non-local memory.

Any more info?




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.