From patchwork Wed Jun 7 09:18:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13270277 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 EA1BEC7EE2F for ; Wed, 7 Jun 2023 09:18:54 +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=CqMpAA9r1AHCC1hK+wKf28DDbVZTTk2ogbDFIUn/exg=; b=fissBexCURKr0G tzPQ2erapF/kAYZSXSOv2d2wQYNPAOt8AKLfMzQsayh3njBFgCqtTeTuSI6sY/quPXh7gAK1eU7OO A9PDgyGrCVrbN+76VGj/sY49EneSaDq2xj/bq7NYhEwL/JEr6yXpZMwC95LtT6JLUMOFUNpk1PK+Q ruGZJny3sMPCdy/dMVW1poLpTcOqqrQkAknYLdQkgqSI/Xk1hM/oHcJGZfZ/LXzVw2yfd+7R3Aq/6 nH79P1gXkGgqLuTR/XInp7bUPWxbPCM+9z4xt1aXsyva9Kwebqw+87qU4GgNewzum0F4bQI1UA9rV rsUo8optJjrJRQhhyqZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6pJD-005CX7-0R; Wed, 07 Jun 2023 09:18:27 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6pJB-005CTx-0E for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2023 09:18:26 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f7368126a6so31151175e9.0 for ; Wed, 07 Jun 2023 02:18:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686129496; x=1688721496; 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=F6Uppj2L6gcNwq0WUQbsPWgkus8exJN5v10BeGre/uY=; b=LkdeFZV14HqmY7jjdKucV4Ug1wKVdn6BKJ6VT2TsWcNkAzbMV/4uVxeur1uXrcccZA p4R+hxApHksn6Sl7gS6C7xyGa37wg+Va7LWIXh3c2U2GNY3TQaf+448yIXMxuzPi6x7a x8erRK9jXNL5MfSZP/R6In7v92OY9c8xRIQY6zMyBITN0fvmrhn25qKSLhpsIvWwXNVc h2kR4lLpvYixrEC6AeQxSG5KbFXFBNiNJa1tscBtEv92Re4YtFoX6QwTBC7zzqq1lNDb dlK6YMd8F0y3YaKtA/uVot3nFlrDnoKJosfd66W4/dkNHzPJv0y7wk4Fcs45/ttcRnCu PuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686129496; x=1688721496; 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=F6Uppj2L6gcNwq0WUQbsPWgkus8exJN5v10BeGre/uY=; b=hJfWbUszJUlf5pImYldraeuPdNi1gbw1rMFKaR8XkmHQSjTGfF/DfQB26KT/UivCfH uS5TmwmF1fHMs+VC87HoETV4/rde1kNMhEGjNEz07kRWUKdeB8aCrqvJCzwEp3daRRDx nISDHOwq2mEWiXXDtUkl7YZJKrOFgQfFQ41jyD9snhtAcsUXJ5K/BnSIqqDcDB8T3Tyo snO0kHDv6Wydx8E120xyTJpov7+SLoKlKdpL8q6EnNgZfdDFX2C+fvAR8k9YX+EQkpQ3 AJzUgStpuxXbUib3payAPqPEsck6vl7dA9KNRnycSw7YsafHPyOId9+/HcRNiPXWI6sr haHw== X-Gm-Message-State: AC+VfDxHvsoFMqwsp6+eHT4aY+CIpyuvoCeteuOxWbc4bCCmRHdfVISZ pAQQvuL7oUJRZEsK8xQQ6Gk= X-Google-Smtp-Source: ACHHUZ6fWYdp7Lua7CKdp+yQFwnOkFtOA2YLDXvuvLbB9rpyF1l73XYHBMSPmnzPLur7GbEFH44EhA== X-Received: by 2002:a05:6000:12c4:b0:306:2d15:fc35 with SMTP id l4-20020a05600012c400b003062d15fc35mr4048090wrx.37.1686129496225; Wed, 07 Jun 2023 02:18:16 -0700 (PDT) Received: from ip-172-31-22-112.eu-west-1.compute.internal (ec2-54-74-169-43.eu-west-1.compute.amazonaws.com. [54.74.169.43]) by smtp.gmail.com with ESMTPSA id cx14-20020a056000092e00b003078681a1e8sm15141958wrb.54.2023.06.07.02.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 02:18:16 -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 v2 1/3] bpf: make bpf_prog_pack allocator portable Date: Wed, 7 Jun 2023 09:18:12 +0000 Message-Id: <20230607091814.46080-2-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230607091814.46080-1-puranjay12@gmail.com> References: <20230607091814.46080-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230607_021825_105254_73F4729D X-CRM114-Status: GOOD ( 14.81 ) 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 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 7421487422d4..2bc9092bf9be 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: