From patchwork Wed Nov 15 01:53:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 743983 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp2511649wrw; Tue, 14 Nov 2023 17:54:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqnSrIYgKKVnyGYEspfvR8Y23m7ahkIm6VRfuHeBqaIuHEVj+sNtf09hvKD2GghXmxQCBY X-Received: by 2002:a17:907:3608:b0:9d3:2de:5cbe with SMTP id bk8-20020a170907360800b009d302de5cbemr10510514ejc.18.1700013256499; Tue, 14 Nov 2023 17:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700013256; cv=none; d=google.com; s=arc-20160816; b=PUQgd81xosPXInCvoL0rKRtozHPU2y95ayoEKiTnBKUc4RA0fbs5QBjv1SffmdQprk pkwgZY1IiiOt9waS4oSn3pOR54GReadp5VCFAGl9DmITAvYMrBgyV73YiCE15q4C395E tId05f2b54pzhk6gF5yAGvmpaQXz+TejFJC2hwwVRbNT+Y52RDn3Zud6nFcaHV8cIfki HdZN5JxK0+z5mI45FLxnKRyB8kunXwtyDZ2vUPPcl0G5PHD880pNs8m4hy4Hbo3+UalW nAmWQtE6LAjZy+rwgV/6o0OS6+jbWjjsMjWnorI7O9SzbzLAEIw9fvldhp8jGTQgWYWX o0HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=hMvRjKgSagfGhAjd/ayWlVt7uZ7h5ZkFzJYGHzHjyy8=; fh=nfsNvhqzSMYQwHfr/wB70ze0iJ1Ln+coBMMqrBKxIj4=; b=YmOSesPQYIbhc6JKG/2w1LgjlAxI/ptZpcQDRaRqzCt66NTF7y4FAPIg3AmYpm+xl0 htoy+2s0C/OWSfnd/Edotq4OUpkhnEhmbUND2rvOaeKThkSeImGbFl6/PPckF9/Esed3 ChOFsyNeKbycpvii44qPiDuoP4twhlcTNnCw/x3ZBhU4aTSxAzl6RSXHHBj83+93tbsx AZJS9VrXNbXhRbxIQkKQyX0cQDyF4YGbU3AN3Ne273oOL87tfIOQDy5eNzWRz+YsYOa6 nRYfmVkD+DHal40XO8fQf9FOHCFXv37/Amg5ofs8UnEKgKrYbdpKikXPuUEgmA6iIh6J L00A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K4rKZWew; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id qb16-20020a1709077e9000b009c51de14efesi4654353ejc.345.2023.11.14.17.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 17:54:16 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K4rKZWew; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF63187063; Wed, 15 Nov 2023 02:54:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="K4rKZWew"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 28CA886FDD; Wed, 15 Nov 2023 02:54:02 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C574A86863 for ; Wed, 15 Nov 2023 02:53:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1cc55bcd51eso5201445ad.0 for ; Tue, 14 Nov 2023 17:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700013238; x=1700618038; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hMvRjKgSagfGhAjd/ayWlVt7uZ7h5ZkFzJYGHzHjyy8=; b=K4rKZWewDAi0A+MDCj5UAs09J1h6Omk4FAaAiw38Otlt3TtD9Grw7D4yUaPL0uHnBx 1x6q2WXvDaGN+hmvEj68Nx9CfYbE1oGDra+VWTPMwj6FSdvtO9QAteNrdGlU1sy6DxD8 LnoGRURusIGl2zw7vQN/AyZMfdXwgs5Exq2iUxoBro4BM2l5ZRxlhrOTOlXkNmagpUKT LZSoxI78riopzCLQSxixAyArlgBfmnc83X7W+JP4xA/I879XY055qpWUykul/G8so8UR cm42r0mscM0v1vrH4/p0zJ6I6CEJmrTaGWBamjOBP9bMxMVIZxPRzkuFH7JzMEyQdctx qPgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700013238; x=1700618038; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hMvRjKgSagfGhAjd/ayWlVt7uZ7h5ZkFzJYGHzHjyy8=; b=J3MUXS+AeIpOGdO0H6k2S/WQ5k9fQrOVxAhKibykW8Oombl6K0XH29OqtDbnBrE25h c1hzqQoBeJNKdgotxhRYHWvCmx/sgXP/H6EVSkvod3tO78Sleqz6/+h+urXkFl2mVGfA wSrYLEQ9o+Dbes8e1wgJT0UBR/ajR/i2lKw2QNoSGm3TCCgIcsIsYbyAj9TM9EewZCUS fQX+AbUAZDSOTaIawZmbAlqYrxkm6cMJPR2qdHNqrNXybYYZkltArI+c4LtQXrCrWcaQ fQolB5nxVhIttNbp2qao+SXcNiduuDAdP/LIUsX0uir//OHPGwAnnCM3ue5lTZjE3tCq 9PdA== X-Gm-Message-State: AOJu0YxHQmWc3y0nFdcraA6cYI6B8nV9EvCCpa9i2MmZ2Xixj44p6mky 6ouODjM1nQmqiV4bEIkPQMtnZA== X-Received: by 2002:a17:902:f54e:b0:1c0:bf60:ba82 with SMTP id h14-20020a170902f54e00b001c0bf60ba82mr1576126plf.5.1700013237956; Tue, 14 Nov 2023 17:53:57 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:4b12:3529:888b:74af]) by smtp.gmail.com with ESMTPSA id b10-20020a170903228a00b001bf6ea340b3sm6348864plh.116.2023.11.14.17.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 17:53:57 -0800 (PST) From: AKASHI Takahiro To: vicooodin@gmail.com, oleksandr_andrushchenko@epam.com Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH] xen: pvblock: fix the maximum io size in one operation Date: Wed, 15 Nov 2023 10:53:45 +0900 Message-Id: <20231115015345.490313-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The current implementation may cause BUG_ON() in blkfront_aio() BUG_ON(n > BLKIF_MAX_SEGMENTS_PER_REQUEST); In pvblock_iop(), a read/write operation will be split into smaller chunks of data so that the size in one access (aio_nbytes) is limited to, at the maximum, BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE But this works only if when the *buffer* passed in to pvblock_io() is page-aligned. If not, the given data region may stand across (BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) pages. See the logic in blkfront_aio(): start = (uintptr_t)aiocbp->aio_buf & PAGE_MASK; end = ((uintptr_t)aiocbp->aio_buf + aiocbp->aio_nbytes + PAGE_SIZE - 1) & PAGE_MASK; Then this will lead to BUG_ON() above. This can be fixed by decreasing the maximum size of aio_nbytes. Signed-off-by: AKASHI Takahiro Fixes: commit 3a739cc6c948 ("xen: pvblock: Implement front-back protocol and do IO") --- drivers/xen/pvblock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c index 4ad548d599d5..1df04e239ad0 100644 --- a/drivers/xen/pvblock.c +++ b/drivers/xen/pvblock.c @@ -632,7 +632,8 @@ static ulong pvblock_iop(struct udevice *udev, lbaint_t blknr, memcpy(blk_dev->bounce_buffer, buffer, desc->blksz); aiocb.aio_nbytes = unaligned ? desc->blksz : - min((size_t)(BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE), + min((size_t)((BLKIF_MAX_SEGMENTS_PER_REQUEST - 1) + * PAGE_SIZE), (size_t)(blocks_todo * desc->blksz)); blkfront_io(&aiocb, write);