Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3838265iob; Tue, 17 May 2022 08:13:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFdUvouXoAb6wNmfnDBersT+JZVlIumdxoeSSAVSWwzpwD/8PYoot+61cC4oLWj6Y/AWuC X-Received: by 2002:a05:6402:90c:b0:415:d340:4ae2 with SMTP id g12-20020a056402090c00b00415d3404ae2mr19392432edz.331.1652800392731; Tue, 17 May 2022 08:13:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652800392; cv=none; d=google.com; s=arc-20160816; b=t7sONlNsa/Bk48uz5vx2YudQJiRATEHGJaX5lwGjtWGa8sJG1D0jUB/4g79moQPPM1 mbnbv+HQX8XnRib0LGzOyzTWjFdvezaPrVXnVhU1tiuwfmn2nAkBoT5CNGdJlEQ6aQYq By15fXmt+U4lcqTgknQkEMWdA0jVUCnQt2oy5XiGcX/Fri/re10pTJPACM9KNHx2rgJL VPvbUqlqts96cCvqmYh7dVhQXQruyVjYzlHm7BZWfAeMsW6AQYqOEkGPZRhJ+WcmXC4R EXwB1l3u6DfEqXs9zXOzjiHFsBtoqJwARqUTtnK0fq7GOrnTAczoUkKkiapnMNXVU27R rADw== 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=CAahiFSy4rTOekhZjCHE7pAMoalyzAwbtWkzogrFEpw=; b=WY75the8NCIFg6zRBlEd+7uXlDy2s8Bu0pNjv3JbHL7LzIKeUZT3DVJJ6OQwUQjdSC 2tzqmsGquuwCyoVbzdJn97qZIkTi8kWnhCE+rG/KK9XmArs7TuySE3qs7Pdv2wa+4eNi Tky+H+3t6VcbvBdMWqD7Cfru5cK+c2hxmu2iKWeu5H7X6qonH4eZsjatRnVJAyB96V8N fuZ6ciqi8j5lpKhfWCG9rWSz8nfWc2/Gii7Q9wujYNaDvuIcExceAikgRra0H6sHBrcw DaQbyUyCx8VqnKdEqt7+Og+ZN8XvJ+IP2gEEh9D8L/eLULCuUDR+6P0qN/NQJcPMhgUv aODQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a056402125000b00425ec219fe2si1180469edw.264.2022.05.17.08.12.46; Tue, 17 May 2022 08:13:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234012AbiEQIKn (ORCPT + 99 others); Tue, 17 May 2022 04:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239899AbiEQIKi (ORCPT ); Tue, 17 May 2022 04:10:38 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D24643C73E; Tue, 17 May 2022 01:10:37 -0700 (PDT) Received: from fraeml707-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4L2THp2D8xz6H8FG; Tue, 17 May 2022 16:07:34 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml707-chm.china.huawei.com (10.206.15.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 17 May 2022 10:10:35 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 17 May 2022 09:10:27 +0100 From: John Garry To: , CC: , , , John Garry Subject: [PATCH] scsi: hisi_sas: Fix memory ordering in hisi_sas_task_deliver() Date: Tue, 17 May 2022 16:04:21 +0800 Message-ID: <1652774661-12935-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The memories for the slot should be observed to be written prior to observing the slot as ready. Prior to commit 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR"), we had a spin_lock() + spin_unlock() immediately before marking the slot as ready. The spin_unlock() - with release semantics - caused the slot memory to be observed to be written. Now that the spin_lock() + spin_unlock() is gone, use a smp_wmb(). Fixes: 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR") Reported-by: Yihang Li Tested-by: Yihang Li Signed-off-by: John Garry --- Hi Martin, Please consider for v5.18, thanks! diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 4bda2f6cb352..f56dd01230ce 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -446,6 +446,8 @@ void hisi_sas_task_deliver(struct hisi_hba *hisi_hba, return; } + /* Make slot memories observable before marking as ready */ + smp_wmb(); WRITE_ONCE(slot->ready, 1); spin_lock(&dq->lock); -- 2.26.2