From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753974AbbFRIPs (ORCPT ); Thu, 18 Jun 2015 04:15:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43156 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932164AbbFRIOr (ORCPT ); Thu, 18 Jun 2015 04:14:47 -0400 Message-ID: <1434615280.4968.14.camel@redhat.com> Subject: Re: [PATCH] virtio-pci: alloc only resources actually used. From: Gerd Hoffmann To: "Michael S. Tsirkin" Cc: "open list:VIRTIO CORE, NET..." , open list Date: Thu, 18 Jun 2015 10:14:40 +0200 In-Reply-To: <20150616160052-mutt-send-email-mst@redhat.com> References: <1434463073-29648-1-git-send-email-kraxel@redhat.com> <20150616160052-mutt-send-email-mst@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, > > +static struct resource *request_capability(struct pci_dev *dev, int off, > > + const char *name) > > +{ > > + u8 bar; > > + u32 offset, length; > > + > > + pci_read_config_byte(dev, off + offsetof(struct virtio_pci_cap, > > + bar), > > + &bar); > > + pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, offset), > > + &offset); > > + pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, length), > > + &length); > > + > > + return request_mem_region(pci_resource_start(dev, bar) + offset, > > + length, name); > > +} > > + > > For device config, this might request too much. The spec says: > The drivers SHOULD only map part of configuration structure large enough > for device operation. We don't map it here though. We just reserve what belongs to virtio according to the capabilities. > I think you should limit this to PAGE_SIZE like we do for map_capability. notify is much larger than PAGE_SIZE. > > err = -EINVAL; > > vp_dev->common = map_capability(pci_dev, common, > > sizeof(struct virtio_pci_common_cfg), 4, > > map_capability has a bunch of checks in place to validate the capability > structure. With request_capability called earlier, they are now done too > late. Hmm, lets move the checks to find_capability then? cheers, Gerd From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gerd Hoffmann Subject: Re: [PATCH] virtio-pci: alloc only resources actually used. Date: Thu, 18 Jun 2015 10:14:40 +0200 Message-ID: <1434615280.4968.14.camel@redhat.com> References: <1434463073-29648-1-git-send-email-kraxel@redhat.com> <20150616160052-mutt-send-email-mst@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20150616160052-mutt-send-email-mst@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: "Michael S. Tsirkin" Cc: open list , "open list:VIRTIO CORE, NET..." List-Id: virtualization@lists.linuxfoundation.org Hi, > > +static struct resource *request_capability(struct pci_dev *dev, int off, > > + const char *name) > > +{ > > + u8 bar; > > + u32 offset, length; > > + > > + pci_read_config_byte(dev, off + offsetof(struct virtio_pci_cap, > > + bar), > > + &bar); > > + pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, offset), > > + &offset); > > + pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, length), > > + &length); > > + > > + return request_mem_region(pci_resource_start(dev, bar) + offset, > > + length, name); > > +} > > + > > For device config, this might request too much. The spec says: > The drivers SHOULD only map part of configuration structure large enough > for device operation. We don't map it here though. We just reserve what belongs to virtio according to the capabilities. > I think you should limit this to PAGE_SIZE like we do for map_capability. notify is much larger than PAGE_SIZE. > > err = -EINVAL; > > vp_dev->common = map_capability(pci_dev, common, > > sizeof(struct virtio_pci_common_cfg), 4, > > map_capability has a bunch of checks in place to validate the capability > structure. With request_capability called earlier, they are now done too > late. Hmm, lets move the checks to find_capability then? cheers, Gerd