From patchwork Mon Aug 24 16:46:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11733809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9424B14E5 for ; Mon, 24 Aug 2020 17:13:19 +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 5DE322063A for ; Mon, 24 Aug 2020 17:13:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VENazrNs"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bJLlDO5g"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="Crej1C1g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DE322063A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=673wYPdpfT3rNmf4ZK70K791erOxJW8QN7TgdVFYHjw=; b=VENazrNsnWpaCldxzdsXVwb2w 80l0KgX8xYVuzCj7RcKBOFuqAb9tc+t1sLJcFax8s6y2XlGkMkAemp9SanDDoIyjdDFIqCYp9nGSS 2J26E6PvxUMEI7vtkVjObWsfiaoxgkX/Is6HG2ybCyUqObtuiBxsG8PgU2HWDxZ+RUEP2lq9pwItH WyaU8k0RPntZXLIFMguwJlnfYOx7KWXw99RembZPvFy+tSUWKcCauJfQUxfsG8hPriIo5f3YHalfG mpQPS7hKCTxu2v7akhm60YRO1J3z04mX9mFrUdEHKUT2vqA3xgAkwp8jTq3AO9+sVcCttjzEk8FjB O/yafKNXw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAG01-0003nH-4r; Mon, 24 Aug 2020 17:11:13 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAFzg-0003ex-E4 for linux-arm-kernel@merlin.infradead.org; Mon, 24 Aug 2020 17:10:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=h90iRs2LNed01ztjCMOd97VyD/Aapry8OrQ+KqoQZhw=; b=bJLlDO5gCfk1I0Z0xHDCDoJGc6 jrXqQ/bcRrdPKIX2QjXuc5v3OtvhZe2X27McMWoZoGiU1uRGtBCIwt0rvFXtHro1Vrnm8mEPHl1u4 b0J7ikn0pU8f0+fky9t75n1iInYpOfbMBVI13/OQ5rWqg0VbJnhebUGHh1vXHdpkp7HhtzoaaFytN ChvTJPSaWxPO0Ow+yY91+6H9TcepNt9vLfqAKSRT5trNuoFkhmvOZWR7BbQ0il49TYQQYw/U+tuou cYqxlXhrjKHNSnLhQRAQjvuQtHCwJsRIktqcJ7ybY+JJKBJUXKnMxFZJ4VH4vueToKBEfm2E0rpmg iz66MnQw==; Received: from mail-dm6nam12on2128.outbound.protection.outlook.com ([40.107.243.128] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAFdv-0001wk-9x for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 16:48:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WApy1dXTtbRFJVTg0PKD+APQCw295emjOQ99J2SdlmlL+KmzZpTtMiZHDjm3bFtMGPvKRB04hrAjy7SBlABDa9K4bv+DvSaCgIIuVZmX82R7Ge7mIKuET5dVmuDPBWY4XdHa7Sd7X4W3zFtKwCFB3Eh7/LYK+Uo0wdl+PBmC9WBpFhCmiE0PmOgiYbl1BJ0bcZIl6ChaL+NGG3wjmPhjedD/qjQkkZy8Br8EUAMyMvpDUp8e/g9nh3CIqgntf33WPb43dIPg1t8VlgDAcf9Tkj8O2sNQwwyMoeHaNjWoCmlGlNWsKBcpRKdkv20oyAfbQoKm6p1pdiNoift7mwKJhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h90iRs2LNed01ztjCMOd97VyD/Aapry8OrQ+KqoQZhw=; b=jHfSVzQa6cStXXqNzi6oDOidexrNLDH8Goge4z7UBoJsXLcw0jjJxNevFhrdFSSg4X96TDGT1Tf/jYCHDli7yp4gkHDQMbdIPJ1KjagWRRgvEDog0hFtQUJJPAFjEohh+IXE5xD+BKYNPGedjG2yTJwWj1ZQgZ82wJKEPziMoyPRUFwcuEtdM0rHxoXwY8de/Hi3YEF8Jx6io37kBelov/3PW44bwxjBwOLbddVkk6zlJyvDHU/P7oCl48PLi8ucv7kPNuZHsrV/kvfE9KfDlZUF2qDDa+Qm73I/HNUsqfXdQiMCNRM+QCV9dVv/XQqXu9o9ysBPsSO4aIUYB1nfhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h90iRs2LNed01ztjCMOd97VyD/Aapry8OrQ+KqoQZhw=; b=Crej1C1g+f6+rcJy/W/WdqFLKdiZWE0jGNvKctAiksBjRz4MliBM5uvJ1nUa3kF3naA6FBTgevlulrGwbjjkNuU8zl6A405BZFCZNnZNgBTsGsnLvI9Fe/+kAsrJFaKd0IhLBu2gjFTTDO/8AQNBg23e2/S8G0lVlaeZFmrlaRk= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=microsoft.com; Received: from BN8PR21MB1281.namprd21.prod.outlook.com (2603:10b6:408:a2::19) by BN6PR21MB0753.namprd21.prod.outlook.com (2603:10b6:404:9c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.4; Mon, 24 Aug 2020 16:47:48 +0000 Received: from BN8PR21MB1281.namprd21.prod.outlook.com ([fe80::e0c9:2634:6fb1:5615]) by BN8PR21MB1281.namprd21.prod.outlook.com ([fe80::e0c9:2634:6fb1:5615%3]) with mapi id 15.20.3326.012; Mon, 24 Aug 2020 16:47:48 +0000 From: Michael Kelley To: will@kernel.org, ardb@kernel.org, arnd@arndb.de, catalin.marinas@arm.com, mark.rutland@arm.com, maz@kernel.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, wei.liu@kernel.org, vkuznets@redhat.com, kys@microsoft.com Subject: [PATCH v7 04/10] arm64: hyperv: Add memory alloc/free functions for Hyper-V size pages Date: Mon, 24 Aug 2020 09:46:17 -0700 Message-Id: <1598287583-71762-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598287583-71762-1-git-send-email-mikelley@microsoft.com> References: <1598287583-71762-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: CO2PR04CA0145.namprd04.prod.outlook.com (2603:10b6:104::23) To BN8PR21MB1281.namprd21.prod.outlook.com (2603:10b6:408:a2::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by CO2PR04CA0145.namprd04.prod.outlook.com (2603:10b6:104::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.25 via Frontend Transport; Mon, 24 Aug 2020 16:47:47 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [131.107.159.16] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6ffa684e-4fd2-4676-1901-08d8484d6f14 X-MS-TrafficTypeDiagnostic: BN6PR21MB0753: X-MS-Exchange-Transport-Forked: True X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HXac9jyTZg9XHgzTC+Ls8xLP/V9eUrl7yqI/53PFWuNgOqJw27gtnh6frOuxOueq2Az4v0xj7CJfLK744+kQwyUkPVq3yHxRgQl6uQqq/c1bEBaXVDyQG60b7tY3rfbPqkykjyV1MnMFGKO1jiISI5nyA8Q0djZAjM79XfBOJ7y8K2A7PX+rB4KfMMlqakFoPAMO9L3hdLOxhhyy/FXqI3IuSnWE4xFd7u+bjSsbT/cVkhvvEWX12pO0mIyht9BxJ+He3XPrMCx2uxefoWPFYEOj6V17GX56FeLS5HgYbrraNDZG8LbMH+7GdAUq+o6+UbVt9zzDCfUAZuSD+OH+hF3oZYE3666qlS/0pNMyCmoB5OUhLT6lpWbQ0oSpBe9o X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN8PR21MB1281.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(366004)(376002)(396003)(346002)(8676002)(86362001)(2616005)(956004)(2906002)(6486002)(8936002)(52116002)(10290500003)(5660300002)(66946007)(16576012)(66556008)(4326008)(6636002)(316002)(36756003)(186003)(82950400001)(478600001)(26005)(6666004)(66476007)(82960400001)(83380400001)(7416002)(921003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: zZd8Q1zNASL8UTDW3/iQ+qv7P9P8HzW1+mzfW8JKblJtAKPc46qGHd30ABZq5adVNeO9fhG1CdKLQJcMV9uTcFQroPABqxfFpWOD/1W9neNqrIbZUQ85jLHYytCLzMO9G+wX57hAPWgIFENsQkGe9wml+wRrrbMkzoUu/uOmYwFWtFJc3ScYlcE6DkiQCxt24Va+MeIsZ8udxOGEevbLZiboqi3Cd3EnwYrtin6iAy49baf3qJgb9bJcHNMHxZ3IntyHJU2rVPIjSgMefOUDmBfdM/7qU0a6d707ymcXckBRSttg6bKdDQKztA4iwFERLF9bDBtnTrjb/m55qcgL/qEicw/ZWjdXipOOxohuvS+B9iDMc3Qf/Jho0KOmO572n8ggVLVPKKoTpfQz+pgnqMUVUKtbFrY2EeyukI1LtujcqEr/XfMbRNM0N3M6BX8mfmqufaxOZpqwAGNFuBcd/GzoKU41TcOUPpn+lKSA5CIhPuBxSBYCAEMwYNZj6t72SSxe7q5ipnhWOlcDWRxDx47nkyHmy+lXgHAttxF7P20YV5lBVaDvOJHECdxeiyHhUZ7HRHtVUKgd5rDgboCqstQPCxgkzv+vuzwlIOMkssFoxa/COB2PuqBiH8mV+ySWqy/M/mMiquHKfM2l/u/LWw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ffa684e-4fd2-4676-1901-08d8484d6f14 X-MS-Exchange-CrossTenant-AuthSource: BN8PR21MB1281.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2020 16:47:48.7434 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ajUFDDZHRXatKiOSPQdQ9+ZNfTGLLw5Qqp2+qWXtgEoZ4/YofhMrDGRPrcLfaa0tgkgEWQNaz0BAkZ6r3r/E3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR21MB0753 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_174823_633099_32953613 X-CRM114-Status: GOOD ( 15.20 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.243.128 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 1.3 RCVD_ILLEGAL_IP Received: contains illegal IP address -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [40.107.243.128 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay -1.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender 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: sunilmut@microsoft.com, boqun.feng@gmail.com, mikelley@microsoft.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add ARM64-specific code to allocate memory with HV_HYP_PAGE_SIZE size and alignment. These are for use when pages need to be shared with Hyper-V. Separate functions are needed as the page size used by Hyper-V may not be the same as the guest page size. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- arch/arm64/hyperv/hv_core.c | 43 ++++++++++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 5 +++++ 2 files changed, 48 insertions(+) diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c index 9b35011..14e41b7 100644 --- a/arch/arm64/hyperv/hv_core.c +++ b/arch/arm64/hyperv/hv_core.c @@ -24,6 +24,49 @@ /* + * Functions for allocating and freeing memory with size and + * alignment HV_HYP_PAGE_SIZE. These functions are needed because + * the guest page size may not be the same as the Hyper-V page + * size. We depend upon kmalloc() aligning power-of-two size + * allocations to the allocation size boundary, so that the + * allocated memory appears to Hyper-V as a page of the size + * it expects. + * + * These functions are used by arm64 specific code as well as + * arch independent Hyper-V drivers. + */ + +void *hv_alloc_hyperv_page(void) +{ + BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE); + + if (PAGE_SIZE == HV_HYP_PAGE_SIZE) + return (void *)__get_free_page(GFP_KERNEL); + else + return kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page); + +void *hv_alloc_hyperv_zeroed_page(void) +{ + if (PAGE_SIZE == HV_HYP_PAGE_SIZE) + return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); + else + return kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page); + +void hv_free_hyperv_page(unsigned long addr) +{ + if (PAGE_SIZE == HV_HYP_PAGE_SIZE) + free_page(addr); + else + kfree((void *)addr); +} +EXPORT_SYMBOL_GPL(hv_free_hyperv_page); + + +/* * hv_do_hypercall- Invoke the specified hypercall */ u64 hv_do_hypercall(u64 control, void *input, void *output) diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index c577996..d345a59 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -101,6 +101,11 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type) extern int vmbus_interrupt; +void *hv_alloc_hyperv_page(void); +void *hv_alloc_hyperv_zeroed_page(void); +void hv_free_hyperv_page(unsigned long addr); + + #if IS_ENABLED(CONFIG_HYPERV) /* * Hypervisor's notion of virtual processor ID is different from