From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3AE9C433E0 for ; Fri, 3 Jul 2020 11:40:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDA8520663 for ; Fri, 3 Jul 2020 11:40:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="khNDcJIv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDA8520663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jrK34-0002kM-4S; Fri, 03 Jul 2020 11:40:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jrK33-0002cF-2T for xen-devel@lists.xenproject.org; Fri, 03 Jul 2020 11:40:05 +0000 X-Inumbo-ID: ef762cde-bd21-11ea-8496-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ef762cde-bd21-11ea-8496-bc764e2007e4; Fri, 03 Jul 2020 11:40:04 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id r12so32248965wrj.13 for ; Fri, 03 Jul 2020 04:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:reply-to:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-transfer-encoding:thread-index :content-language; bh=ljcIZ6Vuoj5BaNfMxfLHzi0gzvCqFiRu4i4B6UXaF44=; b=khNDcJIvTe5mlrs8ldRfBcIoXNzNB9pG9mpWl1pBhlyY4vf3HZMAy9rrF1btR9X40N S0o7c3jNQ6wzLKq0fEqrJIpEGYVRY6e4CcQuIeZBdfXb569SVOMyV/yLO0RoPiYnIsU4 2vtAJIZ6O+5ym1fEBzeGAIFnlq5T43FcX4sYTDgnjXPkPNfBEjdrlWVPnFBNwMWNWuDC 6H8vSDriNggnuSzDDrq9qPxrIED1lPve3lE4V+xzxMafYcDZzv9dm8uvHpF470YQKFhn c1UHjKyQRsJKxDibTW1PsDcVvbIQZ0FS60DmdODMdqtakw0ZF5A1tk+Bf3V9KMY6v0uQ rIjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:reply-to:to:cc:references:in-reply-to :subject:date:message-id:mime-version:content-transfer-encoding :thread-index:content-language; bh=ljcIZ6Vuoj5BaNfMxfLHzi0gzvCqFiRu4i4B6UXaF44=; b=fRTVmYlCIqNfOJGNDEKhCMlhg0bEHG0CRgYgQdrUnCZt2mZ0t/GwXGoHbkpXYsGf0J fiKJ92hwI3D6ShNdIeXPVA8tfrJ1QhhEJ1juUUCsWy4BbdLuHUBanqvHj+G6QO3+XyU6 FGw+MP9fVg9hoEGgvNtWXEFLBk8q9rD9dRhGEC9MRGxpPJbmbV9b1oZncauNEnCpUJ/c yy5FtTH5Ae7ZXg74NDGwrlVCKYxH6ErwhxXzTcgItZun8PtU0u+1pzyhitheCGv/OReq G1ZF6ivuvtTo07mtmuz/ljwztUzVeCr6TIuNQtGtVWj7SRz52c1QLOA2I2qDyAjEdYyT yY5Q== X-Gm-Message-State: AOAM530Gc7v7/TpFP/xHsZxsb1LA0DHx+ynRev5g1CkQ3pgnkuUoUlwI 8AWzYoXehe4GCh5fWLsBG7M= X-Google-Smtp-Source: ABdhPJwr9/tovbfxVLzPHiQ876c1htNcIIcr9lKS4drt4oK8MKec9gW77p5JnK73PDcFFQOCclI7zw== X-Received: by 2002:adf:e482:: with SMTP id i2mr35793062wrm.75.1593776403390; Fri, 03 Jul 2020 04:40:03 -0700 (PDT) Received: from CBGR90WXYV0 (54-240-197-235.amazon.com. [54.240.197.235]) by smtp.gmail.com with ESMTPSA id q7sm14638109wrs.27.2020.07.03.04.40.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jul 2020 04:40:02 -0700 (PDT) From: Paul Durrant X-Google-Original-From: "Paul Durrant" To: "'Julien Grall'" , =?utf-8?Q?'Micha=C5=82_Leszczy=C5=84ski'?= , References: <5be6cb58-82d0-0a78-a9b2-5c078b5d3587@xen.org> <004901d65128$16a6f330$43f4d990$@xen.org> <481e8ee7-561a-10d6-4358-7b07a8911ce8@xen.org> In-Reply-To: <481e8ee7-561a-10d6-4358-7b07a8911ce8@xen.org> Subject: RE: [PATCH v4 06/10] memory: batch processing in acquire_resource() Date: Fri, 3 Jul 2020 12:40:01 +0100 Message-ID: <004a01d6512e$b0b5fab0$1221f010$@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQFzyG1KjeOu8uNiQeFGxRZBsBXsYgGYFxRdAaoW8QMB0iLMpgFYu/uhqYdjH6A= Content-Language: en-gb X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Reply-To: paul@xen.org Cc: 'Stefano Stabellini' , tamas.lengyel@intel.com, 'Wei Liu' , 'Andrew Cooper' , 'Ian Jackson' , 'George Dunlap' , 'Jan Beulich' , luwei.kang@intel.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" > -----Original Message----- > From: Julien Grall > Sent: 03 July 2020 12:18 > To: paul@xen.org; 'Micha=C5=82 Leszczy=C5=84ski' = ; xen-devel@lists.xenproject.org > Cc: luwei.kang@intel.com; tamas.lengyel@intel.com; 'Andrew Cooper' = ; > 'George Dunlap' ; 'Ian Jackson' = ; 'Jan Beulich' > ; 'Stefano Stabellini' ; = 'Wei Liu' > Subject: Re: [PATCH v4 06/10] memory: batch processing in = acquire_resource() >=20 > Hi, >=20 > On 03/07/2020 11:52, Paul Durrant wrote: > >> -----Original Message----- > >> From: Julien Grall > >> Sent: 03 July 2020 11:36 > >> To: Micha=C5=82 Leszczy=C5=84ski ; = xen-devel@lists.xenproject.org > >> Cc: luwei.kang@intel.com; tamas.lengyel@intel.com; Andrew Cooper = ; > George > >> Dunlap ; Ian Jackson = ; Jan Beulich > >> ; Stefano Stabellini ; = Wei Liu ; > paul@xen.org > >> Subject: Re: [PATCH v4 06/10] memory: batch processing in = acquire_resource() > >> > >> (+ Paul as the author XENMEM_acquire_resource) > >> > >> Hi, > >> > >> On 30/06/2020 13:33, Micha=C5=82 Leszczy=C5=84ski wrote: > >>> From: Michal Leszczynski > >>> > >>> Allow to acquire large resources by allowing acquire_resource() > >>> to process items in batches, using hypercall continuation. > >>> > >>> Signed-off-by: Michal Leszczynski > >>> --- > >>> xen/common/memory.c | 32 +++++++++++++++++++++++++++++--- > >>> 1 file changed, 29 insertions(+), 3 deletions(-) > >>> > >>> diff --git a/xen/common/memory.c b/xen/common/memory.c > >>> index 714077c1e5..3ab06581a2 100644 > >>> --- a/xen/common/memory.c > >>> +++ b/xen/common/memory.c > >>> @@ -1046,10 +1046,12 @@ static int acquire_grant_table(struct = domain *d, unsigned int id, > >>> } > >>> > >>> static int acquire_resource( > >>> - XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) > >>> + XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg, > >>> + unsigned long *start_extent) > >>> { > >>> struct domain *d, *currd =3D current->domain; > >>> xen_mem_acquire_resource_t xmar; > >>> + uint32_t total_frames; > >>> /* > >>> * The mfn_list and gfn_list (below) arrays are ok on stack = for the > >>> * moment since they are small, but if they need to grow in = future > >>> @@ -1077,8 +1079,17 @@ static int acquire_resource( > >>> return 0; > >>> } > >>> > >>> + total_frames =3D xmar.nr_frames; > >> > >> On 32-bit, the start_extent would be 26-bits wide which is not = enough to > >> cover all the xmar.nr_frames. Therefore, you want that check that = it is > >> possible to encode a continuation. Something like: > >> > >> /* Is the size too large for us to encode a continuation? */ > >> if ( unlikely(xmar.nr_frames > (UINT_MAX >> MEMOP_EXTENT_SHIFT)) ) > >> > >>> + > >>> + if ( *start_extent ) > + { > >>> + xmar.frame +=3D *start_extent; > >>> + xmar.nr_frames -=3D *start_extent; > >> > >> As start_extent is exposed to the guest, you want to check if it is = not > >> bigger than xmar.nr_frames. > >> > >>> + guest_handle_add_offset(xmar.frame_list, *start_extent); > >>> + } > >>> + > >>> if ( xmar.nr_frames > ARRAY_SIZE(mfn_list) ) > >>> - return -E2BIG; > >>> + xmar.nr_frames =3D ARRAY_SIZE(mfn_list); > >> > >> The documentation of the hypercall suggests that if you pass NULL, = then > >> it will return the maximum number value for nr_frames supported by = the > >> implementation. So technically a domain cannot use more than > >> ARRAY_SIZE(mfn_list). > >> > >> However, you new addition conflict with the documentation. Can you > >> clarify how a domain will know that it can use more than > >> ARRAY_SIZE(mfn_list)? > > > > The domain should not need to know. It should be told the maximum = number of frames of the type it > wants. If we have to carve that up into batches inside Xen then the = caller should not need to care, > right? >=20 > In the current implementation, we tell the guest how many frames it = can > request in a batch. This number may be much smaller that the maximum > number of frames of the type. >=20 > Furthermore this value is not tie to the xmar.type. Therefore, it is > valid for a guest to call this hypercall only once at boot to figure = out > the maximum batch. >=20 > So while the change you suggest looks a good idea, I don't think it is > possible to do that with the current hypercall. >=20 Oh, I was clearly misremembering what the semantic was; I thought it was = implementation max for the given type but indeed we do just return the = array size, so we expect the caller to know the individual resource type = limitations. So, as Jan says, passing back UINT_MAX >> MEMOP_EXTENT_SHIFT seems to be = what we need. Paul