From patchwork Fri Oct 20 02:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yangxingui X-Patchwork-Id: 155773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp785819vqb; Thu, 19 Oct 2023 19:46:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtEqA8jCb7AUDTiVGpOjLneL5FWTYQpjUHnS6wgseR7Ga7O4g9ipSTO4zJCFJxTV9Vzlcd X-Received: by 2002:a05:6a21:3d85:b0:154:e887:f581 with SMTP id bj5-20020a056a213d8500b00154e887f581mr584351pzc.58.1697770012333; Thu, 19 Oct 2023 19:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697770012; cv=none; d=google.com; s=arc-20160816; b=mzp7diwQX2RMu7ER+/Rd1CzttlbHfG0O223AVyO17IvuUB0Ic4hkltfRNhPNReV5Bo 1ebKGlrgyy6r5Rebi7+igrYRG9AaGVzTW91zYxu3pITb8evRerrWJEDMYLZmFjCMreQg QLjSTK0k2MXAphPMqWmImoNcV+nwkaQ05Eodvq+qHGnEvigUo8YkKGMsVbfN8gqr5xI4 qyIYil2zOXi1ReKA/yt0U7WUpT0NkJFzPFXa7tZGsnnSKYE7Jqe6btTLQOJHsTogy+qy 50+woRvoXbZSmyGgkkMRU9fRscPbTY3eyuPx7oHBg5oO5W/ak/ybGsdeYyuY0FsD7GDM iMKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=Ej8L7qST6FE24JDz8YHbsy9TrGZPmFyBJEegrFjKgIk=; fh=27xc93GhJfM5uXum+lQqhfgkfZxmIlVzL9a31/wQrQw=; b=0uJJjo1WQeVS8Wvw/QgGJBp93VaXniUpxEq1fdn73bKFvp9TIOxsAUqNFX/R937CQg +ea31ykcBTQgylM5K8tvXO1lmz++C7/TvUpjbIK/xzkQUikQvNH6EbHn1exUrz5xhzFr XKCgbWuXuucRheWW9e0DwS/+DfpQWJWJCE3o3i0JaofWtk7boubH+7DKpF0ZXGbnQefu 5qfGdseEEMbk87jXwY+ooe5h+DasOUIBQxrcI+fM1+kvr/86R3Lw7NYOJO5ufXjqxB+I 1plGCK/U19kxGcMYuAp8QxNKEukLlTR3TjIJt33H+VcunTdmhtQ0zAlOX+/S8BmYNNI8 aEtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id hk8-20020a17090b224800b00275cffed966si3583599pjb.57.2023.10.19.19.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 19:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 810AD8092DA3; Thu, 19 Oct 2023 19:46:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346873AbjJTCpw (ORCPT + 25 others); Thu, 19 Oct 2023 22:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233397AbjJTCpu (ORCPT ); Thu, 19 Oct 2023 22:45:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EB0F130; Thu, 19 Oct 2023 19:45:44 -0700 (PDT) Received: from dggpemm500012.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SBTQl5mLnzrSbN; Fri, 20 Oct 2023 10:42:55 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpemm500012.china.huawei.com (7.185.36.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 20 Oct 2023 10:45:41 +0800 From: Xingui Yang To: , , , CC: , , , , , , Subject: [PATCH] scsi: libsas: fix set zero-address when device-type != NO_DEVICE Date: Fri, 20 Oct 2023 02:42:40 +0000 Message-ID: <20231020024240.7708-1-yangxingui@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500012.china.huawei.com (7.185.36.89) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 19 Oct 2023 19:46:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780240888797454729 X-GMAIL-MSGID: 1780240888797454729 phy->attached_sas_addr will be set to a zero-address when phy->linkrate < SAS_LINK_RATE_1_5_GBPS but device-type != NO_DEVICE, and it may trigger BUG() as follows when do revalidate with zero-address: [562240.062536] sas: ex 500e004aaaaaaa1f phy0 new device attached [562240.062616] sas: ex 500e004aaaaaaa1f phy00:U:5 attached: 0000000000000000 (stp) [562240.062680] port-7:7:0: trying to add phy phy-7:7:19 fails: it's already part of another port [562240.085064] ------------[ cut here ]------------ [562240.096612] kernel BUG at drivers/scsi/scsi_transport_sas.c:1083! [562240.109611] Internal error: Oops - BUG: 0 [#1] SMP [562240.343518] Process kworker/u256:3 (pid: 435909, stack limit = 0x0000000003bcbebf) [562240.421714] Workqueue: 0000:b4:02.0_disco_q sas_revalidate_domain [libsas] [562240.437173] pstate: 40c00009 (nZcv daif +PAN +UAO) [562240.450478] pc : sas_port_add_phy+0x13c/0x168 [scsi_transport_sas] [562240.465283] lr : sas_port_add_phy+0x13c/0x168 [scsi_transport_sas] [562240.479751] sp : ffff0000300cfa70 [562240.674822] Call trace: [562240.682709] sas_port_add_phy+0x13c/0x168 [scsi_transport_sas] [562240.694013] sas_ex_get_linkrate.isra.5+0xcc/0x128 [libsas] [562240.704957] sas_ex_discover_end_dev+0xfc/0x538 [libsas] [562240.715508] sas_ex_discover_dev+0x3cc/0x4b8 [libsas] [562240.725634] sas_ex_discover_devices+0x9c/0x1a8 [libsas] [562240.735855] sas_ex_revalidate_domain+0x2f0/0x450 [libsas] [562240.746123] sas_revalidate_domain+0x158/0x160 [libsas] [562240.756014] process_one_work+0x1b4/0x448 [562240.764548] worker_thread+0x54/0x468 [562240.772562] kthread+0x134/0x138 [562240.779989] ret_from_fork+0x10/0x18 So set a zero-address for phy->attached_sas_addr only when phy->attached_dev_type == NO_DEVICE. Fixes: 7d1d86518118 ("[SCSI] libsas: fix false positive 'device attached' conditions") Signed-off-by: Xingui Yang --- drivers/scsi/libsas/sas_expander.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index a2204674b680..5a81754d3768 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -239,8 +239,7 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id, /* help some expanders that fail to zero sas_address in the 'no * device' case */ - if (phy->attached_dev_type == SAS_PHY_UNUSED || - phy->linkrate < SAS_LINK_RATE_1_5_GBPS) + if (phy->attached_dev_type == SAS_PHY_UNUSED) memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); else memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE);