Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp878307imm; Fri, 15 Jun 2018 07:40:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK49sZb7bahtllBWWpc34C1E8clNLoRsSxWzEHbXFqDofeADue18WD675YSE3gFaCyJAK/g X-Received: by 2002:a17:902:6105:: with SMTP id t5-v6mr2399187plj.138.1529073640158; Fri, 15 Jun 2018 07:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529073640; cv=none; d=google.com; s=arc-20160816; b=eN5epJssAZwY1p+DhygxyWOhCF30Sgp4c5ek2NKxJQY2k5wr8yBUelf0Z4NfNZct5P ht8hYjiZLLnw0rynV5s2sXxjWWSZ6IF+8YBAkpKWQiVnaVQ0ZcW0hC+4D8Lk4P63HKch Eap/p7tT/UVc7Bf0dGcaB/opJawz+9jjkUszuzdbyEyya2dnvd7Q0rvwNEewWZqMwD/2 vcnYqlQOd7FtXxzO4WmpqKR5kBPiiAOhGSwoFhVPCtjpUCT7RfsThVU4mCOebJHQ2Gz2 jYTi4br3t+uURNXpmNkTfbVH5C7SwBq1p8CCEncJNn3eEouyPFbjz5edf/Ehc3OeXyOQ QbFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=x8d+NbvgjVyRGaaY2BRh+W4SHHqv7nfv/FM+ypTBEfg=; b=e9HFLXPEFVmxa3DXls5rWwQfupH/wbxAM2TEUWFqjqJMHjpK1Ae/D7YBrctCCWvrbc jR88MuS9rXl0ZQ/4GQXEJOt/5TxKsqCMfcYFxqKxKcEEoG9kNecDp9EtXag+Woyon2M4 u9eDn722fGimP2Tp9CUrPyAVbHkHkw9iIbjxtQ5dxe146gu/HJEdn6CuGuP+h8rFr4XY 6M0V02Zbu6kp33oNDJTUT9AAXPvIcoGGilCR5X7JWsobNkiuZUykzXSzKGlMqYUi/Q99 +M5GmcMd+UcsdG4uTs7Y9Ke2FioN7i5LHUAlIxh/XVaGtQnqypFh6Ox4haMR9gGnPz4V jBcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4-v6si6559905pgu.390.2018.06.15.07.40.25; Fri, 15 Jun 2018 07:40:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756282AbeFOOj1 (ORCPT + 99 others); Fri, 15 Jun 2018 10:39:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:49611 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756243AbeFOOj0 (ORCPT ); Fri, 15 Jun 2018 10:39:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 093F9AD29; Fri, 15 Jun 2018 14:39:25 +0000 (UTC) Subject: Re: [Xen-devel] [PATCH] xen: add new hypercall buffer mapping device To: Andrew Cooper , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: boris.ostrovsky@oracle.com References: <20180615131740.5037-1-jgross@suse.com> <530a680a-4df2-e021-14ca-c8e2d5a551eb@citrix.com> From: Juergen Gross Openpgp: preference=signencrypt Autocrypt: addr=jgross@suse.com; prefer-encrypt=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4tyF5Lfs+Ha8xVMhIyzNb1byDI5FKCb Message-ID: Date: Fri, 15 Jun 2018 16:39:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <530a680a-4df2-e021-14ca-c8e2d5a551eb@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/06/18 16:15, Andrew Cooper wrote: > On 15/06/18 14:17, Juergen Gross wrote: >> +MODULE_LICENSE("GPL"); >> + >> +static int limit = 64; >> +module_param(limit, int, 0644); >> +MODULE_PARM_DESC(limit, "Maximum number of pages that may be allocated by " >> + "the privcmd-buf device per open file"); > > I have a feeling that, once we try and remove some of the bounce > buffering, 64 pages will be somewhat restricting.  In particular, > migration performance will benefit by keeping the logdirty bitmap buffer > persistently mapped, rather than allocated/bounced/deallocated on each > iteration. > > However, perhaps 64 is fine for now. > >> +static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) >> +{ >> + struct privcmd_buf_private *file_priv = file->private_data; >> + struct privcmd_buf_vma_private *vma_priv; >> + unsigned int count = vma_pages(vma); > > This will truncate to 0 if anyone tried mmap()ing 8T (if I've done my > calculations correctly) of virtual address space. Okay, I'll change the type to unsigned long. > >> + unsigned int i; >> + int ret = 0; >> + >> + if (!(vma->vm_flags & VM_SHARED)) { >> + pr_err("Mapping must be shared\n"); >> + return -EINVAL; >> + } >> + >> + if (file_priv->allocated + count > limit) { > > cout > limit || (allocated + count) > limit to avoid overflows. unsigned long again. > >> + pr_err("Mapping limit reached!\n"); >> + return -ENOSPC; >> + } >> + >> + vma_priv = kzalloc(sizeof(*vma_priv) + count * sizeof(void *), >> + GFP_KERNEL); >> + if (!vma_priv) >> + return -ENOMEM; >> + >> + vma_priv->n_pages = count; >> + count = 0; >> + for (i = 0; i < vma_priv->n_pages; i++) { >> + vma_priv->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO); >> + if (!vma_priv->pages[i]) >> + break; >> + count++; >> + } >> + >> + mutex_lock(&file_priv->lock); >> + >> + file_priv->allocated += count; >> + >> + vma_priv->file_priv = file_priv; >> + vma_priv->users = 1; >> + >> + vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; > > Why DONTDUMP? Its just data, and stands a reasonable chance of being > related to the cause of a crash. Hmm, yes. I'll drop it. > >> + vma->vm_ops = &privcmd_buf_vm_ops; >> + vma->vm_private_data = vma_priv; >> + >> + list_add(&vma_priv->list, &file_priv->list); >> + >> + if (vma_priv->n_pages != count) >> + ret = -ENOMEM; >> + else >> + for (i = 0; i < vma_priv->n_pages; i++) { >> + ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE, >> + vma_priv->pages[i]); >> + if (ret) >> + break; >> + } >> + >> + if (ret) >> + privcmd_buf_vmapriv_free(vma_priv); >> + >> + mutex_unlock(&file_priv->lock); >> + >> + return ret; >> +} >> + >> +const struct file_operations xen_privcmdbuf_fops = { >> + .owner = THIS_MODULE, >> + .open = privcmd_buf_open, >> + .release = privcmd_buf_release, >> + .mmap = privcmd_buf_mmap, >> +}; >> +EXPORT_SYMBOL_GPL(xen_privcmdbuf_fops); >> + >> +struct miscdevice xen_privcmdbuf_dev = { >> + .minor = MISC_DYNAMIC_MINOR, >> + .name = "xen/privcmd-buf", > > Sorry to nitpick, but how about naming this just "xen/hypercall" ? I really have no special preferences here. > privcmd is currently a rather large security hole because it allows > userspace to have access to all the hypercalls, including the ones which > should be restricted to just the kernel.  In the past, a plan has been > floated to slowly replace the use of the raw ioctl() with proper ioctls > for the hypercalls which userspace might reasonably use. I'd rather let the privcmd driver either ask the hypervisor which hypercalls are fine to call from user mode, or let it encapsulate the hypercall in a new "user hypercall" which the hypervisor can verify then. >> diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c >> index 71ddfb4cf61c..d752d0dd3d1d 100644 >> --- a/drivers/xen/xenfs/super.c >> +++ b/drivers/xen/xenfs/super.c >> @@ -48,6 +48,7 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent) >> [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR }, >> { "capabilities", &capabilities_file_ops, S_IRUGO }, >> { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR }, >> + { "privcmd-buf", &xen_privcmdbuf_fops, S_IRUSR|S_IWUSR }, > > Do we really need to provide the fallback here?  /dev/xen has been > around for ages, and it would really be a good thing if we can > eventually retire xenfs. I'd be fine dropping it. Just did some archaeology: /dev/xen is supported since Xen 4.5. Do we really want to drop support of older Xen versions in the Linux kernel? Juergen