From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 959763E3176 for ; Mon, 17 Aug 2026 13:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974133; cv=none; b=WYwBAajsqd+lyeb8OeghJeTfPdJ+kr5U6h7hJFN5ekZmLc8oTvW6PSulTg4q1GRvpLBYGU3Fow2qTrCR8pkAG1Yq8m2rurx/2V5zj3qMZYWgCbAFrIfU8mFmRleivpOni7sPMNB6arOhyXZ9hzxu55Q2GG6Aw80uAZ4hYQt4KOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974133; c=relaxed/simple; bh=O/bTkpfxDK7wgp8C77ivdtmEVT3RkPujsiRjYOIdbTQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mwBIKnLgpE5p36G3h3OUXdB35V35Ba3B8blNvJ1eWDfaICY7WA4cRtOhnSgMWGMuUnuNfKmzYRHrM90VRgmX0cb9QeFF0WUgvR/YoSDx5maPfyFCk9tF8IJxYxbfwJzva+Nj77IKeDkOnlBiWJVBbPUEoo+hq3/PznE+sKSl4z8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sergiiushakov.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hNcX1XWv; arc=none smtp.client-ip=209.85.128.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sergiiushakov.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hNcX1XWv" Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-499900c9d99so16213065e9.0 for ; Mon, 17 Aug 2026 06:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786974130; x=1787578930; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+a64Ot6/PzSxx+bPX9pOVSI6enVUF78QeyJyJScORM8=; b=hNcX1XWvdiq5zZuWJ0mZuv2FhIbTsh3IAiZyVp/WJ/2BAfn+NvgujeDbj2YTk8i/Xj m7e4eMVopaL+WJeRXyYrlam6ScAqJkfd4N9fwIcaU0NMcArfC00p+PN5BM3r9onKo1ik AnSbYQWdwBzRoGPllK3o6l705FWqhTm0d9Li6prC2m4PuM73KSLAivHb5CQj0m9qQkJB kXnLlG92RxmJ0SyFSpqAJxyoHVCI/Nk8L2Wx6uodAqL0pnNdDUqo9HtMHUttkmefoQB2 ujRU2cY1ZV1AGn2LqF8qzxWoDDxEta/XUygzQY/ZmiTEqYVB7UfjjRy5Q/OnpTQz31fC OBAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786974130; x=1787578930; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+a64Ot6/PzSxx+bPX9pOVSI6enVUF78QeyJyJScORM8=; b=dO48S/KNJf52mEv1Q6+h3cL8npLjx7uZQjmrHQTsR0S/fYnEXQkjeT+g1nIsa2GaGw zP+mBREfqaQmg2u7t2LR/k6Gy4FLlm0AoBU9fOX2IW10Mvlo82XQlx9rcIrqxVTu88iO zUjcXyJSW9eiufK5i+Mc+UItCJUTCH76antL10ua4cIqz1uKBcfSRkpM0SlHOemMVsi5 OiBHTb7IthD9wjH2sPFOmb9oioqGvgSIqfZdk8vmBv30ZGwKkzsX0ZcDhBJH6hN6/Pn7 Tfja8ELtTfl8vPw9tiFSv7w6noO5Vyn+iWaCl/c3uaN+FxldeQYvoXZe0wMjItidIL6e Qbxw== X-Gm-Message-State: AOJu0YysWt1NB+oe7hBbreHMzbI2tnpI8kc6KzxBDEifDsoSCJsk6rGF HR1IhtjciBA8U3SdY55t06sd9kqvIghy2xTewhWfrBuTZ2hJn/tScddm/nTtl4GieUX9/weyWd0 GYzKmbADbIE9MvZQmeVw2syS1LONXizrJHQ== X-Received: from wmbes12.prod.google.com ([2002:a05:600c:810c:b0:495:713d:cc69]) (user=sergiiushakov job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4003:b0:495:3de8:33a6 with SMTP id 5b1f17b1804b1-4998798db40mr336981795e9.16.1786974129626; Mon, 17 Aug 2026 06:42:09 -0700 (PDT) Date: Mon, 17 Aug 2026 15:42:02 +0200 In-Reply-To: <20260814105954.4060627-1-sergiiushakov@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260814105954.4060627-1-sergiiushakov@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260817134202.160669-1-sergiiushakov@google.com> Subject: [PATCH v2] virtio-blk: clamp max_segments when indirect descriptors are disabled From: Sergii Ushakov To: virtualization@lists.linux.dev, linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , "Michael S . Tsirkin" , Jason Wang , Jens Axboe , Xuan Zhuo , "=?UTF-8?q?Eugenio=20P=C3=A9rez?=" , Paolo Bonzini , Stefan Hajnoczi , Sergii Ushakov Content-Type: text/plain; charset="UTF-8" When VIRTIO_RING_F_INDIRECT_DESC is not negotiated by the host, every scatter-gather segment in a request must consume a physical slot in the virtqueue ring. If the host does not advertise VIRTIO_BLK_F_SEG_MAX and provides a small virtqueue (e.g. 128 descriptors on QNX Hypervisor), the block layer defaults max_segments to BLK_MAX_SEGMENTS (1024). When a multi-page compound bio arrives from the page cache, virtqueue_add_split() rejects the request with -ENOSPC and triggers: WARNING: at drivers/virtio/virtio_ring.c:1493 virtqueue_add+... WARN_ON_ONCE(total_sg > vq->split.vring.num && !vq->indirect); This permanently wedges the blk-mq queue and blocks all subsequent disk I/O in uninterruptible sleep (D state). Automatically clamp sg_elems to (ring_size - 2) when indirect descriptors are disabled. Signed-off-by: Sergii Ushakov --- v1 -> v2: - Drop max_segments module parameter and rely solely on automatic clamping when indirect descriptors are disabled (suggested by Christoph Hellwig). - Guard (ring_size - 2) calculation with ring_size > 2 to prevent underflow. - Update commit description accordingly. drivers/block/virtio_blk.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 32bf3ba07a9d..8f5a2d5323a6 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1267,6 +1267,13 @@ static int virtblk_read_limits(struct virtio_blk *vblk, /* Prevent integer overflows and honor max vq size */ sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2); + if (!virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC)) { + u32 ring_size = virtqueue_get_vring_size(vblk->vqs[0].vq); + + if (ring_size > 2) + sg_elems = min(sg_elems, ring_size - 2); + } + /* We can handle whatever the host told us to handle. */ lim->max_segments = sg_elems; -- 2.55.0.691.gc56d675ccc-goog