From patchwork Fri Aug 4 15:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 710601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2720AC001DF for ; Fri, 4 Aug 2023 15:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbjHDPsl (ORCPT ); Fri, 4 Aug 2023 11:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbjHDPsg (ORCPT ); Fri, 4 Aug 2023 11:48:36 -0400 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9536212D; Fri, 4 Aug 2023 08:48:35 -0700 (PDT) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-686daaa5f1fso1707303b3a.3; Fri, 04 Aug 2023 08:48:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691164115; x=1691768915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/dgVJwigdvLnC3PLQrDWBl0zwhzVQqSuEsytYp17x/Y=; b=M4Ot9OTmkOPk+bUQurRH6a97qDMsh8YdTY7WFWWYd8xk8/kPPvX+yqDotL1Fx5OBon A4ySavAUZamGF1PzooWnHeoaWXj5LXIXSgviIS4AjUyDOAD2dahFQoEH4v0j8AsOX2QC uDHpmUbj/MvqbZ8eMtsWlIp7WtMyRWBhhLdNj9mDK+1Nf2mHjDIUk4dZqaP/mVL/1Gwk SwT5UcxVu8Xb5+z3NWbvuG4C3zElGZgZAd4zQUPvIHXQ25eZ5yI5ozUWQScnkRKQnB4e jm6zsaKjQDu3kr39qUzTsHxUVtJd9U2RvrmJqpZ/Ak9+S6LdkS75+4U2qp2lqNjXMuBd Nvag== X-Gm-Message-State: AOJu0YzuRWmbitPH6flf4ITxN/klifSvyJ0pTtPPTUs0/pJBjAx4M69K +4oPnla5CQHehdx7PZJs+I4= X-Google-Smtp-Source: AGHT+IE6UXeJ8m7847TPVs7vLSEAfOlH6ykY+KbSZLgMvhXxq6urbq5zJmbU1hdzw9B2bAQnGhyBoQ== X-Received: by 2002:a05:6a00:22c2:b0:687:3e8f:2211 with SMTP id f2-20020a056a0022c200b006873e8f2211mr2370496pfj.34.1691164115160; Fri, 04 Aug 2023 08:48:35 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:4af5:d063:a66d:403b]) by smtp.gmail.com with ESMTPSA id h8-20020a62b408000000b00640ddad2e0dsm1760839pfn.47.2023.08.04.08.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 08:48:34 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v6 5/7] scsi: scsi_debug: Support injecting unaligned write errors Date: Fri, 4 Aug 2023 08:48:03 -0700 Message-ID: <20230804154821.3232094-6-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230804154821.3232094-1-bvanassche@acm.org> References: <20230804154821.3232094-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allow user space software, e.g. a blktests test, to inject unaligned write errors. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 57c6242bfb26..051b0605f11f 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -181,6 +181,7 @@ static const char *sdebug_version_date = "20210520"; #define SDEBUG_OPT_NO_CDB_NOISE 0x4000 #define SDEBUG_OPT_HOST_BUSY 0x8000 #define SDEBUG_OPT_CMD_ABORT 0x10000 +#define SDEBUG_OPT_UNALIGNED_WRITE 0x20000 #define SDEBUG_OPT_ALL_NOISE (SDEBUG_OPT_NOISE | SDEBUG_OPT_Q_NOISE | \ SDEBUG_OPT_RESET_NOISE) #define SDEBUG_OPT_ALL_INJECTING (SDEBUG_OPT_RECOVERED_ERR | \ @@ -188,7 +189,8 @@ static const char *sdebug_version_date = "20210520"; SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR | \ SDEBUG_OPT_SHORT_TRANSFER | \ SDEBUG_OPT_HOST_BUSY | \ - SDEBUG_OPT_CMD_ABORT) + SDEBUG_OPT_CMD_ABORT | \ + SDEBUG_OPT_UNALIGNED_WRITE) #define SDEBUG_OPT_RECOV_DIF_DIX (SDEBUG_OPT_RECOVERED_ERR | \ SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR) @@ -3587,6 +3589,14 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + if (unlikely(sdebug_opts & SDEBUG_OPT_UNALIGNED_WRITE && + atomic_read(&sdeb_inject_pending))) { + atomic_set(&sdeb_inject_pending, 0); + mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, + UNALIGNED_WRITE_ASCQ); + return check_condition_result; + } + switch (cmd[0]) { case WRITE_16: ei_lba = 0;