From patchwork Thu Mar 18 10:13:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12147821 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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 942EBC433E0 for ; Thu, 18 Mar 2021 10:13:44 +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 4EE8464E21 for ; Thu, 18 Mar 2021 10:13:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EE8464E21 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.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.98871.187819 (Exim 4.92) (envelope-from ) id 1lMpef-0007Mz-9o; Thu, 18 Mar 2021 10:13:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 98871.187819; Thu, 18 Mar 2021 10:13:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMpef-0007Ms-6b; Thu, 18 Mar 2021 10:13:25 +0000 Received: by outflank-mailman (input) for mailman id 98871; Thu, 18 Mar 2021 10:13:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMpee-0007Mm-6W for xen-devel@lists.xenproject.org; Thu, 18 Mar 2021 10:13:24 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 442177c9-9ab5-4fee-8f59-82895bfbff01; Thu, 18 Mar 2021 10:13:23 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B1ABFAC1E; Thu, 18 Mar 2021 10:13:22 +0000 (UTC) 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: 442177c9-9ab5-4fee-8f59-82895bfbff01 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616062402; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y1982WR6j3cpgGsFbVcaDaicMn2WceMWsDl7cYZX9Vg=; b=lFyVfQDVjWzAMl2oA21/i6bVwBTG2NkB0Ir071fgQUFk7xuVaNo6YWTMpzmSUTxn75dWFz NVfq/T6tgSTXsnH0sfXJis3oN6Byhs4bBnvi1bkf909pavpl4m7t5+wW8VvApdjIr0ZkGh UqsCwVlrqcL6xPC/pH+lBbFqA7mjM90= Subject: [PATCH 1/4][4.15?] VT-d: correct off-by-1 in number-of-IOMMUs check From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , Ian Jackson References: Message-ID: <68084b4f-bcd2-59dd-bea7-781b8aa75ef7@suse.com> Date: Thu, 18 Mar 2021 11:13:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Otherwise, if we really run on a system with this many IOMMUs, entering/leaving S3 would overrun iommu_state[]. Signed-off-by: Jan Beulich --- There are more anomalies here, but since we were asked to not make any cosmetic changes for patches to have a chance to go into 4.15, I've put off correcting even the most obvious things (scope of MAX_IOMMUS and nr_iommus) for a later patch. --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1168,10 +1168,10 @@ int __init iommu_alloc(struct acpi_drhd_ unsigned long sagaw, nr_dom; int agaw; - if ( nr_iommus > MAX_IOMMUS ) + if ( nr_iommus >= MAX_IOMMUS ) { dprintk(XENLOG_ERR VTDPREFIX, - "IOMMU: nr_iommus %d > MAX_IOMMUS\n", nr_iommus); + "IOMMU: nr_iommus %d > MAX_IOMMUS\n", nr_iommus + 1); return -ENOMEM; } From patchwork Thu Mar 18 10:13:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12147823 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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 59D03C433E0 for ; Thu, 18 Mar 2021 10:14:19 +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 11CB464E81 for ; Thu, 18 Mar 2021 10:14:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11CB464E81 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.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.98874.187832 (Exim 4.92) (envelope-from ) id 1lMpfE-0007Sw-KT; Thu, 18 Mar 2021 10:14:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 98874.187832; Thu, 18 Mar 2021 10:14:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMpfE-0007Sp-HA; Thu, 18 Mar 2021 10:14:00 +0000 Received: by outflank-mailman (input) for mailman id 98874; Thu, 18 Mar 2021 10:13:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMpfD-0007Sh-BF for xen-devel@lists.xenproject.org; Thu, 18 Mar 2021 10:13:59 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eff9bc1d-c2c1-4203-9268-4c90312ff026; Thu, 18 Mar 2021 10:13:58 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B9C21AC1E; Thu, 18 Mar 2021 10:13:57 +0000 (UTC) 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: eff9bc1d-c2c1-4203-9268-4c90312ff026 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616062437; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jqnxm854ZkzHnoc/cGVME3wbWF5nHrJSeLOnsd7AR3U=; b=Hmwoh+M3z8oP9tjzgCwN6Ee6cUFd/1Hxa1TOQ2G5QPHB7x0Zk9NhupoD9q2ORtUjr4WgsS Q5BuVPoi6bdoOY/Wt2Nk5E5YBXZOPKwlzjKpNupRaCcVAh7c01gLTyEJqxOrWo1bU6WjZZ cRsEfLoel7NpPiL+bstBi/6LipUFxoI= Subject: [PATCH 2/4][4.15?] VT-d: leave FECTL write to vtd_resume() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , Ian Jackson References: Message-ID: <57976bd9-6c50-26c3-1f06-62f1a5546e06@suse.com> Date: Thu, 18 Mar 2021 11:13:57 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US We shouldn't blindly unmask the interrupt when resuming. vtd_resume() will restore the intended state. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2092,7 +2092,7 @@ static int adjust_vtd_irq_affinities(voi } __initcall(adjust_vtd_irq_affinities); -static int __must_check init_vtd_hw(void) +static int __must_check init_vtd_hw(bool resume) { struct acpi_drhd_unit *drhd; struct vtd_iommu *iommu; @@ -2121,6 +2121,10 @@ static int __must_check init_vtd_hw(void disable_qinval(iommu); } + if ( resume ) + /* FECTL write done by vtd_resume(). */ + continue; + spin_lock_irqsave(&iommu->register_lock, flags); sts = dmar_readl(iommu->reg, DMAR_FECTL_REG); sts &= ~DMA_FECTL_IM; @@ -2320,7 +2324,7 @@ static int __init vtd_setup(void) P(iommu_hap_pt_share, "Shared EPT tables"); #undef P - ret = init_vtd_hw(); + ret = init_vtd_hw(false); if ( ret ) goto error; @@ -2590,7 +2594,7 @@ static void vtd_resume(void) if ( !iommu_enabled ) return; - if ( init_vtd_hw() != 0 && force_iommu ) + if ( init_vtd_hw(true) != 0 && force_iommu ) panic("IOMMU setup failed, crash Xen for security purpose\n"); for_each_drhd_unit ( drhd ) From patchwork Thu Mar 18 10:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12147825 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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 54BDDC433DB for ; Thu, 18 Mar 2021 10:14:54 +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 0988364E99 for ; Thu, 18 Mar 2021 10:14:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0988364E99 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.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.98877.187843 (Exim 4.92) (envelope-from ) id 1lMpfn-0007Zm-UB; Thu, 18 Mar 2021 10:14:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 98877.187843; Thu, 18 Mar 2021 10:14:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMpfn-0007Zf-Qw; Thu, 18 Mar 2021 10:14:35 +0000 Received: by outflank-mailman (input) for mailman id 98877; Thu, 18 Mar 2021 10:14:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMpfm-0007ZU-DJ for xen-devel@lists.xenproject.org; Thu, 18 Mar 2021 10:14:34 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f42204a6-c052-46cf-8a96-b10a1d5f3c30; Thu, 18 Mar 2021 10:14:33 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DF035AD20; Thu, 18 Mar 2021 10:14:32 +0000 (UTC) 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: f42204a6-c052-46cf-8a96-b10a1d5f3c30 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616062473; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GPmVawULsDWDzc2AL6YzBoU9qI4rbrFjxnykvjGJcYI=; b=NEmSx4pvrG7l2F8X//6YOPn/o3iD96gvZjEg5yY6K9Fd+Tn+SZVl5rM3AqYLayF2+8nED1 ceIr53Mww7wBfDWSkuGjG5YlEGbjrEnHd+2zeIGp93U23cLvK31APitU3tVxDqsugiJvg2 hg/+EqIJGRdaiJ5/qYjVgvyQR5u5SSI= Subject: [PATCH 3/4][4.15?] VT-d: re-order register restoring in vtd_resume() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , Ian Jackson References: Message-ID: <04332d46-a595-3f42-71f8-a933048982ab@suse.com> Date: Thu, 18 Mar 2021 11:14:32 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US For one FECTL must be written last - the interrupt shouldn't be unmasked without first having written the data and address needed to actually deliver it. In the common case (when dma_msi_set_affinity() doesn't end up bailing early) this happens from init_vtd_hw(), but for this to actually have the intended effect we shouldn't subsequently overwrite what was written there - this is only benign when old and new settings match. Instead we should restore the registers ahead of calling init_vtd_hw(), just for the unlikely case of dma_msi_set_affinity() bailing early. In the moved code drop some stray casts as well. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2594,6 +2594,21 @@ static void vtd_resume(void) if ( !iommu_enabled ) return; + for_each_drhd_unit ( drhd ) + { + iommu = drhd->iommu; + i = iommu->index; + + spin_lock_irqsave(&iommu->register_lock, flags); + dmar_writel(iommu->reg, DMAR_FEDATA_REG, + iommu_state[i][DMAR_FEDATA_REG]); + dmar_writel(iommu->reg, DMAR_FEADDR_REG, + iommu_state[i][DMAR_FEADDR_REG]); + dmar_writel(iommu->reg, DMAR_FEUADDR_REG, + iommu_state[i][DMAR_FEUADDR_REG]); + spin_unlock_irqrestore(&iommu->register_lock, flags); + } + if ( init_vtd_hw(true) != 0 && force_iommu ) panic("IOMMU setup failed, crash Xen for security purpose\n"); @@ -2605,12 +2620,6 @@ static void vtd_resume(void) spin_lock_irqsave(&iommu->register_lock, flags); dmar_writel(iommu->reg, DMAR_FECTL_REG, (u32) iommu_state[i][DMAR_FECTL_REG]); - dmar_writel(iommu->reg, DMAR_FEDATA_REG, - (u32) iommu_state[i][DMAR_FEDATA_REG]); - dmar_writel(iommu->reg, DMAR_FEADDR_REG, - (u32) iommu_state[i][DMAR_FEADDR_REG]); - dmar_writel(iommu->reg, DMAR_FEUADDR_REG, - (u32) iommu_state[i][DMAR_FEUADDR_REG]); spin_unlock_irqrestore(&iommu->register_lock, flags); iommu_enable_translation(drhd); From patchwork Thu Mar 18 10:15:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12147827 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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 7A3C7C433E0 for ; Thu, 18 Mar 2021 10:16:00 +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 1CB3564E90 for ; Thu, 18 Mar 2021 10:16:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CB3564E90 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.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.98882.187867 (Exim 4.92) (envelope-from ) id 1lMph1-0007nU-I1; Thu, 18 Mar 2021 10:15:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 98882.187867; Thu, 18 Mar 2021 10:15:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMph1-0007nN-EZ; Thu, 18 Mar 2021 10:15:51 +0000 Received: by outflank-mailman (input) for mailman id 98882; Thu, 18 Mar 2021 10:15:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lMph0-0007nE-F3 for xen-devel@lists.xenproject.org; Thu, 18 Mar 2021 10:15:50 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 92e2fb4a-7283-4df8-9bd1-08757255efec; Thu, 18 Mar 2021 10:15:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CAEBFACBF; Thu, 18 Mar 2021 10:15:48 +0000 (UTC) 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: 92e2fb4a-7283-4df8-9bd1-08757255efec X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616062548; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1jAuOft1lat9ybZ5l7PuD+O//EBqhMIy794TtaMQe6M=; b=EBhdd20VtJHzJGZyjJcXbjnn4HdIBMkVaTz9b20KNztVaLjeU2LmItT/PULBBTkNKasknX tYe8NrC8CU3rtAzfN9WrQJZ8FuA/Lk6ITht8jVYpm3jwKXNZsVThLZ7/lWRXxsjtRT8DaS TcO8mLqwX2B+UaILh6GSj/dBcpuiPhw= Subject: [PATCH 4/4][4.15?] VT-d: restore flush hooks when disabling qinval From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Kevin Tian , Ian Jackson References: Message-ID: <1fa377f7-d709-2615-55fe-f4d5e0d4f317@suse.com> Date: Thu, 18 Mar 2021 11:15:48 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Leaving the hooks untouched is at best a latent risk: There may well be cases where some flush is needed, which then needs carrying out the "register" way. Switch from u to uint_t while needing to touch the function headers anyway. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -49,6 +49,16 @@ int iommu_flush_iec_global(struct vtd_io int iommu_flush_iec_index(struct vtd_iommu *iommu, u8 im, u16 iidx); void clear_fault_bits(struct vtd_iommu *iommu); +int __must_check vtd_flush_context_reg(struct vtd_iommu *iommu, uint16_t did, + uint16_t source_id, + uint8_t function_mask, uint64_t type, + bool flush_non_present_entry); +int __must_check vtd_flush_iotlb_reg(struct vtd_iommu *iommu, uint16_t did, + uint64_t addr, unsigned int size_order, + uint64_t type, + bool flush_non_present_entry, + bool flush_dev_iotlb); + struct vtd_iommu *ioapic_to_iommu(unsigned int apic_id); struct vtd_iommu *hpet_to_iommu(unsigned int hpet_id); struct acpi_drhd_unit *ioapic_to_drhd(unsigned int apic_id); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -380,10 +380,9 @@ static void iommu_flush_write_buffer(str } /* return value determine if we need a write buffer flush */ -static int __must_check flush_context_reg(struct vtd_iommu *iommu, u16 did, - u16 source_id, u8 function_mask, - u64 type, - bool flush_non_present_entry) +int vtd_flush_context_reg(struct vtd_iommu *iommu, uint16_t did, + uint16_t source_id, uint8_t function_mask, + uint64_t type, bool flush_non_present_entry) { u64 val = 0; unsigned long flags; @@ -449,11 +448,9 @@ static int __must_check iommu_flush_cont } /* return value determine if we need a write buffer flush */ -static int __must_check flush_iotlb_reg(struct vtd_iommu *iommu, u16 did, - u64 addr, - unsigned int size_order, u64 type, - bool flush_non_present_entry, - bool flush_dev_iotlb) +int vtd_flush_iotlb_reg(struct vtd_iommu *iommu, uint16_t did, uint64_t addr, + unsigned int size_order, uint64_t type, + bool flush_non_present_entry, bool flush_dev_iotlb) { int tlb_offset = ecap_iotlb_offset(iommu->ecap); u64 val = 0; @@ -2144,8 +2141,8 @@ static int __must_check init_vtd_hw(bool */ if ( enable_qinval(iommu) != 0 ) { - iommu->flush.context = flush_context_reg; - iommu->flush.iotlb = flush_iotlb_reg; + iommu->flush.context = vtd_flush_context_reg; + iommu->flush.iotlb = vtd_flush_iotlb_reg; } } --- a/xen/drivers/passthrough/vtd/qinval.c +++ b/xen/drivers/passthrough/vtd/qinval.c @@ -462,4 +462,7 @@ void disable_qinval(struct vtd_iommu *io !(sts & DMA_GSTS_QIES), sts); out: spin_unlock_irqrestore(&iommu->register_lock, flags); + + iommu->flush.context = vtd_flush_context_reg; + iommu->flush.iotlb = vtd_flush_iotlb_reg; }