From patchwork Thu Mar 24 09:47:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandrakanth Patil X-Patchwork-Id: 12790581 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 2B387C433EF for ; Thu, 24 Mar 2022 09:47:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345897AbiCXJtQ (ORCPT ); Thu, 24 Mar 2022 05:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239549AbiCXJtP (ORCPT ); Thu, 24 Mar 2022 05:49:15 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E81956C0B for ; Thu, 24 Mar 2022 02:47:44 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id mr5-20020a17090b238500b001c67366ae93so8962581pjb.4 for ; Thu, 24 Mar 2022 02:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:mime-version; bh=Sx4m+xoia2NtNjGC1wC/bNNlqZ2vtnEJVtmP1XR1KFk=; b=aHlgnxwEIs2fP+t9x76ptGI4opHeRDVSA/Y0CSxVQXaRwXntKI2LKxbBgZ6c5b7w3p BPOGvttXoOQwGXO1GsDqdiBkdcoFZCF4exKSID6OYJuJqMXi3eQf2rdk5LnhIeWIxSfl PQGiotB1m3Cy5bf6BUKPisI/npNsfGILJ09AI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=Sx4m+xoia2NtNjGC1wC/bNNlqZ2vtnEJVtmP1XR1KFk=; b=v62pbITcPVYQaBZO882Qfsi++rZA5B+IsaGCw7GueAA+dVJrnyYefSWKmYh+WGt+mV 1dMDFGgspkCLN1FNDyRCwhiMaiC6UXe0zNLNrddqohynCj5bg8/u+Fsu7LCgsPQHORMl gDYSDxNnl0qLaPLmsyI0esYBiswj0SjthPltZGNtPoLGVG91AN9u+xp93iZlT1tvHDKN KOLCyOWnRlWNYXul7VjIhjaQhQMKzlTwrCYJV4w1kR42MMB55n3Dc+nAQC1qVL5+Muve U+AT1fyAOXSR45IvotjQ4xjOriexAjhndpbbzZZIrEsC1EH6so2kIG0N+/cxCJDZ4FTY fMrA== X-Gm-Message-State: AOAM531qCa/wwci59ubnkTtqpqB4ncPZshiqceaGgUy6WamTsRV+IvGJ 6KZPJZKWjLbpHrXwn8WJ/bS7Z1KXZkCtSbTKQP9Zwx55w6Nn066bbk03EpUq/hu2YM3PUrp6zKm DQkSB3fC08eatVJH3aSQz7IThxqya8ZQtXtJa11wMi9xQPjUHdDD5VxDBbmqVitFnKD6+DKP3nF vOZi5HcdkRkJTq X-Google-Smtp-Source: ABdhPJzKwLQvVAOUUtbw+F6U8E/iW/WCTGZnQE3AJINS5cVWlb5PVLi+ye8iOXcJkH+A6I35BO1Brw== X-Received: by 2002:a17:90b:4f43:b0:1c7:552b:7553 with SMTP id pj3-20020a17090b4f4300b001c7552b7553mr5098436pjb.117.1648115263110; Thu, 24 Mar 2022 02:47:43 -0700 (PDT) Received: from dhcp-10-123-20-56.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b001c54dc9061esm2195305pjl.51.2022.03.24.02.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 02:47:42 -0700 (PDT) From: Chandrakanth patil To: linux-scsi@vger.kernel.org Cc: kashyap.desai@broadcom.com, sumit.saxena@broadcom.com, Chandrakanth patil Subject: [PATCH] megaraid_sas: device scan on logical target with invalid LUN ID deletes that target from the OS Date: Thu, 24 Mar 2022 02:47:11 -0700 Message-Id: <20220324094711.48833-1-chandrakanth.patil@broadcom.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The megaraid_sas driver supports single LUN, that is LUN 0. And all other LUNs are unsupported. When a device scan on logical target with invalid lun is invoked through sysfs that target itself is getting removed from the OS. So added a LUN ID validation in the slave destroy to avoid the target deletion. Signed-off-by: Chandrakanth patil --- drivers/scsi/megaraid/megaraid_sas.h | 3 +++ drivers/scsi/megaraid/megaraid_sas_base.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h index 611871ef15b5..4919ea54b827 100644 --- a/drivers/scsi/megaraid/megaraid_sas.h +++ b/drivers/scsi/megaraid/megaraid_sas.h @@ -2560,6 +2560,9 @@ struct megasas_instance_template { #define MEGASAS_IS_LOGICAL(sdev) \ ((sdev->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1) +#define MEGASAS_IS_LUN_VALID(sdev) \ + (((sdev)->lun == 0) ? 1 : 0) + #define MEGASAS_DEV_INDEX(scp) \ (((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \ scp->device->id) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 8bf72dbc33b7..db6793608447 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -2126,6 +2126,9 @@ static int megasas_slave_alloc(struct scsi_device *sdev) goto scan_target; } return -ENXIO; + } else if (!MEGASAS_IS_LUN_VALID(sdev)) { + sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__); + return -ENXIO; } scan_target: @@ -2156,6 +2159,10 @@ static void megasas_slave_destroy(struct scsi_device *sdev) instance = megasas_lookup_instance(sdev->host->host_no); if (MEGASAS_IS_LOGICAL(sdev)) { + if (!MEGASAS_IS_LUN_VALID(sdev)) { + sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__); + return; + } ld_tgt_id = MEGASAS_TARGET_ID(sdev); instance->ld_tgtid_status[ld_tgt_id] = LD_TARGET_ID_DELETED; if (megasas_dbg_lvl & LD_PD_DEBUG)