Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp819775imc; Sat, 16 Mar 2019 17:34:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsc8M8s0sV/htVFjkoFX6sdmMG5517amxV2AEp1mVy/S4T6PQ3kRK/lcaULxUUbuGQ7Wpm X-Received: by 2002:a62:b415:: with SMTP id h21mr11746661pfn.26.1552782870791; Sat, 16 Mar 2019 17:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552782870; cv=none; d=google.com; s=arc-20160816; b=pMm3k3Pu32YEdUylxxBGbKzt8Y5dOC6Kob6cW3dkOVa0HpAo872vbLLkwHNeOW6qIz tID1PiFX7oE2s5lAZ14w/5HXwu4enHmK3d++Yu2xSC5gasg3n9e2ykJqpjagN5wH5rWh e72xsl31VxCPlOkW6GNQppCVG6jeS7UgiuT0qWAmukWu40eI6bt/1IzIEkll26yJstxp aYyVYXaIU9UJd7qj7jNg7zsu62YaP8ibdL+jNdxkYhTq8EGKb4neNbsvfu2SvdU6WzuG m3xF21JK8LwEvtFUMf5ilJ1rji8Cn+pEbNo7fyeMBg8DKM26NapsuLN2s0biO2jV9Wz4 waOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=mopi9pYcuk5FgbIWQDOVaPV2FyH+POS3o4i2Hyc89Qs=; b=FvMYeipIVURUlY07YdxUhH8G/H08fJZL9CSuMSeQ0ZFm2SN7otrEg/qQabTdppWSRo /wkq3gDhS60xNq3X8vZNvN61bg/k31OR8e+pexJj8GffB1Wz3ImSiQc3EszFmTaOpdOH dQH0GvZnuGmRgIlHgaLOFEXJXRHVrqwWfBrsle2NDAjWUzmxhwwg2VZa1ZUexeMxZfob aav6ycAhG61/Qpwi26gLgLZH3moRj4DSnygANQ/ucMKANRaV6tsMoABqNYeLfGIMc/+F PfgM3GjbUVomR8by8v0oMlQx4c2b9yK4PWenBR5sbvqApNL9LzL3Q+U7qFkZBriVhLTl DVug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HOG+M916; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s75si5592290pfa.217.2019.03.16.17.34.14; Sat, 16 Mar 2019 17:34:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HOG+M916; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727130AbfCQAdi (ORCPT + 99 others); Sat, 16 Mar 2019 20:33:38 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:40240 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726828AbfCQAdh (ORCPT ); Sat, 16 Mar 2019 20:33:37 -0400 Received: by mail-qt1-f196.google.com with SMTP id f11so14201438qti.7; Sat, 16 Mar 2019 17:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mopi9pYcuk5FgbIWQDOVaPV2FyH+POS3o4i2Hyc89Qs=; b=HOG+M916fO/a44kAAbke/eNCtkxVTKX1h87cn8+wQBS1F5I46vwtYrB0ZWD1ulOMAa /2MjgsLmV5vbCI/n9DtMPGfA2WUDGV2jHZ57y2qIh1W3QlmmcH0E9Nyc3Bcl6eUqGgdS ku2jzHXmLLGq9Of9ke0ZZCoJSAwlky0ENa9OrWgi9LGru9GWBsy9Liw98FKx3ibr9raC 1DkGjgI7huOWOfE4f7vfPuDxLmO4FcjRexBxW0HDhioZcxpzkUwli3mtIOhTS8UCAMKn j8HurfSGeor2aLD70GqzzMirJ+3tnMxD25iYhUT34gUBK8F1DL4ZZF5kHmShzys5tLCt DUWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mopi9pYcuk5FgbIWQDOVaPV2FyH+POS3o4i2Hyc89Qs=; b=F5l06HEfqpcxAz99DVtlwVPegmbJhOPrPtm9PMweNY2xOuhLwRu+PQ2/fcqkahlRAY l/8rg23EhxKv44+GG93FR4J/2ts0nS+yztZdgSmiERaz60xA5AkbvqOee20jO/a6kAuI 8bI5GrDLFVSMz51X8C9ijybU6zlufMNrmemLu1DEH+hKJWf1RmyYqO+MUnsg8y2mMaZs zaJlGKpYdvfMeAluQbWvCqY9zrAMc1D5bD8vWUiM7LUxIJIQr8dHJCG99HA4VYiCuQFh yDeQuH7FYpcf67q7zp0zB2dangBJAvrHNeeD10aS7a0J1rywMoZ0S85k9LlPatFQNxtS Ab8A== X-Gm-Message-State: APjAAAXi5k69zNycyPwccvCQ3oFW3siS4/wNAlhYzbiYeoteYoqouvRn Oxy6sob4WO+HRk23Ph1cHACZtQ0wxNw4bt7QRv7dXF6M X-Received: by 2002:a0c:8a61:: with SMTP id 30mr7916599qvu.110.1552782816292; Sat, 16 Mar 2019 17:33:36 -0700 (PDT) MIME-Version: 1.0 References: <20181210171318.16998-1-vgoyal@redhat.com> <20181210171318.16998-19-vgoyal@redhat.com> In-Reply-To: <20181210171318.16998-19-vgoyal@redhat.com> From: Liu Bo Date: Sat, 16 Mar 2019 17:33:25 -0700 Message-ID: Subject: Re: [PATCH 18/52] virtio-fs: Map cache using the values from the capabilities To: Vivek Goyal Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, miklos@szeredi.hu, Stefan Hajnoczi , dgilbert@redhat.com, sweil@redhat.com, swhiteho@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 10, 2018 at 9:57 AM Vivek Goyal wrote: > > Instead of assuming we had the fixed bar for the cache, use the > value from the capabilities. > > Signed-off-by: Dr. David Alan Gilbert > --- > fs/fuse/virtio_fs.c | 32 +++++++++++++++++--------------- > 1 file changed, 17 insertions(+), 15 deletions(-) > > diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c > index 60d496c16841..55bac1465536 100644 > --- a/fs/fuse/virtio_fs.c > +++ b/fs/fuse/virtio_fs.c > @@ -14,11 +14,6 @@ > #include > #include "fuse_i.h" > > -enum { > - /* PCI BAR number of the virtio-fs DAX window */ > - VIRTIO_FS_WINDOW_BAR = 2, > -}; > - > /* List of virtio-fs device instances and a lock for the list */ > static DEFINE_MUTEX(virtio_fs_mutex); > static LIST_HEAD(virtio_fs_instances); > @@ -518,7 +513,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) > struct dev_pagemap *pgmap; > struct pci_dev *pci_dev; > phys_addr_t phys_addr; > - size_t len; > + size_t bar_len; > int ret; > u8 have_cache, cache_bar; > u64 cache_offset, cache_len; > @@ -551,17 +546,13 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) > } > > /* TODO handle case where device doesn't expose BAR? */ > - ret = pci_request_region(pci_dev, VIRTIO_FS_WINDOW_BAR, > - "virtio-fs-window"); > + ret = pci_request_region(pci_dev, cache_bar, "virtio-fs-window"); > if (ret < 0) { > dev_err(&vdev->dev, "%s: failed to request window BAR\n", > __func__); > return ret; > } > > - phys_addr = pci_resource_start(pci_dev, VIRTIO_FS_WINDOW_BAR); > - len = pci_resource_len(pci_dev, VIRTIO_FS_WINDOW_BAR); > - > mi = devm_kzalloc(&pci_dev->dev, sizeof(*mi), GFP_KERNEL); > if (!mi) > return -ENOMEM; > @@ -586,6 +577,17 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) > pgmap->ref = &mi->ref; > pgmap->type = MEMORY_DEVICE_FS_DAX; > > + phys_addr = pci_resource_start(pci_dev, cache_bar); > + bar_len = pci_resource_len(pci_dev, cache_bar); > + > + if (cache_offset + cache_len > bar_len) { > + dev_err(&vdev->dev, > + "%s: cache bar shorter than cap offset+len\n", > + __func__); > + return -EINVAL; > + } > + phys_addr += cache_offset; > + > /* Ideally we would directly use the PCI BAR resource but > * devm_memremap_pages() wants its own copy in pgmap. So > * initialize a struct resource from scratch (only the start > @@ -594,7 +596,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) > pgmap->res = (struct resource){ > .name = "virtio-fs dax window", > .start = phys_addr, > - .end = phys_addr + len, > + .end = phys_addr + cache_len, Just in case you haven't noticed/fixed this problem, it should be + .end = phys_addr + cache_len - 1, because resource_size() counts %size as "end - start + 1". The end result of the above is a "conflicting page map" warning when specifying a second virtio-fs pci device. I'll send a patch for this, and feel free to take it along with the patchset if needed. thanks, liubo > }; > > fs->window_kaddr = devm_memremap_pages(&pci_dev->dev, pgmap); > @@ -607,10 +609,10 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) > return ret; > > fs->window_phys_addr = phys_addr; > - fs->window_len = len; > + fs->window_len = cache_len; > > - dev_dbg(&vdev->dev, "%s: window kaddr 0x%px phys_addr 0x%llx len %zu\n", > - __func__, fs->window_kaddr, phys_addr, len); > + dev_dbg(&vdev->dev, "%s: cache kaddr 0x%px phys_addr 0x%llx len %llx\n", > + __func__, fs->window_kaddr, phys_addr, cache_len); > > fs->dax_dev = alloc_dax(fs, NULL, &virtio_fs_dax_ops); > if (!fs->dax_dev) > -- > 2.13.6 >