Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C7D1C433E0 for ; Mon, 4 Jan 2021 09:28:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD68721D79 for ; Mon, 4 Jan 2021 09:28:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD68721D79 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.61034.107084 (Exim 4.92) (envelope-from ) id 1kwMAJ-00036Z-Gq; Mon, 04 Jan 2021 09:28:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 61034.107084; Mon, 04 Jan 2021 09:28:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwMAJ-00036S-Dn; Mon, 04 Jan 2021 09:28:39 +0000 Received: by outflank-mailman (input) for mailman id 61034; Mon, 04 Jan 2021 09:28:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwMAH-00036N-Mc for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 09:28:37 +0000 Received: from mail-wr1-x42d.google.com (unknown [2a00:1450:4864:20::42d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6c78426a-f29c-438c-b06e-0f42d650be2c; Mon, 04 Jan 2021 09:28:36 +0000 (UTC) Received: by mail-wr1-x42d.google.com with SMTP id 91so31421962wrj.7 for ; Mon, 04 Jan 2021 01:28:36 -0800 (PST) Received: from CBGR90WXYV0 (host86-165-42-133.range86-165.btcentralplus.com. [86.165.42.133]) by smtp.gmail.com with ESMTPSA id r2sm90323955wrn.83.2021.01.04.01.28.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2021 01:28:35 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6c78426a-f29c-438c-b06e-0f42d650be2c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:reply-to:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-transfer-encoding:content-language :thread-index; bh=iGNng4Hg1jfuvBKz+O8Pd6DG7R4B7mgDsA/LrrbdQdg=; b=FgZ6kaFtkSiYUuj1e795Wxiu42CUpQl089V2tAOEjrx1kdjsw8dxiM2CVooiAj6+mj J/9XDSYgKGaWro4ravM1RzHFU43CbiDeftoAjXkiIu7j+dx7ZxBj/eGl64uE0/KQ4MuD jbHa7s1D4viLapNXJgWpjT0nCidYv6xuOkRMIX9WN0FI6Qxbmhh8Hj2Z6WxbS5Ym/I58 pRfUX5u6bIyK7x5BImDI/mzdrgpZ59dXDyurp6QzjC1xzHilBkeSzMThSMsPkreoqlGZ MJ+8gJOmT845viC2LytX87bg3rnWQR8sdp0b02ukMlCq85DXQka6ItMdGSQ/oDUzFIPW AD7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:reply-to:to:cc:references:in-reply-to :subject:date:message-id:mime-version:content-transfer-encoding :content-language:thread-index; bh=iGNng4Hg1jfuvBKz+O8Pd6DG7R4B7mgDsA/LrrbdQdg=; b=QtTRayH+/EgajuhtXcvw52p6WeWEPswE/+kmq6Tdd/h64RUX93VNYYqhMPgXhgKeGu JemmBh1MFVEeE3x8uKdyps7QHCHiltYXUMrdPrivETKLM+p+Qfn2U5o7Eyp5kRGy2HOB C3r94jdAtohS7BnUVd8FzUD7MiDsN1YAHveSxOSk2ROooTBkPEcDz6Jnnhap7DLzicfT PG7fjhXh6ZDj03qmGqYAQD2Z+AipZ3Gm33fdEpfyJH57SeaIlPm6ncZP+3+zGJLrTw82 yRIZ6Q/nfd73WBQY/nDzQrBHb90FzvSzCTCdUf7/Ao8l4cW5Ir5Pd7kv8ce2XtSXXsiR QsQw== X-Gm-Message-State: AOAM531d1Pd1qNH7QtPpyDJasexK6d8WIS1/yKxYiprbRKWYD1+mcWDt 3lQhOw3kBEb+uHWlEW2agfQ= X-Google-Smtp-Source: ABdhPJwwQmXrSdt5eRfdrvIbQOTK4WhLVgcytOUKX+tsOdHCj/WO2yf9G/QO4mrwxtB3zyQY5lkdUA== X-Received: by 2002:a5d:43cc:: with SMTP id v12mr52437853wrr.319.1609752516009; Mon, 04 Jan 2021 01:28:36 -0800 (PST) From: Paul Durrant X-Google-Original-From: "Paul Durrant" Reply-To: To: "'Julien Grall'" , Cc: , "'Julien Grall'" , "'Jan Beulich'" References: <20201222154338.9459-1-julien@xen.org> <20201222154338.9459-2-julien@xen.org> In-Reply-To: <20201222154338.9459-2-julien@xen.org> Subject: RE: [PATCH for-4.15 1/4] xen/iommu: Check if the IOMMU was initialized before tearing down Date: Mon, 4 Jan 2021 09:28:34 -0000 Message-ID: <002301d6e27b$f9eaae90$edc00bb0$@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Content-Language: en-gb Thread-Index: AQH2TO5SqTDQ1dUiy31gxFMl+4NKXAJy9PyCqcTFpjA= > -----Original Message----- > From: Julien Grall > Sent: 22 December 2020 15:44 > To: xen-devel@lists.xenproject.org > Cc: hongyxia@amazon.co.uk; Julien Grall ; Jan Beulich ; Paul > Durrant > Subject: [PATCH for-4.15 1/4] xen/iommu: Check if the IOMMU was initialized before tearing down > > From: Julien Grall > > is_iommu_enabled() will return true even if the IOMMU has not been > initialized (e.g. the ops are not set). > > In the case of an early failure in arch_domain_init(), the function > iommu_destroy_domain() will be called even if the IOMMU is initialized. > > This will result to dereference the ops which will be NULL and an host > crash. > > Fix the issue by checking that ops has been set before accessing it. > Note that we are assuming that arch_iommu_domain_init() will cleanup an > intermediate failure if it failed. > > Fixes: 71e617a6b8f6 ("use is_iommu_enabled() where appropriate...") > Signed-off-by: Julien Grall > --- > xen/drivers/passthrough/iommu.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c > index 2358b6eb09f4..f976d5a0b0a5 100644 > --- a/xen/drivers/passthrough/iommu.c > +++ b/xen/drivers/passthrough/iommu.c > @@ -226,7 +226,15 @@ static void iommu_teardown(struct domain *d) > > void iommu_domain_destroy(struct domain *d) > { > - if ( !is_iommu_enabled(d) ) > + struct domain_iommu *hd = dom_iommu(d); > + > + /* > + * In case of failure during the domain construction, it would be > + * possible to reach this function with the IOMMU enabled but not > + * yet initialized. We assume that hd->platforms will be non-NULL as > + * soon as we start to initialize the IOMMU. > + */ > + if ( !is_iommu_enabled(d) || !hd->platform_ops ) > return; TBH, this seems like the wrong way to fix it. The ops dereference is done in iommu_teardown() so that ought to be doing the check, but given it is single line function then it could be inlined at the same time. That said, I think arch_iommu_domain_destroy() needs to be call unconditionally as it arch_iommu_domain_init() is called before the ops pointer is set. Paul > > iommu_teardown(d); > -- > 2.17.1