From nobody Sat Sep 26 20:00:27 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1790091881; cv=none; d=zohomail.com; s=zohoarc; b=YRsw/nOOnCYNKsfK6jDmXMN8fuP2Etvvq2rBlOl+w2BsalGkYHfpP08OYCdgoWkswALoMSmqDR1eLdfGHD49ORiZLTgtKXAV2rw/r6VIdCQSoI+Tg/B7TA2aXkTBHVpWGE4Qc87whkKqQRZ2MRHzvnYvRgt8ezDxc2J6VYWqQ1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790091881; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=a2cNSFKqB3BJbf/3RetPRBDFoS8WgoEIb8qKuxxH0iE=; b=PnvFXo0RXOy53KTz4d8YpUAAkWeepL/R//GMMTF84WgqwLiJodUwhAaLYkLd0itasi54CGowY9Qd+apy7qaJapMZDkOjX6U0HWKu46aZDvHcKsvqv7fo211yon1lQ5FPGGQX4JOfO7z72T0+Lgy9Gin8qktZIHOLdbyQ5XtuXnE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790091881710554.1446381993625; Tue, 22 Sep 2026 08:44:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x92f3-0008W9-FA; Tue, 22 Sep 2026 11:44:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x92f1-0008VT-Mz for qemu-devel@nongnu.org; Tue, 22 Sep 2026 11:43:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x92ez-0004GU-J9 for qemu-devel@nongnu.org; Tue, 22 Sep 2026 11:43:59 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-EbJVJrqyPwWdhaiU4l9PcQ-1; Tue, 22 Sep 2026 11:43:54 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1FEA3185BEBE; Tue, 22 Sep 2026 15:43:53 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 93AD5426; Tue, 22 Sep 2026 15:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790091835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=a2cNSFKqB3BJbf/3RetPRBDFoS8WgoEIb8qKuxxH0iE=; b=JkY3ONQ4Us0HLTM62YP/yxLOpCd/LTQq7mc2qSlL5Kt77gPkwQsupFSHgA69tp8gvmGF9X 6LYvNeDzVc+Zf69JNSwiDYIq88K+nf1Y0AAXnLRlarfoZACO9gsSpwtSj2lxF+N+pbK+qh LjGf6wENhakwN3STKH6zRl/OYuHOg/k= X-MC-Unique: EbJVJrqyPwWdhaiU4l9PcQ-1 X-Mimecast-MFC-AGG-ID: EbJVJrqyPwWdhaiU4l9PcQ_1790091833 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, nsoffer@redhat.com, Stefan Hajnoczi , Eric Biggers Subject: [PATCH] file-posix: add statx(STATX_DIOALIGN) support Date: Tue, 22 Sep 2026 11:43:51 -0400 Message-ID: <20260922154351.226540-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1790091884354158500 Content-Type: text/plain; charset="utf-8" Linux v6.1 commit 825cf206ed51 ("statx: add direct I/O alignment information") added an interface to fetch O_DIRECT alignment values for block devices and file systems. Prefer STATX_DIOALIGN to older interfaces and probing, but keep them as fallbacks in case STATX_DIOALIGN cannot provide the information. STATX_DIOALIGN support as of Linux 6.1: - btrfs: no - ext4: yes - XFS: yes - block devices: yes - dm-crypt: yes This change fixes #1290 ("IO alignment probing delivers incorrect results on Linux when used with e.g. dm-crypt") on Linux host kernel version 6.1 or later by avoiding the problematic probing code in raw_probe_alignment(). It would be nice to fix the probing code but I have not been able to reproduce it. Stable/LTS distros ship Linux 6.1+, so the number of users without STATX_DIOALIGN is becoming small. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1290 Cc: Eric Biggers Signed-off-by: Stefan Hajnoczi Reviewed-by: Ben Chaney --- v3: - Rebase and update commit description v2: - Make sure that XFS_IOC_DIOINFO takes priority over logical blocksize [Eri= c Biggers] --- block/file-posix.c | 56 +++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9aad156aad4..0dedd090068 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -426,28 +426,48 @@ static void raw_probe_alignment(BlockDriverState *bs,= int fd, Error **errp) =20 bs->bl.request_alignment =3D 0; s->buf_align =3D 0; - /* Let's try to use the logical blocksize for the alignment. */ - if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) { - bs->bl.request_alignment =3D 0; + +#if defined(__linux__) && defined(STATX_DIOALIGN) + struct statx stx; + + /* + * Linux 6.1 introduced an interface for both block devices and file + * systems. The system call returns with the STATX_DIOALIGN bit cleared + * when the information is unavailable. + */ + if (statx(fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &stx) =3D=3D 0 && + (stx.stx_mask & STATX_DIOALIGN)) { + bs->bl.request_alignment =3D stx.stx_dio_offset_align; + s->buf_align =3D stx.stx_dio_mem_align; } +#endif /* defined(__linux__) && defined(STATX_DIOALIGN) */ =20 #ifdef __linux__ - /* - * The XFS ioctl definitions are shipped in extra packages that might - * not always be available. Since we just need the XFS_IOC_DIOINFO ioc= tl - * here, we simply use our own definition instead: - */ - struct xfs_dioattr { - uint32_t d_mem; - uint32_t d_miniosz; - uint32_t d_maxiosz; - } da; - if (ioctl(fd, _IOR('X', 30, struct xfs_dioattr), &da) >=3D 0) { - bs->bl.request_alignment =3D da.d_miniosz; - /* The kernel returns wrong information for d_mem */ - /* s->buf_align =3D da.d_mem; */ + if (!bs->bl.request_alignment) { + /* + * The XFS ioctl definitions are shipped in extra packages that mi= ght + * not always be available. Since we just need the XFS_IOC_DIOINFO= ioctl + * here, we simply use our own definition instead: + */ + struct xfs_dioattr { + uint32_t d_mem; + uint32_t d_miniosz; + uint32_t d_maxiosz; + } da; + if (ioctl(fd, _IOR('X', 30, struct xfs_dioattr), &da) >=3D 0) { + bs->bl.request_alignment =3D da.d_miniosz; + /* The kernel returns wrong information for d_mem */ + /* s->buf_align =3D da.d_mem; */ + } + } +#endif /* __linux__ */ + + /* Let's try to use the logical blocksize for the alignment. */ + if (!bs->bl.request_alignment) { + if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) { + bs->bl.request_alignment =3D 0; + } } -#endif =20 /* * If we could not get the sizes so far, we can only guess them. First= try --=20 2.55.0