Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2381589rwn; Fri, 9 Sep 2022 12:48:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR4/U2roY5qub8HABC3i3JKi8YS3KRxf4tD+70jiBPYGJq1Tj+gg2aRoaylfdVUK7Ku+pYO0 X-Received: by 2002:a17:907:2706:b0:77a:4c0e:d37d with SMTP id w6-20020a170907270600b0077a4c0ed37dmr2175625ejk.501.1662752915453; Fri, 09 Sep 2022 12:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662752915; cv=none; d=google.com; s=arc-20160816; b=sELCi7tSEL9Z19jWxQgtlU5onhx/hkU/N3UkpH7IaeLymYQOymj8rXwWbeqR9whRRt LDFeQyGz1eCvzB7ar1FefQhu7j6M2MxGSjiX2a2soGc+KK432xTBQ3RfncILUEQ1QwVA AO6tgyGJW7utUvupNMcSCRpnuPcDcDkoqjw04ZrWPJ+WC827m5sGcBxcwpXgoARwURdt cnV7J86zBMPeSrXMIh5eeCfObRPIqVNO/BxiDf6zHdVH3rD4CyJTCMcgZcQIpLO98cKA wlV57tWH+gUSZYtuoY4l3a+2HJSvRHgYrwv2kYO3+83oXg1Z8c8IwJwnQw9AQjgGB/UF gJLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=g/qnbR3kmCe/hsDgvp6zCp5qkLBtvy6bgBjvx6x6e8w=; b=w2FD6VfhSIBtZhhI0SGBFvMBNeTXFVGsTfyJt5LHa6WjWWAIMt8QkhgxV6wLWxix3r sWYB1e3B9lF+4ER5R9Wf6EI4n3X+xf9b0rpW4hnyFomc6e+MRWA7+xKom6cYyZc3PuvD cUfWFd4F7RTGyKaf1TAdsHnGv/QuiFPiIJcg9yDY68W+67m2UROWRy/e9hRIYQC2eXj7 /NjXd1RQQlK2zi+KbzNB9dcyN10q8reSpdTvkYw2ftM+g708BX2Fn4B31qxoCzU19jxc wHZFVh3ta7EYk9YpAg3rAmYXBAJPqSA10uvJsLsPDAM5hk89A6Cj0F6ELeYPTYe1zeSQ nsZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=YES6vKyJ; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd17-20020a1709076e1100b007720524db1asi1077762ejc.340.2022.09.09.12.48.10; Fri, 09 Sep 2022 12:48:35 -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; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=YES6vKyJ; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbiIITTj (ORCPT + 99 others); Fri, 9 Sep 2022 15:19:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiIITTh (ORCPT ); Fri, 9 Sep 2022 15:19:37 -0400 Received: from mail.baikalelectronics.com (mail.baikalelectronics.com [87.245.175.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB03F12AAF; Fri, 9 Sep 2022 12:19:34 -0700 (PDT) Received: from mail (mail.baikal.int [192.168.51.25]) by mail.baikalelectronics.com (Postfix) with ESMTP id E8885DBA; Fri, 9 Sep 2022 22:23:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.com E8885DBA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1662751391; bh=g/qnbR3kmCe/hsDgvp6zCp5qkLBtvy6bgBjvx6x6e8w=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=YES6vKyJfvMMdrO20kNxAanHBoFyOZ10pFXxE7G1x4aD++ilUms+nwqjVLYPDYEDD 7KE5Frp3PJ6w++pm8zZ0XWDuVTnhPWxcgWSNMuspnYaVeh+L5e5CPxHUDOR5k5Fo88 C90Jhz+tvIVTQlW1sFqCSYEiGhodiDd9T0xPo0M8= Received: from localhost (192.168.168.10) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 9 Sep 2022 22:19:20 +0300 From: Serge Semin To: Jonathan Derrick , Revanth Rajashekar , Jens Axboe , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Guenter Roeck CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Thomas Bogendoerfer , , , Subject: [PATCH 1/2] nvme-hwmon: Cache-line-align the NVME SMART log-buffer Date: Fri, 9 Sep 2022 22:19:15 +0300 Message-ID: <20220909191916.16013-2-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20220909191916.16013-1-Sergey.Semin@baikalelectronics.ru> References: <20220909191916.16013-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 Recent commit 52fde2c07da6 ("nvme: set dma alignment to dword") has caused a regression on our platform. It turned out that the nvme_get_log() method invocation caused the nvme_hwmon_data structure instance corruption. In particular the nvme_hwmon_data.ctrl pointer was overwritten either with zeros or with garbage. After some researches we discovered that the problem happened even before the actual NVME DMA execution, but during the buffer mapping. Since our platform was DMA-noncoherent the mapping implied the cache-lines invalidations or write-backs depending on the DMA-direction parameter. In case of the NVME SMART log getting the DMA was performed from-device-to-memory, thus the cache-invalidation was activated during the buffer mapping. Since the log-buffer wasn't cache-line aligned the cache-invalidation caused the neighbour data discard. The neighbouring data turned to be the data surrounding the buffer in the framework of the nvme_hwmon_data structure. In order to fix that we need to make sure that the whole log-buffer is defined within the cache-line-aligned memory region so the cache-invalidation procedure wouldn't involve the adjacent data. By doing so we not only get rid from the denoted problem but also fulfill the requirement explicitly described in [1]. After a deeper researches we found out that the denoted commit wasn't a root cause of the problem. It just revealed the invalidity by activating the DMA-based NVME SMART log getting performed in the framework of the NVME hwmon driver. The problem was here since the initial commit of the driver. [1] Documentation/core-api/dma-api.rst Fixes: 400b6a7b13a3 ("nvme: Add hardware monitoring support") Signed-off-by: Serge Semin --- Folks, I've thoroughly studied the whole NVME subsystem looking for similar problems. Turned out there is one more place which may cause the same issue. It's connected with the opal_dev.{cmd,req} buffers passed to the nvme_sec_submit() method. The rest of the buffers involved in the NVME DMA are either allocated by kmalloc (must be cache-line-aligned by design) or bounced-buffered if allocated on the stack (see the blk_rq_map_kern() method implementation). --- drivers/nvme/host/hwmon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c index 0a586d712920..94192ab7a02d 100644 --- a/drivers/nvme/host/hwmon.c +++ b/drivers/nvme/host/hwmon.c @@ -10,9 +10,10 @@ #include "nvme.h" +/* DMA-noncoherent platforms require the cache-aligned buffers */ struct nvme_hwmon_data { + struct nvme_smart_log log ____cacheline_aligned; struct nvme_ctrl *ctrl; - struct nvme_smart_log log; struct mutex read_lock; }; -- 2.37.2