From patchwork Tue Feb 6 22:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13547849 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEB8BC48297 for ; Tue, 6 Feb 2024 22:05:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56EC46B00A3; Tue, 6 Feb 2024 17:05:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51D0B6B00A4; Tue, 6 Feb 2024 17:05:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 370836B00A5; Tue, 6 Feb 2024 17:05:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 240186B00A3 for ; Tue, 6 Feb 2024 17:05:44 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E79AF16070A for ; Tue, 6 Feb 2024 22:05:43 +0000 (UTC) X-FDA: 81762761766.29.2FCEB99 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf21.hostedemail.com (Postfix) with ESMTP id 2115E1C001A for ; Tue, 6 Feb 2024 22:05:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZUXqDAHy; spf=pass (imf21.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707257142; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MsJBrUUPtruHWtQsS6zgKVxqPHg8IzuE7qrpmwhQpng=; b=SUFuxw/A+3wuyKpbFScbjH/6+5JzEuueF/cdMrLiujzj/+ylDH5SWXH7fQF8PSwWu/Wy47 cg24+ek11La254oFurvtJR4+FSDycTtDbjOFFaA8yoh3Ndq+g+nFd1eJsH0T2JgMYGBB/3 4RNlW6i3yjkUAU0Iqp/sHpWGODcx7Zg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707257142; a=rsa-sha256; cv=none; b=IM5ltOQXJ3evZvzPYibXAtiN8EBQZgFDSkOAUmVqTwvCSDiq04KFJWlmkUhz8JEbs/BlE1 8chAGzAGU22CNfymUhRJcsgwWYMceAwn06rH1JfG53y8M9RD/iq9hKbBCYPaE16TRI3wUB 9c1ztfzHa4gGviyXTLdwGj35FJSS9wQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZUXqDAHy; spf=pass (imf21.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5cdf76cde78so5486857a12.1 for ; Tue, 06 Feb 2024 14:05:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707257141; x=1707861941; darn=kvack.org; 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=MsJBrUUPtruHWtQsS6zgKVxqPHg8IzuE7qrpmwhQpng=; b=ZUXqDAHy08h8zJF2f0BbF4QaJ8RMATJHQUIp1PBgJ/gi3t8haODg17PoNkW9DOaGPW MmJ+BtX+V928mm93sr5S75iWU6ZM/emkikJQu7U45DHbCL00nBTaJ61cR9E9qtCJI1qr uOAyV5KCYO7a69CpbD7BVjI5djat7GX25613k9kgsJmYh/b+U56eQfqiu+QGvkR2MvLt 2ZIjCRq8l0ANVYNY5cOFEtRQ/Dwd1/jH1QFLAoZZ3O3kA5fZbugn/ZdZy+ROL1dJYUBP cCVCfDCTYOjrWsJkHspUrcy9pzDxnTmVui81YYspbWqztzukOLDZlxNGBrj60vNZPcWf Fo0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707257141; x=1707861941; 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=MsJBrUUPtruHWtQsS6zgKVxqPHg8IzuE7qrpmwhQpng=; b=JISFIuhlLst88xqofLbPggyy/TC0JPaca0fT644g5RT47zJpj51GPtSi/4saXLCTUH P2fA/Gpf07QJOQ9fK/R+dIIGNacfZA+OlTyrNQUEZaxP8xLJv4wEe+XF1SzbooKcnkJb Z4idkhQWUkzocUUF3pSQOq5nVxrGfjRaHwTHDsTNo7d1mgbgof05LUxFI4BvKpseN9w0 bpUYao2WHjZmbKPWAx2DE7v7geAq9FTXHPv4wWVG8Pb+Z+eCmOtqPwDsLM9LRKvdFEUb WstzmuPUt4XQmmvCIe5W1pp4mtfu/e2i+AHuH7+AwL9ym1dHtpZoKHhUuvjpcSjNBNZx 8XSw== X-Gm-Message-State: AOJu0YydN9fo2teANouMnq7pNx1NFYqgYAThfoOVav36n9V8Xay0Mql1 PKoP07mu2AP3A4juUBY5qIy+27IgWc/AwpcqMPqDzLUVn2/F1OTV X-Google-Smtp-Source: AGHT+IGdHBHn8MfZOBdjDr1wev3fr0slDMYt9TgRf3fpt6EWXX4IriOrk3M4U7i1fJwsabnbpdMnnw== X-Received: by 2002:a05:6a21:1798:b0:19e:a1a1:5360 with SMTP id nx24-20020a056a21179800b0019ea1a15360mr1112802pzb.23.1707257141056; Tue, 06 Feb 2024 14:05:41 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXz5G5HRMjkZjOv6ZNWk6IaBtAGKiStm6/yVXkGspRuSxmD8HC/H4mL6JLFh1XIx4+3PUuzmNG1hY1hX1FugKNofjuX0OghF/O+bK3DIKUNmz9/KnpQdtT8//WXOCO2GXI8KGJN+EmACq9yWmsUXs7bFR9BI0sxDJuQnL9vbW+jHQa5a3qDh4DEh2y7YXrvFIQ58H5MaP8nMeLs3gE0dbpirRALVTKUDLfUP/yiW6/QSk3qNwqYmu3W8DUazqg05AWtkQyQJbdVkyiE0bsIoonUbE2V78dSYFLF Received: from localhost.localdomain ([2620:10d:c090:400::4:27bf]) by smtp.gmail.com with ESMTPSA id sz14-20020a17090b2d4e00b00295b93bfb24sm7888pjb.22.2024.02.06.14.05.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 06 Feb 2024 14:05:40 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, memxor@gmail.com, eddyz87@gmail.com, tj@kernel.org, brho@google.com, hannes@cmpxchg.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH bpf-next 14/16] bpf: Add helper macro bpf_arena_cast() Date: Tue, 6 Feb 2024 14:04:39 -0800 Message-Id: <20240206220441.38311-15-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240206220441.38311-1-alexei.starovoitov@gmail.com> References: <20240206220441.38311-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2115E1C001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: rujzmts8ch9mxbifcnxpjhb3h7365zoq X-HE-Tag: 1707257141-95073 X-H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321zzxcK8+JTNbcpG36B7VKa6dpNl7SslZjth3PAxXaip49FTyu7BCwLHOi+fnD/lVaxhfRYBL7Q7V8IfZ+ZyaF9vKSOILKX6b1B6EfwtzCGMVVeJPPXrcolFVLElC/QJQi4CpvSjGjpQlm35f5ePjbGfE3sm33wH8bEwfufDek4fnJz/eZfYBt/zHFT3lsmZhJtNu1SRxX0Ptwm8v9492WePt8TMnPzDm7vpBnMdH7/Aw+CW5uRj7TXNvXYtIBWmaXh5xu234sSLlsqBUp0q9rzkOCrbJjx8ZO2FwOw5dGp56tkAakIHX4vMT4dP5hxtr7l/HvFdbIh62P//qZMEop9760KWZTyFdW8Djwynt9zaeHi91cmRQtd39sr/ya3yUaCFm/lFpbkKDribs0QICJrtaZ2a/xsYRjh7y1f4feANqlybKOk3EQwfe3tcbM9i7PWg2E9yC9D355HhyOND1F+BA0Dnla8FTHNtC9MCckF2oJTYAv1zHvnvU4MmVIrQCNOUitPtK6PNxFPbiRaCLi/YvW4U05O X-Bogosity: Ham, tests=bogofilter, spamicity=0.000296, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov Introduce helper macro bpf_arena_cast() that emits: rX = rX instruction with off = BPF_ARENA_CAST_KERN or off = BPF_ARENA_CAST_USER and encodes address_space into imm32. It's useful with older LLVM that doesn't emit this insn automatically. Signed-off-by: Alexei Starovoitov --- .../testing/selftests/bpf/bpf_experimental.h | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index 0d749006d107..e73b7d48439f 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -331,6 +331,47 @@ l_true: \ asm volatile("%[reg]=%[reg]"::[reg]"r"((short)var)) #endif +/* emit instruction: rX=rX .off = mode .imm32 = address_space */ +#ifndef bpf_arena_cast +#define bpf_arena_cast(var, mode, addr_space) \ + ({ \ + typeof(var) __var = var; \ + asm volatile(".byte 0xBF; \ + .ifc %[reg], r0; \ + .byte 0x00; \ + .endif; \ + .ifc %[reg], r1; \ + .byte 0x11; \ + .endif; \ + .ifc %[reg], r2; \ + .byte 0x22; \ + .endif; \ + .ifc %[reg], r3; \ + .byte 0x33; \ + .endif; \ + .ifc %[reg], r4; \ + .byte 0x44; \ + .endif; \ + .ifc %[reg], r5; \ + .byte 0x55; \ + .endif; \ + .ifc %[reg], r6; \ + .byte 0x66; \ + .endif; \ + .ifc %[reg], r7; \ + .byte 0x77; \ + .endif; \ + .ifc %[reg], r8; \ + .byte 0x88; \ + .endif; \ + .ifc %[reg], r9; \ + .byte 0x99; \ + .endif; \ + .short %[off]; .long %[as]" \ + :: [reg]"r"(__var), [off]"i"(mode), [as]"i"(addr_space)); __var; \ + }) +#endif + /* Description * Assert that a conditional expression is true. * Returns