From patchwork Thu Sep 6 06:57:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 10589931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50D1F6CB for ; Thu, 6 Sep 2018 06:57:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442A52852D for ; Thu, 6 Sep 2018 06:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38AFE2A3AB; Thu, 6 Sep 2018 06:57:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98D3A2852D for ; Thu, 6 Sep 2018 06:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727682AbeIFLbv (ORCPT ); Thu, 6 Sep 2018 07:31:51 -0400 Received: from nbd.name ([46.4.11.11]:48206 "EHLO nbd.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbeIFLbv (ORCPT ); Thu, 6 Sep 2018 07:31:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=v5U4MO+5WpiJJ3dIZg47xo4EgWOABuQAG6tsVvWhGH0=; b=MtVkrpBmo8oVk1hnrMtbncht1I Y4sY9+aNJrr6mGuIDTfaowK/Vq+luTzgIAExsQYKyFH1+Cr69cbpm21SqEEM8WzNru+pz1YT0kmqB s00BlnUXjY+uDVoR4W18IR8S9we2t0ujGFu2KGsWL03lRKMVOBbDqnA95p1VGCzFkeTo=; Received: by maeck.lan (Postfix, from userid 501) id 17803379246B; Thu, 6 Sep 2018 08:57:50 +0200 (CEST) From: Felix Fietkau To: backports@vger.kernel.org Cc: john@phrozen.org Subject: [PATCH 2/6] backport-include: backport kvmalloc and kvmalloc_array Date: Thu, 6 Sep 2018 08:57:46 +0200 Message-Id: <20180906065750.89673-2-nbd@nbd.name> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180906065750.89673-1-nbd@nbd.name> References: <20180906065750.89673-1-nbd@nbd.name> Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Felix Fietkau --- backport/backport-include/linux/mm.h | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/backport/backport-include/linux/mm.h b/backport/backport-include/linux/mm.h index 3234b37d..6ee5c7d8 100644 --- a/backport/backport-include/linux/mm.h +++ b/backport/backport-include/linux/mm.h @@ -3,6 +3,9 @@ #include_next #include #include +#include +#include +#include #ifndef VM_NODUMP /* @@ -123,4 +126,36 @@ static inline bool page_is_pfmemalloc(struct page *page) } #endif /* < 4.2 */ +#if LINUX_VERSION_IS_LESS(4,12,0) +#define kvmalloc LINUX_BACKPORT(kvmalloc) +static inline void *kvmalloc(size_t size, gfp_t flags) +{ + gfp_t kmalloc_flags = flags; + void *ret; + + if ((flags & GFP_KERNEL) != GFP_KERNEL) + return kmalloc(size, flags); + + if (size > PAGE_SIZE) + kmalloc_flags |= __GFP_NOWARN | __GFP_NORETRY; + + ret = kmalloc(size, flags); + if (ret || size < PAGE_SIZE) + return ret; + + return vmalloc(size); +} + +#define kvmalloc_array LINUX_BACKPORT(kvmalloc_array) +static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(n, size, &bytes))) + return NULL; + + return kvmalloc(bytes, flags); +} +#endif + #endif /* __BACKPORT_MM_H */