From patchwork Fri Feb 9 04:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13550857 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 ED7FBC4828F for ; Fri, 9 Feb 2024 04:07:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7931D8D000D; Thu, 8 Feb 2024 23:07:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 741A48D0001; Thu, 8 Feb 2024 23:07:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E2B68D000D; Thu, 8 Feb 2024 23:07:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4B9038D0001 for ; Thu, 8 Feb 2024 23:07:23 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3248C1603DC for ; Fri, 9 Feb 2024 04:07:23 +0000 (UTC) X-FDA: 81770930766.29.20E0799 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf07.hostedemail.com (Postfix) with ESMTP id 4E9F940009 for ; Fri, 9 Feb 2024 04:07:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bYhs3uvS; spf=pass (imf07.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.177 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=1707451641; 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=kfu4M+rQY4YDPeuu76esZ0TIxVCJzZWGNUp4khdft2esLwsTmhvMYDePqL4H3r5MWuObB8 aQweItRxkvjl89KDjDhb2blXLD238+M8+7e5jy/P7+ScUjNAg3GSgnN/DJAX+S8X5tpjo2 LBZT8KjW6aZvYMEgjW5Y2rP3WM6I4vI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707451641; a=rsa-sha256; cv=none; b=i1+e78kJOX9mVEmSWN/fW2e6BXzH7tbcr/o2Zu6fHo75fdzqXB6rVaM+u0z90XzKmK6ZKA O4drR6h3ft0msYkOOb5mPJiJSpRzj8rE6oCfdeiAdfT0MYa+iGXkzr7trhOptMSqvdgwmQ g6IEL6hYncrl8NlRKcizYzvOM6/P6ks= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bYhs3uvS; spf=pass (imf07.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d93f2c3701so3167145ad.3 for ; Thu, 08 Feb 2024 20:07:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707451640; x=1708056440; 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=bYhs3uvSAexCEhBut9bw41bkJaR8YX+JCeKuNxqLbKSdj2GnKos1+tLROgPPuID4Hl +IcBbc9w9Z3wOq6aXUdTQkWsUK+1ZFUNhxFunuTlz3zIkZvrEk8hnpQsAX8ogWF7NhiS n3beBT981/8p4Q6jlD9c2S6I7cdmKuNf9/4h7INjupIVB37+OvZ24MKhDG6qIG+9UNiT tokLpnV96Kh9Gn8rdUj3HWduKMxwitSlIznRjWY9ZfTBfEIYT8BUFWcwQcn37jcqX1RS oOz3D5lLZuegTy2aufO4hjBBlH9IGZzCm9SG68nOBaTwjgxxpCEJhVNv0GehcENSZFsC ImNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707451640; x=1708056440; 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=TsgL8wC57W/Z8oBdBALkqps19JQS9kc3qmTyNR57/WazRhUFGNvXMnT+bv+uoiJcTZ t8OVMfysODqnvCvNJsemHvkzFS8v94jDsc8VA54De/oDtv0YZP4KWeJDei2eeQwGEL4T 9O+znI+GJoGSHO0nSwfdvQUSzOiFG71VFlN/Ax78ATWNU+fycBvJ+RoA1bzviuQ5ut/Q ng0dP8XQ7XXonNSj614+jkXnDbq20YXeDwwS9ZoZnbOeZmWsSpv2VIutUyOMAceT83vg yqxyOGgGqzXkyTn6vwVJzLRZ3v52VvI0Z+z9QchI5Borkmgh5fpjU6R4zzRVHKbVPsP/ FHzA== X-Forwarded-Encrypted: i=1; AJvYcCX6rf1t2zk/6sOh3oIpln8A0pHuiLNMj0yj3M2xFH3KIjMfp2/1rX52vkRJ+F+OWLx9+GcehqLY6erRANZ9RntS+lQ= X-Gm-Message-State: AOJu0Yz4sktRhHjxLPIPBq/CJfRjHLiB7b2Ud6ufjh6boePek7FUIaSZ RfqnAWrf2eTx98Xew7j5U/g+CFiYrI6i8ciEaLJHsEjK7rmShSs9 X-Google-Smtp-Source: AGHT+IFFu/goz1FrmbpZ66r+D/WoNAbblyTq352/gs8sP6e/6QY7jw8AvLvp16EdF9oF+hm9bcXL7A== X-Received: by 2002:a17:902:ced1:b0:1d9:a2d3:8127 with SMTP id d17-20020a170902ced100b001d9a2d38127mr470046plg.52.1707451640097; Thu, 08 Feb 2024 20:07:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWP7HPoDU+RIV0hbhhVZtaTKZ52ozQSAI2pmi/5/+M4R+kofDRBWlviHowAmZf4KAFWB00xVtEVtRwexebBtYOr5AunnGUHJHavtyq1fO76hzOsbjlXb6ahRaPTVniCLqPQVTDLcmGtA+rqFV9qPMYDXBfd1cJ61lPC4OPXYwCm56ZKxVkulgzpnfoB2DhozBGuIbcQ/lmUZzREPwYFIWjmTN+9/y2JuUZspdbHfxqeXh60l+d35X6YqgaPJBYzRA+h7ETU6QLl1X17oZ7YJWJ35m4Mn4X9nbYlY0JqtdjgCe50tzxXbXK82HqDvWSALZFykpj6UqRgzuzDJqpHvP6D7mmZ/eNM3hPd+94XK6JgFgmhKcw1oA== Received: from macbook-pro-49.dhcp.thefacebook.com ([2620:10d:c090:400::4:a894]) by smtp.gmail.com with ESMTPSA id i19-20020a170902eb5300b001d8f3f91a23sm535557pli.258.2024.02.08.20.07.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Feb 2024 20:07:19 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com, eddyz87@gmail.com, tj@kernel.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 16/20] bpf: Add helper macro bpf_arena_cast() Date: Thu, 8 Feb 2024 20:06:04 -0800 Message-Id: <20240209040608.98927-17-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240209040608.98927-1-alexei.starovoitov@gmail.com> References: <20240209040608.98927-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4E9F940009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qkaiys8qr7h3nyyxkt1mt1e577mzqkeh X-HE-Tag: 1707451641-345264 X-HE-Meta: U2FsdGVkX18wmtLP74DCYm/1ytWs6K4jnZY66WoIAKSuStMRiYBCK14IcUgfvKBxlMaf4W/5dC+by8T7p1Va1tJxWj9oCs0zAbO7vOgFAbaBNpHCFFswkcGBCCOLnG6llwbC3Gw0PhmQLaShDYre1aGKckD7LRscSpIgDeqCROW5bFkpFOZDta6RIFSY8faZzmR5mlE7aN9C2nIRSd17fSHc8w7ELXJStljNhQoME8alNwngvXnD1pTH0V25Wi+5F16flvWtAo3PGHDHHz56fY8grCpC5JM5f1RtklMmkq62U4lQJig1MG6EX8JzbPqmUe7fIAjlVBJLNImACX+M0bk3pODfgm2n8QTHq4cpI+xQYxyGhNZ/xb8OTp93ZmK5vcHeOIdYaCdSbv1mCt0jFbkysv/KQznelXPZULT71y4/BHWs8W5FuXUggr2WEHSy6ONk6HOAmZEIn3mnsgBaA2RpkNwe7ygMw6tGcyS0fChGV1mR6gExfTa76DdbfxDA4ZYgS+jCe9qd9vMpPgZkOAaw2FGzEF+WDhMEMFbKXwj0/T7Ct6uuWjP6i4JZxRde0bT/AbLZSzFjZM6tjnIBZ5RLP2R5vux25T9uOQbWRBKflwxSBdGHEG3UGd5L8Stv98fux5MCf4DLBD+4lyG9ohcUBTSJV2m5WUcRMmOef9VKrbd1xNCAQYK0tGNd8o169ZCuw3+ePh83V1oj06CHmtDY+zjcRnG9Ddd8eXoxh9wg+x43+yfmJR4QkQlsCQDK0Nu4eMxXEq/efeJcmH0e5oWeS0CsfHUyT3jXpvKLAuDJgvFhCqJhxi2eTmAESFyrEZDOg3qyO3w5hLnbuieGy7q4EMUK2XnKN1LpW6skApCo89mhsiLgk6U8uHbDO+AsHafeF6xA4AIxXR52aFp4TSLwPvXhAwu49TleRw/kBMffJ9xZX0B1m9y2Omaxt3DvNx6m8uj7XBkW7+0iatL vvpfzZCO eMjqdB7tZEnu9kPdXahDtYHNbnGsH1mAJPqApgiCrDgGA+2TKgSB8lsKm8eY+qQjR3WEOK15QikO0V12f3pjtkZyo9Ooa/qpCQ+NTYLLIFUciBA3rNdYsJSxSbEiKacOd5v0nMM36reC3QN40pkRbyXtNelGfhDgtXnRzlg3x63ngj9wDEnVOEMgsZTwCUR6nu9B/JYMXfuFwp/JSGtqnG4qvYKgnm2nEZfF7kD0irCDTpfRi0Fw0fQPmoHCO6v72yAXtGujHnrxyFXUG8ZpjYBf5JRvWicaZL5CGSObe+99kmdod8+ja9hszWsberj+aRkx/B8+RkVdA46h/p1huEcoiKWVi4nqilP1nGwmuem8pQyYhMRRuQqtTcEon+7Fn1nXyiASFA+O8wCIgs/0pcVL6RrV947K9fUZ9VNYBL2WU9D5cqTsOLflVlJu7QMh/p5gbWfY4U6ddb/IjSxKCyAcE5cpz65n72EMQm8dtxkBwbNpjbhpB+ih/dCUoVZ1AkniktTMDwoLtZ21ThT3M4JCKRUa5aOHpEc0PNc3o6YwhQLNh+K6nBr9Cezjy8e6M/+AXdIXxDDX1lwQ288JL08QXpDq62UJk+Unz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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