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.133.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 20BD5285C91 for ; Tue, 3 Feb 2026 10:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770115674; cv=none; b=XP8x6bNL+inpOk+51mDxa0xlILPDQvHKzz0QnDRXD5fLWGN7u8JH6kRSCFMSdtNavzg0kblPmP+RKVzWQYw8cKwSHLHxde9P7HKbHPK/YTdbLmII9y+HLIp2bKY6N1v5BNNceXLL/G68d1KzsNImZDyT6D4EvrG6BVCH2gYT49Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770115674; c=relaxed/simple; bh=mRoOw6VYyiiTS1YBHJ5D9LVd2pT+NRtpTb+npro7BDg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rdjbtI/bpq2qH6R0lnjXyCvbBrbws9ExJJwx0JFwoO3207hqGm/mirGCwxUHF/fIBJbg/s/pivdcn7TdTxIkPF0fOP5DFSxkO9CJKrcYP3wq6Tp9Vg3BJKJF0+s8vydD7mqaDDPhKW+AdcTzz9nQKuj1qskRPJ1NsKwSlfXIxDM= 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=DwPKkxUD; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=fxlnZEi9; arc=none smtp.client-ip=170.10.133.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="DwPKkxUD"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="fxlnZEi9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770115671; 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=Ie6mxjNs4nfKhcvDWOucpJYRrzrcGs6LSUHOCzj9ABU=; b=DwPKkxUDzQ7FpRZixT80HnGIBpt+pnhQVv5AYB+oHjeIuRGE3hSHgCNOsyfR1HJ67ecc5+ AhD+OTVzTn9jsZks7sbkYbZ+zuFuebaKaO6mk27S5tCLGezojK5Xlz/blXAbKyuWuX4QAB jokmjw+eWByKyDTv9xSbVyhtAkNmjUc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-SgMgn6HRM7OcdTC04P_llA-1; Tue, 03 Feb 2026 05:47:50 -0500 X-MC-Unique: SgMgn6HRM7OcdTC04P_llA-1 X-Mimecast-MFC-AGG-ID: SgMgn6HRM7OcdTC04P_llA_1770115669 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4804157a3c9so63746945e9.1 for ; Tue, 03 Feb 2026 02:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770115669; x=1770720469; 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=Ie6mxjNs4nfKhcvDWOucpJYRrzrcGs6LSUHOCzj9ABU=; b=fxlnZEi9xv4PLbIck6JaavjM1O1G9mal2qlaC+DCGcd/2IRIjIIUBBpxOF1v9/3hWR COmKhLUP7Q5vracdHHnyLLCfnqMivaHNZZR8xosJLGTM5vhU2liVCQ9wCnXm2Pnq/D8u xR8KKiclJHJcXyL8BFWfXax+fkt9q/mHf9AP64T6SYrg/rqjQNj5622v7fxUw7ezc35h 0F/qKMuTsAdV+f91YVt5mQ9yxiGea9i3c4zMRxRhdGewKy5W6H4AxNC98x1fp8a9y+qf ropZGUm4Gk2jbkToyRLJC0bssb315bybqssLoZZh7g5dalFjgc5U8wtXqiG06MPAW7nZ +OYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770115669; x=1770720469; 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=Ie6mxjNs4nfKhcvDWOucpJYRrzrcGs6LSUHOCzj9ABU=; b=wxUaj1uUB+DptlNIpT4w5CDpC/ot2JcSo9M+jSPjN3SQdF729xZXsDJgO3f0Lp3/+T W+rScZG7NaK+dt6ip/a2ayImlfTi5JtkBU5s57NVvRPg2jUO6g1y+3vew44RimpO8Lc+ JT2CSFzzxD57kdYRfX/OhskpuABSg1C96qoLF2kh71pjCmoaBf1/zuQD3w/LhINoXIID xotn4e9Mtl/QO6ysrdqpv4pjaxaaaKF+61g7tDMem7dxSwSMUfu5N0A2O4yUYmeRJoHS TZr7TaC8tpvB+CjqYyNjUwo+++EQLW8DHYLZXhBlJPnqhZJ2eNFEtcdYuxKu12dnk88Q SYhw== X-Forwarded-Encrypted: i=1; AJvYcCUKhgRCpBdL3ASrCheE7j+k31pV+1SciYXxzv2r4/KaW/mgyu0x5psB6cX6NkjjP9lslkrL5WbrcddIAPI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzk7209F3TWcsTHBcxKQTyO5pkmxXsn6Zcln3/miA54dN1oTFwb XPyiS7i15MVLe7fIAs4FiVgWXROmhXje0/KJT9vkru9EOCmk4KYaRa7msn11N/CBkDBpzOlj3yv CCLLpsl8WEWw2d9Vk9xm6kmcV7kS0RtKdJ7J8pFKUlx/OxwkNchaJtVTl6+S3zsZln+nJgVjAFA == X-Gm-Gg: AZuq6aIJQrF39hI72BDAHCctt5cCYHPGEoAPVlj0LSnkXbyMTvV8FVXC1MG+cjNY+sr AglSKXSX8pwBmVrN5p2fv9fQQ57xCzmLBgbyqVTYeEvItAnboJkMfpKyQUBFJt043mgUJwpUiIG Adhu6PULFeW3PRoGrNjuDS6QAIEMiqyPZ+iMksaUg25KAnY2GK1Ol7QS9i52RdiDdb+RNOM9W4r ajIM3sISMk6zpY/7cXDUDuj42FwsE0FR+Qam16tIOLYlTsrwp2bWxBwepKaIosIPSc/+xZyznZH dRn/KgCXeFCIT211my5lKY27cOS5WB9nlvYFWY44CL0FPgsYyIZzN7kILWvo/UWWaIRCFAwGs5y q4EIxMjlCdKXk2NZFGHa/jWF0h8dm3sPvJg== X-Received: by 2002:a05:600c:138d:b0:47e:e5c5:f3a3 with SMTP id 5b1f17b1804b1-482db493a03mr225030715e9.24.1770115669122; Tue, 03 Feb 2026 02:47:49 -0800 (PST) X-Received: by 2002:a05:600c:138d:b0:47e:e5c5:f3a3 with SMTP id 5b1f17b1804b1-482db493a03mr225030365e9.24.1770115668670; Tue, 03 Feb 2026 02:47:48 -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 5b1f17b1804b1-4830512e0edsm59162025e9.7.2026.02.03.02.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 02:47:47 -0800 (PST) Date: Tue, 3 Feb 2026 05:47:44 -0500 From: "Michael S. Tsirkin" To: Arnd Bergmann Cc: Arnd Bergmann , Jason Wang , Xie Yongji , 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: <20260203054152-mutt-send-email-mst@kernel.org> References: <20260202224835.559538-1-arnd@kernel.org> <20260202224835.559538-2-arnd@kernel.org> <20260203050216-mutt-send-email-mst@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: On Tue, Feb 03, 2026 at 11:39:43AM +0100, Arnd Bergmann wrote: > On Tue, Feb 3, 2026, at 11:22, Michael S. Tsirkin wrote: > > 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) > > Sure > > > 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. > > No, the weird alignment rules are only on arc, csky, m68k, > microblaze, nios2, openrisc, sh and x86-32. Out of those, > x86 is hte only one that currently has a 64-bit version > (arc and micrblaze 64-bit support never made it upstream, > sh64 was removed since there were no products). > > All the other architectures with compat support (arm, > powerpc, mips, sparc, riscv) have the same alignment rules > for 32-bit and 64-bit builds and align all integers naturally. Oh interesting. But the code is compiled for and generates useless code for all CONFIG_COMPAT right now. The ifdef you need is COMPAT_FOR_U64_ALIGNMENT then, I think. > >> + * 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. > > Right, I could remove the padding field here, since this is > just used to document the size of the otherwise implied > padding. > > The patch I used to find the issue originally adds explicit > padding to all uapi structures with implied padding, so I > did the smae thing here. > > >> +#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? > > My mistake, that should not have been here. > > >> @@ -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. > > Sure. I only used this because you asked for fewer #ifdefs in > my v1 patch. It's less the amount of ifdefs more them being placed strategically. sorry about being unclear. > If I use an #ifdef around this one, I also have > to add one around the function definition. and the structs, preferably. > In that case, I'd > probably change it back to the x86 check there, and use > > #if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT) > .compat_ioctl = vduse_dev_compat_ioctl, > #else > .compat_ioctl = compat_ptr_ioctl. > #endif > > Arnd