From patchwork Mon Jun 26 08:58:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13292532 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C33BEB64DC for ; Mon, 26 Jun 2023 08:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sjiwsr3rufJH3dUcCnqagrGRKDQ0J31wgND+dNkvO48=; b=y0wyCzkq5KwqPK y3dHsLMplEYKQlkZ9d+5/3lOQt3KtyQ6bSTRXOnP/t84m9ztuZ4nQylknVu6MI6eKb5dw+4MfuZuX cfWh0axJU7CkLAPIOjpkyzvRu3TDzjS3XFGX+ZXKa/Q0giDeueKPhoMoB1i+0kLOG4bf5dESJSPqE 0Chslyk/cpuklYgdK3JGDZsAGF1buBH5xVpvzg7Q+G3vu0M9mQJxQakXzUtfrgcL7rIE/wI/bqFWM Tmz5XRwQrSCNtifGA7QtQ++KrmFyZifnMEhCq8w0E94mflczvZStT7LXhB6aPeK8dDk7Jk/CFTWiT nFwdmfG8JHYRmH6DZkzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qDi38-009gPs-1T; Mon, 26 Jun 2023 08:58:18 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qDi35-009gON-1M for linux-arm-kernel@lists.infradead.org; Mon, 26 Jun 2023 08:58:16 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-311099fac92so4245024f8f.0 for ; Mon, 26 Jun 2023 01:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687769893; x=1690361893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VXoqBJ5SjwaazwPupYLAmCHlcx6sG+m6SwqgWeDfHJg=; b=g4dDFsuLrP/kq6wjidgxCVSZBWexLlLfzozRLHF4rlKHxPrUkNxO67SrjoZCrESpdQ aJ2Cmd5YUbLlw8pzUsKV6d7mq6F1Ezl61pbT7nLBjfXhrL7kiOO05uDTYYlz5VKc6TKz MIjAcqUe2Qlu1VdxLUEhJ2h7eT1qJwLnfYQoUR00XBFUGz6TMBWsQ88/JJWSYusRGkB4 +nFCOiA2zsix3xJzeq14eqep7tG8m21EwDS4MGMT272sTncmfoSbKv6FAjcrd9TK2hYB cU+gfQIrPje7lhB+A4xggWp9smrQ992zaJaUmEBTjsCfRhJayX+epU8BfX6jsLbdC2VW LPFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687769893; x=1690361893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VXoqBJ5SjwaazwPupYLAmCHlcx6sG+m6SwqgWeDfHJg=; b=LUtgXlv4zfCKngoBZK32GcuP9npo6IethJo2KPTx1NEyxY84FHvNmIH1miJFtps61d 74oRGFpMR05yStwvodliYZrmUUYTHhLdGdVKepGkFDH4QhTRcvsJlmeRszCn2uL/4Gz3 d4u9vafF8CUC4stEQLpSi2PbewubXqeqqHd8wc5yZlp84+yJokH4Twz+vv/odTjI4WUT 9B7BFx9ftnGWoNfd/U22D8gy0kXNn3bofUmFv0BAllzrTH1GqkgMvp16Xi8jNkCmWp53 OH9IBudP6cZyaAWDNLr3nS/kaCdjAxFZhe0GVR0UkZ6dkZM/zr+tkisYU7tz6jvo5ZIx dZsQ== X-Gm-Message-State: AC+VfDztktYEFflxiu7+1LF6Bv2DXqu1DjH2RYkCrbiUG8tdtlZCtPxW XD6ci1CJrdNYW2zYcwWZFNA= X-Google-Smtp-Source: ACHHUZ5Amc/Osho99Kkutqafky4CNCXZK+MTntk6OuGOjVXPalxm7R230LqvZchQ4XpX7VlwKr3csQ== X-Received: by 2002:a5d:480c:0:b0:309:3e77:6cac with SMTP id l12-20020a5d480c000000b003093e776cacmr24739369wrq.0.1687769893315; Mon, 26 Jun 2023 01:58:13 -0700 (PDT) Received: from ip-172-31-22-112.eu-west-1.compute.internal (ec2-34-242-96-229.eu-west-1.compute.amazonaws.com. [34.242.96.229]) by smtp.gmail.com with ESMTPSA id h10-20020a5d504a000000b00313e8dc7facsm4883533wrt.116.2023.06.26.01.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 01:58:13 -0700 (PDT) From: Puranjay Mohan To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, bpf@vger.kernel.org, kpsingh@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: puranjay12@gmail.com Subject: [PATCH bpf-next v4 1/3] bpf: make bpf_prog_pack allocator portable Date: Mon, 26 Jun 2023 08:58:09 +0000 Message-Id: <20230626085811.3192402-2-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230626085811.3192402-1-puranjay12@gmail.com> References: <20230626085811.3192402-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230626_015815_454878_B5A52F0F X-CRM114-Status: GOOD ( 14.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The bpf_prog_pack allocator currently uses module_alloc() and module_memfree() to allocate and free memory. This is not portable because different architectures use different methods for allocating memory for BPF programs. Like ARM64 uses vmalloc()/vfree(). Use bpf_jit_alloc_exec() and bpf_jit_free_exec() for memory management in bpf_prog_pack allocator. Other architectures can override these with their implementation and will be able to use bpf_prog_pack directly. Signed-off-by: Puranjay Mohan Acked-by: Song Liu --- Changes in V3 => v4 - No changes Changes in V2 => V3: - No changes Changes in v1 => v2: - No code changes. - Added Acked-by: Song Liu kernel/bpf/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index dc85240a0134..599136cb5096 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -860,7 +860,7 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_ill_ins GFP_KERNEL); if (!pack) return NULL; - pack->ptr = module_alloc(BPF_PROG_PACK_SIZE); + pack->ptr = bpf_jit_alloc_exec(BPF_PROG_PACK_SIZE); if (!pack->ptr) { kfree(pack); return NULL; @@ -884,7 +884,7 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns) mutex_lock(&pack_mutex); if (size > BPF_PROG_PACK_SIZE) { size = round_up(size, PAGE_SIZE); - ptr = module_alloc(size); + ptr = bpf_jit_alloc_exec(size); if (ptr) { bpf_fill_ill_insns(ptr, size); set_vm_flush_reset_perms(ptr); @@ -922,7 +922,7 @@ void bpf_prog_pack_free(struct bpf_binary_header *hdr) mutex_lock(&pack_mutex); if (hdr->size > BPF_PROG_PACK_SIZE) { - module_memfree(hdr); + bpf_jit_free_exec(hdr); goto out; } @@ -946,7 +946,7 @@ void bpf_prog_pack_free(struct bpf_binary_header *hdr) if (bitmap_find_next_zero_area(pack->bitmap, BPF_PROG_CHUNK_COUNT, 0, BPF_PROG_CHUNK_COUNT, 0) == 0) { list_del(&pack->list); - module_memfree(pack->ptr); + bpf_jit_free_exec(pack->ptr); kfree(pack); } out: