Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796090969; b=b9TU72WzACmAwwYAcnpL25rJJDuQrmk8GTQFg0/CAZ+NM0KAd0Hmms1Pg1P9SL2gsqtK xPnSMInstlDIkZKjjhxGOF/mkAlFtwYX5u+t0MOyTt9zYsBH4ra+xfGupSzalryFCn+tv kTAi/BDOW7ZqV2SsG+WfPm03aChVwsY2J0VwjZNEW0A2kptxrT0HM4SqaUKswzWLrYL+M s9iTlxDPH3f5HSIzpEgdANxkTf1MeCcpbM2BNhAtKs0zPo5yn+k/3ytgGYi+5mY82SwEg tKEAFwt2FMlzKpOVMOX35K5CQNBMtbAGBOibh4ugrAKU4haWTPAChS8VpLLB1NdCZhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796090969; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To; bh=2MC91TrlFuFxWlGjZSXvg7InCFYfMAeLf97IUa+u95o=; b=RrmW7LFm+4YwXxI+r7rSmogl0K/xVWS3UYZUYuZkUm6DtmVsPr/f1E0q83kZJzzzQLk/ Lc3Su5DCMQnn1csqcMqy5v+CQivkyMaGfdjM3rMfwsoxj2PU6LTnHYCqsXSj48wuNK/of Mo9n8P4rjbOwljMUfkq7AypTtG/Tu6orJGnwOILPJ0j7tPJyS7zLZequuAlelNVS2OPqG iKCxr0V15rJWlWCwysylM1Oj67xM+DgKwS+sFIHgCFTmxpZeucmJN5i1WN9F+XUDXiEk0 4Am9NUbEoLxr//pvZnX/38YgBS7FCj/M7aPkWkQsU34LKN7nD2K6nvpL84hH9AZjvqA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="UzFn/ne1"; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C50FB606A31A for ; Tue, 1 Dec 2026 02:09:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C50FB606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UzFn/ne1 Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-71ae5389c00so7099069eaf.2 for ; Mon, 30 Nov 2026 18:09:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796090968; x=1796695768; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=2MC91TrlFuFxWlGjZSXvg7InCFYfMAeLf97IUa+u95o=; b=UzFn/ne1btKjtqtp6mCdsr+jjB8ca53lIC5NOOPHyBjse+AvR/OuBiFaA+5Hmbt5px zodEHfz3wLrjwpG6i7xLK0Uwxwib4z+whN5XjmHxS3fE4Ppuf3udv13k2WVny0KetnE2 fyuSwhYHm6a/WxCrS3+mFhX+N1Xu5s7/Oitq8DcuIzQMuWM+ZTOTl544EslQdjZxvQVy zPCDibdnhwr4ANAQLwfAmQoc+wqRACkJEOiMCXjlT2EKaFXrSeOPiY8gWwEYTIHfhw4X UZMBNlqqGq8BXMyTNc+RB4+dLa+Je6/UeHLyLDHAM5dI/P87Djn4aRv1+2D/L4yNA9BM RCQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796090968; x=1796695768; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=2MC91TrlFuFxWlGjZSXvg7InCFYfMAeLf97IUa+u95o=; b=QIbmA4AULlH0svBymZDJXfHKtjuG53EcN5ZGVpRxTdh8WEMdlOtOOUcd1UovvmojCP yZE+Vk7N9+ibor7TpaaNHBzHAq8CVIuoZ/mD08k8DxYlWWLKegrmWH34+SpgRg+mRjas hoUxiABm4sbDHfoS2nt649R++gR59FcqY2v8UTIhCeuQ+vqxdA1hhr+48arcNejqywnr ZNmRFFD4jwOVNtRf7IOD8a0KEN1uUVtvmsjpLJQ11RbvJVUv8Ovpds1m/UeRvJ6mEwOj K0H/xMNAFlZSvl4fgeG2tdjJE2FQhDJ45je6BoAA7jc0RdeBww3MVD1SVd2vxLxo27FL rJAg== X-Forwarded-Encrypted: i=1; AL+hErFKYuPTqnr2sIJqGo/QPoqHrmtdBLsFXg6+gVurTmrEfMVMsurrF6r69LaP5/OWFJK7sLV78yCuAL3QBA==@vger.kernel.org X-Gm-Message-State: APuU4Z/uwJDd+p55RyvsnpMlWpxQJJmgd1+IkG1aO34JH1Ku0jDBsxkd WudzxobhSS5TB8/AmFOWKMPSHhFErju0wn4c3t2MU4zG+JwIz54e8j7Y X-Gm-Gg: AZFdTZdKhq6NaC7E28itGY7T/GaPbhvee5Eh9d3txKgkYMvmhRXBBh/dDCLitTuU8QT 5pSxPU0biCOJ4RvFp+eAFtB4ukowxI/pfYKkACynpU3P7/+2thT/ZW0RdzB6AEhf1ODOEsiZZxE b74gGnYh/a5Ez33JO9kPrnpzY5fFT549GZJ1B+OM6FEWqr4fc+uYNUB21J/b4vZMzRw1WQDvqKk BWKKeZx7bTJo8e2N7U3VOlF330BBHjrxSRUwA/M4V5bjTiLQuD2/3gEjFuzQ+q9SqrnmGK/N+Zh Jb4Y6oHoaz0VKUVs9MrwxJdOxn5v6Htqe3ScHa0JNiChJE6RJzX/ni+O7eOX9E0c6LibBBEFTuj PVdRQmaZAnJZtofPmndPy8dSLX+62MuZ0g+VlRaxDocdHWT6CY8koUdfiQK7wtxO6rV2MYvyKSn f8vTj4CyX4SwYKP+58oBK9z2na+qeP9fWtquPd1QnlQNM8aFVAN7IxgvAJYjqhOJBQbv60OWtZo g+Qqdp6ZS1Z5wOCW+/zPgJ08UfJnPiHEIEnBKYo58yWqw7EF4MLio31ACO4z+a9hsP/r85SW2sk Mq/wTCqHtG6xFKedDjMD5t7GXBYlhJKVl7TzKbKq9AlzfwxwDOrsLUzkEx7Ns8Ko41g5aAqPPiE KC73Fa4doUsDHzEOdmtzBlCrxudnwhvsRSg== X-Received: by 2002:a05:6820:f034:b0:71b:3fec:38a6 with SMTP id 006d021491bc7-71b3fec4b36mr28496716eaf.12.1796090967736; Mon, 30 Nov 2026 18:09:27 -0800 (PST) Received: from fedora-laptop ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc61659cb8sm32363768fac.17.2026.11.30.18.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 18:09:27 -0800 (PST) Date: Mon, 30 Nov 2026 20:09:21 -0600 From: Ming Lei To: Caleb Sander Mateos Cc: Jens Axboe , linux-block@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 1/5] ublk: fail READ/WRITE if the result from the server is invalid Message-ID: References: <20261130023937.606428-1-tom.leiming@gmail.com> <20261130023937.606428-2-tom.leiming@gmail.com> X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Nov 30, 2026 at 10:00:42AM -0800, Caleb Sander Mateos wrote: > On Sun, Nov 29, 2026 at 6:39 PM Ming Lei wrote: > > > > __ublk_complete_rq() passes io->res from the server straight to > > blk_update_request(). If it isn't a multiple of the logical block size, > > the data moves by io->res bytes but the start sector by io->res >> 9, > > so the requeued rest is read or written at the wrong place. > > > > Fail a READ or WRITE with -EIO if io->res isn't a multiple of the > > logical block size or is larger than the request, as is already done > > for a READ that returns 0. Fail a WRITE that returns 0 too, so that it > > can't be requeued forever once a short WRITE is completed by io->res > > again. > > > > The byte count of a READ's data that is copied only in part from the > > server's buffer has the same problem. Fail the READ if that count isn't > > a multiple of the logical block size. > > > > Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver") > > Cc: stable@vger.kernel.org > > Signed-off-by: Ming Lei > > --- > > drivers/block/ublk_drv.c | 16 +++++++++++++--- > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c > > index 0699f22714fd..db1b049b7ac0 100644 > > --- a/drivers/block/ublk_drv.c > > +++ b/drivers/block/ublk_drv.c > > @@ -1577,8 +1577,16 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, > > blk_status_t res = BLK_STS_OK; > > bool requeue; > > > > - /* failed read IO if nothing is read */ > > - if (!io->res && req_op(req) == REQ_OP_READ) > > + /* > > + * The result of READ and WRITE is the number of bytes done. A short > > + * one has to be whole logical blocks, so that a requeued rest starts > > + * at the right sector. Fail anything else: more than the request, not > > + * aligned, or nothing done. > > + */ > > + if ((req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE) && > > Are these the only I/O types that need to be checked? Looks like > partial ZONE_APPEND operations are failed in blk_update_request(), but Patch 4 fails res < blk_rq_bytes(req) for ZONE_APPEND. > do we still need to validate that io->res <= blk_rq_bytes(req)? How > about for DISCARD, WRITE_ZEROES, and DRV_IN (for the zone report)? And > what about requests without data (FLUSH, zone management, etc.)? Yes, for correctness. Only READ and WRITE pass io->res to blk_update_request(). Every other op goes to exit: and ublk_end_request(req, res), where only the sign of io->res matters, so an oversized or unaligned value can't misplace anything. > > > + io->res >= 0 && unlikely(io->res != blk_rq_bytes(req)) && > > Move the unlikely() branch first? Agree, will do. Thanks, Ming