Received: by 10.213.65.68 with SMTP id h4csp586imn; Thu, 15 Mar 2018 14:25:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELv/7sFIQyTUV24wjORQQtxZ669papGSlOxDL8mRc45ziEq8yLcKc71yTTfPzQS7a0aULrx2 X-Received: by 2002:a17:902:a610:: with SMTP id u16-v6mr9507385plq.293.1521149122039; Thu, 15 Mar 2018 14:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521149121; cv=none; d=google.com; s=arc-20160816; b=J5mLCk0o2wXtpbpm6FvqsUUaOy94ZRs9FBOgwBB7+1cvg8Pop4Clji41S5MqNDCJqz a5SkGf0mjtT+p5IkFYJ10sRSmqEHxE/lxMoWR4o5tLYg+lB4Ztx3htci8o7E12Xlkv+9 QZ5iwjcVLasOfFFPaxsRZu2665nl4QNW5RgRQ0WdljLjTfxveVJquBiCE1EvtbGBv/h7 5xEjsR/gdF2OxPjNkan9DlGTOrKiacjsPWdsFcfI8n98ozOa7iAgWOKZK1NfxIhSvihY 06ZaMGlIWekNCZSyjE2sazYpESfO2qDOkPLtnRKk3kKcB/IKKnVZunH7n/ZXhzOjJFjw 1SOw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=cXrsU1QQaaEtT68DtBxC44aFZ4DEWgCV5+7mbG21qA0=; b=uUtQEX8A4SVbXonMSXWgVsqvJwZbYcfnbL0FbMXaIXNIWNZEeoW3/okwlYPIXcioNc z4c4RZT2VLlb67xRsOJuyXPsZei7T9lPucbIRQYJk5TL+MN2bMWevCxK9rXjWY3gOBBl pxT03ak5zFgXoumKJGOGwm6UqGRYChGmDkA77AH4nSmDLBjFIlimC7grwDaKW6+YuOdH /GtiGdKp1RAwxBCNMpmLtoUdRhNjw1Zj+fAk2FGb0PPZcNg0rXGnJ/o3VYwDxplJll8O kiC48Mfp3tirNBlV2+8dX8ob/oCyD+k8kVXverqQ241DTrAY0jMna4GW3DIdLcm21g/W YUwg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si4423387pfa.383.2018.03.15.14.25.05; Thu, 15 Mar 2018 14:25:21 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932448AbeCOVXu (ORCPT + 99 others); Thu, 15 Mar 2018 17:23:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55662 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751877AbeCOVXn (ORCPT ); Thu, 15 Mar 2018 17:23:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAA334068023; Thu, 15 Mar 2018 21:23:42 +0000 (UTC) Received: from w520.home (ovpn-117-203.phx2.redhat.com [10.3.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19BD6C1FB3; Thu, 15 Mar 2018 21:23:35 +0000 (UTC) Date: Thu, 15 Mar 2018 15:23:34 -0600 From: Alex Williamson To: Auger Eric Cc: Alexey Kardashevskiy , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org Subject: Re: [RFC PATCH] vfio/pci: Add ioeventfd support Message-ID: <20180315152334.29ee10b6@w520.home> In-Reply-To: <777482c6-8180-df0f-0a0c-5d6e000553ba@redhat.com> References: <20180207000731.32764.95992.stgit@gimli.home> <20180206212538.50ef0e13@w520.home> <6014d60c-9bdb-4dc0-7cd7-9299005d9c5a@ozlabs.ru> <20180207071253.7c606594@w520.home> <86c09adf-c4ab-5eca-629a-4d6c6a5692be@ozlabs.ru> <777482c6-8180-df0f-0a0c-5d6e000553ba@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 15 Mar 2018 21:23:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 15 Mar 2018 21:23:42 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'alex.williamson@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 13 Mar 2018 13:38:00 +0100 Auger Eric wrote: > On 08/02/18 02:22, Alexey Kardashevskiy wrote: > > On 08/02/18 01:12, Alex Williamson wrote: > >> On Wed, 7 Feb 2018 15:48:26 +1100 > >> Alexey Kardashevskiy wrote: > >>> On 07/02/18 15:25, Alex Williamson wrote: > >>>> On Wed, 7 Feb 2018 15:09:22 +1100 > >>>> Alexey Kardashevskiy wrote: > >>>>> On 07/02/18 11:08, Alex Williamson wrote: > >>>>>> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h > >>>>>> index e3301dbd27d4..07966a5f0832 100644 > >>>>>> --- a/include/uapi/linux/vfio.h > >>>>>> +++ b/include/uapi/linux/vfio.h > >>>>>> @@ -503,6 +503,30 @@ struct vfio_pci_hot_reset { > >>>>>> > >>>>>> #define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13) > >>>>>> > >>>>>> +/** > >>>>>> + * VFIO_DEVICE_IOEVENTFD - _IOW(VFIO_TYPE, VFIO_BASE + 14, > >>>>>> + * struct vfio_device_ioeventfd) > >>>>>> + * > >>>>>> + * Perform a write to the device at the specified device fd offset, with > >>>>>> + * the specified data and width when the provided eventfd is triggered. > >>>>>> + * > >>>>>> + * Return: 0 on success, -errno on failure. > >>>>>> + */ > >>>>>> +struct vfio_device_ioeventfd { > >>>>>> + __u32 argsz; > >>>>>> + __u32 flags; > >>>>>> +#define VFIO_DEVICE_IOEVENTFD_8 (1 << 0) /* 1-byte write */ > >>>>>> +#define VFIO_DEVICE_IOEVENTFD_16 (1 << 1) /* 2-byte write */ > >>>>>> +#define VFIO_DEVICE_IOEVENTFD_32 (1 << 2) /* 4-byte write */ > >>>>>> +#define VFIO_DEVICE_IOEVENTFD_64 (1 << 3) /* 8-byte write */ > >>>>>> +#define VFIO_DEVICE_IOEVENTFD_SIZE_MASK (0xf) > >>>>>> + __u64 offset; /* device fd offset of write */ > >>>>>> + __u64 data; /* data to be written */ > >>>>>> + __s32 fd; /* -1 for de-assignment */ > >>>>>> +}; > >>>>>> + > >>>>>> +#define VFIO_DEVICE_IOEVENTFD _IO(VFIO_TYPE, VFIO_BASE + 14) > >>>>> > >>>>> > >>>>> Is this a first ioctl with endianness fixed to little-endian? I'd suggest > >>>>> to comment on that as things like vfio_info_cap_header do use the host > >>>>> endianness. > >>>> > >>>> Look at our current read and write interface, we call leXX_to_cpu > >>>> before calling iowriteXX there and I think a user would logically > >>>> expect to use the same data format here as they would there. > >>> > >>> If the data is "char data[8]" (i.e. bytestream), then it can be expected to > >>> be device/bus endian (i.e. PCI == little endian), but if it is u64 - then I > >>> am not so sure really, and this made me look around. It could be "__le64 > >>> data" too. > >>> > >>>> Also note > >>>> that iowriteXX does a cpu_to_leXX, so are we really defining the > >>>> interface as little-endian or are we just trying to make ourselves > >>>> endian neutral and counter that implicit conversion? Thanks, > >>> > >>> Defining it LE is fine, I just find it a bit confusing when > >>> vfio_info_cap_header is host endian but vfio_device_ioeventfd is not. > >> > >> But I don't think we are defining the interface as little-endian. > >> iowriteXX does a cpu_to_leXX byteswap. Therefore in order to maintain > >> endian neutrality, if the data does a cpu->le swap on the way out, I > >> need to do a le->cpu swap on the way in, right? Please defend the > >> assertion that we're creating a little-endian interface. Thanks, > > > > > > vfio_pci_ioctl() passes "endian-neutral" ioeventfd.data to > > vfio_pci_ioeventfd() which immediately does the leXX_to_cpu() conversion > > (and uses the result later on in iowriteXX(), which is not VFIO API) so I > > read it as the ioctl really expects LE. > > > > The QEMU part - vfio_nvidia_mirror_quirk MR - does not swap bytes but the > > MR itself it declared DEVICE_LITTLE_ENDIAN which means > > vfio_nvidia_quirk_mirror_write() receives byteswapped @data in the host > > endian == bigendian on a big endian host. So the ioctl() handler will > > receive a BE value, do byteswap #1 in leXX_to_cpu(), and then do byteswap > > #2 in iowriteXX() so after all a BE will be written to a device. So I'd say > > we rather do not need leXX_to_cpu() in vfio_pci_ioeventfd(). Correct me > > where I am wrong. Thanks, > > It is not crystal clear to me what is the outcome of this discussion. > Please can you clarify? > > At the beginning I understood we had a chain of lexx_to_cpu and > cpu_to_lexx (in iowritexx) so it was neutral. Now I am lost about what > we want. I've tried to address this with patch 2/3 in the newer series, adding helpers such that the implicit endian-ness of the io{read,write} functions is hidden and no extraneous swapping is done. Therefore the leXX_to_cpu() is gone, as Alexey wanted. Unless there's a new objection, this is what I intend to go with. Thanks, Alex