From patchwork Wed Mar 17 19:08:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandrakanth Patil X-Patchwork-Id: 12146867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY, SPF_HELO_NONE,SPF_PASS,T_TVD_MIME_NO_HEADERS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EAB5C433E0 for ; Wed, 17 Mar 2021 19:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E926364F26 for ; Wed, 17 Mar 2021 19:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232996AbhCQTJl (ORCPT ); Wed, 17 Mar 2021 15:09:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233077AbhCQTJV (ORCPT ); Wed, 17 Mar 2021 15:09:21 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DC2C06174A for ; Wed, 17 Mar 2021 12:09:21 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id l3so1803756pfc.7 for ; Wed, 17 Mar 2021 12:09:21 -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:in-reply-to:references; bh=lH22rRiKdd/8JzUmI1iuB5JVs6A77Il6ygiTKT2K8eI=; b=ObsgGxHpgXW2DLD9MCPRpS9pox7WcI4e0w1LRcSKArcaLRw571opGEsh/WhrxknXFg ijiOAR6AV/7nhGi1blucFxvwPCj79pejPxD01jseXHShuLp9IqP/ACJGWLrJvPGblPNB 7H5CqseAA1UJgRSflQHPMMZjOvDNp75qfB3u8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lH22rRiKdd/8JzUmI1iuB5JVs6A77Il6ygiTKT2K8eI=; b=NlhSpCZT6nw8BrH1Mcl21my9Cpcwbsb0uJuwl765+nWRkvZxDu75o3aFzCgSFHipJU qwIv5PoGtAu9ijMP6sUgFbJJ0UfVW8H+ExVmnWGj5AOL5iglmU3rYbRlCr77CAb/A6s1 MOb56G8/RRPh79z2tDm96k2NmFe0leWxnkEm3vg4lY9KUZmrRhIvfP6wbpEL8wKsPX31 UkkqNHEAmPSxTt8sBlaAlaliQzdyxOZJxUPnrutxqxqFTTPDuYSrdHCrzQDgnm9QU5P/ oR4SybcXRdBL16BEtGlRWzv8yQM7Khd9zvbLqWrXNbK14SBt3e+w7HwywTan8fmflPC6 wtoQ== X-Gm-Message-State: AOAM531Dv3/6+YTOhRx6EdyJ1mgGb4cigsSbr/+rBBZEULuXM/AjQ1a5 6R/C7w0Q2p+1P5mokcP8CeaTsR5HYyeCSwkoF5ds6+DUNfXraqZS5c0xBVOVeGcrobULBQ7r0M6 XBUXYSHUVeygnXE8xJ52Ef5hCt1I+ne6RKZ6IOyx8LA73RqBux05YI9FgQCwvbarOkuTTkMWO2J 2yPCZvvDNMJ1em X-Google-Smtp-Source: ABdhPJxoQfkr2wyiVLt8p23ouX63OuH3SY0eyDspqWt45ACTCbi/jj6uk3kzp1zLoD2XyeaVK1U3Xg== X-Received: by 2002:a63:d70e:: with SMTP id d14mr3731475pgg.291.1616008160434; Wed, 17 Mar 2021 12:09:20 -0700 (PDT) Received: from dhcp-10-123-20-75.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id w2sm20569437pgh.54.2021.03.17.12.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 12:09:19 -0700 (PDT) From: Chandrakanth Patil To: linux-scsi@vger.kernel.org Cc: kashyap.desai@broadcom.com, sumit.saxena@broadcom.com, kiran-kumar.kasturi@broadcom.com, sankar.patra@broadcom.com, sasikumar.pc@broadcom.com, shivasharan.srikanteshwara@broadcom.com, anand.lodnoor@broadcom.com, Chandrakanth Patil Subject: [PATCH 3/5] megaraid_sas: Early detection of VD deletion through RaidMap update Date: Thu, 18 Mar 2021 00:38:22 +0530 Message-Id: <20210317190824.3050-4-chandrakanth.patil@broadcom.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210317190824.3050-1-chandrakanth.patil@broadcom.com> References: <20210317190824.3050-1-chandrakanth.patil@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Consider in a case, when a VD is deleted and the targetID of that VD is assigned to a newly created VD. If the sequence of deletion/addition of VD happens very quickly, there is a possibility that second event(VD add) occurs even before the driver processes the first event(VD delete). As event processing is done in deferred context the device list remains same(but targetID is re-used) so driver will not learn the VD deletion/additon and IOs meant for older VD will be directed to new VD which may lead to data corruption. In new design, driver will detect the deleted VD as soon as possible based on the RaidMap update and blocks further IOs to that device. Signed-off-by: Kashyap Desai Signed-off-by: Chandrakanth Patil Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/scsi/megaraid/megaraid_sas.h | 3 ++ drivers/scsi/megaraid/megaraid_sas_base.c | 61 ++++++++++++++++++++++- drivers/scsi/megaraid/megaraid_sas_fp.c | 6 ++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h index 0f808d63580e..d7185aa21eb5 100644 --- a/drivers/scsi/megaraid/megaraid_sas.h +++ b/drivers/scsi/megaraid/megaraid_sas.h @@ -2023,6 +2023,7 @@ union megasas_frame { struct MR_PRIV_DEVICE { bool is_tm_capable; bool tm_busy; + bool device_removed_by_fw; atomic_t r1_ldio_hint; u8 interface_type; u8 task_abort_tmo; @@ -2323,6 +2324,8 @@ struct megasas_instance { struct megasas_pd_list pd_list[MEGASAS_MAX_PD]; struct megasas_pd_list local_pd_list[MEGASAS_MAX_PD]; u8 ld_ids[MEGASAS_MAX_LD_IDS]; + u8 ld_ids_prev[MEGASAS_MAX_LD_IDS]; + u8 ld_ids_from_raidmap[MEGASAS_MAX_LD_IDS]; s8 init_id; u16 max_num_sge; diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 7ab741f03b84..f3716f7e1d10 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -426,6 +426,12 @@ megasas_decode_evt(struct megasas_instance *instance) (class_locale.members.locale), format_class(class_locale.members.class), evt_detail->description); + + if (megasas_dbg_lvl & LD_PD_DEBUG) + dev_info(&instance->pdev->dev, + "evt_detail.args.ld.target_id/index %d/%d\n", + evt_detail->args.ld.target_id, evt_detail->args.ld.ld_index); + } /* @@ -1802,7 +1808,8 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) } mr_device_priv_data = scmd->device->hostdata; - if (!mr_device_priv_data) { + if (!mr_device_priv_data || + mr_device_priv_data->device_removed_by_fw) { scmd->result = DID_NO_CONNECT << 16; scmd->scsi_done(scmd); return 0; @@ -3491,6 +3498,39 @@ megasas_complete_abort(struct megasas_instance *instance, } } +void +megasas_set_sdev_removed_by_fw(struct megasas_instance *instance) +{ + struct scsi_device *sdev; + struct MR_PRIV_DEVICE *mr_device_priv_data; + uint channel, id, i; + + for (i = 0; (i < MEGASAS_MAX_LD_IDS); i++) { + if (instance->ld_ids_prev[i] != 0xff && + instance->ld_ids_from_raidmap[i] == 0xff) { + channel = MEGASAS_MAX_PD_CHANNELS + + (instance->ld_ids_prev[i] / + MEGASAS_MAX_DEV_PER_CHANNEL); + id = (instance->ld_ids_prev[i] % + MEGASAS_MAX_DEV_PER_CHANNEL); + + if (megasas_dbg_lvl & LD_PD_DEBUG) + dev_info(&instance->pdev->dev, + "index %d old 0x%x new 0x%x from %s\n", + i, instance->ld_ids_prev[i], + instance->ld_ids_from_raidmap[i], + __func__); + + sdev = scsi_device_lookup(instance->host, channel, id, 0); + if (sdev) { + mr_device_priv_data = sdev->hostdata; + mr_device_priv_data->device_removed_by_fw = true; + scsi_device_put(sdev); + } + } + } +} + /** * megasas_complete_cmd - Completes a command * @instance: Adapter soft state @@ -3656,6 +3696,10 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, megasas_sync_map_info(instance); spin_unlock_irqrestore(instance->host->host_lock, flags); + + if (instance->adapter_type >= INVADER_SERIES) + megasas_set_sdev_removed_by_fw(instance); + break; } if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || @@ -8764,8 +8808,10 @@ megasas_aen_polling(struct work_struct *work) union megasas_evt_class_locale class_locale; int event_type = 0; u32 seq_num; + u16 ld_target_id; int error; u8 dcmd_ret = DCMD_SUCCESS; + struct scsi_device *sdev1; if (!instance) { printk(KERN_ERR "invalid instance!\n"); @@ -8788,12 +8834,23 @@ megasas_aen_polling(struct work_struct *work) break; case MR_EVT_LD_OFFLINE: - case MR_EVT_CFG_CLEARED: case MR_EVT_LD_DELETED: + ld_target_id = instance->evt_detail->args.ld.target_id; + sdev1 = scsi_device_lookup(instance->host, + MEGASAS_MAX_PD_CHANNELS + + (ld_target_id / MEGASAS_MAX_DEV_PER_CHANNEL), + (ld_target_id - MEGASAS_MAX_DEV_PER_CHANNEL), + 0); + if (sdev1) + megasas_remove_scsi_device(sdev1); + + event_type = SCAN_VD_CHANNEL; + break; case MR_EVT_LD_CREATED: event_type = SCAN_VD_CHANNEL; break; + case MR_EVT_CFG_CLEARED: case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: case MR_EVT_FOREIGN_CFG_IMPORTED: case MR_EVT_LD_STATE_CHANGE: diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c index b6c08d620033..470b9797dd65 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fp.c +++ b/drivers/scsi/megaraid/megaraid_sas_fp.c @@ -349,6 +349,10 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id) num_lds = le16_to_cpu(drv_map->raidMap.ldCount); + memcpy(instance->ld_ids_prev, + instance->ld_ids_from_raidmap, + sizeof(instance->ld_ids_from_raidmap)); + memset(instance->ld_ids_from_raidmap, 0xff, MEGASAS_MAX_LD_IDS); /*Convert Raid capability values to CPU arch */ for (i = 0; (num_lds > 0) && (i < MAX_LOGICAL_DRIVES_EXT); i++) { ld = MR_TargetIdToLdGet(i, drv_map); @@ -359,7 +363,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id) raid = MR_LdRaidGet(ld, drv_map); le32_to_cpus((u32 *)&raid->capability); - + instance->ld_ids_from_raidmap[ld] = i; num_lds--; }