From mboxrd@z Thu Jan 1 00:00:00 1970 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 4AB43C43461 for ; Wed, 16 Sep 2020 20:29:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E893121D43 for ; Wed, 16 Sep 2020 20:29:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DZJzl9kV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727215AbgIPU3I (ORCPT ); Wed, 16 Sep 2020 16:29:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40111 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbgIPRYO (ORCPT ); Wed, 16 Sep 2020 13:24:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600277005; h=from:from:reply-to:subject:subject: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=0FBHbk68iVZgx7bJXMjUxCpKA5G+DPHMYndfXbzqZBk=; b=DZJzl9kVrSGmki2zkzK6nz44M28KKXSBxKH+ue+TPelc8nXf+xh2DHbrdNxyTBnI1akNw8 hFgUH8EWn80fLDz3zc0zWwgG4eueKNsYKNMrgX3iwfOCuvX9XcX64mZL/5CXOEye0457WC Q1DXrHG0QMloit5ZMlNX/flyXJT8HI4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-ssaaT3QjOJKzRu4Ac00xZA-1; Wed, 16 Sep 2020 11:12:41 -0400 X-MC-Unique: ssaaT3QjOJKzRu4Ac00xZA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86E7064095; Wed, 16 Sep 2020 15:12:39 +0000 (UTC) Received: from starship (unknown [10.35.206.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD9F25FC36; Wed, 16 Sep 2020 15:12:37 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2] iommu/amd: Restore IRTE.RemapEn bit for amd_iommu_activate_guest_mode From: Maxim Levitsky To: Suravee Suthikulpanit , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: joro@8bytes.org, Joao Martins Date: Wed, 16 Sep 2020 18:12:36 +0300 In-Reply-To: <20200916111720.43913-1-suravee.suthikulpanit@amd.com> References: <20200916111720.43913-1-suravee.suthikulpanit@amd.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.3 (3.36.3-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2020-09-16 at 11:17 +0000, Suravee Suthikulpanit wrote: > 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. > > Reported-by: Maxim Levitsky > Tested-by: Maxim Levitsky > Cc: Joao Martins > Fixes: e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE") > Signed-off-by: Suravee Suthikulpanit > --- > 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 e938677af8bc..db4fb840c59c 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -3900,14 +3900,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; Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky