From: Paul Durrant <Paul.Durrant@citrix.com>
To: 'Jan Beulich' <JBeulich@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
"Tim (Xen.org)" <tim@xen.org>,
George Dunlap <George.Dunlap@citrix.com>,
Ian Jackson <Ian.Jackson@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Daniel De Graaf <dgdegra@tycho.nsa.gov>
Subject: Re: [PATCH 5/7] public / x86: introduce __HYPERCALL_iommu_op
Date: Thu, 7 Jun 2018 11:42:01 +0000 [thread overview]
Message-ID: <efc86f12783d4ab0b6ef15f50a7d59e2@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <5AABC5B402000078001B2C6B@prv-mh.provo.novell.com>
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 16 March 2018 12:25
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: Andrew Cooper <Andrew.Cooper3@citrix.com>; Wei Liu
> <wei.liu2@citrix.com>; George Dunlap <George.Dunlap@citrix.com>; Ian
> Jackson <Ian.Jackson@citrix.com>; Stefano Stabellini
> <sstabellini@kernel.org>; xen-devel@lists.xenproject.org; KonradRzeszutek
> Wilk <konrad.wilk@oracle.com>; Daniel De Graaf <dgdegra@tycho.nsa.gov>;
> Tim (Xen.org) <tim@xen.org>
> Subject: Re: [PATCH 5/7] public / x86: introduce __HYPERCALL_iommu_op
>
> >>> On 12.02.18 at 11:47, <paul.durrant@citrix.com> wrote:
> > --- a/xen/arch/x86/Makefile
> > +++ b/xen/arch/x86/Makefile
> > @@ -33,6 +33,7 @@ obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o
> > obj-y += hypercall.o
> > obj-y += i387.o
> > obj-y += i8259.o
> > +obj-y += iommu_op.o
>
> As mentioned in other contexts, I'd prefer if we stopped using
> underscores in places where dashes (or other separators not
> usable in C identifiers) are fine.
>
I don't see any guidance in CODING_STYLE or elsewhere, and also the majority of the codebase seems to prefer using underscores in module names. Personally I'd prefer new code remain consistent.
> > --- /dev/null
> > +++ b/xen/arch/x86/iommu_op.c
> > @@ -0,0 +1,169 @@
> >
> +/*********************************************************
> *********************
> > + * x86/iommu_op.c
> > + *
> > + * Paravirtualised IOMMU functionality
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; If not, see <http://www.gnu.org/licenses/>.
> > + *
> > + * Copyright (C) 2018 Citrix Systems Inc
> > + */
> > +
> > +#include <xen/event.h>
> > +#include <xen/guest_access.h>
> > +#include <xen/hypercall.h>
> > +
> > +static bool can_control_iommu(void)
> > +{
> > + struct domain *currd = current->domain;
> > +
> > + /*
> > + * IOMMU mappings cannot be manipulated if:
> > + * - the IOMMU is not enabled or,
> > + * - the IOMMU is passed through or,
>
> "is passed through" isn't really a proper description of what
> iommu_passthrough means, I'm afraid. The description of the
> option says "Control whether to disable DMA remapping for
> Dom0." Perhaps "is bypassed"? But then it would be better
> to qualify the check with is_hardware_domain(), despite you
> restricting things to Dom0 for now anyway.
>
I think I'm going to add a hypercall for a domain to enable PV IOMMU at start of day, so I'll re-work all this in a separate patch.
> > + * - shared EPT configured or,
> > + * - Xen is maintaining an identity map.
>
> Is this meant to describe ...
>
> > + */
> > + if ( !iommu_enabled || iommu_passthrough ||
> > + iommu_use_hap_pt(currd) || need_iommu(currd) )
>
> ... need_iommu() here? How is that implying an identity map?
>
> > + return false;
> > +
> > + return true;
>
> Please make this a singe return statement (with the expression as
> operand).
>
> > +long do_iommu_op(XEN_GUEST_HANDLE_PARAM(xen_iommu_op_t)
> uops,
> > + unsigned int count)
> > +{
> > + unsigned int i;
> > + int rc;
> > +
> > + rc = xsm_iommu_op(XSM_PRIV, current->domain);
> > + if ( rc )
> > + return rc;
> > +
> > + if ( !can_control_iommu() )
> > + return -EACCES;
> > +
> > + for ( i = 0; i < count; i++ )
> > + {
> > + xen_iommu_op_t op;
> > +
> > + if ( ((i & 0xff) == 0xff) && hypercall_preempt_check() )
> > + {
> > + rc = i;
>
> For this to be correct for large enough values of "count", rc needs
> to have long type.
Yes, it does indeed.
>
> > + break;
> > + }
> > +
> > + if ( copy_from_guest_offset(&op, uops, i, 1) )
> > + {
> > + rc = -EFAULT;
> > + break;
> > + }
> > +
> > + iommu_op(&op);
> > +
> > + if ( copy_to_guest_offset(uops, i, &op, 1) )
>
> __copy_to_guest_offset()
>
> Also do you really need to copy back other than the status?
At this stage, no. I'll restrict it here and it can expand later if need be.
>
> > --- /dev/null
> > +++ b/xen/include/public/iommu_op.h
> > @@ -0,0 +1,55 @@
> > +/*
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> copy
> > + * of this software and associated documentation files (the "Software"),
> to
> > + * deal in the Software without restriction, including without limitation the
> > + * rights to use, copy, modify, merge, publish, distribute, sublicense,
> and/or
> > + * sell copies of the Software, and to permit persons to whom the
> Software is
> > + * furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included
> in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
> KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
> EVENT SHALL THE
> > + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
> DAMAGES OR OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> OTHERWISE, ARISING
> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
> OR OTHER
> > + * DEALINGS IN THE SOFTWARE.
> > + *
> > + * Copyright (C) 2018 Citrix Systems Inc
> > + */
> > +
> > +#ifndef __XEN_PUBLIC_IOMMU_OP_H__
> > +#define __XEN_PUBLIC_IOMMU_OP_H__
>
> Please can you avoid introducing further name space violations
> into the public headers?
I assume you mean the leading '__'? Again, I chose the name based on consistency with other code and I'd prefer to remain consistent. Could you explain why having a leading '__' is problematic?
Paul
>
> > +#include "xen.h"
> > +
> > +struct xen_iommu_op {
> > + uint16_t op;
> > + uint16_t flags; /* op specific flags */
> > + int32_t status; /* op completion status: */
> > + /* 0 for success otherwise, negative errno */
> > +};
>
> Peeking at patch 6, you need to add the union and a large enough
> placeholder here right away, so that the struct size won't change
> with future additions.
>
> Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-06-07 11:42 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 10:47 [PATCH 0/7] paravirtual IOMMU interface Paul Durrant
2018-02-12 10:47 ` [PATCH 1/7] iommu: introduce the concept of BFN Paul Durrant
2018-03-15 13:39 ` Jan Beulich
2018-03-16 10:31 ` Paul Durrant
2018-03-16 10:39 ` Jan Beulich
2018-02-12 10:47 ` [PATCH 2/7] iommu: make use of type-safe BFN and MFN in exported functions Paul Durrant
2018-03-15 15:44 ` Jan Beulich
2018-03-16 10:26 ` Paul Durrant
2018-07-10 14:29 ` George Dunlap
2018-07-10 14:34 ` Jan Beulich
2018-07-10 14:37 ` Andrew Cooper
2018-07-10 14:58 ` George Dunlap
2018-07-10 15:19 ` Jan Beulich
2018-02-12 10:47 ` [PATCH 3/7] iommu: push use of type-safe BFN and MFN into iommu_ops Paul Durrant
2018-03-15 16:15 ` Jan Beulich
2018-03-16 10:22 ` Paul Durrant
2018-02-12 10:47 ` [PATCH 4/7] vtd: add lookup_page method to iommu_ops Paul Durrant
2018-03-15 16:54 ` Jan Beulich
2018-03-16 10:19 ` Paul Durrant
2018-03-16 10:28 ` Jan Beulich
2018-03-16 10:41 ` Paul Durrant
2018-02-12 10:47 ` [PATCH 5/7] public / x86: introduce __HYPERCALL_iommu_op Paul Durrant
2018-02-13 6:43 ` Tian, Kevin
2018-02-13 9:22 ` Paul Durrant
2018-02-23 5:17 ` Tian, Kevin
2018-02-23 9:41 ` Paul Durrant
2018-02-24 2:57 ` Tian, Kevin
2018-02-26 9:57 ` Paul Durrant
2018-02-26 11:55 ` Tian, Kevin
2018-02-27 5:05 ` Tian, Kevin
2018-02-27 9:32 ` Paul Durrant
2018-02-28 2:53 ` Tian, Kevin
2018-02-28 8:55 ` Paul Durrant
2018-03-16 12:25 ` Jan Beulich
2018-06-07 11:42 ` Paul Durrant [this message]
2018-06-07 13:21 ` Jan Beulich
2018-06-07 13:45 ` George Dunlap
2018-06-07 14:06 ` Paul Durrant
2018-06-07 14:21 ` Ian Jackson
2018-06-07 15:21 ` Paul Durrant
2018-06-07 15:41 ` Jan Beulich
2018-02-12 10:47 ` [PATCH 6/7] x86: add iommu_op to query reserved ranges Paul Durrant
2018-02-13 6:51 ` Tian, Kevin
2018-02-13 9:25 ` Paul Durrant
2018-02-23 5:23 ` Tian, Kevin
2018-02-23 9:02 ` Jan Beulich
2018-03-19 14:10 ` Jan Beulich
2018-03-19 15:13 ` Paul Durrant
2018-03-19 16:30 ` Jan Beulich
2018-03-19 15:13 ` Jan Beulich
2018-03-19 15:36 ` Paul Durrant
2018-03-19 16:31 ` Jan Beulich
2018-02-12 10:47 ` [PATCH 7/7] x86: add iommu_ops to map and unmap pages, and also to flush the IOTLB Paul Durrant
2018-02-13 6:55 ` Tian, Kevin
2018-02-13 9:55 ` Paul Durrant
2018-02-23 5:35 ` Tian, Kevin
2018-02-23 9:35 ` Paul Durrant
2018-02-24 3:01 ` Tian, Kevin
2018-02-26 9:38 ` Paul Durrant
2018-03-19 15:11 ` Jan Beulich
2018-03-19 15:34 ` Paul Durrant
2018-03-19 16:49 ` Jan Beulich
2018-03-19 16:57 ` Paul Durrant
2018-03-20 8:11 ` Jan Beulich
2018-03-20 9:32 ` Paul Durrant
2018-03-20 9:49 ` Jan Beulich
2018-02-13 6:21 ` [PATCH 0/7] paravirtual IOMMU interface Tian, Kevin
2018-02-13 9:18 ` Paul Durrant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=efc86f12783d4ab0b6ef15f50a7d59e2@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=George.Dunlap@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=JBeulich@suse.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).