From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420596; cv=none; d=zohomail.com; s=zohoarc; b=c1bxK6wIBkGsbJ3He2DjdD9Sl5s4YTMiEyMBuSBbOTns3FMTWs8bppNSLUUORgEXgZO4QlQSLtf8BwUCzT698z5rxCFcjS0aLaVvuHmZJefJsWFTubjHeaPECEsLTni7f6+dLo5uJq+RdknYpJb8m4XB/ADgZeEeu/vGT15aW3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420596; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bgyHkocTAQn8Zy/D/YQYiC18eCMiUqs9zorblhNGkY0=; b=Q7glP0z07LU8K1HtextqEqu3oMkYjEfwKFRe2z+XAmcta4K65i6+kT4hxoDwURQXetJfe3mhIXzknQtTLxjBuxQ5ejg5dfPVZrOS/P3pN+kwdQdV7DhB7mcPzqxLKN7wfJW1RXTI6Cmh3uXlGn27VFVD76eWfMLwTkQD3BQ4qEc= 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 1792420596019778.5601478040006; Mon, 19 Oct 2026 07:36:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoT9-0007Co-Gh; Mon, 19 Oct 2026 10:36:07 -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 <69d00f0bb898e3e635d376e6a7e063e0aff072e0@kylie.crudebyte.com>) id 1xIoT7-0007CU-SB for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:05 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <69d00f0bb898e3e635d376e6a7e063e0aff072e0@kylie.crudebyte.com>) id 1xIoT6-0007UC-3n for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=bgyHkocTAQn8Zy/D/YQYiC18eCMiUqs9zorblhNGkY0=; b=co9Lu XOEW/FDJMZxfEQZFvRWaT7eq3D9uUNZmnuYkDHaTrpbzpqIfy7v0+gOCAk9dZKZONnBZiSjLPsjro ur6xFPOVilMbTEhIZJiur1RA+7ySxxATJpvjISRLYAl2g1UZllX2OAvwfz0r/GkTWug7fsHxzBRi+ yLjFRem3RatjOOEamtAVOZ4Dgp01FjdWqRtDz0cMOxI1KItBkgy+P/Eyzc+qDvAjHVx6gitZBGMn8 aKTGcRNb3Gg/JwasmFRz79s223RcuBFXOpdwB4aO+nVFyCwZ7eau1N/f3l4SmYZ7HmWGZXnSdsJN6 XIrZhklHJPsvL/bnqH8IcmbSFV2ONJfh2pzdeED52wbXsSRFM+ukLtvXvVCAn5+xhuffW9t6P2fyx w8yTNui0rL2euzwHwfQ5v3W0/cayTD5/DQtUZVBCrbzlisqK+0Crajm2Vpa1eyFCnED1CBjquuGxp qPKN1MRDOM/0mrNRFEhf2xvFxjTBE+UIg5YrWKEEEslHA0vuTclBwCBB7mJnFfA0M8R3G+6jWnuec tR4O+JRe4qI6z98Xd//WV98D47g6QhTO+cst4+6mkswqhFD7MEubZKk/m/DkhjuR/V7AY1uKLPbYX nmG7EymqJn6xww+OmZABuoiPrKAm+HhucQd43hVD2M8FUbeCB3FQdaBCAzDqs0=; Message-ID: <69d00f0bb898e3e635d376e6a7e063e0aff072e0.1792420035.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 1/9] tests/9p-client: add Txattrwalk / Rxattrwalk test client functions To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=69d00f0bb898e3e635d376e6a7e063e0aff072e0@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420599635158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add v9fs_txattrwalk() and v9fs_rxattrwalk() functions to the 9p test client. This can be used to retrieve a list of xattrs or to acquire a FID that can subsequently be used to retrieve the value of an xattr. This is a preparatory patch, these functions will be used by the subsequently added 9p race test. Link: https://lore.kernel.org/qemu-devel/fcd4dd1ed8cf6ae9af99ba5ade8b592287= 5e442d.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p-client.c | 48 +++++++++++++++++++++++++++ tests/qtest/libqos/virtio-9p-client.h | 28 ++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/vir= tio-9p-client.c index 305b0dac63..b2f0037b7b 100644 --- a/tests/qtest/libqos/virtio-9p-client.c +++ b/tests/qtest/libqos/virtio-9p-client.c @@ -1227,3 +1227,51 @@ void v9fs_rxattrcreate(P9Req *req) v9fs_req_recv(req, P9_RXATTRCREATE); v9fs_req_free(req); } + +/* size[4] Txattrwalk tag[2] fid[4] newfid[4] name[s] */ +TXattrWalkRes v9fs_txattrwalk(TXattrWalkOpt opt) +{ + P9Req *req; + uint32_t err; + uint32_t body_size =3D 4 + 4; + uint16_t string_size; + uint64_t xattr_size =3D 0; + + g_assert(opt.client); + g_assert(opt.name); + + string_size =3D v9fs_string_size(opt.name); + g_assert_cmpint(body_size, <=3D, UINT32_MAX - string_size); + body_size +=3D string_size; + + req =3D v9fs_req_init(opt.client, body_size, P9_TXATTRWALK, opt.tag); + v9fs_uint32_write(req, opt.fid); + v9fs_uint32_write(req, opt.newfid); + v9fs_string_write(req, opt.name); + v9fs_req_send(req); + + if (!opt.requestOnly) { + v9fs_req_wait_for_reply(req, NULL); + if (opt.expectErr) { + v9fs_rlerror(req, &err); + g_assert_cmpint(err, =3D=3D, opt.expectErr); + } else { + v9fs_rxattrwalk(req, &xattr_size); + } + req =3D NULL; /* request was freed */ + } + + return (TXattrWalkRes) { .req =3D req, xattr_size }; +} + +/* size[4] Rxattrwalk tag[2] size[8] */ +void v9fs_rxattrwalk(P9Req *req, uint64_t *size) +{ + v9fs_req_recv(req, P9_RXATTRWALK); + if (size) { + v9fs_uint64_read(req, size); + } else { + v9fs_memskip(req, 8); + } + v9fs_req_free(req); +} diff --git a/tests/qtest/libqos/virtio-9p-client.h b/tests/qtest/libqos/vir= tio-9p-client.h index 4b04324503..c910407f70 100644 --- a/tests/qtest/libqos/virtio-9p-client.h +++ b/tests/qtest/libqos/virtio-9p-client.h @@ -553,6 +553,32 @@ typedef struct TXattrCreateRes { uint32_t err; } TXattrCreateRes; =20 +/* options for 'Txattrwalk' 9p request */ +typedef struct TXattrWalkOpt { + /* 9P client being used (mandatory) */ + QVirtio9P *client; + /* user supplied tag number being returned with response (optional) */ + uint16_t tag; + /* file ID of file/dir from which to walk (required) */ + uint32_t fid; + /* file ID that will refer to the walked-to xattr (required) */ + uint32_t newfid; + /* xattr name, or empty for a list of all xattrs (required) */ + const char *name; + /* only send Txattrwalk request but not wait for a reply? (optional) */ + bool requestOnly; + /* do we expect an Rlerror response, if yes which error code? (optiona= l) */ + uint32_t expectErr; +} TXattrWalkOpt; + +/* result of 'Txattrwalk' 9p request */ +typedef struct TXattrWalkRes { + /* if requestOnly was set: request object for further processing */ + P9Req *req; + /* size of xattr */ + uint64_t size; +} TXattrWalkRes; + void v9fs_set_allocator(QGuestAllocator *t_alloc); void v9fs_memwrite(P9Req *req, const void *addr, size_t len); void v9fs_memskip(P9Req *req, size_t len); @@ -610,5 +636,7 @@ TClunkRes v9fs_tclunk(TClunkOpt opt); void v9fs_rclunk(P9Req *req); TXattrCreateRes v9fs_txattrcreate(TXattrCreateOpt opt); void v9fs_rxattrcreate(P9Req *req); +TXattrWalkRes v9fs_txattrwalk(TXattrWalkOpt opt); +void v9fs_rxattrwalk(P9Req *req, uint64_t *size); =20 #endif --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420596; cv=none; d=zohomail.com; s=zohoarc; b=kAmHrHzlo9tkT2HY5G4nPWl4QnblR4JBV4kg7McrfGGE/uhf/toy9GzQhpxkLiFfc6mrsyOTn3iKYhMWsPrwBJ3+AL5wkI+IzBe4wzswtuyVT+CqqBpYBXk4wvE5+V34ZrIxsKKPyZRJKOLZl1HswV/k6z+lFEO9jnst6m8Bl1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420596; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=B9l+RH/nn5Ye83aCosVc8BFTlO8H5l9zkqzh1p3cyfQ=; b=etlWkzDBo2GPJx4GIZKbekL8LxKadQL6zB5q9hNPGkG5YPyFyZuS23KSxWtPeSD/z5UpuPo6M/tjerUi9wOKZSc6xDaTI8O5F380vLHzEesZQ6Bot1k/j+KVjW0v0TBKy3Xjdbtzw+LiIorPIZQx7/dwkVMkOsJwECKH79pSq3Q= 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 1792420596357675.7436322137725; Mon, 19 Oct 2026 07:36:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoTI-0007F1-TA; Mon, 19 Oct 2026 10:36:16 -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 <2296ed61d2a38b5198d2fd9fe88056be4cd4adba@kylie.crudebyte.com>) id 1xIoTH-0007Eg-BV for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:15 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2296ed61d2a38b5198d2fd9fe88056be4cd4adba@kylie.crudebyte.com>) id 1xIoTD-0007VL-Mo for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=B9l+RH/nn5Ye83aCosVc8BFTlO8H5l9zkqzh1p3cyfQ=; b=LdbS1 f9zOEZuMzJU7jZ33AAdmVMhsOSKE5gq/IdQNeiaI9JBr7o+cNFrKaO5Qou1AujOZZxaWwXVT1nvlO 0hSpUqzx6v2uaLHSS6vC4GI/D9y1uEioKVT/L5L8cGuD93PsNkjDJycuM7hLwslwGRRroL28DJ98W ioa6xVxjsTPVqi4Zc+bIRd86MhgsBWeVvG4Mr8q224iNadhwB/bHcmApCgnaE52EQd5oaaWRKrBM7 0+adorl0kvrhQgm4380iNJTYGBYi8bXOse7KAK+DWhEas8C9ds+gfKy4zXzWRKjEE4bUt+6V7FTse MNNdH/AASqrgzlbYpz7GefOHe5q3EftN6GafUGt7nss5gzja7OQ+QYNBmMEQ4ArKaYwrylXrBZof1 xUma65RBipnz54H1nrIGRdf0cOUVR5rhACvVYoLE3kWsm5Z88Z1AEf7ip68UD70gWWgudexDWf1WQ FaaKq1vSFp2Ukb1Zh0rcjO+sR47zTN9P9F6DOiHVqMfgjt+/ZnwNo9ohMRYCI16nMLT9lQ8aWF7wF Rvjf7wSiPrWjcgJPdZgofKPr1BFcXOBHeR9xncGyGTplCADzFqU3JukX6R+P1aPjfwDsrHHiFkk+x CQo7OvIEP4x83EdgOgUTm4Lf2pS+l2X/Sl09kTQBIwfi3cjU8HUU68CRxY7p/8=; Message-ID: <2296ed61d2a38b5198d2fd9fe88056be4cd4adba.1792420035.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 2/9] tests/9p-race: add 9p race test suite (race FID-path mutations) To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=2296ed61d2a38b5198d2fd9fe88056be4cd4adba@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420597865158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a qtest-based stress test suite racing 9pfs server-side state. This patch adds the first race test "race/fid-path" for this new test suite: it races (per round) one Tlcreate (which is mutating the FID path) against a number of reader requests (Twalk and Txattrwalk) on the same FID. This very first 9pfs race test guards CVE-2026-93834 (fixed by commit fe9e30899f "hw/9pfs: Use read-write lock for protecting fid path."). Hitting the small race window is timing dependant, so this is a probabilistic test, not a deterministic one. During my tests the (unpatched) vulnerability triggered sometimes after few hundred rounds, and sometimes after >100k rounds. Furthermore, it expects QEMU being compiled with a sanitizer (e.g. ASan) which is supposed to detect the actual race (e.g. by memory violation): ../configure --enable-virtfs --enable-debug \ --extra-cflags=3D"-fsanitize=3Daddress -fno-omit-frame-pointer" \ --extra-ldflags=3D"-fsanitize=3Daddress" ... Even though this is a new test suite, in the codebase separate from the already existing deterministic 9pfs test cases (while 9p test client code being shared between the two test suites), this new race test suite is run with the same binary as the other qtests. However being a very slow test, it is registered as such, so the -m slow argument is required for this race test to run (as it is skipped by default): ASAN_OPTIONS=3Ddetect_leaks=3D0 \ tests/qtest/qos-test -m slow Or if you only want to run this single race test (e.g. on x86_64): ASAN_OPTIONS=3Ddetect_leaks=3D0 \ tests/qtest/qos-test -m slow -p \ /x86_64/pc/i440FX-pcihost/pci-bus-pc/pci-bus/virtio-9p-pci/virtio-9p/virt= io-9p-tests/race/fid-path On other systems, use `tests/qtest/qos-test -l` to get the correct (arch dependent) full test name. `ASAN_OPTIONS=3Ddetect_leaks=3D0` is currently required, it suppresses a memory leak error at the end of each race test, which is a known QEMU shutdown memory leak, unrelated to 9p server or this race test suite. The official QEMU CI pipeline sets `ASAN_OPTIONS=3Ddetect_leaks=3D0` by default for this reason. There are some knobs that can be controlled via environment variables: V9FS_RACE: skip test suite by setting to 0 or force running by setting to 1 V9FS_RACE_ROUNDS: total amount of rounds to run (default: 20000) V9FS_RACE_NCONCURRENT: amount of concurrent reader requests (default: 4) A full run with 20000 rounds took around 7 minutes on my test machine. If you can't hit the (narrow) race window with unpatched QEMU, it might help to either add some load on the host system and/or turning the two knobs above. Link: https://lore.kernel.org/qemu-devel/4a0eff0539f16434b48728cd8e5a89f906= c293d8.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- MAINTAINERS | 1 + tests/qtest/meson.build | 1 + tests/qtest/virtio-9p-race-test.c | 575 ++++++++++++++++++++++++++++++ 3 files changed, 577 insertions(+) create mode 100644 tests/qtest/virtio-9p-race-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 33b4f7c259..d9209f043f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2582,6 +2582,7 @@ F: hw/9pfs/ X: hw/9pfs/xen-9p* F: fsdev/ F: tests/qtest/virtio-9p-test.c +F: tests/qtest/virtio-9p-race-test.c F: tests/qtest/libqos/virtio-9p* T: git https://github.com/cschoenebeck/qemu.git 9p.next =20 diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 019c63ca60..2d01837ff2 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -374,6 +374,7 @@ if host_os !=3D 'windows' endif if have_virtfs qos_test_ss.add(files('virtio-9p-test.c')) + qos_test_ss.add(files('virtio-9p-race-test.c')) endif if have_vhost_user qos_test_ss.add(files('vhost-user-test.c')) diff --git a/tests/qtest/virtio-9p-race-test.c b/tests/qtest/virtio-9p-race= -test.c new file mode 100644 index 0000000000..789fb7721d --- /dev/null +++ b/tests/qtest/virtio-9p-race-test.c @@ -0,0 +1,575 @@ +/* + * virtio 9p fs concurrency race test + * + * Copyright (c) 2026 Christian Schoenebeck + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Implements a probabilistic stress test suite (not deterministic reprodu= cers) + * by simulating concurrent requests on the same 9p FID. This test suite is + * expected to be built and run with sanitizers (e.g. ASan) that are suppo= sed + * to actually uncover potential races e.g. by detecting memory violations. + */ + +/* + * Not so fast! You might want to read the 9p developer docs first: + * https://wiki.qemu.org/Documentation/9p + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "libqos/virtio.h" +#include "libqos/virtio-9p-client.h" +#include "libqos/virtio-9p.h" + +/* + * RACE TEST SUITE INFRASTRUCTURE + * + * The following functions implement the shared code for all 9p race + * tests. + */ + +/* depth of the d1/d2/d3 directory chain created below the export root */ +#define V9P_RACE_DIR_DEPTH 3 + +/* export root FID */ +#define V9P_RACE_ROOT_FID 0 + +/* d1 FID of the d1/d2/d3 path chain */ +#define V9P_RACE_D1_FID 40 +/* d2 FID of the d1/d2/d3 path chain */ +#define V9P_RACE_D2_FID 41 +/* d3 FID of the d1/d2/d3 path chain */ +#define V9P_RACE_D3_FID 42 + +/* + * FID range of automatically generated and recycled FIDs per race round. + * Kept small and away from the constant FIDs above. + */ +#define V9P_RACE_FID_ROUND_BASE 100 +#define V9P_RACE_FID_ROUND_SLOTS 32 + +static uint16_t v9p_race_tag; + +/* returns a new tag for the next 9p request */ +static uint16_t v9p_race_new_tag(void) +{ + v9p_race_tag++; + /* tag 0 is the reserved no-tag (P9_NOTAG) value, not a real tag */ + if (v9p_race_tag =3D=3D 0) { + v9p_race_tag =3D 1; + } + return v9p_race_tag; +} + +/* + * How long the test suite waits for one pending request to arrive before + * concluding the 9p server is stuck; ASan builds may be slow, so keep it + * generous. + */ +#define V9P_RACE_TIMEOUT_US (30 * G_USEC_PER_SEC) + +/* + * Maximum amount of pending 9p server responses ever expected. + * + * This is directly tied to server's MAX_REQ (which currently yields to 12= 8). + */ +#define V9P_RACE_RCVD_REPL_MAX (MAX_REQ) + +/* + * A local stash of already received 9p responses. + * + * With several 9p requests in-flight, used ring entries can arrive in a + * different order than the requests were originally sent. A consumed virt= io + * ring entry belonging to a not-yet-collected response is queued here as a + * received-but-unprocessed reply record. The response payload itself stay= s in + * the request's guest buffer either way, so the descriptor index alone is + * enough to acquire it later on. + */ +static struct { + uint32_t desc_idx; + uint32_t len; + bool used; +} v9p_race_rcvd_resp[V9P_RACE_RCVD_REPL_MAX]; + +/* + * Reset virtio test driver's descriptor pool. + * + * The qtest virtio driver never recycles used descriptors, so the + * descriptor table (one queue-size worth of entries) must be reset + * whenever it is about to run out. Safe as long as no request is in + * flight (call between completed round-trips or at the start of a + * round where all previous requests have been collected). + */ +static void v9p_race_reset_pool(QVirtio9P *v9p) +{ + qvirtqueue_reset_pool(v9p->vq); +} + +/* + * Feed the QEMU main loop with one no-op qtest command round-trip. + * + * In qtest mode the 9p device state only advances while the QEMU main + * loop services a qtest command: servicing the command runs inside one + * main loop iteration, which also dispatches previously queued + * virtqueue kicks, steps the 9p handler coroutines on the main thread + * (their worker-side parts run on independent thread pool threads) and + * writes completed responses back into the virtio used ring. + */ +static void v9p_race_feed_main_loop(QVirtio9P *v9p) +{ + /* + * The read target is the virtqueue descriptor table, which only this + * test writes, so the command has no side effects. The read value is + * discarded. + */ + qtest_readl(global_qtest, v9p->vq->desc); +} + +/* stash the received reply identified by @desc_idx for later processing */ +static void v9p_race_rcvd_resp_add(uint32_t desc_idx, uint32_t len) +{ + int i; + + for (i =3D 0; i < V9P_RACE_RCVD_REPL_MAX; i++) { + if (!v9p_race_rcvd_resp[i].used) { + v9p_race_rcvd_resp[i].used =3D true; + v9p_race_rcvd_resp[i].desc_idx =3D desc_idx; + v9p_race_rcvd_resp[i].len =3D len; + return; + } + } + g_assert_not_reached(); +} + +/* + * Pickup the previously stashed reply for @desc_idx, returning its length, + * or UINT32_MAX if no reply for that request has been received yet. + */ +static uint32_t v9p_race_rcvd_resp_remove(uint32_t desc_idx) +{ + int i; + + for (i =3D 0; i < V9P_RACE_RCVD_REPL_MAX; i++) { + if (v9p_race_rcvd_resp[i].used && + v9p_race_rcvd_resp[i].desc_idx =3D=3D desc_idx) { + uint32_t len =3D v9p_race_rcvd_resp[i].len; + + v9p_race_rcvd_resp[i].used =3D false; + return len; + } + } + return UINT32_MAX; +} + +/* + * Wait for the used ring entry of @req, returns immediately if the respon= se + * was already received. + * + * As responses may arrive in a different order than their requests were + * originally sent, received responses that belong to a different, in-flig= ht + * request are locally stashed instead (waiting for later pickup). + * + * NOTE: this implementation polls the used ring directly instead of waiti= ng + * on the legacy virtio interrupt status register (ISR) that + * qvirtio_wait_used_elem() uses: that register is a single boolean read-c= lear + * flag, not a counter. So it could hide several used-ring entries. And si= nce + * that flag is not re-raised for entries that already arrived in the ring, + * waiting on the ISR could continue for good, even though all response + * entries were already received. Furthermore, qvirtio_wait_used_elem() as= serts + * that it receives the response of its own request next from the virtio r= ing. + * So we can't use qvirtio_wait_used_elem(), as it is designed to receive + * exactly one (in-order) response, whereas this race test is designed to + * receive several out-of-order responses. + */ +static void v9p_race_req_wait(QVirtio9P *v9p, P9Req *req, uint32_t *len) +{ + gint64 start =3D g_get_monotonic_time(); + + /* did the response already arrive and was just stashed locally? */ + *len =3D v9p_race_rcvd_resp_remove(req->free_head); + if (*len !=3D UINT32_MAX) { + return; + } + + /* poll virtio ring until requested response arrived */ + while (true) { + uint32_t idx; + + if (qvirtqueue_get_buf(global_qtest, v9p->vq, &idx, len)) { + if (idx =3D=3D req->free_head) { + return; + } + /* not the response we asked for, stash it then continue */ + v9p_race_rcvd_resp_add(idx, *len); + } + g_usleep(1000); + if (g_get_monotonic_time() - start > V9P_RACE_TIMEOUT_US) { + g_printerr("TIMEOUT waiting for tag=3D%u (free_head=3D%u)\n", + req->tag, req->free_head); + fflush(stderr); + g_assert_not_reached(); + } + } +} + +/* + * Wait for the response of @req, verify the tag and return the response + * ID. Frees @req. + */ +static uint8_t v9p_race_resp_collect(QVirtio9P *v9p, P9Req *req) +{ + uint32_t len; + P9MsgHeader hdr; + + v9p_race_req_wait(v9p, req, &len); + v9fs_memread(req, &hdr, sizeof(hdr)); + g_assert_cmpint(hdr.tag_le, =3D=3D, req->tag); + g_assert_cmpint(hdr.size_le, >=3D, sizeof(hdr)); + v9fs_req_free(req); + return hdr.id; +} + +/* Tolerant Tclunk: the FID may or may not exist on the server. */ +static void v9p_race_clunk_relaxed(QVirtio9P *v9p, uint32_t fid) +{ + TClunkRes res =3D v9fs_tclunk((TClunkOpt) { + .client =3D v9p, + .fid =3D fid, + .tag =3D v9p_race_new_tag(), + .requestOnly =3D true, + }); + + v9p_race_resp_collect(v9p, res.req); +} + +/* Tolerant Tunlinkat: the entry may or may not exist on the server. */ +static void v9p_race_unlink_relaxed(QVirtio9P *v9p, uint32_t dfid, + const char *name, uint32_t flags) +{ + TunlinkatRes res =3D v9fs_tunlinkat((TunlinkatOpt) { + .client =3D v9p, + .dirfd =3D dfid, + .name =3D name, + .flags =3D flags, + .tag =3D v9p_race_new_tag(), + .requestOnly =3D true, + }); + + v9p_race_resp_collect(v9p, res.req); +} + +/* + * Create the d1/d2/d3 directory chain inside the attached export root, + * walking each level into its own FID (V9P_RACE_D1_FID .. V9P_RACE_D3_FID= ). + */ +static void v9p_race_create_subdir_chain(QVirtio9P *v9p) +{ + uint16_t dfid =3D V9P_RACE_ROOT_FID; + int i; + + for (i =3D 1; i <=3D V9P_RACE_DIR_DEPTH; ++i) { + char dir[8]; + char *wnames[] =3D { dir }; + uint16_t newfid =3D + (i =3D=3D 1) ? V9P_RACE_D1_FID + : (i =3D=3D 2) ? V9P_RACE_D2_FID : V9P_RACE_D3_FID; + + snprintf(dir, sizeof(dir), "d%d", i); + v9fs_tmkdir((TMkdirOpt) { + .client =3D v9p, + .dfid =3D dfid, + .name =3D dir, + .mode =3D 0755, + .gid =3D 0, + .tag =3D v9p_race_new_tag(), + }); + v9fs_twalk((TWalkOpt) { + .client =3D v9p, + .fid =3D dfid, + .newfid =3D newfid, + .nwname =3D 1, + .wnames =3D wnames, + .tag =3D v9p_race_new_tag(), + }); + dfid =3D newfid; + } +} + +/* Prepare this test suite for running a race test. */ +static void v9p_race_prepare(QVirtio9P *v9p) +{ + int i; + + /* init local response stash */ + for (i =3D 0; i < V9P_RACE_RCVD_REPL_MAX; i++) { + v9p_race_rcvd_resp[i].used =3D false; + } + + /* attach to export root */ + v9fs_tattach((TAttachOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_ROOT_FID, + .tag =3D v9p_race_new_tag(), + }); + + /* create the d1/d2/d3 subdir chain */ + v9p_race_create_subdir_chain(v9p); + + /* open d2 and d3 as directory FIDs (V9P_RACE_D2_FID and V9P_RACE_D3_F= ID) */ + v9fs_tlopen((TLOpenOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D2_FID, + .flags =3D O_DIRECTORY, + .tag =3D v9p_race_new_tag(), + }); + v9fs_tlopen((TLOpenOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D3_FID, + .flags =3D O_DIRECTORY, + .tag =3D v9p_race_new_tag(), + }); +} + +/* Return true if race test shall be skipped. */ +static bool v9p_race_skip(void) { + const char *val =3D getenv("V9FS_RACE"); + + if (val) { + if (!strcmp(val, "0")) { + g_test_skip("V9FS_RACE=3D0 was set"); + return true; + } + if (!strcmp(val, "1")) { + g_print("V9FS_RACE=3D1 was set\n"); + return false; + } + } + if (!g_test_slow()) { + g_test_skip("This is a slow test, run with -m slow or set V9FS_RAC= E=3D1"); + return true; + } + g_print("Skip by setting V9FS_RACE=3D0\n"); + return false; +} + +/* Cleanup after running a race test. */ +static void v9p_race_cleanup(void *data) +{ + /* remove the temp directory used as export root */ + virtio_9p_remove_local_test_dir(); +} + +/* number of rounds a race test runs, shared by all race tests */ +static uint32_t v9p_race_rounds(void) +{ + const char *val =3D getenv("V9FS_RACE_ROUNDS"); + + if (val && *val) { + return atoi(val); + } + return 20000; +} + +/* number of unsynchronized in-flight race requests per round */ +static int v9p_race_nconcurrent(void) +{ + const char *val =3D getenv("V9FS_RACE_NCONCURRENT"); + int nreqs =3D 4; + + if (val && *val) { + nreqs =3D atoi(val); + } + /* an empty or invalid value falls back to the built-in default */ + if (nreqs < 1) { + nreqs =3D 4; + } + return nreqs; +} + +/* + * RACE TEST CASES + * + * The individual 9p race test scenarios. + */ + +/* + * Race 9p server's internal FID-path string (CVE-2026-93834). + * + * Per round, race one Tlcreate (mutating the FID path) request against + * FID path reader requests (Twalk and Txattrwalk) on the same FID. + */ +static void v9p_race_fid_path(void *obj, void *data, QGuestAllocator *t_al= loc) +{ + if (v9p_race_skip()) { + return; + } + QVirtio9P *v9p =3D obj; + uint32_t rounds =3D v9p_race_rounds(); + unsigned long created_files =3D 0; + unsigned long xattr_fids =3D 0, walk_fids =3D 0; + uint32_t i, d, k; + int nconcurrent =3D v9p_race_nconcurrent(); + g_autofree P9Req **readers =3D NULL; + + v9fs_set_allocator(t_alloc); + v9p_race_prepare(v9p); + + /* + * A round consumes one twalk, the Tlcreate itself, nconcurrent + * readers and up to nconcurrent + 2 clunks/unlinks from the + * per-round reset descriptor pool, so limit nconcurrent by the + * queue size. + */ + if (4 + 2 * nconcurrent > v9p->vq->size / 2) { + g_error("V9FS_RACE_NCONCURRENT: %d readers need %d requests " + "per round, but the queue holds at most %d", + nconcurrent, 4 + 2 * nconcurrent, v9p->vq->size / 2); + } + readers =3D g_new0(P9Req *, nconcurrent); + + for (i =3D 0; i < rounds; i++) { + uint16_t fid_a =3D V9P_RACE_FID_ROUND_BASE + + (i % V9P_RACE_FID_ROUND_SLOTS); + uint16_t fid_b =3D fid_a + 100; + uint16_t fid_c =3D fid_a + 200; + char name[16]; + uint16_t tag_a =3D v9p_race_new_tag(); + P9Req *req_a; + uint8_t resp_a; + + /* progress notification */ + if (i % 2000 =3D=3D 0) { + g_print("race/fid-path: %u/%u rounds\n", i, rounds); + fflush(stdout); + } + + /* + * Reset the descriptor pool at the start of every round, where + * no request is in-flight anymore. + */ + v9p_race_reset_pool(v9p); + + /* clone a FID of the target directory */ + v9fs_twalk((TWalkOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D3_FID, + .newfid =3D fid_a, + .nwname =3D 0, + .tag =3D v9p_race_new_tag(), + }); + + snprintf(name, sizeof(name), "r%05x", i); + + /* + * writer: Tlcreate on fid_a mutates its (9p server internal) FID-= path + * string + */ + req_a =3D v9fs_tlcreate((TlcreateOpt) { + .client =3D v9p, + .fid =3D fid_a, + .name =3D name, + .flags =3D O_RDWR | O_CREAT, + .mode =3D 0644, + .gid =3D 0, + .tag =3D tag_a, + .requestOnly =3D true, + }).req; + + /* + * readers: Twalk and Txattrwalk requests + * + * Each reader request is sent after a few v9p_race_feed_main_loop= () + * calls. That allows the Tlcreate PDU advance processing. + */ + for (k =3D 0; k < nconcurrent; k++) { + /* + * Feed the main loop between 0..4 times. + * + * The amount of main loop feeds is changed per round and per + * reader. That way we create different time gaps between the + * writer (Tlcreate) and readers, which increases probability + * to hit the quite small window where a FID path is mutated. + */ + for (d =3D 0; d < ((i + k) % 5); d++) { + v9p_race_feed_main_loop(v9p); + } + if (!(k & 1)) { + uint16_t tag_c =3D v9p_race_new_tag(); + + /* Txattrwalk (list xattrs) */ + readers[k] =3D v9fs_txattrwalk((TXattrWalkOpt) { + .client =3D v9p, + .fid =3D fid_a, + .newfid =3D fid_c + k, + .name =3D "", /* empty xattr name -> list xattrs */ + .tag =3D tag_c, + .requestOnly =3D true, + }).req; + } else { + uint16_t tag_b =3D v9p_race_new_tag(); + + /* Twalk (clone FID) */ + readers[k] =3D v9fs_twalk((TWalkOpt) { + .client =3D v9p, + .fid =3D fid_a, + .newfid =3D fid_b + k, + .nwname =3D 0, /* no names to be walked -> clone FID */ + .tag =3D tag_b, + .requestOnly =3D true, + }).req; + } + } + + resp_a =3D v9p_race_resp_collect(v9p, req_a); + for (k =3D 0; k < nconcurrent; k++) { + uint8_t resp_r =3D v9p_race_resp_collect(v9p, readers[k]); + + if (!(k & 1) && resp_r =3D=3D P9_RXATTRWALK) { + xattr_fids++; + v9p_race_clunk_relaxed(v9p, fid_c + k); + } else if ((k & 1) && resp_r =3D=3D P9_RWALK) { + walk_fids++; + v9p_race_clunk_relaxed(v9p, fid_b + k); + } + } + v9p_race_clunk_relaxed(v9p, fid_a); + if (resp_a =3D=3D P9_RLCREATE) { + created_files++; + v9p_race_unlink_relaxed(v9p, V9P_RACE_D3_FID, name, 0); + } + } + + g_print("race/fid-path: %u rounds done, %lu files created, %lu walk " + "fids, %lu xattr fids\n", + rounds, created_files, walk_fids, xattr_fids); + fflush(stdout); +} + +/* setup and cleanup for race tests using the 9p 'local' fs driver */ +static void *v9p_race_local_driver(GString *cmd_line, void *arg) +{ + /* create a temp directory for being used as 9p export root */ + virtio_9p_create_local_test_dir(); + /* + * Use the "mapped-file" security model (not "mapped-xattr"): xattr on= ly + * works on file systems and systems that support and permit writing + * xattrs. mapped-file (hidden .virtfs_metadata files) OTOH is univers= ally + * more tolerant. + */ + virtio_9p_assign_local_driver(cmd_line, "security_model=3Dmapped-file"= ); + g_test_queue_destroy(v9p_race_cleanup, NULL); + return arg; +} + +/* register this overall test-suite */ +static void v9p_race_register_tests(void) +{ + QOSGraphTestOptions opts =3D { + .before =3D v9p_race_local_driver, + }; + + qos_add_test("race/fid-path", "virtio-9p", v9p_race_fid_path, &opts); +} + +libqos_init(v9p_race_register_tests); --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420613; cv=none; d=zohomail.com; s=zohoarc; b=XyTx+hBLbwK2/sAZ+GleGBk3pgUcx+dzFsHx+5v8Lb3KoZU2qMWKNxixG2qlbxSD2UVg1cfg2FkB87BFOF/gzF0pA65y22WS82+Xf6FSgNeNuBn/IR45oRJAQ1QaTRPPjnZZMSzFeplp6B3XO2obpZ0gWQMlQQUrMIG3pAYvYUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420613; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3sjb3UBBgzDNLh3mbrEpyXJaIuJ4otItdxce6XxFjQo=; b=cvBvZf5Z76OKiwLucVInDlmGTJPRzTTkOc3CJPoo+BeXOg6s1XvXAhdYPJhw3HuSmt3v+0cVwv6GIXmdhveX+PGjZy5wxiG1ZDgJw5MpOM4QLelJv7GfJgvZZOrnGi0pg1ePX5cMbr0dma6Y/8JSvJOk512CiuHyPd9ueTfl5VA= 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 1792420613743663.8354118121489; Mon, 19 Oct 2026 07:36:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoTP-0007Ge-5r; Mon, 19 Oct 2026 10:36:23 -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 <8a9be26b0aac54d97b4228dc1bd61049d80472a8@kylie.crudebyte.com>) id 1xIoTN-0007G0-8L for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:21 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <8a9be26b0aac54d97b4228dc1bd61049d80472a8@kylie.crudebyte.com>) id 1xIoTL-0007Vh-O0 for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=3sjb3UBBgzDNLh3mbrEpyXJaIuJ4otItdxce6XxFjQo=; b=KWRnw 84CstdT21DvgjQLnPd3c20K18lL+A2YbQCe05aES9oBH+rhRsV9Ky3KsRROsNzyVg+4kZkrJpPNyE 9QLa60L0LK3b0T7dTnmuScH8bWKWDzkvfB5rEPYJlr84bKu8Q7iRYM5UsVlwnHnpCY8n+X+2y8obX 7Gp2C900RxfKyek4D8JSWHdy7WRM7ZSwfZFtxnfBJYSrrgJDBOvwPfRe+o0zyQzrhLPVvhR3sFdaF 5KkGWMyKuHl3yLEkiec0kM9fH/HdvgU1O7zLlxWay6fkc0GqGKdsatWApnRskTNOlb5Umwr1Se819 iZ3lTBTCPUN51GduQQR5CKoIx1iNQQyt8t/zy3d8kkrIZH9y07ru3Gu33MG63uszIto1aFCGSIFcd P0V2i1KcymKfd6AjSeh6AryfOPrZ1wkjd9ekiWYw5ceJ7In017911KnXzKaax2xjvGSKR+ilroyG7 uhX4x9bdV6eLbHdpiHYNtwmTCC5G8EJT5fM3EAl8Pl7/ftZ+dSoSxjJ1g0T4XnNU6DM6YAskZu9QE R8KLROo12FozG/dWRplq2w7PICp49vzJ6gQko7c/GSp2KHrJO2CJmgVEkatgw1duij2vcIqkHYP2R /w76epKCU8cczu3qsWVFuLh6ophNxTFHSbIW5jYeB9PppN6iF7ZXp8RRADxqrA=; Message-ID: <8a9be26b0aac54d97b4228dc1bd61049d80472a8.1792420035.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 3/9] tests/9p-client: add Rerror function (legacy 9p2000.u) To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=8a9be26b0aac54d97b4228dc1bd61049d80472a8@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420615754158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add v9fs_rerror() function to the 9p test client. This function is the legacy 9p2000.u variant for returned errors (i.e. in contrast to the already existing Rlerror response handler function v9fs_rlerror() for the 9p2000.L protocol version). Link: https://lore.kernel.org/qemu-devel/13b2cead57321d45b6503059e35c1ec1b4= 9a629a.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p-client.c | 11 +++++++++++ tests/qtest/libqos/virtio-9p-client.h | 1 + 2 files changed, 12 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/vir= tio-9p-client.c index b2f0037b7b..005ae53a3f 100644 --- a/tests/qtest/libqos/virtio-9p-client.c +++ b/tests/qtest/libqos/virtio-9p-client.c @@ -287,6 +287,17 @@ void v9fs_req_free(P9Req *req) g_free(req); } =20 +/* size[4] Rerror tag[2] ename[s] errno[4] */ +void v9fs_rerror(P9Req *req, uint32_t *err) +{ + g_autofree char *ename =3D NULL; + + v9fs_req_recv(req, P9_RERROR); + v9fs_string_read(req, NULL, &ename); + v9fs_uint32_read(req, err); + v9fs_req_free(req); +} + /* size[4] Rlerror tag[2] ecode[4] */ void v9fs_rlerror(P9Req *req, uint32_t *err) { diff --git a/tests/qtest/libqos/virtio-9p-client.h b/tests/qtest/libqos/vir= tio-9p-client.h index c910407f70..5a00a0870c 100644 --- a/tests/qtest/libqos/virtio-9p-client.h +++ b/tests/qtest/libqos/virtio-9p-client.h @@ -599,6 +599,7 @@ void v9fs_req_send(P9Req *req); void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len); void v9fs_req_recv(P9Req *req, uint8_t id); void v9fs_req_free(P9Req *req); +void v9fs_rerror(P9Req *req, uint32_t *err); void v9fs_rlerror(P9Req *req, uint32_t *err); TVersionRes v9fs_tversion(TVersionOpt); void v9fs_rversion(P9Req *req, uint16_t *len, char **version); --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420609; cv=none; d=zohomail.com; s=zohoarc; b=WkkVv1RpM1hRpAHPLJIAEwDZ2IN+OboPbgDG4oc39q5fukn+WPRjmN57LJIpvfFoenq/4ewCBGv9kfzpmikE75qrtLrlqH8OReXquZKwyoNNmfogTbkITksvxgl8LCXzQGeJCSgx/8OlGbKEWHEo0W02M6ghrtyM7H8/ES2GY90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420609; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NGdxEStX6XvYegdLJTFQ6ZsZIwFzQRJXLTHmjAbZj2g=; b=SNKIUq+yuFoD8b4lFUz+h9MjBRLwhXy3oZZZhfdZ6QiOMg3V/cBnnLPG7oubKHmt12L0yq42+sEAG2tu7RtTgP7KC19XSMPXSAaz3GtA4JnjdGzZPUegEEMMbv3iNryYpVVnSNF3n/naxTpgACGkB+lX2o/+FqxeqmrEQXOGb+s= 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 1792420609465310.6293829582197; Mon, 19 Oct 2026 07:36:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoTV-0007H8-IH; Mon, 19 Oct 2026 10:36:29 -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 1xIoTU-0007H0-0w for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:28 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xIoTS-0007WA-4Q for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=NGdxEStX6XvYegdLJTFQ6ZsZIwFzQRJXLTHmjAbZj2g=; b=O06p+ roGSSnVJn6UePVn6rtfmSnKuUord2/tE68rovp/5UX0+lGs3I9q4mEl6/I5Bbu3JoiaO9k5Np31gN QJ3LHIpYbbX63FxF9VjIyKrgltNV33/YasZyfuW8dKZvKrf3UD5F3zTLbGMVTFaMKT0Gpdas3jmpU wJOwl5L0b4FnDjTx3XwgGeFoD3md7mnqGEzaBCBBSqaNBNDY/taxOO2+DjRJnJNY9WGiZiPp8XVkJ SKe0SxAkSHq6KBpvPBoDNIK6EDQYhbn+gN8003W9jwFrHUMX4JWUkK62ydyuPp2rVTEIxxCHM4sk1 ecusA/IL/uNp1cfiF7SKbwLP31cZaH31ECT4q7DQF/RBko3D/K8pi32lFkJTxd4vUIZPc1YKz8yVt rKL4iflC9bHMVeCh5cvjcDf3iwoxwNCD3u4K6lPR5QJwZIkEXVazCnt43QLyVUt1IzdLBBtq7/F+p 3Mi6Xj+88BUTpVjL017A0DDUaft/jzIlpnNUdY2+WWcBR984vG3L5AQlqn1Do02Vf2AEF+v+HLOH+ Bw1qovmT4eGuFcaSaVQcnQaQXpqC7c5/wIIiYrem8WjYDJnCJ2hh0sLD0YFeLH194/Zci+1yCdiLs 2iqNwfTCvBeWPoYc9Zsbc516c1nXJBaKSS7JTWayRimceibwAgc7jWkKR4/Quk=; Message-ID: In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 4/9] tests/9p-client: add Tstat / Rstat test client functions To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=a99e69adc75477caeebb3af14eed1cd21fd0c4fe@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420611665158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add v9fs_tstat() and v9fs_rstat() functions to the 9p test client. Since this is a request type that exists both in legacy 9p2000.u and modern 9p2000.L protocol version, error responses types might differ (Rerror vs. Rlerror). Therefore v9fs_tstat() is using an error type tolerant helper function v9fs_req_check_err() for processing expected errors with this request type. Link: https://lore.kernel.org/qemu-devel/46192047d8b38e4d37cef7115de6cad11e= a8f362.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p-client.c | 79 +++++++++++++++++++++++++++ tests/qtest/libqos/virtio-9p-client.h | 45 +++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/vir= tio-9p-client.c index 005ae53a3f..4a3fc1511b 100644 --- a/tests/qtest/libqos/virtio-9p-client.c +++ b/tests/qtest/libqos/virtio-9p-client.c @@ -306,6 +306,33 @@ void v9fs_rlerror(P9Req *req, uint32_t *err) v9fs_req_free(req); } =20 +/* + * Asserts for caller that the request's response returned with the passed, + * expected error code (in a protocol version agnostic manner). + */ +static void v9fs_req_check_err(P9Req *req, uint32_t expect_err) +{ + P9Hdr hdr; + uint32_t err; + + /* peek the response header */ + v9fs_memread(req, &hdr, sizeof(hdr)); + /* reset offset after peek, so v9fs_rlerror() etc. read correctly */ + req->r_off =3D 0; + + if (hdr.id =3D=3D P9_RLERROR) { + v9fs_rlerror(req, &err); + } else if (hdr.id =3D=3D P9_RERROR) { + v9fs_rerror(req, &err); + } else { + g_printerr("Received response %d (%s) instead of an error response= \n", + hdr.id, rmessage_name(hdr.id)); + v9fs_req_free(req); + g_assert_not_reached(); + } + g_assert_cmpint(err, =3D=3D, expect_err); +} + /* size[4] Tversion tag[2] msize[4] version[s] */ TVersionRes v9fs_tversion(TVersionOpt opt) { @@ -1286,3 +1313,55 @@ void v9fs_rxattrwalk(P9Req *req, uint64_t *size) } v9fs_req_free(req); } + +/* size[4] Tstat tag[2] fid[4] */ +TStatRes v9fs_tstat(TStatOpt opt) +{ + P9Req *req; + + g_assert(opt.client); + /* expecting either Rstat or an error response, but obviously not both= */ + g_assert(!opt.expectErr || !opt.rstat.stat); + + req =3D v9fs_req_init(opt.client, 4, P9_TSTAT, opt.tag); + v9fs_uint32_write(req, opt.fid); + v9fs_req_send(req); + + if (!opt.requestOnly) { + v9fs_req_wait_for_reply(req, NULL); + if (opt.expectErr) { + v9fs_req_check_err(req, opt.expectErr); + } else { + v9fs_rstat(req, opt.rstat.stat); + } + req =3D NULL; /* request was freed */ + } + + return (TStatRes) { .req =3D req }; +} + +/* size[4] Rstat tag[2] stat[n] */ +void v9fs_rstat(P9Req *req, v9fs_stat *stat) +{ + v9fs_req_recv(req, P9_RSTAT); + + v9fs_memskip(req, 2); /* protocol quirk: size appears twice */ + v9fs_uint16_read(req, &stat->size); + v9fs_uint16_read(req, &stat->type); + v9fs_uint32_read(req, &stat->dev); + v9fs_memread(req, &stat->qid, 13); + v9fs_uint32_read(req, &stat->mode); + v9fs_uint32_read(req, &stat->atime); + v9fs_uint32_read(req, &stat->mtime); + v9fs_uint64_read(req, &stat->length); + v9fs_string_read(req, NULL, &stat->name); + v9fs_string_read(req, NULL, &stat->uid); + v9fs_string_read(req, NULL, &stat->gid); + v9fs_string_read(req, NULL, &stat->muid); + v9fs_string_read(req, NULL, &stat->extension); + v9fs_uint32_read(req, &stat->n_uid); + v9fs_uint32_read(req, &stat->n_gid); + v9fs_uint32_read(req, &stat->n_muid); + + v9fs_req_free(req); +} diff --git a/tests/qtest/libqos/virtio-9p-client.h b/tests/qtest/libqos/vir= tio-9p-client.h index 5a00a0870c..f604cc0ee5 100644 --- a/tests/qtest/libqos/virtio-9p-client.h +++ b/tests/qtest/libqos/virtio-9p-client.h @@ -63,6 +63,25 @@ typedef struct v9fs_attr { uint64_t data_version; } v9fs_attr; =20 +typedef struct v9fs_stat { + uint16_t size; + uint16_t type; + uint32_t dev; + v9fs_qid qid; + uint32_t mode; + uint32_t atime; + uint32_t mtime; + uint64_t length; + char *name; + char *uid; + char *gid; + char *muid; + char *extension; + uint32_t n_uid; + uint32_t n_gid; + uint32_t n_muid; +} v9fs_stat; + #define P9_GETATTR_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS = */ #define P9_GETATTR_ALL 0x00003fffULL /* Mask for ALL fields */ =20 @@ -579,6 +598,30 @@ typedef struct TXattrWalkRes { uint64_t size; } TXattrWalkRes; =20 +/* options for 'Tstat' 9p request */ +typedef struct TStatOpt { + /* 9P client being used (mandatory) */ + QVirtio9P *client; + /* user supplied tag number being returned with response (optional) */ + uint16_t tag; + /* file ID to get the Rstat for (required) */ + uint32_t fid; + /* data being received from 9p server as 'Rstat' response (optional) */ + struct { + v9fs_stat *stat; + } rstat; + /* only send Tstat request but not wait for a reply? (optional) */ + bool requestOnly; + /* do we expect an error response, if yes which error code? (optional)= */ + uint32_t expectErr; +} TStatOpt; + +/* result of 'Tstat' 9p request */ +typedef struct TStatRes { + /* if requestOnly was set: request object for further processing */ + P9Req *req; +} TStatRes; + void v9fs_set_allocator(QGuestAllocator *t_alloc); void v9fs_memwrite(P9Req *req, const void *addr, size_t len); void v9fs_memskip(P9Req *req, size_t len); @@ -639,5 +682,7 @@ TXattrCreateRes v9fs_txattrcreate(TXattrCreateOpt opt); void v9fs_rxattrcreate(P9Req *req); TXattrWalkRes v9fs_txattrwalk(TXattrWalkOpt opt); void v9fs_rxattrwalk(P9Req *req, uint64_t *size); +TStatRes v9fs_tstat(TStatOpt opt); +void v9fs_rstat(P9Req *req, v9fs_stat *stat); =20 #endif --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420633; cv=none; d=zohomail.com; s=zohoarc; b=XGx3JEuLK9LP8nMoa9BHYrsGYwahr/I82KGkWelnSTAb0QPX+eY9EJyPPeWtEWapWHE94dfCSjd7PLEH8fG8jpm0M7BDUUcrj3P6mJGTbL1OsflWlnuoRJLNytJrn7cHhqJzgYUS8taF2e81+X2bIDXldioNi8Uks5CU2h44tsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420633; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7Gqh7a2C/ue9oVXVPArZpDD2iFAY0WjHZ3tdoBrmN44=; b=Wl/3SfEDngzvYTYVM/L8d5kJtwyBQYWA95OsXOVbcqZQV+Yv6fF1y7E78KSyXoFwTeIQcPzoSgbh3I1CytTSbn8JxLvTvr3592Lni6k3/dJGhT7XaMymscsDLjQYw0ZyOlf+TPxgj36Od00nQkm7jrqBxlTJKyzgYMsuuDiGEe4= 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 1792420633832937.7900643021579; Mon, 19 Oct 2026 07:37:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoTb-0007L6-UF; Mon, 19 Oct 2026 10:36:35 -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 <4095ea6012b695e976d57604c28bc23862f76504@kylie.crudebyte.com>) id 1xIoTa-0007Hk-NA for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:34 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <4095ea6012b695e976d57604c28bc23862f76504@kylie.crudebyte.com>) id 1xIoTY-0007Wv-Vc for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=7Gqh7a2C/ue9oVXVPArZpDD2iFAY0WjHZ3tdoBrmN44=; b=keb/2 xpAXG2WHxaQ/xvlnrrpPlZKR4ZYlopdFRT8LJXUPjrdjMQBNwY2Q4Ps7gun7VgOPC/26LKE5FMi8l ZRzRwz1eH/Kk80dntTLYMWYfszIRdjqVapwr8ktsfx0MZB8EANXC0nd5esYJJPOvdayIbphHih/YG iwbYcrzoh3nM4YSsAF/5X3ezMom8DtUIAs2wsUzhe7+0Vttv0ZXanGnimjdV5UquYG/Msbr8i51R9 ldXkG3Nyj9nJzwDjgcFqLAyBwZqnfkxU8hSZKcd2TXcm3tIjpCRGbvXFcA/3ZSFEiXFEWEFWpEgLF RdhgyMwKRtGkCzD8AiDhwxFmwfl6wWIeTVbT9OBWCUQFI3JTilKI3lM61qF5VC0h8jH/MwX8gyCMQ cAFLg4578dLo8+pBi+OzMi4/o/bQs3CWh7ZZ7+exc70nPACUSKpJs69PAv8SUhHZPtAGDG2TW+QZO ERw71VcHjFtSfJxhj8Gm0OY9REsRvaZ3dt46a//mdgpmkNKPdHGTmzscshEUpGlubUvVr8fYbEcKi m+DrvY4sjqtMN0ZMgnpEpGscSQJskLOPSdjPZ2B1tbFbNVyEo+4Iu3zHuWoyP8DZQfqUmdtOI8E+0 5pXjr6bJnqdjJnWUp5opOEegkkV5KBN4Hwv79y5PGOM0U0OJ9e5JUzSNw//EOE=; Message-ID: <4095ea6012b695e976d57604c28bc23862f76504.1792420035.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 5/9] tests/9p-race: add Treaddir race test To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=4095ea6012b695e976d57604c28bc23862f76504@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420635980158501 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add "race/readdir" test, a test racing Treaddir's directory stream. In each round a Treaddir request is sent against another Treaddir request or Tstat request on the same FID. This test is registered as slow test (i.e. skipped by default) and therefore requires -m slow to run. On my test machine a full run of 20000 rounds took around 1 minute to complete. Link: https://lore.kernel.org/qemu-devel/74993d75ee26e699b4543a2fb6f3b7c3b7= f49442.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-race-test.c | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tests/qtest/virtio-9p-race-test.c b/tests/qtest/virtio-9p-race= -test.c index 789fb7721d..d2b76bf075 100644 --- a/tests/qtest/virtio-9p-race-test.c +++ b/tests/qtest/virtio-9p-race-test.c @@ -546,6 +546,89 @@ static void v9p_race_fid_path(void *obj, void *data, Q= GuestAllocator *t_alloc) fflush(stdout); } =20 +/* + * Race 9p server's internal directory stream for Treaddir. + * + * Race Treaddir request against another Treaddir or Tstat request on the = same + * FID. + */ +static void v9p_race_readdir(void *obj, void *data, QGuestAllocator *t_all= oc) +{ + QVirtio9P *v9p =3D obj; + uint32_t rounds; + uint32_t i; + + if (v9p_race_skip()) { + return; + } + rounds =3D v9p_race_rounds(); + + v9fs_set_allocator(t_alloc); + v9p_race_prepare(v9p); + + for (i =3D 0; i < rounds; i++) { + P9Req *req_a, *req_b; + uint16_t tag_a =3D v9p_race_new_tag(); + uint16_t tag_b =3D v9p_race_new_tag(); + + if (i % 2000 =3D=3D 0) { + g_print("race/readdir: %u/%u rounds\n", i, rounds); + fflush(stdout); + } + + /* + * Reset the descriptor pool at the start of every round, where + * no request is in-flight anymore. + */ + v9p_race_reset_pool(v9p); + + /* initial Treaddir request */ + req_a =3D v9fs_treaddir((TReadDirOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D2_FID, + .offset =3D 0, + .count =3D 64, + .tag =3D tag_a, + .requestOnly =3D true, + }).req; + + /* + * On every 3rd round send a concurrent Tstat, otherwise a + * concurrent Treaddir request. + */ + if (i % 3 =3D=3D 0) { + /* a Tstat on the same directory FID */ + req_b =3D v9fs_tstat((TStatOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D2_FID, + .tag =3D tag_b, + .requestOnly =3D true, + }).req; + } else { + /* a concurrent Treaddir on the same FID */ + req_b =3D v9fs_treaddir((TReadDirOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D2_FID, + .offset =3D 0, + .count =3D 64, + .tag =3D tag_b, + .requestOnly =3D true, + }).req; + } + + uint8_t resp_a, resp_b; + + resp_a =3D v9p_race_resp_collect(v9p, req_a); + g_assert_cmpint(resp_a, =3D=3D, P9_RREADDIR); + resp_b =3D v9p_race_resp_collect(v9p, req_b); + g_assert_cmpint(resp_b, =3D=3D, + (i % 3 =3D=3D 0) ? P9_RSTAT : P9_RREADDIR); + } + + g_print("race/readdir: %u rounds done\n", rounds); + fflush(stdout); +} + /* setup and cleanup for race tests using the 9p 'local' fs driver */ static void *v9p_race_local_driver(GString *cmd_line, void *arg) { @@ -570,6 +653,7 @@ static void v9p_race_register_tests(void) }; =20 qos_add_test("race/fid-path", "virtio-9p", v9p_race_fid_path, &opts); + qos_add_test("race/readdir", "virtio-9p", v9p_race_readdir, &opts); } =20 libqos_init(v9p_race_register_tests); --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420619; cv=none; d=zohomail.com; s=zohoarc; b=R/3/o8Ul4U9oczQpBgaENYIPK6EQ8Lm9v9dpIk2Zo2ytpT00IsPoUh6uNoY/bXfjujMCjS7ThnoIJR500144rfVCY/yBwiU3pQaj3iYHNmFN0/HSr98fJG+VH6IJfa59WG5T95U/RFWzY1mx9ilGu5HMA4fFkMHJCXr7k+Ffmgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420619; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=upnmIveujoDak5KFIdh40JgC4qu3Wp35hH98+YdcFZ4=; b=abxsNWC4lMx3FJ1vPNSOvX7WXcjUtKbo3kXtIw9tBLDR3BAiNan/ZrguIDl9qlXVNL+M7Jh0fZfvdhXwMBt2ksZXX0jegqzJjNAsoZsju8Pf2N9Y6fNK1hucFVrZlMuw9FM1cXgGRRYdNLZIoOLNre01KULdkIu7HY8TsyryDC8= 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 1792420619038909.4862532420219; Mon, 19 Oct 2026 07:36:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoTj-0007xf-8a; Mon, 19 Oct 2026 10:36:43 -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 <12df3256042c8db14984248d0660d14e380b312d@kylie.crudebyte.com>) id 1xIoTh-0007kd-40; Mon, 19 Oct 2026 10:36:41 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <12df3256042c8db14984248d0660d14e380b312d@kylie.crudebyte.com>) id 1xIoTf-0007XH-5X; Mon, 19 Oct 2026 10:36:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=upnmIveujoDak5KFIdh40JgC4qu3Wp35hH98+YdcFZ4=; b=rONLP vw3Ney5V2+hcLFU7ytWWJDzLorI5B+3/xZWpnqjSf6Ou+excCop9AY7mncrgpwlNhAKR65LB3j2Er 2TtzH65JVG78FO04QsOOxQOAzQR9lWxnqUc5M3qOeX4ZPCtfdMpknak1m9oDZUu6xQicjbilBwwpY veRKpKKbjC8AFwVJu0FCstEZ1DTNYd/N9YmE/flPS6V+1bSuwBkW16kjr+ZJSV8BfL6dnx349ameU OOU9er0qb6ElTQ8MVt2ONYHGBFJXNv1FHA/bnA0YvkIF+FFckpvw1k7slcRHMsnzP9bAtwt6wbHgu cEOqb8c0Wag3FLpCgH2aCh7b50myslJCRqipx0uYVE57qimLzi7HuGAiFmluPQSkNddJEiSQRIPGw NWgdvxZhVCQxnjVFfEMG3+HAjFKAjOOHHc+9ZyalCcoYTlT4XdHp26+atBk4aW8DE3cciLAvAjGyu gieaWi6kquu/oscra2pV5WYezhHnfPVn6r0QgpuyYkD/Xn7LfSIPQwHlHfASTrbrL682MiOw/YNk2 oyQ+RjRQ82olBX0fS27KYaShE/HB3Vpg6xW0rFznBRRvb/JP8tnz1/qsMWy/5g68XYQhoMAtM1Pl9 7zhI4+rb14yUg42wQJGixxcd+y40ruwIdMoGPJ25MqPcpSrlofhaj/V9HUMkJk=; Message-ID: <12df3256042c8db14984248d0660d14e380b312d.1792420035.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 6/9] hw/9pfs: fix dirent stream protection for legacy (9p2000.u) Tread To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=12df3256042c8db14984248d0660d14e380b312d@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420619656158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Concurrent legacy Tread requests (9p2000.u) on the same directory FID race the FID's shared dirent stream. In the initial Tread implementation (a92315553d) the dirent stream was entirely unprotected. Commit 7cde47d4a8 introduced a lock, which mitigated the problem, but without sufficient full coverage for this request type, as it only held the lock during individual dirent stream steps. A concurrent request could mutate the dirent stream in between. Furthermore the initial rewinddir() (to offset 0) was still not protected at all. This could cause corrupted directory entries being returned to client, with entries missing, duplicate entries and wrong order, up to heap corruption of 9p server's QEMU process due to garbage seek targets. Fix this by holding the lock for the entire directory reading transaction (i.e. for the whole v9fs_do_readdir_with_stat() call). Fixes: a92315553d ("virtio-9p: Add P9_TREAD support") Link: https://lore.kernel.org/qemu-devel/2f0a6e10200bb3a0dbc0f762493cf1f4d6= 42d61b.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 4764d9db13..730d1279bb 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2421,6 +2421,10 @@ v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidS= tate *fidp, return offset; } =20 +/* + * The only caller of this function (v9fs_read()) holds the per-FID readdir + * lock during the whole call of this function. + */ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, V9fsFidState *fidp, uint32_t max_count) @@ -2431,6 +2435,7 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9f= sPDU *pdu, int32_t count =3D 0; struct stat stbuf; off_t saved_dir_pos; + off_t current_dir_pos; struct dirent *dent; =20 /* save the directory position */ @@ -2442,12 +2447,11 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V= 9fsPDU *pdu, while (1) { v9fs_path_init(&path); =20 - v9fs_readdir_lock(&fidp->fs.dir); - err =3D v9fs_co_readdir(pdu, fidp, &dent); if (err || !dent) { break; } + current_dir_pos =3D qemu_dirent_off(dent); err =3D v9fs_co_name_to_path(pdu, &fidp->path, dent->d_name, &path= ); if (err < 0) { break; @@ -2461,8 +2465,6 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9f= sPDU *pdu, break; } if ((count + v9stat.size + 2) > max_count) { - v9fs_readdir_unlock(&fidp->fs.dir); - /* Ran out of buffer. Set dir back to old position and return = */ v9fs_co_seekdir(pdu, fidp, saved_dir_pos); v9fs_stat_free(&v9stat); @@ -2473,8 +2475,6 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9f= sPDU *pdu, /* 11 =3D 7 + 4 (7 =3D start offset, 4 =3D space for storing count= ) */ len =3D pdu_marshal(pdu, 11 + count, "S", &v9stat); =20 - v9fs_readdir_unlock(&fidp->fs.dir); - if (len < 0) { v9fs_co_seekdir(pdu, fidp, saved_dir_pos); v9fs_stat_free(&v9stat); @@ -2484,11 +2484,9 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9= fsPDU *pdu, count +=3D len; v9fs_stat_free(&v9stat); v9fs_path_free(&path); - saved_dir_pos =3D qemu_dirent_off(dent); + saved_dir_pos =3D current_dir_pos; } =20 - v9fs_readdir_unlock(&fidp->fs.dir); - v9fs_path_free(&path); if (err < 0) { return err; @@ -2528,10 +2526,17 @@ static void coroutine_fn v9fs_read(void *opaque) err =3D -EOPNOTSUPP; goto out; } + /* + * Hold the lock for the entire readdir transaction (rewind and + * getdents) to prevent dirent stream corruption on concurrent req= uests + * on the same FID. + */ + v9fs_readdir_lock(&fidp->fs.dir); if (off =3D=3D 0) { v9fs_co_rewinddir(pdu, fidp); } count =3D v9fs_do_readdir_with_stat(pdu, fidp, max_count); + v9fs_readdir_unlock(&fidp->fs.dir); if (count < 0) { err =3D count; goto out; --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420702; cv=none; d=zohomail.com; s=zohoarc; b=izph7vzYHqL7pDgcOyM6rRVPkaWV9GEXqZTdMgkG3QnBRwV8AR5piBn4xdVshKZ37GGejRgJE+/vMAWs9rREvYzFdjz24izdO/l4VIfVbmm6GcG2PcPTbVEmoF3Adc++VpKZb3b78L/8SVk9ABze0uk6qybo57TZT97Pp6qKT5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420702; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D/l6eXUlVJjuO9j0jWaOG3I5EU2cMuMJYuYVQoLiou8=; b=WPQL21KJhu8A1cx5YE8EFJSTzogxYugXGX0+S7goH0kL5XgzqvsffL02MSyYK0M9PVYX9uwyQcgrAAd97mpXZtcsbSwebFXMgXZVCGeyUpNZPC6EzKyvU/VhyNetqqmjtvPQValBls3LMXH4Qew+zl2FyxgUJtJbVXneIxie/MI= 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 1792420702369665.2555829919113; Mon, 19 Oct 2026 07:38:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoU6-0008L3-PV; Mon, 19 Oct 2026 10:37:06 -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 1xIoTn-00085v-55 for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:48 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xIoTl-0007Xk-Ee for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=D/l6eXUlVJjuO9j0jWaOG3I5EU2cMuMJYuYVQoLiou8=; b=Ocqku JdGfeEdZ1BjqCAWGeyeXFMGti/TIP9M5Fe4QLJLuqO3ZXW2H7BCLyc6i2TB9hfkeuLpYxYb+i42z9 rdoZOGPyvFH6F18W0/iw+TVD6y7qygiZHtlo1SYTR8gFAVCVvYuiDP+r+nZoRL3Dfza4fWZkDxoaD rrf4CzSjL1PKb0Z3JwsP5hvz5p6XnMqawvXmWA3fDS72zO0irTcsgniuD8df85UVIE5wPHrmzYDZ/ jKoS7ijwYiWWMdpr9Hl1S06/gbQjnIOeR8XKK0xiWShPSypoe0B/aUjuZ9QZtK33c7qdP8E/7+lU9 JCaGhdZJW9hsndWPQ8BQILiCjPLsOc8fkfFq7H0PUriXqW528NsgeIQz9cJ81eaamxvee/JO1WLG9 DaTUz3XDddEBl1c5pPXqpdUVRVPk8AeV/XBHnAXy0+Irf/UoquApvOAJkXcWb+VflrveO/1/QwJY7 uM0tTUc5gBtV8a6EuYiUupqJgG1ESugOrUxe3pmBJFVvd/uur/feE8ThICRgfjrU+yOFMEFywhzAd GavCFy79hpA5WNgDJbWlMcs1Uow013EjH0BCBqAFsfAnBHhYvQd/yFeUac9q7kjLp1F2zT+zJG2Ib o7KPRHBRlfP1H+bJWZYed4+BeJEAlpp1FIlYFOpPqUZCcsnkXM/0gzeWRG2NJE=; Message-ID: In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 7/9] tests/9p-client: add Tcreate / Rcreate test client functions To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=d8dd4017095383bd4b14a7ee8151248f6902eb72@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420703202158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add v9fs_tcreate() and v9fs_rcreate() functions to the 9p test client for the legacy 9p2000(.u) Tcreate request type. This is a preparatory patch, these functions will be used by the subsequently added 9p race test. Link: https://lore.kernel.org/qemu-devel/532fed8595419fd57ec7d24dc5dbcbd8b1= 190e80.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p-client.c | 60 +++++++++++++++++++++++++++ tests/qtest/libqos/virtio-9p-client.h | 50 ++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/vir= tio-9p-client.c index 4a3fc1511b..ce67a4b8c5 100644 --- a/tests/qtest/libqos/virtio-9p-client.c +++ b/tests/qtest/libqos/virtio-9p-client.c @@ -1365,3 +1365,63 @@ void v9fs_rstat(P9Req *req, v9fs_stat *stat) =20 v9fs_req_free(req); } + +/* size[4] Tcreate tag[2] fid[4] name[s] perm[4] mode[1] extension[s] */ +TCreateRes v9fs_tcreate(TCreateOpt opt) +{ + P9Req *req; + uint8_t mode =3D opt.mode; + uint32_t body_size =3D 4 + 4 + 1; + uint16_t string_size; + + g_assert(opt.client); + /* expecting either Rcreate or an error response, but obviously not bo= th */ + g_assert(!opt.expectErr || !(opt.rcreate.qid || opt.rcreate.iounit)); + + if (!opt.perm) { + opt.perm =3D 0644; + } + if (!opt.extension) { + opt.extension =3D ""; + } + + string_size =3D v9fs_string_size(opt.name) + + v9fs_string_size(opt.extension); + g_assert_cmpint(body_size, <=3D, UINT32_MAX - string_size); + body_size +=3D string_size; + + req =3D v9fs_req_init(opt.client, body_size, P9_TCREATE, opt.tag); + v9fs_uint32_write(req, opt.fid); + v9fs_string_write(req, opt.name); + v9fs_uint32_write(req, opt.perm); + v9fs_memwrite(req, &mode, 1); + v9fs_string_write(req, opt.extension); + v9fs_req_send(req); + + if (!opt.requestOnly) { + v9fs_req_wait_for_reply(req, NULL); + if (opt.expectErr) { + v9fs_req_check_err(req, opt.expectErr); + } else { + v9fs_rcreate(req, opt.rcreate.qid, opt.rcreate.iounit); + } + req =3D NULL; /* request was freed */ + } + + return (TCreateRes) { .req =3D req }; +} + +/* size[4] Rcreate tag[2] qid[13] iounit[4] */ +void v9fs_rcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit) +{ + v9fs_req_recv(req, P9_RCREATE); + if (qid) { + v9fs_memread(req, qid, 13); + } else { + v9fs_memskip(req, 13); + } + if (iounit) { + v9fs_uint32_read(req, iounit); + } + v9fs_req_free(req); +} diff --git a/tests/qtest/libqos/virtio-9p-client.h b/tests/qtest/libqos/vir= tio-9p-client.h index f604cc0ee5..88e0f41ff0 100644 --- a/tests/qtest/libqos/virtio-9p-client.h +++ b/tests/qtest/libqos/virtio-9p-client.h @@ -372,6 +372,54 @@ typedef struct TMkdirRes { P9Req *req; } TMkdirRes; =20 +/* create directory */ +#define P9_CREATE_PERM_DMDIR 0x80000000 + +/* options for 'Tcreate' 9p request (legacy 9p2000.u) */ +typedef struct TCreateOpt { + /* 9P client being used (mandatory) */ + QVirtio9P *client; + /* user supplied tag number being returned with response (optional) */ + uint16_t tag; + /* file ID of the directory the new file shall be created in (required= ) */ + uint32_t fid; + /* name of the new file (required) */ + const char *name; + /* + * Create mode bits (including file type bits): + * e.g. 0644 for a regular file, + * or P9_CREATE_PERM_DMDIR | 0755 for a directory + * (optional) + */ + uint32_t perm; + /* + * Open mode byte: + * OREAD (0), OWRITE (1), ORDWR (2), OEXEC(3), OTRUNC(0x10), ORCLOSE(0= x40) + * (optional) + */ + uint8_t mode; + /* + * Extension data for special files (e.g. symlink target), empty for + * regular files. (optional) + */ + const char *extension; + /* data being received from 9p server as 'Rcreate' response (optional)= */ + struct { + v9fs_qid *qid; + uint32_t *iounit; + } rcreate; + /* only send Tcreate request but not wait for a reply? (optional) */ + bool requestOnly; + /* do we expect an error response, if yes which error code? (optional)= */ + uint32_t expectErr; +} TCreateOpt; + +/* result of 'Tcreate' 9p request */ +typedef struct TCreateRes { + /* if requestOnly was set: request object for further processing */ + P9Req *req; +} TCreateRes; + /* options for 'Tlcreate' 9p request */ typedef struct TlcreateOpt { /* 9P client being used (mandatory) */ @@ -666,6 +714,8 @@ TFlushRes v9fs_tflush(TFlushOpt); void v9fs_rflush(P9Req *req); TMkdirRes v9fs_tmkdir(TMkdirOpt); void v9fs_rmkdir(P9Req *req, v9fs_qid *qid); +TCreateRes v9fs_tcreate(TCreateOpt opt); +void v9fs_rcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit); TlcreateRes v9fs_tlcreate(TlcreateOpt); void v9fs_rlcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit); TsymlinkRes v9fs_tsymlink(TsymlinkOpt); --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420667; cv=none; d=zohomail.com; s=zohoarc; b=UTafoItKthYXSUnnpzP00JvyLo/LV4jKbEMsMHpIkOkqkMT6/cC1UwSDVvJ2u1enlVvohj2plLE1JSJx2GzNS6w/8g4J7jpNe9eQJHwiUUU2BE6HHTOWIRXujrPpL2vuORKg+kIE1YWN346IP+rceze9V1epbjFz4GYb19ydxGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420667; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oATbJdAiOnpwZcYA8cLN5rFgwHZ9uzquoQVshJz889Q=; b=Ex0mqf8tSfEFmiI6DzucjWVCR+GikH6LIBoWmfCLLmt67sU0RCeM3V60Ton22RqkF+qdHLKVoJffVA9foGowR97w3xbeWaRSoRdJbsR6ZemMXAz80BtKYMEJuNMN4iQp0d5SMoElOhpwkDMOPBYgE+6Sy+J1OBA2Jas0YnYyCP8= 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 179242066738579.61846158761966; Mon, 19 Oct 2026 07:37:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoUA-0008Re-Ir; Mon, 19 Oct 2026 10:37:10 -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 1xIoTu-0008Dr-2J for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:59 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xIoTs-0007YI-BX for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:36:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=oATbJdAiOnpwZcYA8cLN5rFgwHZ9uzquoQVshJz889Q=; b=f1kC6 4ozb0guQariBTywET5kYKZtOQSqwa/y+74YZzD6SPmlEZZDWDQfRkIZWR9kQrQyeQ51bjd2EWZLCx ACNw+uboMqzYtBOoaLaZqF+UhvSZhn50f+XvcoFdkFftea8CZUuepUaD4SXQ2e7yaFN4hosmMLF7O tOytrdXK34QqVyl5lEjI8So9oZgk4v3wzEE5ZXnaF+WFOpiYTeLOS65Xuzrg3+CwoUDYJHswmH/IP +LGldvDJPtZykifMmKxmX74gkgoV6UJtjz/b4djTRqOJHl31GwSi+HvhuaEFYvzU1Z8lcYmCjs0MJ vWRYJ8vYlteDtQ9Q3NyOBsdYVn4rfKipiRfFPmRNcrcjZJfReuluAsqjZJjInxhzGg6D9aBAyBTlW LGBaAW1YOLnqWfHspZDPmuZysuOUCRB/bTxYvFEzBoC9Ii4xCwlJZ+L7hy8sbWYJieEh3afvtW+1g lDRaYxtmu2lnUXOwn6T7K9B7vodlk0Qop4eaGluhIFclvEkQY5ceDSGkJ7ea3i2kUQK/nJNlsTabb e0jBBVzIhDC2R4sthqXswoZluU1TV27Hx00XmBkdovq2G2Shd5Ih0KbA6dW4shmyJxfYYeHj2zkPe W4ti9ZuC5S3ALlsjKFTmw2yEqESlD+cYG2EgsIzGEps39glX3Cgo+HtaEDHfuk=; Message-ID: In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 8/9] tests/9p-client: track the negotiated 9p version for session To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=b1ba6810f10139f5346c8fe49102d534aa94ce88@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420668765158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" So far v9fs_tattach() always sent an implied Tversion request, which was supposed to be a convenient mechanisms such that not every test case code would need to call v9fs_tversion() prior to a v9fs_tattach(). The problem however is that this implicit Tversion defaults to 9p2000.L, and it would also be (re)sent if an explicit v9fs_tversion() call had been issued with 9p2000.u before, which then would reset the session to the unintended 9p2000.L protocol version. Fix this by storing the initial Tversion request's (desired) protocol version to the client object. And only issue the implicit Tversion request inside of v9fs_tattach() if no protocol version had been negotiated already. This is a preparatory patch for the subsequently added race test, which negotiates a 9p2000.u session. It also allows request / response handling to later become more protocol dialect aware (e.g. expecting specific request / response types according to negotiated protocol version during a session). Link: https://lore.kernel.org/qemu-devel/419b2b047c0f61b9e4a7e58f117c03ec6f= eea1ea.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p-client.c | 15 ++++++++++++++- tests/qtest/libqos/virtio-9p.h | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/vir= tio-9p-client.c index ce67a4b8c5..20c7af91bd 100644 --- a/tests/qtest/libqos/virtio-9p-client.c +++ b/tests/qtest/libqos/virtio-9p-client.c @@ -366,6 +366,15 @@ TVersionRes v9fs_tversion(TVersionOpt opt) v9fs_string_write(req, opt.version); v9fs_req_send(req); =20 + /* store session's protocol version to client object */ + if (!strcmp(opt.version, "9P2000.u")) { + opt.client->proto_version =3D V9FS_PROTO_2000U; + } else if (!strcmp(opt.version, "9P2000.L")) { + opt.client->proto_version =3D V9FS_PROTO_2000L; + } else { + g_assert_not_reached(); + } + if (!opt.requestOnly) { v9fs_req_wait_for_reply(req, NULL); if (opt.expectErr) { @@ -412,7 +421,11 @@ TAttachRes v9fs_tattach(TAttachOpt opt) /* expecting either Rattach or Rlerror, but obviously not both */ g_assert(!opt.expectErr || !opt.rattach.qid); =20 - if (!opt.requestOnly) { + /* + * convenience feature: send an implicit Tversion request, however onl= y if + * Tversion has not been issued for this session before. + */ + if (!opt.requestOnly && opt.client->proto_version =3D=3D 0) { v9fs_tversion((TVersionOpt) { .client =3D opt.client }); } =20 diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h index e7efeef7a1..db21c5059c 100644 --- a/tests/qtest/libqos/virtio-9p.h +++ b/tests/qtest/libqos/virtio-9p.h @@ -22,6 +22,7 @@ #include "qgraph.h" #include "virtio.h" #include "virtio-pci.h" +#include "hw/9pfs/9p.h" =20 typedef struct QVirtio9P QVirtio9P; typedef struct QVirtio9PPCI QVirtio9PPCI; @@ -32,6 +33,11 @@ typedef struct QVirtio9PDevice QVirtio9PDevice; struct QVirtio9P { QVirtioDevice *vdev; QVirtQueue *vq; + /* + * The protocol version negotiated for this 9p session via Tversion re= quest + * (0 if no protocol version negotiated yet) + */ + P9ProtoVersion proto_version; }; =20 struct QVirtio9PPCI { --=20 2.47.3 From nobody Mon Nov 23 04:44:00 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=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1792420655; cv=none; d=zohomail.com; s=zohoarc; b=iW0VHq3vO068Z5fR0b0kKX96fy4HHr+80cmHf95YbxVwp2IzniaTxEZxfwIzaYJMWjcGU2S1B0HscEFulHbScmBXGum/Yz9dsh4ZsTY+ZSgl+U6fuHQKhi06/SvHopllWSE0A3rXB6ya9KJFBTm8A8sf4DlqHWM9SXwnNgmqah4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792420655; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Jcn+uwq7304tuSKjtC7Y/fP6NT1w44+am8hDGlhMZ2k=; b=DSQs1vkJEIalmsmPiBhnUUdjx0IVsxYPd1CbncWXVKaB8hggOqSCeRBRBKlc8qZ0hHCMk18IWRk+WB3pEGq4VlofN+FoPnt5ckcmna07s4dOImbvrdeUpP99PoeYk//H1eHE9h6RPJChS91orMfUKRT6cZRnOWNQx0SS+Gp7bQQ= 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 1792420655228826.6591967662706; Mon, 19 Oct 2026 07:37:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xIoUG-0008UT-8j; Mon, 19 Oct 2026 10:37:19 -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 1xIoU1-0008Kw-6O for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:37:04 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xIoTx-0007Yj-VH for qemu-devel@nongnu.org; Mon, 19 Oct 2026 10:37:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=Jcn+uwq7304tuSKjtC7Y/fP6NT1w44+am8hDGlhMZ2k=; b=QUyd9 PNUu7TL7FYxKu7cJ6NC/BGXO6jvoblhtYyOjli+nxHeQ7IMJoddbXOD5ugpI7motekGeDnsJO52Ms MG5/U3A/WO4Vxwj0QQe2Rxhp6dqSipWIrp2qwCZhJ03SbDlK2fKjdDATIHTH2UCn26tZRQx3XC5L6 wCdTjwJ2aHU9Y6kUS8e4lr5dXHWTv3XkA377a8OXHdSRVz4c88bxzmyPnv9EHisyuop0cLOTMSo13 oeRHe4Nv7jvfFflVrkRYGaoqLJ8xMRuiJJMC9/Va4X4ynAX5EwxcfeXiJ6SovKEfJqrhiu8SYOvHa Po2Rog9Nu9WyN+ruwB9AVXq/ww7W9h3RHGad4TE5gZXu2Wg/ivZBdhP2LvN554QgiHAoc6YFL//sS DpQ84EBgUyjmIiJ7KFLdxlGvgjvyg2/p5AeuIEPKnQxm9NKF3u61EZv/SwE5pbPP0AU6mz+vL+YcV xrcnOE5GhqPrdCv5SijO9doviaKTu9zNNrYPydRGpF//4HGj+b9AiKXSWUANrRX9G0AlyFVbMZaXH qb0RVCG0A4AECxEn1GepGvT2GaOB/MTz3URCw7H6d1JfTsaJ1IcI0wLUkuMBMdnRQaXWnSyY4ohhJ 2JWVM3hZNaFqF/s7ixR+VIj/RDzlAqQbNbHTHd+49DbxzlFIU3SjGOZgZN5qKE=; Message-ID: In-Reply-To: References: From: Christian Schoenebeck Date: Mon, 19 Oct 2026 16:27:16 +0200 Subject: [PULL 9/9] tests/9p-race: add Tread-on-dir race test To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell 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=5.189.157.229; envelope-from=e727e0c5d7d31640708fe3cebe31cc1312eefadc@kylie.crudebyte.com; helo=kylie.crudebyte.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @crudebyte.com) X-ZM-MESSAGEID: 1792420656405158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add "race/tread-dir" test, a test racing legacy (9p2000.u) Tread requests against each other on the same directory FID. This test guards the previous fix patch ("hw/9pfs: fix dirent stream protection for legacy (9p2000.u) Tread"). In each round a configurable number (V9FS_RACE_NCONCURRENT) of concurrent Tread requests are issued against each other, verifying that every Tread response lists the same (leading) directory entries as a reference directory entry list taken before the actual concurrent Tread request sequence starts. A vulnerable server would return directory entries either with corrupted entry names, or entries in varying order, or even crash the QEMU process due to garbage dirent seek targets. This test is explicitly using a 9p2000.u session, as Tread on directories is not a 9p2000.L feature (the latter uses Treaddir instead). This test is registered as slow test (i.e. skipped by default) and therefore requires -m slow to run. On my test machine a full run of 20000 rounds took around 5 minutes to complete. Link: https://lore.kernel.org/qemu-devel/39f9fb4e48dfd08ed6d05519be5a28898a= 3bf872.1791368962.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-race-test.c | 410 ++++++++++++++++++++++++++++-- 1 file changed, 393 insertions(+), 17 deletions(-) diff --git a/tests/qtest/virtio-9p-race-test.c b/tests/qtest/virtio-9p-race= -test.c index d2b76bf075..9d3c9f0a23 100644 --- a/tests/qtest/virtio-9p-race-test.c +++ b/tests/qtest/virtio-9p-race-test.c @@ -270,28 +270,52 @@ static void v9p_race_create_subdir_chain(QVirtio9P *v= 9p) =20 for (i =3D 1; i <=3D V9P_RACE_DIR_DEPTH; ++i) { char dir[8]; - char *wnames[] =3D { dir }; uint16_t newfid =3D (i =3D=3D 1) ? V9P_RACE_D1_FID : (i =3D=3D 2) ? V9P_RACE_D2_FID : V9P_RACE_D3_FID; =20 snprintf(dir, sizeof(dir), "d%d", i); - v9fs_tmkdir((TMkdirOpt) { - .client =3D v9p, - .dfid =3D dfid, - .name =3D dir, - .mode =3D 0755, - .gid =3D 0, - .tag =3D v9p_race_new_tag(), - }); - v9fs_twalk((TWalkOpt) { - .client =3D v9p, - .fid =3D dfid, - .newfid =3D newfid, - .nwname =3D 1, - .wnames =3D wnames, - .tag =3D v9p_race_new_tag(), - }); + if (v9p->proto_version =3D=3D V9FS_PROTO_2000L) { + char *wnames[] =3D { dir }; + + v9fs_tmkdir((TMkdirOpt) { + .client =3D v9p, + .dfid =3D dfid, + .name =3D dir, + .mode =3D 0755, + .gid =3D 0, + .tag =3D v9p_race_new_tag(), + }); + v9fs_twalk((TWalkOpt) { + .client =3D v9p, + .fid =3D dfid, + .newfid =3D newfid, + .nwname =3D 1, + .wnames =3D wnames, + .tag =3D v9p_race_new_tag(), + }); + } else { + /* + * clone dfid for Tcreate + * + * The legacy 9p2000(.u) Tcreate re-points the supplied FID to= the + * created (in this case) directory and requires it to be unop= ened. + */ + v9fs_twalk((TWalkOpt) { + .client =3D v9p, + .fid =3D dfid, + .newfid =3D newfid, + .nwname =3D 0, /* 0 -> clone FID */ + .tag =3D v9p_race_new_tag(), + }); + v9fs_tcreate((TCreateOpt) { + .client =3D v9p, + .fid =3D newfid, + .name =3D dir, + .perm =3D P9_CREATE_PERM_DMDIR | 0755, + .tag =3D v9p_race_new_tag(), + }); + } dfid =3D newfid; } } @@ -629,6 +653,357 @@ static void v9p_race_readdir(void *obj, void *data, Q= GuestAllocator *t_alloc) fflush(stdout); } =20 +/* number of files created for "race/tread-dir" test */ +#define V9P_RACE_TREAD_DIR_NFILES 40 + +/* returns true if @name is one of the dir entries known to exist in d3 */ +static bool v9p_race_tread_dir_entry_name_valid(const char *name) +{ + int n; + + if (!strcmp(name, ".") || !strcmp(name, "..")) { + return true; + } + if (name[0] !=3D 'f' || strlen(name) !=3D 3) { + return false; + } + /* + * atoi() returns 0 on error, therefore the files created for this test + * start with 1, not zero. + */ + n =3D atoi(&name[1]); + return n >=3D 1 && n <=3D V9P_RACE_TREAD_DIR_NFILES; +} + +/* + * Read one directory entry (as v9stat struct) from Rread response. + * + * Only the directory entry's name is returned + * (in @name, at most @name_size - 1 chars). + * + * Returns the number of response body bytes consumed for this entry. + */ +static size_t v9p_race_tread_dir_next_entry(P9Req *req, char *name, + size_t name_size) +{ + /* + * Each directory entry within Tread response is (with 9p2000.u): + * + * size[2] type[2] dev[4] qid[13] mode[4] atime[4] mtime[4] length[8] + * name[s] uid[s] gid[s] muid[s] ext[s] n_uid[4] n_gid[4] n_muid[4] + */ + uint16_t len =3D 0; + size_t consumed =3D 2 + 2 + 4 + 13 + 4 + 4 + 4 + 8; + int s; + + /* fast forward to name[s] */ + v9fs_memskip(req, consumed); + + /* read name[s] */ + v9fs_uint16_read(req, &len); + g_assert_cmpint(len, <, name_size); + v9fs_memread(req, name, len); + name[len] =3D '\0'; + consumed +=3D 2 + len; + + /* consume the rest of this entry */ + for (s =3D 0; s < 4; s++) { /* uid, gid, muid, ext */ + v9fs_string_read(req, &len, NULL); + consumed +=3D 2 + len; + } + v9fs_memskip(req, 4 + 4 + 4); /* n_uid, n_gid, n_muid */ + consumed +=3D 4 + 4 + 4; + + return consumed; +} + +/* + * Parse and verify an Rread response. + * + * We have created V9P_RACE_TREAD_DIR_NFILES number of files in directory = d3, + * so we already know the file name scheme to verify for individual entrie= s. + * + * Additionally, compare the returned directory entries with the passed + * reference list of entries. They must always match exactly in name and o= rder. + */ +static void v9p_race_tread_dir_verify_rread(P9Req *req, + const char *const *ref_names, + int n_ref_names) +{ + uint32_t count =3D 0, consumed =3D 0; + char name[64]; + int ientry; + + v9fs_uint32_read(req, &count); + + for (ientry =3D 0; consumed < count; ientry++) { + consumed +=3D v9p_race_tread_dir_next_entry(req, name, sizeof(name= )); + if (!v9p_race_tread_dir_entry_name_valid(name)) { + g_printerr("invalid dirent name: %.16s\n", name); + fflush(stderr); + g_assert_not_reached(); + } + if (ref_names && ientry < n_ref_names) { + if (strcmp(name, ref_names[ientry]) !=3D 0) { + g_printerr("entry-order mismatch at #%d: got '%s' expected= " + "'%s'\n", ientry, name, ref_names[ientry]); + fflush(stderr); + g_assert_not_reached(); + } + } + } + /* + * an empty Rread body means the dirent stream was corrupted + * (e.g. by a garbage seek) + */ + g_assert_cmpint(ientry, >, 0); +} + +/* + * Wait for response for @req, then verify if response is an Rread response + * with expected tag, then verify all directory entries. + */ +static void v9p_race_tread_dir_collect(QVirtio9P *v9p, P9Req *req, + const char *const *ref_names, + int n_ref_names) +{ + uint32_t len; + P9MsgHeader hdr; + + v9p_race_req_wait(v9p, req, &len); + v9fs_memread(req, &hdr, sizeof(hdr)); + g_assert_cmpint(hdr.tag_le, =3D=3D, req->tag); + if (hdr.id !=3D P9_RREAD) { + uint32_t ecode =3D 0; + + if (hdr.id =3D=3D P9_RERROR) { + v9fs_string_read(req, NULL, NULL); /* skip error string */ + } + if (hdr.id =3D=3D P9_RLERROR || hdr.id =3D=3D P9_RERROR) { + v9fs_uint32_read(req, &ecode); + } + g_error("Tread on dir FID returned ID %d (ecode %u, %s)", hdr.id, + ecode, strerror(ecode)); + } + g_assert_cmpint(hdr.size_le, >=3D, 11); + v9p_race_tread_dir_verify_rread(req, ref_names, n_ref_names); + v9fs_req_free(req); +} + +/* + * Race legacy (9p2000.u) Tread requests against each other on the same + * directory FID. + * + * This test creates V9P_RACE_TREAD_DIR_NFILES number of files under direc= tory + * d3 and verifies that (a portion of) these files are always returned by + * server in a stable manner (i.e. always exact same entry names, and in e= xact + * same order) for each Tread request sent on the same directory FID. + * + * We actually read less directory entries than we created files, just to = keep + * things simple. A small amount of dir entries retrieval is still enough = to + * detect corrupted Rread responses. + */ +static void v9p_race_tread_dir(void *obj, void *data, QGuestAllocator *t_a= lloc) +{ + if (v9p_race_skip()) { + return; + } + + QVirtio9P *v9p =3D obj; + uint32_t rounds =3D v9p_race_rounds(); + uint32_t i =3D 0, n; + + /* max. Rread bytes requested per Tread request */ + const uint32_t tread_size =3D 512; + + /* + * Max. amount of reference directory entries taken for verification + * (kept small enough to fit into one tread_size Rread response) + */ + const uint32_t ref_max =3D 8; + + v9fs_set_allocator(t_alloc); + + /* + * Need to set this session to legacy 9P2000.u dialect, because Tread = on + * directories is only valid there (9p2000.L provides Treaddir instead= ). + */ + v9fs_tversion((TVersionOpt) { + .client =3D v9p, + .version =3D "9P2000.u", + .tag =3D v9p_race_new_tag(), + }); + v9fs_tattach((TAttachOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_ROOT_FID, + .tag =3D v9p_race_new_tag(), + }); + + /* create d1/d2/d3 directory chain */ + v9p_race_create_subdir_chain(v9p); + + /* populate d3 with known directory entries */ + for (n =3D 0; n < V9P_RACE_TREAD_DIR_NFILES; n++) { + char fname[8]; + + /* + * use a new FID for each file created, just to be sure + * (probably not really needed as we clunk it at the end of the lo= op) + */ + uint16_t fid =3D 60 + (n % 32); + + /* no in-flight requests, good to reset virtio descriptor pool */ + v9p_race_reset_pool(v9p); + + /* + * starting to create files by 1, not zero + * (see v9p_race_tread_dir_entry_name_valid() why) + */ + snprintf(fname, sizeof(fname), "f%02d", n + 1); + + /* + * clone d3 FID for Tcreate + * + * The legacy 9p2000(.u) Tcreate re-points the supplied FID to the + * created (in this case) file and requires it to be unopened. + */ + v9fs_twalk((TWalkOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D3_FID, + .newfid =3D fid, + .nwname =3D 0, /* 0 -> clone FID */ + .tag =3D v9p_race_new_tag(), + }); + /* create the file */ + v9fs_tcreate((TCreateOpt) { + .client =3D v9p, + .fid =3D fid, + .name =3D fname, + .tag =3D v9p_race_new_tag(), + }); + v9p_race_clunk_relaxed(v9p, fid); + } + + /* start the actual Tread-dir race test ... */ + { + g_autofree char **ref_storage =3D g_new0(char *, ref_max); + g_autofree const char **ref_names =3D g_new0(const char *, ref_max= ); + uint32_t len =3D 0, count =3D 0, consumed =3D 0; + int idx =3D 0; + int ref_count =3D 0; + g_autofree P9Req **reqs =3D NULL; + int nreq, r; + + /* no in-flight requests, good to reset virtio descriptor pool */ + v9p_race_reset_pool(v9p); + + /* + * Send and collect the initial "reference" Tread. + * + * One fundamental verification mechanism of this race test is to + * verify the order of the individual directory entries returned by + * server to be clean and stable. However the order is fs + * implementation specific, so we cannot simply assume the same or= der + * in which we created the files. + * + * Instead we first send out one safe (no race) Tread and use its + * entries returned as THE reference list of directory entries. + * + * Then in the concurrent Tread loop below, we compare the subsequ= ently + * collected follow-up Tread responses to always exactly match tho= se + * reference directory entries. + * + * One caveat: POSIX does not guarantee order of entries to be sta= ble, + * however in practice for non-modified directories it is actually + * stable. Let's not overcomplicate things (exotic systems) as this + * test is not run by default anyway. + */ + P9Req *req =3D v9fs_tread((TReadOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D3_FID, + .count =3D tread_size, + .tag =3D v9p_race_new_tag(), + .requestOnly =3D true, + }).req; + v9p_race_req_wait(v9p, req, &len); + { + P9MsgHeader hdr; + + v9fs_memread(req, &hdr, sizeof(hdr)); + g_assert_cmpint(hdr.id, =3D=3D, P9_RREAD); + } + v9fs_uint32_read(req, &count); + + /* collect reference directory entries */ + for (consumed =3D 0; consumed < count && idx < ref_max; idx++) { + char nbuf[64]; + + consumed +=3D v9p_race_tread_dir_next_entry(req, nbuf, sizeof(= nbuf)); + g_assert(v9p_race_tread_dir_entry_name_valid(nbuf)); + ref_storage[idx] =3D g_strdup(nbuf); + ref_names[idx] =3D ref_storage[idx]; + } + v9fs_req_free(req); + ref_count =3D idx; + g_assert_cmpint(ref_count, >=3D, 2); + + /* dump the reference list of entries */ + g_print("race/tread-dir: reference listing: %d entries (as follows= ):\n", + ref_count); + for (i =3D 0; i < ref_count; i++) { + g_print("race/tread-dir: reference entry #%u: '%s'\n", + i, ref_storage[i]); + } + fflush(stdout); + + nreq =3D v9p_race_nconcurrent(); + /* + * Limit the number of concurrent Tread requests to the descriptor= pool + * size. + */ + if (nreq > v9p->vq->size / 2) { + g_error("V9FS_RACE_NCONCURRENT: %d concurrent requests " + "exceeds the queue's max. request amount of %d", + nreq, v9p->vq->size / 2); + } + reqs =3D g_new0(P9Req *, nreq); + + /* run the requested number of test rounds */ + for (i =3D 0; i < rounds; i++) { + if (i % 2000 =3D=3D 0) { + g_print("race/tread-dir: %u/%u rounds\n", i, rounds); + fflush(stdout); + } + + /* no in-flight requests, good to reset virtio descriptor pool= */ + v9p_race_reset_pool(v9p); + + /* send the actual concurrent Tread requests */ + for (r =3D 0; r < nreq; r++) { + reqs[r] =3D v9fs_tread((TReadOpt) { + .client =3D v9p, + .fid =3D V9P_RACE_D3_FID, + .count =3D tread_size, + .tag =3D v9p_race_new_tag(), + .requestOnly =3D true, + }).req; + } + + /* collect and verify all responses */ + for (r =3D 0; r < nreq; r++) { + v9p_race_tread_dir_collect(v9p, reqs[r], ref_names, ref_co= unt); + } + } + + for (i =3D 0; i < ref_max; i++) { + g_free(ref_storage[i]); + } + } + + g_print("race/tread-dir: %u rounds done\n", rounds); + fflush(stdout); +} + /* setup and cleanup for race tests using the 9p 'local' fs driver */ static void *v9p_race_local_driver(GString *cmd_line, void *arg) { @@ -654,6 +1029,7 @@ static void v9p_race_register_tests(void) =20 qos_add_test("race/fid-path", "virtio-9p", v9p_race_fid_path, &opts); qos_add_test("race/readdir", "virtio-9p", v9p_race_readdir, &opts); + qos_add_test("race/tread-dir", "virtio-9p", v9p_race_tread_dir, &opts); } =20 libqos_init(v9p_race_register_tests); --=20 2.47.3