Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5213478imm; Wed, 12 Sep 2018 02:49:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY7jA8myCBcaB6MtFCHqkB1g8iLKh6k6KyDF7qL3xrLUPGw13cdgtBI/bBUGDsB26La89gU X-Received: by 2002:a62:6547:: with SMTP id z68-v6mr1310782pfb.20.1536745747609; Wed, 12 Sep 2018 02:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536745747; cv=none; d=google.com; s=arc-20160816; b=Mq/bQvy030O3xNN8l8oLLR5ynfWBYG8iwizi6dS/wqTjjL3ZQ/zIKcmQSsSzRr/p9t NmsfoyIVqgPIJnN+ccTYdZlAtxmsv0gIecrYJbE2+SIQ67BaXCTBkA9e2QvwxgoOlddQ iLt3Cj9/I6zXaCWa/7TUVvZzeZnHlByLlPgaB1Y9oFQoIFHdepymeeb2xGcbOpZC4S4x lsLvLBk8I5j5ut+1AlHqMwDDFMQ55WO5UO/X2zUiWtTonNE34VI1RVE6nJm0DItWwayB fiK+WQOClH9YF32rjSgtD2R1SwNfvmEN9NVfU7Y989ytqMZiSIy5XDsjBxtx754vMTxu MBkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=3LVb87Wb1H20IZutNjX3reeFo/+ZVo/xYDV5ze4Fsls=; b=reLSooAebFnj9OwWy163UQ4jTRA4p+ODmeTd0501Jwv4PrvDKwDCsvjA6dkzUKE0vU Vszqz/UrfpdmdGWj0TfC83wLetErbZ8+sPPUoDiLFBucfC0WW+HVo2H6uH3cGbgK+aWa 3XoM8kih3JOuLCzfA0ub76QrZwxp+zVWsNaqI12LwCVkZUXnegmIWQI980kvbw9ahBbs XVMFEKDjIjYgfnAvTlQBReoEX9IP+4g5c+zOy4S+sybHxxab4DjJSxefqnO4hlDI3ykz kY/wwY2Q+ggmTFrK2Nl3pZ9WPZ1hffaRQa4DsoYBfiiFNGdLmrU1FnVLmgoqyrOO5ZS5 p6Bg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si507716pgw.604.2018.09.12.02.48.52; Wed, 12 Sep 2018 02:49:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726819AbeILOwb (ORCPT + 99 others); Wed, 12 Sep 2018 10:52:31 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:56514 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbeILOwa (ORCPT ); Wed, 12 Sep 2018 10:52:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 812DA7A9; Wed, 12 Sep 2018 02:48:45 -0700 (PDT) Received: from [10.37.12.49] (unknown [10.37.12.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 04DED3F703; Wed, 12 Sep 2018 02:48:43 -0700 (PDT) Subject: Re: [Xen-devel] [PATCH] drivers/block/xen-blkback/common.h: use DIV_ROUND_UP instead of reimplementing its function To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: Jan Beulich , Jens Axboe , Konrad Rzeszutek Wilk , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, xen-devel , zhong jiang References: <1536731100-56054-1-git-send-email-zhongjiang@huawei.com> <5B98CAE202000078001E79CC@prv1-mh.provo.novell.com> <20180912091350.6wuvt2jkvzg6wruo@mac.bytemobile.com> <20180912091639.oynlvdo6pghnqfvt@mac.bytemobile.com> From: Julien Grall Message-ID: <364bad2c-708e-6406-7b52-7bfef9d5dbe1@arm.com> Date: Wed, 12 Sep 2018 10:48:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180912091639.oynlvdo6pghnqfvt@mac.bytemobile.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 09/12/2018 10:16 AM, Roger Pau Monné wrote: > On Wed, Sep 12, 2018 at 11:13:50AM +0200, Roger Pau Monné wrote: >> Adding Julien how did the work to support XEN_PAGE_SIZE != PAGE_SIZE. >> >> On Wed, Sep 12, 2018 at 02:14:26AM -0600, Jan Beulich wrote: >>>>>> On 12.09.18 at 07:45, wrote: >>>> --- a/drivers/block/xen-blkback/common.h >>>> +++ b/drivers/block/xen-blkback/common.h >>>> @@ -65,7 +65,7 @@ >>>> (XEN_PAGES_PER_INDIRECT_FRAME / XEN_PAGES_PER_SEGMENT) >>>> >>>> #define MAX_INDIRECT_PAGES \ >>>> - ((MAX_INDIRECT_SEGMENTS + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME) >>>> + DIV_ROUND_UP(MAX_INDIRECT_SEGMENTS, SEGS_PER_INDIRECT_FRAME) >>>> #define INDIRECT_PAGES(_segs) DIV_ROUND_UP(_segs, XEN_PAGES_PER_INDIRECT_FRAME) >>> >>> My first reaction was to suggest >>> >>> #define MAX_INDIRECT_PAGES INDIRECT_PAGES(MAX_INDIRECT_SEGMENTS) >>> >>> but that wouldn't match what's there currently (note the two different >>> divisors). I can't really decide whether that's just unfortunate naming >>> of the two macros, or an actual bug. >> >> I think there's indeed a bug here. >> >> AFAICT, MAX_INDIRECT_PAGES should use XEN_PAGES_PER_INDIRECT_FRAME and >> then it could be changed as Jan suggested. The problem is SEGS_PER_INDIRECT_FRAME has been miscalculated. So I think it would be fine to use XEN_PAGES_PER_INDIRECT_FRAME in MAX_INDIRECT_PAGES. However the naming for XEN_PAGES_PER_INDIRECT_FRAME is misnamed. We return number of a for segments per indirect frame. So I would rename to SEGS_PER_INDIRECT_FRAME. >> >> Current MAX_INDIRECT_PAGES is misnamed and should instead be >> MAX_INDIRECT_SEGS (which on x86 is exactly the same because PAGE_SIZE >> == XEN_PAGE_SIZE). Looking at the usage: j = min(MAX_INDIRECT_PAGES, INDIRECT_PAGES(nr_segments)) Where j is used as the number of grant ref. So I don't think the variable is misnamed here. Cheers, -- Julien Grall