Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1320494rwb; Thu, 6 Oct 2022 11:15:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6LR1GqtaMk9IeYkv5Tbf+1OM0RciCDPCRj0PKPIYBTlov4Hg/WPIR1tNr4Ly4wIiV67fBb X-Received: by 2002:a63:490:0:b0:458:f364:3e03 with SMTP id 138-20020a630490000000b00458f3643e03mr937956pge.492.1665080152515; Thu, 06 Oct 2022 11:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665080152; cv=none; d=google.com; s=arc-20160816; b=iRaPwXQOW6PcdETB9rKy4WbEwSmcrHmcTMWMLdgEIN99Q+8ukt3P94ZEmspjJY7ny/ NzJmRsU7s9m69er3yzPs5UIpUpqjzkUQP6Ui9NNidxkW2EeIGgO68stKvNNwBtrFHajD pGpt9/7qbr2eAMj0JcYNbQ8H0erctSFhN1m2/8itorch6/FQRaR8zG3JIr9sKFW+RNPi jJuRVAyYvk3wL8bgZqAeFyx9OcvRIggUcrxmzLqbX8mM13GiDqmmvg257IEvSSyfjCjZ c1WBFsxRg6o7ET1iKrahjCzq88HgnQn5fxy6jRFMekGHaZGzUaf9ciy7Xi6xyMmxPqXS OawA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=9C7ByqeSaw8akdMJt6lEHhq8DB9Wv7neSKwYSa568Bc=; b=oPIYb9Q3hmKyrj/PUCfzi7/pcGqE0MsRTtaZWUG+bqVUWC7udczzQMtADBsMgT8ne6 +S5Q8ZPV3VQE5M5xQypQ3jvITJV9q/gXOWtUA2uVJYEeVXL7VUwhBW60pVs5SJu3xKW1 pIqSIUYTlj5EIsS2ng7N0u4t6zuJYxscH4OTwbEQPgfBVYdlcJK4QzQAKJUh9yQsgX4b qmbK44XxlQGzB4qvCKb78CqNL0GmYVMSBg+iZKqEUAdxfAJR0qZPCUtsEALrPbZyPb3F CP3yNG6hBDxb2MonRPE6MBMwBsintZaqd/UMULfDvjel0vwxxEicNEY8w1romMf0UKZh mGIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GBm0FgVh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e124-20020a636982000000b0042bc6e8d3f7si98842pgc.642.2022.10.06.11.15.23; Thu, 06 Oct 2022 11:15:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GBm0FgVh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230307AbiJFR7k (ORCPT + 99 others); Thu, 6 Oct 2022 13:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbiJFR7i (ORCPT ); Thu, 6 Oct 2022 13:59:38 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F711DDF for ; Thu, 6 Oct 2022 10:59:36 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id nb11so6311768ejc.5 for ; Thu, 06 Oct 2022 10:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=9C7ByqeSaw8akdMJt6lEHhq8DB9Wv7neSKwYSa568Bc=; b=GBm0FgVhh/SmHkKRk0VR06xZUv2s5FfWzez1BIME/djcjD8cCDknzdtn1Fzhu5g/kg S0nic5/R50Bm/zdW792pnzivTdOkci4ZuJd6UtTqZkWQR+bgoIeaRseAhInbl5QEe0et 8N9tZHW6xeR/VzU5/A/FgJuS8BCAfMW2jbFDvQk6P/9FFkXYFHolvelHSX0+cC3UQHsT sbTIVXvPoU0hKTnRuQIheFe9SkyQKUzCkxiQfgRPn5TKhablgXDgTJotMao2Y2fAanLQ K2x1hQrwtmzM/aRWdW6b7HIO9mMYR5nU8rLvbd3Nhsd4eWQlW3wVo7MOTKd5tTGzY/XV cC1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9C7ByqeSaw8akdMJt6lEHhq8DB9Wv7neSKwYSa568Bc=; b=QEKA+cEzU+yeTIfdOSP7gJzHAhvTfOgkSwRvcbpAPPh0R/kZ6jr9jRxWI4E5hUkC1S IBm5gyhjw0RUsW329hCVEimH4/IIzv28QQA1hwBH3L4h3MVxpEwWxrCLmFdKQgFvePd7 7eEYn2V4alhVjSOdGMPRQ3n3ssdAHijWphBNZ4oZxn4+Ntyg2kBdPgds4J/uPN3L7mcx R+lm4ifUHVCIv36c7MPb2KkB7NIwr3yRyzuJggGmEEb1C1CqNl8n87vd1Q0P5pY9m0nh K1YKNKqrBizVGri7wY2NmdK+46GXtEOyT2S/9BrAMimpeWAI+rJjNDrCq2Q8ZAZJW23o SM0w== X-Gm-Message-State: ACrzQf14VKpFP3kSKUOxVS9LsCs0+Z8/epZRiGwzwx9m4/iJAR0/UNsv ZyTRdp1GalbPHiuAYuyye97PHXTb7Js0ag== X-Received: by 2002:a17:907:8a0a:b0:78d:2ecb:63e6 with SMTP id sc10-20020a1709078a0a00b0078d2ecb63e6mr919611ejc.620.1665079174812; Thu, 06 Oct 2022 10:59:34 -0700 (PDT) Received: from [192.168.1.93] (adsl-75.176.58.241.tellas.gr. [176.58.241.75]) by smtp.gmail.com with ESMTPSA id b17-20020a17090630d100b0078b03d57fa7sm45931ejb.34.2022.10.06.10.59.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Oct 2022 10:59:34 -0700 (PDT) Message-ID: <96a16b32-0950-b538-65e5-9955ed8cc529@gmail.com> Date: Thu, 6 Oct 2022 20:59:33 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] xen/virtio: Convert PAGE_SIZE/PAGE_SHIFT/PFN_UP to Xen counterparts Content-Language: en-US To: Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Oleksandr Tyshchenko , Stefano Stabellini , Juergen Gross References: <20221006120912.1948459-1-olekstysh@gmail.com> From: Xenia Ragiadakou In-Reply-To: <20221006120912.1948459-1-olekstysh@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/6/22 15:09, Oleksandr Tyshchenko wrote: > From: Oleksandr Tyshchenko > > Although XEN_PAGE_SIZE is equal to PAGE_SIZE (4KB) for now, it would > be more correct to use Xen specific #define-s as XEN_PAGE_SIZE can > be changed at some point in the future. > > Signed-off-by: Oleksandr Tyshchenko > --- > Cc: Juergen Gross > Cc: Xenia Ragiadakou > > As it was proposed at: > https://lore.kernel.org/xen-devel/20221005174823.1800761-1-olekstysh@gmail.com/ > > Should go in only after that series. > --- > drivers/xen/grant-dma-ops.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c > index c66f56d24013..5392fdc25dca 100644 > --- a/drivers/xen/grant-dma-ops.c > +++ b/drivers/xen/grant-dma-ops.c > @@ -31,12 +31,12 @@ static DEFINE_XARRAY_FLAGS(xen_grant_dma_devices, XA_FLAGS_LOCK_IRQ); > > static inline dma_addr_t grant_to_dma(grant_ref_t grant) > { > - return XEN_GRANT_DMA_ADDR_OFF | ((dma_addr_t)grant << PAGE_SHIFT); > + return XEN_GRANT_DMA_ADDR_OFF | ((dma_addr_t)grant << XEN_PAGE_SHIFT); > } With this change, can the offset added to the dma handle, generated by grant_to_dma(), be the offset in the page? Couldn't it corrupt the grant ref? > > static inline grant_ref_t dma_to_grant(dma_addr_t dma) > { > - return (grant_ref_t)((dma & ~XEN_GRANT_DMA_ADDR_OFF) >> PAGE_SHIFT); > + return (grant_ref_t)((dma & ~XEN_GRANT_DMA_ADDR_OFF) >> XEN_PAGE_SHIFT); > } > > static struct xen_grant_dma_data *find_xen_grant_dma_data(struct device *dev) > @@ -79,7 +79,7 @@ static void *xen_grant_dma_alloc(struct device *dev, size_t size, > unsigned long attrs) > { > struct xen_grant_dma_data *data; > - unsigned int i, n_pages = PFN_UP(size); > + unsigned int i, n_pages = XEN_PFN_UP(size); > unsigned long pfn; > grant_ref_t grant; > void *ret; > @@ -91,14 +91,14 @@ static void *xen_grant_dma_alloc(struct device *dev, size_t size, > if (unlikely(data->broken)) > return NULL; > > - ret = alloc_pages_exact(n_pages * PAGE_SIZE, gfp); > + ret = alloc_pages_exact(n_pages * XEN_PAGE_SIZE, gfp); > if (!ret) > return NULL; > > pfn = virt_to_pfn(ret); > > if (gnttab_alloc_grant_reference_seq(n_pages, &grant)) { > - free_pages_exact(ret, n_pages * PAGE_SIZE); > + free_pages_exact(ret, n_pages * XEN_PAGE_SIZE); > return NULL; > } > > @@ -116,7 +116,7 @@ static void xen_grant_dma_free(struct device *dev, size_t size, void *vaddr, > dma_addr_t dma_handle, unsigned long attrs) > { > struct xen_grant_dma_data *data; > - unsigned int i, n_pages = PFN_UP(size); > + unsigned int i, n_pages = XEN_PFN_UP(size); > grant_ref_t grant; > > data = find_xen_grant_dma_data(dev); > @@ -138,7 +138,7 @@ static void xen_grant_dma_free(struct device *dev, size_t size, void *vaddr, > > gnttab_free_grant_reference_seq(grant, n_pages); > > - free_pages_exact(vaddr, n_pages * PAGE_SIZE); > + free_pages_exact(vaddr, n_pages * XEN_PAGE_SIZE); > } > > static struct page *xen_grant_dma_alloc_pages(struct device *dev, size_t size, > @@ -168,7 +168,7 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page, > unsigned long attrs) > { > struct xen_grant_dma_data *data; > - unsigned int i, n_pages = PFN_UP(offset + size); > + unsigned int i, n_pages = XEN_PFN_UP(offset + size); The offset, here, refers to the offset in the page ... > grant_ref_t grant; > dma_addr_t dma_handle; > > @@ -200,8 +200,8 @@ static void xen_grant_dma_unmap_page(struct device *dev, dma_addr_t dma_handle, > unsigned long attrs) > { > struct xen_grant_dma_data *data; > - unsigned long offset = dma_handle & (PAGE_SIZE - 1); > - unsigned int i, n_pages = PFN_UP(offset + size); > + unsigned long offset = dma_handle & ~XEN_PAGE_MASK; ... while, here, it refers to the offset in the grant. So, the calculated number of grants may differ. > + unsigned int i, n_pages = XEN_PFN_UP(offset + size); > grant_ref_t grant; > > if (WARN_ON(dir == DMA_NONE)) -- Xenia