Received: by 10.223.176.5 with SMTP id f5csp1325655wra; Wed, 7 Feb 2018 17:24:13 -0800 (PST) X-Google-Smtp-Source: AH8x224WCNbpZd/5aKViDQ0AS9TU7HHImVbD2zYM/0anOkZpuAV1NSuZldp6FA9T0smTe67fC2jr X-Received: by 10.98.16.9 with SMTP id y9mr5243347pfi.189.1518053053535; Wed, 07 Feb 2018 17:24:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518053053; cv=none; d=google.com; s=arc-20160816; b=afPwLCpIJvHBl/5E2FRMjhHTpSK4FcMPx/Myl+lDfqFdV87/p9yRIwkOw3ORe89Cqq btAwUwE5LtwsrXRyMitiyrDodMF2kKCoNbCoEqbh/ixCaP1HA0zOzlMlW/ZPSTjTnxCx ZFOc9DzDQGbdT7nB3rFLL1TuzjQwwHE0zuu2hGlz+fRKDrgRlyyBRRFHoZoCuxwOmfJf 1jSvCEoJWrg3CtyFNsOrnv8KQiKz2Wum3BeLb6RlF5vQMurgK4Ny3OoyP8YWCDnuxVab D7IVkTRNAaXkF+lxhMM17w3FfWuz9hYpn7JcQwLmEujJXVhvGybTUadPoQDSWYnCa/XB PCKA== 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:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=yAM4Fm9ZbvaRy5fMdgz7Gvy4A+wsDEUI509v0rQLRbc=; b=GOGhhish5ildQJJ/ColSXAX8C399k/t6iDvB1tAV08HdZCHDNDD82t9GOCr2aVvPfX 2qiXpP0bKSRu1Lovr3yZXuawAWupL769m0+FRWJuJ+0o3p0DOaiQ1ojh/d6H/CeUrXu7 ziNUbttuqGrjWUKRk5ga2MiFWYdKZXaOd50+OwsP3S7O2JMQM7Q6xRJRCotej+6fnNDr iF8ocmKi2exBfgVuG9Q5ljXiU9EvLF0rE6DPGndK02e+kpFcGVdcxAwFqQod66bxAdeZ gI3FIYLzlIc5z1EzRX0kKUBbXvUkD0oxuPXSMMXNWoer6B5zsQHYw9ep+MtjDfpalAVy 24Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=l5fPA0rI; 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 j23si124787pga.474.2018.02.07.17.23.59; Wed, 07 Feb 2018 17:24:13 -0800 (PST) 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; dkim=pass header.i=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=l5fPA0rI; 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 S1752059AbeBHBXC (ORCPT + 99 others); Wed, 7 Feb 2018 20:23:02 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:43715 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752010AbeBHBXB (ORCPT ); Wed, 7 Feb 2018 20:23:01 -0500 Received: by mail-pg0-f67.google.com with SMTP id f6so1031748pgs.10 for ; Wed, 07 Feb 2018 17:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=yAM4Fm9ZbvaRy5fMdgz7Gvy4A+wsDEUI509v0rQLRbc=; b=l5fPA0rImJUkFNPgeVQFu+rFrpN8m0DLkGJotXKah49kd67Zp0FId5mDW1McdV/hGF ByfVEgkRCyVuMDX1Vx6LO9+boMD+3CMGxwTTcSnRUbj0gBbe4y0BO/rU7G9potlA2HaK +caRcTmTYGXPtmJnjVuUamIKKGGg4/yX3is4Xx/QEtLMWHHyWZ5fpZc16MQTBfo7+hKK /WDliLNe/oAsigCrBiNrHz+aL8sog5UhhtVuNID/Z5YG034cOz+/wlqXQjNF2I7cQUnl gGRuRqvtSbxLUGkM9EA/3shxAHXfFU3Bw7PSAGDifVqk+aEPd4xUEMW10CuS5VCQORzA ZdEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yAM4Fm9ZbvaRy5fMdgz7Gvy4A+wsDEUI509v0rQLRbc=; b=c7t/pCSUeBV6eOV+Vxq+FuRrQh33BT8N5gBdGx4YPONyiZXHnIHOcw7eFogRdytewW CN2p+ZoTfYbzAYou5tO2AL4YuvUtWFuOTa3XhI/wNHBQFr3dVsV7m33Au4xviE01OXh+ CNRXmJ9x0mLoMkjoyJnM3LWENmaLMUVN/0wIsTErKXKZstep3IUCSD8HFnDLlTuhV/17 SYmiBsiH32V9Hl160lj4FQ6XNyGgL5ZDx90/newvcHNLSOuT8BTwx+2XFtojWwwhmQ7I NFAnYLG9mQOebk5kfagYi3G5G9PEiYPy62QCFqfeoHllcqJFybKNcb8cB8e94A8Wtytd ZOMw== X-Gm-Message-State: APf1xPBp2+XtnzNIiRHJ1QwXHXZ5xhenmkn3pOsT8cZUR2XcHuz2o2qD dRdIg0PSzxbi8SDosn4xj8swpp0M X-Received: by 10.98.34.139 with SMTP id p11mr3921561pfj.119.1518052980189; Wed, 07 Feb 2018 17:23:00 -0800 (PST) Received: from [10.61.2.175] ([122.99.82.10]) by smtp.googlemail.com with ESMTPSA id g9sm5283090pgr.60.2018.02.07.17.22.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2018 17:22:59 -0800 (PST) Subject: Re: [RFC PATCH] vfio/pci: Add ioeventfd support To: Alex Williamson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org References: <20180207000731.32764.95992.stgit@gimli.home> <20180206212538.50ef0e13@w520.home> <6014d60c-9bdb-4dc0-7cd7-9299005d9c5a@ozlabs.ru> <20180207071253.7c606594@w520.home> From: Alexey Kardashevskiy Message-ID: <86c09adf-c4ab-5eca-629a-4d6c6a5692be@ozlabs.ru> Date: Thu, 8 Feb 2018 12:22:53 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20180207071253.7c606594@w520.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-AU Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- Alexey