Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1268998ybt; Thu, 2 Jul 2020 00:53:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvpOUL9rB4of4SY6it/QkpKCSV1qiIQwlmhLTX3Z7ZgWO0674jUrdKvDSHrRUvqonHvUDx X-Received: by 2002:a05:6402:2212:: with SMTP id cq18mr35111143edb.173.1593676392688; Thu, 02 Jul 2020 00:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593676392; cv=none; d=google.com; s=arc-20160816; b=AWhZfccsJ/7LziGZC8ElQssahJEwX0ZSWrXaXPZCUj5x6NHXqTAe7buTlnPNoPDS3O Z+Qra4egqEAa5uIoZKP34hlBUSU6NuKGADfCeAgueZWIDieOH4J5NhG5hAsu6mdlQZdC Kv0f1nmozK13xvaFpQ975B+OO8OXD7bQuqC7KTz2XsXeNmgN+SNv5NOmtYXXmA5PhFJe PHmYNsgSfoIx8Lb6iGXPh8K1Cmt5bj5Zf2YzqUHOUpdj7/0ow82vwTyEpAjovaqe/qLb np7bLJiroSYpiuUG3L9d11wDQ0S8rxfu39WsfnvaCLxpNTiBZ4SvRS1ND2CdM/9hlk8U BVxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=siZTOIfPD9T2MnCdUtEwr4YB3Ao/TtbkwOBgLqvQBKk=; b=XTl9MPT5J4sLSfcikSZLB+3t6GdNasVnYgpycXFiOPc6azoTgpURpuaepZ0IflbZbA R2Q4PqtO7+LGGaSa0ZFWOE2xWl4q1vNXy9PF54woPifNfVk8qNTho+Ul0+HW1KAsFsVP ohM3AbYX+JWWdz7SCtzYLEzoSLAjf8B1XDTx43g3YstmeDnDwBVIOOY64mr7lwWhXVrm Bk8BGC8HlWZeI05lJBo1OXWhNA7FY1SIMRdImj7DNHfxKZ8QNDJYtx+pE+tFM2z0ULwU M92G/IkSdGXR0LXh8+qhMTcb2feVu+HvhyZvEZFBDeUBGpp/XgHu0ihCDdj40GR4boL5 lT7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Iy6q1YUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si6087128edo.16.2020.07.02.00.52.50; Thu, 02 Jul 2020 00:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Iy6q1YUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728038AbgGBHuc (ORCPT + 99 others); Thu, 2 Jul 2020 03:50:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59857 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726042AbgGBHuc (ORCPT ); Thu, 2 Jul 2020 03:50:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593676230; 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=siZTOIfPD9T2MnCdUtEwr4YB3Ao/TtbkwOBgLqvQBKk=; b=Iy6q1YUMaAawWYkEIDew9xHSJ3TS1n9GcWCn+QLy1Z+xMtEHJGmUMsZi5ncRkgwg8gMpnL ZsZdPPtxCGzJtRyiUTt7BNXImWytLLLdG3yaKb7nuZsle9aZ1mEG8EGJJ9C0DhOvydplUR VS8SxlacVC7lOumjXzOTokUiY0jQKKs= 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-287-YfE5AYJQMdOWPk_ilgXALg-1; Thu, 02 Jul 2020 03:50:25 -0400 X-MC-Unique: YfE5AYJQMdOWPk_ilgXALg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BC7819253C0; Thu, 2 Jul 2020 07:50:23 +0000 (UTC) Received: from [10.36.112.70] (ovpn-112-70.ams2.redhat.com [10.36.112.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 691291002397; Thu, 2 Jul 2020 07:50:21 +0000 (UTC) Subject: Re: [PATCH v3 4/7] iommu/vt-d: Handle non-page aligned address To: Jacob Pan , iommu@lists.linux-foundation.org, LKML , Lu Baolu , Joerg Roedel , David Woodhouse Cc: Yi Liu , "Tian, Kevin" , Raj Ashok References: <1593617636-79385-1-git-send-email-jacob.jun.pan@linux.intel.com> <1593617636-79385-5-git-send-email-jacob.jun.pan@linux.intel.com> From: Auger Eric Message-ID: <40a83912-f8ad-9887-38d0-39a70ecc062c@redhat.com> Date: Thu, 2 Jul 2020 09:50:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <1593617636-79385-5-git-send-email-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacob, On 7/1/20 5:33 PM, Jacob Pan wrote: > From: Liu Yi L > > Address information for device TLB invalidation comes from userspace > when device is directly assigned to a guest with vIOMMU support. > VT-d requires page aligned address. This patch checks and enforce > address to be page aligned, otherwise reserved bits can be set in the > invalidation descriptor. Unrecoverable fault will be reported due to > non-zero value in the reserved bits. on the other hand if user space sends unaligned invalidations, shouldn't it be reported in some way? > > Fixes: 61a06a16e36d8 ("iommu/vt-d: Support flushing more translation > cache types") > Acked-by: Lu Baolu > Signed-off-by: Liu Yi L > Signed-off-by: Jacob Pan > > Signed-off-by: Jacob Pan > --- > drivers/iommu/intel/dmar.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c > index d9f973fa1190..3899f3161071 100644 > --- a/drivers/iommu/intel/dmar.c > +++ b/drivers/iommu/intel/dmar.c > @@ -1455,9 +1455,25 @@ void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid, > * Max Invs Pending (MIP) is set to 0 for now until we have DIT in > * ECAP. > */ > - desc.qw1 |= addr & ~mask; > - if (size_order) > + if (addr & ~VTD_PAGE_MASK) > + pr_warn_ratelimited("Invalidate non-page aligned address %llx\n", addr); > + > + /* Take page address */ > + desc.qw1 |= QI_DEV_EIOTLB_ADDR(addr); > + > + if (size_order) { > + /* > + * Existing 0s in address below size_order may be the least > + * significant bit, we must set them to 1s to avoid having > + * smaller size than desired. Shouldn't you test the input addr against the size_order. Aren't they supposed to be consistent? Otherwise one should emit a warning at least? > + */ > + desc.qw1 |= GENMASK_ULL(size_order + VTD_PAGE_SHIFT, > + VTD_PAGE_SHIFT); nit: instead of working directly on .qw1, couldn't you perform all those manipulations directly on addr? and eventually override qw1 at the end? > + /* Clear size_order bit to indicate size */ > + desc.qw1 &= ~mask; > + /* Set the S bit to indicate flushing more than 1 page */ > desc.qw1 |= QI_DEV_EIOTLB_SIZE; > + } > > qi_submit_sync(iommu, &desc, 1, 0); > } > Thanks Eric