From patchwork Tue Nov 16 18:57:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 328982 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAGIwuxp021270 for ; Tue, 16 Nov 2010 18:58:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757132Ab0KPS5w (ORCPT ); Tue, 16 Nov 2010 13:57:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29557 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756185Ab0KPS5v (ORCPT ); Tue, 16 Nov 2010 13:57:51 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAGIvTXr026154 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 16 Nov 2010 13:57:29 -0500 Received: from [10.3.113.132] (ovpn-113-132.phx2.redhat.com [10.3.113.132]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAGIvS7C016191; Tue, 16 Nov 2010 13:57:28 -0500 Subject: Re: [PATCH] vfio: fix config virtualization, esp command byte From: Alex Williamson To: Tom Lyon Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org In-Reply-To: <1289930061.3069.5.camel@x201> References: <4cd9f0d6.jnHBr6PBphKwDwhM%pugs@cisco.com> <1289930061.3069.5.camel@x201> Date: Tue, 16 Nov 2010 11:57:27 -0700 Message-ID: <1289933847.3069.8.camel@x201> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 16 Nov 2010 18:58:57 +0000 (UTC) diff --git a/drivers/vfio/vfio_pci_config.c b/drivers/vfio/vfio_pci_config.c index 7132ac4..422d7b1 100644 --- a/drivers/vfio/vfio_pci_config.c +++ b/drivers/vfio/vfio_pci_config.c @@ -964,11 +964,6 @@ static int vfio_config_rwbyte(int write, return 0; } - if (write) { - if (copy_from_user(&newval, buf, 1)) - return -EFAULT; - } - if (~virt) { /* mix of real and virt bits */ /* update vconfig with latest hw bits */ ret = vfio_read_config_byte(vdev, pos, &realbits); @@ -978,9 +973,14 @@ static int vfio_config_rwbyte(int write, (vdev->vconfig[pos] & virt) | (realbits & ~virt); } - /* update vconfig with writeable bits */ - vdev->vconfig[pos] = - (vdev->vconfig[pos] & ~wr) | (newval & wr); + if (write) { + if (copy_from_user(&newval, buf, 1)) + return -EFAULT; + + /* update vconfig with writeable bits */ + vdev->vconfig[pos] = + (vdev->vconfig[pos] & ~wr) | (newval & wr); + } /* * Now massage virtual fields