Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1271921rbb; Mon, 26 Feb 2024 04:31:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX9omDtLel5NHNi+hEDKXe+PyW1yRkp4OGCrUeoDs6IY4RCYX5x1dP7z2QqOErJY9qRH9HVgYizi8thGer2aLjE7zXf+hSWJf+IMHiUMw== X-Google-Smtp-Source: AGHT+IEuGvDzlASr8ICevLXYvpTDtW7+EgJPGOQ3c8JEOIm7yyqN4wNfdI/KfYsnIkLirtaVX8uR X-Received: by 2002:a17:906:f9cc:b0:a3f:d2e2:4ce5 with SMTP id lj12-20020a170906f9cc00b00a3fd2e24ce5mr4433801ejb.29.1708950707988; Mon, 26 Feb 2024 04:31:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708950707; cv=pass; d=google.com; s=arc-20160816; b=VHNgCRmbFwNkIraFdX+ESdP/uvzlTF7EG5DSC5s7FSsLnYMUWfYaFXKPDIIH79ywjJ NQTgAdOrlIs/gu/SUJx2Jug22lSoc4sxsOrun62SAn3i/xQGdIAIrF2elriltOwmBxWU j3hQqbsNHV6hHwKUq2tT1466qjVPHpszrQJlQsQaHhIP0D/KlN/fNKoKKv7tYZSiwy76 cUNegoeIzZqewuQER+X8R9kZsLVWN0YVPOFzq1UfAVNz78h686rSFIhbFgnclHkkHKwq i9hHo/nO7kGRekUB6U9TAgKUyYE1yvOeEFLJy4wfc9yzgXAiEYjPNhQcq9LPSkU0HqJ8 BexQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=acfhiAEYKv/fRZfkXsnQvHufoF9GiESpiHmHcvN4pIo=; fh=NxEgvf8Rw6A11ITJWFIYtOfb5rphg3RFyVjPJ/rcJm4=; b=gndnPv8KvjB5BxX9lzCfmwFxJ+LTSMXCIVWONUdX8643iu3QOec5uhg4+kXQIq579T IBzLd5/z1iMuKScZhjclbiqpeh9KpFeWJwr/Vt1wcsG+E7wz8Wze+qXyGmEMKo1ZokwC 76ZnycPLynVfur/iPAkMyeC8vM0nfVuKQqWp8EKUS55xan3vioxhKHa9Bb4UZypj2pGF /16hcvueeJ9LEhzLgH191sZEl5XOufPPqdHc17FIwHhmPkY99GVFpuVw2wQ0V79zQWg0 +MUsArfH9wsNkR0s5k8U8iTQjid9YYZKlkBjx6jb14Xl32LKSIH4hBVmKh4dz1rYs5J0 Fllg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-81356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dn22-20020a17090794d600b00a3e4ecbbed6si2137484ejc.597.2024.02.26.04.31.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:31:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-81356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6A4571F2BFD1 for ; Mon, 26 Feb 2024 12:21:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8716605A4; Mon, 26 Feb 2024 12:21:47 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECF891B27D; Mon, 26 Feb 2024 12:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708950107; cv=none; b=eA3JodmapVfBbQJZgvQ0iBRHpJIxmvlwWLmhOgBOx5XSvGsR1lw1o+FitHhktCO8w0bpUsB9fFs7uJhHX+8zupx94Pl9Q9iEoyr1Cg5t4QIunczEsuU7wM+5OWk7b3gJWxXYWSl5Kh/4N0gkSKe/Z1RMVkC+mBvqfqsk4/4YoDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708950107; c=relaxed/simple; bh=pi3BrUr3ur1vJpL7LOfjfmoG+suaosBkg1tWLQHk5BU=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eDJypdXrTtigFt3O3M8nJYLrQhB8Y0L6mgB7jMdvXtMyZ7rNJRVOxdBQOPOjVj1v1W5tyx9TmzeRfiztpf0j0mdqzTFdh4+YeTcFBAtr6VXKejCpsHWSTnDruzsaEd/in4C7Ldktiz3KB87zFZim1XrskglFQ2IPdV0g0DpPBwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Tk04k1G1Pz6K9M8; Mon, 26 Feb 2024 20:17:58 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 5C7CA1400DB; Mon, 26 Feb 2024 20:21:41 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 26 Feb 2024 12:21:40 +0000 Date: Mon, 26 Feb 2024 12:21:39 +0000 From: Jonathan Cameron To: John Groves CC: John Groves , Jonathan Corbet , "Dan Williams" , Vishal Verma , Dave Jiang , "Alexander Viro" , Christian Brauner , "Jan Kara" , Matthew Wilcox , , , , , , , Dave Chinner , Christoph Hellwig , , Subject: Re: [RFC PATCH 04/20] dev_dax_iomap: Save the kva from memremap Message-ID: <20240226122139.0000135b@Huawei.com> In-Reply-To: <66620f69fa3f3664d955649eba7da63fdf8d65ad.1708709155.git.john@groves.net> References: <66620f69fa3f3664d955649eba7da63fdf8d65ad.1708709155.git.john@groves.net> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100005.china.huawei.com (7.191.160.25) To lhrpeml500005.china.huawei.com (7.191.163.240) On Fri, 23 Feb 2024 11:41:48 -0600 John Groves wrote: > Save the kva from memremap because we need it for iomap rw support > > Prior to famfs, there were no iomap users of /dev/dax - so the virtual > address from memremap was not needed. > > Also: in some cases dev_dax_probe() is called with the first > dev_dax->range offset past pgmap[0].range. In those cases we need to > add the difference to virt_addr in order to have the physaddr's in > dev_dax->ranges match dev_dax->virt_addr. Probably good to have info on when this happens and preferably why this dragon is there. > > Dragons... > > Signed-off-by: John Groves > --- > drivers/dax/dax-private.h | 1 + > drivers/dax/device.c | 15 +++++++++++++++ > 2 files changed, 16 insertions(+) > > diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h > index 446617b73aea..894eb1c66b4a 100644 > --- a/drivers/dax/dax-private.h > +++ b/drivers/dax/dax-private.h > @@ -63,6 +63,7 @@ struct dax_mapping { > struct dev_dax { > struct dax_region *region; > struct dax_device *dax_dev; > + u64 virt_addr; Why as a u64? If it's a virt address why not just void *? > unsigned int align; > int target_node; > bool dyn_id; > diff --git a/drivers/dax/device.c b/drivers/dax/device.c > index 40ba660013cf..6cd79d00fe1b 100644 > --- a/drivers/dax/device.c > +++ b/drivers/dax/device.c > @@ -372,6 +372,7 @@ static int dev_dax_probe(struct dev_dax *dev_dax) > struct dax_device *dax_dev = dev_dax->dax_dev; > struct device *dev = &dev_dax->dev; > struct dev_pagemap *pgmap; > + u64 data_offset = 0; > struct inode *inode; > struct cdev *cdev; > void *addr; > @@ -426,6 +427,20 @@ static int dev_dax_probe(struct dev_dax *dev_dax) > if (IS_ERR(addr)) > return PTR_ERR(addr); > > + /* Detect whether the data is at a non-zero offset into the memory */ > + if (pgmap->range.start != dev_dax->ranges[0].range.start) { > + u64 phys = (u64)dev_dax->ranges[0].range.start; Why the cast? Ranges use u64s internally. > + u64 pgmap_phys = (u64)dev_dax->pgmap[0].range.start; > + u64 vmemmap_shift = (u64)dev_dax->pgmap[0].vmemmap_shift; > + > + if (!WARN_ON(pgmap_phys > phys)) > + data_offset = phys - pgmap_phys; > + > + pr_notice("%s: offset detected phys=%llx pgmap_phys=%llx offset=%llx shift=%llx\n", > + __func__, phys, pgmap_phys, data_offset, vmemmap_shift); pr_debug() + dynamic debug will then deal with __func__ for you. > + } > + dev_dax->virt_addr = (u64)addr + data_offset; > + > inode = dax_inode(dax_dev); > cdev = inode->i_cdev; > cdev_init(cdev, &dax_fops);