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=-4.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 8CD51C4338F for ; Fri, 13 Aug 2021 21:45:33 +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 32D2160F51 for ; Fri, 13 Aug 2021 21:45:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 32D2160F51 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.166927.304707 (Exim 4.92) (envelope-from ) id 1mEezN-0000sj-Ac; Fri, 13 Aug 2021 21:45:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 166927.304707; Fri, 13 Aug 2021 21:45:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mEezN-0000sc-7O; Fri, 13 Aug 2021 21:45:17 +0000 Received: by outflank-mailman (input) for mailman id 166927; Fri, 13 Aug 2021 21:45:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mEezL-0000sU-Lw for xen-devel@lists.xenproject.org; Fri, 13 Aug 2021 21:45:15 +0000 Received: from mail-lf1-x12e.google.com (unknown [2a00:1450:4864:20::12e]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e033cc89-fa00-4f44-8d18-a655e831e82a; Fri, 13 Aug 2021 21:45:14 +0000 (UTC) Received: by mail-lf1-x12e.google.com with SMTP id n17so22348790lft.13 for ; Fri, 13 Aug 2021 14:45:14 -0700 (PDT) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id c13sm253547lfv.133.2021.08.13.14.45.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Aug 2021 14:45:12 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e033cc89-fa00-4f44-8d18-a655e831e82a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=lxcjhUazLVa3sWBGA1sU9XXPAd+MdzYWvpCzlHEoKUQ=; b=le07xKNqR2DZhwwHfwMb20aGOo2SxcVsxwqx9XUfcBfUViKwvh4JKeOX3Mc9HZjyoB Iva83Tiagn0qjnfd8z7ML6XaVpVBdYpq+SQY/8d5j3WLw4l+WorcexjECdkThUfCly5N eAPxTpNdH4Uk3f2VhKIkr+fyX6oxpkpbRWtOc6dJH7jvJrudxBPWZWNUT8V7lOUt2qr7 vzgEl/ZF/5Dyo6Pwy1jCwIh0JL6OwMlne92URkea4QDNTZfaQm1wdnsWhpOsP8Xy9NLw ud325LgCUwxSPT/Qdo1mxlp9/L/xjUhZz6pmDwNbEwM0j7phkkbt+1M7N+F80lBcl8cP SW5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=lxcjhUazLVa3sWBGA1sU9XXPAd+MdzYWvpCzlHEoKUQ=; b=jVCGtTI5aueAAS+akOsq1lYkLQAvGJrQnreXw5pqbMHWlqU4mhGa9mHNkkxOvYm7fd VnkGXXuo0MOn7vg+jF+UrhFuQULKMY1cVCCBMnxxxnkWkex6qAUML3Y7RA3+voazX9bI +W5hycPwusCQ7/1yIf2OsdA5jvYJPDDFMec/vpllxSfRY8lEGYpRduVq0ckvYTAe8ybk TZxoH8ihkSF7kwembuob9DtaFcsnv654wPNgmvQcOm4V2Bo2i3V8l7siaHF8qqG67NDj 03hWoUbkqLfrNz9yN54FKrHvg9OHH3YjB9p6VLTUANu1C9Ln61epTDvE0GEABfJ9F1nn Clew== X-Gm-Message-State: AOAM532WnlIWNcIVpX95LsTsSR45s60FNKJiC0ERF2pbhc2LgyacFSil n2LBqzQYpB6+hJaXXoPB2hY= X-Google-Smtp-Source: ABdhPJwa9myeFmdjDIMUQP8r5H/8xW3VW/sFJeq/kJMpyz5aiq2W5TT0S7KsnpZ6WL67z61vefQH0Q== X-Received: by 2002:ac2:5fd1:: with SMTP id q17mr3096725lfg.439.1628891113172; Fri, 13 Aug 2021 14:45:13 -0700 (PDT) Subject: Re: [RFC PATCH] xen/memory: Introduce a hypercall to provide unallocated space To: Julien Grall Cc: Stefano Stabellini , Andrew Cooper , xen-devel@lists.xenproject.org, Oleksandr Tyshchenko , Daniel De Graaf , "Daniel P. Smith" , Ian Jackson , Wei Liu , George Dunlap , Jan Beulich , Volodymyr Babchuk , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , Bertrand Marquis , Wei Chen References: <1627489110-25633-1-git-send-email-olekstysh@gmail.com> <80fafc01-f063-d6e5-1c08-7ad64550310c@citrix.com> <4de5ed21-379e-b618-44c8-924d88b1a519@citrix.com> <6a633f4e-13e0-4a2b-cf6e-35ef90ae977c@gmail.com> <5643d414-0b76-74a4-2c37-c7a99338d547@gmail.com> <93d0df14-2c8a-c2e3-8c51-54412190171c@xen.org> From: Oleksandr Message-ID: Date: Sat, 14 Aug 2021 00:45:11 +0300 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: <93d0df14-2c8a-c2e3-8c51-54412190171c@xen.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US On 09.08.21 17:51, Julien Grall wrote: > Hi, Hi Julien, all > > I am writing down here what we discussed on another thread and on IRC. > This will be easier to track in a single thread. > > On 04/08/2021 23:00, Julien Grall wrote: >> On 04/08/2021 21:56, Oleksandr wrote: >>> Now, I am wondering, would it be possible to update/clarify the >>> current "reg" purpose and use it to pass a safe unallocated space >>> for any Xen specific mappings (grant, foreign, whatever) instead of >>> just for the grant table region. In case, it is not allowed for any >>> reason (compatibility PoV, etc), would it be possible to extend a >>> property by passing an extra range separately, something similar to >>> how I described above? >> >> I think it should be fine to re-use the same region so long the size >> of the first bank is at least the size of the original region. > > While answering to the DT binding question on the DT ML, I realized > that this is probably not going to be fine because there is a bug in > Xen when mapping grant-table frame. > > The function gnttab_map_frame() is used to map the grant table frame. > If there is an old mapping, it will first remove it. > > The function is using the helper gnttab_map_frame() to find the > corresponding GFN or return INVALID_GFN if not mapped. > > On Arm, gnttab_map_frame() is implementing using an array index by the > grant table frame number. The trouble is we don't update the array > when the page is unmapped. So if the GFN is re-used before the > grant-table is remapped, then we will end up to remove whatever was > mapped there (this could be a foreign page...). > > This behavior already happens today as the toolstack will use the > first GFN of the region if Linux doesn't support the acquire resource > interface. We are getting away in the Linux because the toolstack only > map the first grant table frame and: >  - Newer Linux will not used the region provided by the DT and nothing > will be mapped there. >  - Older Linux will use the region but still map the grant table frame > 0 to the same GFN. > > I am not sure about U-boot and other OSes here. > > This is not new but it is going to be become a bigger source of > problem (read more chance to hit it) as we try to re-use the first > region. > > This means the first region should exclusively used for the > grant-table (in a specific order) until the issue is properly fixed. > > A potential fix is to update the array in p2m_put_l3_page(). The > default max size of the array is 1024, so it might be fine to just > walk it (it would be simply a comparison). > > Note that this is not a problem on x86 because the is using the M2P. > So when a mapping is removed, the mapping MFN -> GFN will also be > removed. > > Cheers, The fix is already pushed: https://lore.kernel.org/xen-devel/1628890077-12545-1-git-send-email-olekstysh@gmail.com/ Thanks! -- Regards, Oleksandr Tyshchenko