From patchwork Fri Mar 8 01:08:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13586417 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 BB7C9C54798 for ; Fri, 8 Mar 2024 01:08:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CB0F6B02D6; Thu, 7 Mar 2024 20:08:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 477406B0305; Thu, 7 Mar 2024 20:08:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EF136B02E9; Thu, 7 Mar 2024 20:08:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 19EC76B0248 for ; Thu, 7 Mar 2024 20:08:58 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EBA1FC1206 for ; Fri, 8 Mar 2024 01:08:57 +0000 (UTC) X-FDA: 81872087514.01.E962AD5 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf05.hostedemail.com (Postfix) with ESMTP id 4F33E100013 for ; Fri, 8 Mar 2024 01:08:56 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bQxn2Q6x; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709860136; 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=fY/F16mIRVOasuBIDKCOT+6tHBoD4McdBdkvkV719K0=; b=FgZ8VKgdxP7HHHsxiumwZ4PXG6Lb76mOQn5hIZwDHYzbXHGyZi43nKeHE9/V9Aw5aqNP8O PnuoQRc1o0AlVdN4EhSq/INZ4XPo42av/OHEgOrZABgzVLRv+zRDbjKGLth5tvOznyvLBy 9+PkiXsK3vPv+CCFhHzLMoYMhd9Cfw0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bQxn2Q6x; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709860136; a=rsa-sha256; cv=none; b=z9BoQjQ8GJ0rCAXPTFS55hf3m0Pd5xF+dNQHobX5NO3SDpTsoIkgN5FN/cJZWeJ/m88URi haA+8b/E5/3qSzPW5127NKe+Clc3J2Hrzrh3K/SkiIAb7JLYPt+HHzpTWD6bR5rwss8ZzA DYChVrw3wPOA5Q2qgUhEMaXkp+xEqd8= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso239976a12.3 for ; Thu, 07 Mar 2024 17:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709860135; x=1710464935; 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=fY/F16mIRVOasuBIDKCOT+6tHBoD4McdBdkvkV719K0=; b=bQxn2Q6xl71+IPIY8tINQPkJbV49+bJHcNrtcCR8tvLyI+mgtadhtRlFcecTV9NUn2 FhSXSsHuR8EReozM2Rq/5fx4qRg3JoXWJabS2Grlpo2GRs+R4HFMeX5Y/yXf51VqGhUU 6RUYkCDAy9X3t1mgCp7oPkTkaReh7FSoUNcmTMXK5rzlwttGrWrvL4fEqsdZgIGvtzvw qqG04CzonTqLLNCJN+7PBauNRWSaIVyxktZBnzyTpfzh8sj7KTTrt9b0wNDtenanmcSM TPgiKgVSjK0aq6DvKa34/J51MS4Zz8t1n+FPM9xGpbTV9SwpiiHJOg6NcSLaEKk+LP96 C3EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709860135; x=1710464935; 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=fY/F16mIRVOasuBIDKCOT+6tHBoD4McdBdkvkV719K0=; b=b14TD3ySmMDe0iXelXwtuHoN8g2AGI135R5q0Z+98ZptKkfIh2OETnH4htn/Y2KGbQ G0R8IKyYVKvrSZIrQTuwX7A5SvMLpi/fjO3vrvJVw4XU33exDvMH/o/OBz8lnm4BYmUx M81wAVV5ksTC5n4REK4kVfKx/+JMmAgGvNbMHbQ9PoY2fXCG4aBxmSLHyDRv1E3uxvmY zWQ4CxgcWZSIS6dSYXGC3qyRQihOhSTaqiQ+Wo160TVnQ3GCZ8cnnVAu3jxVR11ArHM2 ySYq6XQfwLJWv0HZ9Hi/wum5y39X3sHj47O2BnUF+JJDOdtAG0dwgYVXqBuhBGtNLwIl j2Tw== X-Forwarded-Encrypted: i=1; AJvYcCVGYV9OvPgKqp2a6CmS+QFyKL29zS32WZdc3bJ1j/JTD9WA1PHwnALhONWMUB1n3vRBYOJQRW9iiYnGVI8dlyLNJnY= X-Gm-Message-State: AOJu0YzL2wOUUH8a1QhvM+Fx85+YCoQAeFtwmyOObDG9FYotVynymtuS 1aZCJrWvfn9hfnu6xpky/uEQf5BWatebU+/aJNYdYw2PgqBrQ1vk X-Google-Smtp-Source: AGHT+IEWFfgDbiPyPpjCyTYluBMUWMicvAov1vS/S70/NNvOG0O9g/+u39VNVA1PkSDmuLHqgwejNA== X-Received: by 2002:a17:902:eb4b:b0:1dd:6263:62d4 with SMTP id i11-20020a170902eb4b00b001dd626362d4mr1877271pli.3.1709860135228; Thu, 07 Mar 2024 17:08:55 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:428c]) by smtp.gmail.com with ESMTPSA id u15-20020a1709026e0f00b001dd4bc67910sm2241108plk.79.2024.03.07.17.08.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 Mar 2024 17:08:54 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH v3 bpf-next 11/14] bpf: Add helper macro bpf_addr_space_cast() Date: Thu, 7 Mar 2024 17:08:09 -0800 Message-Id: <20240308010812.89848-12-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240308010812.89848-1-alexei.starovoitov@gmail.com> References: <20240308010812.89848-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: f6ctgn6j16fayd18f8n9fo6geigo4ogn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4F33E100013 X-HE-Tag: 1709860136-45339 X-HE-Meta: U2FsdGVkX18RtmtS1WESwfEZiM8yuxF8spDh7TnPYnMCw6GVM7/FmjtVnea0TS199d6yMj08e/1xm5AaHJrab/ol7uwPNzRMvpWpZvKg/Gr8ZKzZx2Q2ItJrWZ9PvLHd56XX4lQiWaRRlnHCtlFnEbHpJtQw/0E+CAHsfOfE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m@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov Introduce helper macro bpf_addr_space_cast() that emits: rX = rX instruction with off = BPF_ADDR_SPACE_CAST and encodes dest and src address_space-s into imm32. It's useful with older LLVM that doesn't emit this insn automatically. Acked-by: Kumar Kartikeya Dwivedi Signed-off-by: Alexei Starovoitov --- .../testing/selftests/bpf/bpf_experimental.h | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index bc9a0832ae72..a5b9df38c162 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -343,6 +343,49 @@ l_true: \ asm volatile("%[reg]=%[reg]"::[reg]"r"((short)var)) #endif +/* emit instruction: + * rX = rX .off = BPF_ADDR_SPACE_CAST .imm32 = (dst_as << 16) | src_as + */ +#ifndef bpf_addr_space_cast +#define bpf_addr_space_cast(var, dst_as, src_as)\ + 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"(BPF_ADDR_SPACE_CAST) \ + , [as]"i"((dst_as << 16) | src_as)); +#endif + /* Description * Assert that a conditional expression is true. * Returns