From patchwork Mon Jun 5 11:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanfei Xu X-Patchwork-Id: 103213 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2615112vqr; Mon, 5 Jun 2023 04:34:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VMMlGhGMUE7gjy1Tqj4miaQVzK8m8mi5FkmD+93szyFj9564z77V/MDxg38W0MXPoI3J1 X-Received: by 2002:a92:de0e:0:b0:335:6e5d:afb4 with SMTP id x14-20020a92de0e000000b003356e5dafb4mr16737403ilm.24.1685964878315; Mon, 05 Jun 2023 04:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685964878; cv=none; d=google.com; s=arc-20160816; b=kFSEQZzySfungekEVbWw4rFhg9fW3mFOkTzJ4FGr8odldRsw5lc235+cULzVEDCHl3 QjAaLt6RKiE3KRWOCotRw5Zj6kRi2gdxwKqNuTXEl4NQtI26ObDGlm2XzNBmOFm/P+q4 VXArZ2eJIayhZ2KNHyzwyZVwGYj1+FIXqMqhUu1Ska1Zt018u8kSsl4WimBgJX6JfNNS kO9V2/7GT4ud0h07ApH+BSwW44C02yrZE+KrjryVXGvFue/lV+dW2yP7lqSH2L/joW0I VLK7DCue7ItlVtFLynbhUlgtVOjGq3D5zKoorcQqVXA9ICd8lEWmZUo1BlhM4/6jDic6 sIHg== 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=c/9F+2IyhRU5KITHrvOLFwcmIfkutFv5VVsVTelJeAo=; b=YxHyqmd3PeR9s3vdsUqk2D7UGSV5KZ1NO8iP0SEKMcQFBeHuorWS3NlJtplBoDVQ1r YWZYDD/kzNgMq7wI/Wavd6uAeA975FmROMeG+gYHwrAEUrzJsYQWqo63MJRFbTEMxtZ6 CfaXRCEiz5T/hqOS/02oXfUgNgcRwv2HkiVxwKY+j/NK/viifygqJ5QC/zvdaVJSgnYi NYcQsow5yxUN/wqDs1Ja+liebWQc3J/Q7YsIjC5U9Xj0ziMvhcQ5zrqJOOEmL5lzaClc ioJiedMoT42vGoG2w4tfq61wDVt7Yk93XXHUrNy3WBPlg5GPxBh5CfcBxhB0YJRTfmCd Go0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F4qmDLin; 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 d190-20020a6336c7000000b00543c6a8c7c8si527565pga.583.2023.06.05.04.34.25; Mon, 05 Jun 2023 04:34:38 -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=F4qmDLin; 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 S229570AbjFEL3z (ORCPT + 99 others); Mon, 5 Jun 2023 07:29:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbjFEL3r (ORCPT ); Mon, 5 Jun 2023 07:29:47 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18376DF for ; Mon, 5 Jun 2023 04:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685964586; x=1717500586; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xTKbEBDDCXHkiOwFc8keR7O1v8qG4g2CVMGkrh5HwGY=; b=F4qmDLinHiPUi1r4HMGClI4bzPYB+Idiyoie6zQ+StyadjzFnt507zoT ByhdC/xvn6WnMPXEmBr5FHaZFR94BRmzrXd6aE2LVzSqKoxB753EQ6JFJ J3araf93lCAoe39ah6s+y5QjRNp+JjvSCzgptwyUdCPfUeIKZFUR6LmwH rLONSxUgBH5uF3NrCKRjdRK2H8j9WiAItQDaiMfEcK67HzsAILVu3iev0 YUd+BoADalqgZ6xEeWI4jk3SoavhfzWK5IF/aY4KkW/twlQhO1CxCYCHo oyLu9UHYNZbN1yg8QbyPwzZaWkgVpXks/TgEb56PO5M+Fxi3b/slq7jFI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="336699349" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="336699349" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 04:29:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="708626664" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="708626664" Received: from tower.bj.intel.com ([10.238.157.62]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 04:29:43 -0700 From: Yanfei Xu To: dwmw2@infradead.org, baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, yanfei.xu@intel.com Subject: [PATCH v3 1/2] iommu/vt-d: Handle the failure case of dmar_reenable_qi() Date: Mon, 5 Jun 2023 19:26:58 +0800 Message-Id: <20230605112659.308981-2-yanfei.xu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230605112659.308981-1-yanfei.xu@intel.com> References: <20230605112659.308981-1-yanfei.xu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767862308133686518?= X-GMAIL-MSGID: =?utf-8?q?1767862308133686518?= dmar_reenable_qi() may not succeed. Check and return when it fails. Signed-off-by: Yanfei Xu --- drivers/iommu/intel/iommu.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 8096273b034c..c13c6475b626 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2967,10 +2967,15 @@ static int init_iommu_hw(void) { struct dmar_drhd_unit *drhd; struct intel_iommu *iommu = NULL; + int ret; - for_each_active_iommu(iommu, drhd) - if (iommu->qi) - dmar_reenable_qi(iommu); + for_each_active_iommu(iommu, drhd) { + if (iommu->qi) { + ret = dmar_reenable_qi(iommu); + if (ret) + return ret; + } + } for_each_iommu(iommu, drhd) { if (drhd->ignored) { From patchwork Mon Jun 5 11:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanfei Xu X-Patchwork-Id: 103211 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2614184vqr; Mon, 5 Jun 2023 04:33:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ603G6Fbaonir72WSpJG8fdgLRBL7iXb1wCwbqp6kyTmpl8ErTxxgy8a/x2XF5Ay7EOBorT X-Received: by 2002:a17:902:f548:b0:1ac:4735:45d7 with SMTP id h8-20020a170902f54800b001ac473545d7mr8786470plf.6.1685964781256; Mon, 05 Jun 2023 04:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685964781; cv=none; d=google.com; s=arc-20160816; b=Xo1lhP8cu1f5IkUjaIK3LC4JMd+c5240ug59vPYxVTnMyF6ZoGzQuTKlO86og0QkHM +XMv8KGwKDQAU9aEpWYcIlidkFWuCMznGN1e8OWpaKriURtoTjANdzc2XZZbOEZM00i7 bHbfDKiaJn33rMxEEFw6KpnRsanyvoYxHFZn/1sBTPEHNzueUjssqvBePzeH4R5PgScj A1ReCLdHdHRyxFp4In7wqbX1uVafN0zGSm0QjLLol8qnR66zXCW8yTI7WEJ1XMs0PeDh /AsFn0AL2k1a71WKYJu6Qoi9wRX43TqnWQdqgMKpeu4T5TxqxKCN80Me5dgfqXH/ZvPd 2JBw== 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=fWnoi8rAQ4/zASfqkoPutemyxWGUlMtp1Ho5U3caBlU=; b=fNbUvzBtPtgcxhkIyY/fEZvJ2RXgvJrbao6NyX5PHGwx6J5BTrSIYQ3QhlNLXafN/v ZFCUR5jUzTMdzyRLaavanM7F68+Pg/S3ZycHuXpw8PGDDGeRw4RJeZeUWnFKWT4v6dmI DzbDmZR5xg89B1j2JPZpH0t8q7UyBSuG4sPBE/uv9vwA/9n7F58+gKHgGAXvEOXtEyfV qrwIHQQXjMf1kkbq0/5THF0kYxNDIbpXo27w8qoOoTektn6kI9Bo9o8JWCHDAQ49yby1 uvQ8hV8SJwd75Wx3iUqblsbsyEkolOfECAu7vBUrj9ZepjkGLJ/TsZs7xmW8GEjswxbg becw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FXQnaWXr; 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 f9-20020a170902ce8900b001b1f984784fsi2489452plg.476.2023.06.05.04.32.47; Mon, 05 Jun 2023 04:33:01 -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=FXQnaWXr; 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 S232157AbjFEL37 (ORCPT + 99 others); Mon, 5 Jun 2023 07:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbjFEL3t (ORCPT ); Mon, 5 Jun 2023 07:29:49 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 648C4F9 for ; Mon, 5 Jun 2023 04:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685964588; x=1717500588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WEJON0mdcarcf+gq8BZwb49Cru53/uhaflnw7S9fEAQ=; b=FXQnaWXrpKbXMlEDWrQ7hJWXjYZRv3n+bmwx1R4fIrPkZ7l3HUtq48ix QV3SokPOGPWYkUVGXF8kcp76HLzULeXX3j7eSVCnpaSs1BB8TdWeQBW+m 7NzW9Mj9KZ20OvYTuVDpfYjdlU2UkjvM9EaMZMk4mAuJ84xOYxQDlueke 6Oi7v9h1tStl4NGvpWZb5RrU2gMn/DmbeeUneErl6JoEOQNXeNSPFfFAE deYI/0mdziFRFkVMYoX4myYBKGibwP5vExzdUQk0OwiPKSu3O+iWK0syI Q6htNz4tL7wOQHsDwLt9oluUWi1FSANTcTjNspV6aenXWpoyExqkhhBnm Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="336699362" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="336699362" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 04:29:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="708626668" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="708626668" Received: from tower.bj.intel.com ([10.238.157.62]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 04:29:45 -0700 From: Yanfei Xu To: dwmw2@infradead.org, baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, yanfei.xu@intel.com Subject: [PATCH v3 2/2] iommu/vt-d: Remove two WARN_ON in domain_context_mapping_one() Date: Mon, 5 Jun 2023 19:26:59 +0800 Message-Id: <20230605112659.308981-3-yanfei.xu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230605112659.308981-1-yanfei.xu@intel.com> References: <20230605112659.308981-1-yanfei.xu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767862206636275343?= X-GMAIL-MSGID: =?utf-8?q?1767862206636275343?= Remove the WARN_ON(did == 0) as the domain id 0 is reserved and set once the domain_ids is allocated. So iommu_init_domains will never return 0. Remvoe the WARN_ON(!table) as this pointer will be accessed in the following code, if empty "table" really happens, the kernel will report a NULL pointer reference warning at the first place. Signed-off-by: Yanfei Xu --- drivers/iommu/intel/iommu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c13c6475b626..cd9e01a0aa1d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1897,8 +1897,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain, struct context_entry *context; int ret; - WARN_ON(did == 0); - if (hw_pass_through && domain_type_is_si(domain)) translation = CONTEXT_TT_PASS_THROUGH; @@ -1944,8 +1942,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain, if (sm_supported(iommu)) { unsigned long pds; - WARN_ON(!table); - /* Setup the PASID DIR pointer: */ pds = context_get_sm_pds(table); context->lo = (u64)virt_to_phys(table->table) |