Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp599160pxb; Tue, 5 Apr 2022 15:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9fBQT6gJY8/atm/4sMDXT8WN2Ngi8Z7WMepVbNeUtTBGBG6HVlhO3CzNIbnpvHALOLBzj X-Received: by 2002:a63:d64b:0:b0:382:6aff:3e43 with SMTP id d11-20020a63d64b000000b003826aff3e43mr4624236pgj.438.1649197725043; Tue, 05 Apr 2022 15:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649197725; cv=none; d=google.com; s=arc-20160816; b=kiVojsSCUl4MWH88A9EnUrtGAoXduCYvav2UDsrFubLrQFI5/GKiiE2SloJpMbvuKC eWUN7/fbnvJk+kjAMKd2nqBe85TThyDeSBfRjZeQJ0XBeTZu4Bg2FwlvG1kJUOW8HBx8 TD8w9ScMrj4eIUD5JpeZwpY0wAaW7fifGEWXWaKMMkOjhzVahkoJ9ss8OQMoZyhNQutI 7GNycRy18aLao2tWOcwoLzDIAiERCV9lxDKTRRq2Ad7zWLgLyz9dVpYxG46uZkDTHsy1 m0AaFPA37Er0z2US4i0RreuOxui/Dz+JprehPPfw7701hjKRZ1n/esSBpIkosk957gYK zIwA== 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=GJ7dI3Wf+4DwQCVU9VTIImcviQYir/ZrIxp2tftt690=; b=MI4Z3nSyT8faWWIMWD/qrtjSMRKd4iUfg+ghnLMhsZREhe80hBmsscBdMUZU4Jnysh ImNxjGviDQ5FzsZ3O3E/i1mGhkC3SS6EcX9fxFhZK9FOLuWAebTDSk98IMP8AUt/2oUD CyGPbMTdrP95Nzhc6WjJFbqP9XST0cBI0Dz75zI+CW2+Vrjo4d+sI6FxZzHXZjf9oRLG 2L3oWKMlF6HdMHNfNtcFt/Hr7bDQRisUTPSA+MIU1n194ALMp8e/a2zmumi1t7Toe+Og odaVVWG/AIS7zMsM/qG8Eak3E+br/CsO9QOGJ/Z9ImM5X/q+Toxfi2yt3OjfonhA9MBP ruiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QHtJr9nP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q2-20020a63e942000000b003816043ef39si13966261pgj.302.2022.04.05.15.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:28:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QHtJr9nP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B24B31FE268; Tue, 5 Apr 2022 15:10:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380041AbiDEO7y (ORCPT + 99 others); Tue, 5 Apr 2022 10:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344809AbiDEJmq (ORCPT ); Tue, 5 Apr 2022 05:42:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B625BF03E; Tue, 5 Apr 2022 02:28:08 -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 ams.source.kernel.org (Postfix) with ESMTPS id 381D8B81C84; Tue, 5 Apr 2022 09:28:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4509C385A0; Tue, 5 Apr 2022 09:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150886; bh=TamW6Xsci8vfjCNSf+pGM21D24uxs4X8EZtl3LmgROo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QHtJr9nP1GN6ts3P2qlxV0CVjrB0j2GzmpGxWo0Tq5SQItlzjWTRBqiP+bLE38tGA mSAaFomPo+jxH9+rGBxRQ446FBplG4GgmStlEYms52ohutyG0wuEoRuI1TMUfxxe8G HU428rDmmKsKJB1hOfRSBEnkMxqYWK7T7Ewn129s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni , Sasha Levin Subject: [PATCH 5.15 217/913] nvme: fix the check for duplicate unique identifiers Date: Tue, 5 Apr 2022 09:21:19 +0200 Message-Id: <20220405070346.362888752@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 e2724cb9f0c406b8fb66efd3aa9e8b3edfd8d5c8 ] nvme_subsys_check_duplicate_ids should needs to return an error if any of the identifiers matches, not just if all of them match. But it does not need to and should not look at the CSI value for this sanity check. Rewrite the logic to be separate from nvme_ns_ids_equal and optimize it by reducing duplicate checks for non-present identifiers. Fixes: ed754e5deeb1 ("nvme: track shared namespaces") Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Chaitanya Kulkarni Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e06d6026e7fa..b349e19e745b 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1674,13 +1674,6 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); } -static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids) -{ - return !uuid_is_null(&ids->uuid) || - memchr_inv(ids->nguid, 0, sizeof(ids->nguid)) || - memchr_inv(ids->eui64, 0, sizeof(ids->eui64)); -} - static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) { return uuid_equal(&a->uuid, &b->uuid) && @@ -3537,12 +3530,21 @@ static struct nvme_ns_head *nvme_find_ns_head(struct nvme_subsystem *subsys, static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys, struct nvme_ns_ids *ids) { + bool has_uuid = !uuid_is_null(&ids->uuid); + bool has_nguid = memchr_inv(ids->nguid, 0, sizeof(ids->nguid)); + bool has_eui64 = memchr_inv(ids->eui64, 0, sizeof(ids->eui64)); struct nvme_ns_head *h; lockdep_assert_held(&subsys->lock); list_for_each_entry(h, &subsys->nsheads, entry) { - if (nvme_ns_ids_valid(ids) && nvme_ns_ids_equal(ids, &h->ids)) + if (has_uuid && uuid_equal(&ids->uuid, &h->ids.uuid)) + return -EINVAL; + if (has_nguid && + memcmp(&ids->nguid, &h->ids.nguid, sizeof(ids->nguid)) == 0) + return -EINVAL; + if (has_eui64 && + memcmp(&ids->eui64, &h->ids.eui64, sizeof(ids->eui64)) == 0) return -EINVAL; } -- 2.34.1