Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751161AbdFAVE4 (ORCPT ); Thu, 1 Jun 2017 17:04:56 -0400 Received: from mail-eopbgr00079.outbound.protection.outlook.com ([40.107.0.79]:27859 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751050AbdFAVEx (ORCPT ); Thu, 1 Jun 2017 17:04:53 -0400 Authentication-Results: apm.com; dkim=none (message not signed) header.d=none;apm.com; dmarc=none action=none header.from=arm.com; Subject: Re: [PATCH] xen/privcmd: Support correctly 64KB page granularity when mapping memory To: Boris Ostrovsky , xen-devel@lists.xen.org References: <20170531130357.14492-1-julien.grall@arm.com> <7199e366-f56a-acc8-ffa5-0c85d6975049@oracle.com> <592886a8-1443-6475-e318-85cb9acecead@arm.com> <0b91491d-8f67-fa22-8b27-7692f00bba51@arm.com> <1f38dcc0-8538-b8e5-a792-85867ea1c44d@arm.com> <0e7b0066-6219-79f8-5b17-b997a400d3f6@oracle.com> Cc: nd@arm.com, sstabellini@kernel.org, jgross@suse.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Feng Kan From: Julien Grall Message-ID: <31f7022c-c232-66ee-bb16-b25602cb6c23@arm.com> Date: Thu, 1 Jun 2017 22:04:47 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <0e7b0066-6219-79f8-5b17-b997a400d3f6@oracle.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [82.1.229.77] X-ClientProxiedBy: AM3PR07CA0071.eurprd07.prod.outlook.com (2603:10a6:207:4::29) To DB6PR0802MB2184.eurprd08.prod.outlook.com (2603:10a6:4:84::18) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB6PR0802MB2184: X-MS-Office365-Filtering-Correlation-Id: 8b3b68e1-5c68-4b79-4f16-08d4a931d805 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081)(201703131423075)(201703031133081);SRVR:DB6PR0802MB2184; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2184;3:fw8RoinMvfZb+t2oWhG4XnVj4CQWp1YIXM6ss/mPrGc09jhGi5T7ask4pzTdtEpzfI1QejNA9H7mUf91Let5vu6yqrm4jmsXvbliG5jZb6m6r8swllfMYiw3Uw//8OeJZzg61+rmbH7m7HH+O6WzBmjTmO9tEIolmhYzZLgzPzadkHb/kZswffWMuma87Se+s2sEjizdJ4Ma7qV6OX8UWVKXLbidXrCcDpdwTlYmaUmBN8cuWYRKgoP5JxsFimhWerS6Z9+WiPHoTL7ujG8Xg+z1Qk3sdNrJ/h0DMQogIEx89r3sdlN8E1xTQpavrPBrRcqzeqoB0Qw44VAAUtW0ut0GTw5gepIjAcrWpeg15qg=;25:ocno4XYI1xnxxovq2tEUW06NzKh5uHEPo56aH672pJBc/GsNLABTXucIkN/5Zb8g1qQJNVhDZVNAON2jct6zIH+6xPwC608J1sa7BtGnyOvS4gvmvWOhtDzFXmzq66nFBWZiejDint5BkRvVNuqFFJIyH9qy4yb+rI3aKJrvwqh6blPBaqtUjuxeb36eHR4Ie8XxgpJeCRgQGlgLBakILdtn4OZY4HLZ8Q/bUnvZXhkC07Ww1aqz8kx+rSFsvYVbuFKzf359PGW3AMviuJMZk17CFbRV4wJ0kU7VEBcPZw948tdnG7BZr5ff8cbshf8oELq77q7fkhSmJNgYwqvJHKpPll93mLOnMc75Of7TOWfzhluwlHvPa0SpH5mGLnWabyKFBg72w9HtnVUakjlkDroDNopbwhSutApYtT//HHWBpPPWXil5yFiGgLzCemjgJO1UjJa9EtmsqBI2VpDLuKbnlPoLQ3tRzX7Cq3hLTjw= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2184;31:aqsmrznVDUotaA3s9kCYFNG093KgT5wZKLlx0jkIN04X3eDPyKZYtC16Kp2zSlqNyL1oVTrN50sFybzUIUU5mWg8lm3TZ95XV0R4wVol9RJcO/Tsm04+J8ofR3U2q874OhCjsx8ckkKNQAHlLI6v9z+xeXcjY9nb700Zm50pafDi8AdakpkhOobOBSPEX63F6DPXwyZJIS5i6plc8dzVOV2uXUhTX6GKnigpjOMnmGA=;20:jFzWNqe4w5j8irCBM2vuMi8uFjcXNxxMz+6ttkbI0tLFLfuZq/l2ghlBzvylbgnsSmCLuQ98rR35MUuYnandVFlLS7E/WXKsY8Gb/a5qEQaFcncSiUQ8hDj8xBn3CU/5YzSDz9RjcGIOS/axFsNXjMVnjuJGk1uYogK5V9YKiek= NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(9452136761055)(146099531331640); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(100000703101)(100105400095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123562025)(20161123558100)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DB6PR0802MB2184;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DB6PR0802MB2184; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;DB6PR0802MB2184;4:scBBS3mwTN/Lmfz7ujDJFlMyPQdfYg/YZ3rT?= =?Windows-1252?Q?5XVndLzwYr3J1hLM84uXl8WyNLcyB2MnkH+Ddoox9o3CUEoS2YaGFJli?= =?Windows-1252?Q?zVe+03wu6rTi81rLC/y9zZKn81UgNgYNBtQlgpGEFvd8Qurd5VBWueuD?= =?Windows-1252?Q?MPAMck2E/qpLQqGsIGbX4uCDWXkyd/YW9OzovTHcrbvtL1R4nFbMTicC?= =?Windows-1252?Q?W/n22wyUs3Bt1ydEnjSH8DC8a0h/nKE5/mU1ht5bCiUYcOxUQhHCr6+7?= =?Windows-1252?Q?MQyV/Yjb8M0UnHQ+o4MPPj0YHzeWRlqRSVshm2dTiV2COSxjatvsaXps?= =?Windows-1252?Q?imLTh7NOMZFKP8Eea/F1j93z/7ceHkBSYNae62qMZdrUAbsnXRj/Nf63?= =?Windows-1252?Q?XT1v2hw+J000tJdLDYexu+1FDKtMUBlOJiQR8ZxMXlCYgZOLU+LQvaqD?= =?Windows-1252?Q?JqbVq/i2ZaVvLrzF6LgUwG8mrvV2FwKMn5YcrGY0V7F6JQ0mUX3pIsLv?= =?Windows-1252?Q?mZVBYGk/G3oRCZjyFhTV6CyWPTsFMogO7wrLYd0awxlt/KeA56u4/ROJ?= =?Windows-1252?Q?zUC69ZBTX1I/S29z5hE0OHECVv6S2SLoVc8Z2mmto0gRFLnholiBa6l+?= =?Windows-1252?Q?xPFZNrYunaX7EqM1c1Hc0R2LL8i0xYh3rzLFTuQjizPsR1uw21wD90Ja?= =?Windows-1252?Q?VNgcogMcz2a9uAG7pndoAkTv5Od5vPyBtARkmclQmXnYWnUPszjWD6pF?= =?Windows-1252?Q?/rxYkycVeM9xpbmlQ34bCTG7OBS4AsV4IYQcXHsajarxLieXBHnK8gEQ?= =?Windows-1252?Q?0YEboPUQiXaB1Ju3+0zL4kYGvpAfIBetasY9FYHNknjt9DRNcbzB6uyf?= =?Windows-1252?Q?KGvdwDEpKqNtlSiStUKwQA84Sz/Qkyttu41dy+OJ+DFXIBvvBbXrKl8K?= =?Windows-1252?Q?4we9xsU8CduMb8vHMAmeV8BncOGZztHYHTvB/JDLeLNaGqIwI5ykYGm6?= =?Windows-1252?Q?5XqmCd6huwRd0lwZ2xiQtOHnNtxdg3cACKMe5FPr4yatQmIUkb4Ic5py?= =?Windows-1252?Q?ezk2opPOQj/gTh1OkA0pky1kTYOXjxJ2gb8l5NYgcInrp0QA95rK0k5q?= =?Windows-1252?Q?Osgihmonealc8dp6S3a+vX9uotr/vMmrmGb51tpy/mYZQSo+t+4X1AwS?= =?Windows-1252?Q?sIURID8O6cwHdzm7oxjJU7/DRsQX1atGCVcCMK7QnK9hCraVwao2sczD?= =?Windows-1252?Q?VnCf/u8Q0La4Vz43cFygLFnZzFq3Rma5L4MsxNMC/bcGKF5Vc7Tf+ZkN?= =?Windows-1252?Q?tow1qw6pdZHpLO558pYSQD4mq864UmKyE41GV/9vAVWDZOmocw4e/lqc?= =?Windows-1252?Q?kWxYOB3gEEok?= X-Forefront-PRVS: 0325F6C77B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39410400002)(39840400002)(39450400003)(39400400002)(24454002)(377454003)(31696002)(86362001)(3846002)(8676002)(7736002)(478600001)(4326008)(23746002)(66066001)(25786009)(72206003)(53546009)(2906002)(5660300001)(110136004)(83506001)(65956001)(38730400002)(47776003)(6512007)(305945005)(53936002)(6246003)(33646002)(76176999)(6486002)(42186005)(36756003)(50986999)(6506006)(6666003)(229853002)(54356999)(2950100002)(64126003)(6116002)(4001350100001)(50466002)(230700001)(31686004)(81166006)(189998001)(93886004);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0802MB2184;H:Juliens-MacBook-Pro.local;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;DB6PR0802MB2184;23:02ZRROdsfD0Bt+bDIPZp+LCEkM0apR5XqNI?= =?Windows-1252?Q?zbc4LviiMVCIQ4ehYmNAC7Ws55TIeEcc/jZxqf/uaH7gsEP1gEUqDk4V?= =?Windows-1252?Q?+HLCjmcfv/aat5Pjjpj1VhmgbRQ4uEIv9Njsr1IAa2KB8XY1jG7bRdW2?= =?Windows-1252?Q?kXQisaWpc0GQ3l3mZd0XbNH/5G6jmj5MJUGf4k9+oClPaAWQMyNNNDf2?= =?Windows-1252?Q?XhZOjweRftTZJTyE3ppotHHYUaK2Sazv1IFayBNUByzNxnyXyjGxngCi?= =?Windows-1252?Q?Wg8GXujIT3t8+iCv6X6cTfpONIQuXE1gztQ+OJOJgO6cndHVwb0z+iCk?= =?Windows-1252?Q?GqhPB5RbAGtVspGO3M3phtXFZGYQGtUNr2tDMAKn3U2ds/LL3O2N/4R+?= =?Windows-1252?Q?2xTbbuAfQNRtikz2asacnHdtdTlL9H9pmhvqyDyqVwjOerAqnmxs/+Xs?= =?Windows-1252?Q?BQqqWOKN7EcNuWPDqGN+9o1eE5PO91ff7lpYJPFd/7EGxoH+rJTXJUit?= =?Windows-1252?Q?lL6WgSg5/opYbkgLa4kGUt5PjEr6+XcbZ6lpFYOcbRHX6e47jKVj0fQN?= =?Windows-1252?Q?nFrVu3WYw5cHiRv6xdRodjlNmkOLkLQ2+eyJNVR9nJxNtWcQJ6y+Eay0?= =?Windows-1252?Q?UrzavVwM7dTrDI2JWxIrANTXgbT6qqvNjdVc0sDAX7Jf5D58rpyx8q3r?= =?Windows-1252?Q?y3zimwHORQaZJ/CUFmCvRu8pOlxefpNR0wDxwO5PK7s+7mKlz8lhpJWY?= =?Windows-1252?Q?ufNUmDr1Hu1W9hHlTQCvnGC4te99Njt2owLWExgg+Glo6LjzdwrR8ZCn?= =?Windows-1252?Q?KSBqTHdaOE6iYZBxrWK8XO+BsYl0BDiisXNGj8eIOcJez1uvL7hNTc2E?= =?Windows-1252?Q?IjptAgh1fxaMYlKkQSerDSL0YI7Ty5ColC5kjtJottn0wpa2l7ZX/J3k?= =?Windows-1252?Q?1q4CXhSEopdEVUVuGXE4UKAwXtoOFy+C9m9lPSc67o5YOodTBjHtU6X0?= =?Windows-1252?Q?j1+6yBahB5hTP0F6U6Swrxek7yhlfGbmIEmFmFahPonego8HiAodUPxf?= =?Windows-1252?Q?YSrOuxnnYrL/O++wbjDcqZza7pAupkWMwYUI+lUnUsqkAUHM/ammDmEx?= =?Windows-1252?Q?mQgk66VmkX6v+URrLscg0KtbywZANn60ixyP8b86/g4p/NRkI/62Q82f?= =?Windows-1252?Q?e72zomqDG0xZz6autiWwm9j5NrHTS03FncCF8gUVWPPhLwN1Ol6fAUIY?= =?Windows-1252?Q?WEy3Z/WsiyMW7sNiU+Vifh7ltl+K1uDjKybkuchjyGpXnqRSe8vn2CjJ?= =?Windows-1252?Q?Yqrj0kdX9xRKLgEAX+O1HP4U0th/wl3COpcbPFLOBfBu+hAMWNXsurZ4?= =?Windows-1252?Q?CHOou4Io2WGI3?= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2184;6:34DfctrUHoP7k/JIH7wXdyyPnXf1mn6X/A7cerGR63nmZ9xpiADmTkJ8rLyCBwyAFTTVMNuF4Lkqod+wBsrSYLYQGyn7mhgKepSvR4ugVVU7CwAhK1TXzVih0rDFVuq5vETPUYQ7fHBgnaooA1XhhxMqUhFTnZJZqtA+Fh4j34LyP4GB1qAXfSC0FwIrHE8GzfFX2T8SwDieQPbAPKOa8mfrICcA3NKpsKDMojp4nH06TU6KyM3Ub9EcQUKvAgvyFV6c1mo6Ra1LNTEBidZARoPVok8u5ElidZRvUSLsK1p+/YTGOzTvyV5W6aHJi8H9os3wriud7baoZzcJpg4ERzF7Kfj3QwPxLAvs5uwXZpgpX19OWkZ5xhBYaSKXbSpU6P5smWh+ck1pK4O7Nwd4RxJlYObpieRR29alabTy8KIDrqDjUjOw7kilYWn1mp8t2y3mE9wUODA3Owvubx7yex44o8h6KwY7uNVUzTQBnTa30E0bDmtOujyhdkzqkbJXYTgGiAdweRF61ylT9dJmc4jFzrc1cuCUIrlyeTsfpBE= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2184;5:lA0DExjIHTW3zR8t8p+oQfYQ4zZ7Qd+qfeIPf9oNF6x2IVIUegSCQoNhPlXGxyaXvWheuKkErcTyDtdW5OQmKaNn9O52fSl0qdSMgJoD5Tyn31jJGJsgRL4aZKileDvYE231a4T026YqmcBtYypblCsteMs8BG9CVLbKrufm2q+QPT0FeDzkfpLGuV0oy1PLSxjRX2u/vh/lxFx6y9z/izKSHpkm31nzp545hdi9xONR+e7NrWhZJjldKFInGW1sXvVsBUF8D/ufJtweIcst0NOY6f5DR0Ek4nPL1pePVMFTX2w/vKxcC6e9k4Tu81M3Wwlq61WEtF1xlNLLpuUJ3wU/kNp0C5Mlvtdu2B5UuFZybgTYB5ms7b0HOkMFaFUWXXvEuGjimIIec4yxQG1qyab+24rHNa19ucjCCbpjkSGvUQrt0E9QFgurd2ez9BMtKb1Ru/lrq0mFhKr6izsVMrEtu940bR+S1zl2qUlNhS5gB6Ew8lQeihUgdcp33bfD;24:NdAi/RDqTIy77r5p2TIDakisD1l6sRcfOe3p18CTUUJNZXrRaiNUnkvDRWzYXIihQDjFF3kN3fGLjjD3eKueBdwubwy9mSIWhuszv0aDH48= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2184;7:TaU78Rd3muHPpaDXL0XsegoGPmrhH+igUcuvjMgv8U1qyEineyvhAy/EmhhK8wYx/9ao2LUEWIm+lc7q5sCAu27NwcZwjF4CL4MhTbtpLhJnzGzbm+Xvg624gXA1yguFwLhXGqGB5sdtV1w10eSlzdWgW8ufQbAM6pFmk5Mavg4koIrvdcQVWSe6m8Vk/PpQC8gBRw4uUN80K01/VFrDJ1kCVnb/4BK7A+PcZeiUFsDd+r2GT+zJovrjvphRGVmh34RmLrZWc+veNJR4OJC1EEQraTLbpz02+j4Sspir6TVpDig0hX2j10Kvq0sMpsrPKosbj0oU3qky5Tu1DbyegQ== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 21:04:50.0050 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2184 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3737 Lines: 108 On 01/06/2017 21:41, Boris Ostrovsky wrote: > On 06/01/2017 11:38 AM, Julien Grall wrote: >> Hi Boris, >> >> On 01/06/17 16:16, Boris Ostrovsky wrote: >>> On 06/01/2017 10:01 AM, Julien Grall wrote: >>>> Hi Boris, >>>> >>>> On 01/06/17 14:33, Boris Ostrovsky wrote: >>>>> On 06/01/2017 08:50 AM, Julien Grall wrote: >>>>>> Hi Boris, >>>>>> >>>>>> On 31/05/17 14:54, Boris Ostrovsky wrote: >>>>>>> On 05/31/2017 09:03 AM, Julien Grall wrote: >>>>>>>> Commit 5995a68 "xen/privcmd: Add support for Linux 64KB page >>>>>>>> granularity" did >>>>>>>> not go far enough to support 64KB in mmap_batch_fn. >>>>>>>> >>>>>>>> The variable 'nr' is the number of 4KB chunk to map. However, when >>>>>>>> Linux >>>>>>>> is using 64KB page granularity the array of pages >>>>>>>> (vma->vm_private_data) >>>>>>>> contain one page per 64KB. Fix it by incrementing st->index >>>>>>>> correctly. >>>>>>>> >>>>>>>> Furthermore, st->va is not correctly incremented as PAGE_SIZE != >>>>>>>> XEN_PAGE_SIZE. >>>>>>>> >>>>>>>> Fixes: 5995a68 ("xen/privcmd: Add support for Linux 64KB page >>>>>>>> granularity") >>>>>>>> CC: stable@vger.kernel.org >>>>>>>> Reported-by: Feng Kan >>>>>>>> Signed-off-by: Julien Grall >>>>>>>> --- >>>>>>>> drivers/xen/privcmd.c | 4 ++-- >>>>>>>> 1 file changed, 2 insertions(+), 2 deletions(-) >>>>>>>> >>>>>>>> diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c >>>>>>>> index 7a92a5e1d40c..feca75b07fdd 100644 >>>>>>>> --- a/drivers/xen/privcmd.c >>>>>>>> +++ b/drivers/xen/privcmd.c >>>>>>>> @@ -362,8 +362,8 @@ static int mmap_batch_fn(void *data, int nr, >>>>>>>> void *state) >>>>>>>> st->global_error = 1; >>>>>>>> } >>>>>>>> } >>>>>>>> - st->va += PAGE_SIZE * nr; >>>>>>>> - st->index += nr; >>>>>>>> + st->va += XEN_PAGE_SIZE * nr; >>>>>>>> + st->index += nr / XEN_PFN_PER_PAGE; >>>>>>>> >>>>>>>> return 0; >>>>>>>> } >>>>>>> >>>>>>> >>>>>>> Are we still using PAGE_MASK for xen_remap_domain_gfn_array()? >>>>>> >>>>>> Do you mean in the xen_xlate_remap_gfn_array implementation? If so >>>>>> there are no use of PAGE_MASK as the code has been converted to >>>>>> support 64K page granularity. >>>>>> >>>>>> If you mean the x86 version of xen_remap_domain_gfn_array, then we >>>>>> don't really care as x86 only use 4KB page granularity. >>>>> >>>>> >>>>> I meant right above the change that you made. Should it also be >>>>> replaced >>>>> with XEN_PAGE_MASK? (Sorry for being unclear.) >>>> >>>> Oh. The code in xen_remap_domain_gfn_array is relying on st->va to be >>>> page aligned. So I think we want to keep PAGE_MASK here. >>> >>> Doe this imply then that 'nr' 4K pages is integral number of PAGE_SIZE >>> (i.e. (nr*XEN_PAGE_SIZE) % PAGE_SIZE == 0) and if yes --- do we test >>> this somewhere? I don't see it. >> > > I now see that this should (obviously) stay as PAGE_MASK, so > > Reviewed-by: Boris Ostrovsky Thank you! > > but > >> nr might be smaller for the last batch. But all the intermediate batch >> should have ((nr * XEN_PAGE_SIZE) % PAGE_SIZE == 0). > > how can we have nr not covering full PAGE_SIZEs? If you are using 64K > pages, how can you map, say, only 4K (if nr==1)? Xen is using 4K page granularity and so does the toolstack and the hypercall interface. They are unaware of the page size of the kernel. So even if Linux is using 64K pages, the resulting mapping will be broken down in 4K chunk to issue the hypercall. To give you a concrete example, if the toolstack requests to map 4K, Linux will allocate a 64K page. Only the first 4K chunk (0-4K) will have effective mapping to host RAM. The rest (4-64K) will not be mapped. Cheers, -- Julien Grall