Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp793507pxj; Fri, 7 May 2021 22:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeALoWCUPpEVrmXGoH/RuIRkBOKRALxjYnBBa4RlefHgoyl5qLO8U4oS/Jsc7KV6dgZE89 X-Received: by 2002:a17:90a:4588:: with SMTP id v8mr26940508pjg.195.1620450629086; Fri, 07 May 2021 22:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620450629; cv=none; d=google.com; s=arc-20160816; b=L3OvoPH08YP2lYjyY/UtKZoNrE3GxR1adRf7+wz5bFU111mOm44Ji5ocByYrIkB/tU e6jAGGmwJJVkd+Gv2COZsJHz8yFSRR+oMk5n3KwGYSThkUyclyHkunmOQ7gRlBVDo3Wf iKDTrxMsp5urAOFfmk9SrEvm6s2fiYW69lUMhyhrWdupx6fk49Q6IO7xH+wF+Qn8QvD0 nsRxCGS2+WEHlMROaXYPqMp4P53uVbOYVUe1blS1V3oMrOMjwEeeu3CYL6rRd9bk1dt5 obhpO+oJ2WcfSaqzouNIgoZjtLJGAAaA+ymI1OSRl/0saM30ol+tfhdmtu8nptN0HXC/ bufw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=qCU8arB0T5o/wbUzfm2GY1e3Y91/al6CtTaeEsbWyxk=; b=nfChJUYhFx+sw/LCdv04MpJOYgy1+dzVuOJVLjltjJzxJwkWwt/jkk4WrufN6gf35V 2McvwrTZaYBAlyn+9ODLFBKFrPWiDhxgdaPjfwWSWif+5DtDCw9WPl8GN/4joIyEoRns nhLUuWWdykQNTSbJTOE1ZJabXOS603sy9ORSkEhjU5z7mp+o1x2pPuWwLWr8lNjMXFrZ cjYoAA9bJcPS1cn0+iwn288g9ivbeK20F1v9L1VjRRqY4Y8kCrW1qCn18M6U3aQPusam UniKywDNdQy/tY7dnMOSsrXFV6ia/1s4fCTzncKKseshwi3EkJXC2dOVvvPJw9IDHdco jexw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h3si9004263pls.293.2021.05.07.22.10.16; Fri, 07 May 2021 22:10:29 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230417AbhEHFJx (ORCPT + 99 others); Sat, 8 May 2021 01:09:53 -0400 Received: from mga05.intel.com ([192.55.52.43]:44649 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbhEHFJw (ORCPT ); Sat, 8 May 2021 01:09:52 -0400 IronPort-SDR: PV/luzZuE82VIC9b1M9LifUL7iKLG6C5D846ri5UNlEBF/+7VtdzUPdCRZBejh38UV83ns7JAu jZpiswjunfYg== X-IronPort-AV: E=McAfee;i="6200,9189,9977"; a="284333992" X-IronPort-AV: E=Sophos;i="5.82,282,1613462400"; d="asc'?scan'208";a="284333992" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2021 22:08:52 -0700 IronPort-SDR: Dv3dGDws6GEtevLyQTECKkR1AuLUReLH1KTJFez646MGA6b4ixaiVRy+90+G3n+Xr5SvbCm8K9 suwx2W96fVUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,282,1613462400"; d="asc'?scan'208";a="460405312" Received: from zhen-hp.sh.intel.com (HELO zhen-hp) ([10.239.160.147]) by FMSMGA003.fm.intel.com with ESMTP; 07 May 2021 22:08:50 -0700 Date: Sat, 8 May 2021 12:50:04 +0800 From: Zhenyu Wang To: Alex Williamson Cc: tkffaul@outlook.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfio/pci: Sanity check IGD OpRegion Size Message-ID: <20210508045004.GH4589@zhen-hp.sh.intel.com> Reply-To: Zhenyu Wang References: <162041357421.21800.16214130780777455390.stgit@omen> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="KFztAG8eRSV9hGtP" Content-Disposition: inline In-Reply-To: <162041357421.21800.16214130780777455390.stgit@omen> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --KFztAG8eRSV9hGtP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021.05.07 12:53:17 -0600, Alex Williamson wrote: > The size field of the IGD OpRegion table is supposed to indicate table > size in KB, but we've seen at least one report of a BIOS that appears > to incorrectly report size in bytes. The default size is 8 (*1024 =3D > 8KB), but an incorrect implementation may report 8192 (*1024 =3D 8MB) > and can cause a variety of mapping errors. >=20 > It's believed that 8MB would be an implausible, if not absurd, actual > size, so we can probably be pretty safe in assuming this is a BIOS bug > where the intended size is likely 8KB. >=20 > Reported-by: Travis Faulhaber > Tested-by: Travis Faulhaber > Signed-off-by: Alex Williamson > --- > drivers/vfio/pci/vfio_pci_igd.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/vfio/pci/vfio_pci_igd.c b/drivers/vfio/pci/vfio_pci_= igd.c > index 228df565e9bc..c89a4797cd18 100644 > --- a/drivers/vfio/pci/vfio_pci_igd.c > +++ b/drivers/vfio/pci/vfio_pci_igd.c > @@ -86,7 +86,16 @@ static int vfio_pci_igd_opregion_init(struct vfio_pci_= device *vdev) > return -EINVAL; > } > =20 > - size *=3D 1024; /* In KB */ > + /* > + * The OpRegion size field is specified as size in KB, but there have b= een > + * user reports where this field appears to report size in bytes. If we > + * read 8192, assume this is the case. > + */ > + if (size =3D=3D OPREGION_SIZE) > + pci_warn(vdev->pdev, > + "BIOS Bug, IGD OpRegion reports invalid size, assuming default 8KB\n= "); > + else > + size *=3D 1024; /* In KB */ > =20 > /* > * Support opregion v2.1+ >=20 Reviewed-by: Zhenyu Wang thanks --KFztAG8eRSV9hGtP Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQTXuabgHDW6LPt9CICxBBozTXgYJwUCYJYYcwAKCRCxBBozTXgY J9gLAJ9WZQAELAZanHt41Fm37Zpywbd/5wCgnfwh7QDlG6+zsX/eLRycHAm9RmY= =mQOk -----END PGP SIGNATURE----- --KFztAG8eRSV9hGtP--