From patchwork Mon Sep 21 16:28:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 263616 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=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 289AAC43469 for ; Mon, 21 Sep 2020 16:55:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E93B4206FB for ; Mon, 21 Sep 2020 16:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600707342; bh=9zGEvBYjjk3/TckniU3gjntHp7zocFs48AHjGEiHBsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=m3jaPHd/SBOUMLpXV4BPJ0Z4Z/KVFujBk33a3GTOSqb3t9L7cPZbbaBE05LUNsAmn 36J5Eleuj9MjG6O6n+E6tdvypSRqz0tSiaQ8Tc0a2qj+DXzwQRoi1Y8pR+HY/kuWe5 7xHbAOiloxQslGuTYSw2Y+m+sD+6OwMYgKO3KxK4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgIUQpo (ORCPT ); Mon, 21 Sep 2020 12:45:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:51642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729515AbgIUQph (ORCPT ); Mon, 21 Sep 2020 12:45:37 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 687B323788; Mon, 21 Sep 2020 16:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706735; bh=9zGEvBYjjk3/TckniU3gjntHp7zocFs48AHjGEiHBsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mY7rvqqgPyGm6StdN/UD9R1IHq9InA9rhHA+sMqbHE5ZAqQCyuLzULcexYyOEmeUD y5Sz8GtOePzTwFvaGUFug3Xk0NaqtliFtqvviVJePKjCfECaZceYQGH5U5ATCHHq5x ZAtPQ8tYjyUw7LHd9FOwmzYhwjGQE9LbH4u6+mNM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Levitsky , Suravee Suthikulpanit , Joao Martins , Joerg Roedel , Sasha Levin Subject: [PATCH 5.8 074/118] iommu/amd: Restore IRTE.RemapEn bit for amd_iommu_activate_guest_mode Date: Mon, 21 Sep 2020 18:28:06 +0200 Message-Id: <20200921162039.772722555@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Suravee Suthikulpanit [ Upstream commit e97685abd5d711c885053d4949178f7ab9acbaef ] Commit e52d58d54a32 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE") removed an assumption that modify_irte_ga always set the valid bit, which requires the callers to set the appropriate value for the struct irte_ga.valid bit before calling the function. Similar to the commit 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE"), which is for the function amd_iommu_deactivate_guest_mode(). The same change is also needed for the amd_iommu_activate_guest_mode(). Otherwise, this could trigger IO_PAGE_FAULT for the VFIO based VMs with AVIC enabled. Fixes: e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE") Reported-by: Maxim Levitsky Signed-off-by: Suravee Suthikulpanit Tested-by: Maxim Levitsky Reviewed-by: Joao Martins Reviewed-by: Maxim Levitsky Cc: Joao Martins Link: https://lore.kernel.org/r/20200916111720.43913-1-suravee.suthikulpanit@amd.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 48fe272da6e9c..a51dcf26b09f2 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -3831,14 +3831,18 @@ int amd_iommu_activate_guest_mode(void *data) { struct amd_ir_data *ir_data = (struct amd_ir_data *)data; struct irte_ga *entry = (struct irte_ga *) ir_data->entry; + u64 valid; if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) || !entry || entry->lo.fields_vapic.guest_mode) return 0; + valid = entry->lo.fields_vapic.valid; + entry->lo.val = 0; entry->hi.val = 0; + entry->lo.fields_vapic.valid = valid; entry->lo.fields_vapic.guest_mode = 1; entry->lo.fields_vapic.ga_log_intr = 1; entry->hi.fields.ga_root_ptr = ir_data->ga_root_ptr;