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=-0.7 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 EF243C433DB for ; Wed, 24 Feb 2021 02:39:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 8D5F564E7A for ; Wed, 24 Feb 2021 02:39:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D5F564E7A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=d+F+5R2CThC5XRWNelll55zUHS6RrQ/jlQAcQJ2eHx8=; b=cwj9nqfxj5TxzZYwlzJhDwJC8 j69njOEpqjcKotly090nX8PsreHzj0I+e8hi0CG5QTRTVrDJecRai6J1KYNekqToXWvSgm6Q3rbNk olNjX5xwmkxLJsZQIpBzwMjgXc8gxmFwY/QnClOKE5ENzKSRShrBjMWgc6gf6RlxqI61a03VcrrwD vD/++UusmBW5cHmakeYXpjhHpCWq91rP9O7xGBT7Q66A2i9r1BNnpo24Wb7D6RjIkXohXuQaprgmh ZDDnGnZ3shYg5jA1pZF720zuq534rH0cLf5UAPua6pFyTfozboml0EQEnBuVemJyjUVVJlnqcQCuD f0y8lyxzQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lEk3u-0007bY-JS; Wed, 24 Feb 2021 02:38:02 +0000 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lEk3s-0007b0-3s for linux-arm-kernel@lists.infradead.org; Wed, 24 Feb 2021 02:38:01 +0000 Received: by mail-qk1-x72a.google.com with SMTP id t62so860192qke.7 for ; Tue, 23 Feb 2021 18:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Gew/d97c74HBNGUJfx+Rk0cvl8/ZTJmIMUjr9vTVx7M=; b=Ba9GMlCINUM+zY2JrGDsVLEbfP5OL5LB5Lw8Zm/phXQTYxBbGx1KE8j1zohBruOQKI O0/tmltbBWlopzuFvEvxtJioRfKWXhrusxsyjarp2eL2szg6ZMZJ7o9J+lgTvTOFa2WI Ulwcafe8tfBPsjfdWBRQM0tyAatPbS2YClRL1zMjwXGwMaOo6gY7aPG3ACfHQhcWFuSw Q+5YkT04eJI5IZJhj/RX/meMx4pTWC5xkLcA33T9HuGWo9gjzPlfLFqe1IoNIpxg9A+B ifTmRqN/+mNOc/gqTLAf40Tr4UifQF4DwB2IT1VGfqA/Z0WP83q8OzfvfASkL1hpBU8W /I4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Gew/d97c74HBNGUJfx+Rk0cvl8/ZTJmIMUjr9vTVx7M=; b=CGwPLDFw+vlL1tV20+CP3qQhaF9G4rH2mESqJ43X1TgCvomiGHd0DUjjdlYqY0y5RO NXxw0l3rO9ULMtDVxGgby+QCAgLvti+CA/dT+IHHgh40MnrQtUwMlO0Z2OfSX/f/VHW7 ek/rc0ny/V1TIufSJrLUkZbfdZxkMbcbPn5V86nbI0Ef0QF4zGrDMOyZFZXsAin4rE28 38b1fYPTqMSFjUHHRsW60bJq7uftnL07aUDeXNl3yXPiNpShPRzh42MomYeOaRCldQHf IbWSCyjzYX7hN2sxJK5TsfT3PKJauq1Md5lLC/Jxelbi8nM70ldIW0X2ruHG+/eQiByk bkVw== X-Gm-Message-State: AOAM5328QgaibsaVc5DkKiRiATRnVezPFvNh6NS7/pYUu/mpu4zxQwLo 1aBZ5QIgFaNEGsTBZ5X4TeA= X-Google-Smtp-Source: ABdhPJyv6fSMmxXyLVhqw8VjDlG1wwoFJhAdl2rxOscK1Ck0FT3LMmAZ/S0HMcFZ+aoVAWLm+IdRLg== X-Received: by 2002:a37:389:: with SMTP id 131mr29684614qkd.177.1614134276886; Tue, 23 Feb 2021 18:37:56 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id v187sm578477qkd.50.2021.02.23.18.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 18:37:56 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 7279727C0054; Tue, 23 Feb 2021 21:37:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 23 Feb 2021 21:37:55 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrkeeigdeghecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpedvleeigedugfegveejhfejveeuveeiteejieekvdfgjeefudehfefhgfegvdeg jeenucfkphepudefuddruddtjedrudegjedruddvieenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhp vghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrd hfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Received: from localhost (unknown [131.107.147.126]) by mail.messagingengine.com (Postfix) with ESMTPA id C334A108005C; Tue, 23 Feb 2021 21:37:53 -0500 (EST) Date: Wed, 24 Feb 2021 10:37:16 +0800 From: Boqun Feng To: Michael Kelley Subject: Re: [PATCH v8 1/6] arm64: hyperv: Add Hyper-V hypercall and register access utilities Message-ID: References: <1613690194-102905-1-git-send-email-mikelley@microsoft.com> <1613690194-102905-2-git-send-email-mikelley@microsoft.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1613690194-102905-2-git-send-email-mikelley@microsoft.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210223_213800_211638_1DEE1532 X-CRM114-Status: GOOD ( 19.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, linux-hyperv@vger.kernel.org, linux-efi@vger.kernel.org, arnd@arndb.de, catalin.marinas@arm.com, daniel.lezcano@linaro.org, linux-kernel@vger.kernel.org, wei.liu@kernel.org, kys@microsoft.com, will@kernel.org, ardb@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Feb 18, 2021 at 03:16:29PM -0800, Michael Kelley wrote: [...] > + > +/* > + * Get the value of a single VP register. One version > + * returns just 64 bits and another returns the full 128 bits. > + * The two versions are separate to avoid complicating the > + * calling sequence for the more frequently used 64 bit version. > + */ > + > +void __hv_get_vpreg_128(u32 msr, > + struct hv_get_vp_registers_input *input, > + struct hv_get_vp_registers_output *res) > +{ > + u64 status; > + > + input->header.partitionid = HV_PARTITION_ID_SELF; > + input->header.vpindex = HV_VP_INDEX_SELF; > + input->header.inputvtl = 0; > + input->element[0].name0 = msr; > + input->element[0].name1 = 0; > + > + > + status = hv_do_hypercall( > + HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_REP_COMP_1, > + input, res); > + > + /* > + * Something is fundamentally broken in the hypervisor if > + * getting a VP register fails. There's really no way to > + * continue as a guest VM, so panic. > + */ > + BUG_ON((status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS); > +} > + > +u64 hv_get_vpreg(u32 msr) > +{ > + struct hv_get_vp_registers_input *input; > + struct hv_get_vp_registers_output *output; > + u64 result; > + > + /* > + * Allocate a power of 2 size so alignment to that size is > + * guaranteed, since the hypercall input and output areas > + * must not cross a page boundary. > + */ > + input = kzalloc(roundup_pow_of_two(sizeof(input->header) + > + sizeof(input->element[0])), GFP_ATOMIC); > + output = kmalloc(roundup_pow_of_two(sizeof(*output)), GFP_ATOMIC); > + Do we need to BUG_ON(!input || !output)? Or we expect the page fault (for input being NULL) or the failure of hypercall (for output being NULL) to tell us the allocation failed? Hmm.. think a bit more on this, maybe we'd better retry the allocation if it failed. Because say we are under memory pressusre, and only have memory enough for doing one hvcall, and one thread allocates that memory but gets preempted by another thread trying to do another hvcall: hv_get_vpreg(): input = kzalloc(...); output = kmalloc(...); hv_get_vpreg(): intput = kzalloc(...); // allocation fails, but actually if // we wait for thread 1 to finish its // hvcall, we can get enough memory. , in this case, if thread 2 retried, it might get the enough memory, therefore there is no need to BUG_ON() on allocation failure. That said, I don't think this is likely to happen, and there may be better solutions for this, so maybe we can keep it as it is (assuming that memory allocation for hvcall never fails) and improve later. Regards, Boqun > + __hv_get_vpreg_128(msr, input, output); > + > + result = output->as64.low; > + kfree(input); > + kfree(output); > + return result; > +} > +EXPORT_SYMBOL_GPL(hv_get_vpreg); > + > +void hv_get_vpreg_128(u32 msr, struct hv_get_vp_registers_output *res) > +{ > + struct hv_get_vp_registers_input *input; > + struct hv_get_vp_registers_output *output; > + > + /* > + * Allocate a power of 2 size so alignment to that size is > + * guaranteed, since the hypercall input and output areas > + * must not cross a page boundary. > + */ > + input = kzalloc(roundup_pow_of_two(sizeof(input->header) + > + sizeof(input->element[0])), GFP_ATOMIC); > + output = kmalloc(roundup_pow_of_two(sizeof(*output)), GFP_ATOMIC); > + > + __hv_get_vpreg_128(msr, input, output); > + > + res->as64.low = output->as64.low; > + res->as64.high = output->as64.high; > + kfree(input); > + kfree(output); > +} [...] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel