Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9ACDC433EF for ; Thu, 21 Jul 2022 15:11:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 78F09810E8; Thu, 21 Jul 2022 17:11:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Wyt8+ZaX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D5BC8110C; Thu, 21 Jul 2022 17:11:35 +0200 (CEST) Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 20D9C80755 for ; Thu, 21 Jul 2022 17:11:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olekstysh@gmail.com Received: by mail-wr1-x432.google.com with SMTP id bu1so2704548wrb.9 for ; Thu, 21 Jul 2022 08:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=tz1RZGc0uU0GAUj0ZnZP+CR86XAYFDqYQ62VjvQy7PI=; b=Wyt8+ZaXiKq9/S5ee28G398OVb/sEnH3Q/0JXjgClHN4nkS2iFT37HRQvncJTH/2Cc 9eOF4VLV+pU636M4z9WjuHuT5d1NX0KWSuMqZxxszHm85g9H2V5Cr954tFgOPJ9zWel/ BAbZh4a3whqe9aldSvz0L9NFl/HQH6k1WYlaciwRshTsJwoQ44f4e1opp/F1Kw1ygSh+ IX12xZNP1dNg6TCZALcRv37xXfmF+2G+j3GpxEiFejUUwcS62QFfVPMT5grUb+rWHC/V mB04/wBiPHTgs6ezOPIrOL9Xz5iW3s0ysqxX6o1JPg3IZ7PpGTyeIMGn/1Kkp4MmrEuD +BaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=tz1RZGc0uU0GAUj0ZnZP+CR86XAYFDqYQ62VjvQy7PI=; b=z6uLvbHHe0W5izE4wB58gR47zfFWwvIeNCDJNU2SZczWrucUuwH/HG5xS0XOacLPDm jfVAoOi1ZEbTQ46Ai9jMvM7S6hz5bYzVz8FOoS1JUqj5l5QuelK/kSaFbSH3elpnUaZy qMhQjeSjN4kTR6TF9Jo7LfclJSj1UDq0SEvwlKHh9I3lOnpfCjyhdw3cWiqji9CjISQ9 5N/cSn6E3o4gkwMUzzE6QDCa7YVjWzs29tcXnf2HzV/rJrzNp2aQpVMwtVHnuQC2cPY8 af8YS6o/cEw8GOEjKgcuHp+kPHP+gFMySh/S4iSZXpmWrNh+LHS/DciVSEbj6S+D9KO1 djYg== X-Gm-Message-State: AJIora955hOKzKeRA02iJXCQjcZO2lBB57acsNddwP6E6KZbLjEE+Njn zyUWTVx/rQ8W/t4/lcrmj5U= X-Google-Smtp-Source: AGRyM1vFCQH70bpRcmHUXsbIfPpj1A56muNXHG6qA1wwCK1S0S1OVnDcmTzinu3cbmZ0Sp8RHiaOrA== X-Received: by 2002:a05:6000:18a6:b0:21d:c651:1ac5 with SMTP id b6-20020a05600018a600b0021dc6511ac5mr29701320wri.435.1658416292588; Thu, 21 Jul 2022 08:11:32 -0700 (PDT) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id j9-20020a5d5649000000b0021d7ff34df7sm2366709wrw.117.2022.07.21.08.11.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jul 2022 08:11:32 -0700 (PDT) Message-ID: Date: Thu, 21 Jul 2022 18:11:30 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v2] drivers: xen: unmap Enlighten page before jumping to Linux Content-Language: en-US To: Dmytro Firsov , "u-boot@lists.denx.de" Cc: "vicooodin@gmail.com" , "julien@xen.org" References: <20220719145519.1795950-1-dmytro_firsov@epam.com> From: Oleksandr In-Reply-To: <20220719145519.1795950-1-dmytro_firsov@epam.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 19.07.22 17:55, Dmytro Firsov wrote: Hello Dmytro First of all, thanks for fixing this issue. Patch looks good, just a nit below. > This commit fixes issue with usage of Xen hypervisor shared info page. > Previously U-boot did not unmap it at the end of OS boot process. Xen > did not prevent guest from this. So, it worked, but caused wierd > issues - one memory page, that was returned by memalign in U-boot > for Enlighten mapping was not unmaped by Xen (shared_info values was > not removed from there) and returned to allocator. During the Linux > boot, it uses shared_info page as regular RAM page, which leads to > hypervisor shared info corruption. > > So, to fix this issue, as discussed on the xen-devel mailing list, the > code should: > 1) Unmap the page > 2) Populate the area with memory using XENMEM_populate_physmap > > This patch adds page unmapping via XENMEM_remove_from_physmap, fills > hole in address space where page was mapped via XENMEM_populate_physmap > and return this address to memory allocator for freeing. > > Signed-off-by: Dmytro Firsov > --- > > Changes in v2: > - Reword commit message to be more clear with purpose of the patch > - Change BUG() helper to panic() and add error messages > - Add struct zeroing during initialization > - Fix typo in comment > --- > drivers/xen/hypervisor.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/drivers/xen/hypervisor.c b/drivers/xen/hypervisor.c > index 2560894832..16c7c96c94 100644 > --- a/drivers/xen/hypervisor.c > +++ b/drivers/xen/hypervisor.c > @@ -144,6 +144,36 @@ struct shared_info *map_shared_info(void *p) > return HYPERVISOR_shared_info; > } > > +void unmap_shared_info(void) > +{ > + xen_pfn_t shared_info_pfn = virt_to_pfn(HYPERVISOR_shared_info); > + struct xen_remove_from_physmap xrfp = {0}; > + struct xen_memory_reservation reservation = {0}; > + xen_ulong_t nr_exts = 1; > + > + xrfp.domid = DOMID_SELF; > + xrfp.gpfn = shared_info_pfn; > + if (HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp) != 0) > + panic("Failed to unmap HYPERVISOR_shared_info\n"); > + > + /* > + * After removing from physmap there will be a hole in address space on > + * HYPERVISOR_shared_info address, so to free memory allocated with > + * memalign and prevent exceptions during access to this page we need to > + * fill this 4KB hole with XENMEM_populate_physmap before jumping to Linux. > + */ > + reservation.domid = DOMID_SELF; > + reservation.extent_order = 0; > + reservation.address_bits = 0; I think the explicit field's zeroing could be dropped now. [snip] -- Regards, Oleksandr Tyshchenko