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=-9.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 56472C4338F for ; Thu, 5 Aug 2021 21:56:38 +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 0351761102 for ; Thu, 5 Aug 2021 21:56:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0351761102 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.164594.300888 (Exim 4.92) (envelope-from ) id 1mBlLX-0000wb-P5; Thu, 05 Aug 2021 21:56:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 164594.300888; Thu, 05 Aug 2021 21:56:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mBlLX-0000wU-La; Thu, 05 Aug 2021 21:56:11 +0000 Received: by outflank-mailman (input) for mailman id 164594; Thu, 05 Aug 2021 21:56:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mBlLW-0000wO-D0 for xen-devel@lists.xenproject.org; Thu, 05 Aug 2021 21:56:10 +0000 Received: from mail-lj1-x234.google.com (unknown [2a00:1450:4864:20::234]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 95e11c37-fc84-4fed-b387-9c6cc4ea15c7; Thu, 05 Aug 2021 21:56:07 +0000 (UTC) Received: by mail-lj1-x234.google.com with SMTP id b21so9031386ljo.13 for ; Thu, 05 Aug 2021 14:56:07 -0700 (PDT) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id b14sm514918lji.91.2021.08.05.14.56.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Aug 2021 14:56:06 -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: 95e11c37-fc84-4fed-b387-9c6cc4ea15c7 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=0yMYBSSM7CnT0tSAdjnTTx3aY4/DoOlmJ2kAA80ZkIQ=; b=ufjdOQEZTCoFijCbAr80H337fFeIqChTIt3GQsguGa7eQBf04Js0CjInr2wAA4LfHW /urj1PNMxxLHXIZl1hzkKn4aDTkJ4EEuyeyNIFvkRQ3TLihrqMS7a+J5gh1qwpXLjiY8 kXdjlOmYu08kVFW4hvbRX2UC9pSyVDyPfz1TzHsXyE9mo4UZ+D8NudYyxzpBSUFH6UpV Q2FvvIjazFL31gksvd4NEYjoD2j05+7DdhVlHYpFTgMF5DBsGlfmAQp/+jihsNCSkTf+ Rr/u7Pm6+qBDP+Bof+meuO3re9m/5yLGqWZpTfCZDsO3UwBsthDE0CMDjzrr8W3pcNnz TdMg== 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=0yMYBSSM7CnT0tSAdjnTTx3aY4/DoOlmJ2kAA80ZkIQ=; b=dB9EFP0bdD+k8JNbLIPMsZSVUkiamxf3/TMh/HtixSFsGFExeHJ9TuovhRGlQy9JsY NwKpGdR4z7pdGDfycRyiXLZ5Y9SputRwwRtBTTX/jBhlJesDb+vTH4UoGG2xyaVGuNRF 3fxwdXXLp1OKGPlSAGTa/p2HvUSw/miPI398PcTxU8UU4MtIa0ka6PI9g1YtlieSI20p Ax2KP9CXTYUTMRgi3agqk0fMTZGHW7oEAwP5AL9bIMK3xWZg3NKQZacaU9poRkU+bBSx GxU2RsRdm1+m2BQSla+xsA1MZbx1fw50qF1nhEt+I1sbVkf5zipn4EHNqF3Ziro4LaNk kipw== X-Gm-Message-State: AOAM533OHy4h+uk/70nxhbOeJVo/YONOsWbdPO4mzFbXIlXSPN/YGqyJ s/FxfC2QtIbTd22a3Kb4NyM= X-Google-Smtp-Source: ABdhPJzUfzI2knRV+3ZX4TqjWta1ux1AtStqFiMHX2nCVq65m+fZLtzh8IfCVdDRUU3ODvguX7hZcQ== X-Received: by 2002:a2e:2d01:: with SMTP id t1mr4297765ljt.400.1628200566635; Thu, 05 Aug 2021 14:56:06 -0700 (PDT) Subject: Re: [RFC PATCH] xen/memory: Introduce a hypercall to provide unallocated space To: "Daniel P. Smith" Cc: xen-devel@lists.xenproject.org, Oleksandr Tyshchenko , Daniel De Graaf , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Volodymyr Babchuk , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , Bertrand Marquis , Wei Chen References: <1627489110-25633-1-git-send-email-olekstysh@gmail.com> <6e573489-ceb7-03f4-3511-e6c166b318a6@apertussolutions.com> From: Oleksandr Message-ID: <13cc6316-4d53-cc23-05d0-3a83a21195d6@gmail.com> Date: Fri, 6 Aug 2021 00:56:05 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US On 05.08.21 19:37, Daniel P. Smith wrote: > Hey Oleksandr! Hi Daniel. > > On 8/5/21 11:59 AM, Oleksandr wrote: >> On 05.08.21 18:03, Daniel P. Smith wrote: >> >> Hi Daniel. >> >>> On 7/28/21 12:18 PM, Oleksandr Tyshchenko wrote: >>>> From: Oleksandr Tyshchenko >>> ... >>> >>>> diff --git a/xen/common/memory.c b/xen/common/memory.c >>>> index e07bd9a..3f9b816 100644 >>>> --- a/xen/common/memory.c >>>> +++ b/xen/common/memory.c >>>> @@ -1811,6 +1811,62 @@ long do_memory_op(unsigned long cmd, >>>> XEN_GUEST_HANDLE_PARAM(void) arg) >>>>               start_extent); >>>>           break; >>>>   +    case XENMEM_get_unallocated_space: >>>> +    { >>>> +        struct xen_get_unallocated_space xgus; >>>> +        struct xen_unallocated_region *regions; >>>> + >>>> +        if ( unlikely(start_extent) ) >>>> +            return -EINVAL; >>>> + >>>> +        if ( copy_from_guest(&xgus, arg, 1) || >>>> +             !guest_handle_okay(xgus.buffer, xgus.nr_regions) ) >>>> +            return -EFAULT; >>>> + >>>> +        d = rcu_lock_domain_by_any_id(xgus.domid); >>>> +        if ( d == NULL ) >>>> +            return -ESRCH; >>>> + >>>> +        rc = xsm_get_unallocated_space(XSM_HOOK, d); >>> Not sure if you are aware but XSM_HOOK is a no-op check, meaning that >>> you are allowing any domain to do this operation on any other domain. In >>> most cases there is an XSM check at the beginning of the hypercall >>> processing to do an initial clamp down but I am pretty sure there is no >>> prior XSM check on this path. Based on my understanding of how this is >>> intended, which may be incorrect, but I think you would actually want >>> XSM_TARGET.the >> Thank you for pointing this out. >> I am aware what the XSM_HOOK is, but I was thinking what the default >> action would be better suited for that hypercall, and failed to think of >> a better alternative. >> I was going to choose XSM_TARGET, but the description "/* Can perform on >> self or your target domain */" confused me a bit, as there was no target >> domain involved as I thought, XSM_PRIV >> sounded too strictly to me, etc. So, I decided to leave a "hook" for the >> RFC version. But, now I see that XSM_TARGET might be indeed better >> choice across all possible variants. > If you unravel the craftiness that is xsm_default_action, there is > actually a bit of hierarchy there. If you set the default_action to > XSM_TARGET, it will first check if calling domain(src) is the target, > then falls into the XSM_DM_PRIV check which is if src->target == target, > and then finally checks if is_control_domain(src). That will constrict > the operation so that a domain can call it on itself, a device model > domain (stubdom) can call it on the domain it is backing, and the > control domain can make the call. I am not a 100% sure on this but I do > not believe a hardware domain would be able to make the call with it set > to XSM_TARGET and not employing Flask. Hope this helps. This definitely helps. Thank you for the explanation. > > > -- Regards, Oleksandr Tyshchenko