From patchwork Fri Mar 8 01:08:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13586408 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 3A943C54E49 for ; Fri, 8 Mar 2024 01:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF4526B02F2; Thu, 7 Mar 2024 20:08:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA2166B02F4; Thu, 7 Mar 2024 20:08:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1C676B02F5; Thu, 7 Mar 2024 20:08:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8E05E6B02F2 for ; Thu, 7 Mar 2024 20:08:26 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 61F6B1C151A for ; Fri, 8 Mar 2024 01:08:26 +0000 (UTC) X-FDA: 81872086212.29.B5ADE61 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf08.hostedemail.com (Postfix) with ESMTP id A481B16000E for ; Fri, 8 Mar 2024 01:08:24 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=k+XH6Faa; spf=pass (imf08.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.181 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=1709860104; 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=eol0rLj8ZVaqzxemLtYqGJLGqcrhD/N/8xdUYrW35uM=; b=uloLEMQ17vgAeJMzkskhmqPjLxvHPLGvVUV6zYKoaQ/9mU0y2iIXTNYDWjGGbc4u0nRi1y IZhgRvmPMd1eYcRh29lJrGRAImY04gZh3DuHrUSoobpT+M6lTVbGbMSKcRQJgKU40PV6It T5ey4cw8OshIEEV0XOlWWttJMNFu37Y= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=k+XH6Faa; spf=pass (imf08.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709860104; a=rsa-sha256; cv=none; b=8AG0xag1lMnnOh2GM8aDW5A/MCIqM4zjiJ3RVJXumhhJGtray4W1Gf3qmKeQYrDtRPBaz/ Y9yA49QvqPo2jRBai3pbaFhvh/yvn5VuhWGBnUKKYgddgCCUhk3uzHO1a2LYf/shJdYSXK tUHD3VxYMY7pTFySRDVPKA/3TTNNYfY= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e6092a84f4so1277521b3a.0 for ; Thu, 07 Mar 2024 17:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709860103; x=1710464903; 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=eol0rLj8ZVaqzxemLtYqGJLGqcrhD/N/8xdUYrW35uM=; b=k+XH6FaaoY49A+6YuBeDqBivPCNkthOz6u0ByGyczT+5W9q+3pPw8+WG6k17wP2vNR 4Lx5di+wGovI1K2sDVyC64MriBLmfaObUi0gcXPEJZ11Hik7/wO+CiUoLHIJYQa+7Xl2 iMzckQnIjtOZuxpYh8MMzrci8wPhjjKEFYeIY22/uONTNhFoM9YoHS77bMkqCMpr100w cWBMzM5sPX0uoOXK4DPHSQoz4tuGCah1mqsRZsmjNPrU5oQ7FQguo13IRQpqLaiy1YGc h7rmCAeaYC7d58bSPXrSQhbiXXgkjjkWR9d1MtH+B+pkTvml/KmFxWFopeMnkEqYucTI XVAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709860103; x=1710464903; 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=eol0rLj8ZVaqzxemLtYqGJLGqcrhD/N/8xdUYrW35uM=; b=aGIN6cNtGM1zpvLowCtszsn5vOqZRZklna9hQLCnsp4qPKgjpVgVuzSNv8IGHct3qs DzVht0lIerWeeVNny8FwQxUQ9ARvaEy+PRQW+8FJqQJlx6stBwZDKMws0rv9BWddmC3g DFNV3s+OkYL3gAhN0uVE9hKaoUa8AMCdpZjFByxIyfjHCbHGbIEMqxhXw0nf0t7q+da8 SWKRJon5EcbHmnDRJfkSeXL6+xQ5WQp8qA2Jd0ICsXvbIaROCiya5+XZ+qKSesJxk7XQ nWXIau7wsNMzznMqe4ULceCtL2W2Lhb4cIDF1Q20VgVH7rDIDWYxVfNPz0vHg8I3DVvh 7XCg== X-Forwarded-Encrypted: i=1; AJvYcCX04UJkpUvQiGoQCZNRxlkvRI8HpxyGjBohJpNcBD5ANvndXVM/kYlqwY5n0RhhULtO/k7yjHUGThJMf4gaj5/53WI= X-Gm-Message-State: AOJu0YwTBC9dGdD5uV9w5Hytf1HlzpRIAARIxc6AlZ7fyMUPikR0P/zE yhoEjRQ2yrSvkSDnbdXUElJ2X8S2SpZEBN/98nt6Gesz3WewWX+BfG+vNFZP X-Google-Smtp-Source: AGHT+IEVuK7WXVcuZMt8VNUGYBFGky0WlIL+If2MnPNUNirTnV2pe36+CiCA+QDit7CvlPgNYZps4g== X-Received: by 2002:a05:6a20:6a1c:b0:1a1:6f1b:90f1 with SMTP id p28-20020a056a206a1c00b001a16f1b90f1mr4702201pzk.1.1709860103430; Thu, 07 Mar 2024 17:08:23 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:428c]) by smtp.gmail.com with ESMTPSA id gu19-20020a056a004e5300b006e6499d9c03sm3914096pfb.197.2024.03.07.17.08.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 Mar 2024 17:08:23 -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 02/14] bpf: Disasm support for addr_space_cast instruction. Date: Thu, 7 Mar 2024 17:08:00 -0800 Message-Id: <20240308010812.89848-3-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-Rspamd-Queue-Id: A481B16000E X-Rspam-User: X-Stat-Signature: 1dyfgcdrbki8kibsjfm7k5yo5iacgtk3 X-Rspamd-Server: rspam01 X-HE-Tag: 1709860104-776061 X-HE-Meta: U2FsdGVkX1/tJDltELt8WyDz1jR+004vSJY9oMVS2svBMiFWWzkWuLq/MzzZDqHaZnjk7MlHGXxiVo5icmv3Gql1BylhZSzaPICUAhyoYPGu4ZfVvsw2iC2k6uwqoVUAQ77qmcOS4m+ndP5IVXawFQfb/+pZQ6u/Jsx8VqYeb2VGWzWWfAq4Gn9zWBByeprKEa1OJS9hCTODaW+s8junUh1Y0uD9gmx8+k5hfiTgyThmQ+3w7gmIxUVOQu9sy11KYgam3kW+cumn4g9cWNlFrYhns/NBmX6RtMRV9Hy6KPV/1KkioDtUr3wNgsRfVwxivM0S1qd+SVDIfcPxaYRpuKCGgiZ59kx9XYU1ykc5CC4f2kggd6EgAQnSw2+Gbu099jASH8k6lqukE47uquFZL2d0JU398B/0Ds6ewzVCMYmDLogDvXandL5mXNzQhdnAZr9Eanf3sE9olLzlo12SpivZJYJNVdbxpLShURhA+etzXFi55btrQpKihxpqSQOt5Lg+hIo1nHTlTj289YSs7qxb1HGEoui/lzyz6VJb8NMTfE4T4UmxZIh1ZjMzfJyhfgcCZLcQLcLZYLeyND9lI52MxQWxj9H59zo4dMeq7VTLZO72iTI2Lwrz9UJx5/yoGTPJOK5g4MW3nurbnoWU1AHItrqRlp+IbJmRP3RsZR7ianGsH2pLpnCaGekzGtbf8LcyHqUlFk+kfqOctteVWFgdGPWdeQG2HmBw6bkDiRSr5/plWEAbA7l5GnNAQd3dnXaxc6mzvDbNQZjcaQVqKpbnz5dXmpF09osCzwB98urJNIrefd07AMZl+CFIjCUNw7fPAy3Oqh3BD0ruoTl2hQPLmCgROLCUSFUh+GEpvrRjkDNYtcl1/jPY57VaWy+x94XC8MEYOVscEhb2Iyr/NyDHTI42eSH1DTPbk6m3V/TL6LXmQ4PnxuWdGiMYrqbVnojLtiJLzhJeG/JTdNc eBTy8Szu pkwSXSuLPDHr3+UwrC1MvBfUS/beaLO50wGbGOh5YclvGfDzca5p2knL4wAyXzV9hNm63zq8P7G+vVQMaDxb0vZqtnlyvQ8qx67Vq9g/3rdDqqyuaTLG7a86StRxih4UvALlfnu9hnWeb9n+KsvvxmpjiyGOxGvk1eofPQa+HoBemV+qEGOh8mJN6d+b4OiE117nA 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 LLVM generates rX = addr_space_cast(rY, dst_addr_space, src_addr_space) instruction when pointers in non-zero address space are used by the bpf program. Recognize this insn in uapi and in bpf disassembler. Acked-by: Kumar Kartikeya Dwivedi Signed-off-by: Alexei Starovoitov --- include/uapi/linux/bpf.h | 4 ++++ kernel/bpf/disasm.c | 10 ++++++++++ tools/include/uapi/linux/bpf.h | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index e30d943db8a4..3c42b9f1bada 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1339,6 +1339,10 @@ enum { */ #define BPF_PSEUDO_KFUNC_CALL 2 +enum bpf_addr_space_cast { + BPF_ADDR_SPACE_CAST = 1, +}; + /* flags for BPF_MAP_UPDATE_ELEM command */ enum { BPF_ANY = 0, /* create new element or update existing */ diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c index 82b2dbdd048f..bd2e2dd04740 100644 --- a/kernel/bpf/disasm.c +++ b/kernel/bpf/disasm.c @@ -166,6 +166,12 @@ static bool is_movsx(const struct bpf_insn *insn) (insn->off == 8 || insn->off == 16 || insn->off == 32); } +static bool is_addr_space_cast(const struct bpf_insn *insn) +{ + return insn->code == (BPF_ALU64 | BPF_MOV | BPF_X) && + insn->off == BPF_ADDR_SPACE_CAST; +} + void print_bpf_insn(const struct bpf_insn_cbs *cbs, const struct bpf_insn *insn, bool allow_ptr_leaks) @@ -184,6 +190,10 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, insn->code, class == BPF_ALU ? 'w' : 'r', insn->dst_reg, class == BPF_ALU ? 'w' : 'r', insn->dst_reg); + } else if (is_addr_space_cast(insn)) { + verbose(cbs->private_data, "(%02x) r%d = addr_space_cast(r%d, %d, %d)\n", + insn->code, insn->dst_reg, + insn->src_reg, ((u32)insn->imm) >> 16, (u16)insn->imm); } else if (BPF_SRC(insn->code) == BPF_X) { verbose(cbs->private_data, "(%02x) %c%d %s %s%c%d\n", insn->code, class == BPF_ALU ? 'w' : 'r', diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index e30d943db8a4..3c42b9f1bada 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1339,6 +1339,10 @@ enum { */ #define BPF_PSEUDO_KFUNC_CALL 2 +enum bpf_addr_space_cast { + BPF_ADDR_SPACE_CAST = 1, +}; + /* flags for BPF_MAP_UPDATE_ELEM command */ enum { BPF_ANY = 0, /* create new element or update existing */