Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp200640rwb; Wed, 5 Oct 2022 17:20:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4UFE9PXXBDUv4vg5EMKeARysURVkJYCAx4fBKf8wImnGks6XO7IEQkBREB101Ane2aGgta X-Received: by 2002:a05:6402:1a4d:b0:459:319f:ff80 with SMTP id bf13-20020a0564021a4d00b00459319fff80mr2164440edb.144.1665015657114; Wed, 05 Oct 2022 17:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665015657; cv=none; d=google.com; s=arc-20160816; b=rJJtLAsUB405shh8EbglYAmLoeb72xvuqZV0Qkj7m/Q3rA2Vdzs5O+hovhwOQPzpl8 oKeKJLLGM/XcAjoUpfsny2FxcZ9OFGHht0BQtqxg0wbP06ng4Xb0KjgJb+tTS3Vqt6CB TdJTqjFZN/vFAA5Sa/1bBrb5N5ax6MIpijQ5+NS1BvDHBegp/W3Z0J3ArRQ8VFhQVhnZ u77U43JcvTZYW91zd0g5VViVaIc+ln1cSZjFuDqR+n3ojMrGGBlSW6JgpjLyGuN2HoF9 CB22W8ZtluegUqtmzs3h/OXPxc1UYUWiNbGeGnaPDa4vAtGeuL7t3GKEd4xKUlsZFfXu 0Hww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=9uE8howCP7HGpilxi1c8baCzcWpXMgHRY9l8kVUURbE=; b=iyXxa7y6gUMpZRxMM95vKGwDNcoZRtLXZux8QkfaKQdgOi37Ugwsd+F1WalIIEklOz R3cM7O8iA//GmQElUc8cdlaVtKyUmGd9DXO8x+JfKB9GrUvgx/UTTKM7PP9MfbiM95Pa RBmpiSe39pLhWilkk163uirvb8Z9k/NKASXHPckoCUT04ky0t+uaahC7Tz+OIasN0FV0 Hjpd4UpRMryA4FzcXg4wNm90SJGO8gAB6PiGYVJI21mz4SBhxUPBYYlcL5M/cqRCrYg/ j8LmdjfeVDsomIAxL/3LgUMO1q+AIR/IYF88nUO/q0v5aaLEUO5sH5YjZQQmCipvziwj /eHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O4ZbMxFb; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a170906684d00b0078aa0801a40si8340871ejs.323.2022.10.05.17.20.30; Wed, 05 Oct 2022 17:20:57 -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=@kernel.org header.s=k20201202 header.b=O4ZbMxFb; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbiJFAIC (ORCPT + 99 others); Wed, 5 Oct 2022 20:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbiJFAIB (ORCPT ); Wed, 5 Oct 2022 20:08:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E2729B for ; Wed, 5 Oct 2022 17:07:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 01246B81F67 for ; Thu, 6 Oct 2022 00:07:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB950C433D6; Thu, 6 Oct 2022 00:07:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665014876; bh=EgI5M5TZ7BXqRvIKSX8CVCy28PNbu8v3l83emSft2nY=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=O4ZbMxFbU6j4RmRFHUi23ZOJvwnBTO1TjieTJErvhUv7V94SIH4cmt/mCkLuw2vMI sL0l6ODgVeWmczm584ssbe6JPJ1Yu9yl6++jLUbVcXHP3S5eplE2u9SpHzmDlbvt9A eY3/0pTHSuSgBv/u3Us4DzIwLKm80l4m/0RydAXZI/UjJKsG81/jqTlzDbz6M4ikXp c4WGSEuLRRCZHaTCe7DCwZ1fd9WVc+MqndCcz4FDM0th3OyLf42l7Whwwjvsv/FR3W oM3SywnqeRJ+/WQYTt40Ki3DFWOT6E1tuCBXfib1jpi2cC38J4AiiGz3NbF44kQgKX o0EF/aJv/Cz0g== Date: Wed, 5 Oct 2022 17:07:53 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Oleksandr Tyshchenko cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , Stefano Stabellini , Juergen Gross Subject: Re: [PATCH 1/2] xen/virtio: Fix n_pages calculation in xen_grant_dma_map(unmap)_page() In-Reply-To: <20221005174823.1800761-2-olekstysh@gmail.com> Message-ID: References: <20221005174823.1800761-1-olekstysh@gmail.com> <20221005174823.1800761-2-olekstysh@gmail.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Wed, 5 Oct 2022, Oleksandr Tyshchenko wrote: > From: Oleksandr Tyshchenko > > Take page offset into the account when calculating the number of pages > to be granted. > > Signed-off-by: Oleksandr Tyshchenko > Fixes: d6aca3504c7d ("xen/grant-dma-ops: Add option to restrict memory access under Xen") Reviewed-by: Stefano Stabellini > --- > drivers/xen/grant-dma-ops.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c > index 8973fc1e9ccc..1998d0e8ce82 100644 > --- a/drivers/xen/grant-dma-ops.c > +++ b/drivers/xen/grant-dma-ops.c > @@ -153,7 +153,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(size); > + unsigned int i, n_pages = PFN_UP(offset + size); > grant_ref_t grant; > dma_addr_t dma_handle; > > @@ -185,7 +185,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 int i, n_pages = PFN_UP(size); > + unsigned long offset = dma_handle & (PAGE_SIZE - 1); > + unsigned int i, n_pages = PFN_UP(offset + size); > grant_ref_t grant; > > if (WARN_ON(dir == DMA_NONE)) > -- > 2.25.1 >