Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4125193ioa; Tue, 26 Apr 2022 18:03:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwY56NYrCIFpVzDDWMmfIMqxeDpygQgntXODFtP69D+YM7A+4ssWBMYUchdidbJ2Dej5RNP X-Received: by 2002:a17:906:d54b:b0:6e7:f185:18d5 with SMTP id cr11-20020a170906d54b00b006e7f18518d5mr25374814ejc.155.1651021415235; Tue, 26 Apr 2022 18:03:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651021415; cv=none; d=google.com; s=arc-20160816; b=wrLVUrhNV4M1SyHcn9l472lPz3jOFxnVbMKHyEhtn+Uj2x2dmdJJdOAHdbR7BaEwOB 5jGzD7ORInSgNqUZkyJf9RRHYSZe2WF9GfR+O5jFbsIv9IF2+8stXbBp6Ur0hLvNDTPZ qD3PqSTVoj9Tj5gnQXv1bQHorfMPDuqOeathOiMsojGf5iQrYz7exLhFug1w4PY5YwE8 3GgSkwUbnDQg2VynZWAnRdE1VT2hBjfW9yGrQJwi+pTSujLoDQnTYLgoo+Lyo+BFuVHw 29pJoQRmMXW4NJFnBYmc3brnsviwngXDBZHvwCj/PzizGXulxDy7WbXAyHLEFBtUI0uH PhWA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6KWDB0lXYeStjHZNbFwJnS1fpsmvM2CQ5B7H6Moonjw=; b=ub/Tb2EIj2pdTScKy3ewV1NxD9oDOOI1TM4Fz8Ysmh0dcY+zvQ3PW3I9EG3B8tHPGt neOMNG3IoA9PLewAduCJ6zR5eCbd3QNezuinVrd7rhK5dpq743GtWE+FOTw5MkNEDJHI 9DMYNhnzekbG9WkOUr11IOHv2pzTtZXcnLrLrfkaqrJ7VPfhWRtsUNsZx5pNINhnAJiK 5/nlL4KBfL2UKusshDrEOojJEUKTU5dYhyvr3PoFZTRXUrrx5cWRlBLP/3ypWfEMjhM7 RT8rmimvIQhHJOdnm5nwDKeTdqC14W1y5tT6S+bF8fnOkQ1GW0pocN7gkcffQ2kpzTQD 8GJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eMfAGrIZ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a50d50f000000b00425ed30f8fdsi155959edi.234.2022.04.26.18.03.11; Tue, 26 Apr 2022 18:03: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=@linuxfoundation.org header.s=korg header.b=eMfAGrIZ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241791AbiDZJSc (ORCPT + 99 others); Tue, 26 Apr 2022 05:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345905AbiDZIoR (ORCPT ); Tue, 26 Apr 2022 04:44:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5357815CF5E; Tue, 26 Apr 2022 01:33:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 28A5161899; Tue, 26 Apr 2022 08:33:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3726AC385AC; Tue, 26 Apr 2022 08:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962029; bh=BKmbcASJHd6f1rIBhJ/lD0NYZIRNWXppaDUSuvpXYF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eMfAGrIZpK7Rk2iQ4UENUWj92y3FKV3jt/59bYJgZt2enLv1cSSoljPeedD44Uhry ztie5ppoKz5P23YdX21lETapOB497qiR51oKt1DKLbdfkAh58x+o8A0+pHJq2PbhMP gDpjwgxRpdtMM2GOmmxNjq+TSahzBke4fxeE1zbQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , Sasha Levin Subject: [PATCH 5.10 49/86] nvme: add a quirk to disable namespace identifiers Date: Tue, 26 Apr 2022 10:21:17 +0200 Message-Id: <20220426081742.619192756@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081741.202366502@linuxfoundation.org> References: <20220426081741.202366502@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Christoph Hellwig [ Upstream commit 00ff400e6deee00f7b15e200205b2708b63b8cf6 ] Add a quirk to disable using and exporting namespace identifiers for controllers where they are broken beyond repair. The most directly visible problem with non-unique namespace identifiers is that they break the /dev/disk/by-id/ links, with the link for a supposedly unique identifier now pointing to one of multiple possible namespaces that share the same ID, and a somewhat random selection of which one actually shows up. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Sagi Grimberg Reviewed-by: Chaitanya Kulkarni Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 24 ++++++++++++++++++------ drivers/nvme/host/nvme.h | 5 +++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 853b9a24f744..ad4f1cfbad2e 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1270,6 +1270,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, warn_str, cur->nidl); return -1; } + if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) + return NVME_NIDT_EUI64_LEN; memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN); return NVME_NIDT_EUI64_LEN; case NVME_NIDT_NGUID: @@ -1278,6 +1280,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, warn_str, cur->nidl); return -1; } + if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) + return NVME_NIDT_NGUID_LEN; memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN); return NVME_NIDT_NGUID_LEN; case NVME_NIDT_UUID: @@ -1286,6 +1290,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, warn_str, cur->nidl); return -1; } + if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) + return NVME_NIDT_UUID_LEN; uuid_copy(&ids->uuid, data + sizeof(*cur)); return NVME_NIDT_UUID_LEN; case NVME_NIDT_CSI: @@ -1381,12 +1387,18 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, if ((*id)->ncap == 0) /* namespace not allocated or attached */ goto out_free_id; - if (ctrl->vs >= NVME_VS(1, 1, 0) && - !memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) - memcpy(ids->eui64, (*id)->eui64, sizeof(ids->eui64)); - if (ctrl->vs >= NVME_VS(1, 2, 0) && - !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) - memcpy(ids->nguid, (*id)->nguid, sizeof(ids->nguid)); + + if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { + dev_info(ctrl->device, + "Ignoring bogus Namespace Identifiers\n"); + } else { + if (ctrl->vs >= NVME_VS(1, 1, 0) && + !memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) + memcpy(ids->eui64, (*id)->eui64, sizeof(ids->eui64)); + if (ctrl->vs >= NVME_VS(1, 2, 0) && + !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) + memcpy(ids->nguid, (*id)->nguid, sizeof(ids->nguid)); + } return 0; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 5dd1dd8021ba..10e5ae3a8c0d 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -150,6 +150,11 @@ enum nvme_quirks { * encoding the generation sequence number. */ NVME_QUIRK_SKIP_CID_GEN = (1 << 17), + + /* + * Reports garbage in the namespace identifiers (eui64, nguid, uuid). + */ + NVME_QUIRK_BOGUS_NID = (1 << 18), }; /* -- 2.35.1