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 61D7A37E310 for ; Mon, 2 Feb 2026 16:45:21 +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=1770050722; cv=none; b=ttjTBKoyOSMlU6fx64FkTh6S+HF70VsLXEi5m/MYqAnrRnrSg/5CMzIzD3J+DeBKOtMPyoKjrGZ9mMKCID0EuDMBt8fW6BBQF272RVOxADWTAymTSJX1LJjZXYurecPJXSlx2ljuPb5B3Lqks7KK2eN+VP9KBh+xs+0+95lI3eg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770050722; c=relaxed/simple; bh=lkML6C8/WI/y0YcNHGPg1vTCJcq1BxkxXOZpicvA2+E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PN69UzjJTA8ixo6AZC/WVOHdvnyn65wos03HxEF6nnz1+0GAuqulw64Haqx7VAmDTnh9VEHjcQsECAsoOt3UQ7BAQUpyxoi2nhBA3PL6PYkulWIHA5Tl8GEZ639GQKp7hNy+isAECWJJomlx1JO9QbdKhl8+GUJVPSe2QvuLEBg= 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=QrpEmD6x; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=S3CyBHoH; 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="QrpEmD6x"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="S3CyBHoH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770050720; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1MaLyDAEXIM+1K7joqwk/7F2Jjy8XHWKQlNGyxT7zGc=; b=QrpEmD6xnBiViuo+mPtx3ktk9RyUVxWZE2721efjU0AyuPbZpF/izPj1MZC+dM3XyADzb2 WbF9yTMYOyfGGx20QmdNtdUZt25nGHeUqK4iozKUqMGAqOvPGuZ0yJ4kl5NZpqaVFNCD0K w4FrBdh7zwmKIs8QIwpP/yxQ7+ltsAo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-dGJ8xWvJO2y5kr-FOTpEZQ-1; Mon, 02 Feb 2026 11:45:19 -0500 X-MC-Unique: dGJ8xWvJO2y5kr-FOTpEZQ-1 X-Mimecast-MFC-AGG-ID: dGJ8xWvJO2y5kr-FOTpEZQ_1770050718 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4806cfffca6so55651725e9.2 for ; Mon, 02 Feb 2026 08:45:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770050718; x=1770655518; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=1MaLyDAEXIM+1K7joqwk/7F2Jjy8XHWKQlNGyxT7zGc=; b=S3CyBHoHzHL7uUIEr5Whiy0Apg9ijzAKE6dLPqBezlHbBdt0/2edXu1AQQ5dYXuJJO d6uxs3S5tPg4neVmxCd7i3Sd80mfyFWQ8RfREE5djp41YvZQMLk/jEWcgwjuxZs5VCV/ FNNUCa62BHViIv0hb0lHhBtzBj1zPKQBMbEzmimlgr5INgQE48U1f04mWMhHCwhVMXmY 3QyE+EpAAuW88B13HFYeFeIFWyrVNnsDsXAc269u7lJpsCCdQUFdIiwvYreVfMu4fsn7 bdHu63ybo/dw9TLAe2TmWJrjhlUSMoxeJVcSOx+Ie1Y2pZRey0/AdYO+seSKjoOoEOhJ et7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770050718; x=1770655518; h=in-reply-to:content-transfer-encoding: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=1MaLyDAEXIM+1K7joqwk/7F2Jjy8XHWKQlNGyxT7zGc=; b=oq7ocgqtMZkKUASKp0nfm2y5QcmhQcXomhhDoMzxexObLG+h2tRfIUDvIo/7vVsXfV ikb4+qjxvWoCsD6wF+i9EQSCoURmFW7oQKxS9VtJ0/t7bRbCNJJB348UrRo9i72KSBxq UBm/3N0DTVNWqQCaboVES8hiqYq7E/Jt+QJ7Wfy4oIpqZYQCi0QrDs7Kdh7ShWTY0edR fdwEfGLSPY1ngiYtQw0nEsa9hg1cgzOGyD2TZeVkxNRGJVA6eEY7jxBU73AWU9wCZDlU CudIp/dKomDKfcjsMgR8g/zywP4mHOIZFqTx8b5kgGMTeZBi0qv3P5DCP+pq/ZatMdCF Cp5A== X-Forwarded-Encrypted: i=1; AJvYcCV3UyvkUpqImdxJEruZjT8odyhd2cy1Bv8ETUMSjKVWSAyrTMko901xMo5skwDTfVyFEXp+Vy4wcqkopW0=@vger.kernel.org X-Gm-Message-State: AOJu0YzsGXsgUN0epBeDQCpGC96h1FzpE87kPoE5cSBY7ls7qbGThhqX 0qMSADaJ7c61IxQIaVtvL6SP+UgGgpkJ1DgHL3kS8QeHevpv9PcsD8A9UOc7vn/K52HvO4BUKWe eW2DDtsVZ6vkXt5NAdTE1v/TBoFE/pIglIw4L3cO97JlHaJ8mt0nHOulqtlFZRS38hw== X-Gm-Gg: AZuq6aJerkZK8g0mVpWutpcIfgpHEQHxP8k9Dg8WVxnDCiJnGpibvf5ya+oS5Hon8ZB jPKjWT3/Bq5sotPOqKuMIMSCPlX+AjyN/rdbF4FSkpH6h/2f+dbRMZ93wjNzdNoeEFFoWYCdkgS xs1TnH4HNcXX1SOjN5UVkcc8FChTn4Z9S/Fp/FKL5fNoQ38TZ4kkRYaVYj/CPXz6B/Z2iBay8uk JwvGZ5gkz21BRorYrs8u9v2u2Cfsk6brzrjItQ1wnjlhen+7fJGDjH2pFYFmMd9/JYpyzQvdW9E 30z7wAftmnZ2NjmRxWPijt7M0vaHn7Cmzt8lZw8cruYQcLpTuupwvk7F7wqJ9VhRMfVSm+b/wBZ UOR29Iw== X-Received: by 2002:a05:600d:8449:b0:482:ef72:5778 with SMTP id 5b1f17b1804b1-482ef7258admr74875135e9.8.1770050717800; Mon, 02 Feb 2026 08:45:17 -0800 (PST) X-Received: by 2002:a05:600d:8449:b0:482:ef72:5778 with SMTP id 5b1f17b1804b1-482ef7258admr74874785e9.8.1770050717367; Mon, 02 Feb 2026 08:45:17 -0800 (PST) Received: from redhat.com ([2a06:c701:73e3:8f00:866c:5eeb:fc46:7674]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483051247ebsm1055045e9.4.2026.02.02.08.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 08:45:16 -0800 (PST) Date: Mon, 2 Feb 2026 11:45:13 -0500 From: "Michael S. Tsirkin" To: Arnd Bergmann Cc: Eugenio =?iso-8859-1?Q?P=E9rez?= , Arnd Bergmann , Jason Wang , Xie Yongji , Xuan Zhuo , Anders Roxell , Marco Crivellari , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] vduse: fix compat handling for VDUSE_IOTLB_GET_FD/VDUSE_VQ_GET_INFO Message-ID: <20260202114412-mutt-send-email-mst@kernel.org> References: <20260202095940.1358613-1-arnd@kernel.org> <20260202095940.1358613-2-arnd@kernel.org> <30db98bd-8361-46f5-aec1-ffbc4e8574dd@app.fastmail.com> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <30db98bd-8361-46f5-aec1-ffbc4e8574dd@app.fastmail.com> On Mon, Feb 02, 2026 at 12:59:03PM +0100, Arnd Bergmann wrote: > On Mon, Feb 2, 2026, at 12:34, Eugenio Perez Martin wrote: > > On Mon, Feb 2, 2026 at 11:07 AM 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 compad handling to the regular ioctl handler to just handle > >> them the same way and ignore the extra padding. This could be > >> done in a separate .compat_ioctl handler, but the main one already > >> handles two versions of VDUSE_IOTLB_GET_FD, so adding a third one > >> fits in rather well. > >> > > > > I'm just learning about the COMPAT_ stuff but does this mean the > > userland app need to call a different ioctl depending if it is > > compiled for 32 bits or 64 bits? I guess it is not the case, but how > > is that handled? > > In a definition like > > #define VDUSE_IOTLB_GET_FD _IOWR(VDUSE_BASE, 0x10, struct vduse_iotlb_entry) > > The resulting integer value encodes sizeof(struct vduse_iotlb_entry) > in some of the bits. Since x86-32 and x86-64 have different > sizes for this particular structure, the command codes are > different for the same macro. The recommendation from > Documentation/driver-api/ioctl.rst is to use structures with > a consistent layout across all architectures to avoid that. > > The normal way to handle this once it has gone wrong is to split > out the actual handler into a function that takes the kernel > structure, and a .compat_ioctl() handler that copies the > 32-bit structure to the stack in the correct format. > > Since the v1 structures here are /almost/ compatible aside from > the padding at the end, my patch here takes a shortcut and does > not add a custom .compat_ioctl handler but instead changes > the native version on x86-64 to deal with both layouts. > This does mean that the kernel driver now also accepts the > 64-bit layout coming from compat tasks, and the compat layout > coming from 64-bit tasks. > > Nothing in userspace changes, as it still just uses the existing > VDUSE_IOTLB_GET_FD macro, and the kernel continues to handle > the native layout as before. > > Arnd I think .compat_ioctl would be cleaner frankly. Just look at all the ifdefery. And who knows what broken-ness userspace comes up with with this approach. Better use the standard approach.