From patchwork Wed Oct 19 00:44:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 4390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp60846wrs; Tue, 18 Oct 2022 17:56:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CvqD/RAI58cuZ7pGjxWYj8qWdBdLHqsANdWVplXhvS2MBOI7sZRiF/E8daMS35YwNMKME X-Received: by 2002:a17:906:dac3:b0:780:a242:2f14 with SMTP id xi3-20020a170906dac300b00780a2422f14mr4440911ejb.668.1666141004707; Tue, 18 Oct 2022 17:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666141004; cv=none; d=google.com; s=arc-20160816; b=EFS6+1ZmOq0kOKXZaXTGyEi4Cw8GY/5+tHeTJdRiecJGOX3rhRnh5byWu9WqbcTnNn Cfay2JtV9n4N5oPRXyD6JdtLuxBTQ2PjDGxysEguch1bxNCBebdOZsdgYKh3kj5UOP92 qwXw3jW9p9xawu8ucr1VXHl4wnXn5mZZrrGjihvNi5/PFWnbnZUqTkDw4n3b4JIOlCUn NbWQzbd+gXAXrilRBBdziN9IOaCoYj6m9qinMKpZ9yid3N2BiAyU3huHTTs8xC3+cXYv Iea/E+f/wZX61M/hkfFc+FPnCPkmEFmT7rqCaJXkDZkiAwhCZo16edoshzGPaYiBy+xV Sdgg== 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=lP6CrHXRPAu3bPYfYEaTCEeNE3duRhsmVvEFSsEeddk=; b=OO8RXR0fcgw5W5iDi03nyqJqIiUrLGWgL+s/y8qKpZR/R9NKBp3luyXcIlVP+vKlV+ B2y2BKFiDIJc61cL0WARet5DMeZDfSmAs3qrwxbb2Rdo6xWYmiMduOuQaLABpHwWCDso /PBYuBGkMNsSVMfIcngJSOI2Lkeha4HV5PWobA0BRC5wLC0Ryz1Qr595l6P5ZfKZoT6B DCuQlRZ7LbP7SyIthVBO58ilV7pOdcqZ1BfziIFOEa291+HDGIlKaUapL6gwq326NdOz BI2Ak3vZe6xnHclOdM+nVAl/32+O/9SmClwYOgxGIhGqj4X2Y5UEHX0jDzwYfIHKGqw3 vbBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XpcBbEzO; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x18-20020a05640226d200b0045cc9072f14si15923943edd.8.2022.10.18.17.56.20; Tue, 18 Oct 2022 17:56:44 -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=@intel.com header.s=Intel header.b=XpcBbEzO; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbiJSAvU (ORCPT + 99 others); Tue, 18 Oct 2022 20:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbiJSAvS (ORCPT ); Tue, 18 Oct 2022 20:51:18 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D21AE85E for ; Tue, 18 Oct 2022 17:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666140677; x=1697676677; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O8SgalDcLyJd4IbAX0q7EC2IARrdcdPwcMMNK5wsxVo=; b=XpcBbEzO5P9azqdvltzWIjDBq7vICw9VnXT77srHFjIgU1g0mB9LGGcw lwVdpiDBrJARfGkn08kUSOcXsgeIbMYlAeKNXmABdsunLtYyBorNbHYP3 9S4x8AsgqwJ0ndbB9FdrIh1gQJho1rtoRLs6yfdW31mYpTETzktUuGL+P q031MCPIb1RfDDUIopEbVQG7+7Rbugn2jU5F20ghvtA8lUl4ckGKQH9uG p933onAyjNN5T+yxOg4+304yvXi1IFiFZ/QZfn40gy8pdh8kxN/xiYQxu kmtpgALRctC5Ku3EtAe4b173y5f3DUVVL2PtlVJ3QapWc4/RQFSudAs2k A==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="289591509" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="289591509" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 17:51:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="606824801" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="606824801" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga006.jf.intel.com with ESMTP; 18 Oct 2022 17:51:15 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jerry Snitselaar , Charlotte Tan , Alex Williamson , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] iommu: Add gfp parameter to iommu_alloc_resv_region Date: Wed, 19 Oct 2022 08:44:44 +0800 Message-Id: <20221019004447.4563-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019004447.4563-1-baolu.lu@linux.intel.com> References: <20221019004447.4563-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747075470007592983?= X-GMAIL-MSGID: =?utf-8?q?1747075470007592983?= Add gfp parameter to iommu_alloc_resv_region() for the callers to specify the memory allocation behavior. Thus iommu_alloc_resv_region() could also be available in critical contexts. Signed-off-by: Lu Baolu Tested-by: Alex Williamson Link: https://lore.kernel.org/r/20220927053109.4053662-2-baolu.lu@linux.intel.com --- include/linux/iommu.h | 2 +- drivers/acpi/arm64/iort.c | 3 ++- drivers/iommu/amd/iommu.c | 7 ++++--- drivers/iommu/apple-dart.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +- drivers/iommu/intel/iommu.c | 8 +++++--- drivers/iommu/iommu.c | 7 ++++--- drivers/iommu/mtk_iommu.c | 3 ++- drivers/iommu/virtio-iommu.c | 9 ++++++--- 10 files changed, 27 insertions(+), 18 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a325532aeab5..3c9da1f8979e 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -455,7 +455,7 @@ extern void iommu_set_default_translated(bool cmd_line); extern bool iommu_default_passthrough(void); extern struct iommu_resv_region * iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot, - enum iommu_resv_type type); + enum iommu_resv_type type, gfp_t gfp); extern int iommu_get_group_resv_regions(struct iommu_group *group, struct list_head *head); diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index ca2aed86b540..8059baf4ef27 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1142,7 +1142,8 @@ static void iort_iommu_msi_get_resv_regions(struct device *dev, struct iommu_resv_region *region; region = iommu_alloc_resv_region(base + SZ_64K, SZ_64K, - prot, IOMMU_RESV_MSI); + prot, IOMMU_RESV_MSI, + GFP_KERNEL); if (region) list_add_tail(®ion->list, head); } diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 65856e401949..d3b39d0416fa 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2330,7 +2330,8 @@ static void amd_iommu_get_resv_regions(struct device *dev, type = IOMMU_RESV_RESERVED; region = iommu_alloc_resv_region(entry->address_start, - length, prot, type); + length, prot, type, + GFP_KERNEL); if (!region) { dev_err(dev, "Out of memory allocating dm-regions\n"); return; @@ -2340,14 +2341,14 @@ static void amd_iommu_get_resv_regions(struct device *dev, region = iommu_alloc_resv_region(MSI_RANGE_START, MSI_RANGE_END - MSI_RANGE_START + 1, - 0, IOMMU_RESV_MSI); + 0, IOMMU_RESV_MSI, GFP_KERNEL); if (!region) return; list_add_tail(®ion->list, head); region = iommu_alloc_resv_region(HT_RANGE_START, HT_RANGE_END - HT_RANGE_START + 1, - 0, IOMMU_RESV_RESERVED); + 0, IOMMU_RESV_RESERVED, GFP_KERNEL); if (!region) return; list_add_tail(®ion->list, head); diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 4526575b999e..4f4a323be0d0 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -758,7 +758,7 @@ static void apple_dart_get_resv_regions(struct device *dev, region = iommu_alloc_resv_region(DOORBELL_ADDR, PAGE_SIZE, prot, - IOMMU_RESV_MSI); + IOMMU_RESV_MSI, GFP_KERNEL); if (!region) return; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index ba47c73f5b8c..6d5df91c5c46 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2757,7 +2757,7 @@ static void arm_smmu_get_resv_regions(struct device *dev, int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH, - prot, IOMMU_RESV_SW_MSI); + prot, IOMMU_RESV_SW_MSI, GFP_KERNEL); if (!region) return; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 6c1114a4d6cc..30dab1418e3f 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1534,7 +1534,7 @@ static void arm_smmu_get_resv_regions(struct device *dev, int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH, - prot, IOMMU_RESV_SW_MSI); + prot, IOMMU_RESV_SW_MSI, GFP_KERNEL); if (!region) return; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a8b36c3fddf1..d5965b4f8b60 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4552,7 +4552,8 @@ static void intel_iommu_get_resv_regions(struct device *device, IOMMU_RESV_DIRECT_RELAXABLE : IOMMU_RESV_DIRECT; resv = iommu_alloc_resv_region(rmrr->base_address, - length, prot, type); + length, prot, type, + GFP_KERNEL); if (!resv) break; @@ -4567,7 +4568,8 @@ static void intel_iommu_get_resv_regions(struct device *device, if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) { reg = iommu_alloc_resv_region(0, 1UL << 24, prot, - IOMMU_RESV_DIRECT_RELAXABLE); + IOMMU_RESV_DIRECT_RELAXABLE, + GFP_KERNEL); if (reg) list_add_tail(®->list, head); } @@ -4576,7 +4578,7 @@ static void intel_iommu_get_resv_regions(struct device *device, reg = iommu_alloc_resv_region(IOAPIC_RANGE_START, IOAPIC_RANGE_END - IOAPIC_RANGE_START + 1, - 0, IOMMU_RESV_MSI); + 0, IOMMU_RESV_MSI, GFP_KERNEL); if (!reg) return; list_add_tail(®->list, head); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4893c2429ca5..65a3b3d886dc 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -504,7 +504,7 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new, LIST_HEAD(stack); nr = iommu_alloc_resv_region(new->start, new->length, - new->prot, new->type); + new->prot, new->type, GFP_KERNEL); if (!nr) return -ENOMEM; @@ -2579,11 +2579,12 @@ EXPORT_SYMBOL(iommu_put_resv_regions); struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot, - enum iommu_resv_type type) + enum iommu_resv_type type, + gfp_t gfp) { struct iommu_resv_region *region; - region = kzalloc(sizeof(*region), GFP_KERNEL); + region = kzalloc(sizeof(*region), gfp); if (!region) return NULL; diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 5a4e00e4bbbc..2ab2ecfe01f8 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -917,7 +917,8 @@ static void mtk_iommu_get_resv_regions(struct device *dev, continue; region = iommu_alloc_resv_region(resv->iova_base, resv->size, - prot, IOMMU_RESV_RESERVED); + prot, IOMMU_RESV_RESERVED, + GFP_KERNEL); if (!region) return; diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index b7c22802f57c..8b1b5c270e50 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -490,11 +490,13 @@ static int viommu_add_resv_mem(struct viommu_endpoint *vdev, fallthrough; case VIRTIO_IOMMU_RESV_MEM_T_RESERVED: region = iommu_alloc_resv_region(start, size, 0, - IOMMU_RESV_RESERVED); + IOMMU_RESV_RESERVED, + GFP_KERNEL); break; case VIRTIO_IOMMU_RESV_MEM_T_MSI: region = iommu_alloc_resv_region(start, size, prot, - IOMMU_RESV_MSI); + IOMMU_RESV_MSI, + GFP_KERNEL); break; } if (!region) @@ -909,7 +911,8 @@ static void viommu_get_resv_regions(struct device *dev, struct list_head *head) */ if (!msi) { msi = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH, - prot, IOMMU_RESV_SW_MSI); + prot, IOMMU_RESV_SW_MSI, + GFP_KERNEL); if (!msi) return; From patchwork Wed Oct 19 00:44:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 4392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp60868wrs; Tue, 18 Oct 2022 17:56:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nrKxOa1SPD5EtBRdLb6nJ/sNBgukslgnFxaCOOaFvj7/CjlrNr2TFbNyvlsPQHe0AhGKZ X-Received: by 2002:a17:907:7203:b0:78d:b8ba:c1a4 with SMTP id dr3-20020a170907720300b0078db8bac1a4mr4564042ejc.60.1666141008172; Tue, 18 Oct 2022 17:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666141008; cv=none; d=google.com; s=arc-20160816; b=XpstX09o4G8KWquamNGpII/oUtoKut4Qb/9laOXAuWsoLjPZrItTSZ91aQsOjTe5rc XkHnt/rhaWO0MoL9LOWua3PtZZdQH5y2MRJaiCr1hLaGgsWY2AmZ4YS4l8xMGT4hG7dj QF0sIpBr0bCnd2TLzNVI5A8g2S4kCzmgOY0Mdj0phh7LF7dIwPpsSZ+mwkSLNPBaBmod 9GB8nWs5D4xKFpywYUp0AoSVXC79nsLDgemqJnIS2GBF7lBW0iP17ueIEDIdTyP/RaPC GZxBzg9UFaL4+oao10Hy2S5SHBbuS02EXOwkopVkhn+9tEANjaN/93ASDtBXuYKZm+ZX tLjw== 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=95+7d03pNDBUWcOM9spOhfvKEXHbr5VTU3Y+R5uAJhg=; b=FeEpbSZYkXkUhNYdPiU/438jObWlU0vS9dRZiUGrfv/rgr82+mDLtRMjqV8BdwLaIQ nVpMCXQjP+MNX4K1MXO38QWr+TROy3mqsP6N9IcBdFQ0hCCMRgepmaT4bsoYuZHcdFUk cfXXysUW4X0hvjLfiCi9oTZP97ufDTUAzflOegMPn3YyzosaSXCW/ppmLpk/l3JH57Ad lKd9r933BXFjRb2zyM3aRm1fOlR/fAy1po8dS5psl0lxktGet6Oo12O0GVBNh5NxC1rQ wktkgRztDOW85xmYOfJlDJxJebvND+CwR59lQT6B0PUCvmOvGJ4iPljdH7MkKNfsSxNo sjdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RCqiQj7l; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a05640204ca00b00458d5d907c6si11490269edw.514.2022.10.18.17.56.23; Tue, 18 Oct 2022 17:56:48 -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=@intel.com header.s=Intel header.b=RCqiQj7l; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbiJSAv1 (ORCPT + 99 others); Tue, 18 Oct 2022 20:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiJSAvU (ORCPT ); Tue, 18 Oct 2022 20:51:20 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23CF4B03F7 for ; Tue, 18 Oct 2022 17:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666140679; x=1697676679; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3zwXomiEc0/Qr/lnU6GyoSXL6F5EdLCqksR4gooDUl0=; b=RCqiQj7lq4TlWFhUlaGAi79oapea7DoZN2NovOK4UJ49gYZDx4iDZ1L2 5mrGCyxL0LXR4GLSo2Uq9KWSiyh6YxI6XnMljWw+GmSE8lvEAVueBYWS5 1dslA0nWZFUCJLqKeH64JnxkOzjPuG8aAAPcUEOeoyV1TXEI36Zfi36xH jr7Qro7crVROp30OAgEgkqkJ+3/y59dwWDqTCfCzj3bzifl2agnHh6brL OJqXhjQoEXbTPROy8wR/RpvuNws2+ZMdvl0kN4eoa2oIfHH7DA327g2Sr dp4T53/l8nbqcujyYFirofGUG47DDRrXdJFktLT0TneQfRVsdbyR1GkJg A==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="289591515" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="289591515" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 17:51:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="606824807" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="606824807" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga006.jf.intel.com with ESMTP; 18 Oct 2022 17:51:17 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jerry Snitselaar , Charlotte Tan , Alex Williamson , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] iommu/vt-d: Use rcu_lock in get_resv_regions Date: Wed, 19 Oct 2022 08:44:45 +0800 Message-Id: <20221019004447.4563-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019004447.4563-1-baolu.lu@linux.intel.com> References: <20221019004447.4563-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747075473765192451?= X-GMAIL-MSGID: =?utf-8?q?1747075473765192451?= Commit 5f64ce5411b46 ("iommu/vt-d: Duplicate iommu_resv_region objects per device list") converted rcu_lock in get_resv_regions to dmar_global_lock to allow sleeping in iommu_alloc_resv_region(). This introduced possible recursive locking if get_resv_regions is called from within a section where intel_iommu_init() already holds dmar_global_lock. Especially, after commit 57365a04c921 ("iommu: Move bus setup to IOMMU device registration"), below lockdep splats could always be seen. ============================================ WARNING: possible recursive locking detected 6.0.0-rc4+ #325 Tainted: G I -------------------------------------------- swapper/0/1 is trying to acquire lock: ffffffffa8a18c90 (dmar_global_lock){++++}-{3:3}, at: intel_iommu_get_resv_regions+0x25/0x270 but task is already holding lock: ffffffffa8a18c90 (dmar_global_lock){++++}-{3:3}, at: intel_iommu_init+0x36d/0x6ea ... Call Trace: dump_stack_lvl+0x48/0x5f __lock_acquire.cold.73+0xad/0x2bb lock_acquire+0xc2/0x2e0 ? intel_iommu_get_resv_regions+0x25/0x270 ? lock_is_held_type+0x9d/0x110 down_read+0x42/0x150 ? intel_iommu_get_resv_regions+0x25/0x270 intel_iommu_get_resv_regions+0x25/0x270 iommu_create_device_direct_mappings.isra.28+0x8d/0x1c0 ? iommu_get_dma_cookie+0x6d/0x90 bus_iommu_probe+0x19f/0x2e0 iommu_device_register+0xd4/0x130 intel_iommu_init+0x3e1/0x6ea ? iommu_setup+0x289/0x289 ? rdinit_setup+0x34/0x34 pci_iommu_init+0x12/0x3a do_one_initcall+0x65/0x320 ? rdinit_setup+0x34/0x34 ? rcu_read_lock_sched_held+0x5a/0x80 kernel_init_freeable+0x28a/0x2f3 ? rest_init+0x1b0/0x1b0 kernel_init+0x1a/0x130 ret_from_fork+0x1f/0x30 This rolls back dmar_global_lock to rcu_lock in get_resv_regions to avoid the lockdep splat. Fixes: 57365a04c921 ("iommu: Move bus setup to IOMMU device registration") Signed-off-by: Lu Baolu Tested-by: Alex Williamson Link: https://lore.kernel.org/r/20220927053109.4053662-3-baolu.lu@linux.intel.com --- drivers/iommu/intel/iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index d5965b4f8b60..b3cf0f991e29 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4534,7 +4534,7 @@ static void intel_iommu_get_resv_regions(struct device *device, struct device *i_dev; int i; - down_read(&dmar_global_lock); + rcu_read_lock(); for_each_rmrr_units(rmrr) { for_each_active_dev_scope(rmrr->devices, rmrr->devices_cnt, i, i_dev) { @@ -4553,14 +4553,14 @@ static void intel_iommu_get_resv_regions(struct device *device, resv = iommu_alloc_resv_region(rmrr->base_address, length, prot, type, - GFP_KERNEL); + GFP_ATOMIC); if (!resv) break; list_add_tail(&resv->list, head); } } - up_read(&dmar_global_lock); + rcu_read_unlock(); #ifdef CONFIG_INTEL_IOMMU_FLOPPY_WA if (dev_is_pci(device)) { From patchwork Wed Oct 19 00:44:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 4393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp60882wrs; Tue, 18 Oct 2022 17:56:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63yA1K2DPKAmtW/1NkVXjZYiVPCAdY1/bekZnJnEnqvW7szEcocDftSIVZHiqEPnpnry0W X-Received: by 2002:a17:907:2bdb:b0:78d:cf5a:210e with SMTP id gv27-20020a1709072bdb00b0078dcf5a210emr4538362ejc.747.1666141010900; Tue, 18 Oct 2022 17:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666141010; cv=none; d=google.com; s=arc-20160816; b=u7djInCWguGzBC1BE8JfVBazOVxMWP7Nbj5Uz11yTPKVvDXs/ev6jqSJIz55OkWEcg hN9NIwRCVowm5RO4UsYTLg0cdbYtHhXgWXbzCYlyozTJRSTUX1vOTg3igbW1DFuRfAJs f71kCbizdGiGQ4fxy44VYEOpr4TJiW1bbqvCrVJYtnzdBXPrXW9XE6JFqd61Z0W59blu 6RjT0vSk9wpLQnpAF9VaM39FtpZMaaCm1hbUXCNGiPAQ7Xbbzfh92oVpgV92Vu9NCR12 bAoCKbgJNEQQdRPdm3lKfZntV3LdmhJrbFvdDu6nbk7WTGWvWLcHZw0dI5/sGACFw6Sx BpSQ== 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=BflbgMiJU/DLGfSAt/mGwWoPEUPCDEBqGJzxRNf6EDE=; b=le0gTdJH8pw/BffvPiVXw1I1XW/Wzfscev0q8Vb1B5cT1OnwEsY3oseZ6yI3mvUgCA YqhDKOKwFsCJ10AaYn/rtV14IodQba4xfywYXMjxy0C1049g5SpBKNRD2D/XVwNI8MOt dCgDkWFy+th/nzXUCdYwyAwVR1HTb+bgeB9SYbVwlX7j9GEkUasPOPb++5MEZuLuhjv5 cBh30+K0eXKj461X2snFzNewk26AYo+/t7LeWn8XHaRF7SucMBfZGh8vb8/Hatqbholo cw2v+7D02qw61jp/QgRNefD7GZGV1+sdH8I12L7OHHC4NYms8vN+4S2JL7F4IDalXme1 JVOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bznA4vOE; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga13-20020a1709070c0d00b0078db1343eedsi13448943ejc.774.2022.10.18.17.56.26; Tue, 18 Oct 2022 17:56:50 -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=@intel.com header.s=Intel header.b=bznA4vOE; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbiJSAv3 (ORCPT + 99 others); Tue, 18 Oct 2022 20:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbiJSAvV (ORCPT ); Tue, 18 Oct 2022 20:51:21 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18944B1DE9 for ; Tue, 18 Oct 2022 17:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666140681; x=1697676681; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Al/7LZbe8QdirMOyPmBDmhB4puBPIgFgDynAt3svbtY=; b=bznA4vOECfcVEZotwI5Z4GfN6iYOubT6uCV4c+z6b6Ol6iRWXWqEbfK7 kpetQ3yCjjMVtB8ENJds4iPtp9VMNP1sx1+aZ+E/e0os5i/tbJFdhyhUC /lm6EfUpeeTu507vUAyJstosiyJXCaNs1eUBXaC/lD6L3NzCBtpkaoGl9 DpKiFFfulfPcStyM9tVTboEUmfgCV0O1cZ6uaH+v4BBLdKrt2ejNi6Xxk bOwjjh/yo3UCl4OJ1v7fVqSXAMCPz8K0396OEaa3rmb8DndT5UF69kS0g vKlV7nz3EbqACdKpiiTdU1FaW8GKszTrjcMeVZrAVvBvxqnn/A7t+cIUH A==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="289591520" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="289591520" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 17:51:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="606824817" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="606824817" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga006.jf.intel.com with ESMTP; 18 Oct 2022 17:51:19 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jerry Snitselaar , Charlotte Tan , Alex Williamson , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] iommu/vt-d: Allow NVS regions in arch_rmrr_sanity_check() Date: Wed, 19 Oct 2022 08:44:46 +0800 Message-Id: <20221019004447.4563-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019004447.4563-1-baolu.lu@linux.intel.com> References: <20221019004447.4563-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747075476360472054?= X-GMAIL-MSGID: =?utf-8?q?1747075476360472054?= From: Charlotte Tan arch_rmrr_sanity_check() warns if the RMRR is not covered by an ACPI Reserved region, but it seems like it should accept an NVS region as well. The ACPI spec https://uefi.org/specs/ACPI/6.5/15_System_Address_Map_Interfaces.html uses similar wording for "Reserved" and "NVS" region types; for NVS regions it says "This range of addresses is in use or reserved by the system and must not be used by the operating system." There is an old comment on this mailing list that also suggests NVS regions should pass the arch_rmrr_sanity_check() test: The warnings come from arch_rmrr_sanity_check() since it checks whether the region is E820_TYPE_RESERVED. However, if the purpose of the check is to detect RMRR has regions that may be used by OS as free memory, isn't E820_TYPE_NVS safe, too? This patch overlaps with another proposed patch that would add the region type to the log since sometimes the bug reporter sees this log on the console but doesn't know to include the kernel log: https://lore.kernel.org/lkml/20220611204859.234975-3-atomlin@redhat.com/ Here's an example of the "Firmware Bug" apparent false positive (wrapped for line length): DMAR: [Firmware Bug]: No firmware reserved region can cover this RMRR [0x000000006f760000-0x000000006f762fff], contact BIOS vendor for fixes DMAR: [Firmware Bug]: Your BIOS is broken; bad RMRR [0x000000006f760000-0x000000006f762fff] This is the snippet from the e820 table: BIOS-e820: [mem 0x0000000068bff000-0x000000006ebfefff] reserved BIOS-e820: [mem 0x000000006ebff000-0x000000006f9fefff] ACPI NVS BIOS-e820: [mem 0x000000006f9ff000-0x000000006fffefff] ACPI data Fixes: f036c7fa0ab6 ("iommu/vt-d: Check VT-d RMRR region in BIOS is reported as reserved") Cc: Will Mortensen Link: https://lore.kernel.org/linux-iommu/64a5843d-850d-e58c-4fc2-0a0eeeb656dc@nec.com/ Link: https://bugzilla.kernel.org/show_bug.cgi?id=216443 Signed-off-by: Charlotte Tan Reviewed-by: Aaron Tomlin Link: https://lore.kernel.org/r/20220929044449.32515-1-charlotte@extrahop.com Signed-off-by: Lu Baolu --- arch/x86/include/asm/iommu.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h index 0bef44d30a27..2fd52b65deac 100644 --- a/arch/x86/include/asm/iommu.h +++ b/arch/x86/include/asm/iommu.h @@ -25,8 +25,10 @@ arch_rmrr_sanity_check(struct acpi_dmar_reserved_memory *rmrr) { u64 start = rmrr->base_address; u64 end = rmrr->end_address + 1; + int entry_type; - if (e820__mapped_all(start, end, E820_TYPE_RESERVED)) + entry_type = e820__get_entry_type(start, end); + if (entry_type == E820_TYPE_RESERVED || entry_type == E820_TYPE_NVS) return 0; pr_err(FW_BUG "No firmware reserved region can cover this RMRR [%#018Lx-%#018Lx], contact BIOS vendor for fixes\n", From patchwork Wed Oct 19 00:44:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 4391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp60856wrs; Tue, 18 Oct 2022 17:56:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM77fRdQrr87yiZfYn5lqGdFW5kKLCKXBHgdrlyFPWUiSWsJ9fuQE6AtdbykyjrFNGYc7JXh X-Received: by 2002:a05:6a00:114c:b0:528:2c7a:630e with SMTP id b12-20020a056a00114c00b005282c7a630emr5895634pfm.86.1666141006563; Tue, 18 Oct 2022 17:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666141006; cv=none; d=google.com; s=arc-20160816; b=WFN9qBYf5XfDhv8YglLqAJI2Utlzi8JEX/8A3U1lwuh/g204XSG1cr7oCthpVCmsc6 O5B/CBqZBoCMOm48WO8y/KaYEVkOcF1i2RkN1YeniDTTT5reEQBc1GRwtgH5A8a8mvQN 8HudeiUuhzBInUpKdjm7BMb1ESN3STM/oOkFu+w3JgAezmTqYCD/qwF2rUQzq11AirQO epWdMuogmUOYaN6+dNjVwvZ5/vX/Ro80fRq7jonOSlJ5SMIg68WW5AJrPYlxcaF34mAp 7NX3SGfUALqkJxC//sCmQ5ebD4cuovD3NsxVlcALHOtDzj7St48LEXIBflldRr1wuSnG iArQ== 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=iUbX9LrvloHXcmBGtfI89gWrowKur3dca8ZkOVKyOoo=; b=OVy4GnTKzqkOajiAKSBUJDGHnDtXov3Go6tTBrZYSzn0A86/tN5TtI9cBix1zyGe4F zXc6lw7BJGWVkabNtmKWRKFRIaWwyXzMNT1okqiKjHFZJbsPqOVxhkmXIb6obYMUkYFc t38UdvljpWQ/M4sEvDuuUNdSobeRhg/VLSQA9jKBE+3/MP6okzihenB3dPhxUnOsqmts q0dNpvn7e0bTe06fAkhPpXd+q2G337L6fiWKX7mnOMtf9jLjZOD7HYkDRqzNg1dEyAiV P7iofYUtgBq6yx7oX0CH1QXi/EMcLAC2Y4xKNkWoirj02IZdAifSzh4J1nOELD+XBJTC DS7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hhtnhbL9; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob9-20020a17090b390900b00202a519f846si23747156pjb.173.2022.10.18.17.56.31; Tue, 18 Oct 2022 17:56:46 -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=@intel.com header.s=Intel header.b=hhtnhbL9; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbiJSAvc (ORCPT + 99 others); Tue, 18 Oct 2022 20:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiJSAv0 (ORCPT ); Tue, 18 Oct 2022 20:51:26 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 012A0C4C2E for ; Tue, 18 Oct 2022 17:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666140683; x=1697676683; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pB2ZZZeQe2vKmC5MueLvWUhrKOCkzfzRW7G6Fd2Jikw=; b=hhtnhbL97wOkEncURgkk7o+cpK1sfBMp3HSp5mukqMheMBxXXMJIpAoJ BZWSg695e/ozOABmCoB2MBMZ3/ldM2GfSFJ0WAYHgxfZTd4Tf+yokpQpl sI68W3xiaQuKJx4C8f+c6zDBE0aF5x3et5JVF2O9xbUr0ZdWNjzbgfhuQ I3HniEK4R3CaQSS2pI0RcAVFZRfnZcmYQgPM3CefhvuW2ALijouwZfzOz Brm+NLNQuyVT2Grqx3VzyJG80efoOEX3J/CYM33OwuiZ0vg+lZfdamUT1 jGqKHISm45i4oreIBbGlp0hzF93nYZBuWAHmROIb6z+y3gGrKHilUeeJj w==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="289591527" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="289591527" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 17:51:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="606824824" X-IronPort-AV: E=Sophos;i="5.95,194,1661842800"; d="scan'208";a="606824824" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga006.jf.intel.com with ESMTP; 18 Oct 2022 17:51:21 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jerry Snitselaar , Charlotte Tan , Alex Williamson , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] iommu/vt-d: Clean up si_domain in the init_dmars() error path Date: Wed, 19 Oct 2022 08:44:47 +0800 Message-Id: <20221019004447.4563-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019004447.4563-1-baolu.lu@linux.intel.com> References: <20221019004447.4563-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747075471958018160?= X-GMAIL-MSGID: =?utf-8?q?1747075471958018160?= From: Jerry Snitselaar 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 Link: https://lore.kernel.org/r/20221010144842.308890-1-jsnitsel@redhat.com Signed-off-by: Lu Baolu --- 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 b3cf0f991e29..48cdcd0a5cf3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2410,6 +2410,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; } @@ -3052,6 +3053,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; }