From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D55A6314D0E for ; Tue, 3 Feb 2026 10:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770114165; cv=none; b=bA/r8ALhNJMBvLlz+DE7xiQf6SN18dxaguGMfSCGa0CJMhrgN0qS2W0oZTtU/pUzLJSOWKiXBDnncj7qmDJcDxAL1ckvL7ebm0iVcl+ddYKldhDYWuVuD0kPv4CrLrxOF2RcfVSwEsPiGThkwjfkZ/TkTSnQOOGDvjHLqlwHem4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770114165; c=relaxed/simple; bh=prmaXrFKwwio+mOGSzr/9ol8L22BVJeYEEhmds/TAh0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MGxATicXHak2V7x/Cv6v7tcZCmngq7njdxB+1hOPa2lUDVtbgyBGK+XxidyHMlFtB/XtxyyNhzoAhFwUeDB8dpyNZVJCaImRt8KHyZ9PKXf62KIfhSE22o1svZPSw8GEMJ6fcKeh83m3riJCvQIKi7HFluGpubuF0F2IlIaOS2s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SBoFBQaI; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y0kn6oVk; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SBoFBQaI"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y0kn6oVk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770114163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xh/UmK3MDA/v1xjO80i0eilp6Lnmx07hLEk6LbEtMTs=; b=SBoFBQaIl/W4+LGX8wbUvL+lpjnSbEEMebbrtEoUBL+aQABvmlur7o9QbcIjivPvHAicuj U0g8xaVdx1g1ac4ZAIWGGPZMz4mFt6IDQ+9OwpMY4PX2rgOd+SQmEE+jsKAAMm4zXrLCJr DH9ny5rdUWKQtOmyDk3pNXrmyNE0LpE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-147-kjNf3c75PhGY5i2nue6XGg-1; Tue, 03 Feb 2026 05:22:40 -0500 X-MC-Unique: kjNf3c75PhGY5i2nue6XGg-1 X-Mimecast-MFC-AGG-ID: kjNf3c75PhGY5i2nue6XGg_1770114160 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4325b81081aso7183332f8f.3 for ; Tue, 03 Feb 2026 02:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770114160; x=1770718960; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xh/UmK3MDA/v1xjO80i0eilp6Lnmx07hLEk6LbEtMTs=; b=Y0kn6oVkPVKx/SQ6RjiT5bX89GBHLwpit4YHaKae/7HeBpinJw+Drj8cWstEniD7AY PDjph94cg9JAIXTgKMd2XuO/PWqcX7kK7OBdeeuZDgTagSy8KDukOk32RXH1uCdqO6vy h7tA4j1xZwTBuGdIaaj7Qq2KMkLmOXaD+mhspBWeOPsf7Q9ULCe1rnNDcWNTCWJ0Pegg DwasjLPRNaPgFOHOf9UhgP5UuRaXACPK+Rwe9G0HSl5JvZLadYvzi+om5j1TaVj8F/XG yS8utC4NmYyEVV6KHuLwsN19Ztnw3FrvTKnZ+OwomBFvf6vmcPjMIOYbckox/wuOMUUT Lr8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770114160; x=1770718960; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xh/UmK3MDA/v1xjO80i0eilp6Lnmx07hLEk6LbEtMTs=; b=qfsNTfD3lwGDvm5gTyqtKEjy8ISA89M4GsnwcATd73l4IeuGKealhT1AukA/DgV201 tHvvC4csZljzyYIVsGoUSLMf21UEezGR2CVl4goFj32jTKx2sly/kXEeXdMKsm8sZxsp ppPLSMDVNf0TRpYSCD9fMt5q15GifmUMSv1iNARIt3qifE6TnKoWtQpEkNNFroJzVFQZ 4gtHCNLfZx1JZUN6CHTHbXgssNS9o8+eswu6s9qa3pSWi3Yw15KKMZ9v5LUyuqg0R1w5 oUh3CRQ7YXDNvmk4CV/cg3Njkc0hGt7bQh5cqBK4Lz8NFTjpD1s5U6W8b+30DCGCpl+o YAOw== X-Forwarded-Encrypted: i=1; AJvYcCWD5gVxV4JGYbtbNE9W1I81vI46oZMxcDWSw9wCs57yBok7GjA+s7COS0FZq3Xv+6CB5fB9WqkbhZZ1spA=@vger.kernel.org X-Gm-Message-State: AOJu0YywME8iL37J58J0ll4K6tkQ+BrP5mIdR+lf2WRmGKE/kMboUUVM eNICst6X5BsNRs45n3/A1b86FhVLvxBukjMYk7iSZA1suCq54Il9B25dZk0dQdiVJhIoEkYQKUJ GQPaygNMtr4Kwkf+zM+n3D5rVicanpQdC5ascbhIb4vjU5ldh5DSHiNkoriqlpaDpjw== X-Gm-Gg: AZuq6aKnujDkQQ7+jn0zowyBkTzGnyC7Zh5mKdXc15RvEM7ZzWH7EGfK61zaDdV8Age /286Ge/Mc4ruX773Ba/4mBKkp7D/h9ii7l2V3MJxVrx9uAoMuvSg0A0gpikm34PR/UXeCvZaqze MW8qD8RkdgcbtRFRkOqhGBkE61fvOiXZ4aJPJ7vQEhhZCwrbwj+M0PL9pG2KWdRnRrhyvZImgKD KuvUIarzizxuJ58H48s0s9JlQWOIFxkyIXRP3MIvnBu6Jvy4k2TlK0qCTheG7uPmYmK3q1AXQUX hfH/TAYHr2x0B14FcE6DjsMS/tNcgNY/YS75fJaMXXy1EZ+Ou23j/20d1mLgpW/3BglB88e2Af+ t4CKJqxE2EGBkrejOmwNJR1MO5L7db0pLVQ== X-Received: by 2002:a05:6000:40da:b0:435:9bf5:b32c with SMTP id ffacd0b85a97d-435f3ab283amr23460765f8f.29.1770114159579; Tue, 03 Feb 2026 02:22:39 -0800 (PST) X-Received: by 2002:a05:6000:40da:b0:435:9bf5:b32c with SMTP id ffacd0b85a97d-435f3ab283amr23460716f8f.29.1770114159007; Tue, 03 Feb 2026 02:22:39 -0800 (PST) Received: from redhat.com (IGLD-80-230-34-155.inter.net.il. [80.230.34.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435e10ed952sm52718921f8f.10.2026.02.03.02.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 02:22:37 -0800 (PST) Date: Tue, 3 Feb 2026 05:22:35 -0500 From: "Michael S. Tsirkin" To: Arnd Bergmann Cc: Jason Wang , Xie Yongji , Arnd Bergmann , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] [v2] vduse: fix compat handling for VDUSE_IOTLB_GET_FD/VDUSE_VQ_GET_INFO Message-ID: <20260203050216-mutt-send-email-mst@kernel.org> References: <20260202224835.559538-1-arnd@kernel.org> <20260202224835.559538-2-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260202224835.559538-2-arnd@kernel.org> On Mon, Feb 02, 2026 at 11:48:08PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > These two ioctls are incompatible on 32-bit x86 userspace, because > the data structures are shorter than they are on 64-bit. > > Add a proper .compat_ioctl handler for x86 that reads the structures > with the smaller padding before calling the internal handlers. > > Fixes: ad146355bfad ("vduse: Support querying information of IOVA regions") > Fixes: c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace") > Signed-off-by: Arnd Bergmann > --- > The code is directly copied from the native ioctl handler, but I > did not test this with actual x86-32 userspace, so please review > carefully. More importantly, I'm not applying this until it's tested) > --- > drivers/vdpa/vdpa_user/vduse_dev.c | 123 ++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 1 deletion(-) > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c > index 405d59610f76..3ada167ac260 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -1618,6 +1618,127 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, > return ret; > } > > +/* ifndef CONFIG_COMPAT around the structs will make it clearer they are only for this purpose. > + * i386 has different alignment constraints than x86_64, why i386 specifically? many architectures have CONFIG_COMPAT and it looks like all of them will have the issue. > + * so there are only 3 bytes of padding instead of 7. > + */ > +struct compat_vduse_iotlb_entry { > + compat_u64 offset; > + compat_u64 start; > + compat_u64 last; > + __u8 perm; > + __u8 padding[__alignof__(compat_u64) - 1]; Was surprised to learn __alignof__ can be used to size arrays. This is the first use of this capability in the kernel. I think the point of all this is that compat_vduse_iotlb_entry will be 4 byte aligned now? Very well. But why do we bother with specifying the hidden padding? compilers adds exactly this amount anyway. Just plan compat_u64 will do the trick. > +}; > +#define COMPAT_VDUSE_IOTLB_GET_FD _IOWR(VDUSE_BASE, 0x10, struct compat_vduse_iotlb_entry) > + > +struct compat_vduse_vq_info { > + __u32 index; > + __u32 num; > + compat_u64 desc_addr; > + compat_u64 driver_addr; > + compat_u64 device_addr; > + union { > + struct vduse_vq_state_split split; > + struct vduse_vq_state_packed packed; > + }; > + __u8 ready; > + __u8 padding[__alignof__(compat_u64) - 1]; > +} __uapi_arch_align; it's a global variable? I'm not aware of this trick. What is this doing? > +#define COMPAT_VDUSE_VQ_GET_INFO _IOWR(VDUSE_BASE, 0x15, struct compat_vduse_vq_info) > + > +static long vduse_dev_compat_ioctl(struct file *file, unsigned int cmd, > + unsigned long arg) > +{ > + struct vduse_dev *dev = file->private_data; > + void __user *argp = (void __user *)arg; > + int ret; > + > + if (!IS_ENABLED(CONFIG_X86_64)) > + return vduse_dev_ioctl(file, cmd, > + (unsigned long)compat_ptr(arg)); > + > + if (unlikely(dev->broken)) > + return -EPERM; > + > + switch (cmd) { > + case COMPAT_VDUSE_IOTLB_GET_FD: { > + struct vduse_iotlb_entry_v2 entry = {0}; > + struct file *f = NULL; > + > + ret = -EFAULT; > + if (copy_from_user(&entry, argp, _IOC_SIZE(cmd))) > + break; > + > + ret = vduse_dev_iotlb_entry(dev, &entry, &f, NULL); > + if (ret) > + break; > + > + ret = -EINVAL; > + if (!f) > + break; > + > + ret = copy_to_user(argp, &entry, _IOC_SIZE(cmd)); > + if (ret) { > + ret = -EFAULT; > + fput(f); > + break; > + } > + ret = receive_fd(f, NULL, perm_to_file_flags(entry.perm)); > + fput(f); > + break; > + } > + case COMPAT_VDUSE_VQ_GET_INFO: { > + struct vduse_vq_info vq_info = {}; > + struct vduse_virtqueue *vq; > + u32 index; > + > + ret = -EFAULT; > + if (copy_from_user(&vq_info, argp, > + sizeof(struct compat_vduse_vq_info))) > + break; > + > + ret = -EINVAL; > + if (vq_info.index >= dev->vq_num) > + break; > + > + index = array_index_nospec(vq_info.index, dev->vq_num); > + vq = dev->vqs[index]; > + vq_info.desc_addr = vq->desc_addr; > + vq_info.driver_addr = vq->driver_addr; > + vq_info.device_addr = vq->device_addr; > + vq_info.num = vq->num; > + > + if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) { > + vq_info.packed.last_avail_counter = > + vq->state.packed.last_avail_counter; > + vq_info.packed.last_avail_idx = > + vq->state.packed.last_avail_idx; > + vq_info.packed.last_used_counter = > + vq->state.packed.last_used_counter; > + vq_info.packed.last_used_idx = > + vq->state.packed.last_used_idx; > + } else > + vq_info.split.avail_index = > + vq->state.split.avail_index; > + > + vq_info.ready = vq->ready; > + > + ret = -EFAULT; > + if (copy_to_user(argp, &vq_info, > + sizeof(struct compat_vduse_vq_info))) > + break; > + > + ret = 0; > + break; > + } > + default: > + ret = -ENOIOCTLCMD; > + break; > + } > + > + return vduse_dev_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); > +} > + > static int vduse_dev_release(struct inode *inode, struct file *file) > { > struct vduse_dev *dev = file->private_data; > @@ -1678,7 +1799,7 @@ static const struct file_operations vduse_dev_fops = { > .write_iter = vduse_dev_write_iter, > .poll = vduse_dev_poll, > .unlocked_ioctl = vduse_dev_ioctl, > - .compat_ioctl = compat_ptr_ioctl, > + .compat_ioctl = PTR_IF(IS_ENABLED(CONFIG_COMPAT), vduse_dev_compat_ioctl), Too funky IMHO. Everyone uses ifdef around this, let's do the same. > .llseek = noop_llseek, > }; > > -- > 2.39.5