From nobody Sat Nov 30 02:55:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1616062432; cv=none; d=zohomail.com; s=zohoarc; b=Rzrtnk5PErfyGkaZQYH78VOa4F4aWdZDQKRt96Ij10GSOclwTsSCFQegQjrzzapKcasMamW8rSTtOoKGJp+/qq0/lxvX4tF8QyqyNvp0ekFpvgXTAuaMy6VgRgWi0MhnWabgIZB8P3X4rw1Jr+q/TUM5rvhkpQUSUEUDKizq21k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616062432; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y1982WR6j3cpgGsFbVcaDaicMn2WceMWsDl7cYZX9Vg=; b=bGEDn0AIQGVezaxdwu78OyHr4X/OA9ZaelS6inll2FM9I2+ovdKxGoVoNWrMdcOSH4GmGsyL561ssweXdn/c95ICybgAJmOU5pVO1in2bIhAJ5A6qt71uMpc2n/W9Glg998b82xLJwgVctZxMINLZGDtHNy+H50r2wTI6bwePxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1616062432614267.6244923892208; Thu, 18 Mar 2021 03:13:52 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Otherwise, if we really run on a system with this many IOMMUs, entering/leaving S3 would overrun iommu_state[]. Signed-off-by: Jan Beulich Reviewed-by: Kevin Tian --- 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; =20 - if ( nr_iommus > MAX_IOMMUS ) + if ( nr_iommus >=3D 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; } =20 From nobody Sat Nov 30 02:55:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1616062464; cv=none; d=zohomail.com; s=zohoarc; b=DZe7oLR4WWsyZBLHzWR5WumC0N63BCCAhWFGMcxQ4wx0D4jmfDrAAMmIPNoTXZbgur4mFU4RR19dp7t9dYg2U7uWv1AniPxMXNW+W5wQTTca4eOzWGLKSZo/H3Oomuvrj4cueV/NVaqcYUzbYONkYIGiE7XDQ1Cdk8j8VPL22uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616062464; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jqnxm854ZkzHnoc/cGVME3wbWF5nHrJSeLOnsd7AR3U=; b=TZBtCx+6voCspQXzq1jr6J754wB6KWnEk8pVg651y6OPq87UHoGnr7vT7Jd+DHRlXHwrfFsTYxcuwtqbMmJLhQ8IfcrTc3mbmhLeykow4+/z3k4JZ+vKgtTHzki1jZDEnVHluJWFdzk6AV8/waKLsggxOV8CFjxRJM+fjAvuSLo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1616062464681964.226881660985; Thu, 18 Mar 2021 03:14:24 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" We shouldn't blindly unmask the interrupt when resuming. vtd_resume() will restore the intended state. Signed-off-by: Jan Beulich Reviewed-by: Kevin Tian --- 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); =20 -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); } =20 + if ( resume ) + /* FECTL write done by vtd_resume(). */ + continue; + spin_lock_irqsave(&iommu->register_lock, flags); sts =3D dmar_readl(iommu->reg, DMAR_FECTL_REG); sts &=3D ~DMA_FECTL_IM; @@ -2320,7 +2324,7 @@ static int __init vtd_setup(void) P(iommu_hap_pt_share, "Shared EPT tables"); #undef P =20 - ret =3D init_vtd_hw(); + ret =3D init_vtd_hw(false); if ( ret ) goto error; =20 @@ -2590,7 +2594,7 @@ static void vtd_resume(void) if ( !iommu_enabled ) return; =20 - if ( init_vtd_hw() !=3D 0 && force_iommu ) + if ( init_vtd_hw(true) !=3D 0 && force_iommu ) panic("IOMMU setup failed, crash Xen for security purpose\n"); =20 for_each_drhd_unit ( drhd ) From nobody Sat Nov 30 02:55:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1616062501; cv=none; d=zohomail.com; s=zohoarc; b=SIsRXFuxNvUGFdRZV1c4gOHD2Ozplgy1x6ysOjn6N1AMvDBCBAzWRmF6/STr9E/HiLSirJq7LdU6gxhL718ufWGlba3x/0ahu+WiItW/ZWq24g+wGJQ0A11TcvQ6TyaqAS3qjIXSS3nFlcKDNI8QTSVkOAADEaFzNAh+ZSUhSgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616062501; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GPmVawULsDWDzc2AL6YzBoU9qI4rbrFjxnykvjGJcYI=; b=gTY9D4FNkTngR5aPJL0ubuFIL52QK3AY6xs2tNNN90wKMIkNrRm4fuaazaSbu/Eo2sZD6nI5Kq2Mu37FGF2Fwym6wmFnoG7mvoajqd8sqK9+aOBvuPaYyPh4QNC17CPeZXcjsmEsqpNPY64oWhNrI7Njf7x21tTyIy3CjOKSWaY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1616062501358122.76241714469256; Thu, 18 Mar 2021 03:15:01 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Kevin Tian --- 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; =20 + for_each_drhd_unit ( drhd ) + { + iommu =3D drhd->iommu; + i =3D 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) !=3D 0 && force_iommu ) panic("IOMMU setup failed, crash Xen for security purpose\n"); =20 @@ -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); =20 iommu_enable_translation(drhd); From nobody Sat Nov 30 02:55:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1616062571; cv=none; d=zohomail.com; s=zohoarc; b=Tc2pn2nQJphtmQXFPq20Ay+78QapcF/EQ5CLqF554p5upEmk31jt6XurWIcVoqPCr+yhl9x6JdPhXvSnJ3cAQNT/m6zhZO1JI1iENMUX947OUl/yQuDHp/TvqvMcX6syNHCQ7UpZZvC9PEepUCr/64rCObXCQkhuzrwtDRjEdkc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616062571; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1jAuOft1lat9ybZ5l7PuD+O//EBqhMIy794TtaMQe6M=; b=RkXJCDPZ5N/x5pHAJ/c74pHCgR9jz0BRlMPZW2shH0Z3uoHl1CQqWrXbkwEJjKcyZk3No1cheVCUBDM5/XntYTW96v2OtyJTEcKW2lCyQyH9B4aDcrM3aXgjvDZgPFCK71JrtQdRlWpWqypIbmLy+MotVoYcTEwgx/VogKFQzd8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161606257148182.13119856766866; Thu, 18 Mar 2021 03:16:11 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Kevin Tian --- 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); =20 +int __must_check vtd_flush_context_reg(struct vtd_iommu *iommu, uint16_t d= id, + uint16_t source_id, + uint8_t function_mask, uint64_t typ= e, + 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_orde= r, + 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 } =20 /* 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 =3D 0; unsigned long flags; @@ -449,11 +448,9 @@ static int __must_check iommu_flush_cont } =20 /* 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 ad= dr, + unsigned int size_order, uint64_t type, + bool flush_non_present_entry, bool flush_dev_iotlb) { int tlb_offset =3D ecap_iotlb_offset(iommu->ecap); u64 val =3D 0; @@ -2144,8 +2141,8 @@ static int __must_check init_vtd_hw(bool */ if ( enable_qinval(iommu) !=3D 0 ) { - iommu->flush.context =3D flush_context_reg; - iommu->flush.iotlb =3D flush_iotlb_reg; + iommu->flush.context =3D vtd_flush_context_reg; + iommu->flush.iotlb =3D vtd_flush_iotlb_reg; } } =20 --- 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 =3D vtd_flush_context_reg; + iommu->flush.iotlb =3D vtd_flush_iotlb_reg; }