Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp886876rwi; Mon, 10 Oct 2022 08:25:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Jb3NLCOApEdM4cpzEcozTHySHXsjRNiLlz8mMstTushbvbaDMhOqYbQZgTuCsW+lXQdNF X-Received: by 2002:a17:907:3fa9:b0:782:ed33:df8d with SMTP id hr41-20020a1709073fa900b00782ed33df8dmr15444813ejc.745.1665415512760; Mon, 10 Oct 2022 08:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665415512; cv=none; d=google.com; s=arc-20160816; b=CJSnM3gw/tjTQqCMG1MG/vk5iV517G7qdNzjTg64BjOvmOBjgSICkgBmMwDNeAnlPJ 3WK2R2FjrL62axHKekerGTgTALD9/wkHAhQmSZsIp+icVONIQAg8VMFC91t1zHPU17aG 8etCfNsagX0sNPyZD/Mf0+G4XF1e+iL1PRH1vQyD8sdz66+HMcY6diZs+zc2PAMzn22j bnU3zJVGE6BV0dGLee8aOelCeLYSD70pzrskpat9yrPTe1k6D9N3DYafkQw6VycDBBZb HZvEn7QQX3Or3d+v44Wmhqgn/A0mA7fAtiyNG2ZRB1K9UOIUeAO/TU03fLofEgorFa9K 9zDw== 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; bh=tJZd3UB6IhHIssxO7zFtx8iIa2A93YDht882wbaSn9M=; b=f7WPBiqqvTHcytpks7zqiL6rR8wDz2Fbi5kJIWhIMKgrkm/tRbEcsYIE5kLOauy8U9 jVhxq2dUIvdfwoJmAHLXX/zBGOxCmmcDSIh9FvVb4IKyg4KIqw3MKlsvANQdyJPqch9J IZjNE6Y26Zj1HpB3y7aRNkF8mO1QpIOa+/9F8rk5byJOnPooIEXr9cue3fiIfcNLysmB JeQBnHlkEQvJQlnk7+TRI5H7CBFb9EnuZPxPrBUzyhavNSVFpcoM561kGSoTZfMqvyvf 8gtbXO0vyXP5BWpOrym2BkevNkc+0QIeNwXNbUAPfOOjhK8dwPwOAc27r5VyHa4ZtZV6 Dgjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UeErqxlV; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz2-20020a1709072ce200b007819684b56fsi10914345ejc.225.2022.10.10.08.24.46; Mon, 10 Oct 2022 08:25: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UeErqxlV; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbiJJOs4 (ORCPT + 99 others); Mon, 10 Oct 2022 10:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbiJJOsw (ORCPT ); Mon, 10 Oct 2022 10:48:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695705F12C for ; Mon, 10 Oct 2022 07:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665413330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tJZd3UB6IhHIssxO7zFtx8iIa2A93YDht882wbaSn9M=; b=UeErqxlV+eAzoHhEWzifdL8eAbepmHsMTg5pPp7m/Zl+yLt8GWUUN9L7/q9WoJk+HKVI3p 92Iu27XH5TTWeWBM9yIw0IRD3KcNW8m/Wk5fmKjV1fcntGYo0wXpfgKPZINU/REDpuHUxE ZZymFZpjV0u9texoFah02Svpemq23A4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-74-eX_a1Le3MxWdSHUyYQIZHA-1; Mon, 10 Oct 2022 10:48:47 -0400 X-MC-Unique: eX_a1Le3MxWdSHUyYQIZHA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0460101245C; Mon, 10 Oct 2022 14:48:46 +0000 (UTC) Received: from cantor.redhat.com (unknown [10.2.16.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB323145F94F; Mon, 10 Oct 2022 14:48:45 +0000 (UTC) From: Jerry Snitselaar To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy Subject: [PATCH v2] iommu/vt-d: Clean up si_domain in the init_dmars() error path Date: Mon, 10 Oct 2022 07:48:42 -0700 Message-Id: <20221010144842.308890-1-jsnitsel@redhat.com> In-Reply-To: <20221010065608.281860-1-jsnitsel@redhat.com> References: <20221010065608.281860-1-jsnitsel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 A splat from kmem_cache_destroy() was seen with a kernel prior to commit ee2653bbe89d ("iommu/vt-d: Remove domain and devinfo mempool") when there was a failure in init_dmars(), because the iommu_domain cache still had objects. While the mempool code is now gone, there still is a leak of the si_domain memory if init_dmars() fails. So clean up si_domain in the init_dmars() error path. Cc: Lu Baolu Cc: Joerg Roedel Cc: Will Deacon Cc: Robin Murphy Fixes: 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()") Signed-off-by: Jerry Snitselaar --- v2: Set si_domain to NULL after the memory it points to has been freed. drivers/iommu/intel/iommu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 31bc50e538a3..ecc0b05b2796 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2400,6 +2400,7 @@ static int __init si_domain_init(int hw) if (md_domain_init(si_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) { domain_exit(si_domain); + si_domain = NULL; return -EFAULT; } @@ -3042,6 +3043,10 @@ static int __init init_dmars(void) disable_dmar_iommu(iommu); free_dmar_iommu(iommu); } + if (si_domain) { + domain_exit(si_domain); + si_domain = NULL; + } return ret; } -- 2.37.2