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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 2BA69C2D0E2 for ; Tue, 22 Sep 2020 13:13:23 +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 A87A02396D for ; Tue, 22 Sep 2020 13:13:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="W3gTSHov" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A87A02396D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.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 1kKi6N-0007eh-Q9; Tue, 22 Sep 2020 13:12:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kKi6N-0007ec-AI for xen-devel@lists.xenproject.org; Tue, 22 Sep 2020 13:12:59 +0000 X-Inumbo-ID: d0f2bd9a-07ed-45cd-b2ad-eec58a52c2ce Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d0f2bd9a-07ed-45cd-b2ad-eec58a52c2ce; Tue, 22 Sep 2020 13:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1600780378; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=FYgj1VEQPUemY32Hi4e4dgBECJLH6eHprjqhID6NS0o=; b=W3gTSHovAsCnEkP4r2OucmuRWcPXeMuz12CnrhCiKhSsGx87UelJgoS2 z/geBMjfADEhJEFzllnTfaCUL0cN6/KuPacBFIrLFLUg4FVQLNyIFeY/R j7xxcvdo3cY9DdwaGxwcIxvJQR3WiEsR3i34t8laPFaBJE6ow9gvkM+5G 8=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: pe3pUhcvGgKT4f3ms30G8x5jr7Ktw6jIGvNeZbFFHnG6ySNjo50mVcTtExBj5OXu1kO9kTfpP5 S8UozOUfBvL0BVbf+Ug7ZtI/a5vQOt9Ke8rWLtvy4uWahML/8RxIlt/3Wdn/czZHE/ADoamFGq QhESiqdxm44H7AozTNxi+vvmTssCrQ7yB2z9qFTX6tDwdc4CSq24GG4hmGhPYx0MdBNwYzLHKO a46XweF3eddYWrNKQOMh6TBQIFyRLAsIXgWzYagQLMiNdZ64uwN0VJaUCT3O8kF5pD68YMqkCJ avc= X-SBRS: 2.7 X-MesageID: 27258497 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.77,290,1596513600"; d="scan'208";a="27258497" Subject: Re: [PATCH 2/5] xen/gnttab: Rework resource acquisition To: Jan Beulich CC: Xen-devel , George Dunlap , Ian Jackson , "Konrad Rzeszutek Wilk" , Stefano Stabellini , Wei Liu , Julien Grall , Paul Durrant , =?UTF-8?Q?Micha=c5=82_Leszczy=c5=84ski?= , "Hubert Jasudowicz" References: <20200728113712.22966-1-andrew.cooper3@citrix.com> <20200728113712.22966-3-andrew.cooper3@citrix.com> <784bf5c1-be13-2c09-5494-6eb64c400473@suse.com> From: Andrew Cooper Message-ID: <17123e43-ca3e-4075-ad36-45e324bb6214@citrix.com> Date: Tue, 22 Sep 2020 14:10:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <784bf5c1-be13-2c09-5494-6eb64c400473@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-GB X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To FTLPEX02CL05.citrite.net (10.13.108.178) 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: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 29/07/2020 21:02, Jan Beulich wrote: > On 28.07.2020 13:37, Andrew Cooper wrote: >> The existing logic doesn't function in the general case for mapping a >> guests >> grant table, due to arbitrary 32 frame limit, and the default grant >> table >> limit being 64. >> >> In order to start addressing this, rework the existing grant table >> logic by >> implementing a single gnttab_acquire_resource().  This is far more >> efficient >> than the previous acquire_grant_table() in memory.c because it >> doesn't take >> the grant table write lock, and attempt to grow the table, for every >> single >> frame. > > Among the code you replace there is a comment "Iterate backwards in case > table needs to grow" explaining why what you say about growing the grant > table didn't actually happen. What I have said is accurate. Iterating backwards caused it to actually grow once, but every iteration still takes the lock and attempts to grow the table. > >> --- a/xen/common/grant_table.c >> +++ b/xen/common/grant_table.c >> @@ -4013,6 +4013,72 @@ static int gnttab_get_shared_frame_mfn(struct >> domain *d, >>       return 0; >>   } >>   +int gnttab_acquire_resource( >> +    struct domain *d, unsigned int id, unsigned long frame, >> +    unsigned int nr_frames, xen_pfn_t mfn_list[]) >> +{ >> +    struct grant_table *gt = d->grant_table; >> +    unsigned int i = nr_frames, tot_frames; >> +    void **vaddrs; >> +    int rc = 0; >> + >> +    /* Input sanity. */ >> +    if ( !nr_frames ) >> +        return -EINVAL; > > I can't seem to be able to find an equivalent of this in the old logic, > and hence this looks like an unwarranted change in behavior to me. We > have quite a few hypercall ops where some count being zero is simply > a no-op, i.e. yielding success without doing anything. There is no possible circumstance when getting here requesting 0 is legitimate. Tolerating a zero input for a mapping request is a very expensive way of hiding caller bugs. Most importantly however, the correctness of the logic does depends on nr_frames being nonzero. > >> +    /* Overflow checks */ >> +    if ( frame + nr_frames < frame ) >> +        return -EINVAL; >> + >> +    tot_frames = frame + nr_frames; >> +    if ( tot_frames != frame + nr_frames ) >> +        return -EINVAL; > > I find the naming here quite confusing. I realize part of this stems > from the code you replace, but anyway: "unsigned long frame" typically > represents a memory frame number of some sort, making the calculation > look as if it was wrong. (Initially I merely meant to ask whether this > check isn't redundant with the prior one, or vice versa.) Both checks are strictly necessary.  The top one checks 64bit wrapping, while the second is checking 32bit truncation. This code is horrible, both in terms of the acquire_resource API, and the grant API being off by one compared to normal, and needing the max_frame index, not the number of frames. ~Andrew